NewsService.php 325 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. use App\Model\GroupMemberImp;
  65. use App\Model\GroupImp;
  66. use App\Model\GroupTalkImp;
  67. use App\Model\GroupTalkMessagerImp;
  68. use App\Model\ArticleIgnore;
  69. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  70. class NewsService implements NewsServiceInterface
  71. {
  72. #[Inject]
  73. protected Redis $redis;
  74. /**
  75. * 获取导航池列表
  76. * @param array $data
  77. * @return array
  78. */
  79. public function getCategoryList(array $data): array
  80. {
  81. $search = $data['name'] ?? '';
  82. $page = (int)($data['page'] ?? 1);
  83. $perPage = (int)($data['pageSize'] ?? 10);
  84. // 1. 查出所有匹配的分类id
  85. if ($search) {
  86. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  87. if (empty($matchedIds)) {
  88. return Result::success(['rows' => [], 'total' => 0]);
  89. }
  90. // 2. 递归查所有父级,直到一级分类
  91. $idsStr = implode(',', $matchedIds);
  92. $sql = "
  93. WITH RECURSIVE parents AS (
  94. SELECT * FROM category WHERE id IN ($idsStr)
  95. UNION ALL
  96. SELECT c.* FROM category c
  97. INNER JOIN parents p ON c.id = p.pid
  98. )
  99. SELECT * FROM parents
  100. ";
  101. $parents = Db::select($sql);
  102. $parentIds = [];
  103. foreach ($parents as $row) {
  104. if ($row->pid == 0) {
  105. $parentIds[] = $row->id;
  106. }
  107. }
  108. $parentIds = array_unique($parentIds);
  109. } else {
  110. // 没有搜索,一级分类就是根
  111. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  112. }
  113. // 3. 一级分类分页
  114. $total = count($parentIds);
  115. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  116. if (empty($parentIds)) {
  117. return Result::success(['rows' => [], 'total' => $total]);
  118. }
  119. // 4. 递归查所有子孙
  120. $idsStr = implode(',', $parentIds);
  121. $sql = "
  122. WITH RECURSIVE subcategories AS (
  123. SELECT * FROM category WHERE id IN ($idsStr)
  124. UNION ALL
  125. SELECT c.* FROM category c
  126. INNER JOIN subcategories s ON c.pid = s.id
  127. )
  128. SELECT * FROM subcategories ORDER BY updated_at DESC
  129. ";
  130. $allCategories = Db::select($sql);
  131. // 5. 组装树结构
  132. $categoryMap = [];
  133. foreach ($allCategories as $cat) {
  134. $cat = (array)$cat;
  135. $cat['children'] = [];
  136. $categoryMap[$cat['id']] = $cat;
  137. }
  138. foreach ($categoryMap as $id => &$cat) {
  139. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  140. $categoryMap[$cat['pid']]['children'][] = &$cat;
  141. }
  142. }
  143. unset($cat);
  144. $categoryTree = [];
  145. foreach ($parentIds as $id) {
  146. if (isset($categoryMap[$id])) {
  147. $categoryTree[] = $categoryMap[$id];
  148. }
  149. }
  150. return Result::success([
  151. 'rows' => $categoryTree,
  152. 'total' => $total,
  153. ]);
  154. }
  155. private function findMatchedCategories($search)
  156. {
  157. if ($search) {
  158. return Category::where('name', 'like', "%{$search}%")
  159. ->orderBy('updated_at', 'desc')
  160. ->get();
  161. }
  162. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  163. ->get();
  164. }
  165. private function findAllParents($categories)
  166. {
  167. $allCategories = [];
  168. foreach ($categories as $category) {
  169. $parentId = $category->pid;
  170. while ($parentId > 0) {
  171. $parent = Category::find($parentId);
  172. if ($parent) {
  173. $allCategories[$parent->id] = $parent;
  174. $parentId = $parent->pid;
  175. } else {
  176. break;
  177. }
  178. }
  179. $allCategories[$category->id] = $category;
  180. }
  181. return array_values($allCategories);
  182. }
  183. private function buildCategoryTree($category, $allRequiredCategories)
  184. {
  185. $categoryData = $category->toArray();
  186. $children = [];
  187. foreach ($allRequiredCategories as $c) {
  188. if ($c->pid === $category->id) {
  189. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  190. }
  191. }
  192. if (!empty($children)) {
  193. $categoryData['children'] = $children;
  194. }
  195. return $categoryData;
  196. }
  197. public function myCategoryList(array $data): array
  198. {
  199. $sszq = $data['sszq'] ?? '';
  200. unset($data['sszq']);
  201. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  202. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  203. $where[] = [
  204. 'pid',
  205. '=',
  206. $data['pid'],
  207. ];
  208. if (isset($data['name'])) {
  209. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  210. }
  211. var_dump($where);
  212. //根据分类id,从category表中取出分类信息
  213. $result = Category::where($where)
  214. ->whereIn('category.id', $catorytids)
  215. ->select('category.*', 'category.id as category_id')->get();
  216. if (empty($result)) {
  217. return Result::error("没有栏目数据");
  218. }
  219. return Result::success($result);
  220. }
  221. /**
  222. * @param array $data
  223. * @return array
  224. */
  225. public function categoryList(array $data): array
  226. {
  227. $where[] = [
  228. 'pid',
  229. '=',
  230. $data['pid']
  231. ];
  232. if (isset($data['name'])) {
  233. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  234. }
  235. var_dump($where);
  236. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  237. if (empty($result)) {
  238. return Result::error("没有栏目数据");
  239. }
  240. return Result::success($result);
  241. }
  242. /**
  243. * @param array $data
  244. * @return array
  245. */
  246. public function addCategory(array $data): array
  247. {
  248. if (isset($data['id'])) {
  249. unset($data['id']);
  250. }
  251. $id = Category::insertGetId($data);
  252. if (empty($id)) {
  253. return Result::error("添加失败");
  254. }
  255. return Result::success(['id' => $id]);
  256. }
  257. /**
  258. * @param array $data
  259. * @return array
  260. */
  261. public function delCategory(array $data): array
  262. {
  263. Db::beginTransaction();
  264. try {
  265. $categoryList = Category::where(['pid' => $data['id']])->get();
  266. if ($categoryList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有子分类不能删除");
  269. }
  270. $articleList = Article::where(['catid' => $data['id']])->get();
  271. if ($articleList->toArray()) {
  272. Db::rollBack();
  273. return Result::error("分类下面有资讯不能删除");
  274. }
  275. $result = Category::where($data)->delete();
  276. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  277. if (!$result) {
  278. Db::rollBack();
  279. return Result::error("删除失败");
  280. }
  281. Db::commit();
  282. return Result::success($result);
  283. } catch (\Exception $e) {
  284. Db::rollBack();
  285. return Result::error("删除失败" . $e->getMessage());
  286. }
  287. }
  288. /**
  289. * @param array $data
  290. * @return array
  291. */
  292. public function updateCategory(array $data): array
  293. {
  294. $where = [
  295. 'id' => $data['id'],
  296. ];
  297. $result = Category::where($where)->update($data);
  298. if ($result) {
  299. return Result::success($result);
  300. } else {
  301. return Result::error("更新失败");
  302. }
  303. }
  304. /**
  305. * 获取导航池信息
  306. * @param array $data
  307. * @return array
  308. */
  309. public function getCategoryInfo(array $data): array
  310. {
  311. $where = [
  312. 'id' => $data['id'],
  313. ];
  314. $result = Category::where($where)->first();
  315. if ($result) {
  316. return Result::success($result);
  317. } else {
  318. return Result::error("更新失败");
  319. }
  320. }
  321. public function getArticleCommend(array $data): array
  322. {
  323. $where = [
  324. 'website_id' => $data['website_id'],
  325. ];
  326. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  327. var_dump($ids);
  328. if (empty($ids)) {
  329. return Result::error("没有推荐数据");
  330. }
  331. //id
  332. $whereArticle = [];
  333. if (isset($data['id'])) {
  334. $whereArticle['id'] = $data['id'];
  335. }
  336. //title like
  337. if (isset($data['title'])) {
  338. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  339. }
  340. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  341. ->where($whereArticle)
  342. ->orderBy('id', 'desc')
  343. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  344. if ($article) {
  345. $data = [
  346. 'rows' => $article->items(),
  347. 'count' => $article->total(),
  348. ];
  349. return Result::success($data);
  350. } else {
  351. return Result::error("获取失败失败");
  352. }
  353. }
  354. /**
  355. * @param array $data
  356. * @return array
  357. */
  358. public function getArticleList(array $data): array
  359. {
  360. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  361. $type_id = $data['type_id'];
  362. unset($data['type_id']);
  363. $user_id = $data['user_id'];
  364. unset($data['user_id']);
  365. $where = [];
  366. $status1 = [];
  367. if (isset($data['id']) && $data['id']) {
  368. array_push($where, ['article.id', '=', $data['id']]);
  369. }
  370. if (isset($data['title']) && $data['title']) {
  371. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  372. }
  373. if (isset($data['category_name']) && $data['category_name']) {
  374. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  375. }
  376. if (isset($data['catid']) && $data['catid']) {
  377. array_push($where, ['article.catid', '=', $data['catid']]);
  378. }
  379. if (isset($data['author']) && $data['author']) {
  380. array_push($where, ['article.author', '=', $data['author']]);
  381. }
  382. if (isset($data['islink']) && $data['islink'] !== "") {
  383. array_push($where, ['article.islink', '=', $data['islink']]);
  384. }
  385. if (isset($data['status']) && $data['status'] !== "") {
  386. array_push($where, ['article.status', '=', $data['status']]);
  387. }
  388. if (isset($data['status1'])) {
  389. $status1 = json_decode(($data['status1']));
  390. }
  391. //不是管理员展示个人数据;
  392. if ($type_id != 10000) {
  393. $where[] = ['article.admin_user_id', '=', $user_id];
  394. }
  395. $startTime = microtime(true);
  396. $rep = Article::query()
  397. // 预加载相关关联
  398. ->with([
  399. 'category' => function ($query) {
  400. $query->select('id', 'name');
  401. },
  402. 'websiteCategory' => function ($query) {
  403. $query->select('website_id', 'category_id', 'alias');
  404. }
  405. ])
  406. // 构建where条件
  407. ->when(isset($data['id']) && $data['id'], function ($query) use ($data) {
  408. $query->where('article.id', '=', $data['id']);
  409. })
  410. ->when(isset($data['title']) && $data['title'], function ($query) use ($data) {
  411. $query->where('article.title', 'like', '%' . $data['title'] . '%');
  412. })
  413. ->when(isset($data['category_name']) && $data['category_name'], function ($query) use ($data) {
  414. // 使用子查询替代左连接进行模糊搜索
  415. $query->whereHas('category', function ($subQuery) use ($data) {
  416. $subQuery->where('name', 'like', '%' . $data['category_name'] . '%');
  417. });
  418. })
  419. ->when(isset($data['catid']) && $data['catid'], function ($query) use ($data) {
  420. $query->where('article.catid', '=', $data['catid']);
  421. })
  422. ->when(isset($data['author']) && $data['author'], function ($query) use ($data) {
  423. $query->where('article.author', '=', $data['author']);
  424. })
  425. ->when(isset($data['islink']) && $data['islink'] !== "", function ($query) use ($data) {
  426. $query->where('article.islink', '=', $data['islink']);
  427. })
  428. ->when(isset($data['status']) && $data['status'] !== "", function ($query) use ($data) {
  429. $query->where('article.status', '=', $data['status']);
  430. })
  431. ->when(isset($data['status1']) && $data['status1'], function ($query) use ($data) {
  432. // 安全地处理JSON字符串
  433. $status1 = is_array($data['status1']) ? $data['status1'] : json_decode($data['status1'], true) ?? [];
  434. if (!empty($status1)) {
  435. $query->whereIn('article.status', $status1);
  436. }
  437. })
  438. ->select('article.*')
  439. // 非管理员限制
  440. ->when($type_id != 10000, function ($query) use ($user_id) {
  441. // 非管理员只能看自己的文章,同时把 article_ignore 的 c_show_time 一起查出来
  442. $query->where('article.admin_user_id', $user_id)
  443. ->leftJoin('article_ignore', function ($join) {
  444. // 关联条件:article.id = article_ignore.article_id 且 article.web_site_id = article_ignore.website_id
  445. $join->on('article_ignore.article_id', '=', 'article.id')
  446. ->whereColumn('article_ignore.website_id', 'article.web_site_id');
  447. })
  448. ->addSelect('article_ignore.article_id','article_ignore.c_show_time'); // 用 addSelect 追加字段,避免覆盖原有 select
  449. })
  450. // 基础条件
  451. ->whereNotIn('article.status', [404])
  452. // 排序和分页
  453. ->orderBy('article.updated_at', 'desc')
  454. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  455. // 获取结果并格式化
  456. $data = [
  457. 'rows' => $rep->items(),
  458. 'count' => $rep->total(),
  459. ];
  460. // 执行查询
  461. $endTime = microtime(true);
  462. $executionTime = ($endTime - $startTime) * 1000;
  463. echo "查询执行时间: {$executionTime}ms\n";
  464. return Result::success($data);
  465. }
  466. /**
  467. * @param array $data
  468. * @return array
  469. */
  470. public function addArticle(array $data): array
  471. {
  472. var_dump($data, '----------12-----------1');
  473. // ------c_show_time********add***1****
  474. $is_collect = $data['is_collect'] ?? 0;
  475. $user_type = $data['user_type'];
  476. unset($data['is_collect']);
  477. unset($data['user_type']);
  478. // ------c_show_time********add***1****
  479. unset($data['nav_add_pool_id']);
  480. // unset($data['commend_id']);
  481. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  482. Db::beginTransaction();
  483. try {
  484. //处理投票
  485. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  486. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  487. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  488. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  489. unset($data['is_survey']);
  490. unset($data['survey_name']);
  491. unset($data['suvey_array']);
  492. // unset($data['website_id']);
  493. // unset($data['web_site_id']);
  494. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  495. if ($data['hits'] == '') {
  496. $data['hits'] = 0;
  497. }
  498. if ($data['is_original'] == '') {
  499. $data['is_original'] = 0;
  500. }
  501. if ($data['status'] == '') {
  502. $data['status'] = 0;
  503. }
  504. $articleData = $data;
  505. unset($articleData['content']);
  506. //自动处理缩略图、关键字、描述
  507. if ($articleData['imgurl'] == '') {
  508. //如果没有图,设置level=0
  509. $levelArr = json_decode($articleData['level'], true);
  510. var_dump($levelArr, '----------levelArr-----------1');
  511. //content中提取图片第一个图,正则提取
  512. // -------采集器相关优化-----
  513. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  514. if ($is_collect == 1) {
  515. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  516. } else {
  517. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  518. }
  519. // -------采集器相关优化-----
  520. preg_match_all($reg, $data['content'], $matches);
  521. if (isset($matches[1][0])) {
  522. //截取varchar240
  523. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  524. //如果有图,设置level=3
  525. if (!in_array(3, $levelArr)) {
  526. $levelArr[] = 3;
  527. }
  528. $articleData['level'] = json_encode($levelArr);
  529. } else {
  530. if (!in_array(0, $levelArr)) {
  531. $levelArr[] = 0;
  532. }
  533. $articleData['level'] = json_encode($levelArr);
  534. }
  535. }
  536. var_dump($articleData['level'], '----------$articleData[level]----------1');
  537. if ($articleData['keyword'] == '') {
  538. //提取标题+内容中的关键词
  539. $articleData['keyword'] = $data['title'];
  540. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  541. Jieba::init(); // 初始化 jieba-php
  542. Finalseg::init();
  543. $segList = Jieba::cut($articleData['keyword']);
  544. $segList1 = array_slice($segList, 0, 8);
  545. $articleData['keyword'] = implode(',', $segList1);
  546. }
  547. if ($articleData['introduce'] == '') {
  548. //提取内容中的描述
  549. $content = $data['content'];
  550. // 去除 <style> 和 <script> 标签及其内容
  551. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  552. // 去除所有 HTML 标签
  553. $content = strip_tags($content);
  554. // 去除 HTML 实体
  555. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  556. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  557. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  558. // 去除多余空白
  559. $content = preg_replace('/\s+/u', '', $content);
  560. // 截取 100 个字符
  561. $articleData['introduce'] = mb_substr($content, 0, 100);
  562. }
  563. if ($articleData['status'] == 0) {
  564. $this->sendMessage([
  565. 'talk_type' => 100,
  566. 'title' => $articleData['title'],
  567. 'content' => '提交了审核',
  568. 'messageType' => 2,
  569. ]);
  570. }
  571. $id = Article::insertGetId($articleData);
  572. if (!$id) {
  573. throw new \Exception('文章插入失败');
  574. }
  575. $articleDataContent = [
  576. 'article_id' => $id,
  577. 'content' => $data['content'],
  578. ];
  579. // 采集器中的文章内容,在添加时,去掉div标签
  580. if ($is_collect == 1) {
  581. // 采集来的文章,content中可能包含div标签,需要先移除
  582. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  583. $article_data = preg_replace($pattern, '', $data['content']);
  584. $$articleDataContent['content'] = $article_data;
  585. }
  586. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  587. if (!$contentInsertId) {
  588. throw new \Exception('文章内容插入失败');
  589. }
  590. // ------c_show_time********add***2****
  591. // 直接使用当前系统时间,不再强制添加8小时
  592. $now = date('Y-m-d H:i:s');
  593. if ($user_type == 10000 || $is_collect == 1) {
  594. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  595. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  596. if (!isset($data['catid'])) {
  597. throw new \Exception('缺少必要字段:catid');
  598. }
  599. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  600. $web = WebsiteCategory::where('category_id', $data['catid'])
  601. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  602. ->select(
  603. 'website_id',
  604. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  605. )
  606. ->get();
  607. // $id = 225; -----测试开启
  608. // 采集来的文章,错开时间在两小时之内发布
  609. if ($user_type == 10000 && $is_collect == 1) {
  610. $web_num = $web->where('is_core', '!=', 2)->count();
  611. $waiting_interval = 10;
  612. if ($web_num > 12) {
  613. // 若网站数量大于12个,则每个网站间隔时间取均值
  614. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  615. $waiting_interval = 120 / max(1, $web_num);
  616. }
  617. $time = 0;
  618. } else {
  619. // 非核心站与核心站----显示时间-----间隔
  620. $time = 20;
  621. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  622. $waiting_interval = 5;
  623. }
  624. // 将 Hyperf\Database\Model\Collection 转换为数组
  625. $webArray = $web->toArray();
  626. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  627. // 检查 $item 对象是否有 is_core 属性
  628. if (!isset($item['is_core'])) {
  629. throw new \Exception('$item 对象缺少 is_core 属性');
  630. }
  631. // 当 is_core 为 2 时,则表示此网站不存在
  632. if ($item['is_core'] == 2) {
  633. return null;
  634. }
  635. if ($is_collect == 1) {
  636. // 采集来的文章,错开时间在两小时之内发布
  637. // $time = 0;
  638. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  639. $time += $waiting_interval;
  640. } else if ($item['is_core'] == 1) {
  641. // 当 is_core 为 1 时,则表示此网站是核心站
  642. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  643. } else {
  644. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  645. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  646. if ($item['is_core'] == 0) {
  647. $time += $waiting_interval;
  648. }
  649. }
  650. return [
  651. 'article_id' => $id,
  652. 'website_id' => $item['website_id'],
  653. 'c_show_time' => $c_show_time,
  654. // 'is_core' => $item['is_core'],
  655. // 'time' => $time
  656. ];
  657. }, array_keys($webArray), $webArray)));
  658. // Db::commit();
  659. // return Result::success($article_ignore);
  660. if (!empty($article_ignore)) {
  661. $article_ignores = ArticleIgnore::insert($article_ignore);
  662. if (!$article_ignores) {
  663. throw new \Exception('c端展示时间插入失败');
  664. }
  665. }
  666. }
  667. // ------c_show_time********add***2****
  668. //处理投票
  669. if ($is_survey == 1) {
  670. //生成年月日时分秒+8位随机数
  671. $uuid = date('YmdHis') . rand(10000000, 99999999);
  672. var_dump($suvey_array, 'suvey_array________');
  673. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  674. var_dump($suveys_array, '---------------------1');
  675. var_dump($suvey_array, '---------------------2');
  676. $suvey_data = [];
  677. foreach ($suveys_array as $key => $value) {
  678. if ($value == '') {
  679. continue;
  680. }
  681. if (is_array($value)) {
  682. $suvey_data[] = [
  683. 'sur_id' => $uuid,
  684. 'art_id' => $id,
  685. 'website_id' => $website_id ?? 2,
  686. 'survey_name' => $survey_name,
  687. 'choice_name' => $value[1],
  688. 'is_other' => 1,
  689. 'other_id' => 0,
  690. 'results' => 0,
  691. ];
  692. } else {
  693. $suvey_data[] = [
  694. 'sur_id' => $uuid,
  695. 'art_id' => $id,
  696. 'website_id' => $website_id ?? 2,
  697. 'survey_name' => $survey_name,
  698. 'choice_name' => $value,
  699. 'is_other' => 0,
  700. 'other_id' => 0,
  701. 'results' => 0,
  702. ];
  703. }
  704. if (empty($suvey_data)) {
  705. throw new \Exception("投票数据为空");
  706. }
  707. }
  708. $result = ArticleSurvey::insert($suvey_data);
  709. if (!$result) {
  710. throw new \Exception("投票失败,ArticleSurvey插入失败");
  711. }
  712. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  713. if (!$result) {
  714. throw new \Exception("投票失败,更新主表失败");
  715. }
  716. }
  717. Db::commit();
  718. return Result::success(['id' => $id]);
  719. } catch (\Throwable $ex) {
  720. Db::rollBack();
  721. var_dump($ex->getMessage());
  722. return Result::error("创建失败", 0);
  723. }
  724. }
  725. /**
  726. * @param array $data
  727. * @return array
  728. */
  729. public function delArticle(array $data): array
  730. {
  731. // ------c_show_time********del*******
  732. Db::beginTransaction();
  733. try {
  734. $article = Article::where(['id' => $data['id']])->delete();
  735. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  736. if (!$article) {
  737. throw new \Exception("删除失败,文章删除失败");
  738. }
  739. //survey投票删除
  740. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  741. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  742. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  743. // 若文章详情删除失败,抛出异常
  744. if (!$article_data) {
  745. throw new \Exception("删除失败,文章详情删除失败");
  746. }
  747. Db::commit(); // 所有操作成功,提交事务
  748. } catch (\Throwable $ex) {
  749. Db::rollBack();
  750. var_dump($ex->getMessage());
  751. return Result::error("删除失败: " . $ex->getMessage(), 0);
  752. }
  753. // ------c_show_time********del*******
  754. if (!$article) {
  755. return Result::error("删除失败");
  756. }
  757. return Result::success($article);
  758. }
  759. /**
  760. * @param array $data
  761. * @return array
  762. */
  763. public function updateArticle(array $data): array
  764. {
  765. var_dump($data, '----------12-----------1');
  766. Db::beginTransaction();
  767. // ------c_show_time********up*******
  768. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  769. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  770. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  771. $web = WebsiteCategory::where('category_id', $data['catid'])
  772. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  773. ->select(
  774. 'website_id',
  775. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  776. )
  777. ->get();
  778. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  779. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  780. $websiteIds = $web->pluck('website_id')->toArray();
  781. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  782. if ($user_type == 0) {
  783. throw new \Exception("用户类型不能为空");
  784. }
  785. if ($user_type == 10000) {
  786. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  787. $web = WebsiteCategory::where('category_id', $data['catid'])
  788. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  789. ->select(
  790. 'website_id',
  791. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  792. )
  793. ->get();
  794. // 非核心站与核心站----显示时间-----间隔
  795. $time = 20;
  796. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  797. $waiting_interval = 5;
  798. $webArray = $web->toArray();
  799. if (empty($webArray)) {
  800. throw new \Exception('网站分类不存在');
  801. }
  802. // 直接使用当前系统时间,不再强制添加8小时
  803. $now = date('Y-m-d H:i:s');
  804. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  805. // 检查 $item 对象是否有 is_core 属性
  806. if (!isset($item['is_core'])) {
  807. throw new \Exception('$item 对象缺少 is_core 属性');
  808. }
  809. // 当 is_core 为 2 时,则表示此网站不存在
  810. if ($item['is_core'] == 2) {
  811. return null;
  812. } else if ($item['is_core'] == 1) {
  813. // 当 is_core 为 1 时,则表示此网站是核心站
  814. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  815. } else {
  816. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  817. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  818. if ($item['is_core'] == 0) {
  819. $time += $waiting_interval;
  820. }
  821. }
  822. return [
  823. 'article_id' => $data['id'],
  824. 'website_id' => $item['website_id'],
  825. 'c_show_time' => $c_show_time,
  826. ];
  827. }, array_keys($webArray), $webArray)));
  828. if (!empty($article_ignore)) {
  829. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  830. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  831. $article_ignores = ArticleIgnore::upsert(
  832. $article_ignore,
  833. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  834. ['c_show_time'] // 需要更新的字段
  835. );
  836. if (!$article_ignores) {
  837. throw new \Exception('c端展示时间插入失败');
  838. }
  839. }
  840. // Db::commit();
  841. // return Result::success($article_ignore);
  842. }
  843. // ------c_show_time********up*******
  844. unset($data['user_type']);
  845. // unset($data['web_site_id']);
  846. unset($data['nav_add_pool_id']);
  847. try {
  848. //处理投票
  849. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  850. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  851. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  852. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  853. unset($data['is_survey']);
  854. unset($data['survey_name']);
  855. unset($data['suvey_array']);
  856. unset($data['website_id']);
  857. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  858. if ($data['hits'] == '') {
  859. $data['hits'] = 0;
  860. }
  861. if ($data['is_original'] == '') {
  862. $data['is_original'] = 0;
  863. }
  864. if ($data['status'] == '') {
  865. $data['status'] = 0;
  866. }
  867. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  868. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  869. $articleData = $data;
  870. unset($articleData['content']);
  871. unset($articleData['status_name']);
  872. unset($articleData['name']);
  873. unset($articleData['content']);
  874. unset($articleData['pid_arr']);
  875. unset($articleData['pid']);
  876. //自动处理缩略图、关键字、描述
  877. if ($articleData['imgurl'] == '') {
  878. //如果没有图,设置level=0
  879. $levelArr = json_decode($articleData['level'], true);
  880. var_dump($levelArr, '----------levelArr-----------1');
  881. //content中提取图片第一个图,正则提取
  882. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  883. preg_match_all($reg, $data['content'], $matches);
  884. if (isset($matches[1][0])) {
  885. //截取varchar240
  886. // 截取到第一个<
  887. $articleData['imgurl'] = $matches[1][0];
  888. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  889. $pos = strpos($articleData['imgurl'], '"');
  890. if ($pos !== false) {
  891. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  892. }
  893. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  894. //如果有图,设置level=3
  895. if (!in_array(3, $levelArr)) {
  896. $levelArr[] = 3;
  897. }
  898. $articleData['level'] = json_encode($levelArr);
  899. } else {
  900. if (!in_array(0, $levelArr)) {
  901. $levelArr[] = 0;
  902. }
  903. $articleData['level'] = json_encode($levelArr);
  904. }
  905. }
  906. var_dump($articleData['level'], '----------$articleData[level]----------1');
  907. if ($articleData['keyword'] == '') {
  908. //提取标题+内容中的关键词
  909. $articleData['keyword'] = $data['title'];
  910. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  911. Jieba::init(); // 初始化 jieba-php
  912. Finalseg::init();
  913. $segList = Jieba::cut($articleData['keyword']);
  914. $segList1 = array_slice($segList, 0, 8);
  915. $articleData['keyword'] = implode(',', $segList1);
  916. }
  917. if ($articleData['introduce'] == '') {
  918. //提取内容中的描述
  919. $content = $data['content'];
  920. // 去除 <style> 和 <script> 标签及其内容
  921. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  922. // 去除所有 HTML 标签
  923. $content = strip_tags($content);
  924. // 去除 HTML 实体
  925. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  926. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  927. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  928. // 去除多余空白
  929. $content = preg_replace('/\s+/u', '', $content);
  930. // 截取 100 个字符
  931. $articleData['introduce'] = mb_substr($content, 0, 100);
  932. }
  933. if ($articleData['status'] == 0) {
  934. $this->sendMessage([
  935. 'talk_type' => 100,
  936. 'title' => $articleData['title'],
  937. 'content' => '提交了审核',
  938. 'messageType' => 2,
  939. ]);
  940. }
  941. $id = Article::where(['id' => $data['id']])->update($articleData);
  942. // $articleDataContent = [
  943. // 'content' => $data['content'],
  944. // ];
  945. // 采集来的文章,content中可能包含div标签,需要先移除
  946. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  947. $article_data = preg_replace($pattern, '', $data['content']);
  948. $articleDataContent['content'] = $article_data;
  949. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  950. //处理投票
  951. $id = $data['id'];
  952. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  953. var_dump($suvey_array, 'suvey_array________delete');
  954. //处理投票
  955. if ($is_survey == 1) {
  956. //生成年月日时分秒+8位随机数
  957. $uuid = date('YmdHis') . rand(10000000, 99999999);
  958. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  959. var_dump($suveys_array, '---------------------1');
  960. $suvey_data = [];
  961. if (is_array($suveys_array)) {
  962. foreach ($suveys_array as $key => $value) {
  963. if ($value == '') {
  964. continue;
  965. }
  966. if (is_array($value)) {
  967. $suvey_data[] = [
  968. 'sur_id' => $uuid,
  969. 'art_id' => $id,
  970. 'website_id' => $website_id ?? 2,
  971. 'survey_name' => $survey_name,
  972. 'choice_name' => $value[1],
  973. 'is_other' => 1,
  974. 'other_id' => 0,
  975. 'results' => 0,
  976. ];
  977. } else {
  978. $suvey_data[] = [
  979. 'sur_id' => $uuid,
  980. 'art_id' => $id,
  981. 'website_id' => $website_id ?? 2,
  982. 'survey_name' => $survey_name,
  983. 'choice_name' => $value,
  984. 'is_other' => 0,
  985. 'other_id' => 0,
  986. 'results' => 0,
  987. ];
  988. }
  989. if (empty($suvey_data)) {
  990. throw new \Exception("投票数据为空");
  991. }
  992. }
  993. }
  994. $result = ArticleSurvey::insert($suvey_data);
  995. if (!$result) {
  996. throw new \Exception("投票失败");
  997. }
  998. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  999. if (!$result) {
  1000. throw new \Exception("投票失败");
  1001. }
  1002. } else {
  1003. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  1004. }
  1005. Db::commit();
  1006. return Result::success([]);
  1007. } catch (\Throwable $ex) {
  1008. Db::rollBack();
  1009. var_dump($ex->getMessage());
  1010. return Result::error("更新失败" . $ex->getMessage(), 0);
  1011. }
  1012. }
  1013. /**
  1014. * 更新资讯状态
  1015. * @param array $data
  1016. * @return array
  1017. */
  1018. public function upArticleStatus(array $data): array
  1019. {
  1020. $articleData = Article::where(['id' => $data['id']])->first();
  1021. //发送10次
  1022. // for ($i = 0; $i < 10; $i++) {
  1023. // $this->sendMessage([
  1024. // 'talk_type' => 100,
  1025. // 'title' => $i . $articleData['title'],
  1026. // 'content' => '审核通过',
  1027. // 'messageType' => 2,
  1028. // 'user_id' => $articleData['admin_user_id'],
  1029. // ]);
  1030. // }
  1031. // var_dump($data['status'], 'status');
  1032. // return Result::success();
  1033. if ($data['status'] == 1) {
  1034. $this->sendMessage([
  1035. 'talk_type' => 101,
  1036. 'title' => $articleData['title'],
  1037. 'content' => '审核通过',
  1038. 'messageType' => 2,
  1039. 'user_id' => $articleData['admin_user_id'],
  1040. ]);
  1041. }
  1042. if ($data['status'] == 2) {
  1043. $this->sendMessage([
  1044. 'talk_type' => 101,
  1045. 'title' => $articleData['title'],
  1046. 'content' => '审核拒绝',
  1047. 'messageType' => 2,
  1048. 'user_id' => $articleData['admin_user_id'],
  1049. ]);
  1050. }
  1051. if ($data['status'] == 0) {
  1052. $this->sendMessage([
  1053. 'talk_type' => 100,
  1054. 'title' => $articleData['title'],
  1055. 'content' => '提交了审核',
  1056. 'messageType' => 2,
  1057. ]);
  1058. }
  1059. $result = Article::where(['id' => $data['id']])->update($data);
  1060. // ------c_show_time********up_status*******
  1061. // 若是审核通过 则更新c_show_time
  1062. if ($data['status'] == 1) {
  1063. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1064. $web = Article::where('article.id', $data['id'])
  1065. ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  1066. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1067. ->select(
  1068. 'website_id',
  1069. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  1070. )
  1071. ->get();
  1072. // 非核心站与核心站----显示时间-----间隔
  1073. $time = 20;
  1074. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1075. $waiting_interval = 5;
  1076. $webArray = $web->toArray();
  1077. if (empty($webArray)) {
  1078. throw new \Exception('网站分类不存在');
  1079. }
  1080. // 直接使用当前系统时间,不再强制添加8小时
  1081. $now = date('Y-m-d H:i:s');
  1082. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1083. if (isset($data['ignore_ids'])) {
  1084. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1085. if (in_array($item['website_id'], $ignore_website_ids)) {
  1086. $is_ignore = 1;
  1087. } else {
  1088. $is_ignore = 0;
  1089. }
  1090. return [
  1091. 'article_id' => $data['id'],
  1092. 'website_id' => $item['website_id'],
  1093. 'is_ignore' => $is_ignore,
  1094. ];
  1095. } else {
  1096. // 检查 $item 对象是否有 is_core 属性
  1097. if (!isset($item['is_core'])) {
  1098. throw new \Exception('$item 对象缺少 is_core 属性');
  1099. }
  1100. // 当 is_core 为 2 时,则表示此网站不存在
  1101. if ($item['is_core'] == 2) {
  1102. return null;
  1103. } else if ($item['is_core'] == 1) {
  1104. // 当 is_core 为 1 时,则表示此网站是核心站
  1105. $c_show_time = $now;
  1106. } else {
  1107. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1108. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  1109. if ($item['is_core'] == 0) {
  1110. $time += $waiting_interval;
  1111. }
  1112. }
  1113. return [
  1114. 'article_id' => $data['id'],
  1115. 'website_id' => $item['website_id'],
  1116. 'c_show_time' => $c_show_time,
  1117. ];
  1118. }
  1119. }, array_keys($webArray), $webArray)));
  1120. if (!empty($article_ignore) && !isset($data['ignore_ids'])) {
  1121. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1122. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1123. $websiteIds = $web->pluck('website_id')->toArray();
  1124. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1125. $article_ignores = ArticleIgnore::upsert(
  1126. $article_ignore,
  1127. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1128. ['c_show_time'] // 需要更新的字段
  1129. );
  1130. if (!$article_ignores) {
  1131. throw new \Exception('c端展示时间插入失败');
  1132. }
  1133. }
  1134. if (!empty($data['ignore_ids'])) {
  1135. // return Result::success($article_ignore);
  1136. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1137. if (!empty($article_ignore)) {
  1138. $article_ignores = ArticleIgnore::upsert(
  1139. $article_ignore,
  1140. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1141. ['is_ignore'] // 需要更新的字段
  1142. );
  1143. // if(!$article_ignores){
  1144. // throw new \Exception('屏蔽网站更新失败');
  1145. // }
  1146. }
  1147. }
  1148. }
  1149. // ------c_show_time********up_status*******
  1150. if ($result) {
  1151. return Result::success();
  1152. } else {
  1153. return Result::error("更新状态失败", 0);
  1154. }
  1155. }
  1156. /**
  1157. * 获取新闻详情
  1158. * @param array $data
  1159. * @return array
  1160. */
  1161. public function getArticleInfo(array $data): array
  1162. {
  1163. $where = [
  1164. 'article.id' => $data['id'],
  1165. // 'article.status' => 1,
  1166. ];
  1167. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1168. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1169. $info = $result;
  1170. // var_dump($info, 'info');
  1171. $info['survey_array'] = $articleSurvey;
  1172. if ($result) {
  1173. return Result::success($info);
  1174. } else {
  1175. return Result::error("查询失败", 0);
  1176. }
  1177. }
  1178. /**
  1179. * 获取头条新闻
  1180. * @param array $data
  1181. * @return array
  1182. */
  1183. public function getWebsiteArticlett(array $data): array
  1184. {
  1185. $website_id = $data['website_id'];
  1186. $website = Website::where('id', $data['website_id'])->first();
  1187. if (empty($website)) {
  1188. return Result::error("网站不存在", 0);
  1189. }
  1190. $categorys = $this->processArticlePro($website_id);
  1191. $catiall = $categorys['catiall'];
  1192. $categoryIds = $categorys['categoryIds'];
  1193. $where = [
  1194. 'status' => 1
  1195. ];
  1196. // $website_column = $website['column'];
  1197. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1198. $website_column = json_decode($website['website_column_arr_id'], true);
  1199. }
  1200. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1201. // return Result::success($diff_pid_categoryIds);
  1202. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1203. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1204. }
  1205. // $website_id = $data['website_id'];
  1206. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1207. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1208. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1209. switch ($data['level']) {
  1210. case 1:
  1211. case 2:
  1212. case 3:
  1213. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1214. $query = Article::where($where)
  1215. ->where('level', 'like', '%' . $data['level'] . '%')
  1216. ->orderBy('updated_at', 'desc');
  1217. break;
  1218. case 4: //最新资讯
  1219. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1220. break;
  1221. case 5: //资讯推荐
  1222. $query = Article::where($where)
  1223. ->where('updated_at', '>', $month);
  1224. break;
  1225. case 7: //资讯分类
  1226. if (isset($data['id']) && !empty($data['id'])) {
  1227. $keyword = Article::where('id', $data['id'])->value('keyword');
  1228. $keywordArray = explode(',', $keyword);
  1229. $whereL7 = [];
  1230. foreach ($keywordArray as $k => $v) {
  1231. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1232. }
  1233. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1234. break;
  1235. } else {
  1236. return Result::error("请输入资讯ID", 0);
  1237. break;
  1238. }
  1239. default:
  1240. break;
  1241. }
  1242. // $whereL7 = [];
  1243. // if(isset($data['id']) && !empty($data['id'])){
  1244. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1245. // $keywordArray = explode(',', $keyword);
  1246. // foreach ($keywordArray as $k => $v) {
  1247. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1248. // }
  1249. // }
  1250. // $query = Article::where($where)
  1251. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1252. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1253. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1254. // }
  1255. // if($data['level'] == 7){
  1256. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1257. // }
  1258. // if($data['level'] == 4){
  1259. // $query = $query->inRandomOrder()
  1260. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1261. // }
  1262. // if($data['level'] == 5){
  1263. // $query = $query->orderBy('updated_at','desc');
  1264. // }
  1265. // });
  1266. if ($data['textnum'] > 0) {
  1267. $query = clone $query;
  1268. $result['text'] = $query
  1269. ->whereIn('catid', $categoryIds)
  1270. ->leftJoinSub(function ($query) use ($website_id) {
  1271. $query->from('article_ignore')
  1272. ->where('website_id', $website_id);
  1273. }, 'article_ignore', function ($join) {
  1274. $join->on('article_ignore.article_id', '=', 'article.id');
  1275. })
  1276. ->where(function ($query) {
  1277. $query->whereNull('article_ignore.article_id')
  1278. ->orWhere(function ($subQuery) {
  1279. $subQuery->whereNotNull('article_ignore.article_id')
  1280. ->where('article_ignore.is_ignore', 0)
  1281. ->where(function ($subSubQuery) {
  1282. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1283. ->orWhereNull('article_ignore.c_show_time');
  1284. });
  1285. });
  1286. })
  1287. // ->where(function ($query) use ($website_id) {
  1288. // $query->whereNull('article_ignore.article_id')
  1289. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1290. // })
  1291. ->select(
  1292. 'article.id',
  1293. 'article.title',
  1294. 'article.author',
  1295. 'article.updated_at',
  1296. 'article.introduce',
  1297. 'article.islink',
  1298. 'article.linkurl',
  1299. 'article.copyfrom',
  1300. 'article.cat_arr_id',
  1301. 'article.catid',
  1302. 'article.level',
  1303. // 'article_ignore.is_ignore',
  1304. // 'article_ignore.c_show_time',
  1305. )
  1306. ->offset($data['placeid'])
  1307. ->limit($data['textnum'])
  1308. ->get()->all();
  1309. foreach ($result['text'] as $k => $v) {
  1310. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1311. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1312. }
  1313. }
  1314. if ($data['imgnum'] > 0) {
  1315. $query = clone $query;
  1316. if ($data['textnum'] == 0) {
  1317. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1318. $query->from('article_ignore')
  1319. ->where('website_id', $website_id);
  1320. }, 'article_ignore', function ($join) {
  1321. $join->on('article_ignore.article_id', '=', 'article.id');
  1322. })
  1323. ->where(function ($query) {
  1324. $query->whereNull('article_ignore.article_id')
  1325. ->orWhere(function ($subQuery) {
  1326. $subQuery->whereNotNull('article_ignore.article_id')
  1327. ->where('article_ignore.is_ignore', 0)
  1328. ->where(function ($subSubQuery) {
  1329. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1330. ->orWhereNull('article_ignore.c_show_time');
  1331. });
  1332. });
  1333. });
  1334. }
  1335. $result['img'] = $query
  1336. ->whereIn('catid', $categoryIds)
  1337. ->where('article.imgurl', '!=', '')
  1338. ->select(
  1339. 'article.id',
  1340. 'article.title',
  1341. 'article.imgurl',
  1342. 'article.author',
  1343. 'article.updated_at',
  1344. 'article.introduce',
  1345. 'article.islink',
  1346. 'article.linkurl',
  1347. 'article.copyfrom',
  1348. 'article.cat_arr_id',
  1349. 'article.catid',
  1350. 'article.level',
  1351. // 'article_ignore.is_ignore',
  1352. // 'article_ignore.c_show_time',
  1353. )
  1354. ->offset($data['placeid'])
  1355. ->limit($data['imgnum'])
  1356. ->get()->all();
  1357. foreach ($result['img'] as $k => $v) {
  1358. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1359. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1360. }
  1361. }
  1362. if (empty($result)) {
  1363. return Result::error("暂无相关资讯", 0);
  1364. }
  1365. return Result::success($result);
  1366. }
  1367. /**
  1368. * 获取模块新闻
  1369. * @param array $data
  1370. * @return array
  1371. */
  1372. public function getWebsiteModelArticles(array $data): array
  1373. {
  1374. $catid = $data['catid'];
  1375. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1376. $category = $category->toArray();
  1377. if (!empty($category)) {
  1378. $where = [
  1379. 'status' => 1,
  1380. 'catid' => $catid,
  1381. ];
  1382. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1383. // 1:文字新闻;2:轮播图;3:图文;
  1384. // 级别:0:未分类
  1385. // 3:推荐图片
  1386. if ($data['level'] == 1) {
  1387. $data['level'] = 0;
  1388. }
  1389. $result = Article::where($where)
  1390. ->where(function ($query) use ($data) {
  1391. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1392. ->orWhereNull("level")
  1393. ->orWhereRaw("level = '[]'");
  1394. })
  1395. ->leftJoinSub(function ($query) use ($data) {
  1396. $query->from('article_ignore')
  1397. ->where('website_id', $data['website_id']);
  1398. }, 'article_ignore', function ($join) {
  1399. $join->on('article_ignore.article_id', '=', 'article.id');
  1400. })
  1401. ->where(function ($query) {
  1402. $query->whereNull('article_ignore.article_id')
  1403. ->orWhere(function ($subQuery) {
  1404. $subQuery->whereNotNull('article_ignore.article_id')
  1405. ->where('article_ignore.is_ignore', 0)
  1406. ->where(function ($subSubQuery) {
  1407. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1408. ->orWhereNull('article_ignore.c_show_time');
  1409. });
  1410. });
  1411. })
  1412. // ->where(function ($query) use ($data) {
  1413. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1414. // ->orWhereNull("ignore_ids");
  1415. // })
  1416. ->orderBy("updated_at", "desc")
  1417. ->offset($placeid)
  1418. ->limit($data['pagesize'])
  1419. ->get();
  1420. if (empty($result)) {
  1421. return Result::error("此栏目暂无相关新闻", 0);
  1422. }
  1423. } else {
  1424. return Result::error("此网站暂无此栏目", 0);
  1425. }
  1426. return Result::success($result);
  1427. }
  1428. /**
  1429. *获取新闻列表
  1430. * @param array $data
  1431. * @return array
  1432. */
  1433. public function getWebsiteArticleList(array $data): array
  1434. {
  1435. // return Result::success($data);
  1436. $where[] = ['status', '=', 1];
  1437. $website_id = $data['website_id'];
  1438. $website = Website::where('id', $data['website_id'])->first();
  1439. if (empty($website)) {
  1440. return Result::error("网站不存在", 0);
  1441. }
  1442. // $website_column = $website['column'];
  1443. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1444. $website_column = json_decode($website['website_column_arr_id'], true);
  1445. }
  1446. $categorys = $this->processArticlePro($website_id);
  1447. $cat_1st_arr = $categorys['cat_1st_arr'];
  1448. $catiall = $categorys['catiall'];
  1449. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1450. // return Result::success($diff_pid_categoryIds);
  1451. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1452. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1453. }
  1454. if (isset($data['catid']) && !empty($data['catid'])) {
  1455. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1456. if (empty($category)) {
  1457. return Result::error("此网站暂无此栏目", 0);
  1458. }
  1459. array_push($where, ['catid', '=', $data['catid']]);
  1460. }
  1461. // return Result::success($where);
  1462. $query = Article::where($where)
  1463. ->leftJoinSub(function ($query) use ($website_id) {
  1464. $query->from('article_ignore')
  1465. ->where('website_id', $website_id);
  1466. }, 'article_ignore', function ($join) {
  1467. $join->on('article_ignore.article_id', '=', 'article.id');
  1468. })
  1469. ->where(function ($query) {
  1470. $query->whereNull('article_ignore.article_id')
  1471. ->orWhere(function ($subQuery) {
  1472. $subQuery->whereNotNull('article_ignore.article_id')
  1473. ->where('article_ignore.is_ignore', 0)
  1474. ->where(function ($subSubQuery) {
  1475. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1476. ->orWhereNull('article_ignore.c_show_time');
  1477. });
  1478. });
  1479. })
  1480. ->select(
  1481. 'article.id',
  1482. 'article.title',
  1483. 'article.imgurl',
  1484. 'article.author',
  1485. 'article.updated_at',
  1486. 'article.introduce',
  1487. 'article.islink',
  1488. 'article.linkurl',
  1489. 'article.copyfrom',
  1490. 'article.cat_arr_id',
  1491. 'article.catid'
  1492. );
  1493. $count = $query->count();
  1494. $rep = $query->orderBy("updated_at", "desc")
  1495. ->offset(($data['page'] - 1) * $data['pageSize'])
  1496. ->limit($data['pageSize'])
  1497. ->get()->all();
  1498. $categorys = $this->processArticlePro($website_id);
  1499. $cat_1st_arr = $categorys['cat_1st_arr'];
  1500. $catiall = $categorys['catiall'];
  1501. // $web['website_id'] = $data['website_id'];
  1502. foreach ($rep as $k => $v) {
  1503. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1504. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1505. }
  1506. // $rep = $this->processArticles($rep,$web);
  1507. $data = [
  1508. 'rows' => $rep,
  1509. 'count' => $count,
  1510. ];
  1511. if (empty($rep)) {
  1512. return Result::error("没有信息数据");
  1513. }
  1514. return Result::success($data);
  1515. }
  1516. /**
  1517. * 前端-获取新闻详情
  1518. * @param array $data
  1519. * @return array
  1520. */
  1521. public function selectWebsiteArticleInfo(array $data): array
  1522. {
  1523. $where = [
  1524. 'article.id' => $data['id'],
  1525. 'article.status' => 1,
  1526. ];
  1527. $result = Article::where($where)
  1528. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1529. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1530. // ->where(function ($query) use ($data) {
  1531. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1532. // ->orWhereNull("ignore_ids");
  1533. // })
  1534. ->leftJoinSub(function ($query) use ($data) {
  1535. $query->from('article_ignore')
  1536. ->where('website_id', $data['website_id']);
  1537. }, 'article_ignore', function ($join) {
  1538. $join->on('article_ignore.article_id', '=', 'article.id');
  1539. })
  1540. ->where(function ($query) {
  1541. $query->whereNull('article_ignore.article_id')
  1542. ->orWhere(function ($subQuery) {
  1543. $subQuery->whereNotNull('article_ignore.article_id')
  1544. ->where('article_ignore.is_ignore', 0)
  1545. ->where(function ($subSubQuery) {
  1546. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1547. ->orWhereNull('article_ignore.c_show_time');
  1548. });
  1549. });
  1550. })
  1551. ->select(
  1552. 'article.*',
  1553. 'article_data.content',
  1554. 'article_data.article_id',
  1555. 'article_extend.website_url',
  1556. 'article_extend.email',
  1557. 'article_extend.contacts',
  1558. 'article_extend.contacts_mobile',
  1559. 'article_extend.contacts_address',
  1560. 'article_extend.zip_code',
  1561. 'article_extend.enterprise_name'
  1562. )
  1563. ->first();
  1564. if (empty($result)) {
  1565. return Result::error("暂无此新闻!", 0);
  1566. }
  1567. if (!empty($result['publiced_at'])) {
  1568. $result['updated_at'] = $result['publiced_at'];
  1569. }
  1570. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1571. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1572. ->where('website_category.website_id', $data['website_id'])
  1573. ->where(['website_category.category_id' => $result['catid']])
  1574. ->first();
  1575. if (empty($category)) {
  1576. return Result::error("查询失败", 0);
  1577. }
  1578. //手动推荐文章
  1579. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1580. if (empty($commend_ids)) {
  1581. $commendArticle = [];
  1582. } else {
  1583. //去除不存在的文章ID
  1584. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1585. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1586. ->leftJoinSub(function ($query) use ($data) {
  1587. $query->from('article_ignore')
  1588. ->where('website_id', $data['website_id']);
  1589. }, 'article_ignore', function ($join) {
  1590. $join->on('article_ignore.article_id', '=', 'article.id');
  1591. })
  1592. ->where(function ($query) {
  1593. $query->whereNull('article_ignore.article_id')
  1594. ->orWhere(function ($subQuery) {
  1595. $subQuery->whereNotNull('article_ignore.article_id')
  1596. ->where('article_ignore.is_ignore', 0)
  1597. ->where(function ($subSubQuery) {
  1598. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1599. ->orWhereNull('article_ignore.c_show_time');
  1600. });
  1601. });
  1602. })
  1603. ->where('article.status', 1)
  1604. ->where('website_category.website_id', $data['website_id'])
  1605. ->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')
  1606. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1607. // ->orderBy('article.updated_at', 'desc')
  1608. ->limit(5)
  1609. ->get();
  1610. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1611. foreach ($commendArticle as $k => $v) {
  1612. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1613. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1614. $cat_arr_id = array_unique($cat_arr_id);
  1615. // 从website_category取出alias_pinyin
  1616. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1617. ->whereIn('category_id', $cat_arr_id)
  1618. ->pluck('alias_pinyin', 'category_id')
  1619. ->toArray();
  1620. // 将cat_arr_id的json转成路径/隔开
  1621. $path_parts = [];
  1622. foreach ($cat_arr_id as $cat_id) {
  1623. if (isset($cat_arr[$cat_id])) {
  1624. $path_parts[] = $cat_arr[$cat_id];
  1625. }
  1626. }
  1627. $v->alias_pinyin = implode('/', $path_parts);
  1628. } else {
  1629. $v->alias_pinyin = '';
  1630. }
  1631. }
  1632. }
  1633. $result['category_id'] = $category['category_id'];
  1634. $result['cat_name'] = $category['alias'];
  1635. $result['website_name'] = $category['website_name'] ?? "";
  1636. $result['suffix'] = $category['suffix'] ?? "";
  1637. $result['commendArticle'] = $commendArticle;
  1638. $result['commend_ids'] = $commend_ids;
  1639. return Result::success($result);
  1640. }
  1641. /**
  1642. * 前端-获取网站调查问卷
  1643. * @param array $data
  1644. * @return array
  1645. */
  1646. public function getWebsiteSurvey(array $data): array
  1647. {
  1648. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1649. $website = Website::where('id', $data['website_id'])->first();
  1650. if (empty($website)) {
  1651. return Result::error("暂无此网站", 0);
  1652. }
  1653. }
  1654. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1655. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1656. if (empty($article)) {
  1657. return Result::error("暂无此文章", 0);
  1658. }
  1659. // return Result::error($data,0);
  1660. $where['art_id'] = $data['art_id'];
  1661. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1662. } else {
  1663. $survey = Article::where(function ($query) {
  1664. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1665. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1666. })
  1667. ->where('status', 1)
  1668. ->where('is_survey', 1)
  1669. ->select('survey_id')
  1670. ->orderBy('updated_at', 'desc')
  1671. ->first();
  1672. if (empty($survey)) {
  1673. return Result::error("暂无调查问卷", 0);
  1674. }
  1675. $where['sur_id'] = $survey['survey_id'];
  1676. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1677. }
  1678. // return Result::success($where);
  1679. $result = ArticleSurvey::where($where)
  1680. ->where(function ($query) {
  1681. $query->where('is_other', 0)
  1682. ->orWhere(function ($subQuery) {
  1683. $subQuery->where('is_other', 1)
  1684. ->where('other_id', 0);
  1685. });
  1686. })
  1687. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1688. ->select('article_survey.*', 'article.survey_type')
  1689. ->get()->all();
  1690. if (empty($result)) {
  1691. return Result::error("此文章暂无调查问卷", 0);
  1692. }
  1693. return Result::success($result);
  1694. }
  1695. /**
  1696. * 前端-添加网站调查问卷选项
  1697. * @param array $data
  1698. * @return array
  1699. */
  1700. public function addWebsiteSurveyOption(array $data): array
  1701. {
  1702. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1703. $website = Website::where('id', $data['website_id'])->first();
  1704. if (empty($website)) {
  1705. return Result::error("暂无此网站", 0);
  1706. }
  1707. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1708. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1709. if (empty($survey)) {
  1710. return Result::error("此调查问卷不可添加选项", 0);
  1711. }
  1712. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1713. $choice = [
  1714. 'art_id' => $survey['art_id'],
  1715. 'website_id' => $data['website_id'],
  1716. 'survey_name' => $survey['survey_name'],
  1717. 'choice_name' => $data['choice_name'],
  1718. 'sur_id' => $survey['sur_id'],
  1719. 'is_other' => 1,
  1720. 'other_id' => $survey['id'],
  1721. ];
  1722. $result = ArticleSurvey::insertGetId($choice);
  1723. if (empty($result)) {
  1724. return Result::error("添加失败", 0);
  1725. }
  1726. return Result::success($result);
  1727. }
  1728. }
  1729. return Result::error("添加失败", 0);
  1730. }
  1731. return Result::error("添加失败", 0);
  1732. }
  1733. /**
  1734. * 前端-调查问卷投票
  1735. * @param array $data
  1736. * @return array
  1737. */
  1738. public function addWebsiteSurveyVote(array $data): array
  1739. {
  1740. // return Result::success($data);
  1741. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1742. $website = Website::where('id', $data['website_id'])->first();
  1743. if (empty($website)) {
  1744. return Result::error("暂无此网站", 0);
  1745. }
  1746. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1747. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1748. // return Result::success($survey);
  1749. if (empty($is_survey)) {
  1750. return Result::error("此调查问卷不存在", 0);
  1751. }
  1752. // return Result::success($survey);
  1753. // 调查问卷类型
  1754. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1755. //多选 若是json型则转化成数组类型
  1756. if (strpos($data['choice_id'], '[') === 0) {
  1757. $data['choice_id'] = json_decode($data['choice_id'], true);
  1758. } else {
  1759. // 单选 也转换成数组
  1760. $data['choice_id'] = [$data['choice_id']];
  1761. }
  1762. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1763. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1764. // ->where('website_id',$data['website_id'])
  1765. ->where('is_other', 1)
  1766. ->where('other_id', 0)
  1767. ->first();
  1768. if (!empty($other)) {
  1769. return Result::error("请选择已有的选项!", 0);
  1770. }
  1771. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1772. // ->where('website_id',$data['website_id'])
  1773. ->where('is_other', 1)
  1774. ->where('other_id', '!=', 0)
  1775. ->first();
  1776. // return Result::success($choice['other']);
  1777. $choice_id = $data['choice_id'];
  1778. if (!empty($choice['other'])) {
  1779. // array_push($data['choice_id'],$choice['other']['other_id']);
  1780. if (!empty($choice_id)) {
  1781. $key = array_search($choice['other']['id'], $choice_id);
  1782. if ($key !== false) {
  1783. unset($choice_id[$key]);
  1784. $choice_id = array_values($choice_id);
  1785. }
  1786. array_push($choice_id, $choice['other']['other_id']);
  1787. } else {
  1788. $choice_id[0] = $choice['other']['other_id'];
  1789. }
  1790. array_push($data['choice_id'], $choice['other']['other_id']);
  1791. }
  1792. // return Result::success($data);
  1793. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1794. // ->where('website_id',$data['website_id'])
  1795. ->increment('results', 1);
  1796. if (empty($choice)) {
  1797. return Result::error("请选择已有的选项!", 0);
  1798. }
  1799. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1800. // ->where('website_id',$data['website_id'])
  1801. ->where('other_id', 0)
  1802. ->get();
  1803. $survey['choice'] = $choice_id;
  1804. return Result::success($survey);
  1805. }
  1806. return Result::error("参数必填!");
  1807. }
  1808. return Result::error("此调查问卷不存在", 0);
  1809. }
  1810. return Result::error("参数必填!");
  1811. }
  1812. /**
  1813. * 后端-获取网站调查问卷列表
  1814. * @param array $data
  1815. * @return array
  1816. */
  1817. public function getSurveyList(array $data): array
  1818. {
  1819. $where = [];
  1820. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1821. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1822. }
  1823. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1824. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1825. }
  1826. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1827. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1828. }
  1829. // return Result::success($where);
  1830. if (!empty($where)) {
  1831. $query = Article::where($where)->where(function ($q) {
  1832. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1833. });
  1834. } else {
  1835. $query = Article::where(function ($q) {
  1836. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1837. });
  1838. }
  1839. $count = $query->count();
  1840. $survey = $query->orderByDesc('id')
  1841. ->limit($data['pageSize'])
  1842. ->offset(($data['page'] - 1) * $data['pageSize'])
  1843. ->get();
  1844. if (empty($survey->toArray())) {
  1845. return Result::error("暂无调查问卷!", 0);
  1846. }
  1847. $result = [
  1848. 'rows' => $survey,
  1849. 'count' => $count,
  1850. ];
  1851. return Result::success($result);
  1852. }
  1853. /**
  1854. * 后端-获取网站调查问卷详情
  1855. * @param array $data
  1856. * @return array
  1857. */
  1858. public function getSurveyInfo(array $data): array
  1859. {
  1860. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1861. $where = ['sur_id' => $data['sur_id']];
  1862. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1863. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1864. ->select('article_survey.*', 'article.survey_type')
  1865. ->get()->all();
  1866. if (empty($choose)) {
  1867. return Result::error("此调查问卷不存在", 0);
  1868. }
  1869. $resultsArray = array_column($choose, 'results');
  1870. $total = array_sum($resultsArray);
  1871. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1872. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1873. // $total = 0;
  1874. if (!empty($other)) {
  1875. $total = $total + $other['results'];
  1876. $other['choice_name'] = '(其他)';
  1877. if (!empty($others)) {
  1878. $other['hasChildren'] = true;
  1879. // array_push($other,['hasChildren','=',true]);
  1880. $other['children'] = $others;
  1881. $other_choices = [$other->toArray()];
  1882. $mer_choice = array_merge($choose, $other_choices);
  1883. $value_choice = array_values($mer_choice);
  1884. } else {
  1885. // return Result::error('1111');
  1886. $other_choices = [$other->toArray()];
  1887. $other_choices = array_merge($choose, $other_choices);
  1888. $value_choice = array_values($other_choices);
  1889. // return Result::success($result);
  1890. }
  1891. } else {
  1892. $value_choice = $choose;
  1893. }
  1894. $result = [
  1895. 'choose' => $value_choice,
  1896. 'total' => $total,
  1897. ];
  1898. }
  1899. return Result::success($result);
  1900. }
  1901. /**
  1902. * 前端-搜索新闻列表
  1903. * @param array $data
  1904. * @return array
  1905. */
  1906. public function selectWebsiteArticle(array $data): array
  1907. {
  1908. $website = Website::where('id', $data['website_id'])->first();
  1909. if (empty($website)) {
  1910. return Result::error("网站不存在", 0);
  1911. }
  1912. // $website_column = $website['column'];
  1913. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1914. $website_column = json_decode($website['website_column_arr_id'], true);
  1915. }
  1916. $website_id = $data['website_id'];
  1917. $categorys = $this->processArticlePro($website_id);
  1918. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1919. // return Result::success($diff_pid_categoryIds);
  1920. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1921. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1922. }
  1923. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1924. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1925. $catiall = $categorys['catiall'];
  1926. $categoryIds = $categorys['categoryIds'];
  1927. // return Result::success($categoryIds);
  1928. $query = Article::where('status', 1)
  1929. ->whereIn('catid', $categoryIds)
  1930. ->leftJoinSub(function ($query) use ($website_id) {
  1931. $query->from('article_ignore')
  1932. ->where('website_id', $website_id);
  1933. }, 'article_ignore', function ($join) {
  1934. $join->on('article_ignore.article_id', '=', 'article.id');
  1935. })
  1936. ->where(function ($query) {
  1937. $query->whereNull('article_ignore.article_id')
  1938. ->orWhere(function ($subQuery) {
  1939. $subQuery->whereNotNull('article_ignore.article_id')
  1940. ->where('article_ignore.is_ignore', 0)
  1941. ->where(function ($subSubQuery) {
  1942. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1943. ->orWhereNull('article_ignore.c_show_time');
  1944. });
  1945. });
  1946. });
  1947. // ->get()->all();
  1948. // return Result::success($query);
  1949. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1950. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1951. }
  1952. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1953. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1954. }
  1955. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1956. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1957. }
  1958. // 计算总数
  1959. $count = $query->count();
  1960. // return Result::success($count);
  1961. // 分页查询
  1962. $articles = $query
  1963. ->select(
  1964. 'article.id',
  1965. 'article.title',
  1966. 'article.imgurl',
  1967. 'article.author',
  1968. 'article.updated_at',
  1969. 'article.introduce',
  1970. 'article.islink',
  1971. 'article.linkurl',
  1972. 'article.copyfrom',
  1973. 'article.cat_arr_id',
  1974. 'article.catid',
  1975. 'article.department_arr_id',
  1976. 'article.city_arr_id',
  1977. // 'article_ignore.c_show_time',
  1978. // 'article_ignore.is_ignore'
  1979. )
  1980. ->orderBy("updated_at", "desc")
  1981. ->offset(($data['page'] - 1) * $data['pageSize'])
  1982. ->limit($data['pageSize'])
  1983. ->get();
  1984. // return Result::success($articles);
  1985. foreach ($articles as $k => $v) {
  1986. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1987. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1988. }
  1989. if (empty($articles)) {
  1990. return Result::error("没有符合条件的资讯数据");
  1991. }
  1992. $result = [
  1993. 'rows' => $articles,
  1994. 'count' => $count,
  1995. ];
  1996. return Result::success($result);
  1997. }
  1998. /**
  1999. * 模块新闻加强版
  2000. * @param array $data
  2001. * @return array
  2002. */
  2003. public function getWebsiteCatidArticle(array $data): array
  2004. {
  2005. $where = [
  2006. 'website_category.category_id' => $data['catid'],
  2007. 'website_category.website_id' => $data['website_id'],
  2008. ];
  2009. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  2010. $child_catnum = $data['child_catnum'] ?? 1;
  2011. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  2012. $childCategoryIds = array_column($category['child'], 'category_id');
  2013. if (empty($childCategoryIds)) {
  2014. return Result::error("暂无子栏目", 0);
  2015. }
  2016. $imgArticles = [];
  2017. $textArticles = [];
  2018. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2019. // 初始化子分类图片新闻和文字新闻数组
  2020. // 查询所有子级栏目的图文新闻
  2021. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2022. ->where(function ($query) use ($data) {
  2023. $query->where(function ($subQuery) use ($data) {
  2024. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2025. })->orWhereNull("ignore_ids");
  2026. })
  2027. ->where('status', 1)
  2028. ->where('imgurl', '!=', '')
  2029. ->select('*')
  2030. ->orderBy('updated_at', 'desc')
  2031. ->limit($data['child_imgnum'])
  2032. ->get();
  2033. }
  2034. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2035. // 查询所有子级栏目的文字新闻
  2036. $textArticles = Article::where('catid', $childCategoryIds[0])
  2037. ->where('status', 1)
  2038. ->where(function ($query) use ($data) {
  2039. $query->where(function ($subQuery) use ($data) {
  2040. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2041. })->orWhereNull("ignore_ids");
  2042. })
  2043. ->select('*')
  2044. ->orderBy('updated_at', 'desc')
  2045. ->limit($data['child_textnum'])
  2046. ->get();
  2047. }
  2048. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2049. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2050. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2051. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2052. return $child;
  2053. }, $category['child']);
  2054. }
  2055. // }
  2056. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2057. $category['img'] = WebsiteCategory::where($where)
  2058. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2059. ->where('article.status', 1)
  2060. ->where('article.imgurl', '!=', '')
  2061. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2062. ->orderBy('article.updated_at', 'desc')
  2063. ->limit($data['img_num'])
  2064. ->get();
  2065. }
  2066. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2067. $category['text'] = WebsiteCategory::where($where)
  2068. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2069. ->where('article.status', 1)
  2070. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2071. ->orderBy('article.updated_at', 'desc')
  2072. ->limit($data['text_num'])
  2073. ->get();
  2074. }
  2075. // $category = $category->get();
  2076. if (empty($category)) {
  2077. return Result::error("查询失败", 0);
  2078. }
  2079. return Result::success($category);
  2080. }
  2081. /**
  2082. * 模块新闻加强plus版
  2083. * @param array $data
  2084. * @return array
  2085. */
  2086. public function getWebsiteAllArticle(array $data): array
  2087. {
  2088. // return Result::success($data);
  2089. $time1 = microtime(true);
  2090. $wetbsite_id = $data['website_id'] ?? 2;
  2091. $data = json_decode($data['id'], true);
  2092. $website = Website::where('id', $wetbsite_id)->first();
  2093. if (empty($website)) {
  2094. return Result::error("网站不存在", 0);
  2095. }
  2096. // return Result::success($website);
  2097. $website_column = $website['website_column_arr_id'] ?? '[]';
  2098. $website_column = json_decode($website_column, true);
  2099. $categorys = $this->processArticlePro($wetbsite_id);
  2100. $cat_1st_arr = $categorys['cat_1st_arr'];
  2101. $catiall = $categorys['catiall'];
  2102. // return Result::success($catiall);
  2103. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2104. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2105. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2106. }
  2107. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2108. // return Result::success($categorys);
  2109. $parent_category = array_column($data, 'parent');
  2110. $parent_cat = [];
  2111. $child_category = array_column($data, 'child');
  2112. if (!empty($parent_category)) {
  2113. foreach ($parent_category as $key => $value) {
  2114. $arr = array_map('intval', explode(',', $value));
  2115. $parent_cat[$key] = $arr[0] ?? 0;
  2116. $parent_category = $arr[0] ?? 0;
  2117. $article_imgnum = $arr[1] ?? 0;
  2118. $article_textnum = $arr[2] ?? 0;
  2119. if ($parent_category != 0) {
  2120. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2121. // return Result::success($category_arr);
  2122. if ($article_imgnum != 0) {
  2123. $img_article = Article::whereIn('catid', $category_arr)
  2124. ->where('status', 1)
  2125. ->where('imgurl', '!=', '')
  2126. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2127. $query->from('article_ignore')
  2128. ->where('website_id', $wetbsite_id);
  2129. }, 'article_ignore', function ($join) {
  2130. $join->on('article_ignore.article_id', '=', 'article.id');
  2131. })
  2132. ->where(function ($query) {
  2133. $query->whereNull('article_ignore.article_id')
  2134. ->orWhere(function ($subQuery) {
  2135. $subQuery->whereNotNull('article_ignore.article_id')
  2136. ->where('article_ignore.is_ignore', 0)
  2137. ->where(function ($subSubQuery) {
  2138. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2139. ->orWhereNull('article_ignore.c_show_time');
  2140. });
  2141. });
  2142. })
  2143. ->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')
  2144. ->orderBy('updated_at', 'desc')
  2145. ->limit($article_imgnum)
  2146. ->get()->all();
  2147. foreach ($img_article as $k => $v) {
  2148. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2149. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2150. }
  2151. } else {
  2152. $img_article = [];
  2153. }
  2154. if ($article_textnum != 0) {
  2155. $text_article = Article::whereIn('catid', $category_arr)
  2156. ->where('status', 1)
  2157. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2158. $query->from('article_ignore')
  2159. ->where('website_id', $wetbsite_id);
  2160. }, 'article_ignore', function ($join) {
  2161. $join->on('article_ignore.article_id', '=', 'article.id');
  2162. })
  2163. ->where(function ($query) {
  2164. $query->whereNull('article_ignore.article_id')
  2165. ->orWhere(function ($subQuery) {
  2166. $subQuery->whereNotNull('article_ignore.article_id')
  2167. ->where('article_ignore.is_ignore', 0)
  2168. ->where(function ($subSubQuery) {
  2169. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2170. ->orWhereNull('article_ignore.c_show_time');
  2171. });
  2172. });
  2173. })
  2174. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2175. ->orderBy('updated_at', 'desc')
  2176. ->limit($article_textnum)
  2177. ->get()->all();
  2178. foreach ($text_article as $k => $v) {
  2179. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2180. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2181. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2182. }
  2183. } else {
  2184. $text_article = [];
  2185. }
  2186. $catiall[$parent_category]['imgnum'] = $img_article;
  2187. $catiall[$parent_category]['textnum'] = $text_article;
  2188. $parent[$key] = $catiall[$parent_category];
  2189. } else {
  2190. $parent[$key] = '';
  2191. }
  2192. }
  2193. }
  2194. if (!empty($child_category)) {
  2195. foreach ($child_category as $key => $value) {
  2196. $arr = array_map('intval', explode(',', $value));
  2197. $parent_category = $parent_cat[$key];
  2198. $child_category = $arr[0] ?? 0;
  2199. $article_imgnum = $arr[1] ?? 0;
  2200. $article_textnum = $arr[2] ?? 0;
  2201. if ($child_category != 0) {
  2202. $all_childcat = $cat_1st_arr[$parent_category];
  2203. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2204. // 从 $websiteInfoIndexed 中获取对应的数据
  2205. $info = $websiteInfoIndexed[$v];
  2206. // 返回一个包含所需信息的数组
  2207. return [
  2208. 'alias' => $info->alias,
  2209. 'category_id' => $info->category_id,
  2210. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2211. 'pid' => $info->pid,
  2212. 'type' => $info->type,
  2213. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2214. 'pinyin' => $info->pinyin,
  2215. ];
  2216. }, $all_childcat);
  2217. if ($article_imgnum != 0) {
  2218. $img_article = Article::where('catid', $child_category)
  2219. ->where('status', 1)
  2220. ->where('imgurl', '!=', '')
  2221. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2222. $query->from('article_ignore')
  2223. ->where('website_id', $wetbsite_id);
  2224. }, 'article_ignore', function ($join) {
  2225. $join->on('article_ignore.article_id', '=', 'article.id');
  2226. })
  2227. ->where(function ($query) {
  2228. $query->whereNull('article_ignore.article_id')
  2229. ->orWhere(function ($subQuery) {
  2230. $subQuery->whereNotNull('article_ignore.article_id')
  2231. ->where('article_ignore.is_ignore', 0)
  2232. ->where(function ($subSubQuery) {
  2233. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2234. ->orWhereNull('article_ignore.c_show_time');
  2235. });
  2236. });
  2237. })
  2238. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2239. ->orderBy('updated_at', 'desc')
  2240. ->limit($article_imgnum)
  2241. ->get()->all();
  2242. foreach ($img_article as $k => $v) {
  2243. // var_dump($v);
  2244. // var_dump($k);
  2245. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2246. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2247. }
  2248. } else {
  2249. $img_article = [];
  2250. }
  2251. if ($article_textnum != 0) {
  2252. $text_article = Article::where('catid', $child_category)
  2253. ->where('status', 1)
  2254. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2255. $query->from('article_ignore')
  2256. ->where('website_id', $wetbsite_id);
  2257. }, 'article_ignore', function ($join) {
  2258. $join->on('article_ignore.article_id', '=', 'article.id');
  2259. })
  2260. ->where(function ($query) {
  2261. $query->whereNull('article_ignore.article_id')
  2262. ->orWhere(function ($subQuery) {
  2263. $subQuery->whereNotNull('article_ignore.article_id')
  2264. ->where('article_ignore.is_ignore', 0)
  2265. ->where(function ($subSubQuery) {
  2266. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2267. ->orWhereNull('article_ignore.c_show_time');
  2268. });
  2269. });
  2270. })
  2271. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2272. ->orderBy('updated_at', 'desc')
  2273. ->limit($article_textnum)
  2274. ->get()->all();
  2275. foreach ($text_article as $k => $v) {
  2276. // var_dump($v);
  2277. // var_dump($k);
  2278. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2279. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2280. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2281. }
  2282. } else {
  2283. $text_article = [];
  2284. }
  2285. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2286. $catiall[$child_category]['imgnum'] = $img_article;
  2287. $catiall[$child_category]['textnum'] = $text_article;
  2288. $child[$key] = $catiall[$child_category];
  2289. // var_dump($pids);
  2290. } else {
  2291. $child[$key] = '';
  2292. }
  2293. }
  2294. }
  2295. foreach ($parent as $key => $value) {
  2296. $result[$key] = $value;
  2297. if (!empty($child[$key])) {
  2298. // var_dump($child[$key]);
  2299. $result[$key]['child'] = $child[$key];
  2300. // $value[$key]['child'] = $child[$key];
  2301. } else {
  2302. $result[$key]['child'] = [
  2303. "alias" => null,
  2304. "category_id" => null,
  2305. "type" => null,
  2306. "pinyin" => null,
  2307. "all_childcat" => [],
  2308. "imgnum" => [],
  2309. "textnum" => []
  2310. ];
  2311. }
  2312. }
  2313. return Result::success($result);
  2314. }
  2315. /**
  2316. * 辅助方法:获取文章列表
  2317. */
  2318. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2319. {
  2320. sleep(1);
  2321. $query = Article::where('article.status', 1)
  2322. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2323. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2324. ->where(function ($query) use ($website) {
  2325. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2326. })
  2327. ->leftJoin('website_category', function ($join) use ($website) {
  2328. $join->on('article.catid', '=', 'website_category.category_id')
  2329. ->where('website_category.website_id', '=', $website['website_id']);
  2330. })
  2331. ->select(
  2332. 'article.id',
  2333. 'article.title',
  2334. 'article.imgurl',
  2335. 'article.author',
  2336. 'article.updated_at',
  2337. 'article.introduce',
  2338. 'article.islink',
  2339. 'article.linkurl',
  2340. 'article.copyfrom',
  2341. 'article.cat_arr_id',
  2342. 'article.catid',
  2343. 'website_category.alias as category_name'
  2344. )
  2345. ->orderBy('updated_at', 'desc')
  2346. ->limit($limit);
  2347. // 如果是图片文章,添加图片URL条件
  2348. if ($isImageArticle) {
  2349. $query->where('imgurl', '!=', '');
  2350. } else {
  2351. // 文字文章不需要imgurl字段
  2352. $query->addSelect('article.introduce');
  2353. }
  2354. $articles = $query->get();
  2355. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2356. }
  2357. /**
  2358. * 乡村网-获取特殊新闻模块
  2359. * @param array $data
  2360. * @return array
  2361. */
  2362. public function getWebsiteArticles(array $data): array
  2363. {
  2364. $website_id = $data['website_id'];
  2365. $website = Website::where('id', $website_id)->first();
  2366. if (empty($website)) {
  2367. return Result::error("网站不存在", 0);
  2368. }
  2369. // return Result::success($website);
  2370. $website_column = $website['website_column_arr_id'] ?? '[]';
  2371. $website_column = json_decode($website_column, true);
  2372. $catids = json_decode($data['id'], true);
  2373. $parent_category = array_column($catids, 'parent');
  2374. if (!empty($parent_category) && is_array($parent_category)) {
  2375. $categorys = $this->processArticlePro($website_id);
  2376. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2377. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2378. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2379. }
  2380. $catiall = $categorys['catiall'];
  2381. $cat_1st_arr = $categorys['cat_1st_arr'];
  2382. // return Result::success($categorys);
  2383. foreach ($parent_category as $key => $value) {
  2384. $arr = array_map('intval', explode(',', $value));
  2385. $parent_category = $arr[0] ?? 0;
  2386. $article_imgnum = $arr[1] ?? 0;
  2387. $article_textnum = $arr[2] ?? 0;
  2388. if ($parent_category != 0) {
  2389. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2390. // return Result::success($category_arr);
  2391. if ($article_imgnum != 0) {
  2392. $img_article = Article::whereIn('article.catid', $category_arr)
  2393. ->where('article.status', 1)
  2394. ->where('article.imgurl', '!=', '')
  2395. ->leftJoinSub(function ($query) use ($website_id) {
  2396. $query->from('article_ignore')
  2397. ->where('website_id', $website_id);
  2398. }, 'article_ignore', function ($join) {
  2399. $join->on('article_ignore.article_id', '=', 'article.id');
  2400. })
  2401. ->where(function ($query) {
  2402. $query->whereNull('article_ignore.article_id')
  2403. ->orWhere(function ($subQuery) {
  2404. $subQuery->whereNotNull('article_ignore.article_id')
  2405. ->where('article_ignore.is_ignore', 0)
  2406. ->where(function ($subSubQuery) {
  2407. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2408. ->orWhereNull('article_ignore.c_show_time');
  2409. });
  2410. });
  2411. })
  2412. ->select(
  2413. 'article.id',
  2414. 'article.title',
  2415. 'article.imgurl',
  2416. 'article.author',
  2417. 'article.updated_at',
  2418. 'article.introduce',
  2419. 'article.islink',
  2420. 'article.linkurl',
  2421. 'article.copyfrom',
  2422. 'article.cat_arr_id',
  2423. 'article.catid as category_id'
  2424. )
  2425. ->orderBy('updated_at', 'desc')
  2426. ->limit($article_imgnum)
  2427. ->get()->all();
  2428. foreach ($img_article as $k => $v) {
  2429. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2430. // return Result::success($v);
  2431. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2432. }
  2433. } else {
  2434. $img_article = [];
  2435. }
  2436. if ($article_textnum != 0) {
  2437. $text_article = Article::whereIn('article.catid', $category_arr)
  2438. ->where('article.status', 1)
  2439. ->leftJoinSub(function ($query) use ($website_id) {
  2440. $query->from('article_ignore')
  2441. ->where('website_id', $website_id);
  2442. }, 'article_ignore', function ($join) {
  2443. $join->on('article_ignore.article_id', '=', 'article.id');
  2444. })
  2445. ->where(function ($query) {
  2446. $query->whereNull('article_ignore.article_id')
  2447. ->orWhere(function ($subQuery) {
  2448. $subQuery->whereNotNull('article_ignore.article_id')
  2449. ->where('article_ignore.is_ignore', 0)
  2450. ->where(function ($subSubQuery) {
  2451. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2452. ->orWhereNull('article_ignore.c_show_time');
  2453. });
  2454. });
  2455. })
  2456. ->select(
  2457. 'article.id',
  2458. 'article.title',
  2459. 'article.author',
  2460. 'article.updated_at',
  2461. 'article.introduce',
  2462. 'article.islink',
  2463. 'article.linkurl',
  2464. 'article.copyfrom',
  2465. 'article.cat_arr_id',
  2466. 'article.catid as category_id'
  2467. )
  2468. ->orderBy('updated_at', 'desc')
  2469. ->limit($article_textnum)
  2470. ->get()->all();
  2471. foreach ($text_article as $k => $v) {
  2472. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2473. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2474. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2475. }
  2476. } else {
  2477. $text_article = [];
  2478. }
  2479. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2480. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2481. $parent[$key] = $catiall[$parent_category];
  2482. } else {
  2483. $parent[$key] = [];
  2484. }
  2485. }
  2486. }
  2487. return Result::success($parent);
  2488. }
  2489. // 封装处理商品的路由问题
  2490. function processGoods($goods, $data)
  2491. {
  2492. return $goods->map(function ($good) use ($data) {
  2493. $catid = $good->catid ?? 0;
  2494. // $pinyin = '';
  2495. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2496. if (!empty($category->pid) && $category->pid != 0) {
  2497. $level = json_decode($category->category_arr_id, true);
  2498. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2499. ->whereIn('category_id', $level)
  2500. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2501. ->get(['aLIas_pinyin'])
  2502. ->pluck('aLIas_pinyin')
  2503. ->implode('/');
  2504. } else {
  2505. $pinyin = $category->aLIas_pinyin ?? '';
  2506. }
  2507. if (isset($good->city_id) && !empty($good->city_id)) {
  2508. $city = District::where('id', $good->city_id)->first(['name']);
  2509. $good->city_name = $city->name ?? '';
  2510. }
  2511. // 解析imgurl JSON并取第一条数据
  2512. $imgUrls = json_decode($good->imgurl, true);
  2513. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2514. $good->pinyin = $pinyin;
  2515. return $good;
  2516. });
  2517. }
  2518. /**
  2519. * 获取商城首页-根据栏目id
  2520. * @param array $data
  2521. * @return array
  2522. * */
  2523. function getWebsiteCatidshop(array $data): array
  2524. {
  2525. $input['catid'] = $data['catid'];
  2526. $input['website_id'] = $data['website_id'];
  2527. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2528. $result = array_map(function ($item) use ($input) {
  2529. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2530. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2531. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2532. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2533. if (empty($category) || $category->type != 2) {
  2534. return Result::error("暂无此栏目", 0);
  2535. } else {
  2536. $website['website_id'] = $input['website_id'];
  2537. $goods = Good::where('good.status', 2)
  2538. ->where('good.website_id', $website['website_id'])
  2539. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2540. ->select(
  2541. 'good.id',
  2542. 'good.name',
  2543. 'good.imgurl',
  2544. 'good.description',
  2545. 'good.updated_at',
  2546. 'good.catid',
  2547. 'good.type_id',
  2548. 'good.price',
  2549. 'good.com',
  2550. 'good.level',
  2551. 'good.unit'
  2552. )
  2553. ->orderBy('updated_at', 'desc')
  2554. ->offset($goodStart)
  2555. ->limit($goodNum);
  2556. $all_goods = $goods->get();
  2557. $all_goods = $this->processGoods($all_goods, $website);
  2558. }
  2559. return $all_goods ?? [];
  2560. }
  2561. }, $data);
  2562. return Result::success($result);
  2563. }
  2564. /**
  2565. * 获取商品模块
  2566. * @param array $data
  2567. * @return array
  2568. * */
  2569. public function getWebsiteshop(array $data): array
  2570. {
  2571. $input['id'] = $data['id'];
  2572. $input['website_id'] = $data['website_id'];
  2573. $catid = $data['catid'];
  2574. $data = json_decode($input['id'] ?? '', true) ?? [];
  2575. $result['goods'] = array_map(function ($item) use ($input) {
  2576. // 检查parent元素是否存在且不是undefined
  2577. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2578. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2579. $website = $input['website_id'];
  2580. $query = Good::where('good.status', 2)
  2581. ->where('good.website_id', $website);
  2582. switch ($Levelid) {
  2583. case 1:
  2584. case 2:
  2585. case 3:
  2586. $goods = $query->where(function ($q) use ($Levelid) {
  2587. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2588. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2589. });
  2590. break;
  2591. case 4:
  2592. $goods = $query;
  2593. break;
  2594. case 5:
  2595. $goods = $query->where('type_id', 1);
  2596. break;
  2597. case 6:
  2598. $goods = $query->where('type_id', 2);
  2599. break;
  2600. default:
  2601. return [];
  2602. }
  2603. $all_goods = $goods
  2604. ->select(
  2605. 'good.id',
  2606. 'good.name',
  2607. 'good.imgurl',
  2608. 'good.description',
  2609. 'good.updated_at',
  2610. 'good.catid',
  2611. 'good.type_id',
  2612. 'good.price',
  2613. 'good.level',
  2614. 'good.website_id'
  2615. )
  2616. ->orderBy('updated_at', 'desc')
  2617. ->offset($goodStart)
  2618. ->limit($goodNum)
  2619. ->get();
  2620. $web['website_id'] = $website;
  2621. $all_goods = $this->processGoods($all_goods, $web);
  2622. }
  2623. return $all_goods;
  2624. }, $data);
  2625. $website = $input['website_id'];
  2626. $result['article'] = Article::where(function ($query) use ($website) {
  2627. $query->where(function ($subQuery) use ($website) {
  2628. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2629. })->orWhereNull("ignore_ids");
  2630. })
  2631. ->where('catid', $catid)
  2632. ->where('article.status', 1)
  2633. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2634. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2635. ->orderBy('article.updated_at', 'desc')
  2636. ->first();
  2637. return Result::success($result);
  2638. }
  2639. /**
  2640. * 获取商品分类
  2641. * @param array $data
  2642. * @return array
  2643. * */
  2644. public function getWebsiteshopCat(array $data): array
  2645. {
  2646. $website = $data['website_id'];
  2647. $category = WebsiteCategory::where('website_id', $website)
  2648. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2649. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2650. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2651. ->orderBy('sort')
  2652. ->get();
  2653. $cat = $category->map(function ($item) use ($website) {
  2654. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2655. $pid = $item->pid ?? 0;
  2656. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2657. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2658. ->where('website_id', $website)
  2659. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2660. ->get(['aLIas_pinyin'])
  2661. ->pluck('aLIas_pinyin')
  2662. ->implode('/');
  2663. } else {
  2664. $pinyin = $item->aLIas_pinyin ?? '';
  2665. }
  2666. $item->pinyin = $pinyin;
  2667. });
  2668. if (empty($category)) {
  2669. return Result::error("栏目查询失败", 0);
  2670. }
  2671. $cat_tree = Result::buildMenuTree($category);
  2672. $web['website_id'] = $website;
  2673. $goods = Good::where('website_id', $website)
  2674. ->where('status', 2)
  2675. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2676. ->latest('updated_at')
  2677. ->offset(($data['page'] - 1) * $data['pageSize'])
  2678. ->limit($data['pageSize'])
  2679. ->get();
  2680. if (!empty($goods)) {
  2681. if ($goods->count() > 1 && !empty($goods)) {
  2682. $goods = $this->processGoods($goods, $web);
  2683. }
  2684. } else {
  2685. $goods = [];
  2686. }
  2687. $result = [
  2688. 'category' => $cat_tree,
  2689. 'goods' => $goods,
  2690. ];
  2691. // $resul['goods'] = $goods;
  2692. if (empty($result)) {
  2693. return Result::error("查询失败", 0);
  2694. }
  2695. return Result::success($result);
  2696. }
  2697. /*
  2698. * 获取商品列表
  2699. * @param array $data
  2700. * @return array
  2701. * */
  2702. public function getWebsiteshopList(array $data): array
  2703. {
  2704. // return Result::success($data);
  2705. $where = [
  2706. 'status' => 2,
  2707. 'website_id' => $data['website_id'],
  2708. ];
  2709. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2710. // return Result::error("查询失败", 0);
  2711. // }
  2712. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2713. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2714. $data['catid'] = $category->category_id ?? 0;
  2715. }
  2716. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2717. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2718. }
  2719. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2720. array_push($where, ['type_id', $data['type_id']]);
  2721. }
  2722. $query = Good::where($where)
  2723. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2724. $query->where(function ($q) use ($data) {
  2725. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2726. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2727. });
  2728. })
  2729. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2730. $query->where(function ($q) use ($data) {
  2731. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2732. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2733. });
  2734. })
  2735. ->select(
  2736. 'good.id',
  2737. 'good.name',
  2738. 'good.imgurl',
  2739. 'good.description',
  2740. 'good.updated_at',
  2741. 'good.com',
  2742. 'good.catid',
  2743. 'good.type_id',
  2744. 'good.website_id',
  2745. 'good.cat_arr_id',
  2746. 'good.created_at',
  2747. 'good.city_id'
  2748. )
  2749. ->latest('updated_at');
  2750. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2751. $result['count'] = $query->clone()->count();
  2752. $result['goods'] = $this->processGoods(
  2753. $query->clone()
  2754. ->offset(($data['page'] - 1) * $data['pageSize'])
  2755. ->limit($data['pageSize'])
  2756. ->get(),
  2757. $data
  2758. );
  2759. } else {
  2760. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2761. // 获取 type_id 为 1 的数据
  2762. $result['type1'] = $this->processGoods(
  2763. $query->clone()
  2764. ->where('type_id', 1)
  2765. ->offset(($data['page'] - 1) * $data['pageSize'])
  2766. ->limit($data['pageSize'])
  2767. ->get(),
  2768. $data
  2769. );
  2770. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2771. // 获取 type_id 为 2 的数据
  2772. $result['type2'] = $this->processGoods(
  2773. $query->clone()
  2774. ->where('type_id', 2)
  2775. ->offset(($data['page'] - 1) * $data['pageSize'])
  2776. ->limit($data['pageSize'])
  2777. ->get(),
  2778. $data
  2779. );
  2780. }
  2781. if (empty($result)) {
  2782. return Result::error("查询失败", 0);
  2783. }
  2784. return Result::success($result);
  2785. }
  2786. /**
  2787. * 获取商品详情
  2788. * @param array $data
  2789. * @return array
  2790. * */
  2791. public function getWebsiteshopInfo(array $data): array
  2792. {
  2793. $where = [
  2794. 'good.status' => 2,
  2795. 'good.website_id' => $data['website_id'],
  2796. 'good.id' => $data['id'],
  2797. ];
  2798. $goods = Good::where($where)
  2799. ->where('good.id', $data['id'])
  2800. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2801. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2802. ->first();
  2803. if (empty($goods)) {
  2804. return Result::error("查询失败", 0);
  2805. }
  2806. $goods->imgurl = json_decode($goods->imgurl, true);
  2807. return Result::success($goods);
  2808. }
  2809. /**
  2810. * plus pro 处理文章路由问题
  2811. */
  2812. function processArticlePro($website_id)
  2813. {
  2814. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2815. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2816. // // 取出category_id 对应的aLIas_pinyin
  2817. // $categoryIds = array_column($categorys, 'category_id');
  2818. // $categoryPIds = array_column($categorys, 'pid');
  2819. // $aliasPinyins = array_column($categorys, 'path');
  2820. // $alias = array_column($categorys, 'alias');
  2821. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2822. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2823. // // return Result::success($cat_arr);
  2824. // // $catiall = [];
  2825. // //一级所有子级的记录
  2826. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2827. // return [
  2828. // 'cat_1st_arr' => $cat_alias_arr,
  2829. // 'catiall' => $cat_arr,
  2830. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2831. // 'categoryIds' => $categoryIds,
  2832. // ];
  2833. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2834. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2835. // 取出category_id 对应的aLIas_pinyin
  2836. $categoryIds = array_column($categorys, 'category_id');
  2837. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2838. return $pid != 0;
  2839. })));
  2840. $category_path = array_column($categorys, 'path');
  2841. $cat_arr = array_combine($categoryIds, $category_path);
  2842. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2843. $catiall = [];
  2844. //一级所有子级的记录
  2845. $cat_1st_arr = [];
  2846. foreach ($categorys as $key => $value) {
  2847. // $category_arr_id = json_decode($value->category_arr_id);
  2848. // $pinyin_str = '';
  2849. // // 算出一级 并且算出子级
  2850. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2851. $cat_1st_arr[$value->pid][] = $value->category_id;
  2852. }
  2853. // foreach ($category_arr_id as $k => $v) {
  2854. // $pinyin_str .= $cat_arr[$v] . '/';
  2855. // }
  2856. // $pinyin_str = rtrim($pinyin_str, '/');
  2857. $catiall[$value->category_id]['alias'] = $value->alias;
  2858. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2859. $catiall[$value->category_id]['type'] = $value->type;
  2860. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2861. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2862. }
  2863. return [
  2864. 'cat_1st_arr' => $cat_1st_arr,
  2865. 'catiall' => $catiall,
  2866. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2867. 'categoryIds' => $categoryIds,
  2868. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2869. 'categoryPIds' => $categoryPIds,
  2870. ];
  2871. }
  2872. /**
  2873. * 封装处理文章的路由问题
  2874. * */
  2875. function processArticles($articles, $data)
  2876. {
  2877. // 检查 $articles 是否为数组或可迭代对象
  2878. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2879. return $articles->map(function ($article) use ($data) {
  2880. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2881. $catid = $article->cat_arr_id ?? '';
  2882. }
  2883. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2884. $catid = $article->category_arr_id ?? '';
  2885. }
  2886. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2887. $level = json_decode($catid, true);
  2888. if (!is_array($level)) {
  2889. return $article;
  2890. } else {
  2891. $level = array_map('intval', $level);
  2892. }
  2893. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2894. ->where($data)
  2895. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2896. ->pluck('aLIas_pinyin')
  2897. ->implode('/');
  2898. $article->pinyin = $pinyin ?? '';
  2899. return $article;
  2900. });
  2901. } else {
  2902. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2903. $catid = $articles->cat_arr_id ?? '';
  2904. $level = json_decode($catid, true);
  2905. if (!is_array($level)) {
  2906. return $articles;
  2907. } else {
  2908. $level = array_map('intval', $level);
  2909. }
  2910. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2911. ->where($data)
  2912. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2913. ->pluck('aLIas_pinyin')
  2914. ->implode('/');
  2915. $articles->pinyin = $pinyin ?? '';
  2916. return $articles;
  2917. }
  2918. }
  2919. // 封装处理由问题
  2920. function processJob($job, $data)
  2921. {
  2922. return $job->map(function ($job) use ($data) {
  2923. $category = $job->cat_arr_id ?? '';
  2924. $cityid = $job->city_arr_id ?? '';
  2925. $city = json_decode($cityid, true);
  2926. $pinyin = '';
  2927. $level = json_decode($category, true);
  2928. // 路由
  2929. if (!empty($level) && is_array($level)) {
  2930. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2931. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2932. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2933. ->get(['aLIas_pinyin'])
  2934. ->pluck('aLIas_pinyin')
  2935. ->implode('/');
  2936. if (empty($pinyin)) {
  2937. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2938. }
  2939. $job->pinyin = $pinyin;
  2940. }
  2941. // 取职位-城市 市??省
  2942. if (!empty($city) && is_array($city)) {
  2943. if (isset($city[1]) && !empty($city[1])) {
  2944. $city = District::where('id', $city[1])->first(['name']);
  2945. $job->city_name = $city->name ?? '';
  2946. } else if (isset($city[0]) && !empty($city[0])) {
  2947. $city = District::where('id', $city[0])->first(['name']);
  2948. $job->city_name = $city->name ?? '';
  2949. } else {
  2950. $job->city_name = '全国';
  2951. }
  2952. }
  2953. // 获取简历最后一级地区
  2954. if (isset($job->city_id) && !empty($job->city_id)) {
  2955. $city = District::where('id', $job->city_id)->first(['name']);
  2956. $job->hunt_cityname = $city->name ?? '';
  2957. }
  2958. // 组合详细地址
  2959. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2960. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2961. if (is_array($address_id) && !empty($address_id)) {
  2962. $address = District::whereIn('id', $address_id)
  2963. ->orderBy('level', 'asc')
  2964. ->get(['name'])
  2965. ->pluck('name')
  2966. ->implode('');
  2967. // $job->address_name = $address ?? '';
  2968. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2969. }
  2970. }
  2971. // 取行业
  2972. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2973. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2974. if (!empty($job->industry)) {
  2975. $query->where('hyid', $job->industry);
  2976. } else if (!empty($job->hy_id)) {
  2977. $query->where('hyid', $job->hy_id);
  2978. } else if (!empty($job->company_hy_id)) {
  2979. $query->where('hyid', $job->company_hy_id);
  2980. } else {
  2981. $query->where('hyid', $job->job_industry);
  2982. }
  2983. })->first(['hyname']);
  2984. $job->hy_name = $hy_name->hyname ?? '';
  2985. }
  2986. // 取职位类别
  2987. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2988. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2989. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2990. $job->zw_name = $zw_name->zwname ?? '';
  2991. }
  2992. // 取具体职位
  2993. 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))) {
  2994. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2995. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2996. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2997. }
  2998. // 取工作经验
  2999. if (isset($job->experience) && !empty($job->experience)) {
  3000. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  3001. $job->experience_name = $experience->ename ?? '';
  3002. }
  3003. // 取学历
  3004. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  3005. $education = $job->educational ?? $job->school_education;
  3006. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  3007. $job->education_name = $education->ename ?? '';
  3008. }
  3009. // 语言
  3010. if (isset($job->language) && !empty($job->language)) {
  3011. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  3012. $job->language_name = $language->ename ?? '';
  3013. }
  3014. // 薪资
  3015. if (isset($job->salary) && !empty($job->salary)) {
  3016. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3017. $job->salary_name = $salary->ename ?? '';
  3018. }
  3019. // 职位性质
  3020. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3021. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3022. $job->job_nature_name = $job_nature->ename ?? '';
  3023. }
  3024. // 公司规模
  3025. if (isset($job->company_size) && !empty($job->company_size)) {
  3026. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3027. $job->company_size_name = $company_size->ename ?? '';
  3028. }
  3029. // 公司性质
  3030. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3031. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3032. $job->company_nature_name = $company_nature->nature_name ?? '';
  3033. }
  3034. // $job->pinyin = $pinyin;
  3035. return $job;
  3036. });
  3037. }
  3038. /**
  3039. * 获取书籍模块
  3040. * @param array $data
  3041. * @return array
  3042. * */
  3043. public function getWebsiteBook(array $data): array
  3044. {
  3045. $input['id'] = $data['id'];
  3046. $input['website_id'] = $data['website_id'];
  3047. // 将 JSON 字符串转换为 PHP 数组
  3048. $data = json_decode($input['id'], true);
  3049. // 使用 array_map 处理每个元素
  3050. $result = array_map(function ($item) use ($input) {
  3051. // 检查parent元素是否存在且不是undefined
  3052. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3053. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3054. $website = [
  3055. 'website_id' => $input['website_id'],
  3056. ];
  3057. // 查询栏目名称
  3058. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3059. if (empty($category)) {
  3060. $parent_alias = '';
  3061. $parent_pinyin = null;
  3062. $imgBooks = [];
  3063. $textBooks = [];
  3064. } else {
  3065. $parent_alias = $category->alias ?? '';
  3066. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3067. // 查找子分类ID数组
  3068. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3069. array_push($childCategoryIds, $parentCatId);
  3070. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3071. if ($parentImgNum != 0) {
  3072. // 查询图片新闻
  3073. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3074. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3075. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3076. })
  3077. ->where('book.status', 2)
  3078. ->where('book.img_url', '!=', '')
  3079. ->where('book.website_id', $website['website_id'])
  3080. ->leftJoin('website_category', function ($join) use ($website) {
  3081. $join->on('book.cat_id', '=', 'website_category.category_id')
  3082. ->where('website_category.website_id', '=', $website['website_id']);
  3083. })
  3084. ->select(
  3085. 'book.id',
  3086. 'book.title',
  3087. 'book.img_url',
  3088. 'book.price',
  3089. 'book.market_price',
  3090. 'book.description',
  3091. 'book.cat_id',
  3092. 'book.description',
  3093. 'book.updated_at',
  3094. 'website_category.alias as category_name',
  3095. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3096. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3097. )
  3098. ->orderBy('updated_at', 'desc')
  3099. ->limit($parentImgNum)
  3100. ->get()->all();
  3101. // 查询文字新闻
  3102. }
  3103. if ($parentTextNum != 0) {
  3104. $textBooks = [];
  3105. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3106. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3107. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3108. })
  3109. ->where('book.status', 2)
  3110. ->where('book.website_id', $website['website_id'])
  3111. ->leftJoin('website_category', function ($join) use ($website) {
  3112. $join->on('book.cat_id', '=', 'website_category.category_id')
  3113. ->where('website_category.website_id', '=', $website['website_id']);
  3114. })
  3115. ->select(
  3116. 'book.id',
  3117. 'book.title',
  3118. 'book.img_url',
  3119. 'book.price',
  3120. 'book.market_price',
  3121. 'book.description',
  3122. 'book.cat_id',
  3123. 'book.description',
  3124. 'book.updated_at',
  3125. 'website_category.alias as category_name',
  3126. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3127. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3128. )
  3129. ->orderBy('updated_at', 'desc')
  3130. ->limit($parentTextNum)
  3131. ->get()->all();
  3132. }
  3133. }
  3134. }
  3135. $resultItem = [
  3136. 'alias' => $parent_alias ?? '',
  3137. 'category_id' => $parentCatId ?? 0,
  3138. 'pinyin' => $parent_pinyin ?? null,
  3139. 'imgnum' => $imgBooks ?? [],
  3140. 'textnum' => $textBooks ?? [],
  3141. ];
  3142. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3143. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3144. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3145. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3146. ->get()->all();
  3147. if (!empty($childCategory)) {
  3148. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3149. // 查询子栏目名称
  3150. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3151. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3152. ->first();
  3153. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3154. $childImgArticles = [];
  3155. $childTextArticles = [];
  3156. $resultItem['child'] = [];
  3157. } else {
  3158. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3159. // 查询子栏目图片新闻
  3160. $childImgArticles = Book::where('cat_id', $childCatId)
  3161. ->where('status', 2)
  3162. ->where('img_url', '!=', '')
  3163. ->where('book.website_id', $website['website_id'])
  3164. ->leftJoin('website_category', function ($join) use ($website) {
  3165. $join->on('book.cat_id', '=', 'website_category.category_id')
  3166. ->where('website_category.website_id', '=', $website['website_id']);
  3167. })
  3168. ->select(
  3169. 'book.id',
  3170. 'book.title',
  3171. 'book.img_url',
  3172. 'book.price',
  3173. 'book.market_price',
  3174. 'book.description',
  3175. 'book.cat_id',
  3176. 'book.description',
  3177. 'book.updated_at',
  3178. DB::raw("'$child_pinyin' as pinyin")
  3179. )
  3180. ->orderBy('updated_at', 'desc')
  3181. ->limit($childImgNum)
  3182. ->get()->all();
  3183. // 查询子栏目文字新闻
  3184. $childTextArticles = Book::where('cat_id', $childCatId)
  3185. ->where('status', 2)
  3186. ->where('book.website_id', $website['website_id'])
  3187. ->leftJoin('website_category', function ($join) use ($website) {
  3188. $join->on('book.cat_id', '=', 'website_category.category_id')
  3189. ->where('website_category.website_id', '=', $website['website_id']);
  3190. })
  3191. ->select(
  3192. 'book.id',
  3193. 'book.title',
  3194. 'book.img_url',
  3195. 'book.price',
  3196. 'book.market_price',
  3197. 'book.description',
  3198. 'book.cat_id',
  3199. 'book.description',
  3200. 'book.updated_at',
  3201. DB::raw("'$child_pinyin' as pinyin")
  3202. )
  3203. ->orderBy('updated_at', 'desc')
  3204. ->limit($childTextNum)
  3205. ->get()->all();
  3206. $resultItem['child'] = [
  3207. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3208. 'category_id' => $childCatId,
  3209. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3210. 'all_childcat' => $childCategory,
  3211. 'imgnum' => $childImgArticles,
  3212. 'textnum' => $childTextArticles,
  3213. ];
  3214. }
  3215. }
  3216. } else {
  3217. $resultItem['child'] = [];
  3218. }
  3219. return $resultItem;
  3220. }, $data);
  3221. return Result::success($result);
  3222. }
  3223. /**
  3224. * 获取书刊列表
  3225. * @param array $data
  3226. * @return array
  3227. * */
  3228. public function getWebsiteBookList(array $data): array
  3229. {
  3230. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3231. if (empty($web)) {
  3232. return Result::error("查询失败", 0);
  3233. }
  3234. $catid = $data['id'];
  3235. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3236. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3237. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3238. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3239. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3240. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3241. ->where('pid', $category['pid'])
  3242. ->select(
  3243. 'category_id',
  3244. 'alias',
  3245. 'aLIas_pinyin',
  3246. 'pid',
  3247. 'sort',
  3248. 'is_url',
  3249. 'web_url',
  3250. 'seo_title',
  3251. 'seo_keywords',
  3252. 'seo_description',
  3253. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3254. )
  3255. ->orderBy('sort')
  3256. ->get()->all();
  3257. if (empty($category)) {
  3258. return Result::error("查询失败", 0);
  3259. }
  3260. $query = Book::where('book.status', 2)
  3261. ->where('book.website_id', $data['website_id'])
  3262. ->where('book.cat_id', $catid)
  3263. ->select(
  3264. 'book.id',
  3265. 'book.title',
  3266. 'book.img_url',
  3267. 'book.description',
  3268. 'book.updated_at',
  3269. 'book.cat_id',
  3270. DB::raw("'$pinyin' as pinyin")
  3271. )
  3272. ->orderBy('book.updated_at', 'desc');
  3273. $count = $query->count();
  3274. $query = clone $query;
  3275. $Book = $query
  3276. ->limit($data['pageSize'])
  3277. ->offset(($data['page'] - 1) * $data['pageSize'])
  3278. ->get()->all();
  3279. $result = [
  3280. 'category' => $categorys,
  3281. 'books' => $Book,
  3282. 'count' => $count,
  3283. ];
  3284. // if(empty($result)){
  3285. // return Result::error("查询失败", 0);
  3286. // }
  3287. return Result::success($result);
  3288. }
  3289. /**
  3290. * 获取书刊详情
  3291. * @param array $data
  3292. * @return array
  3293. * */
  3294. public function getWebsiteBookInfo(array $data): array
  3295. {
  3296. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3297. if (empty($web)) {
  3298. return Result::error("查询失败", 0);
  3299. }
  3300. $book = Book::where('status', 2)
  3301. ->where('website_id', $data['website_id'])
  3302. ->where('id', $data['id'])
  3303. ->select(
  3304. 'book.*',
  3305. )
  3306. ->orderBy('updated_at', 'desc')
  3307. ->first();
  3308. if (empty($book)) {
  3309. return Result::error("查询失败", 0);
  3310. }
  3311. // 先查询当前分类的 pid
  3312. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3313. ->where('category_id', $book['cat_id'])
  3314. ->first(['pid', 'category_id']);
  3315. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3316. if (!empty($carpid)) {
  3317. if ($carpid->pid != 0) {
  3318. $pid = $carpid['pid'];
  3319. // $parent_pinyin = '';
  3320. } else {
  3321. $pid = $carpid['category_id'];
  3322. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3323. }
  3324. }
  3325. $categorys = $query->where('pid', $pid)
  3326. ->select(
  3327. 'category_id',
  3328. 'alias',
  3329. 'aLIas_pinyin',
  3330. 'pid',
  3331. 'sort',
  3332. 'is_url',
  3333. 'web_url',
  3334. 'category_arr_id as cat_arr_id',
  3335. )
  3336. ->orderBy('sort')
  3337. ->get();
  3338. $category = $this->processArticle($categorys, $data);
  3339. $result = [
  3340. 'category' => $category,
  3341. 'books' => $book,
  3342. ];
  3343. return Result::success($result);
  3344. }
  3345. /**
  3346. * 尝试
  3347. * @param array $data
  3348. * @return array
  3349. * */
  3350. public function test(array $data): array
  3351. {
  3352. $input['id'] = $data['id'];
  3353. $input['website_id'] = $data['website_id'];
  3354. // 将 JSON 字符串转换为 PHP 数组
  3355. $data = json_decode($input['id'], true);
  3356. $result = [];
  3357. $article = $data;
  3358. $result = array_map(function ($item) use ($input) {
  3359. $website = [
  3360. 'website_id' => $input['website_id'],
  3361. ];
  3362. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3363. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3364. $parent = [
  3365. 0 => $category['category_id'] ?? [],
  3366. 1 => $parentImgNum ?? [],
  3367. 2 => $parentTextNum ?? [],
  3368. ];
  3369. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3370. $child = [];
  3371. $resultItem = [
  3372. // 'alias' => $parent_alias ?? '',
  3373. 'category_id' => $parentCatId ?? 0,
  3374. 'pinyin' => $parentImgNum ?? null,
  3375. 'imgnum' => $parentTextNum ?? [],
  3376. // 'textnum' => $textArticles ?? [],
  3377. ];
  3378. return $parent;
  3379. }, $data);
  3380. return Result::success($result);
  3381. // });
  3382. }
  3383. /**
  3384. * 封装处理文章的路由问题
  3385. * */
  3386. function processArticle($article, $data)
  3387. {
  3388. return $article->map(function ($article) use ($data) {
  3389. $catid = $article->cat_arr_id ?? '';
  3390. $level = json_decode($catid, true);
  3391. $pinyin = '';
  3392. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3393. if (!empty($level) && is_array($level)) {
  3394. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3395. ->where('website_id', $data['website_id'])
  3396. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3397. ->get(['aLIas_pinyin'])
  3398. ->pluck('aLIas_pinyin')
  3399. ->implode('/');
  3400. } else {
  3401. $pinyin = '';
  3402. }
  3403. $article->pinyin = $pinyin;
  3404. return $article;
  3405. });
  3406. }
  3407. /**
  3408. * c端-获取招工招聘下拉选框
  3409. * @param array $data
  3410. * @return array
  3411. * */
  3412. public function getWebsiteJobSelect(array $data): array
  3413. {
  3414. $web = Website::where('id', $data['website_id'])->first();
  3415. if (empty($web)) {
  3416. return Result::error("该网站不存在", 0);
  3417. }
  3418. $hy = JobIndustry::get()->all();
  3419. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3420. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3421. $result = [
  3422. 'hy' => $hy,
  3423. 'zw' => $zw,
  3424. 'jtzw' => $jtzw,
  3425. ];
  3426. if (empty($result)) {
  3427. return Result::error("查询失败", 0);
  3428. }
  3429. return Result::success($result);
  3430. }
  3431. /**
  3432. * c端-获取招工招聘
  3433. * @param array $data
  3434. * @return array
  3435. * */
  3436. public function getWebsiteJob(array $data): array
  3437. {
  3438. $web = Website::where('id', $data['website_id'])->first();
  3439. if (empty($web)) {
  3440. return Result::error("该网站不存在", 0);
  3441. }
  3442. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3443. ->where('job_hunting.website_id', $data['website_id'])
  3444. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3445. $query->where(function ($q) use ($data) {
  3446. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3447. });
  3448. })
  3449. ->select(
  3450. 'job_hunting.id',
  3451. 'job_hunting.catid',
  3452. 'job_hunting.cat_arr_id',
  3453. 'job_hunting.job_name_get',
  3454. 'job_hunting.industry',
  3455. 'job_hunting.name',
  3456. 'job_hunting.sexy',
  3457. 'job_hunting.origin',
  3458. 'job_hunting.city_arr_id',
  3459. 'job_hunting.experience',
  3460. 'job_hunting.updated_at',
  3461. 'job_hunting.salary',
  3462. 'job_hunting.skillList',
  3463. 'job_hunting.slelf_evaluation',
  3464. )
  3465. ->orderBy('updated_at', 'desc')
  3466. ->limit($data['job1_num'])
  3467. ->get();
  3468. $web['website_id'] = $data['website_id'];
  3469. if (empty($job_hunting)) {
  3470. $job_huntings = "未查询到相关简历信息";
  3471. } else {
  3472. $job_huntings = $this->processJob($job_hunting, $web);
  3473. }
  3474. // 0:待审核 1:已通过 2:已拒绝
  3475. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3476. ->where('job_recruiting.website_id', $data['website_id'])
  3477. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3478. $query->where(function ($q) use ($data) {
  3479. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3480. });
  3481. })
  3482. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3483. ->select(
  3484. 'job_recruiting.id',
  3485. 'job_recruiting.catid',
  3486. 'job_recruiting.cat_arr_id',
  3487. 'job_recruiting.title',
  3488. 'job_recruiting.jtzw_id',
  3489. 'job_recruiting.hy_id',
  3490. 'job_recruiting.city_arr_id',
  3491. 'job_recruiting.due_data',
  3492. 'job_recruiting.updated_at',
  3493. 'job_recruiting.experience',
  3494. 'job_recruiting.educational',
  3495. 'job_recruiting.salary',
  3496. 'job_recruiting.zw_id',
  3497. 'job_company.business_name',
  3498. 'job_recruiting.keyword',
  3499. 'job_recruiting.description',
  3500. )
  3501. ->orderBy('updated_at', 'desc')
  3502. ->limit($data['job2_num'])
  3503. ->get();
  3504. if (empty($job_recruiting->toArray())) {
  3505. $job_recruitings = "未查询到相关职位信息";
  3506. } else {
  3507. $job_recruitings = $this->processJob($job_recruiting, $web);
  3508. }
  3509. $result = [
  3510. 'job_hunting' => $job_huntings,
  3511. 'job_recuiting' => $job_recruitings,
  3512. ];
  3513. return Result::success($result);
  3514. }
  3515. /**
  3516. * c端-获取招工招聘列表
  3517. * @param array $data
  3518. * @return array
  3519. * */
  3520. public function getWebsiteJobList(array $data): array
  3521. {
  3522. $recruit_where = [];
  3523. $hunt_where = [];
  3524. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3525. if (empty($web)) {
  3526. return Result::error("此网站不存在", 0);
  3527. }
  3528. $website_id['website_id'] = $data['website_id'];
  3529. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3530. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3531. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3532. }
  3533. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3534. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3535. }
  3536. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3537. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3538. }
  3539. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3540. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3541. }
  3542. $query = JobRecruiting::where('job_recruiting.status', 1)
  3543. ->where('job_recruiting.website_id', $data['website_id'])
  3544. ->where($recruit_where)
  3545. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3546. $query->where(function ($q) use ($data) {
  3547. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3548. });
  3549. })
  3550. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3551. $query->where(function ($q) use ($data) {
  3552. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3553. });
  3554. })
  3555. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3556. ->select(
  3557. 'job_recruiting.id',
  3558. 'job_recruiting.catid',
  3559. 'job_recruiting.hy_id',
  3560. 'job_recruiting.title',
  3561. 'job_recruiting.zw_id',
  3562. 'job_recruiting.educational',
  3563. 'job_recruiting.jtzw_id',
  3564. 'job_recruiting.city_arr_id',
  3565. 'job_recruiting.due_data',
  3566. 'job_recruiting.experience',
  3567. 'job_recruiting.cat_arr_id',
  3568. 'job_recruiting.updated_at',
  3569. 'job_company.business_name',
  3570. 'job_recruiting.keyword',
  3571. 'job_recruiting.description',
  3572. )
  3573. ->orderBy('job_recruiting.updated_at', 'desc');
  3574. $recruit_count = $query->count();
  3575. $query = clone $query;
  3576. $JobRecruiting = $query
  3577. ->offset(($data['page'] - 1) * $data['pageSize'])
  3578. ->limit($data['pageSize'])
  3579. ->get();
  3580. if (empty($JobRecruiting)) {
  3581. $JobRecruiting = "暂无相关职位信息";
  3582. } else {
  3583. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3584. }
  3585. }
  3586. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3587. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3588. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3589. }
  3590. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3591. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3592. }
  3593. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3594. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3595. }
  3596. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3597. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3598. }
  3599. $query = JobHunting::where('job_hunting.status', 2)
  3600. ->where('job_hunting.website_id', $data['website_id'])
  3601. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3602. ->where($hunt_where)
  3603. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3604. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3605. // })
  3606. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3607. $query->where(function ($q) use ($data) {
  3608. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3609. });
  3610. })
  3611. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3612. $query->where(function ($q) use ($data) {
  3613. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3614. });
  3615. })
  3616. ->select(
  3617. 'job_hunting.id',
  3618. 'job_hunting.catid',
  3619. 'job_hunting.sexy',
  3620. 'job_hunting.experience',
  3621. 'job_hunting.origin',
  3622. 'job_hunting.industry',
  3623. 'job_hunting.name',
  3624. 'job_hunting.job',
  3625. 'job_hunting.job_name_get',
  3626. 'job_hunting.city_arr_id',
  3627. 'job_hunting.cat_arr_id',
  3628. 'job_hunting.created_at',
  3629. 'job_hunting.updated_at',
  3630. 'job_position.zwname as job_name',
  3631. 'job_hunting.skillList',
  3632. 'job_hunting.slelf_evaluation',
  3633. )
  3634. ->orderBy('job_hunting.updated_at', 'desc');
  3635. $hunt_count = $query->count();
  3636. $query = clone $query;
  3637. $JobHunting = $query
  3638. ->offset(($data['page'] - 1) * $data['pageSize'])
  3639. ->limit($data['pageSize'])
  3640. ->get();
  3641. if (empty($JobHunting)) {
  3642. $JobRecruiting = "暂无相关简历信息";
  3643. } else {
  3644. $JobHunting = $this->processJob($JobHunting, $website_id);
  3645. }
  3646. }
  3647. $result = [
  3648. 'JobRecruiting' => $JobRecruiting ?? [],
  3649. 'recruit_count' => $recruit_count ?? 0,
  3650. 'JobHunting' => $JobHunting ?? [],
  3651. 'hunt_count' => $hunt_count ?? 0,
  3652. ];
  3653. return Result::success($result);
  3654. }
  3655. /**
  3656. * c端-获取招工招聘详情
  3657. * @param array $data
  3658. * @return array
  3659. * */
  3660. public function getWebsiteJobInfo(array $data): array
  3661. {
  3662. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3663. if (empty($web)) {
  3664. return Result::error("该网站不存在", 0);
  3665. }
  3666. $webid = [
  3667. 'website_id' => $data['website_id'],
  3668. ];
  3669. // 职位相关信息
  3670. if ($data['type'] == 1) {
  3671. $query = JobRecruiting::where('status', 1)
  3672. ->where('website_id', $data['website_id'])
  3673. ->select('*');
  3674. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3675. $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();
  3676. if (!empty($company)) {
  3677. $result['company'] = $this->processJob($company, $webid);
  3678. }
  3679. $other_job = JobRecruiting::where('status', 1)
  3680. ->where('website_id', $data['website_id'])
  3681. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3682. ->where('id', '!=', $data['id'])
  3683. ->where('user_id', '=', $job[0]['user_id'])
  3684. ->limit($data['pageSize'])
  3685. ->get();
  3686. if (!empty($other_job)) {
  3687. $result['other_job'] = $this->processJob($other_job, $webid);
  3688. }
  3689. } else {
  3690. // 简历相关信息
  3691. $job = JobHunting::where('job_hunting.status', 2)
  3692. ->where('job_hunting.website_id', $data['website_id'])
  3693. ->where('job_hunting.id', $data['id'])
  3694. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3695. ->select('job_hunting.*', 'user_name')
  3696. ->get();
  3697. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3698. if (!empty($resume->toArray())) {
  3699. $result['resume'] = 1;
  3700. } else {
  3701. $result['resume'] = 0;
  3702. }
  3703. }
  3704. if (empty($job->toArray())) {
  3705. return Result::error("id参数错误", 0);
  3706. }
  3707. if (!empty($job[0]['job_experience'])) {
  3708. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3709. if (!empty($job_experience)) {
  3710. // $hy = [];
  3711. foreach ($job_experience as $key => $value) {
  3712. // $id = $value['id'];
  3713. $hy[$key] = $value['job_industry'];
  3714. $zw_id[$key] = $value['job_typename'];
  3715. $jtzw_id[$key] = $value['job_name'];
  3716. }
  3717. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3718. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3719. // 先将关联表转换为索引数组,提高查找效率
  3720. $hyLookup = [];
  3721. foreach ($hy_table as $item) {
  3722. $hyLookup[$item['hyid']] = $item['hyname'];
  3723. }
  3724. $zwLookup = [];
  3725. foreach ($zw_table as $item) {
  3726. $zwLookup[$item['zwid']] = $item['zwname'];
  3727. }
  3728. foreach ($job_experience as $key => &$value) {
  3729. // 处理行业名称
  3730. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3731. $value['hy_name'] = $hyLookup[$hy[$key]];
  3732. }
  3733. // 处理职位名称
  3734. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3735. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3736. }
  3737. // 处理具体职位名称
  3738. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3739. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3740. }
  3741. }
  3742. // 释放引用,防止意外修改后续代码
  3743. unset($value);
  3744. }
  3745. $result['job_experience'] = $job_experience ?? [];
  3746. }
  3747. if (!empty($job[0]['education_experience'])) {
  3748. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3749. if (!empty($education_experience)) {
  3750. foreach ($education_experience as $key => $value) {
  3751. // $id = $value['id'];
  3752. $education[$key] = $value['school_education'];
  3753. }
  3754. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3755. // // 先将关联表转换为索引数组,提高查找效率
  3756. $educationLookup = [];
  3757. foreach ($education_table as $item) {
  3758. $educationLookup[$item['evalue']] = $item['ename'];
  3759. }
  3760. foreach ($education_experience as $key => &$value) {
  3761. // 处理学历名称
  3762. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3763. $value['education_name'] = $educationLookup[$education[$key]];
  3764. }
  3765. }
  3766. }
  3767. $result['education_experience'] = $job_experience ?? [];
  3768. }
  3769. $result['job'] = $this->processJob($job, $webid);
  3770. // // 返现对应的栏目
  3771. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3772. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3773. ->whereIn('category_id', $catid)
  3774. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3775. ->orderBy('pid')->get()->all();
  3776. if (!empty($category)) {
  3777. $result['category'] = $category;
  3778. }
  3779. $result['job'] = $job;
  3780. $result['job_experience'] = $job_experience ?? [];
  3781. $result['education_experience'] = $education_experience ?? [];
  3782. if (empty($result)) {
  3783. return Result::error("参数错误", 0);
  3784. }
  3785. return Result::success($result);
  3786. }
  3787. /**
  3788. * c端-申请职位
  3789. * @param array $data
  3790. * @return array
  3791. * */
  3792. public function getWebsiteJobApply(array $data): array
  3793. {
  3794. // 首先验证网站是否存在
  3795. // return Result::success($data);
  3796. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3797. if (empty($web)) {
  3798. return Result::error("该网站不存在", 0);
  3799. }
  3800. // 验证用户是否存在且为个人会员/管理员
  3801. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3802. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3803. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3804. return Result::error("用户不存在", 0);
  3805. }
  3806. // 去除重复元素和空元素,并保持原始顺序
  3807. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3808. return !empty($value);
  3809. }));
  3810. // 验证职位是否存在 1:审核通过
  3811. $recruiting = JobRecruiting::where('status', 1)
  3812. ->where('website_id', $data['website_id'])
  3813. ->whereIn('id', $data['recruit_id'])
  3814. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3815. if (empty($recruiting)) {
  3816. return Result::error("该职位不存在", 0);
  3817. }
  3818. // 简历是否存在
  3819. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3820. if (empty($hunt_id)) {
  3821. return Result::error("该简历不存在", 0);
  3822. }
  3823. $data['hunt_id'] = $hunt_id['hunt_id'];
  3824. // // 验证是否已投递过该职位
  3825. $apply = JobApply::where('user_id', $data['user_id'])
  3826. ->where('hunt_id', $data['hunt_id'])
  3827. ->where('website_id', $data['website_id'])
  3828. ->whereIn('recruit_id', $data['recruit_id'])
  3829. ->get(['recruit_id']);
  3830. if (!empty($apply->toArray())) {
  3831. return Result::error("您已投递过该职位!");
  3832. }
  3833. $insertData = array_map(function ($recruiting) use ($data) {
  3834. return [
  3835. 'user_id' => $data['user_id'],
  3836. 'hunt_id' => $data['hunt_id'],
  3837. 'website_id' => $data['website_id'],
  3838. 'recruit_id' => $recruiting['recruit_id'],
  3839. 'receiver_id' => $recruiting['receiver_id'],
  3840. 'status' => 1,
  3841. ];
  3842. }, $recruiting);
  3843. // 批量插入数据
  3844. $result = JobApply::insert($insertData);
  3845. if (empty($result)) {
  3846. return Result::error("投递失败", 0);
  3847. }
  3848. return Result::success($result);
  3849. }
  3850. /**
  3851. * 招工招聘-沟通简历
  3852. * @param array $data
  3853. * @return array
  3854. * */
  3855. public function getWebsiteJobResume(array $data): array
  3856. {
  3857. // 首先验证网站是否存在
  3858. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3859. if (empty($web)) {
  3860. return Result::error("该网站不存在", 0);
  3861. }
  3862. // return Result::success($data);
  3863. // 验证用户是否存在且为企业会员/管理员
  3864. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3865. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3866. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3867. return Result::error("用户不存在", 0);
  3868. }
  3869. // 去除重复元素和空元素,并保持原始顺序
  3870. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3871. return !empty($value);
  3872. }));
  3873. // 验证简历是否存在
  3874. $hunting = JobHunting::where('status', 2)
  3875. ->where('website_id', $data['website_id'])
  3876. ->whereIn('id', $data['hunt_id'])
  3877. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3878. if (empty($hunting)) {
  3879. return Result::error("该简历不存在", 0);
  3880. }
  3881. // 验证是否已沟通过该简历
  3882. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3883. ->where('recruit_id', $data['recruit_id'])
  3884. ->where('website_id', $data['website_id'])
  3885. ->whereIn('hunt_id', $data['hunt_id'])
  3886. ->get(['hunt_id']);
  3887. if (!empty($remuse->toArray())) {
  3888. return Result::error("您已沟通过该简历!");
  3889. }
  3890. // 准备要插入的数据数组
  3891. $insertData = array_map(function ($hunting) use ($data) {
  3892. return [
  3893. 'user_id' => $data['user_id'],
  3894. 'recruit_id' => $data['recruit_id'],
  3895. 'website_id' => $data['website_id'],
  3896. 'hunt_id' => $hunting['hunt_id'],
  3897. 'receiver_id' => $hunting['receiver_id'],
  3898. 'status' => 1,
  3899. ];
  3900. }, $hunting);
  3901. // 批量插入数据
  3902. $result = JobRemuse::insert($insertData);
  3903. if (empty($result)) {
  3904. return Result::error("沟通失败", 0);
  3905. }
  3906. return Result::success($result);
  3907. }
  3908. /**
  3909. * 招工招聘 -我的职位(企业会员)
  3910. * @param array $data
  3911. * @return array
  3912. */
  3913. public function getWebsiteJobRecruiting(array $data): array
  3914. {
  3915. $web = Website::where('id', $data['website_id'])->first('id');
  3916. if (empty($web)) {
  3917. return Result::error("该网站不存在", 0);
  3918. }
  3919. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3920. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3921. return Result::error("用户暂无权限!", 0);
  3922. }
  3923. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3924. $result = JobRecruiting::where('website_id', $data['website_id'])
  3925. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3926. $query->where('user_id', $user['id']);
  3927. })
  3928. ->where('status', 1)
  3929. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3930. ->orderBy('updated_at', 'desc')
  3931. ->limit($data['pageSize'])
  3932. ->get();
  3933. if (empty($result)) {
  3934. return Result::error("暂无相关职位信息", 0);
  3935. }
  3936. return Result::success($result);
  3937. }
  3938. /**
  3939. * c端 - 验证路由
  3940. * @param array $data
  3941. * @return array
  3942. */
  3943. /**
  3944. * c端 - 验证路由
  3945. * @param array $data
  3946. * @return array
  3947. */
  3948. public function checkWebsiteRoute(array $data): array
  3949. {
  3950. // 测试001111111222
  3951. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3952. if (empty($web)) {
  3953. return Result::error("该网站不存在", 0);
  3954. } elseif ($web['status'] != 1) {
  3955. return Result::error("网站已经关闭", 0);
  3956. }
  3957. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3958. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3959. // 验证路由是否存在
  3960. if (empty($whiteRouterInfo)) {
  3961. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3962. }
  3963. if (!empty($whiteRouterInfo)) {
  3964. return Result::success($whiteRouterInfo->toArray());
  3965. }
  3966. }
  3967. // 验证栏目路由
  3968. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3969. ->where('path', $data['all_route'])
  3970. ->get()->all();
  3971. if (count($last_category) == 0) {
  3972. return Result::error("该栏目不存在", 0);
  3973. }
  3974. if (count($last_category) > 1) {
  3975. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3976. }
  3977. if (count($last_category) == 1) {
  3978. $last_category = $last_category[0];
  3979. }
  3980. // return Result::success($last_category);
  3981. if (isset($data['id']) && !empty($data['id'])) {
  3982. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3983. switch ($last_category['type']) {
  3984. case 1:
  3985. // 文章
  3986. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3987. $article = Article::where('status', 1)
  3988. ->where('id', $data['id'])
  3989. ->where(function ($query) use ($data) {
  3990. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3991. ->orWhereNull("ignore_ids");
  3992. })
  3993. ->first(['catid']);
  3994. if (empty($article)) {
  3995. return Result::error("该文章不存在", 0);
  3996. }
  3997. // return Result::success($article);
  3998. break;
  3999. case 2:
  4000. // 商品
  4001. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4002. $article = Good::where('website_id', $data['website_id'])
  4003. ->where('status', 2)
  4004. ->where('id', $data['id'])
  4005. ->first(['cat_arr_id']);
  4006. if (empty($article)) {
  4007. return Result::error("该商品不存在", 0);
  4008. }
  4009. break;
  4010. case 3:
  4011. // 书刊信息
  4012. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4013. $article = Book::where('website_id', $data['website_id'])
  4014. ->where('status', 2)
  4015. ->where('id', $data['id'])
  4016. ->first(['id', 'cat_arr_id']);
  4017. if (empty($article)) {
  4018. return Result::error("该书刊不存在", 0);
  4019. }
  4020. break;
  4021. case 4:
  4022. // 招聘
  4023. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4024. $article = JobRecruiting::where('website_id', $data['website_id'])
  4025. ->where('status', 1)
  4026. ->where('id', $data['id'])
  4027. ->first(['cat_arr_id']);
  4028. if (empty($article)) {
  4029. return Result::error("该招聘不存在", 0);
  4030. }
  4031. break;
  4032. case 5:
  4033. // 求职
  4034. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4035. $article = JobHunting::where('website_id', $data['website_id'])
  4036. ->where('status', 2)
  4037. ->where('id', $data['id'])
  4038. ->first(['cat_arr_id']);
  4039. if (empty($article)) {
  4040. return Result::error("该求职不存在", 0);
  4041. }
  4042. break;
  4043. case 6:
  4044. // 企业
  4045. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4046. $article = Company::
  4047. // where('website_id', $data['website_id'])
  4048. // ->
  4049. where('status', 1)
  4050. ->where('id', $data['id'])
  4051. ->first(['cat_arr_id']);
  4052. if (empty($article)) {
  4053. return Result::error("该企业不存在", 0);
  4054. }
  4055. break;
  4056. case 7:
  4057. // 项目
  4058. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4059. $article = Project::where('website_id', $data['website_id'])
  4060. ->where('status', 1)
  4061. ->where('id', $data['id'])
  4062. ->first(['cat_arr_id']);
  4063. if (empty($article)) {
  4064. return Result::error("该项目不存在", 0);
  4065. }
  4066. break;
  4067. default:
  4068. return Result::error("该数据不存在", 0);
  4069. break;
  4070. }
  4071. // return Result::success($article);
  4072. // $catid =0 ;
  4073. if (!isset($article['cat_arr_id'])) {
  4074. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4075. } else {
  4076. $catidArray = json_decode($article['cat_arr_id'], true);
  4077. $catid = !empty($catidArray) ? end($catidArray) : null;
  4078. }
  4079. // return Result::success($catid);
  4080. // // return Result::success($article['cat_arr_id']);
  4081. if (empty($catid)) {
  4082. return Result::error("该栏目路径不存在", 0);
  4083. }
  4084. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4085. ->where('category_id', $catid)
  4086. ->first('path');
  4087. }
  4088. // else{
  4089. // // if ($last_category['pid'] != 0) {
  4090. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4091. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4092. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4093. // ->where('category_id',$catid)
  4094. // ->where('path',$data['all_route'])
  4095. // ->first('path');
  4096. // // } else {
  4097. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4098. // // }
  4099. // }
  4100. // return Result::success($path);
  4101. if (!empty($path) && $path['path'] != $data['all_route']) {
  4102. return Result::error('非法路径!');
  4103. } else {
  4104. return Result::success($last_category['path']);
  4105. }
  4106. }
  4107. /**
  4108. * 招工招聘 - 获取推荐职位
  4109. * @param array $data
  4110. * @return array
  4111. */
  4112. public function getWebsiteLevelJob(array $data): array
  4113. {
  4114. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4115. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4116. ->where('job_recruiting.status', 1)
  4117. ->where('job_level', $data['job_level'])
  4118. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4119. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4120. ->orderBy('job_recruiting.updated_at', 'desc')
  4121. ->limit($data['pageSize'])
  4122. ->get();
  4123. $web = ['website_id' => $data['website_id']];
  4124. if (!empty($job)) {
  4125. $result = $this->processJob($job, $web);
  4126. }
  4127. if (empty($result)) {
  4128. return Result::error("暂无相关职位信息", 0);
  4129. }
  4130. return Result::success($result);
  4131. }
  4132. /**
  4133. * 验证导航名称是否重复
  4134. * @return void
  4135. */
  4136. //20250226 产品列表
  4137. public function getGoodList(array $data): array
  4138. {
  4139. var_dump($data, '---------1-2--');
  4140. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4141. unset($data['user_type_id']);
  4142. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4143. $where = [];
  4144. if ($type_id != '10000') {
  4145. $where = [
  4146. 'good.user_id' => $user_id,
  4147. ];
  4148. }
  4149. //类型
  4150. if (isset($data['type_id']) && $data['type_id']) {
  4151. $where['good.type_id'] = $data['type_id'];
  4152. }
  4153. //名称
  4154. if (isset($data['name']) && $data['name']) {
  4155. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4156. }
  4157. //status
  4158. if (isset($data['status']) && $data['status'] != '') {
  4159. $where['good.status'] = $data['status'];
  4160. }
  4161. //status1
  4162. // if (isset($data['status1']) && $data['status1'] == 1) {
  4163. // $status1 = 1;
  4164. // }
  4165. $where1 = [];
  4166. //website_id
  4167. // if (isset($data['website_id']) && $data['website_id']) {
  4168. // $where1 = [
  4169. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4170. // ];
  4171. // }
  4172. // website_name
  4173. if (isset($data['website_name']) && $data['website_name']) {
  4174. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4175. }
  4176. // catid
  4177. if (isset($data['category_name']) && $data['category_name']) {
  4178. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4179. }
  4180. // $result = Good::where($where)
  4181. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4182. var_dump($where, '---------1---');
  4183. $result = Good::where($where)
  4184. ->when(!empty($where1), function ($query) use ($where1) {
  4185. return $query->where($where1);
  4186. })
  4187. //status 1待审核2已审核3已拒绝
  4188. ->when(isset($data['status1']), function ($query) {
  4189. return $query->whereIn('good.status', [1, 3]);
  4190. })
  4191. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4192. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4193. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4194. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4195. ->orderBy("updated_at", "desc")
  4196. ->limit($data['page_size'])
  4197. ->offset(($data['page'] - 1) * $data['page_size'])
  4198. ->get();
  4199. $count = Good::where($where)
  4200. ->when(!empty($where1), function ($query) use ($where1) {
  4201. return $query->where($where1);
  4202. })
  4203. //status 1待审核2已审核3已拒绝
  4204. ->when(isset($data['status1']), function ($query) {
  4205. return $query->whereIn('good.status', [1, 3]);
  4206. })
  4207. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4208. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4209. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4210. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4211. ->orderBy("updated_at", "desc")->count();
  4212. $data = [
  4213. 'rows' => $result->toArray(),
  4214. 'count' => $count,
  4215. ];
  4216. if (empty($result)) {
  4217. return Result::error("此栏目暂无相关产品", 0);
  4218. }
  4219. return Result::success($data);
  4220. }
  4221. public function getGoodInfo(array $data): array
  4222. {
  4223. $result = Good::where('id', $data['id'])->first();
  4224. if (empty($result)) {
  4225. return Result::error("此产品不存在", 0);
  4226. }
  4227. return Result::success($result);
  4228. }
  4229. public function addGood(array $data): array
  4230. {
  4231. // unset($data['city_arr_id']);
  4232. // unset($data['cat_arr_id']);
  4233. $data['city_id'] = end($data['city_arr_id']);
  4234. $data['catid'] = end($data['cat_arr_id']);
  4235. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4236. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4237. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4238. unset($data['imgUrl']); //大小写
  4239. if (isset($data['price']) && $data['price'] == '') {
  4240. $data['price'] = 0;
  4241. }
  4242. if ($data['imgurl'] == '') {
  4243. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4244. preg_match_all($reg, $data['detail'], $matches);
  4245. if (isset($matches[1][0])) {
  4246. //截取varchar240
  4247. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4248. }
  4249. }
  4250. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4251. //提取标题+内容中的关键词
  4252. $data['keyword'] = $data['name'];
  4253. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4254. Jieba::init(); // 初始化 jieba-php
  4255. Finalseg::init();
  4256. $segList = Jieba::cut($data['keyword']);
  4257. $segList1 = array_slice($segList, 0, 8);
  4258. $data['keyword'] = implode(',', $segList1);
  4259. }
  4260. if ($data['description'] == '') {
  4261. //提取内容中的描述
  4262. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4263. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4264. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4265. }
  4266. if ($data['status'] == 1) {
  4267. $this->sendMessage([
  4268. 'talk_type' => 200,
  4269. 'title' => $data['name'],
  4270. 'content' => '提交了审核',
  4271. 'messageType' => 3,
  4272. ]);
  4273. }
  4274. $result = Good::insert($data);
  4275. if (empty($result)) {
  4276. return Result::error("添加失败", 0);
  4277. }
  4278. return Result::success($result);
  4279. }
  4280. public function updateGood(array $data): array
  4281. {
  4282. $data['city_id'] = end($data['city_arr_id']);
  4283. $data['catid'] = end($data['cat_arr_id']);
  4284. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4285. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4286. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4287. //设置东八区
  4288. date_default_timezone_set('Asia/Shanghai');
  4289. $data['updated_at'] = date('Y-m-d H:i:s');
  4290. if (isset($data['price']) && $data['price'] == '') {
  4291. $data['price'] = 0;
  4292. }
  4293. if ($data['imgurl'] == '') {
  4294. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4295. preg_match_all($reg, $data['detail'], $matches);
  4296. if (isset($matches[1][0])) {
  4297. //截取varchar240
  4298. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4299. }
  4300. }
  4301. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4302. //提取标题+内容中的关键词
  4303. $data['keyword'] = $data['name'];
  4304. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4305. Jieba::init(); // 初始化 jieba-php
  4306. Finalseg::init();
  4307. $segList = Jieba::cut($data['keyword']);
  4308. $segList1 = array_slice($segList, 0, 8);
  4309. $data['keyword'] = implode(',', $segList1);
  4310. }
  4311. if ($data['description'] == '') {
  4312. //提取内容中的描述
  4313. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4314. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4315. }
  4316. if ($data['status'] == 1) {
  4317. $this->sendMessage([
  4318. 'talk_type' => 200,
  4319. 'title' => $data['name'],
  4320. 'content' => '提交了审核',
  4321. 'messageType' => 3,
  4322. ]);
  4323. }
  4324. $result = Good::where('id', $data['id'])->update($data);
  4325. if (empty($result)) {
  4326. return Result::error("更新失败", 0);
  4327. }
  4328. return Result::success($result);
  4329. }
  4330. public function delGood(array $data): array
  4331. {
  4332. $result = Good::where('id', $data['id'])->delete();
  4333. if (empty($result)) {
  4334. return Result::error("删除失败", 0);
  4335. }
  4336. return Result::success($result);
  4337. }
  4338. //20250226 产品列表
  4339. //20250306 求职信息
  4340. public function getJobHuntingList(array $data): array
  4341. {
  4342. $where = [];
  4343. if (isset($data['username']) && !empty($data['username'])) {
  4344. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4345. }
  4346. //status 1待审核2已审核3已拒绝
  4347. if (isset($data['status']) && $data['status'] != '') {
  4348. $where = [
  4349. 'job_hunting.status' => $data['status'],
  4350. ];
  4351. }
  4352. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4353. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4354. unset($data['type_id']);
  4355. if ($type_id != '10000') {
  4356. $where[] = ['job_hunting.user_id', '=', $user_id];
  4357. }
  4358. $result = JobHunting::where($where)
  4359. ->when(!empty($data['status1']), function ($query) use ($data) {
  4360. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4361. })
  4362. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4363. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4364. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4365. ->orderBy("updated_at", "desc")
  4366. ->limit($data['page_size'])
  4367. ->offset(($data['page'] - 1) * $data['page_size'])
  4368. ->get();
  4369. if (empty($result)) {
  4370. return Result::error("查询失败", 0);
  4371. }
  4372. $count = JobHunting::where($where)
  4373. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4374. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4375. ->count();
  4376. $data = [
  4377. 'rows' => $result->toArray(),
  4378. 'count' => $count,
  4379. ];
  4380. return Result::success($data);
  4381. }
  4382. public function getJobHuntingApply(array $data): array
  4383. {
  4384. var_dump($data, '-----------------test--------1-');
  4385. $where = [];
  4386. if (isset($data['username']) && !empty($data['username'])) {
  4387. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4388. }
  4389. if (isset($data['salary']) && !empty($data['salary'])) {
  4390. $where[] = [
  4391. 'job_hunting.salary',
  4392. '=',
  4393. $data['salary'],
  4394. ];
  4395. }
  4396. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4397. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4398. unset($data['type_id']);
  4399. if ($type_id != '10000') {
  4400. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4401. }
  4402. var_dump($where, '-----------------test---------');
  4403. $result = jobApply::where($where)
  4404. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4405. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4406. // })
  4407. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4408. ->where('job_enum.egroup', '=', 'income')
  4409. ->where('job_hunting.status', 2) //已审核
  4410. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4411. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4412. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4413. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4414. //职位----是申请职位
  4415. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4416. ->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')
  4417. ->orderBy("job_hunting.updated_at", "desc")
  4418. ->limit($data['page_size'])
  4419. ->offset(($data['page'] - 1) * $data['page_size'])
  4420. ->get();
  4421. if (empty($result)) {
  4422. return Result::error("查询失败", 0);
  4423. }
  4424. $count = jobApply::where($where)
  4425. ->where('job_enum.egroup', '=', 'income')
  4426. ->where('job_hunting.status', 2) //已审核
  4427. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4428. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4429. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4430. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4431. //职位----是申请职位
  4432. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4433. ->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')
  4434. ->count();
  4435. $data = [
  4436. 'rows' => $result->toArray(),
  4437. 'count' => $count,
  4438. ];
  4439. return Result::success($data);
  4440. }
  4441. public function addJobHunting(array $data): array
  4442. {
  4443. date_default_timezone_set('Asia/Shanghai');
  4444. unset($data['company_name']);
  4445. unset($data['job_industry']);
  4446. unset($data['job_name']);
  4447. unset($data['department']);
  4448. unset($data['job_timeList']);
  4449. unset($data['job_content']);
  4450. unset($data['job_typename']); //不知道这是啥,
  4451. $data['created_at'] = date('Y-m-d H:i:s');
  4452. $data['updated_at'] = date('Y-m-d H:i:s');
  4453. //根据用户 user_id 只能添加一次
  4454. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4455. if (!empty($result)) {
  4456. return Result::error("您已添加过求职信息", 0);
  4457. }
  4458. var_dump($result, '-----------------test---------');
  4459. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4460. if (is_string($data['city_arr_id'])) {
  4461. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4462. $cityArr = json_decode($data['city_arr_id'], true);
  4463. // 确保 $cityArr 是数组
  4464. if (is_array($cityArr)) {
  4465. $data['city_id'] = end($cityArr);
  4466. }
  4467. } else {
  4468. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4469. if (is_array($data['city_arr_id'])) {
  4470. $data['city_id'] = end($data['city_arr_id']);
  4471. }
  4472. }
  4473. }
  4474. // 处理求职所绑定栏目
  4475. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4476. if (is_string($data['cat_arr_id'])) {
  4477. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4478. // 先清理可能存在的无效 JSON 字符
  4479. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4480. $catArr = json_decode($cleanedCatArrStr, true);
  4481. // 检查 JSON 解码是否成功且结果是数组
  4482. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4483. $data['catid'] = end($catArr);
  4484. }
  4485. } else {
  4486. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4487. if (is_array($data['cat_arr_id'])) {
  4488. $data['catid'] = end($data['cat_arr_id']);
  4489. }
  4490. }
  4491. }
  4492. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4493. $this->sendMessage([
  4494. 'talk_type' => 600,
  4495. 'title' => $data['name'],
  4496. 'content' => '提交了审核',
  4497. 'messageType' => 11,
  4498. ]);
  4499. }
  4500. $result = JobHunting::create($data);
  4501. if (empty($result)) {
  4502. return Result::error("添加失败", 0);
  4503. }
  4504. return Result::success($result);
  4505. }
  4506. public function delJobHunting(array $data): array
  4507. {
  4508. $result = JobHunting::where('id', $data['id'])->delete();
  4509. if (empty($result)) {
  4510. return Result::error("删除失败", 0);
  4511. }
  4512. return Result::success($result);
  4513. }
  4514. public function updateJobHunting(array $data): array
  4515. {
  4516. //设置东八区
  4517. date_default_timezone_set('Asia/Shanghai');
  4518. unset($data['company_name']);
  4519. unset($data['job_industry']);
  4520. unset($data['job_name']);
  4521. unset($data['department']);
  4522. unset($data['job_timeList']);
  4523. unset($data['job_content']);
  4524. unset($data['job_typename']); //不知道这是啥,
  4525. $data['created_at'] = date('Y-m-d H:i:s');
  4526. $data['updated_at'] = date('Y-m-d H:i:s');
  4527. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4528. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4529. $cityArr = json_decode($data['city_arr_id'], true);
  4530. $data['city_id'] = end($cityArr);
  4531. } else {
  4532. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4533. $data['city_id'] = end($data['city_arr_id']);
  4534. }
  4535. // 处理求职所绑定栏目
  4536. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4537. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4538. $catArr = json_decode($data['cat_arr_id'], true);
  4539. $data['catid'] = end($catArr);
  4540. } else {
  4541. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4542. $data['catid'] = end($data['cat_arr_id']);
  4543. }
  4544. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4545. $this->sendMessage([
  4546. 'talk_type' => 600,
  4547. 'title' => $data['name'],
  4548. 'content' => '提交了审核',
  4549. 'messageType' => 11,
  4550. ]);
  4551. }
  4552. $result = JobHunting::where('id', $data['id'])->update($data);
  4553. if (empty($result)) {
  4554. return Result::error("更新失败", 0);
  4555. }
  4556. return Result::success($result);
  4557. }
  4558. public function getJobHuntingInfo(array $data): array
  4559. {
  4560. $result = JobHunting::where('id', $data['id'])->first();
  4561. if (empty($result)) {
  4562. return Result::error("查询失败", 0);
  4563. }
  4564. return Result::success($result);
  4565. }
  4566. public function getJobHuntingData(array $data): array
  4567. {
  4568. $jobEnum = JobEnum::get();
  4569. $jobIndustry = JobIndustry::get();
  4570. $jobNature = JobNature::get();
  4571. $jobPosition = JobPosition::get();
  4572. $data = [
  4573. 'jobEnum' => $jobEnum,
  4574. 'jobIndustry' => $jobIndustry,
  4575. 'jobNature' => $jobNature,
  4576. 'jobPosition' => $jobPosition,
  4577. ];
  4578. return Result::success($data);
  4579. }
  4580. public function delJobHuntingInfo(array $data): array
  4581. {
  4582. $result = JobHunting::where('id', $data['id'])->delete();
  4583. return Result::success();
  4584. }
  4585. //20250324 通知,公告,消息
  4586. public function delNotice(array $data): array
  4587. {
  4588. $result = Notice::where('id', $data['id'])->delete();
  4589. if ($result) {
  4590. return Result::success();
  4591. } else {
  4592. return Result::error("删除失败", 0);
  4593. }
  4594. }
  4595. public function getNoticeInfo(array $data): array
  4596. {
  4597. $result = Notice::where('id', $data['id'])->first();
  4598. // var_dump($result['re_user_ids'], '--------------------');
  4599. if (empty($result)) {
  4600. return Result::error("查询失败", 0);
  4601. }
  4602. return Result::success($result);
  4603. }
  4604. public function readNotice(array $data): array
  4605. {
  4606. $result = Notice::where('id', $data['id'])->first();
  4607. // var_dump($result['re_user_ids'], '--------------------');
  4608. if (empty($result)) {
  4609. return Result::error("查询失败", 0);
  4610. }
  4611. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4612. $re_user_ids = json_decode($result['re_user_ids'], true);
  4613. var_dump($re_user_ids, '--------------1---test---------');
  4614. var_dump($data, '--------------1---test---------');
  4615. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4616. //如果已经存在,就不再添加
  4617. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4618. $read_id = json_decode($result['read_id'], true);
  4619. if (!is_array($read_id)) {
  4620. $read_id = [];
  4621. }
  4622. if (!in_array($data['user_id'], $read_id)) {
  4623. $read_id[] = $data['user_id'];
  4624. $result['read_id'] = json_encode($read_id);
  4625. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4626. }
  4627. } else {
  4628. //如果不存在,就添加
  4629. $result['read_id'] = json_encode([$data['user_id']]);
  4630. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4631. }
  4632. }
  4633. return Result::success($result);
  4634. }
  4635. public function addNotice(array $data): array
  4636. {
  4637. date_default_timezone_set('Asia/Shanghai');
  4638. $data['created_at'] = date('Y-m-d H:i:s');
  4639. $data['updated_at'] = date('Y-m-d H:i:s');
  4640. // $data['level'] = "1,2,3,4,5";
  4641. $level = json_decode($data['level'], true);
  4642. $user_id = UserInfo::
  4643. //city_id不是null
  4644. whereNotNull('city_id')
  4645. ->whereNotNull('department_id')
  4646. ->where(function ($query) use ($data) {
  4647. $query->where(function ($subQuery) use ($data) {
  4648. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4649. });
  4650. })
  4651. ->where(function ($query) use ($data) {
  4652. $query->where(function ($subQuery) use ($data) {
  4653. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4654. });
  4655. })
  4656. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4657. $query->whereIn('level', $level);
  4658. })
  4659. ->pluck('user_id')->toArray();
  4660. $user_id = array_unique($user_id);
  4661. $chat_ids = $user_id;
  4662. $user_id = json_encode($user_id);
  4663. $data['re_user_ids'] = $user_id;
  4664. $this->sendMessage([
  4665. 'talk_type' => 700,
  4666. 'title' => $data['title'],
  4667. 'content' => '提交了审核',
  4668. 'messageType' => 5,
  4669. ]);
  4670. $result = Notice::insertGetId($data);
  4671. if (empty($result)) {
  4672. return Result::error("添加失败", 0);
  4673. }
  4674. return Result::success($result);
  4675. }
  4676. public function updateNotice(array $data): array
  4677. {
  4678. date_default_timezone_set('Asia/Shanghai');
  4679. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4680. $user_id = UserInfo::
  4681. //city_id不是null
  4682. whereNotNull('city_id')
  4683. ->whereNotNull('department_id')
  4684. ->where(function ($query) use ($data) {
  4685. $query->where(function ($subQuery) use ($data) {
  4686. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4687. });
  4688. })
  4689. ->where(function ($query) use ($data) {
  4690. $query->where(function ($subQuery) use ($data) {
  4691. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4692. });
  4693. })
  4694. ->pluck('user_id')->toArray();
  4695. $user_id = array_unique($user_id);
  4696. $user_id = json_encode($user_id);
  4697. $data['re_user_ids'] = $user_id;
  4698. $data['updated_at'] = date('Y-m-d H:i:s');
  4699. $this->sendMessage([
  4700. 'talk_type' => 700,
  4701. 'title' => $data['title'],
  4702. 'content' => '提交了审核',
  4703. 'messageType' => 5,
  4704. ]);
  4705. $result = Notice::where('id', $data['id'])->update($data);
  4706. return Result::success($result);
  4707. }
  4708. public function getNoticeList(array $data): array
  4709. {
  4710. $where = [];
  4711. //title
  4712. if (isset($data['title']) && !empty($data['title'])) {
  4713. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4714. }
  4715. //level
  4716. if (isset($data['level']) && !empty($data['level'])) {
  4717. $where[] = ['notice.level', '=', $data['level']];
  4718. }
  4719. //status
  4720. if (isset($data['status']) && !empty($data['status'])) {
  4721. $where[] = ['notice.status', '=', $data['status']];
  4722. }
  4723. //type
  4724. if (isset($data['type']) && !empty($data['type'])) {
  4725. $where[] = ['notice.type', '=', $data['type']];
  4726. }
  4727. var_dump($data, '------------11111-2----test---------');
  4728. if ($data['type_id'] == 10000) {
  4729. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4730. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4731. })
  4732. ->where($where)
  4733. ->orderBy('updated_at', 'desc')
  4734. ->limit($data['page_size'])
  4735. ->offset(($data['page'] - 1) * $data['page_size'])
  4736. ->get();
  4737. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4738. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4739. })
  4740. ->where($where)
  4741. ->orderBy('updated_at', 'desc')
  4742. ->count();
  4743. } else {
  4744. $result = Notice::where($where)
  4745. // ->where('user_id', $data['user_id'])
  4746. ->Where(function ($query) use ($data) {
  4747. $query->Where(function ($q) use ($data) {
  4748. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4749. ->orWhere('notice.user_id', $data['user_id']);
  4750. });
  4751. })
  4752. ->when(!empty($data['status1']), function ($query) use ($data) {
  4753. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4754. })
  4755. ->orderBy('updated_at', 'desc')
  4756. ->limit($data['page_size'])
  4757. ->offset(($data['page'] - 1) * $data['page_size'])
  4758. ->get();
  4759. $total = Notice::where($where)
  4760. ->when(!empty($data['status1']), function ($query) use ($data) {
  4761. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4762. })
  4763. // ->where('user_id', $data['user_id'])
  4764. ->Where(function ($query) use ($data) {
  4765. $query->Where(function ($q) use ($data) {
  4766. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4767. ->orWhere('notice.user_id', $data['user_id']);
  4768. });
  4769. })
  4770. ->count();
  4771. }
  4772. if (empty($result)) {
  4773. return Result::error("查询失败", 0);
  4774. }
  4775. $data = [
  4776. 'rows' => $result,
  4777. 'count' => $total,
  4778. ];
  4779. return Result::success($data);
  4780. }
  4781. public function noticeList(array $data): array
  4782. {
  4783. $where = [];
  4784. //title
  4785. if (isset($data['title']) && !empty($data['title'])) {
  4786. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4787. }
  4788. //level
  4789. if (isset($data['level']) && !empty($data['level'])) {
  4790. $where[] = ['notice.level', '=', $data['level']];
  4791. }
  4792. //status
  4793. if (isset($data['status']) && !empty($data['status'])) {
  4794. $where[] = ['notice.status', '=', $data['status']];
  4795. }
  4796. //type
  4797. if (isset($data['type']) && !empty($data['type'])) {
  4798. $where[] = ['notice.type', '=', $data['type']];
  4799. }
  4800. var_dump($data, '------------11111-2----test---------');
  4801. if ($data['type_id'] == 10000) {
  4802. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4803. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4804. })
  4805. ->where($where)
  4806. ->orderBy('updated_at', 'desc')
  4807. ->limit($data['page_size'])
  4808. ->offset(($data['page'] - 1) * $data['page_size'])
  4809. ->get();
  4810. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4811. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4812. })
  4813. ->where($where)
  4814. ->orderBy('updated_at', 'desc')
  4815. ->count();
  4816. } else {
  4817. $result = Notice::where($where)
  4818. // ->where('user_id', $data['user_id'])
  4819. ->Where(function ($query) use ($data) {
  4820. $query->Where(function ($q) use ($data) {
  4821. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4822. ->orWhere('notice.user_id', $data['user_id']);
  4823. });
  4824. })
  4825. ->when(!empty($data['status1']), function ($query) use ($data) {
  4826. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4827. })
  4828. ->orderBy('updated_at', 'desc')
  4829. ->limit($data['page_size'])
  4830. ->offset(($data['page'] - 1) * $data['page_size'])
  4831. ->get();
  4832. $total = Notice::where($where)
  4833. ->when(!empty($data['status1']), function ($query) use ($data) {
  4834. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4835. })
  4836. // ->where('user_id', $data['user_id'])
  4837. ->Where(function ($query) use ($data) {
  4838. $query->Where(function ($q) use ($data) {
  4839. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4840. ->orWhere('notice.user_id', $data['user_id']);
  4841. });
  4842. })
  4843. ->count();
  4844. }
  4845. if (empty($result)) {
  4846. return Result::error("查询失败", 0);
  4847. }
  4848. $data = [
  4849. 'rows' => $result,
  4850. 'count' => $total,
  4851. ];
  4852. return Result::success($data);
  4853. }
  4854. public function getNoticeDetail(array $data): array
  4855. {
  4856. $result = Notice::where('id', $data['id'])->first();
  4857. if (empty($result)) {
  4858. return Result::error("查询失败", 0);
  4859. }
  4860. return Result::success($result);
  4861. }
  4862. public function deleteNotice(array $data): array
  4863. {
  4864. $notice = Notice::where('id', $data['id'])->first();
  4865. if (empty($notice)) {
  4866. return Result::error("删除失败", 0);
  4867. }
  4868. $chat_group_id = $notice->group_id;
  4869. if ($chat_group_id) {
  4870. //删除群聊
  4871. ChatGroups::where('id', $chat_group_id)->delete();
  4872. //删除群成员
  4873. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4874. //删除群聊记录
  4875. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4876. }
  4877. $result = Notice::where('id', $data['id'])->delete();
  4878. return Result::success($result);
  4879. }
  4880. public function complaintList(array $data): array
  4881. {
  4882. var_dump($data, '---------1---------');
  4883. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4884. unset($data['type_id']);
  4885. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4886. $where = [];
  4887. if ($type_id != 10000 && empty($data['deal_user'])) {
  4888. // $where['complaint.user_id'] = $user_id;
  4889. }
  4890. if (!empty($data['title'])) {
  4891. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4892. }
  4893. if (!empty($data['department_id'])) {
  4894. $where['complaint.department_id'] = $data['department_id'];
  4895. }
  4896. if (!empty($data['deal'])) {
  4897. $where['complaint.deal'] = $data['deal'];
  4898. }
  4899. if (!empty($data['status'])) {
  4900. $where['complaint.status'] = $data['status'];
  4901. }
  4902. var_dump(!empty($data['deal_user']), '----------1');
  4903. var_dump($where, '----------2');
  4904. $result = Complaint::where($where)
  4905. ->when(!empty($data['status1']), function ($query) use ($data) {
  4906. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4907. })
  4908. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4909. //json re_user_ids data[user_id]是不是在里面
  4910. $query->Where(function ($q) use ($data) {
  4911. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4912. ->where('complaint.status', 2);
  4913. });
  4914. })
  4915. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4916. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4917. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4918. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4919. ->orderBy('updated_at', 'desc')
  4920. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4921. //sql输出
  4922. if (empty($result)) {
  4923. return Result::error("暂无投诉信息", 0);
  4924. }
  4925. // 取出数据
  4926. $rows = $result->items();
  4927. $count = $result->total();
  4928. $responseData = [
  4929. 'rows' => $rows,
  4930. 'count' => $count,
  4931. ];
  4932. return Result::success($responseData);
  4933. }
  4934. public function getComplaintList(array $data): array
  4935. {
  4936. var_dump($data, '00000001000000000000');
  4937. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4938. unset($data['type_id']);
  4939. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4940. $where = [];
  4941. if ($type_id != 10000 && empty($data['deal_user'])) {
  4942. $where['complaint.user_id'] = $user_id;
  4943. }
  4944. if (!empty($data['title'])) {
  4945. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4946. }
  4947. if (!empty($data['department_id'])) {
  4948. $where['complaint.department_id'] = $data['department_id'];
  4949. }
  4950. if (!empty($data['deal'])) {
  4951. $where['complaint.deal'] = $data['deal'];
  4952. }
  4953. if (!empty($data['status'])) {
  4954. $where['complaint.status'] = $data['status'];
  4955. }
  4956. var_dump(!empty($data['deal_user']), '----------1');
  4957. var_dump($where, '----------2');
  4958. $result = Complaint::where($where)
  4959. ->when(!empty($data['status1']), function ($query) use ($data) {
  4960. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4961. })
  4962. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4963. // //json re_user_ids data[user_id]是不是在里面
  4964. // $query->Where(function ($q) use ($data) {
  4965. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4966. // ->where('complaint.status', 2);
  4967. // });
  4968. // })
  4969. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4970. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4971. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4972. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4973. ->orderBy('updated_at', 'desc')
  4974. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4975. //sql输出
  4976. if (empty($result)) {
  4977. return Result::error("暂无投诉信息", 0);
  4978. }
  4979. // 取出数据
  4980. $rows = $result->items();
  4981. $count = $result->total();
  4982. $responseData = [
  4983. 'rows' => $rows,
  4984. 'count' => $count,
  4985. ];
  4986. return Result::success($responseData);
  4987. }
  4988. public function getComplaintInfo(array $data): array
  4989. {
  4990. $result = Complaint::where('id', $data['id'])->first();
  4991. if (empty($result)) {
  4992. return Result::error("查询失败", 0);
  4993. }
  4994. return Result::success($result);
  4995. }
  4996. public function readComplaint(array $data): array
  4997. {
  4998. $result = Complaint::where('id', $data['id'])->first();
  4999. if (empty($result)) {
  5000. return Result::error("查询失败", 0);
  5001. }
  5002. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  5003. $re_user_ids = json_decode($result['re_user_ids'], true);
  5004. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  5005. //如果已经存在,就不再添加
  5006. if (isset($result['read_id']) && !empty($result['read_id'])) {
  5007. $read_id = json_decode($result['read_id'], true);
  5008. if (!is_array($read_id)) {
  5009. $read_id = [];
  5010. }
  5011. if (!in_array($data['user_id'], $read_id)) {
  5012. $read_id[] = $data['user_id'];
  5013. $result['read_id'] = json_encode($read_id);
  5014. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  5015. }
  5016. } else {
  5017. //如果不存在,就添加
  5018. $result['read_id'] = json_encode([$data['user_id']]);
  5019. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  5020. }
  5021. }
  5022. return Result::success($result);
  5023. }
  5024. public function addComplaint(array $data): array
  5025. {
  5026. date_default_timezone_set('Asia/Shanghai');
  5027. $data['created_at'] = date('Y-m-d H:i:s');
  5028. $data['updated_at'] = date('Y-m-d H:i:s');
  5029. $this->sendMessage([
  5030. 'talk_type' => 800,
  5031. 'title' => $data['title'],
  5032. 'content' => '提交了审核',
  5033. 'messageType' => 6,
  5034. ]);
  5035. $result = Complaint::create($data);
  5036. return Result::success($result);
  5037. }
  5038. public function updateComplaint(array $data): array
  5039. {
  5040. date_default_timezone_set('Asia/Shanghai');
  5041. $data['updated_at'] = date('Y-m-d H:i:s');
  5042. $user_id = $data['user_id'] ?? 0;
  5043. $type_id = $data['type_id'] ?? 0;
  5044. unset($data['user_id']);
  5045. unset($data['type_id']);
  5046. $this->sendMessage([
  5047. 'talk_type' => 800,
  5048. 'title' => $data['title'],
  5049. 'content' => '提交了审核',
  5050. 'messageType' => 6,
  5051. ]);
  5052. $result = Complaint::where('id', $data['id'])->update($data);
  5053. return Result::success($result);
  5054. }
  5055. public function deleteComplaint(array $data): array
  5056. {
  5057. $result = Complaint::where('id', $data['id'])->delete();
  5058. return Result::success($result);
  5059. }
  5060. public function getComplainInfo(array $data): array
  5061. {
  5062. $result = Complaint::where('id', $data['id'])->first();
  5063. if (empty($result)) {
  5064. return Result::error("查询失败", 0);
  5065. }
  5066. return Result::success($result);
  5067. }
  5068. public function updateComplaintStatus(array $data): array
  5069. {
  5070. date_default_timezone_set('Asia/Shanghai');
  5071. $data['updated_at'] = date('Y-m-d H:i:s');
  5072. $user_id = $data['user_id'] ?? 0;
  5073. $type_id = $data['type_id'] ?? 0;
  5074. unset($data['user_id']);
  5075. unset($data['type_id']);
  5076. //处理, 写入处理人
  5077. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5078. $data['real_deal_user'] = $user_id;
  5079. }
  5080. //如果是deal 23,则判断是不是处理人
  5081. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5082. $complaintInof = Complaint::where('id', $data['id'])
  5083. ->where('real_deal_user', $user_id)
  5084. ->first();
  5085. if (empty($complaintInof)) {
  5086. return Result::error("处理人错误", 0);
  5087. }
  5088. }
  5089. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5090. if ($data['status'] == 1) {
  5091. $this->sendMessage([
  5092. 'talk_type' => 800,
  5093. 'title' => $complaintInfo['title'],
  5094. 'content' => '提交了审核',
  5095. 'messageType' => 6,
  5096. ]);
  5097. }
  5098. if ($data['status'] == 2 && !isset($data['deal'])) {
  5099. $this->sendMessage([
  5100. 'talk_type' => 801,
  5101. 'title' => $complaintInfo['title'],
  5102. 'content' => '审核通过',
  5103. 'messageType' => 6,
  5104. 'user_id' => $complaintInfo['user_id'],
  5105. ]);
  5106. $this->sendMessage([
  5107. 'talk_type' => 802,
  5108. 'title' => $complaintInfo['title'],
  5109. 'content' => '待处理',
  5110. 'messageType' => 6,
  5111. 'user_id' => $complaintInfo['re_user_ids'],
  5112. ]);
  5113. }
  5114. if ($data['status'] == 3 && !isset($data['deal'])) {
  5115. $this->sendMessage([
  5116. 'talk_type' => 801,
  5117. 'title' => $complaintInfo['title'],
  5118. 'content' => '审核拒绝',
  5119. 'messageType' => 6,
  5120. 'user_id' => $complaintInfo['user_id'],
  5121. ]);
  5122. }
  5123. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5124. $this->sendMessage([
  5125. 'talk_type' => 802,
  5126. 'title' => $complaintInfo['title'],
  5127. 'content' => '处理中',
  5128. 'messageType' => 6,
  5129. 'user_id' => $complaintInfo['re_user_ids'],
  5130. ]);
  5131. }
  5132. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5133. $this->sendMessage([
  5134. 'talk_type' => 802,
  5135. 'title' => $complaintInfo['title'],
  5136. 'content' => '不予处理',
  5137. 'messageType' => 6,
  5138. 'user_id' => $complaintInfo['re_user_ids'],
  5139. ]);
  5140. }
  5141. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5142. $this->sendMessage([
  5143. 'talk_type' => 802,
  5144. 'title' => $complaintInfo['title'],
  5145. 'content' => '已完结',
  5146. 'messageType' => 6,
  5147. 'user_id' => $complaintInfo['re_user_ids'],
  5148. ]);
  5149. }
  5150. $result = complaint::where('id', $data['id'])->update($data);
  5151. return Result::success($result);
  5152. }
  5153. public function updateGoodStatus(array $data): array
  5154. {
  5155. $user_id = $data['user_id'] ?? 0;
  5156. $type_id = $data['type_id'] ?? 0;
  5157. unset($data['user_id']);
  5158. unset($data['type_id']);
  5159. $goodInfo = Good::where('id', $data['id'])->first();
  5160. if ($data['status'] == 2) {
  5161. $this->sendMessage([
  5162. 'talk_type' => 201,
  5163. 'title' => $goodInfo['name'],
  5164. 'content' => '审核通过',
  5165. 'messageType' => 3,
  5166. 'user_id' => $goodInfo['user_id'],
  5167. ]);
  5168. }
  5169. if ($data['status'] == 3) {
  5170. $this->sendMessage([
  5171. 'talk_type' => 201,
  5172. 'title' => $goodInfo['name'],
  5173. 'content' => '审核拒绝',
  5174. 'messageType' => 3,
  5175. 'user_id' => $goodInfo['user_id'],
  5176. ]);
  5177. }
  5178. if ($data['status'] == 1) {
  5179. $this->sendMessage([
  5180. 'talk_type' => 200,
  5181. 'title' => $goodInfo['name'],
  5182. 'content' => '提交了审核',
  5183. 'messageType' => 3,
  5184. ]);
  5185. }
  5186. $result = Good::where('id', $data['id'])->update($data);
  5187. return Result::success($result);
  5188. }
  5189. public function updateJobHuntingStatus(array $data): array
  5190. {
  5191. $user_id = $data['user_id'] ?? 0;
  5192. $type_id = $data['type_id'] ?? 0;
  5193. unset($data['user_id']);
  5194. unset($data['type_id']);
  5195. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5196. if ($data['status'] == 2) {
  5197. $this->sendMessage([
  5198. 'talk_type' => 601,
  5199. 'title' => $jogHuntingInfo['name'],
  5200. 'content' => '审核通过',
  5201. 'messageType' => 11,
  5202. 'user_id' => $jogHuntingInfo['user_id'],
  5203. ]);
  5204. }
  5205. if ($data['status'] == 3) {
  5206. $this->sendMessage([
  5207. 'talk_type' => 601,
  5208. 'title' => $jogHuntingInfo['name'],
  5209. 'content' => '审核拒绝',
  5210. 'messageType' => 11,
  5211. 'user_id' => $jogHuntingInfo['user_id'],
  5212. ]);
  5213. }
  5214. if ($data['status'] == 1) {
  5215. $this->sendMessage([
  5216. 'talk_type' => 600,
  5217. 'title' => $jogHuntingInfo['name'],
  5218. 'content' => '提交了审核',
  5219. 'messageType' => 11,
  5220. ]);
  5221. }
  5222. $result = JobHunting::where('id', $data['id'])->update($data);
  5223. return Result::success($result);
  5224. }
  5225. public function updateNoticeStatus(array $data): array
  5226. {
  5227. $user_id = $data['user_id'] ?? 0;
  5228. $type_id = $data['type_id'] ?? 0;
  5229. unset($data['user_id']);
  5230. unset($data['type_id']);
  5231. //查询公告
  5232. $notice = Notice::where('id', $data['id'])->first();
  5233. if (empty($notice)) {
  5234. return Result::error("公告不存在", 0);
  5235. }
  5236. //$chat_ids 去除掉$data['user_id']
  5237. $chat_ids = json_decode($notice['re_user_ids'], true);
  5238. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5239. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5240. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5241. //chat_group
  5242. $group_id = PublicData::uuid();
  5243. $groupData = [
  5244. 'id' => $group_id,
  5245. 'creator_id' => $notice['user_id'],
  5246. 'group_name' => $notice['group_name'] ?? '',
  5247. 'profile' => $notice['profile'] ?? 0,
  5248. ];
  5249. var_dump($groupData, '-----------------groupData-------');
  5250. $groupResult = ChatGroups::insertGetId($groupData);
  5251. var_dump($groupResult, '-----------------groupid-------');
  5252. $groupMemberData = [
  5253. 'id' => PublicData::uuid(),
  5254. 'user_id' => $notice['user_id'],
  5255. 'group_id' => $group_id,
  5256. 'leader' => 2,
  5257. ];
  5258. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5259. //插入群成员表
  5260. $groupMemberDataUser = [];
  5261. $chatData = [];
  5262. foreach ($chat_ids as $key => $value) {
  5263. $groupMemberDataUser[] = [
  5264. 'id' => PublicData::uuid(),
  5265. 'user_id' => $value,
  5266. 'group_id' => $group_id,
  5267. 'leader' => 1,
  5268. ];
  5269. $chatData[] = [
  5270. 'user_id' => $value,
  5271. 'msg_type' => 1,
  5272. 'receiver_id' => $group_id,
  5273. 'content' => '通过通知创建群聊',
  5274. 'group_receiver_id' => $notice['user_id'],
  5275. 'action' => 'recieved',
  5276. 'created_at' => date('Y-m-d H:i:s'),
  5277. ];
  5278. }
  5279. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5280. ChatGroupsMember::insert($groupMemberDataUser);
  5281. //插入一条管理员聊天记录
  5282. $chatData[] = [
  5283. 'user_id' => $notice['user_id'],
  5284. 'msg_type' => 1,
  5285. 'receiver_id' => $group_id,
  5286. 'content' => '通过通知创建群聊',
  5287. 'group_receiver_id' => $notice['user_id'],
  5288. 'action' => 'said',
  5289. 'created_at' => date('Y-m-d H:i:s'),
  5290. ];
  5291. var_dump($chatData, '-----------------chatData-------');
  5292. $chatResult = ChatRecords::insert($chatData);
  5293. //处理imp
  5294. $group = [
  5295. 'type' => 1,
  5296. 'name' => $notice['group_name'] ?? '',
  5297. 'profile' => '',
  5298. 'avatar' => '',
  5299. 'creator_id' => $notice['user_id'],
  5300. ];
  5301. $groupResult = GroupImp::insertGetId($group);
  5302. var_dump($groupResult, '获取imp group_id');
  5303. $groupMember = [
  5304. 'user_id' => $notice['user_id'],
  5305. 'group_id' => $groupResult,
  5306. 'leader' => 1,
  5307. 'join_time' => Date('Y-m-d H:i:s')
  5308. ];
  5309. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5310. $talk_session = [
  5311. 'user_id' => $notice['user_id'],
  5312. 'to_from_id' => $groupResult,
  5313. 'talk_mode' => 2,
  5314. 'created_at' => Date('Y-m-d H:i:s'),
  5315. 'updated_at' => Date('Y-m-d H:i:s'),
  5316. ];
  5317. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5318. //被通知人员处理
  5319. foreach ($chat_ids as $key => $value) {
  5320. $groupMemberdata[] = [
  5321. 'user_id' => $value,
  5322. 'group_id' => $groupResult,
  5323. 'leader' => 3,
  5324. 'join_time' => Date('Y-m-d H:i:s')
  5325. ];
  5326. $talk_sessionData[] = [
  5327. 'user_id' => $value,
  5328. 'to_from_id' => $groupResult,
  5329. 'talk_mode' => 2,
  5330. 'created_at' => Date('Y-m-d H:i:s'),
  5331. 'updated_at' => Date('Y-m-d H:i:s'),
  5332. ];
  5333. }
  5334. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5335. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5336. $group_id = $groupResult;
  5337. //更新result的 group_id
  5338. $data['group_id'] = $group_id;
  5339. Notice::where(['id' => $data['id']])->update($data);
  5340. }
  5341. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5342. //删除掉信息
  5343. GroupImp::where('id', $notice['group_id'])->delete();
  5344. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5345. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5346. foreach ($chat_ids as $key => $value) {
  5347. }
  5348. //聊天记录删除
  5349. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5350. $data['group_id'] = null;
  5351. Notice::where(['id' => $data['id']])->update($data);
  5352. }
  5353. $result = Notice::where('id', $data['id'])->update($data);
  5354. $noticeInfo = Notice::where('id', $data['id'])->first();
  5355. if ($data['status'] == 2) {
  5356. $this->sendMessage([
  5357. 'talk_type' => 701,
  5358. 'title' => $noticeInfo['title'],
  5359. 'content' => '审核通过',
  5360. 'messageType' => 3,
  5361. 'user_id' => $noticeInfo['user_id'],
  5362. ]);
  5363. }
  5364. if ($data['status'] == 3) {
  5365. $this->sendMessage([
  5366. 'talk_type' => 701,
  5367. 'title' => $noticeInfo['title'],
  5368. 'content' => '审核拒绝',
  5369. 'messageType' => 3,
  5370. 'user_id' => $noticeInfo['user_id'],
  5371. ]);
  5372. }
  5373. if ($data['status'] == 1) {
  5374. $this->sendMessage([
  5375. 'talk_type' => 700,
  5376. 'title' => $noticeInfo['title'],
  5377. 'content' => '提交了审核',
  5378. 'messageType' => 3,
  5379. ]);
  5380. }
  5381. return Result::success($result);
  5382. }
  5383. public function getDUser(array $data): array
  5384. {
  5385. if (!empty($data['ids'])) {
  5386. $user = User::whereIn('id', $data['ids'])->getall();
  5387. if (empty($user)) {
  5388. return Result::error('无数据', 0);
  5389. }
  5390. return Result::success($user);
  5391. }
  5392. $where = [];
  5393. if (!empty($data['department_id'])) {
  5394. $where['department_id'] = $data['department_id'];
  5395. }
  5396. if (!empty($data['city_id'])) {
  5397. $where['city_id'] = $data['city_id'];
  5398. }
  5399. $result = User::where('type_id', 2)
  5400. ->where('status', 1)
  5401. ->where($where)
  5402. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5403. ->get();
  5404. if (empty($result)) {
  5405. return Result::error("查询失败", 0);
  5406. }
  5407. return Result::success($result);
  5408. }
  5409. /**
  5410. * 验证导航名称是否重复
  5411. * @return void
  5412. */
  5413. public function checkCategoryName(array $data): array
  5414. {
  5415. $result = Category::when($data, function ($query) use ($data) {
  5416. if (isset($data['name']) && $data['name']) {
  5417. $query->where("name", $data['name']);
  5418. }
  5419. if (isset($data['id']) && $data['id']) {
  5420. $query->where("id", "!=", $data['id']);
  5421. }
  5422. })->first();
  5423. if ($result) {
  5424. return Result::error("已存在");
  5425. } else {
  5426. return Result::success();
  5427. }
  5428. }
  5429. //20250226 产品列表
  5430. // 20250306 -------招聘--------fr
  5431. /*
  5432. * 招聘列表
  5433. * */
  5434. public function getJobRecruitingList(array $data): array
  5435. {
  5436. $where = [];
  5437. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5438. if ($data['checkout'] == 0) {
  5439. $job_status = [0, 2];
  5440. } else {
  5441. $job_status = [1];
  5442. }
  5443. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5444. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5445. }
  5446. $user = User::where('id', $data['user_id'])->first();
  5447. if (empty($user)) {
  5448. return Result::error("用户不存在", 0);
  5449. }
  5450. // 3:企业会员
  5451. if ($user['type_id'] == 3) {
  5452. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5453. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5454. }
  5455. // 如果 $where 为空,则不添加 where 条件
  5456. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5457. return $query->where($where);
  5458. })
  5459. ->whereIn('job_recruiting.status', $job_status)
  5460. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5461. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5462. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5463. ->orderBy("updated_at", "desc")
  5464. ->offset(($data['page'] - 1) * $data['page_size'])
  5465. ->limit($data['page_size'])
  5466. ->get()
  5467. ->all();
  5468. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5469. return $query->where($where);
  5470. })
  5471. ->whereIn('job_recruiting.status', $job_status)
  5472. ->count();
  5473. if (empty($result)) {
  5474. return Result::error("暂无招聘信息", 0);
  5475. }
  5476. return Result::success($result);
  5477. }
  5478. /*
  5479. * 招聘信息添加
  5480. * */
  5481. public function addJobRecruiting(array $data): array
  5482. {
  5483. // var_dump('添加招聘进入news------data',$data);
  5484. // return Result::success($data);
  5485. $user = User::where('user.id', $data['user_id'])
  5486. ->where('user.status', 1)
  5487. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5488. ->select(
  5489. 'user.type_id',
  5490. 'user.mobile',
  5491. 'user.email',
  5492. 'user_info.business_name',
  5493. 'user_info.company_hy_id',
  5494. 'user_info.company_nature',
  5495. 'user_info.company_size',
  5496. 'user_info.introduction',
  5497. 'user_info.real_name',
  5498. 'user_info.company_url',
  5499. 'user_info.address_arr_id',
  5500. 'user_info.address'
  5501. )
  5502. ->first();
  5503. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5504. return Result::error("用户不存在", 0);
  5505. }
  5506. $web = Website::where('id', $data['website_id'])->first();
  5507. if (empty($web)) {
  5508. return Result::error("网站不存在", 0);
  5509. }
  5510. // var_dump('添加招聘进入news---user---user',$user);
  5511. // 处理招聘关键词
  5512. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5513. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5514. } else {
  5515. Jieba::init(); // 初始化 jieba-php
  5516. Finalseg::init();
  5517. $segList = Jieba::cut($data['title']);
  5518. $segList1 = array_slice($segList, 0, 8);
  5519. $data['keyword'] = implode(',', $segList1);
  5520. }
  5521. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5522. $content = $data['description'];
  5523. // 去除 <style> 和 <script> 标签及其内容
  5524. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5525. // 去除所有 HTML 标签
  5526. $content = strip_tags($content);
  5527. // 去除 HTML 实体
  5528. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5529. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5530. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5531. // 去除多余空白
  5532. $content = preg_replace('/\s+/u', '', $content);
  5533. // 截取 100 个字符
  5534. $data['seo_description'] = mb_substr($content, 0, 100);
  5535. }
  5536. // return Result::success($user);
  5537. $data['action_id'] = $data['user_id'] ?? null;
  5538. $data['user_type'] = $user['type_id'] ?? null;
  5539. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5540. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5541. $data['catid'] = end($data['cat_arr_id']);
  5542. } else {
  5543. $data['catid'] = 0;
  5544. }
  5545. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5546. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5547. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5548. // 公司地址 管理员必填
  5549. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5550. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5551. // 管理员-企业相关信息
  5552. $company = [
  5553. // 'user_id' => $data['user_id']?? null,
  5554. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5555. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5556. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5557. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5558. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5559. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5560. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5561. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5562. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5563. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5564. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5565. ];
  5566. //去掉相关企业信息
  5567. $job = array_diff_key($data, array_flip(array_keys($company)));
  5568. // var_dump('添加招聘进入news---job---user',$job);
  5569. Db::beginTransaction();
  5570. try {
  5571. // // 先添加职位相关信息
  5572. if ($user['type_id'] == 10000) {
  5573. $job['status'] = 1;
  5574. }
  5575. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5576. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5577. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5578. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5579. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5580. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5581. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5582. // return Result::success($job);
  5583. $jobId = JobRecruiting::insertGetId($job);
  5584. if (empty($jobId)) {
  5585. Db::rollBack();
  5586. return Result::error("添加失败");
  5587. }
  5588. // 添加公司信息
  5589. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5590. $company['job_id'] = $jobId;
  5591. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5592. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5593. if ($user['type_id'] == 10000) {
  5594. // 管理员添加企业信息
  5595. $companyId = JobCompany::insertGetId($company);
  5596. if (empty($companyId)) {
  5597. Db::rollBack();
  5598. return Result::error("添加失败");
  5599. }
  5600. } else {
  5601. // 企业会员添加企业信息
  5602. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5603. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5604. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5605. $company['job_id'] = $jobId;
  5606. $companyId = JobCompany::insertGetId($company);
  5607. if (empty($companyId)) {
  5608. Db::rollBack();
  5609. return Result::error("添加失败");
  5610. }
  5611. }
  5612. Db::commit();
  5613. $result = [
  5614. 'job_id' => $jobId,
  5615. 'company_id' => $companyId,
  5616. ];
  5617. return Result::success($result);
  5618. } catch (\Exception $e) {
  5619. Db::rollBack();
  5620. return Result::error($e->getMessage(), 0);
  5621. }
  5622. // return Result::success($result);
  5623. }
  5624. /*
  5625. * 获取招聘信息详情
  5626. * */
  5627. public function getJobRecruitingInfo(array $data): array
  5628. {
  5629. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5630. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5631. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5632. ->select(
  5633. 'job_recruiting.*',
  5634. 'website.website_name as website_name',
  5635. 'job_company.business_name',
  5636. 'job_company.company_hy_id',
  5637. 'job_company.company_size',
  5638. 'job_company.company_nature',
  5639. 'job_company.introduction',
  5640. 'job_company.real_name',
  5641. 'job_company.mobile',
  5642. 'job_company.company_url',
  5643. 'job_company.address_arr_id',
  5644. 'job_company.address',
  5645. 'job_company.email'
  5646. )
  5647. ->first();
  5648. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5649. if (!empty($cityId)) {
  5650. if (isset($cityId[1]) && $cityId[1] != null) {
  5651. $city = District::where('id', $cityId[1])->first(['name']);
  5652. } else {
  5653. $city = District::where('id', $cityId[0])->first(['name']);
  5654. }
  5655. $result['city'] = $city['name'] ?? '';
  5656. }
  5657. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5658. if (is_array($addressId) && !empty($addressId)) {
  5659. $address = District::whereIn('id', $addressId)
  5660. ->orderBy('level', 'asc')
  5661. ->get(['name'])
  5662. ->pluck('name')
  5663. ->implode('');
  5664. // $job->address_name = $address ?? '';
  5665. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5666. }
  5667. if (empty($result)) {
  5668. return Result::error("招聘信息不存在", 0);
  5669. }
  5670. // return Result::success($job);
  5671. return Result::success($result);
  5672. }
  5673. /*
  5674. * 修改招聘信息
  5675. * */
  5676. public function upJobRecruiting(array $data): array
  5677. {
  5678. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5679. // return Result::success($job);
  5680. if (empty($job)) {
  5681. return Result::error("招聘信息不存在", 0);
  5682. }
  5683. $user = User::where('id', $data['user_id'])->first();
  5684. // return Result::success($user);
  5685. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5686. return Result::error("用户不存在", 0);
  5687. }
  5688. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5689. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5690. }
  5691. // 处理招聘关键词
  5692. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5693. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5694. } else {
  5695. Jieba::init(); // 初始化 jieba-php
  5696. Finalseg::init();
  5697. $segList = Jieba::cut($data['title']);
  5698. $segList1 = array_slice($segList, 0, 8);
  5699. $data['keyword'] = implode(',', $segList1);
  5700. }
  5701. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5702. $content = $data['description'];
  5703. // 去除 <style> 和 <script> 标签及其内容
  5704. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5705. // 去除所有 HTML 标签
  5706. $content = strip_tags($content);
  5707. // 去除 HTML 实体
  5708. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5709. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5710. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5711. // 去除多余空白
  5712. $content = preg_replace('/\s+/u', '', $content);
  5713. // 截取 100 个字符
  5714. $data['seo_description'] = mb_substr($content, 0, 100);
  5715. }
  5716. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5717. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5718. $data['catid'] = end($data['cat_arr_id']);
  5719. } else {
  5720. }
  5721. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5722. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5723. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5724. // 公司地址 管理员必填
  5725. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5726. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5727. // 管理员-企业相关信息
  5728. $company = [
  5729. // 'user_id' => $data['user_id']?? null,
  5730. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5731. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5732. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5733. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5734. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5735. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5736. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5737. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5738. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5739. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5740. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5741. ];
  5742. //去掉相关企业信息
  5743. $data = array_diff_key($data, array_flip(array_keys($company)));
  5744. $jobId = $data['id'];
  5745. $web = $data['website_id'];
  5746. $data['action_id'] = $data['user_id'];
  5747. unset($data['user_id']);
  5748. unset($data['user_type']);
  5749. unset($data['id']);
  5750. unset($data['website_id']);
  5751. // return Result::success($data);
  5752. Db::beginTransaction();
  5753. try {
  5754. // 管理员修改招聘信息
  5755. if ($user['type_id'] == 10000) {
  5756. $data['website_id'] = $web;
  5757. $company['website_id'] = $data['website_id'];
  5758. $data['status'] = 1;
  5759. } else {
  5760. $data['status'] = 0;
  5761. }
  5762. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5763. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5764. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5765. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5766. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5767. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5768. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5769. // return Result::success($job);
  5770. // Db::rollBack();
  5771. // return Result::success($company);
  5772. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5773. $this->sendMessage([
  5774. 'talk_type' => 500,
  5775. 'title' => $data['title'],
  5776. 'content' => '提交了审核',
  5777. 'messageType' => 10,
  5778. ]);
  5779. }
  5780. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5781. if (empty($result['job'])) {
  5782. Db::rollBack();
  5783. return Result::error("修改招聘信息失败");
  5784. }
  5785. // 管理员修改企业相关信息
  5786. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5787. if (empty($result['company'])) {
  5788. Db::rollBack();
  5789. return Result::error("修改企业相关信息失败");
  5790. }
  5791. Db::commit();
  5792. // return Result::success($result);
  5793. } catch (\Exception $e) {
  5794. Db::rollBack();
  5795. return Result::error($e->getMessage(), 0);
  5796. }
  5797. return Result::success($result);
  5798. }
  5799. /*
  5800. * 招聘信息删除
  5801. * */
  5802. public function delJobRecruiting(array $data): array
  5803. {
  5804. $user = User::where('id', $data['user_id'])->first();
  5805. if (empty($user)) {
  5806. return Result::error("用户不存在", 0);
  5807. }
  5808. $job = JobRecruiting::where('id', $data['id'])->first();
  5809. if (empty($job)) {
  5810. return Result::error("招聘信息不存在", 0);
  5811. }
  5812. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5813. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5814. }
  5815. Db::beginTransaction();
  5816. try {
  5817. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5818. if (empty($result['job'])) {
  5819. Db::rollBack();
  5820. return Result::error("删除招聘信息失败");
  5821. }
  5822. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5823. if (empty($result['company'])) {
  5824. Db::rollBack();
  5825. return Result::error("删除企业相关信息失败");
  5826. }
  5827. Db::commit();
  5828. } catch (\Exception $e) {
  5829. Db::rollBack();
  5830. return Result::error($e->getMessage(), 0);
  5831. }
  5832. return Result::success($result);
  5833. }
  5834. /*
  5835. * 获取公司信息
  5836. * */
  5837. public function getJobCompany(array $data): array
  5838. {
  5839. $user = User::where('user.id', $data['user_id'])
  5840. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5841. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5842. ->first();
  5843. // return Result::success($user);
  5844. if (empty($user)) {
  5845. return Result::error("用户不存在", 0);
  5846. }
  5847. if ($user['type_id'] == 3) {
  5848. $result = [
  5849. // 'id' => 0,
  5850. 'user_id' => $data['user_id'],
  5851. 'website_id' => $data['website_id'],
  5852. 'business_name' => $user['business_name'], // 企业名称
  5853. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5854. 'company_nature' => $user['company_nature'], // 公司性质
  5855. 'company_size' => $user['company_size'], // 公司规模
  5856. 'introduction' => $user['introduction'], // 公司简介
  5857. 'real_name' => $user['real_name'], // 企业联系人
  5858. 'mobile' => $user['mobile'], // 企业联系电话
  5859. 'company_url' => $user['company_url'], // 企业网址
  5860. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5861. 'address' => $user['address'], // 企业地址
  5862. 'email' => $user['email'], // 企业邮箱
  5863. ];
  5864. } else {
  5865. return Result::error("用户类型错误", 0);
  5866. }
  5867. if (empty($result)) {
  5868. return Result::error("公司信息不存在", 0);
  5869. }
  5870. return Result::success($result);
  5871. }
  5872. /*
  5873. * 修改公司信息
  5874. * */
  5875. public function upJobCompany(array $data): array
  5876. {
  5877. // return Result::success($data);
  5878. $user = User::where('user.id', $data['user_id'])
  5879. ->where('user.status', 1)
  5880. ->select('user.user_name', 'user.type_id')
  5881. ->first();
  5882. if (empty($user)) {
  5883. return Result::error("用户不存在", 0);
  5884. }
  5885. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5886. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5887. $company = [
  5888. 'business_name' => $data['business_name'], // 企业名称
  5889. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5890. 'company_nature' => $data['company_nature'], // 公司性质
  5891. 'company_size' => $data['company_size'], // 公司规模
  5892. 'introduction' => $data['introduction'], // 公司简介
  5893. // 'real_name' => $data['real_name'], // 企业联系人
  5894. 'company_url' => $data['company_url'], // 企业网址
  5895. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5896. 'address' => $data['address'], // 企业详细地址
  5897. // 'email' => $data['email'], // 企业邮箱
  5898. ];
  5899. if ($user['type_id'] == 3) {
  5900. Db::beginTransaction();
  5901. try {
  5902. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5903. 'business_name' => $data['business_name'], // 企业名称
  5904. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5905. 'company_nature' => $data['company_nature'], // 公司性质
  5906. 'company_size' => $data['company_size'], // 公司规模
  5907. 'introduction' => $data['introduction'], // 公司简介
  5908. // 'real_name' => $data['real_name'], // 企业联系人
  5909. 'company_url' => $data['company_url'], // 企业网址
  5910. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5911. 'address' => $data['address'], // 企业详细地址
  5912. ]);
  5913. if (empty($result['userinfo'])) {
  5914. Db::rollBack();
  5915. return Result::error('修改企业会员信息失败!');
  5916. }
  5917. $result['user'] = User::where('id', $data['user_id'])->update([
  5918. 'email' => $data['email'], // 企业邮箱
  5919. ]);
  5920. if (empty($result['user'])) {
  5921. Db::rollBack();
  5922. return Result::error('修改个人中心信息失败!');
  5923. }
  5924. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5925. if (!empty($job_company)) {
  5926. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5927. if (empty($result['job_company'])) {
  5928. Db::rollBack();
  5929. return Result::error('修改企业会员信息失败!');
  5930. }
  5931. }
  5932. Db::commit();
  5933. return Result::success($result);
  5934. } catch (\Exception $e) {
  5935. Db::rollBack();
  5936. return Result::error($e->getMessage(), 0);
  5937. }
  5938. } else {
  5939. return Result::error("用户类型错误", 0);
  5940. }
  5941. }
  5942. /*
  5943. * 获取省-市
  5944. * */
  5945. public function getJobRecruitingArea(array $data): array
  5946. {
  5947. if (isset($data['pid']) && $data['pid'] != null) {
  5948. $result = District::where('pid', $data['pid'])->get()->all();
  5949. } else {
  5950. $result = District::where('level', 1)->get()->all();
  5951. }
  5952. if (empty($result)) {
  5953. return Result::error("暂无此省市", 0);
  5954. }
  5955. return Result::success($result);
  5956. }
  5957. /*
  5958. * 获取行业分类
  5959. * */
  5960. public function getIndustry(array $data): array
  5961. {
  5962. $result = JobIndustry::get()->all();
  5963. if (empty($result)) {
  5964. return Result::error("暂无行业分类", 0);
  5965. }
  5966. return Result::success($result);
  5967. }
  5968. /*
  5969. * 获取职位
  5970. * */
  5971. public function getPositionList(array $data): array
  5972. {
  5973. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5974. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5975. } else {
  5976. $result = JobPosition::where('zwpid', 0)->get()->all();
  5977. }
  5978. if (empty($result)) {
  5979. return Result::error("暂无此职位", 0);
  5980. }
  5981. return Result::success($result);
  5982. }
  5983. /*
  5984. * 获取工作性质-菜单
  5985. * */
  5986. public function getJobNature(array $data): array
  5987. {
  5988. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5989. if (empty($result)) {
  5990. return Result::error("暂无工作性质", 0);
  5991. }
  5992. return Result::success($result);
  5993. }
  5994. /*
  5995. * 获取工作经验-菜单
  5996. * */
  5997. public function getExperience(array $data): array
  5998. {
  5999. $result = JobEnum::where('egroup', 'years')->get()->all();
  6000. if (empty($result)) {
  6001. return Result::error("暂无工作经验", 0);
  6002. }
  6003. return Result::success($result);
  6004. }
  6005. /*
  6006. * 获取学历-菜单
  6007. * */
  6008. public function getEducation(array $data): array
  6009. {
  6010. $result = JobEnum::where('egroup', 'education')->get()->all();
  6011. if (empty($result)) {
  6012. return Result::error("暂无学历", 0);
  6013. }
  6014. return Result::success($result);
  6015. }
  6016. /*
  6017. * 获取薪资-菜单
  6018. * */
  6019. public function getSalary(array $data): array
  6020. {
  6021. $result = JobEnum::where('egroup', 'income')->get()->all();
  6022. if (empty($result)) {
  6023. return Result::error("暂无薪资", 0);
  6024. }
  6025. return Result::success($result);
  6026. }
  6027. /*
  6028. * 获取语言-菜单
  6029. * */
  6030. public function getLanguage(array $data): array
  6031. {
  6032. $result = JobEnum::where('egroup', 'language')->get()->all();
  6033. if (empty($result)) {
  6034. return Result::error("暂无语言", 0);
  6035. }
  6036. return Result::success($result);
  6037. }
  6038. /*
  6039. * 获取掌握程度-菜单
  6040. * */
  6041. public function getLevel(array $data): array
  6042. {
  6043. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6044. if (empty($result)) {
  6045. return Result::error("暂无工作性质", 0);
  6046. }
  6047. return Result::success($result);
  6048. }
  6049. // 公司信息
  6050. /*
  6051. * 获取公司性质-菜单
  6052. * */
  6053. public function getCompanyNature(array $data): array
  6054. {
  6055. $result = JobNature::get()->all();
  6056. if (empty($result)) {
  6057. return Result::error("暂无公司性质", 0);
  6058. }
  6059. return Result::success($result);
  6060. }
  6061. /*
  6062. * 获取公司规模-菜单
  6063. * */
  6064. public function getCompanySize(array $data): array
  6065. {
  6066. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6067. if (empty($result)) {
  6068. return Result::error("暂无公司规模", 0);
  6069. }
  6070. return Result::success($result);
  6071. }
  6072. /*
  6073. * 招聘信息审核
  6074. * */
  6075. public function checkJobRecruiting(array $data): array
  6076. {
  6077. $user = User::where('id', $data['user_id'])->first();
  6078. if (empty($user)) {
  6079. return Result::error("用户不存在", 0);
  6080. }
  6081. $job = JobRecruiting::where('id', $data['id'])->first();
  6082. if (empty($job)) {
  6083. return Result::error("招聘信息不存在", 0);
  6084. }
  6085. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6086. if ($user['type_id'] != 10000) {
  6087. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6088. }
  6089. // 驳回原因
  6090. if ($data['status'] == 2) {
  6091. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6092. }
  6093. $data['action_id'] = $data['user_id'];
  6094. unset($data['user_id']);
  6095. if ($data['status'] == 1) {
  6096. $this->sendMessage([
  6097. 'talk_type' => 501,
  6098. 'title' => $job['title'],
  6099. 'content' => '审核通过',
  6100. 'messageType' => 10,
  6101. 'user_id' => $job['user_id'],
  6102. ]);
  6103. }
  6104. if ($data['status'] == 2) {
  6105. $this->sendMessage([
  6106. 'talk_type' => 501,
  6107. 'title' => $job['title'],
  6108. 'content' => '审核拒绝',
  6109. 'messageType' => 10,
  6110. 'user_id' => $job['user_id'],
  6111. ]);
  6112. }
  6113. if ($data['status'] == 0) {
  6114. $this->sendMessage([
  6115. 'talk_type' => 500,
  6116. 'title' => $job['title'],
  6117. 'content' => '提交了审核',
  6118. 'messageType' => 10,
  6119. ]);
  6120. }
  6121. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6122. if (empty($result)) {
  6123. return Result::error("审核失败", 0);
  6124. }
  6125. return Result::success($result);
  6126. }
  6127. public function myApplyList(array $data): array
  6128. {
  6129. var_dump($data, '------参数');
  6130. $user = User::where('id', $data['user_id'])->first();
  6131. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6132. return Result::error("用户不存在", 0);
  6133. }
  6134. // 1:个人会员 职场机会
  6135. if ($user['type_id'] == 1) {
  6136. $where['user_id'] = $user['id'];
  6137. }
  6138. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6139. $query->where('user_id', $user['id']);
  6140. })
  6141. ->pluck('recruit_id');
  6142. $where = [];
  6143. if (isset($data['salary']) && $data['salary'] != null) {
  6144. $where['job_recruiting.salary'] = $data['salary'];
  6145. }
  6146. if (isset($data['experience']) && $data['experience'] != null) {
  6147. $where['job_recruiting.experience'] = $data['experience'];
  6148. }
  6149. if (isset($data['business_name']) && $data['business_name'] != null) {
  6150. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6151. }
  6152. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6153. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6154. ->where($where);
  6155. // ->count();
  6156. $count = $query->count();
  6157. $query = clone $query;
  6158. $job = $query
  6159. ->leftJoin('job_enum as income_enum', function ($join) {
  6160. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6161. ->where('income_enum.egroup', 'income');
  6162. })
  6163. ->leftJoin('job_enum as years_enum', function ($join) {
  6164. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6165. ->where('years_enum.egroup', 'years');
  6166. })
  6167. // ->where($where)
  6168. ->orderBy('job_recruiting.updated_at', 'desc')
  6169. ->select(
  6170. 'job_recruiting.id',
  6171. 'job_recruiting.title',
  6172. 'job_company.business_name',
  6173. 'income_enum.evalue as salary_evalue',
  6174. 'income_enum.ename as salary_ename',
  6175. 'years_enum.evalue as experience_evalue',
  6176. 'years_enum.ename as experience_ename',
  6177. 'job_recruiting.updated_at'
  6178. )
  6179. ->offset(($data['page'] - 1) * $data['pageSize'])
  6180. ->limit($data['pageSize'])
  6181. ->get()
  6182. ->all();
  6183. if (empty($job)) {
  6184. return Result::error("暂无招聘信息", 0);
  6185. }
  6186. $result = [
  6187. 'row' => $job,
  6188. 'count' => $count,
  6189. ];
  6190. return Result::success($result);
  6191. }
  6192. public function readJobApply(array $data): array
  6193. {
  6194. $result = JobApply::where('id', $data['id'])->first();
  6195. if (empty($result)) {
  6196. return Result::error("查询失败", 0);
  6197. }
  6198. $result = JobApply::where('id', $data['id'])->update([
  6199. 'status' => 2,
  6200. ]);
  6201. return Result::success($result);
  6202. }
  6203. /*
  6204. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6205. * */
  6206. public function getRecruitingList(array $data): array
  6207. {
  6208. $user = User::where('id', $data['user_id'])->first();
  6209. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6210. return Result::error("用户不存在", 0);
  6211. }
  6212. // 1:个人会员 职场机会
  6213. if ($user['type_id'] == 1) {
  6214. $where['user_id'] = $user['id'];
  6215. }
  6216. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6217. $query->where('receiver_id', $user['id']);
  6218. })
  6219. ->pluck('recruit_id');
  6220. // return Result::success($recruitingId);
  6221. $where = [];
  6222. if (isset($data['salary']) && $data['salary'] != null) {
  6223. $where['job_recruiting.salary'] = $data['salary'];
  6224. }
  6225. if (isset($data['experience']) && $data['experience'] != null) {
  6226. $where['job_recruiting.experience'] = $data['experience'];
  6227. }
  6228. if (isset($data['business_name']) && $data['business_name'] != null) {
  6229. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6230. }
  6231. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6232. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6233. ->where($where);
  6234. // ->count();
  6235. $count = $query->count();
  6236. $query = clone $query;
  6237. $job = $query
  6238. ->leftJoin('job_enum as income_enum', function ($join) {
  6239. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6240. ->where('income_enum.egroup', 'income');
  6241. })
  6242. ->leftJoin('job_enum as years_enum', function ($join) {
  6243. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6244. ->where('years_enum.egroup', 'years');
  6245. })
  6246. // ->where($where)
  6247. ->orderBy('job_recruiting.updated_at', 'desc')
  6248. ->select(
  6249. 'job_recruiting.id',
  6250. 'job_recruiting.title',
  6251. 'job_company.business_name',
  6252. 'income_enum.evalue as salary_evalue',
  6253. 'income_enum.ename as salary_ename',
  6254. 'years_enum.evalue as experience_evalue',
  6255. 'years_enum.ename as experience_ename',
  6256. 'job_recruiting.updated_at'
  6257. )
  6258. ->offset(($data['page'] - 1) * $data['pageSize'])
  6259. ->limit($data['pageSize'])
  6260. ->get()
  6261. ->all();
  6262. if (empty($job)) {
  6263. return Result::error("暂无招聘信息", 0);
  6264. }
  6265. $result = [
  6266. 'row' => $job,
  6267. 'count' => $count,
  6268. ];
  6269. return Result::success($result);
  6270. }
  6271. /*
  6272. * 获取企业会员-招聘信息列表
  6273. * */
  6274. public function getRecruitingInfo(array $data): array
  6275. {
  6276. $user = User::where('id', $data['user_id'])->first();
  6277. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6278. return Result::error("用户不存在", 0);
  6279. }
  6280. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6281. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6282. ->select(
  6283. 'job_recruiting.*',
  6284. 'job_company.business_name',
  6285. 'job_company.company_hy_id',
  6286. 'job_company.company_size',
  6287. 'job_company.company_nature',
  6288. 'job_company.introduction',
  6289. 'job_company.real_name',
  6290. 'job_company.mobile',
  6291. 'job_company.company_url',
  6292. 'job_company.address_arr_id',
  6293. 'job_company.address',
  6294. 'job_company.email'
  6295. )
  6296. ->get();
  6297. if (empty($recruiting)) {
  6298. return Result::error("暂无招聘信息", 0);
  6299. }
  6300. return Result::success($recruiting);
  6301. }
  6302. /*
  6303. * 获取企业会员-我的沟通
  6304. * */
  6305. public function getJobResumeList(array $data): array
  6306. {
  6307. $user = User::where('id', $data['user_id'])->first();
  6308. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6309. return Result::error("用户不存在", 0);
  6310. }
  6311. $where = [];
  6312. if (isset($data['salary']) && $data['salary'] != null) {
  6313. $where['job_hunting.salary'] = $data['salary'];
  6314. }
  6315. if (isset($data['user_name']) && $data['user_name'] != null) {
  6316. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6317. }
  6318. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6319. $query->where('job_resume.user_id', $user['id']);
  6320. })
  6321. ->when(!empty($where), function ($query) use ($where) {
  6322. $query->where($where);
  6323. })
  6324. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6325. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6326. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6327. ->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');
  6328. $count = $job->count();
  6329. if ($count == 0) {
  6330. return Result::error("暂无沟通记录", 0);
  6331. }
  6332. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6333. ->offset(($data['page'] - 1) * $data['pageSize'])
  6334. ->limit($data['pageSize'])
  6335. ->get();
  6336. if (empty($jobs)) {
  6337. return Result::error("暂无沟通记录", 0);
  6338. }
  6339. $result['row'] = $this->processJob($jobs, '');
  6340. $result['count'] = $count;
  6341. return Result::success($result);
  6342. }
  6343. public function readJobResume(array $data): array
  6344. {
  6345. $result = JobResume::where('id', $data['id'])->first();
  6346. if (empty($result)) {
  6347. return Result::error("查询失败", 0);
  6348. }
  6349. $result = JobResume::where('id', $data['id'])->update([
  6350. 'status' => 2,
  6351. ]);
  6352. return Result::success($result);
  6353. }
  6354. // 20250306 招聘
  6355. //20250422 书刊音像
  6356. public function addBook(array $data): array
  6357. {
  6358. $user_id = $data['user_id'] ?? 0;
  6359. $type_id = $data['type_id'] ?? 0;
  6360. // $website_id = $data['website_id'] ?? 0;
  6361. // unset($data['user_id']);
  6362. unset($data['type_id']);
  6363. // unset($data['website_id']);
  6364. //处理数组
  6365. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6366. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6367. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6368. if ($data['img_url'] == '') {
  6369. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6370. preg_match_all($reg, $data['detail'], $matches);
  6371. if (isset($matches[1][0])) {
  6372. //截取varchar240
  6373. $data['img_url'] = substr($matches[1][0], 0, 240);
  6374. }
  6375. }
  6376. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6377. //提取标题+内容中的关键词
  6378. $data['keyword'] = $data['title'];
  6379. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6380. Jieba::init(); // 初始化 jieba-php
  6381. Finalseg::init();
  6382. $segList = Jieba::cut($data['keyword']);
  6383. $segList1 = array_slice($segList, 0, 8);
  6384. $data['keyword'] = implode(',', $segList1);
  6385. }
  6386. if ($data['description'] == '') {
  6387. //提取内容中的描述
  6388. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6389. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6390. }
  6391. var_dump($data, '--');
  6392. if ($data['status'] == 1) {
  6393. $this->sendMessage([
  6394. 'talk_type' => 400,
  6395. 'title' => $data['title'],
  6396. 'content' => '提交了审核',
  6397. 'messageType' => 7,
  6398. ]);
  6399. }
  6400. $result = Book::insertGetId($data);
  6401. if (empty($result)) {
  6402. return Result::error("添加失败", 0);
  6403. }
  6404. return Result::success($result);
  6405. }
  6406. public function getBookList(array $data): array
  6407. {
  6408. $where = [];
  6409. if (!empty($data["title"])) {
  6410. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6411. }
  6412. if (!empty($data['website_name'])) {
  6413. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6414. }
  6415. if (!empty($data['status'])) {
  6416. $where[] = ['book.status', '=', $data['status']];
  6417. }
  6418. $user_id = $data['user_id'];
  6419. $type_id = $data['type_id'];
  6420. // $type_id = 4;
  6421. var_dump($type_id, '------1--------');
  6422. if ($type_id != 10000) {
  6423. $where[] = ['book.user_id', '=', $user_id];
  6424. }
  6425. var_dump(!empty($data['status1']), '=-===1');
  6426. $result = Book::where($where)
  6427. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6428. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6429. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6430. ->when(isset($data['status1']), function ($query) use ($data) {
  6431. $query->whereIn('book.status', [1, 3]);
  6432. })
  6433. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6434. ->orderBy("updated_at", "desc")
  6435. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6436. if (empty($result)) {
  6437. return Result::error("暂无数据", 0);
  6438. }
  6439. // 取出数据
  6440. $rows = $result->items();
  6441. $count = $result->total();
  6442. $responseData = [
  6443. 'rows' => $rows,
  6444. 'count' => $count,
  6445. ];
  6446. return Result::success($responseData);
  6447. }
  6448. public function deleteBook(array $data): array
  6449. {
  6450. $result = Book::where('id', $data['id'])->delete();
  6451. if (empty($result)) {
  6452. return Result::error("删除失败", 0);
  6453. }
  6454. return Result::success($result);
  6455. }
  6456. public function updateBook(array $data): array
  6457. {
  6458. // $user_id = $data['user_id'] ?? 0;
  6459. $type_id = $data['type_id'] ?? 0;
  6460. // $website_id = $data['website_id'] ?? 0;
  6461. unset($data['user_id']);
  6462. unset($data['type_id']);
  6463. // unset($data['website_id']);
  6464. //处理数组
  6465. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6466. if ($data['img_url'] == '') {
  6467. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6468. preg_match_all($reg, $data['detail'], $matches);
  6469. if (isset($matches[1][0])) {
  6470. //截取varchar240
  6471. $data['img_url'] = substr($matches[1][0], 0, 240);
  6472. }
  6473. }
  6474. if ($data['keyword'] == '') {
  6475. //提取标题+内容中的关键词
  6476. $data['keyword'] = $data['title'];
  6477. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6478. Jieba::init(); // 初始化 jieba-php
  6479. Finalseg::init();
  6480. $segList = Jieba::cut($data['keyword']);
  6481. $segList1 = array_slice($segList, 0, 8);
  6482. $data['keyword'] = implode(',', $segList1);
  6483. }
  6484. if ($data['description'] == '') {
  6485. //提取内容中的描述
  6486. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6487. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6488. }
  6489. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6490. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6491. if ($data['status'] == 1) {
  6492. $this->sendMessage([
  6493. 'talk_type' => 400,
  6494. 'title' => $data['title'],
  6495. 'content' => '提交了审核',
  6496. 'messageType' => 7,
  6497. ]);
  6498. }
  6499. $result = Book::where("id", $data["id"])->update($data);
  6500. if (empty($result)) {
  6501. return Result::error("更新失败", 0);
  6502. }
  6503. return Result::success($result);
  6504. }
  6505. public function getBookInfo(array $data): array
  6506. {
  6507. $result = Book::where("id", $data["id"])->first();
  6508. if (empty($result)) {
  6509. return Result::error("获取失败", 0);
  6510. }
  6511. return Result::success($result);
  6512. }
  6513. public function updateBookStatus(array $data): array
  6514. {
  6515. //审核
  6516. unset($data['user_id']);
  6517. $bookInfo = Book::where("id", $data["id"])->first();
  6518. var_dump($bookInfo, '----');
  6519. if ($data['status'] == 2) {
  6520. $this->sendMessage([
  6521. 'talk_type' => 401,
  6522. 'title' => $bookInfo['title'],
  6523. 'content' => '审核通过',
  6524. 'messageType' => 7,
  6525. 'user_id' => $bookInfo['user_id'],
  6526. ]);
  6527. }
  6528. if ($data['status'] == 3) {
  6529. $this->sendMessage([
  6530. 'talk_type' => 401,
  6531. 'title' => $bookInfo['title'],
  6532. 'content' => '审核拒绝',
  6533. 'messageType' => 7,
  6534. 'user_id' => $bookInfo['user_id'],
  6535. ]);
  6536. }
  6537. if ($data['status'] == 1) {
  6538. $this->sendMessage([
  6539. 'talk_type' => 400,
  6540. 'title' => $bookInfo['title'],
  6541. 'content' => '提交了审核',
  6542. 'messageType' => 7,
  6543. // 'user_id'=>$bookInfo['user_id'],
  6544. ]);
  6545. }
  6546. $result = Book::where("id", $data["id"])->update($data);
  6547. if (empty($result)) {
  6548. return Result::error("更新失败", 0);
  6549. }
  6550. return Result::success($result);
  6551. }
  6552. //20250422 书刊音像
  6553. /**
  6554. * 贴身宝贝
  6555. * @param array $data
  6556. * @return array
  6557. */
  6558. public function getWebsiteTsbb(array $data): array
  6559. {
  6560. $month = $data['month'] ?? date('m');
  6561. $day = $data['day'] ?? date('d');
  6562. // 使用缓存键
  6563. $cacheKey = "tsbb_data_{$month}_{$day}";
  6564. // 尝试从缓存获取数据
  6565. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6566. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6567. if ($cachedData = $cache->get($cacheKey)) {
  6568. return Result::success(unserialize($cachedData));
  6569. }
  6570. //查询老黄历
  6571. try {
  6572. $date = date('Y-m-d');
  6573. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6574. // 使用 curl 替代 file_get_contents
  6575. $ch = curl_init();
  6576. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6577. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6578. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6579. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6580. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6581. 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');
  6582. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6583. 'Accept: application/json',
  6584. 'Content-Type: application/json',
  6585. 'Referer: https://www.36jxs.com/'
  6586. ]);
  6587. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6588. curl_setopt($ch, CURLOPT_ENCODING, '');
  6589. $almanacResponse = curl_exec($ch);
  6590. var_dump("====:", $almanacResponse);
  6591. if (curl_errno($ch)) {
  6592. var_dump('Curl error:', curl_error($ch));
  6593. throw new \Exception('Curl error: ' . curl_error($ch));
  6594. }
  6595. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6596. curl_close($ch);
  6597. if ($almanacResponse === false) {
  6598. throw new \Exception('Failed to fetch almanac data');
  6599. }
  6600. $almanacData = json_decode($almanacResponse, true);
  6601. if (json_last_error() !== JSON_ERROR_NONE) {
  6602. throw new \Exception('Failed to parse almanac data');
  6603. }
  6604. $almanacInfo = $almanacData['data'] ?? [];
  6605. } catch (\Exception $e) {
  6606. var_dump('Exception:', $e->getMessage());
  6607. $almanacInfo = [];
  6608. }
  6609. // 获取历史上的今天数据
  6610. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6611. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6612. ->orderBy('year', 'asc')
  6613. ->select("title", "id", "year", DB::raw('1 as type'))
  6614. ->limit(16)
  6615. ->get();
  6616. // 获取节日数据 - 从今天开始获取未来4条
  6617. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6618. ->orderBy('showtime', 'asc')
  6619. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6620. ->limit(16)
  6621. ->get();
  6622. //说文解字
  6623. $chartacterList = Character::orderBy('updated_at', 'desc')
  6624. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6625. ->limit(6)
  6626. ->get();
  6627. //谜语沙龙
  6628. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6629. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6630. ->limit(4)
  6631. ->get();
  6632. //成语欣赏
  6633. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6634. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6635. ->limit(32)
  6636. ->get();
  6637. //名联赏析
  6638. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6639. ->select("id", "first", "second", DB::raw('6 as type'))
  6640. ->limit(6)
  6641. ->get();
  6642. // 获取分类文章数据
  6643. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6644. ->pluck('category_id')
  6645. ->toArray();
  6646. $articlesList = [];
  6647. foreach ($categoryIds as $catid) {
  6648. // 先查有图片的
  6649. $withImg = DB::table('article')
  6650. ->where('status', 1)
  6651. ->where('catid', $catid)
  6652. ->whereNotNull('imgurl')
  6653. ->where('imgurl', '!=', '')
  6654. ->orderBy('updated_at', 'desc')
  6655. ->limit(6)
  6656. ->get();
  6657. $count = $withImg->count();
  6658. if ($count < 6) {
  6659. // 不足6条再查无图片的补足
  6660. $withoutImg = DB::table('article')
  6661. ->where('status', 1)
  6662. ->where('catid', $catid)
  6663. ->where(function ($q) {
  6664. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6665. })
  6666. ->orderBy('updated_at', 'desc')
  6667. ->limit(6 - $count)
  6668. ->get();
  6669. $articles = $withImg->concat($withoutImg);
  6670. } else {
  6671. $articles = $withImg;
  6672. }
  6673. // 组装
  6674. $category = \App\Model\Category::find($catid);
  6675. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6676. $articlesList[] = [
  6677. 'category_name' => $category ? $category->name : '',
  6678. 'catid' => $catid,
  6679. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6680. 'type' => 100,
  6681. 'list' => $articles->map(function ($item) {
  6682. return [
  6683. 'id' => $item->id,
  6684. 'title' => $item->title,
  6685. 'imgurl' => $item->imgurl,
  6686. 'created_at' => $item->created_at
  6687. ];
  6688. })->values()
  6689. ];
  6690. }
  6691. $result = [
  6692. 'almanac' => $almanacInfo,
  6693. 'historyTodayList' => [
  6694. 'category_name' => '历史上的今天',
  6695. 'list' => $historyTodayList,
  6696. 'type' => 1
  6697. ],
  6698. 'festivalList' => [
  6699. 'category_name' => '节日预告',
  6700. 'list' => $festivalList,
  6701. 'type' => 2
  6702. ],
  6703. 'chartacterList' => [
  6704. 'category_name' => '说文解字',
  6705. 'list' => $chartacterList,
  6706. 'type' => 3
  6707. ],
  6708. 'coupletList' => [
  6709. 'category_name' => '名联赏析',
  6710. 'list' => $coupletList,
  6711. 'type' => 6
  6712. ],
  6713. 'riddletList' => [
  6714. 'category_name' => '谜语沙龙',
  6715. 'list' => $riddletList,
  6716. 'type' => 4
  6717. ],
  6718. 'idiomList' => [
  6719. 'category_name' => '成语欣赏',
  6720. 'list' => $idiomList,
  6721. 'type' => 5
  6722. ],
  6723. 'articlesList' => $articlesList
  6724. ];
  6725. // 缓存结果,设置1小时过期
  6726. $cache->set($cacheKey, serialize($result), 3600);
  6727. return Result::success($result);
  6728. }
  6729. /**
  6730. * 获取资讯列表
  6731. */
  6732. public function getWebsiteTsbbList(array $data): array
  6733. {
  6734. $page = $data['page'] ?? 1;
  6735. $pageSize = $data['pageSize'] ?? 10;
  6736. // 如果没有传入月份和日期,则使用今天的日期
  6737. $month = $data['month'] ?? date('m');
  6738. $day = $data['day'] ?? date('d');
  6739. $total = 0;
  6740. $result = [];
  6741. $data['type'] = intval($data['type']);
  6742. var_dump("接收参数:", $data);
  6743. switch ($data['type']) {
  6744. case 1:
  6745. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6746. // 当前月份之后的数据
  6747. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6748. // 或者当前月份且日期大于等于当前日期的数据
  6749. ->orWhere(function ($q) use ($month, $day) {
  6750. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6751. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6752. });
  6753. })
  6754. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6755. $total = $query->count();
  6756. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6757. ->offset(($page - 1) * $pageSize)
  6758. ->limit($pageSize)
  6759. ->get();
  6760. break;
  6761. case 2:
  6762. $query = Festival::where(function ($q) use ($month, $day) {
  6763. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6764. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6765. ->orWhere(function ($q) use ($month, $day) {
  6766. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6767. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6768. });
  6769. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6770. $total = $query->count();
  6771. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6772. ->offset(($page - 1) * $pageSize)
  6773. ->limit($pageSize)
  6774. ->get();
  6775. break;
  6776. case 3:
  6777. $query = Character::orderBy("updated_at", "desc");
  6778. $total = $query->count();
  6779. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6780. ->offset(($page - 1) * $pageSize)
  6781. ->limit($pageSize)
  6782. ->get();
  6783. break;
  6784. case 4:
  6785. $query = Riddle::orderBy("updated_at", "desc");
  6786. $total = $query->count();
  6787. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6788. ->offset(($page - 1) * $pageSize)
  6789. ->limit($pageSize)
  6790. ->get();
  6791. break;
  6792. case 5:
  6793. $query = Idiom::orderBy("updated_at", "desc");
  6794. $total = $query->count();
  6795. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6796. ->offset(($page - 1) * $pageSize)
  6797. ->limit($pageSize)
  6798. ->get();
  6799. break;
  6800. case 6:
  6801. $query = Couplet::orderBy("updated_at", "desc");
  6802. $total = $query->count();
  6803. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6804. ->offset(($page - 1) * $pageSize)
  6805. ->limit($pageSize)
  6806. ->get();
  6807. break;
  6808. default:
  6809. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6810. $total = $query->count();
  6811. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6812. ->offset(($page - 1) * $pageSize)
  6813. ->limit($pageSize)
  6814. ->get();
  6815. }
  6816. return Result::success([
  6817. 'list' => $result,
  6818. 'total' => $total,
  6819. 'page' => (int)$page,
  6820. 'pageSize' => (int)$pageSize,
  6821. 'month' => $month,
  6822. 'day' => $day
  6823. ]);
  6824. }
  6825. /**
  6826. * 1:历史上的今天
  6827. * 2:节日
  6828. * 3:文章
  6829. *
  6830. * 资讯详情信息
  6831. */
  6832. public function getWebsiteTsbbDetail(array $data): array
  6833. {
  6834. $data['type'] = intval($data['type']);
  6835. switch ($data['type']) {
  6836. case 1:
  6837. $result = HistoryToday::where("id", $data['id'])->first();
  6838. break;
  6839. case 2:
  6840. $result = Festival::where("id", $data['id'])->first();
  6841. break;
  6842. case 3:
  6843. $result = Character::where("id", $data['id'])->first();
  6844. break;
  6845. case 4:
  6846. $result = Riddle::where("id", $data['id'])->first();
  6847. break;
  6848. case 5:
  6849. $result = Idiom::where("id", $data['id'])->first();
  6850. break;
  6851. case 6:
  6852. $result = Couplet::where("id", $data['id'])->first();
  6853. break;
  6854. default:
  6855. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6856. break;
  6857. }
  6858. return Result::success($result);
  6859. }
  6860. /**
  6861. * 农网导航首页数据
  6862. */
  6863. public function getWebsiteNwHomeList(array $data): array
  6864. {
  6865. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6866. ->pluck('category_id')
  6867. ->toArray();
  6868. // 使用子查询优化
  6869. $articlesList = DB::table('article')
  6870. ->select([
  6871. 'article.id',
  6872. 'article.title',
  6873. 'article.imgurl',
  6874. 'article.created_at',
  6875. 'category.name as category_name',
  6876. 'category.id as category_id',
  6877. 'website_category.aLIas_pinyin as pinyin',
  6878. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6879. DB::raw('100 as type')
  6880. ])
  6881. ->join('category', 'article.catid', '=', 'category.id')
  6882. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6883. ->leftJoin('website_category as parent_wc', function ($join) {
  6884. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6885. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6886. })
  6887. ->where('website_category.website_id', $data['website_id'])
  6888. ->where('article.status', 1)
  6889. ->whereIn('category.id', $categoryIds)
  6890. ->orderBy('article.created_at', 'desc')
  6891. ->get()
  6892. ->groupBy('category_id')
  6893. ->map(function ($group) {
  6894. // 确保第一条数据有图片
  6895. $firstWithImage = $group->first(function ($item) {
  6896. return !empty($item->imgurl);
  6897. });
  6898. if ($firstWithImage) {
  6899. // 如果有带图片的文章,将其放在第一位
  6900. $group = $group->filter(function ($item) use ($firstWithImage) {
  6901. return $item->id !== $firstWithImage->id;
  6902. })->prepend($firstWithImage);
  6903. }
  6904. return [
  6905. 'category_name' => $group->first()->category_name,
  6906. 'catid' => $group->first()->category_id,
  6907. 'pinyin' => $group->first()->pinyin,
  6908. 'parent_pinyin' => $group->first()->parent_pinyin,
  6909. 'list' => $group->take(4)->map(function ($item) {
  6910. return [
  6911. 'id' => $item->id,
  6912. 'title' => $item->title,
  6913. ];
  6914. })->values()
  6915. ];
  6916. })
  6917. ->values()
  6918. ->toArray();
  6919. return Result::success($articlesList);
  6920. }
  6921. /**
  6922. * 企业管理
  6923. * @param array $data
  6924. * @return array
  6925. */
  6926. public function getCompanyList(array $data): array
  6927. {
  6928. // return Result::success($data);
  6929. $where = [];
  6930. $user = User::where('id', $data['user_id'])->first();
  6931. if (empty($user)) {
  6932. return Result::error('用户不存在!');
  6933. }
  6934. if ($user['type_id'] != 10000) {
  6935. $where['user_id'] = $data['user_id'];
  6936. }
  6937. if (isset($data['title']) && !empty($data['title'])) {
  6938. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6939. }
  6940. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6941. array_push($where, ['website.id', $data['website_id']]);
  6942. }
  6943. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6944. if ($data['ischeck'] == 1) {
  6945. if (isset($data['status']) && $data['status'] != '') {
  6946. array_push($where, ['company.status', $data['status']]);
  6947. $query = Company::where($where);
  6948. } else {
  6949. $query = Company::whereIn('company.status', [0, 2]);
  6950. }
  6951. } else {
  6952. $query = Company::where('company.status', 1);
  6953. }
  6954. }
  6955. $result = $query->where($where)
  6956. ->leftJoin('website_category', function ($query) {
  6957. $query->on('website_category.category_id', '=', 'company.category_id')
  6958. ->on('website_category.website_id', '=', 'company.website_id');
  6959. })
  6960. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6961. ->select(
  6962. 'company.id',
  6963. 'company.title',
  6964. 'company.website_id',
  6965. 'company.category_id',
  6966. 'website.website_name',
  6967. 'website_category.alias as category_name',
  6968. 'company.status',
  6969. 'company.updated_at',
  6970. 'company.user_id'
  6971. )
  6972. ->orderBy('company.updated_at', 'desc')
  6973. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6974. if ($result->isEmpty()) {
  6975. return Result::error("暂无企业", 0);
  6976. }
  6977. return Result::success($result);
  6978. }
  6979. /**
  6980. * 添加企业
  6981. * @param array $data
  6982. * @return array
  6983. */
  6984. public function addCompany(array $data): array
  6985. {
  6986. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6987. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6988. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6989. $data['cat_arr_id'] = json_encode($car_arr_id);
  6990. } else {
  6991. $data['cat_arr_id'] = '';
  6992. }
  6993. if ($data['imgurl'] == '') {
  6994. //content中提取图片第一个图,正则提取
  6995. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6996. preg_match_all($reg, $data['content'], $matches);
  6997. if (isset($matches[1][0])) {
  6998. //截取varchar240
  6999. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7000. }
  7001. }
  7002. if ($data['keyword'] == '') {
  7003. //提取标题+内容中的关键词
  7004. $data['keyword'] = $data['title'];
  7005. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7006. Jieba::init(); // 初始化 jieba-php
  7007. Finalseg::init();
  7008. $segList = Jieba::cut($data['keyword']);
  7009. $segList1 = array_slice($segList, 0, 8);
  7010. $data['keyword'] = implode(',', $segList1);
  7011. }
  7012. if ($data['introduce'] == '' || empty($data['introduce'])) {
  7013. //提取内容中的描述
  7014. $content = $data['content'];
  7015. // 去除 <style> 和 <script> 标签及其内容
  7016. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7017. // 去除所有 HTML 标签
  7018. $content = strip_tags($content);
  7019. // 去除 HTML 实体
  7020. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7021. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7022. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7023. // 去除多余空白
  7024. $content = preg_replace('/\s+/u', '', $content);
  7025. // 截取 100 个字符
  7026. $data['introduce'] = mb_substr($content, 0, 100);
  7027. }
  7028. $user = User::where('id', $data['user_id'])->first();
  7029. if (empty($user)) {
  7030. return Result::error('用户不存在!');
  7031. }
  7032. if ($user['type_id'] == 10000) {
  7033. $data['status'] = 1;
  7034. }
  7035. if (isset($data['level']) && $data['level'] != null) {
  7036. $data['level'] = intval($data['level']);
  7037. } else {
  7038. $data['level'] = null;
  7039. }
  7040. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7041. $this->sendMessage([
  7042. 'talk_type' => 900,
  7043. 'title' => $data['title'],
  7044. 'content' => '提交了审核',
  7045. 'messageType' => 8,
  7046. ]);
  7047. }
  7048. $result = Company::insertGetId($data);
  7049. if ($result) {
  7050. return Result::success($result);
  7051. } else {
  7052. return Result::error('添加失败');
  7053. }
  7054. }
  7055. /**
  7056. * 更新企业
  7057. * @param array $data
  7058. * @return array
  7059. */
  7060. public function upCompany(array $data): array
  7061. {
  7062. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7063. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7064. $data['cat_arr_id'] = json_encode($car_arr_id);
  7065. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7066. } else {
  7067. $data['cat_arr_id'] = '';
  7068. }
  7069. if ($data['imgurl'] == '') {
  7070. //content中提取图片第一个图,正则提取
  7071. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7072. preg_match_all($reg, $data['content'], $matches);
  7073. if (isset($matches[1][0])) {
  7074. //截取varchar
  7075. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7076. }
  7077. }
  7078. if ($data['keyword'] == '') {
  7079. //提取标题+内容中的关键词
  7080. $data['keyword'] = $data['title'];
  7081. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7082. Jieba::init(); // 初始化 jieba-php
  7083. Finalseg::init();
  7084. $segList = Jieba::cut($data['keyword']);
  7085. $segList1 = array_slice($segList, 0, 8);
  7086. $data['keyword'] = implode(',', $segList1);
  7087. }
  7088. if ($data['introduce'] == '') {
  7089. //提取内容中的描述
  7090. $content = $data['content'];
  7091. // 去除 <style> 和 <script> 标签及其内容
  7092. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7093. // 去除所有 HTML 标签
  7094. $content = strip_tags($content);
  7095. // 去除 HTML 实体
  7096. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7097. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7098. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7099. // 去除多余空白
  7100. $content = preg_replace('/\s+/u', '', $content);
  7101. // 截取 100 个字符
  7102. $data['introduce'] = mb_substr($content, 0, 100);
  7103. }
  7104. if (isset($data['level']) && $data['level'] != null) {
  7105. $data['level'] = intval($data['level']);
  7106. } else {
  7107. $data['level'] = null;
  7108. }
  7109. $user = User::where('id', $data['user_id'])->first();
  7110. if (empty($user)) {
  7111. return Result::error('用户不存在!');
  7112. }
  7113. if ($user['type_id'] == 10000) {
  7114. $data['status'] = 1;
  7115. } else {
  7116. $data['status'] = 0;
  7117. }
  7118. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7119. $this->sendMessage([
  7120. 'talk_type' => 900,
  7121. 'title' => $data['title'],
  7122. 'content' => '提交了审核',
  7123. 'messageType' => 8,
  7124. ]);
  7125. }
  7126. $result = Company::where('id', $data['id'])->update($data);
  7127. if ($result) {
  7128. return Result::success($result);
  7129. } else {
  7130. return Result::error('修改失败');
  7131. }
  7132. }
  7133. /**
  7134. * 删除企业
  7135. * @param array $data
  7136. * @return array
  7137. */
  7138. public function delCompany(array $data): array
  7139. {
  7140. $result = Company::where('id', $data['id'])->delete();
  7141. if ($result) {
  7142. return Result::success($result);
  7143. } else {
  7144. return Result::error('删除失败');
  7145. }
  7146. }
  7147. /**
  7148. * 审核企业
  7149. * @param array $data
  7150. * @return array
  7151. */
  7152. public function checkCompany(array $data): array
  7153. {
  7154. $user = User::where('id', $data['user_id'])->first();
  7155. if (empty($user)) {
  7156. return Result::error('用户不存在!');
  7157. }
  7158. $company = Company::where('id', $data['id'])->first();
  7159. if (empty($company)) {
  7160. return Result::error('企业不存在!');
  7161. }
  7162. // 状态:0:未审核 1:已审核 2:已拒绝
  7163. if ($data['status'] == 2 || $data['status'] == '2') {
  7164. $this->sendMessage([
  7165. 'talk_type' => 901,
  7166. 'title' => $company['title'],
  7167. 'content' => '审核拒绝',
  7168. 'messageType' => 8,
  7169. 'user_id' => $company['user_id'],
  7170. ]);
  7171. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7172. } else {
  7173. if ($data['status'] == 1) {
  7174. $this->sendMessage([
  7175. 'talk_type' => 901,
  7176. 'title' => $company['title'],
  7177. 'content' => '审核通过',
  7178. 'messageType' => 8,
  7179. 'user_id' => $company['user_id'],
  7180. ]);
  7181. } else if ($data['status'] == 0) {
  7182. $this->sendMessage([
  7183. 'talk_type' => 900,
  7184. 'title' => $company['title'],
  7185. 'content' => '提交了审核',
  7186. 'messageType' => 8,
  7187. ]);
  7188. }
  7189. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7190. }
  7191. if (empty($result)) {
  7192. return Result::error('审核失败!');
  7193. } else {
  7194. return Result::success($result);
  7195. }
  7196. }
  7197. /**
  7198. * 获取企业信息
  7199. * @param array $data
  7200. * @return array
  7201. */
  7202. public function getCompanyInfo(array $data): array
  7203. {
  7204. $result = Company::where('id', $data['id'])->first();
  7205. $city_arr = json_decode($result['city_arr_id']);
  7206. $result['city_name'] = District::whereIn('id', $city_arr)
  7207. ->pluck('name')
  7208. ->implode('-');
  7209. if (empty($result)) {
  7210. return Result::error('企业不存在!');
  7211. } else {
  7212. return Result::success($result);
  7213. }
  7214. }
  7215. /**
  7216. * @param array $data
  7217. * @return array
  7218. */
  7219. public function getWebsiteCompany(array $data): array
  7220. {
  7221. $categorys = json_decode($data['id'], true);
  7222. $category_arr = $this->processArticlePro($data['website_id']);
  7223. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7224. $catiall = $category_arr['catiall'];
  7225. $categoryIds = $category_arr['categoryIds'];
  7226. // return Result::success($category_arr);
  7227. foreach ($categorys as $key => $value) {
  7228. if (array_key_exists('level', $value)) {
  7229. $parts = explode(',', $value['level']);
  7230. $level = $parts[0] ?? null;
  7231. $imgnum = $parts[1] ?? null;
  7232. $textnum = $parts[2] ?? null;
  7233. if (!empty($textnum) && $textnum > 0) {
  7234. $text_num = Company::where('level', $level)
  7235. ->whereIn('category_id', $categoryIds)
  7236. ->where('status', 1)
  7237. ->select(
  7238. 'company.id',
  7239. 'company.title',
  7240. 'company.description',
  7241. 'company.updated_at',
  7242. 'company.category_id',
  7243. 'company.cat_arr_id'
  7244. )
  7245. ->orderBy('updated_at', 'desc')
  7246. ->limit($textnum)
  7247. ->get()->all();
  7248. }
  7249. if (!empty($imgnum) && $imgnum > 0) {
  7250. $img_num = Company::where('level', $level)
  7251. ->whereIn('category_id', $categoryIds)
  7252. ->where('status', 1)
  7253. ->where('imgurl', '!=', '')
  7254. ->whereNotNull('imgurl')
  7255. ->select(
  7256. 'company.id',
  7257. 'company.title',
  7258. 'company.description',
  7259. 'company.updated_at',
  7260. 'company.imgurl as imgs',
  7261. 'company.category_id',
  7262. 'company.cat_arr_id'
  7263. )
  7264. ->orderBy('updated_at', 'desc')
  7265. ->limit($imgnum)
  7266. ->get()->all();
  7267. }
  7268. }
  7269. if (array_key_exists('id', $value)) {
  7270. $parts = explode(',', $value['id']);
  7271. $category_id = $parts[0] ?? null;
  7272. $imgnum = $parts[1] ?? null;
  7273. $textnum = $parts[2] ?? null;
  7274. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7275. if (!empty($textnum) && $textnum > 0) {
  7276. $text_num = Company::whereIn('category_id', $category_arr)
  7277. // ->where('website_id', $data['website_id'])
  7278. ->where('status', 1)
  7279. ->select(
  7280. 'company.id',
  7281. 'company.title',
  7282. 'company.description',
  7283. 'company.updated_at',
  7284. 'company.category_id',
  7285. 'company.cat_arr_id'
  7286. )
  7287. ->orderBy('updated_at', 'desc')
  7288. ->limit($textnum)
  7289. ->get()->all();
  7290. }
  7291. if (!empty($imgnum) && $imgnum > 0) {
  7292. $img_num = Company::whereIn('category_id', $category_arr)
  7293. // ->where('website_id', $data['website_id'])
  7294. ->where('status', 1)
  7295. ->where('imgurl', '!=', '')
  7296. ->whereNotNull('imgurl')
  7297. ->select(
  7298. 'company.id',
  7299. 'company.title',
  7300. 'company.description',
  7301. 'company.updated_at',
  7302. 'company.imgurl as imgs',
  7303. 'company.category_id',
  7304. 'company.cat_arr_id'
  7305. )
  7306. ->orderBy('updated_at', 'desc')
  7307. ->limit($imgnum)
  7308. ->get()->all();
  7309. }
  7310. }
  7311. if (!empty($text_num)) {
  7312. foreach ($text_num as $k => $v) {
  7313. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7314. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7315. }
  7316. }
  7317. if (!empty($img_num)) {
  7318. foreach ($img_num as $k => $v) {
  7319. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7320. $imgurl = json_decode($v['imgs'], true);
  7321. if (!empty($imgurl)) {
  7322. $img_num[$k]->imgurl = $imgurl[0];
  7323. }
  7324. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7325. }
  7326. }
  7327. $company[$key]['img_num'] = $img_num ?? [];
  7328. $company[$key]['text_num'] = $text_num ?? [];
  7329. }
  7330. if (empty($company)) {
  7331. return Result::error("暂无相关企业信息", 0);
  7332. }
  7333. return Result::success($company);
  7334. }
  7335. /**
  7336. * @param array $data
  7337. * @return array
  7338. */
  7339. public function getWebsiteCompanyList(array $data): array
  7340. {
  7341. $where['website_id'] = $data['website_id'];
  7342. $where['status'] = 1;
  7343. $categoryIds = [];
  7344. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7345. $category_id = $data['category_id'];
  7346. }
  7347. $category_arr = $this->processArticlePro($data['website_id']);
  7348. $categoryIds = $category_arr['categoryIds'];
  7349. // return Result::success($cat_1st_arr);
  7350. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7351. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7352. })
  7353. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7354. $query->whereIn('category_id', $categoryIds);
  7355. })
  7356. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7357. $query->where('category_id', $category_id);
  7358. })
  7359. ->where('status',1)
  7360. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7361. ->orderBy('updated_at', 'desc')
  7362. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7363. if (empty($company)) {
  7364. return Result::error("暂无相关公司信息", 0);
  7365. }
  7366. $result = [
  7367. 'count' => $company->total(),
  7368. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7369. ];
  7370. return Result::success($result);
  7371. }
  7372. /**
  7373. * 获取项目列表
  7374. * @param array $data
  7375. * @return array
  7376. */
  7377. public function getProjectList(array $data): array
  7378. {
  7379. $where = [];
  7380. $user = User::where('id', $data['user_id'])->first();
  7381. if (empty($user)) {
  7382. return Result::error('用户不存在!');
  7383. }
  7384. if ($user->type_id != 10000) {
  7385. array_push($where, ['project.user_id', $data['user_id']]);
  7386. }
  7387. $query = Project::query();
  7388. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7389. array_push($where, ['project.website_id', $data['website_id']]);
  7390. }
  7391. if (isset($data['title']) && !empty($data['title'])) {
  7392. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7393. }
  7394. if ($data['status'] != 3) {
  7395. array_push($where, ['project.status', $data['status']]);
  7396. }
  7397. $query = Project::where($where)
  7398. ->when($data['status'] == 3, function ($query) {
  7399. $query->whereIn('project.status', [0, 2]);
  7400. });
  7401. $count = $query->clone()
  7402. ->count();
  7403. $rows = $query->clone()
  7404. ->leftJoin('website', 'project.website_id', 'website.id')
  7405. ->leftJoin('website_category', function ($join) {
  7406. $join->on('project.website_id', '=', 'website_category.website_id')
  7407. ->on('project.category_id', '=', 'website_category.category_id');
  7408. })
  7409. ->select(
  7410. 'project.id',
  7411. 'project.title',
  7412. 'project.updated_at',
  7413. 'project.status',
  7414. 'website.website_name',
  7415. 'website_category.alias as category_name',
  7416. 'project.website_id',
  7417. 'project.user_id'
  7418. )
  7419. ->orderBy('project.updated_at', 'desc')
  7420. ->offset(($data['page'] - 1) * $data['pageSize'])
  7421. ->limit($data['pageSize'])
  7422. ->get();
  7423. if ($rows->isEmpty()) {
  7424. return Result::error("暂无相关项目信息", 0);
  7425. }
  7426. $result = [
  7427. 'count' => $count,
  7428. 'rows' => $rows,
  7429. ];
  7430. return Result::success($result);
  7431. }
  7432. /**
  7433. * 添加项目
  7434. * @param array $data
  7435. * @return array
  7436. */
  7437. public function addProject(array $data): array
  7438. {
  7439. $user = User::where('id', $data['user_id'])->first();
  7440. if (empty($user)) {
  7441. return Result::error("暂无相关用户信息", 0);
  7442. }
  7443. if ($user->type_id == 10000) {
  7444. $data['status'] = 1;
  7445. } else {
  7446. $data['status'] = 0;
  7447. }
  7448. if ($data['keyword'] == '') {
  7449. //提取标题+内容中的关键词
  7450. $data['keyword'] = $data['title'];
  7451. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7452. Jieba::init(); // 初始化 jieba-php
  7453. Finalseg::init();
  7454. $segList = Jieba::cut($data['keyword']);
  7455. $segList1 = array_slice($segList, 0, 8);
  7456. $data['keyword'] = implode(',', $segList1);
  7457. }
  7458. if ($data['description'] == '') {
  7459. //提取内容中的描述
  7460. // var_dump(11111);
  7461. //提取内容中的描述
  7462. $content = $data['introduce'];
  7463. // 去除 <style> 和 <script> 标签及其内容
  7464. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7465. // 去除所有 HTML 标签
  7466. $content = strip_tags($content);
  7467. // 去除 HTML 实体
  7468. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7469. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7470. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7471. // 去除多余空白
  7472. $content = preg_replace('/\s+/u', '', $content);
  7473. // 截取 100 个字符
  7474. $data['description'] = mb_substr($content, 0, 100);
  7475. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7476. }
  7477. if ($data['status'] == 0) {
  7478. $this->sendMessage([
  7479. 'talk_type' => 1000,
  7480. 'title' => $data['title'],
  7481. 'content' => '提交了审核',
  7482. 'messageType' => 9,
  7483. ]);
  7484. }
  7485. $project = Project::insertGetId($data);
  7486. if (empty($project)) {
  7487. return Result::error("暂无相关项目信息", 0);
  7488. }
  7489. return Result::success($project);
  7490. }
  7491. /**
  7492. * 更新项目
  7493. * @param array $data
  7494. * @return array
  7495. */
  7496. public function upProject(array $data): array
  7497. {
  7498. $project = Project::where('id', $data['id'])->first();
  7499. if (empty($project)) {
  7500. return Result::error("暂无相关项目信息", 0);
  7501. }
  7502. $id = $data['id'];
  7503. unset($data['id']);
  7504. $user = User::where('id', $data['user_id'])->first();
  7505. if (empty($user)) {
  7506. return Result::error("暂无相关用户信息", 0);
  7507. }
  7508. if ($user->type_id == 10000) {
  7509. $data['status'] = 1;
  7510. } else {
  7511. $data['status'] = 0;
  7512. }
  7513. unset($data['user_id']);
  7514. if ($data['keyword'] == '') {
  7515. //提取标题+内容中的关键词
  7516. $data['keyword'] = $data['title'];
  7517. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7518. Jieba::init(); // 初始化 jieba-php
  7519. Finalseg::init();
  7520. $segList = Jieba::cut($data['keyword']);
  7521. $segList1 = array_slice($segList, 0, 8);
  7522. $data['keyword'] = implode(',', $segList1);
  7523. }
  7524. if ($data['description'] == '') {
  7525. //提取内容中的描述
  7526. // var_dump(11111);
  7527. //提取内容中的描述
  7528. $content = $data['introduce'];
  7529. // 去除 <style> 和 <script> 标签及其内容
  7530. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7531. // 去除所有 HTML 标签
  7532. $content = strip_tags($content);
  7533. // 去除 HTML 实体
  7534. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7535. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7536. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7537. // 去除多余空白
  7538. $content = preg_replace('/\s+/u', '', $content);
  7539. // 截取 100 个字符
  7540. $data['description'] = mb_substr($content, 0, 100);
  7541. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7542. }
  7543. if ($data['status'] == 0) {
  7544. $this->sendMessage([
  7545. 'talk_type' => 1000,
  7546. 'title' => $data['title'],
  7547. 'content' => '提交了审核',
  7548. 'messageType' => 9,
  7549. ]);
  7550. }
  7551. $result = Project::where('id', $id)->update($data);
  7552. if (empty($result)) {
  7553. return Result::error("更新失败", 0);
  7554. }
  7555. return Result::success($result);
  7556. }
  7557. /**
  7558. * 删除项目
  7559. * @param array $data
  7560. * @return array
  7561. */
  7562. public function delProject(array $data): array
  7563. {
  7564. $user = User::where('id', $data['user_id'])->first();
  7565. if (empty($user)) {
  7566. return Result::error("暂无相关用户信息", 0);
  7567. }
  7568. $project = Project::where('id', $data['id'])->first();
  7569. if (empty($project)) {
  7570. return Result::error("暂无相关项目信息", 0);
  7571. }
  7572. $result = Project::where('id', $data['id'])->delete();
  7573. if (empty($result)) {
  7574. return Result::error("删除失败", 0);
  7575. }
  7576. return Result::success($result);
  7577. }
  7578. /**
  7579. * 审核项目
  7580. * @param array $data
  7581. * @return array
  7582. */
  7583. public function checkProject(array $data): array
  7584. {
  7585. $user = User::where('id', $data['user_id'])->first();
  7586. if (empty($user)) {
  7587. return Result::error("暂无相关用户信息", 0);
  7588. }
  7589. // 0:未审核; 1:已审核; 2:已拒绝;
  7590. if ($user->type_id != 10000) {
  7591. if ($data['status'] == 1 || $data['status'] == 2) {
  7592. return Result::error("此用户权限不足", 0);
  7593. }
  7594. }
  7595. $project = Project::where('id', $data['id'])->first();
  7596. if (empty($project)) {
  7597. return Result::error("暂无相关项目信息", 0);
  7598. }
  7599. if ($data['status'] == 2) {
  7600. $this->sendMessage([
  7601. 'talk_type' => 1001,
  7602. 'title' => $project['title'],
  7603. 'content' => '审核拒绝',
  7604. 'messageType' => 9,
  7605. 'user_id' => $project['user_id'],
  7606. ]);
  7607. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7608. } else {
  7609. if ($data['status'] == 1) {
  7610. $this->sendMessage([
  7611. 'talk_type' => 1001,
  7612. 'title' => $project['title'],
  7613. 'content' => '审核通过',
  7614. 'messageType' => 9,
  7615. 'user_id' => $project['user_id'],
  7616. ]);
  7617. } else if ($data['status'] == 0) {
  7618. $this->sendMessage([
  7619. 'talk_type' => 1000,
  7620. 'title' => $project['title'],
  7621. 'content' => '提交了审核',
  7622. 'messageType' => 9,
  7623. ]);
  7624. }
  7625. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7626. }
  7627. if (empty($result)) {
  7628. return Result::error("审核失败", 0);
  7629. }
  7630. return Result::success($result);
  7631. }
  7632. /**
  7633. * 获取项目详情
  7634. * @param array $data
  7635. * @return array
  7636. */
  7637. public function getProjectInfo(array $data): array
  7638. {
  7639. $project = Project::where('id', $data['id'])->first();
  7640. if (empty($project)) {
  7641. return Result::error("暂无相关项目信息", 0);
  7642. }
  7643. return Result::success($project);
  7644. }
  7645. public function getWebsiteCompanyInfo(array $data): array
  7646. {
  7647. $company = Company::where('id', $data['id'])
  7648. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7649. ->where('status', 1)
  7650. // ->where('website_id', $data['website_id'])
  7651. ->select('company.*', 'job_industry.hyname as hy_name')
  7652. ->first();
  7653. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7654. $jobnature_id = $company['jobnature_id'] ?? null;
  7655. if ($jobnature_id !== null) {
  7656. switch ($jobnature_id) {
  7657. case 0:
  7658. $company->jobnature_name = '市场监督';
  7659. break;
  7660. case 1:
  7661. $company->jobnature_name = '信访纪检';
  7662. break;
  7663. case 2:
  7664. $company->jobnature_name = '公检法司';
  7665. break;
  7666. case 3:
  7667. $company->jobnature_name = '高关注机构';
  7668. break;
  7669. default:
  7670. $company->jobnature_name = '';
  7671. break;
  7672. }
  7673. } else {
  7674. $company->jobnature_name = '';
  7675. }
  7676. $city_arr = $company->city_arr_id;
  7677. if (!empty($city_arr)) {
  7678. $city_arr = json_decode($city_arr, true);
  7679. $cityNames = District::whereIn('id', $city_arr)
  7680. ->pluck('name')
  7681. ->implode('-');
  7682. $company->city_name = $cityNames;
  7683. } else {
  7684. $company->city_name = '';
  7685. }
  7686. if (empty($company)) {
  7687. return Result::error("暂无相关公司信息", 0);
  7688. }
  7689. return Result::success($company);
  7690. }
  7691. public function getMSG(array $data): array
  7692. {
  7693. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7694. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7695. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7696. $result = [];
  7697. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7698. //最近的5篇已审的文章
  7699. $apply_articale = Article::where('status', 1)
  7700. ->where('admin_user_id', $user_id)
  7701. ->orderBy('updated_at', 'desc')
  7702. // ->limit(5)
  7703. ->get();
  7704. //获取5条用户的已审核商品
  7705. $good = Good::where('status', 2)
  7706. ->where('user_id', $user_id)
  7707. ->orderBy('updated_at', 'desc')
  7708. // ->limit(5)
  7709. ->get();
  7710. //获取5条用户待审核的公告
  7711. $notice = Notice::where('status', 2)
  7712. ->where('user_id', $user_id)
  7713. ->orderBy('updated_at', 'desc')
  7714. ->limit(5)->get();
  7715. //获取5条用户的待审核投诉
  7716. $complaint = Complaint::where('status', 2)
  7717. ->where('user_id', $user_id)
  7718. ->orderBy('updated_at', 'desc')
  7719. // ->limit(5)
  7720. ->get();
  7721. //获取5条用户的book
  7722. $book = Book::where('status', 2)
  7723. ->where('user_id', $user_id)
  7724. ->orderBy('updated_at', 'desc')
  7725. // ->limit(5)
  7726. ->get();
  7727. //获取5条用户的求职
  7728. //获取5条用户的求职 1
  7729. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7730. ->where('job_hunting.user_id', $user_id)
  7731. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7732. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7733. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7734. ->orderBy('updated_at', 'desc')
  7735. // ->limit(5)
  7736. ->get();
  7737. //获取5条用户的求职 2
  7738. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7739. ->where('job_recruiting.user_id', $user_id)
  7740. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7741. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7742. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7743. ->orderBy('updated_at', 'desc')
  7744. // ->limit(5)
  7745. ->get();
  7746. //人才库 1
  7747. $job_apply = JobApply::where('job_apply.status', 1)
  7748. ->where('job_apply.receiver_id', $user_id)
  7749. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7750. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7751. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7752. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7753. ->select('job_recruiting', 'job_recruiting.', '', '')
  7754. ->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')
  7755. ->orderBy('updated_at', 'desc')
  7756. // ->limit(5)
  7757. ->get();
  7758. // 职场机会 2
  7759. $job_resume = JobResume::where('job_resume.status', 1)
  7760. ->where('job_resume.receiver_id', $user_id)
  7761. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7762. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7763. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7764. ->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')
  7765. ->orderBy('updated_at', 'desc')
  7766. // ->limit(5)
  7767. ->get();
  7768. //获取5条用户待处理的投诉
  7769. $complaint_deal = Complaint::where('status', 2)
  7770. ->where('deal', 1)
  7771. ->whereJsonContains('re_user_ids', $user_id)
  7772. ->orderBy('updated_at', 'desc')
  7773. // ->limit(5)
  7774. ->get();
  7775. //获取 被通知者未读信息
  7776. $notice_unread = Notice::where('status', 2)
  7777. ->whereJsonContains('re_user_ids', $user_id)
  7778. //未读消息
  7779. ->where(function ($query) use ($user_id) {
  7780. $query->whereJsonDoesntContain('read_id', $user_id)
  7781. ->orWhereNull('read_id');
  7782. })
  7783. ->orderBy('updated_at', 'desc')
  7784. ->get();
  7785. $complaint_unread = Complaint::where('status', 2)
  7786. ->whereJsonContains('re_user_ids', $user_id)
  7787. //未读消息
  7788. ->where(function ($query) use ($user_id) {
  7789. $query->whereJsonDoesntContain('read_id', $user_id)
  7790. ->orWhereNull('read_id');
  7791. })
  7792. ->orderBy('updated_at', 'desc')
  7793. ->get();
  7794. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7795. $complany = Company::where('status', 1)
  7796. ->where('user_id', $user_id)
  7797. ->orderBy('updated_at', 'desc')
  7798. // ->limit(5)
  7799. ->get();
  7800. //获取5条单聊未读聊天消息
  7801. // $chat = ChatRecords::where('is_read', 0)
  7802. // ->where('user_id', $user_id)
  7803. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7804. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7805. // ->where('action', 'recieved')
  7806. // ->where('talk_type', 1)
  7807. // ->orderBy('created_at', 'desc')
  7808. // // ->limit(5)
  7809. // ->get();
  7810. //获取5条未读群聊信息
  7811. // $chat_group = ChatRecords::where('is_read', 0)
  7812. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7813. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7814. // ->where('user_id', $user_id)
  7815. // ->where('talk_type', 2)
  7816. // ->orderBy('created_at', 'desc')
  7817. // // ->limit(5)
  7818. // ->get();
  7819. //获取5条用户的待审核项目
  7820. $project = Project::where('status', 1)
  7821. ->where('user_id', $user_id)
  7822. ->orderBy('updated_at', 'desc')
  7823. // ->limit(5)
  7824. ->get();
  7825. // count($chat) + count($chat_group) +
  7826. $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)
  7827. + count($complany)
  7828. + count($project)
  7829. + count($notice_unread)
  7830. + count($complaint_unread)
  7831. // + count($chat) + count($chat_group)
  7832. ;
  7833. $result = [
  7834. 'apply_articale' => $apply_articale,
  7835. // 'chat' => $chat,
  7836. // 'chat_group' => $chat_group,
  7837. 'good' => $good,
  7838. 'notice' => $notice,
  7839. 'complaint' => $complaint,
  7840. 'book' => $book,
  7841. 'job_hunting' => $job_hunting,
  7842. 'job_recruiting' => $job_recruiting,
  7843. 'job_apply' => $job_apply,
  7844. 'job_resume' => $job_resume,
  7845. 'complaint_deal' => $complaint_deal,
  7846. 'complany' => $complany,
  7847. 'project' => $project,
  7848. 'notice_unread' => $notice_unread,
  7849. 'complaint_unread' => $complaint_unread,
  7850. 'count' => $count,
  7851. ];
  7852. } elseif ($type_id == 12) {
  7853. //最近的5篇已审的文章
  7854. $apply_articale = Article::where('status', 1)
  7855. ->where('admin_user_id', $user_id)
  7856. ->limit(5)->get();
  7857. //获取5条单聊未读聊天消息
  7858. $chat = ChatRecords::where('is_read', 0)
  7859. ->where('user_id', $user_id)
  7860. ->where('talk_type', 1)
  7861. ->orderBy('created_at', 'desc')
  7862. ->limit(5)->get();
  7863. //获取5条未读群聊信息
  7864. $chat_group = ChatRecords::where('is_read', 0)
  7865. ->where('user_id', $user_id)
  7866. ->where('talk_type', 2)
  7867. ->orderBy('created_at', 'desc')
  7868. ->limit(5)->get();
  7869. //获取5条用户的已审核商品
  7870. $good = Good::where('status', 2)
  7871. ->where('user_id', $user_id)
  7872. ->orderBy('updated_at', 'desc')
  7873. ->limit(5)->get();
  7874. //获取5条用户的book
  7875. $book = Book::where('status', 2)
  7876. ->where('user_id', $user_id)
  7877. ->orderBy('updated_at', 'desc')
  7878. ->limit(5)->get();
  7879. //获取5条用户的求职
  7880. //获取5条用户的求职 1
  7881. //count($chat) + count($chat_group)
  7882. $count = count($apply_articale) + count($good);
  7883. $result = [
  7884. 'apply_articale' => $apply_articale,
  7885. 'chat' => $chat,
  7886. 'chat_group' => $chat_group,
  7887. 'good' => $good,
  7888. 'book' => $book,
  7889. 'count' => $count,
  7890. ];
  7891. } elseif ($type_id == 13) {
  7892. //最近的5篇已审的文章
  7893. $apply_articale = Article::where('status', 1)
  7894. ->where('admin_user_id', $user_id)
  7895. ->limit(5)->get();
  7896. //获取5条单聊未读聊天消息
  7897. $chat = ChatRecords::where('is_read', 0)
  7898. ->where('user_id', $user_id)
  7899. ->where('talk_type', 1)
  7900. ->orderBy('created_at', 'desc')
  7901. ->limit(5)->get();
  7902. //获取5条未读群聊信息
  7903. $chat_group = ChatRecords::where('is_read', 0)
  7904. ->where('user_id', $user_id)
  7905. ->where('talk_type', 2)
  7906. ->orderBy('created_at', 'desc')
  7907. ->limit(5)->get();
  7908. //获取5条用户的已审核商品
  7909. $good = Good::where('status', 2)
  7910. ->where('user_id', $user_id)
  7911. ->orderBy('updated_at', 'desc')
  7912. ->limit(5)->get();
  7913. //count($chat) + count($chat_group) +
  7914. $count = count($apply_articale) + count($good);
  7915. $result = [
  7916. 'apply_articale' => $apply_articale,
  7917. 'chat' => $chat,
  7918. 'chat_group' => $chat_group,
  7919. 'good' => $good,
  7920. 'count' => $count,
  7921. ];
  7922. } elseif ($type_id == 14) {
  7923. //最近的5篇已审的文章
  7924. $apply_articale = Article::where('status', 1)
  7925. ->where('admin_user_id', $user_id)
  7926. // ->limit(5)
  7927. ->get();
  7928. //获取5条用户的已审核商品
  7929. $good = Good::where('status', 2)
  7930. ->where('user_id', $user_id)
  7931. ->orderBy('updated_at', 'desc')
  7932. // ->limit(5)
  7933. ->get();
  7934. $count = count($apply_articale) + count($good);
  7935. $result = [
  7936. 'apply_articale' => $apply_articale,
  7937. 'chat' => '',
  7938. 'chat_group' => '',
  7939. 'good' => $good,
  7940. 'count' => $count,
  7941. ];
  7942. } elseif ($type_id == 10000) {
  7943. //获取未审核的5篇文章
  7944. $apply_articale = Article::where('status', 0)
  7945. ->orderBy('updated_at', 'desc')
  7946. // ->limit(5)
  7947. ->get();
  7948. //获取5条单聊未读聊天消息
  7949. //获取5条单聊未读聊天消息
  7950. // $chat = ChatRecords::where('is_read', 0)
  7951. // ->where('user_id', $user_id)
  7952. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7953. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7954. // ->where('action', 'recieved')
  7955. // ->where('talk_type', 1)
  7956. // ->orderBy('created_at', 'desc')
  7957. // // ->limit(5)
  7958. // ->get();
  7959. // //获取5条未读群聊信息
  7960. // $chat_group = ChatRecords::where('is_read', 0)
  7961. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7962. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7963. // ->where('user_id', $user_id)
  7964. // ->where('talk_type', 2)
  7965. // ->orderBy('created_at', 'desc')
  7966. // // ->limit(5)
  7967. // ->get();
  7968. //获取5条用户的已审核商品
  7969. $good = Good::where('status', 1)
  7970. // ->where('user_id', $user_id)
  7971. ->orderBy('updated_at', 'desc')
  7972. // ->limit(5)
  7973. ->get();
  7974. //获取5条用户待审核的公告
  7975. $notice = Notice::where('status', 1)
  7976. ->orderBy('updated_at', 'desc')
  7977. // ->limit(5)
  7978. ->get();
  7979. //获取5条用户的待审核投诉
  7980. $complaint = Complaint::where('status', 1)
  7981. ->orderBy('updated_at', 'desc')
  7982. // ->limit(5)
  7983. ->get();
  7984. //获取5条用户的book
  7985. $book = Book::where('status', 1)
  7986. ->orderBy('updated_at', 'desc')
  7987. // ->limit(5)
  7988. ->get();
  7989. //获取5条用户的求职 1
  7990. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7991. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7992. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7993. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7994. ->orderBy('updated_at', 'desc')
  7995. // ->limit(5)
  7996. ->get();
  7997. //获取5条用户的求职 2
  7998. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7999. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  8000. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  8001. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8002. ->orderBy('updated_at', 'desc')
  8003. // ->limit(5)
  8004. ->get();
  8005. //人才库 1
  8006. $job_apply = JobApply::where('job_apply.status', 1)
  8007. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  8008. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  8009. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  8010. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  8011. ->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')
  8012. ->orderBy('updated_at', 'desc')
  8013. // ->limit(5)
  8014. ->get();
  8015. // 职场机会 2
  8016. $job_resume = JobResume::where('job_resume.status', 1)
  8017. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  8018. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  8019. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  8020. ->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')
  8021. ->orderBy('updated_at', 'desc')
  8022. // ->limit(5)
  8023. ->get();
  8024. //待审核数据com pro
  8025. $complany = Company::where('status', 0)
  8026. ->orderBy('updated_at', 'desc')
  8027. // ->limit(5)
  8028. ->get();
  8029. $project = Project::where('status', 0)
  8030. ->orderBy('updated_at', 'desc')
  8031. // ->limit(5)
  8032. ->get();
  8033. $count =
  8034. // count($chat) +
  8035. // count($chat_group) +
  8036. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8037. // + count($job_apply)
  8038. // + count($job_resume)
  8039. + count($complany)
  8040. + count($project);
  8041. $result = [
  8042. 'apply_articale' => $apply_articale,
  8043. // 'chat' => $chat,
  8044. // 'chat_group' => $chat_group,
  8045. 'good' => $good,
  8046. 'notice' => $notice,
  8047. 'complaint' => $complaint,
  8048. 'book' => $book,
  8049. 'job_hunting' => $job_hunting,
  8050. 'job_recruiting' => $job_recruiting,
  8051. // 'job_apply' => $job_apply,
  8052. // 'job_resume' => $job_resume,
  8053. 'complany' => $complany,
  8054. 'project' => $project,
  8055. 'count' => $count,
  8056. ];
  8057. } elseif ($type_id == 20000) {
  8058. }
  8059. var_dump($type_id, '-----------------test---------');
  8060. return Result::success($result);
  8061. }
  8062. /**
  8063. * @param array $data
  8064. * @return array
  8065. */
  8066. public function getWebsiteProject(array $data): array
  8067. {
  8068. $categorys = json_decode($data['id'], true);
  8069. if (!empty($categorys)) {
  8070. $category_arr = $this->processArticlePro($data['website_id']);
  8071. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8072. $catiall = $category_arr['catiall'];
  8073. // return Result::success($catiall);
  8074. foreach ($categorys as $key => $val) {
  8075. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8076. $level = explode(',', $val['level'])[0];
  8077. $imgnum = explode(',', $val['level'])[1] ?? null;
  8078. $textnum = explode(',', $val['level'])[2] ?? null;
  8079. if ($level == 1) {
  8080. if (!empty($textnum) && $textnum > 0) {
  8081. $text_num = Project::where('level', $level)
  8082. ->where('website_id', $data['website_id'])
  8083. ->where('status', 1)
  8084. ->select(
  8085. 'project.id',
  8086. 'project.title',
  8087. 'project.description',
  8088. 'project.updated_at',
  8089. 'project.category_id',
  8090. 'project.cat_arr_id'
  8091. )
  8092. ->orderBy('updated_at', 'desc')
  8093. ->limit($textnum)
  8094. ->get()->all();
  8095. }
  8096. if (!empty($imgnum) && $imgnum > 0) {
  8097. $img_num = Project::where('level', $level)
  8098. ->where('website_id', $data['website_id'])
  8099. ->where('status', 1)
  8100. ->where('imgurl', '!=', '')
  8101. ->whereNotNull('imgurl')
  8102. ->select(
  8103. 'project.id',
  8104. 'project.title',
  8105. 'project.description',
  8106. 'project.updated_at',
  8107. 'project.imgurl as imgs',
  8108. 'project.category_id',
  8109. 'project.cat_arr_id'
  8110. )
  8111. ->orderBy('updated_at', 'desc')
  8112. ->limit($imgnum)
  8113. ->get()->all();
  8114. }
  8115. } else {
  8116. if (!empty($textnum) && $textnum > 0) {
  8117. $text_num = Project::where('website_id', $data['website_id'])
  8118. ->where('status', 1)
  8119. ->select(
  8120. 'project.id',
  8121. 'project.title',
  8122. 'project.description',
  8123. 'project.updated_at',
  8124. 'project.category_id',
  8125. 'project.cat_arr_id',
  8126. 'project.website_id',
  8127. 'project.updated_at',
  8128. 'project.created_at'
  8129. )
  8130. ->orderBy('updated_at', 'desc')
  8131. ->limit($textnum)
  8132. ->get()->all();
  8133. }
  8134. if (!empty($imgnum) && $imgnum > 0) {
  8135. $img_num = Project::where('website_id', $data['website_id'])
  8136. ->where('status', 1)
  8137. ->where('imgurl', '!=', '')
  8138. ->whereNotNull('imgurl')
  8139. ->select(
  8140. 'project.id',
  8141. 'project.title',
  8142. 'project.description',
  8143. 'project.updated_at',
  8144. 'project.imgurl as imgs',
  8145. 'project.category_id',
  8146. 'project.cat_arr_id'
  8147. )
  8148. ->orderBy('updated_at', 'desc')
  8149. ->limit($imgnum)
  8150. ->get()->all();
  8151. }
  8152. }
  8153. }
  8154. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8155. $category_ids = explode(',', $val['id'])[0];
  8156. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8157. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8158. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8159. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8160. $text_num = Project::whereIn('category_id', $category_arr)
  8161. ->where('website_id', $data['website_id'])
  8162. ->where('status', 1)
  8163. ->select(
  8164. 'project.id',
  8165. 'project.title',
  8166. 'project.description',
  8167. 'project.updated_at',
  8168. 'project.category_id',
  8169. 'project.cat_arr_id'
  8170. )
  8171. ->orderBy('updated_at', 'desc')
  8172. ->limit($cat_textnum)
  8173. ->get()->all();
  8174. }
  8175. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8176. $img_num = Project::whereIn('category_id', $category_arr)
  8177. ->where('website_id', $data['website_id'])
  8178. ->where('status', 1)
  8179. ->where('imgurl', '!=', '')
  8180. ->whereNotNull('imgurl')
  8181. ->select(
  8182. 'project.id',
  8183. 'project.title',
  8184. 'project.description',
  8185. 'project.updated_at',
  8186. 'project.imgurl as imgs',
  8187. 'project.category_id',
  8188. 'project.cat_arr_id'
  8189. )
  8190. ->orderBy('updated_at', 'desc')
  8191. ->limit($cat_imgnum)
  8192. ->get()->all();
  8193. }
  8194. }
  8195. if (!empty($img_num)) {
  8196. foreach ($img_num as $k => $v) {
  8197. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8198. $imgurl = json_decode($v['imgs'], true);
  8199. if (!empty($imgurl)) {
  8200. $img_num[$k]->imgurl = $imgurl[0];
  8201. }
  8202. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8203. }
  8204. }
  8205. if (!empty($text_num)) {
  8206. foreach ($text_num as $k => $v) {
  8207. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8208. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8209. }
  8210. }
  8211. $project[$key]['img_num'] = $img_num ?? [];
  8212. $project[$key]['text_num'] = $text_num ?? [];
  8213. }
  8214. }
  8215. if (empty($project)) {
  8216. return Result::error("暂无相关项目信息", 0);
  8217. }
  8218. return Result::success($project);
  8219. }
  8220. /**
  8221. * @param array $data
  8222. * @return array
  8223. */
  8224. public function getWebsiteProjectInfo(array $data): array
  8225. {
  8226. $project = Project::where('id', $data['id'])
  8227. ->where('status', 1)
  8228. ->where('website_id', $data['website_id'])
  8229. ->select('project.*')
  8230. ->first();
  8231. if (empty($project)) {
  8232. return Result::error("暂无相关项目信息", 0);
  8233. }
  8234. return Result::success($project);
  8235. }
  8236. /**
  8237. * @param array $data
  8238. * @return array
  8239. */
  8240. public function getWebsiteProjectList(array $data): array
  8241. {
  8242. $where = [];
  8243. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8244. $where['category_id'] = $data['category_id'];
  8245. }
  8246. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8247. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8248. }
  8249. $query = Project::where($where)
  8250. ->where('status', 1)
  8251. ->where('website_id', $data['website_id'])
  8252. ->select(
  8253. 'project.id',
  8254. 'project.title',
  8255. 'project.description',
  8256. 'project.imgurl as imgs',
  8257. 'project.category_id',
  8258. 'project.cat_arr_id'
  8259. )
  8260. ->orderBy('updated_at', 'desc');
  8261. $count = $query->count();
  8262. $project = $query->clone()
  8263. ->offset(($data['page'] - 1) * $data['pageSize'])
  8264. ->limit($data['pageSize'])
  8265. ->get()->all();
  8266. if (empty($project)) {
  8267. return Result::error("暂无相关项目信息", 0);
  8268. }
  8269. $categorys = $this->processArticlePro($data['website_id']);
  8270. $catiall = $categorys['catiall'];
  8271. foreach ($project as $key => $val) {
  8272. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8273. if (!empty($val['imgs'])) {
  8274. $imgurl = json_decode($val['imgs'], true);
  8275. if (!empty($imgurl)) {
  8276. $project[$key]->imgurl = $imgurl[0];
  8277. }
  8278. } else {
  8279. $project[$key]->imgurl = '';
  8280. }
  8281. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8282. }
  8283. $result = [
  8284. 'rows' => $project,
  8285. 'count' => $count,
  8286. ];
  8287. return Result::success($result);
  8288. }
  8289. /**
  8290. * @param array $data
  8291. * @return array
  8292. */
  8293. public function getWebsiteCategoryJob(array $data): array
  8294. {
  8295. $categorys = json_decode($data['id'], true);
  8296. if (!empty($categorys)) {
  8297. $category_arr = $this->processArticlePro($data['website_id']);
  8298. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8299. $catiall = $category_arr['catiall'];
  8300. foreach ($categorys as $key => $val) {
  8301. if (isset($val['id']) && !empty($val['id'])) {
  8302. $catid = explode(',', $val['id'])[0] ?? null;
  8303. $type = explode(',', $val['id'])[1] ?? null;
  8304. $textnum = explode(',', $val['id'])[2] ?? null;
  8305. }
  8306. // 4:招聘;5:求职;
  8307. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8308. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8309. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8310. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8311. ->where('job_recruiting.status', 1)
  8312. ->where('job_recruiting.website_id', $data['website_id'])
  8313. ->select(
  8314. 'job_recruiting.id',
  8315. 'job_recruiting.title',
  8316. 'job_company.business_name',
  8317. 'job_recruiting.updated_at',
  8318. 'job_recruiting.cat_arr_id',
  8319. 'job_recruiting.keyword',
  8320. 'job_recruiting.description'
  8321. )
  8322. ->orderBy('job_recruiting.updated_at', 'desc')
  8323. ->limit($textnum)
  8324. ->get()->all();
  8325. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8326. // 状态 审核状态,1待审核2已审核3已拒绝
  8327. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8328. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8329. ->where('job_hunting.status', 2)
  8330. ->where('job_hunting.website_id', $data['website_id'])
  8331. ->select(
  8332. 'job_hunting.id',
  8333. 'job_hunting.name',
  8334. 'job_hunting.cat_arr_id',
  8335. 'job_position.zwname as job_name',
  8336. 'job_hunting.updated_at',
  8337. // 'job_hunting.keyword',
  8338. 'job_hunting.slelf_evaluation'
  8339. )
  8340. ->orderBy('updated_at', 'desc')
  8341. ->limit($textnum)
  8342. ->get()->all();
  8343. } else {
  8344. $job = [];
  8345. }
  8346. // var_dump($catid.'222uuuuuuu'.$key);
  8347. if (!empty($job)) {
  8348. foreach ($job as $k => $value) {
  8349. if (isset($value->cat_arr_id)) {
  8350. $catArr = json_decode($value->cat_arr_id, true);
  8351. $catId = end($catArr);
  8352. } else {
  8353. continue;
  8354. }
  8355. if (isset($catiall[$catId])) {
  8356. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8357. }
  8358. }
  8359. }
  8360. // var_dump($catid.'xxxxx'.$key);
  8361. $result[$key] = $job ?? [];
  8362. }
  8363. }
  8364. if (empty($result)) {
  8365. return Result::error("暂无相关分类信息", 0);
  8366. }
  8367. return Result::success($result);
  8368. }
  8369. /**
  8370. * 发送消息
  8371. * @param array $messageData
  8372. * @return void
  8373. */
  8374. public function sendMessage($messageData)
  8375. {
  8376. $msg = [
  8377. 'talk_type' => $messageData['talk_type'],
  8378. 'title' => $messageData['title'],
  8379. 'content' => $messageData['content'],
  8380. 'messageType' => $messageData['messageType'],
  8381. 'user_id' => $messageData['user_id'] ?? '',
  8382. 'time' => microtime(),
  8383. ];
  8384. $message = new MqProducer($msg);
  8385. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8386. $producer->produce($message);
  8387. }
  8388. /**
  8389. * 行业分类管理 ------1121
  8390. * @param array $data
  8391. * @return array
  8392. */
  8393. public function getJobIndustryList(array $data): array
  8394. {
  8395. $page = $data['page'] ?? 1;
  8396. $page_size = $data['page_size'] ?? 10;
  8397. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8398. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8399. } else {
  8400. $where = [];
  8401. }
  8402. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8403. $query->where([$where]); // 修复:将条件包装成二维数组
  8404. })
  8405. ->orderBy('updated_at', 'desc');
  8406. $count = $rs_query->count();
  8407. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8408. $result = [
  8409. 'count' => $count,
  8410. 'list' => $hy,
  8411. ];
  8412. if (empty($hy)) {
  8413. return Result::success('暂无数据');
  8414. }
  8415. return Result::success($result);
  8416. }
  8417. /**
  8418. * 添加行业分类
  8419. * @param array $data
  8420. * @return array
  8421. */
  8422. public function addJobIndustry(array $data): array
  8423. {
  8424. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8425. if (!empty($hy_name)) {
  8426. return Result::error('行业分类已存在');
  8427. }
  8428. $hy = JobIndustry::insertGetId($data);
  8429. if (empty($hy)) {
  8430. return Result::error('添加失败');
  8431. }
  8432. return Result::success($hy);
  8433. }
  8434. /**
  8435. * 更新行业分类
  8436. * @param array $data
  8437. * @return array
  8438. */
  8439. public function upJobIndustry(array $data): array
  8440. {
  8441. $hy_query = JobIndustry::get();
  8442. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8443. $hy_names = $hy_query->pluck('hyname')->toArray();
  8444. if (!in_array($data['hyid'], $hy_ids)) {
  8445. return Result::error('行业分类不存在');
  8446. }
  8447. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8448. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8449. // return Result::success($other_key_hy);
  8450. unset($hy_names[$other_key_hy]);
  8451. if (in_array($data['hyname'], $hy_names)) {
  8452. return Result::error('行业分类名称已存在');
  8453. }
  8454. }
  8455. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8456. if (empty($hy)) {
  8457. return Result::error('更新失败');
  8458. }
  8459. return Result::success($hy);
  8460. }
  8461. /**
  8462. * 删除行业分类
  8463. * @param array $data
  8464. * @return array
  8465. */
  8466. public function delJobIndustry(array $data): array
  8467. {
  8468. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8469. if (empty($hy_id)) {
  8470. return Result::error('行业分类不存在');
  8471. }
  8472. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  8473. if (empty($hy)) {
  8474. return Result::error('删除失败');
  8475. }
  8476. return Result::success($hy);
  8477. }
  8478. /**
  8479. * 职位分类-列表
  8480. * @param array $data
  8481. * @return array
  8482. */
  8483. public function getJobPositionList(array $data): array
  8484. {
  8485. $page = $data['page'] ?? 1;
  8486. $page_size = $data['page_size'] ?? 10;
  8487. $where = [];
  8488. if (isset($data['zwname']) && !empty($data['zwname'])) {
  8489. $zwids = JobPosition::where('zwpid', 0)
  8490. ->when(!empty($data['zwname']), function ($query) use ($data) {
  8491. $query->where('zwname', 'like', '%' . $data['zwname'] . '%');
  8492. })
  8493. ->orderBy('updated_at', 'desc')
  8494. ->pluck('zwid')
  8495. // ->get()
  8496. ->toArray();
  8497. }
  8498. if (isset($data['childname']) && !empty($data['childname'])) {
  8499. $child_zwids = JobPosition::where('zwpid', '!=', 0)
  8500. ->when(!empty($data['childname']), function ($query) use ($data) {
  8501. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8502. })
  8503. ->orderBy('updated_at', 'desc')
  8504. ->pluck('zwpid')
  8505. // ->get()
  8506. ->toArray();
  8507. if (isset($zwids) && is_array($zwids) && is_array($child_zwids)) {
  8508. $child_zwids = array_intersect($zwids, $child_zwids);
  8509. }
  8510. $zwids = array_values(array_unique($child_zwids));
  8511. }
  8512. $zwids = $zwids ?? null;
  8513. $count = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8514. $query->whereIn('zwid', $zwids);
  8515. })
  8516. ->where('zwpid', 0)
  8517. ->count();
  8518. $position = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8519. $query->whereIn('zwid', $zwids);
  8520. })
  8521. ->where('zwpid', 0)
  8522. ->orderBy('updated_at', 'desc')
  8523. ->offset(($page - 1) * $page_size)
  8524. ->limit($page_size)->get()
  8525. ->map(function ($item) use ($data) {
  8526. $item->children = $item->where('zwpid', $item->zwid)
  8527. ->when(!empty($data['childname']), function ($query) use ($data) {
  8528. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8529. })
  8530. ->orderBy('updated_at', 'desc')
  8531. ->get();
  8532. return $item;
  8533. })
  8534. ->all();
  8535. $result = [
  8536. 'count' => $count,
  8537. 'list' => $position,
  8538. ];
  8539. if (empty($result)) {
  8540. return Result::success('暂无数据');
  8541. }
  8542. return Result::success($result);
  8543. }
  8544. /**
  8545. * 职位分类-添加
  8546. * @param array $data
  8547. * @return array
  8548. */
  8549. public function addJobPosition(array $data): array
  8550. {
  8551. $zw_name = JobPosition::where('zwpid', $data['zwpid'])
  8552. ->where('zwname', $data['zwname'])->first(['zwid']);
  8553. if (!empty($zw_name)) {
  8554. return Result::error('职位分类已存在');
  8555. }
  8556. $zw = JobPosition::insertGetId($data);
  8557. if(empty($zw)){
  8558. return Result::error('添加失败');
  8559. }
  8560. return Result::success($zw);
  8561. }
  8562. /**
  8563. * 更新职位分类
  8564. * @param array $data
  8565. * @return array
  8566. */
  8567. public function upJobPosition(array $data): array
  8568. {
  8569. $zw_position = JobPosition::get();
  8570. if (!in_array($data['zwid'], $zw_position->pluck('zwid')->toArray())) {
  8571. return Result::error('职位分类不存在');
  8572. }
  8573. $zw_name = $zw_position->where('zwid', '!=', $data['zwid'])
  8574. ->where('zwpid', $data['zwpid'])
  8575. ->where('zwname', $data['zwname'])->first();
  8576. if (!empty($zw_name)) {
  8577. return Result::error('职位分类已存在');
  8578. }
  8579. $result = JobPosition::where('zwid', $data['zwid'])->update($data);
  8580. if (empty($result)) {
  8581. return Result::error('更新失败');
  8582. }
  8583. return Result::success($result);
  8584. }
  8585. /**
  8586. * 删除职位分类
  8587. * @param array $data
  8588. * @return array
  8589. */
  8590. public function delJobPosition(array $data): array
  8591. {
  8592. $zw_jobposition = JobPosition::get();
  8593. $zw_id = $zw_jobposition->where('zwid', $data['zwid'])->first();
  8594. if (empty($zw_id)) {
  8595. return Result::error('职位分类不存在');
  8596. }
  8597. if($zw_id->zwpid == 0){
  8598. $zw_job = JobPosition::where('zwpid', $zw_id->zwid)->first();
  8599. if(!empty($zw_job)){
  8600. return Result::error('请先删除子分类');
  8601. }
  8602. }
  8603. $result = JobPosition::where('zwid', $data['zwid'])->delete();
  8604. if (empty($result)) {
  8605. return Result::error('删除失败');
  8606. }
  8607. return Result::success($result);
  8608. }
  8609. }