NewsService.php 324 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850
  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. // 非管理员限制
  439. ->when($type_id != 10000, function ($query) use ($user_id) {
  440. $query->where('article.admin_user_id', '=', $user_id);
  441. })
  442. // 基础条件
  443. ->whereNotIn('article.status', [404])
  444. // 排序和分页
  445. ->orderBy('article.updated_at', 'desc')
  446. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  447. // 获取结果并格式化
  448. $data = [
  449. 'rows' => $rep->items(),
  450. 'count' => $rep->total(),
  451. ];
  452. // 执行查询
  453. $endTime = microtime(true);
  454. $executionTime = ($endTime - $startTime) * 1000;
  455. echo "查询执行时间: {$executionTime}ms\n";
  456. return Result::success($data);
  457. }
  458. /**
  459. * @param array $data
  460. * @return array
  461. */
  462. public function addArticle(array $data): array
  463. {
  464. var_dump($data, '----------12-----------1');
  465. // ------c_show_time********add***1****
  466. $is_collect = $data['is_collect'] ?? 0;
  467. $user_type = $data['user_type'];
  468. unset($data['is_collect']);
  469. unset($data['user_type']);
  470. // ------c_show_time********add***1****
  471. unset($data['nav_add_pool_id']);
  472. // unset($data['commend_id']);
  473. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  474. Db::beginTransaction();
  475. try {
  476. //处理投票
  477. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  478. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  479. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  480. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  481. unset($data['is_survey']);
  482. unset($data['survey_name']);
  483. unset($data['suvey_array']);
  484. // unset($data['website_id']);
  485. // unset($data['web_site_id']);
  486. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  487. if ($data['hits'] == '') {
  488. $data['hits'] = 0;
  489. }
  490. if ($data['is_original'] == '') {
  491. $data['is_original'] = 0;
  492. }
  493. if ($data['status'] == '') {
  494. $data['status'] = 0;
  495. }
  496. $articleData = $data;
  497. unset($articleData['content']);
  498. //自动处理缩略图、关键字、描述
  499. if ($articleData['imgurl'] == '') {
  500. //如果没有图,设置level=0
  501. $levelArr = json_decode($articleData['level'], true);
  502. var_dump($levelArr, '----------levelArr-----------1');
  503. //content中提取图片第一个图,正则提取
  504. // -------采集器相关优化-----
  505. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  506. if ($is_collect == 1) {
  507. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  508. } else {
  509. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  510. }
  511. // -------采集器相关优化-----
  512. preg_match_all($reg, $data['content'], $matches);
  513. if (isset($matches[1][0])) {
  514. //截取varchar240
  515. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  516. //如果有图,设置level=3
  517. if (!in_array(3, $levelArr)) {
  518. $levelArr[] = 3;
  519. }
  520. $articleData['level'] = json_encode($levelArr);
  521. } else {
  522. if (!in_array(0, $levelArr)) {
  523. $levelArr[] = 0;
  524. }
  525. $articleData['level'] = json_encode($levelArr);
  526. }
  527. }
  528. var_dump($articleData['level'], '----------$articleData[level]----------1');
  529. if ($articleData['keyword'] == '') {
  530. //提取标题+内容中的关键词
  531. $articleData['keyword'] = $data['title'];
  532. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  533. Jieba::init(); // 初始化 jieba-php
  534. Finalseg::init();
  535. $segList = Jieba::cut($articleData['keyword']);
  536. $segList1 = array_slice($segList, 0, 8);
  537. $articleData['keyword'] = implode(',', $segList1);
  538. }
  539. if ($articleData['introduce'] == '') {
  540. //提取内容中的描述
  541. $content = $data['content'];
  542. // 去除 <style> 和 <script> 标签及其内容
  543. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  544. // 去除所有 HTML 标签
  545. $content = strip_tags($content);
  546. // 去除 HTML 实体
  547. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  548. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  549. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  550. // 去除多余空白
  551. $content = preg_replace('/\s+/u', '', $content);
  552. // 截取 100 个字符
  553. $articleData['introduce'] = mb_substr($content, 0, 100);
  554. }
  555. if ($articleData['status'] == 0) {
  556. $this->sendMessage([
  557. 'talk_type' => 100,
  558. 'title' => $articleData['title'],
  559. 'content' => '提交了审核',
  560. 'messageType' => 2,
  561. ]);
  562. }
  563. $id = Article::insertGetId($articleData);
  564. if (!$id) {
  565. throw new \Exception('文章插入失败');
  566. }
  567. $articleDataContent = [
  568. 'article_id' => $id,
  569. 'content' => $data['content'],
  570. ];
  571. // 采集器中的文章内容,在添加时,去掉div标签
  572. if ($is_collect == 1) {
  573. // 采集来的文章,content中可能包含div标签,需要先移除
  574. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  575. $article_data = preg_replace($pattern, '', $data['content']);
  576. $$articleDataContent['content'] = $article_data;
  577. }
  578. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  579. if (!$contentInsertId) {
  580. throw new \Exception('文章内容插入失败');
  581. }
  582. // ------c_show_time********add***2****
  583. // 直接使用当前系统时间,不再强制添加8小时
  584. $now = date('Y-m-d H:i:s');
  585. if ($user_type == 10000 || $is_collect == 1) {
  586. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  587. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  588. if (!isset($data['catid'])) {
  589. throw new \Exception('缺少必要字段:catid');
  590. }
  591. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  592. $web = WebsiteCategory::where('category_id', $data['catid'])
  593. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  594. ->select(
  595. 'website_id',
  596. 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')
  597. )
  598. ->get();
  599. // $id = 225; -----测试开启
  600. // 采集来的文章,错开时间在两小时之内发布
  601. if ($user_type == 10000 && $is_collect == 1) {
  602. $web_num = $web->where('is_core', '!=', 2)->count();
  603. $waiting_interval = 10;
  604. if ($web_num > 12) {
  605. // 若网站数量大于12个,则每个网站间隔时间取均值
  606. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  607. $waiting_interval = 120 / max(1, $web_num);
  608. }
  609. $time = 0;
  610. } else {
  611. // 非核心站与核心站----显示时间-----间隔
  612. $time = 20;
  613. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  614. $waiting_interval = 5;
  615. }
  616. // 将 Hyperf\Database\Model\Collection 转换为数组
  617. $webArray = $web->toArray();
  618. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  619. // 检查 $item 对象是否有 is_core 属性
  620. if (!isset($item['is_core'])) {
  621. throw new \Exception('$item 对象缺少 is_core 属性');
  622. }
  623. // 当 is_core 为 2 时,则表示此网站不存在
  624. if ($item['is_core'] == 2) {
  625. return null;
  626. }
  627. if ($is_collect == 1) {
  628. // 采集来的文章,错开时间在两小时之内发布
  629. // $time = 0;
  630. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  631. $time += $waiting_interval;
  632. } else if ($item['is_core'] == 1) {
  633. // 当 is_core 为 1 时,则表示此网站是核心站
  634. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  635. } else {
  636. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  637. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  638. if ($item['is_core'] == 0) {
  639. $time += $waiting_interval;
  640. }
  641. }
  642. return [
  643. 'article_id' => $id,
  644. 'website_id' => $item['website_id'],
  645. 'c_show_time' => $c_show_time,
  646. // 'is_core' => $item['is_core'],
  647. // 'time' => $time
  648. ];
  649. }, array_keys($webArray), $webArray)));
  650. // Db::commit();
  651. // return Result::success($article_ignore);
  652. if (!empty($article_ignore)) {
  653. $article_ignores = ArticleIgnore::insert($article_ignore);
  654. if (!$article_ignores) {
  655. throw new \Exception('c端展示时间插入失败');
  656. }
  657. }
  658. }
  659. // ------c_show_time********add***2****
  660. //处理投票
  661. if ($is_survey == 1) {
  662. //生成年月日时分秒+8位随机数
  663. $uuid = date('YmdHis') . rand(10000000, 99999999);
  664. var_dump($suvey_array, 'suvey_array________');
  665. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  666. var_dump($suveys_array, '---------------------1');
  667. var_dump($suvey_array, '---------------------2');
  668. $suvey_data = [];
  669. foreach ($suveys_array as $key => $value) {
  670. if ($value == '') {
  671. continue;
  672. }
  673. if (is_array($value)) {
  674. $suvey_data[] = [
  675. 'sur_id' => $uuid,
  676. 'art_id' => $id,
  677. 'website_id' => $website_id ?? 2,
  678. 'survey_name' => $survey_name,
  679. 'choice_name' => $value[1],
  680. 'is_other' => 1,
  681. 'other_id' => 0,
  682. 'results' => 0,
  683. ];
  684. } else {
  685. $suvey_data[] = [
  686. 'sur_id' => $uuid,
  687. 'art_id' => $id,
  688. 'website_id' => $website_id ?? 2,
  689. 'survey_name' => $survey_name,
  690. 'choice_name' => $value,
  691. 'is_other' => 0,
  692. 'other_id' => 0,
  693. 'results' => 0,
  694. ];
  695. }
  696. if (empty($suvey_data)) {
  697. throw new \Exception("投票数据为空");
  698. }
  699. }
  700. $result = ArticleSurvey::insert($suvey_data);
  701. if (!$result) {
  702. throw new \Exception("投票失败,ArticleSurvey插入失败");
  703. }
  704. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  705. if (!$result) {
  706. throw new \Exception("投票失败,更新主表失败");
  707. }
  708. }
  709. Db::commit();
  710. return Result::success(['id' => $id]);
  711. } catch (\Throwable $ex) {
  712. Db::rollBack();
  713. var_dump($ex->getMessage());
  714. return Result::error("创建失败", 0);
  715. }
  716. }
  717. /**
  718. * @param array $data
  719. * @return array
  720. */
  721. public function delArticle(array $data): array
  722. {
  723. // ------c_show_time********del*******
  724. Db::beginTransaction();
  725. try {
  726. $article = Article::where(['id' => $data['id']])->delete();
  727. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  728. if (!$article) {
  729. throw new \Exception("删除失败,文章删除失败");
  730. }
  731. //survey投票删除
  732. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  733. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  734. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  735. // 若文章详情删除失败,抛出异常
  736. if (!$article_data) {
  737. throw new \Exception("删除失败,文章详情删除失败");
  738. }
  739. Db::commit(); // 所有操作成功,提交事务
  740. } catch (\Throwable $ex) {
  741. Db::rollBack();
  742. var_dump($ex->getMessage());
  743. return Result::error("删除失败: " . $ex->getMessage(), 0);
  744. }
  745. // ------c_show_time********del*******
  746. if (!$article) {
  747. return Result::error("删除失败");
  748. }
  749. return Result::success($article);
  750. }
  751. /**
  752. * @param array $data
  753. * @return array
  754. */
  755. public function updateArticle(array $data): array
  756. {
  757. var_dump($data, '----------12-----------1');
  758. Db::beginTransaction();
  759. // ------c_show_time********up*******
  760. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  761. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  762. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  763. $web = WebsiteCategory::where('category_id', $data['catid'])
  764. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  765. ->select(
  766. 'website_id',
  767. 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')
  768. )
  769. ->get();
  770. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  771. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  772. $websiteIds = $web->pluck('website_id')->toArray();
  773. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  774. if ($user_type == 0) {
  775. throw new \Exception("用户类型不能为空");
  776. }
  777. if ($user_type == 10000) {
  778. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  779. $web = WebsiteCategory::where('category_id', $data['catid'])
  780. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  781. ->select(
  782. 'website_id',
  783. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  784. )
  785. ->get();
  786. // 非核心站与核心站----显示时间-----间隔
  787. $time = 20;
  788. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  789. $waiting_interval = 5;
  790. $webArray = $web->toArray();
  791. if (empty($webArray)) {
  792. throw new \Exception('网站分类不存在');
  793. }
  794. // 直接使用当前系统时间,不再强制添加8小时
  795. $now = date('Y-m-d H:i:s');
  796. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  797. // 检查 $item 对象是否有 is_core 属性
  798. if (!isset($item['is_core'])) {
  799. throw new \Exception('$item 对象缺少 is_core 属性');
  800. }
  801. // 当 is_core 为 2 时,则表示此网站不存在
  802. if ($item['is_core'] == 2) {
  803. return null;
  804. } else if ($item['is_core'] == 1) {
  805. // 当 is_core 为 1 时,则表示此网站是核心站
  806. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  807. } else {
  808. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  809. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  810. if ($item['is_core'] == 0) {
  811. $time += $waiting_interval;
  812. }
  813. }
  814. return [
  815. 'article_id' => $data['id'],
  816. 'website_id' => $item['website_id'],
  817. 'c_show_time' => $c_show_time,
  818. ];
  819. }, array_keys($webArray), $webArray)));
  820. if (!empty($article_ignore)) {
  821. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  822. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  823. $article_ignores = ArticleIgnore::upsert(
  824. $article_ignore,
  825. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  826. ['c_show_time'] // 需要更新的字段
  827. );
  828. if (!$article_ignores) {
  829. throw new \Exception('c端展示时间插入失败');
  830. }
  831. }
  832. // Db::commit();
  833. // return Result::success($article_ignore);
  834. }
  835. // ------c_show_time********up*******
  836. unset($data['user_type']);
  837. // unset($data['web_site_id']);
  838. unset($data['nav_add_pool_id']);
  839. try {
  840. //处理投票
  841. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  842. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  843. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  844. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  845. unset($data['is_survey']);
  846. unset($data['survey_name']);
  847. unset($data['suvey_array']);
  848. unset($data['website_id']);
  849. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  850. if ($data['hits'] == '') {
  851. $data['hits'] = 0;
  852. }
  853. if ($data['is_original'] == '') {
  854. $data['is_original'] = 0;
  855. }
  856. if ($data['status'] == '') {
  857. $data['status'] = 0;
  858. }
  859. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  860. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  861. $articleData = $data;
  862. unset($articleData['content']);
  863. unset($articleData['status_name']);
  864. unset($articleData['name']);
  865. unset($articleData['content']);
  866. unset($articleData['pid_arr']);
  867. unset($articleData['pid']);
  868. //自动处理缩略图、关键字、描述
  869. if ($articleData['imgurl'] == '') {
  870. //如果没有图,设置level=0
  871. $levelArr = json_decode($articleData['level'], true);
  872. var_dump($levelArr, '----------levelArr-----------1');
  873. //content中提取图片第一个图,正则提取
  874. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  875. preg_match_all($reg, $data['content'], $matches);
  876. if (isset($matches[1][0])) {
  877. //截取varchar240
  878. // 截取到第一个<
  879. $articleData['imgurl'] = $matches[1][0];
  880. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  881. $pos = strpos($articleData['imgurl'], '"');
  882. if ($pos !== false) {
  883. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  884. }
  885. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  886. //如果有图,设置level=3
  887. if (!in_array(3, $levelArr)) {
  888. $levelArr[] = 3;
  889. }
  890. $articleData['level'] = json_encode($levelArr);
  891. } else {
  892. if (!in_array(0, $levelArr)) {
  893. $levelArr[] = 0;
  894. }
  895. $articleData['level'] = json_encode($levelArr);
  896. }
  897. }
  898. var_dump($articleData['level'], '----------$articleData[level]----------1');
  899. if ($articleData['keyword'] == '') {
  900. //提取标题+内容中的关键词
  901. $articleData['keyword'] = $data['title'];
  902. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  903. Jieba::init(); // 初始化 jieba-php
  904. Finalseg::init();
  905. $segList = Jieba::cut($articleData['keyword']);
  906. $segList1 = array_slice($segList, 0, 8);
  907. $articleData['keyword'] = implode(',', $segList1);
  908. }
  909. if ($articleData['introduce'] == '') {
  910. //提取内容中的描述
  911. $content = $data['content'];
  912. // 去除 <style> 和 <script> 标签及其内容
  913. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  914. // 去除所有 HTML 标签
  915. $content = strip_tags($content);
  916. // 去除 HTML 实体
  917. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  918. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  919. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  920. // 去除多余空白
  921. $content = preg_replace('/\s+/u', '', $content);
  922. // 截取 100 个字符
  923. $articleData['introduce'] = mb_substr($content, 0, 100);
  924. }
  925. if ($articleData['status'] == 0) {
  926. $this->sendMessage([
  927. 'talk_type' => 100,
  928. 'title' => $articleData['title'],
  929. 'content' => '提交了审核',
  930. 'messageType' => 2,
  931. ]);
  932. }
  933. $id = Article::where(['id' => $data['id']])->update($articleData);
  934. // $articleDataContent = [
  935. // 'content' => $data['content'],
  936. // ];
  937. // 采集来的文章,content中可能包含div标签,需要先移除
  938. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  939. $article_data = preg_replace($pattern, '', $data['content']);
  940. $articleDataContent['content'] = $article_data;
  941. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  942. //处理投票
  943. $id = $data['id'];
  944. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  945. var_dump($suvey_array, 'suvey_array________delete');
  946. //处理投票
  947. if ($is_survey == 1) {
  948. //生成年月日时分秒+8位随机数
  949. $uuid = date('YmdHis') . rand(10000000, 99999999);
  950. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  951. var_dump($suveys_array, '---------------------1');
  952. $suvey_data = [];
  953. if (is_array($suveys_array)) {
  954. foreach ($suveys_array as $key => $value) {
  955. if ($value == '') {
  956. continue;
  957. }
  958. if (is_array($value)) {
  959. $suvey_data[] = [
  960. 'sur_id' => $uuid,
  961. 'art_id' => $id,
  962. 'website_id' => $website_id ?? 2,
  963. 'survey_name' => $survey_name,
  964. 'choice_name' => $value[1],
  965. 'is_other' => 1,
  966. 'other_id' => 0,
  967. 'results' => 0,
  968. ];
  969. } else {
  970. $suvey_data[] = [
  971. 'sur_id' => $uuid,
  972. 'art_id' => $id,
  973. 'website_id' => $website_id ?? 2,
  974. 'survey_name' => $survey_name,
  975. 'choice_name' => $value,
  976. 'is_other' => 0,
  977. 'other_id' => 0,
  978. 'results' => 0,
  979. ];
  980. }
  981. if (empty($suvey_data)) {
  982. throw new \Exception("投票数据为空");
  983. }
  984. }
  985. }
  986. $result = ArticleSurvey::insert($suvey_data);
  987. if (!$result) {
  988. throw new \Exception("投票失败");
  989. }
  990. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  991. if (!$result) {
  992. throw new \Exception("投票失败");
  993. }
  994. } else {
  995. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  996. }
  997. Db::commit();
  998. return Result::success([]);
  999. } catch (\Throwable $ex) {
  1000. Db::rollBack();
  1001. var_dump($ex->getMessage());
  1002. return Result::error("更新失败" . $ex->getMessage(), 0);
  1003. }
  1004. }
  1005. /**
  1006. * 更新资讯状态
  1007. * @param array $data
  1008. * @return array
  1009. */
  1010. public function upArticleStatus(array $data): array
  1011. {
  1012. $articleData = Article::where(['id' => $data['id']])->first();
  1013. //发送10次
  1014. // for ($i = 0; $i < 10; $i++) {
  1015. // $this->sendMessage([
  1016. // 'talk_type' => 100,
  1017. // 'title' => $i . $articleData['title'],
  1018. // 'content' => '审核通过',
  1019. // 'messageType' => 2,
  1020. // 'user_id' => $articleData['admin_user_id'],
  1021. // ]);
  1022. // }
  1023. // var_dump($data['status'], 'status');
  1024. // return Result::success();
  1025. if ($data['status'] == 1) {
  1026. $this->sendMessage([
  1027. 'talk_type' => 101,
  1028. 'title' => $articleData['title'],
  1029. 'content' => '审核通过',
  1030. 'messageType' => 2,
  1031. 'user_id' => $articleData['admin_user_id'],
  1032. ]);
  1033. }
  1034. if ($data['status'] == 2) {
  1035. $this->sendMessage([
  1036. 'talk_type' => 101,
  1037. 'title' => $articleData['title'],
  1038. 'content' => '审核拒绝',
  1039. 'messageType' => 2,
  1040. 'user_id' => $articleData['admin_user_id'],
  1041. ]);
  1042. }
  1043. if ($data['status'] == 0) {
  1044. $this->sendMessage([
  1045. 'talk_type' => 100,
  1046. 'title' => $articleData['title'],
  1047. 'content' => '提交了审核',
  1048. 'messageType' => 2,
  1049. ]);
  1050. }
  1051. $result = Article::where(['id' => $data['id']])->update($data);
  1052. // ------c_show_time********up_status*******
  1053. // 若是审核通过 则更新c_show_time
  1054. if ($data['status'] == 1) {
  1055. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1056. $web = Article::where('article.id', $data['id'])
  1057. ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  1058. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1059. ->select(
  1060. 'website_id',
  1061. 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')
  1062. )
  1063. ->get();
  1064. // 非核心站与核心站----显示时间-----间隔
  1065. $time = 20;
  1066. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1067. $waiting_interval = 5;
  1068. $webArray = $web->toArray();
  1069. if (empty($webArray)) {
  1070. throw new \Exception('网站分类不存在');
  1071. }
  1072. // 直接使用当前系统时间,不再强制添加8小时
  1073. $now = date('Y-m-d H:i:s');
  1074. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1075. if (isset($data['ignore_ids'])) {
  1076. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1077. if (in_array($item['website_id'], $ignore_website_ids)) {
  1078. $is_ignore = 1;
  1079. } else {
  1080. $is_ignore = 0;
  1081. }
  1082. return [
  1083. 'article_id' => $data['id'],
  1084. 'website_id' => $item['website_id'],
  1085. 'is_ignore' => $is_ignore,
  1086. ];
  1087. } else {
  1088. // 检查 $item 对象是否有 is_core 属性
  1089. if (!isset($item['is_core'])) {
  1090. throw new \Exception('$item 对象缺少 is_core 属性');
  1091. }
  1092. // 当 is_core 为 2 时,则表示此网站不存在
  1093. if ($item['is_core'] == 2) {
  1094. return null;
  1095. } else if ($item['is_core'] == 1) {
  1096. // 当 is_core 为 1 时,则表示此网站是核心站
  1097. $c_show_time = $now;
  1098. } else {
  1099. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1100. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  1101. if ($item['is_core'] == 0) {
  1102. $time += $waiting_interval;
  1103. }
  1104. }
  1105. return [
  1106. 'article_id' => $data['id'],
  1107. 'website_id' => $item['website_id'],
  1108. 'c_show_time' => $c_show_time,
  1109. ];
  1110. }
  1111. }, array_keys($webArray), $webArray)));
  1112. if (!empty($article_ignore) && !isset($data['ignore_ids'])) {
  1113. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1114. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1115. $websiteIds = $web->pluck('website_id')->toArray();
  1116. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1117. $article_ignores = ArticleIgnore::upsert(
  1118. $article_ignore,
  1119. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1120. ['c_show_time'] // 需要更新的字段
  1121. );
  1122. if (!$article_ignores) {
  1123. throw new \Exception('c端展示时间插入失败');
  1124. }
  1125. }
  1126. if (!empty($data['ignore_ids'])) {
  1127. // return Result::success($article_ignore);
  1128. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1129. if (!empty($article_ignore)) {
  1130. $article_ignores = ArticleIgnore::upsert(
  1131. $article_ignore,
  1132. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1133. ['is_ignore'] // 需要更新的字段
  1134. );
  1135. // if(!$article_ignores){
  1136. // throw new \Exception('屏蔽网站更新失败');
  1137. // }
  1138. }
  1139. }
  1140. }
  1141. // ------c_show_time********up_status*******
  1142. if ($result) {
  1143. return Result::success();
  1144. } else {
  1145. return Result::error("更新状态失败", 0);
  1146. }
  1147. }
  1148. /**
  1149. * 获取新闻详情
  1150. * @param array $data
  1151. * @return array
  1152. */
  1153. public function getArticleInfo(array $data): array
  1154. {
  1155. $where = [
  1156. 'article.id' => $data['id'],
  1157. // 'article.status' => 1,
  1158. ];
  1159. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1160. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1161. $info = $result;
  1162. // var_dump($info, 'info');
  1163. $info['survey_array'] = $articleSurvey;
  1164. if ($result) {
  1165. return Result::success($info);
  1166. } else {
  1167. return Result::error("查询失败", 0);
  1168. }
  1169. }
  1170. /**
  1171. * 获取头条新闻
  1172. * @param array $data
  1173. * @return array
  1174. */
  1175. public function getWebsiteArticlett(array $data): array
  1176. {
  1177. $website_id = $data['website_id'];
  1178. $website = Website::where('id', $data['website_id'])->first();
  1179. if (empty($website)) {
  1180. return Result::error("网站不存在", 0);
  1181. }
  1182. $categorys = $this->processArticlePro($website_id);
  1183. $catiall = $categorys['catiall'];
  1184. $categoryIds = $categorys['categoryIds'];
  1185. $where = [
  1186. 'status' => 1
  1187. ];
  1188. // $website_column = $website['column'];
  1189. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1190. $website_column = json_decode($website['website_column_arr_id'], true);
  1191. }
  1192. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1193. // return Result::success($diff_pid_categoryIds);
  1194. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1195. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1196. }
  1197. // $website_id = $data['website_id'];
  1198. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1199. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1200. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1201. switch ($data['level']) {
  1202. case 1:
  1203. case 2:
  1204. case 3:
  1205. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1206. $query = Article::where($where)
  1207. ->where('level', 'like', '%' . $data['level'] . '%')
  1208. ->orderBy('updated_at', 'desc');
  1209. break;
  1210. case 4: //最新资讯
  1211. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1212. break;
  1213. case 5: //资讯推荐
  1214. $query = Article::where($where)
  1215. ->where('updated_at', '>', $month);
  1216. break;
  1217. case 7: //资讯分类
  1218. if (isset($data['id']) && !empty($data['id'])) {
  1219. $keyword = Article::where('id', $data['id'])->value('keyword');
  1220. $keywordArray = explode(',', $keyword);
  1221. $whereL7 = [];
  1222. foreach ($keywordArray as $k => $v) {
  1223. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1224. }
  1225. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1226. break;
  1227. } else {
  1228. return Result::error("请输入资讯ID", 0);
  1229. break;
  1230. }
  1231. default:
  1232. break;
  1233. }
  1234. // $whereL7 = [];
  1235. // if(isset($data['id']) && !empty($data['id'])){
  1236. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1237. // $keywordArray = explode(',', $keyword);
  1238. // foreach ($keywordArray as $k => $v) {
  1239. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1240. // }
  1241. // }
  1242. // $query = Article::where($where)
  1243. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1244. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1245. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1246. // }
  1247. // if($data['level'] == 7){
  1248. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1249. // }
  1250. // if($data['level'] == 4){
  1251. // $query = $query->inRandomOrder()
  1252. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1253. // }
  1254. // if($data['level'] == 5){
  1255. // $query = $query->orderBy('updated_at','desc');
  1256. // }
  1257. // });
  1258. if ($data['textnum'] > 0) {
  1259. $query = clone $query;
  1260. $result['text'] = $query
  1261. ->whereIn('catid', $categoryIds)
  1262. ->leftJoinSub(function ($query) use ($website_id) {
  1263. $query->from('article_ignore')
  1264. ->where('website_id', $website_id);
  1265. }, 'article_ignore', function ($join) {
  1266. $join->on('article_ignore.article_id', '=', 'article.id');
  1267. })
  1268. ->where(function ($query) {
  1269. $query->whereNull('article_ignore.article_id')
  1270. ->orWhere(function ($subQuery) {
  1271. $subQuery->whereNotNull('article_ignore.article_id')
  1272. ->where('article_ignore.is_ignore', 0)
  1273. ->where(function ($subSubQuery) {
  1274. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1275. ->orWhereNull('article_ignore.c_show_time');
  1276. });
  1277. });
  1278. })
  1279. // ->where(function ($query) use ($website_id) {
  1280. // $query->whereNull('article_ignore.article_id')
  1281. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1282. // })
  1283. ->select(
  1284. 'article.id',
  1285. 'article.title',
  1286. 'article.author',
  1287. 'article.updated_at',
  1288. 'article.introduce',
  1289. 'article.islink',
  1290. 'article.linkurl',
  1291. 'article.copyfrom',
  1292. 'article.cat_arr_id',
  1293. 'article.catid',
  1294. 'article.level',
  1295. // 'article_ignore.is_ignore',
  1296. // 'article_ignore.c_show_time',
  1297. )
  1298. ->offset($data['placeid'])
  1299. ->limit($data['textnum'])
  1300. ->get()->all();
  1301. foreach ($result['text'] as $k => $v) {
  1302. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1303. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1304. }
  1305. }
  1306. if ($data['imgnum'] > 0) {
  1307. $query = clone $query;
  1308. if ($data['textnum'] == 0) {
  1309. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1310. $query->from('article_ignore')
  1311. ->where('website_id', $website_id);
  1312. }, 'article_ignore', function ($join) {
  1313. $join->on('article_ignore.article_id', '=', 'article.id');
  1314. })
  1315. ->where(function ($query) {
  1316. $query->whereNull('article_ignore.article_id')
  1317. ->orWhere(function ($subQuery) {
  1318. $subQuery->whereNotNull('article_ignore.article_id')
  1319. ->where('article_ignore.is_ignore', 0)
  1320. ->where(function ($subSubQuery) {
  1321. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1322. ->orWhereNull('article_ignore.c_show_time');
  1323. });
  1324. });
  1325. });
  1326. }
  1327. $result['img'] = $query
  1328. ->whereIn('catid', $categoryIds)
  1329. ->where('article.imgurl', '!=', '')
  1330. ->select(
  1331. 'article.id',
  1332. 'article.title',
  1333. 'article.imgurl',
  1334. 'article.author',
  1335. 'article.updated_at',
  1336. 'article.introduce',
  1337. 'article.islink',
  1338. 'article.linkurl',
  1339. 'article.copyfrom',
  1340. 'article.cat_arr_id',
  1341. 'article.catid',
  1342. 'article.level',
  1343. // 'article_ignore.is_ignore',
  1344. // 'article_ignore.c_show_time',
  1345. )
  1346. ->offset($data['placeid'])
  1347. ->limit($data['imgnum'])
  1348. ->get()->all();
  1349. foreach ($result['img'] as $k => $v) {
  1350. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1351. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1352. }
  1353. }
  1354. if (empty($result)) {
  1355. return Result::error("暂无相关资讯", 0);
  1356. }
  1357. return Result::success($result);
  1358. }
  1359. /**
  1360. * 获取模块新闻
  1361. * @param array $data
  1362. * @return array
  1363. */
  1364. public function getWebsiteModelArticles(array $data): array
  1365. {
  1366. $catid = $data['catid'];
  1367. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1368. $category = $category->toArray();
  1369. if (!empty($category)) {
  1370. $where = [
  1371. 'status' => 1,
  1372. 'catid' => $catid,
  1373. ];
  1374. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1375. // 1:文字新闻;2:轮播图;3:图文;
  1376. // 级别:0:未分类
  1377. // 3:推荐图片
  1378. if ($data['level'] == 1) {
  1379. $data['level'] = 0;
  1380. }
  1381. $result = Article::where($where)
  1382. ->where(function ($query) use ($data) {
  1383. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1384. ->orWhereNull("level")
  1385. ->orWhereRaw("level = '[]'");
  1386. })
  1387. ->leftJoinSub(function ($query) use ($data) {
  1388. $query->from('article_ignore')
  1389. ->where('website_id', $data['website_id']);
  1390. }, 'article_ignore', function ($join) {
  1391. $join->on('article_ignore.article_id', '=', 'article.id');
  1392. })
  1393. ->where(function ($query) {
  1394. $query->whereNull('article_ignore.article_id')
  1395. ->orWhere(function ($subQuery) {
  1396. $subQuery->whereNotNull('article_ignore.article_id')
  1397. ->where('article_ignore.is_ignore', 0)
  1398. ->where(function ($subSubQuery) {
  1399. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1400. ->orWhereNull('article_ignore.c_show_time');
  1401. });
  1402. });
  1403. })
  1404. // ->where(function ($query) use ($data) {
  1405. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1406. // ->orWhereNull("ignore_ids");
  1407. // })
  1408. ->orderBy("updated_at", "desc")
  1409. ->offset($placeid)
  1410. ->limit($data['pagesize'])
  1411. ->get();
  1412. if (empty($result)) {
  1413. return Result::error("此栏目暂无相关新闻", 0);
  1414. }
  1415. } else {
  1416. return Result::error("此网站暂无此栏目", 0);
  1417. }
  1418. return Result::success($result);
  1419. }
  1420. /**
  1421. *获取新闻列表
  1422. * @param array $data
  1423. * @return array
  1424. */
  1425. public function getWebsiteArticleList(array $data): array
  1426. {
  1427. // return Result::success($data);
  1428. $where[] = ['status', '=', 1];
  1429. $website_id = $data['website_id'];
  1430. $website = Website::where('id', $data['website_id'])->first();
  1431. if (empty($website)) {
  1432. return Result::error("网站不存在", 0);
  1433. }
  1434. // $website_column = $website['column'];
  1435. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1436. $website_column = json_decode($website['website_column_arr_id'], true);
  1437. }
  1438. $categorys = $this->processArticlePro($website_id);
  1439. $cat_1st_arr = $categorys['cat_1st_arr'];
  1440. $catiall = $categorys['catiall'];
  1441. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1442. // return Result::success($diff_pid_categoryIds);
  1443. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1444. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1445. }
  1446. if (isset($data['catid']) && !empty($data['catid'])) {
  1447. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1448. if (empty($category)) {
  1449. return Result::error("此网站暂无此栏目", 0);
  1450. }
  1451. array_push($where, ['catid', '=', $data['catid']]);
  1452. }
  1453. // return Result::success($where);
  1454. $query = Article::where($where)
  1455. ->leftJoinSub(function ($query) use ($website_id) {
  1456. $query->from('article_ignore')
  1457. ->where('website_id', $website_id);
  1458. }, 'article_ignore', function ($join) {
  1459. $join->on('article_ignore.article_id', '=', 'article.id');
  1460. })
  1461. ->where(function ($query) {
  1462. $query->whereNull('article_ignore.article_id')
  1463. ->orWhere(function ($subQuery) {
  1464. $subQuery->whereNotNull('article_ignore.article_id')
  1465. ->where('article_ignore.is_ignore', 0)
  1466. ->where(function ($subSubQuery) {
  1467. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1468. ->orWhereNull('article_ignore.c_show_time');
  1469. });
  1470. });
  1471. })
  1472. ->select(
  1473. 'article.id',
  1474. 'article.title',
  1475. 'article.imgurl',
  1476. 'article.author',
  1477. 'article.updated_at',
  1478. 'article.introduce',
  1479. 'article.islink',
  1480. 'article.linkurl',
  1481. 'article.copyfrom',
  1482. 'article.cat_arr_id',
  1483. 'article.catid'
  1484. );
  1485. $count = $query->count();
  1486. $rep = $query->orderBy("updated_at", "desc")
  1487. ->offset(($data['page'] - 1) * $data['pageSize'])
  1488. ->limit($data['pageSize'])
  1489. ->get()->all();
  1490. $categorys = $this->processArticlePro($website_id);
  1491. $cat_1st_arr = $categorys['cat_1st_arr'];
  1492. $catiall = $categorys['catiall'];
  1493. // $web['website_id'] = $data['website_id'];
  1494. foreach ($rep as $k => $v) {
  1495. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1496. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1497. }
  1498. // $rep = $this->processArticles($rep,$web);
  1499. $data = [
  1500. 'rows' => $rep,
  1501. 'count' => $count,
  1502. ];
  1503. if (empty($rep)) {
  1504. return Result::error("没有信息数据");
  1505. }
  1506. return Result::success($data);
  1507. }
  1508. /**
  1509. * 前端-获取新闻详情
  1510. * @param array $data
  1511. * @return array
  1512. */
  1513. public function selectWebsiteArticleInfo(array $data): array
  1514. {
  1515. $where = [
  1516. 'article.id' => $data['id'],
  1517. 'article.status' => 1,
  1518. ];
  1519. $result = Article::where($where)
  1520. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1521. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1522. // ->where(function ($query) use ($data) {
  1523. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1524. // ->orWhereNull("ignore_ids");
  1525. // })
  1526. ->leftJoinSub(function ($query) use ($data) {
  1527. $query->from('article_ignore')
  1528. ->where('website_id', $data['website_id']);
  1529. }, 'article_ignore', function ($join) {
  1530. $join->on('article_ignore.article_id', '=', 'article.id');
  1531. })
  1532. ->where(function ($query) {
  1533. $query->whereNull('article_ignore.article_id')
  1534. ->orWhere(function ($subQuery) {
  1535. $subQuery->whereNotNull('article_ignore.article_id')
  1536. ->where('article_ignore.is_ignore', 0)
  1537. ->where(function ($subSubQuery) {
  1538. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1539. ->orWhereNull('article_ignore.c_show_time');
  1540. });
  1541. });
  1542. })
  1543. ->select(
  1544. 'article.*',
  1545. 'article_data.content',
  1546. 'article_data.article_id',
  1547. 'article_extend.website_url',
  1548. 'article_extend.email',
  1549. 'article_extend.contacts',
  1550. 'article_extend.contacts_mobile',
  1551. 'article_extend.contacts_address',
  1552. 'article_extend.zip_code',
  1553. 'article_extend.enterprise_name'
  1554. )
  1555. ->first();
  1556. if (empty($result)) {
  1557. return Result::error("暂无此新闻!", 0);
  1558. }
  1559. if (!empty($result['publiced_at'])) {
  1560. $result['updated_at'] = $result['publiced_at'];
  1561. }
  1562. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1563. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1564. ->where('website_category.website_id', $data['website_id'])
  1565. ->where(['website_category.category_id' => $result['catid']])
  1566. ->first();
  1567. if (empty($category)) {
  1568. return Result::error("查询失败", 0);
  1569. }
  1570. //手动推荐文章
  1571. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1572. if (empty($commend_ids)) {
  1573. $commendArticle = [];
  1574. } else {
  1575. //去除不存在的文章ID
  1576. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1577. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1578. ->leftJoinSub(function ($query) use ($data) {
  1579. $query->from('article_ignore')
  1580. ->where('website_id', $data['website_id']);
  1581. }, 'article_ignore', function ($join) {
  1582. $join->on('article_ignore.article_id', '=', 'article.id');
  1583. })
  1584. ->where(function ($query) {
  1585. $query->whereNull('article_ignore.article_id')
  1586. ->orWhere(function ($subQuery) {
  1587. $subQuery->whereNotNull('article_ignore.article_id')
  1588. ->where('article_ignore.is_ignore', 0)
  1589. ->where(function ($subSubQuery) {
  1590. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1591. ->orWhereNull('article_ignore.c_show_time');
  1592. });
  1593. });
  1594. })
  1595. ->where('article.status', 1)
  1596. ->where('website_category.website_id', $data['website_id'])
  1597. ->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')
  1598. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1599. // ->orderBy('article.updated_at', 'desc')
  1600. ->limit(5)
  1601. ->get();
  1602. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1603. foreach ($commendArticle as $k => $v) {
  1604. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1605. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1606. $cat_arr_id = array_unique($cat_arr_id);
  1607. // 从website_category取出alias_pinyin
  1608. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1609. ->whereIn('category_id', $cat_arr_id)
  1610. ->pluck('alias_pinyin', 'category_id')
  1611. ->toArray();
  1612. // 将cat_arr_id的json转成路径/隔开
  1613. $path_parts = [];
  1614. foreach ($cat_arr_id as $cat_id) {
  1615. if (isset($cat_arr[$cat_id])) {
  1616. $path_parts[] = $cat_arr[$cat_id];
  1617. }
  1618. }
  1619. $v->alias_pinyin = implode('/', $path_parts);
  1620. } else {
  1621. $v->alias_pinyin = '';
  1622. }
  1623. }
  1624. }
  1625. $result['category_id'] = $category['category_id'];
  1626. $result['cat_name'] = $category['alias'];
  1627. $result['website_name'] = $category['website_name'] ?? "";
  1628. $result['suffix'] = $category['suffix'] ?? "";
  1629. $result['commendArticle'] = $commendArticle;
  1630. $result['commend_ids'] = $commend_ids;
  1631. return Result::success($result);
  1632. }
  1633. /**
  1634. * 前端-获取网站调查问卷
  1635. * @param array $data
  1636. * @return array
  1637. */
  1638. public function getWebsiteSurvey(array $data): array
  1639. {
  1640. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1641. $website = Website::where('id', $data['website_id'])->first();
  1642. if (empty($website)) {
  1643. return Result::error("暂无此网站", 0);
  1644. }
  1645. }
  1646. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1647. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1648. if (empty($article)) {
  1649. return Result::error("暂无此文章", 0);
  1650. }
  1651. // return Result::error($data,0);
  1652. $where['art_id'] = $data['art_id'];
  1653. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1654. } else {
  1655. $survey = Article::where(function ($query) {
  1656. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1657. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1658. })
  1659. ->where('status', 1)
  1660. ->where('is_survey', 1)
  1661. ->select('survey_id')
  1662. ->orderBy('updated_at', 'desc')
  1663. ->first();
  1664. if (empty($survey)) {
  1665. return Result::error("暂无调查问卷", 0);
  1666. }
  1667. $where['sur_id'] = $survey['survey_id'];
  1668. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1669. }
  1670. // return Result::success($where);
  1671. $result = ArticleSurvey::where($where)
  1672. ->where(function ($query) {
  1673. $query->where('is_other', 0)
  1674. ->orWhere(function ($subQuery) {
  1675. $subQuery->where('is_other', 1)
  1676. ->where('other_id', 0);
  1677. });
  1678. })
  1679. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1680. ->select('article_survey.*', 'article.survey_type')
  1681. ->get()->all();
  1682. if (empty($result)) {
  1683. return Result::error("此文章暂无调查问卷", 0);
  1684. }
  1685. return Result::success($result);
  1686. }
  1687. /**
  1688. * 前端-添加网站调查问卷选项
  1689. * @param array $data
  1690. * @return array
  1691. */
  1692. public function addWebsiteSurveyOption(array $data): array
  1693. {
  1694. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1695. $website = Website::where('id', $data['website_id'])->first();
  1696. if (empty($website)) {
  1697. return Result::error("暂无此网站", 0);
  1698. }
  1699. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1700. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1701. if (empty($survey)) {
  1702. return Result::error("此调查问卷不可添加选项", 0);
  1703. }
  1704. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1705. $choice = [
  1706. 'art_id' => $survey['art_id'],
  1707. 'website_id' => $data['website_id'],
  1708. 'survey_name' => $survey['survey_name'],
  1709. 'choice_name' => $data['choice_name'],
  1710. 'sur_id' => $survey['sur_id'],
  1711. 'is_other' => 1,
  1712. 'other_id' => $survey['id'],
  1713. ];
  1714. $result = ArticleSurvey::insertGetId($choice);
  1715. if (empty($result)) {
  1716. return Result::error("添加失败", 0);
  1717. }
  1718. return Result::success($result);
  1719. }
  1720. }
  1721. return Result::error("添加失败", 0);
  1722. }
  1723. return Result::error("添加失败", 0);
  1724. }
  1725. /**
  1726. * 前端-调查问卷投票
  1727. * @param array $data
  1728. * @return array
  1729. */
  1730. public function addWebsiteSurveyVote(array $data): array
  1731. {
  1732. // return Result::success($data);
  1733. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1734. $website = Website::where('id', $data['website_id'])->first();
  1735. if (empty($website)) {
  1736. return Result::error("暂无此网站", 0);
  1737. }
  1738. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1739. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1740. // return Result::success($survey);
  1741. if (empty($is_survey)) {
  1742. return Result::error("此调查问卷不存在", 0);
  1743. }
  1744. // return Result::success($survey);
  1745. // 调查问卷类型
  1746. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1747. //多选 若是json型则转化成数组类型
  1748. if (strpos($data['choice_id'], '[') === 0) {
  1749. $data['choice_id'] = json_decode($data['choice_id'], true);
  1750. } else {
  1751. // 单选 也转换成数组
  1752. $data['choice_id'] = [$data['choice_id']];
  1753. }
  1754. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1755. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1756. // ->where('website_id',$data['website_id'])
  1757. ->where('is_other', 1)
  1758. ->where('other_id', 0)
  1759. ->first();
  1760. if (!empty($other)) {
  1761. return Result::error("请选择已有的选项!", 0);
  1762. }
  1763. $choice['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. // return Result::success($choice['other']);
  1769. $choice_id = $data['choice_id'];
  1770. if (!empty($choice['other'])) {
  1771. // array_push($data['choice_id'],$choice['other']['other_id']);
  1772. if (!empty($choice_id)) {
  1773. $key = array_search($choice['other']['id'], $choice_id);
  1774. if ($key !== false) {
  1775. unset($choice_id[$key]);
  1776. $choice_id = array_values($choice_id);
  1777. }
  1778. array_push($choice_id, $choice['other']['other_id']);
  1779. } else {
  1780. $choice_id[0] = $choice['other']['other_id'];
  1781. }
  1782. array_push($data['choice_id'], $choice['other']['other_id']);
  1783. }
  1784. // return Result::success($data);
  1785. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1786. // ->where('website_id',$data['website_id'])
  1787. ->increment('results', 1);
  1788. if (empty($choice)) {
  1789. return Result::error("请选择已有的选项!", 0);
  1790. }
  1791. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1792. // ->where('website_id',$data['website_id'])
  1793. ->where('other_id', 0)
  1794. ->get();
  1795. $survey['choice'] = $choice_id;
  1796. return Result::success($survey);
  1797. }
  1798. return Result::error("参数必填!");
  1799. }
  1800. return Result::error("此调查问卷不存在", 0);
  1801. }
  1802. return Result::error("参数必填!");
  1803. }
  1804. /**
  1805. * 后端-获取网站调查问卷列表
  1806. * @param array $data
  1807. * @return array
  1808. */
  1809. public function getSurveyList(array $data): array
  1810. {
  1811. $where = [];
  1812. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1813. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1814. }
  1815. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1816. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1817. }
  1818. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1819. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1820. }
  1821. // return Result::success($where);
  1822. if (!empty($where)) {
  1823. $query = Article::where($where)->where(function ($q) {
  1824. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1825. });
  1826. } else {
  1827. $query = Article::where(function ($q) {
  1828. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1829. });
  1830. }
  1831. $count = $query->count();
  1832. $survey = $query->orderByDesc('id')
  1833. ->limit($data['pageSize'])
  1834. ->offset(($data['page'] - 1) * $data['pageSize'])
  1835. ->get();
  1836. if (empty($survey->toArray())) {
  1837. return Result::error("暂无调查问卷!", 0);
  1838. }
  1839. $result = [
  1840. 'rows' => $survey,
  1841. 'count' => $count,
  1842. ];
  1843. return Result::success($result);
  1844. }
  1845. /**
  1846. * 后端-获取网站调查问卷详情
  1847. * @param array $data
  1848. * @return array
  1849. */
  1850. public function getSurveyInfo(array $data): array
  1851. {
  1852. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1853. $where = ['sur_id' => $data['sur_id']];
  1854. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1855. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1856. ->select('article_survey.*', 'article.survey_type')
  1857. ->get()->all();
  1858. if (empty($choose)) {
  1859. return Result::error("此调查问卷不存在", 0);
  1860. }
  1861. $resultsArray = array_column($choose, 'results');
  1862. $total = array_sum($resultsArray);
  1863. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1864. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1865. // $total = 0;
  1866. if (!empty($other)) {
  1867. $total = $total + $other['results'];
  1868. $other['choice_name'] = '(其他)';
  1869. if (!empty($others)) {
  1870. $other['hasChildren'] = true;
  1871. // array_push($other,['hasChildren','=',true]);
  1872. $other['children'] = $others;
  1873. $other_choices = [$other->toArray()];
  1874. $mer_choice = array_merge($choose, $other_choices);
  1875. $value_choice = array_values($mer_choice);
  1876. } else {
  1877. // return Result::error('1111');
  1878. $other_choices = [$other->toArray()];
  1879. $other_choices = array_merge($choose, $other_choices);
  1880. $value_choice = array_values($other_choices);
  1881. // return Result::success($result);
  1882. }
  1883. } else {
  1884. $value_choice = $choose;
  1885. }
  1886. $result = [
  1887. 'choose' => $value_choice,
  1888. 'total' => $total,
  1889. ];
  1890. }
  1891. return Result::success($result);
  1892. }
  1893. /**
  1894. * 前端-搜索新闻列表
  1895. * @param array $data
  1896. * @return array
  1897. */
  1898. public function selectWebsiteArticle(array $data): array
  1899. {
  1900. $website = Website::where('id', $data['website_id'])->first();
  1901. if (empty($website)) {
  1902. return Result::error("网站不存在", 0);
  1903. }
  1904. // $website_column = $website['column'];
  1905. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1906. $website_column = json_decode($website['website_column_arr_id'], true);
  1907. }
  1908. $website_id = $data['website_id'];
  1909. $categorys = $this->processArticlePro($website_id);
  1910. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1911. // return Result::success($diff_pid_categoryIds);
  1912. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1913. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1914. }
  1915. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1916. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1917. $catiall = $categorys['catiall'];
  1918. $categoryIds = $categorys['categoryIds'];
  1919. // return Result::success($categoryIds);
  1920. $query = Article::where('status', 1)
  1921. ->whereIn('catid', $categoryIds)
  1922. ->leftJoinSub(function ($query) use ($website_id) {
  1923. $query->from('article_ignore')
  1924. ->where('website_id', $website_id);
  1925. }, 'article_ignore', function ($join) {
  1926. $join->on('article_ignore.article_id', '=', 'article.id');
  1927. })
  1928. ->where(function ($query) {
  1929. $query->whereNull('article_ignore.article_id')
  1930. ->orWhere(function ($subQuery) {
  1931. $subQuery->whereNotNull('article_ignore.article_id')
  1932. ->where('article_ignore.is_ignore', 0)
  1933. ->where(function ($subSubQuery) {
  1934. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1935. ->orWhereNull('article_ignore.c_show_time');
  1936. });
  1937. });
  1938. });
  1939. // ->get()->all();
  1940. // return Result::success($query);
  1941. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1942. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1943. }
  1944. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1945. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1946. }
  1947. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1948. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1949. }
  1950. // 计算总数
  1951. $count = $query->count();
  1952. // return Result::success($count);
  1953. // 分页查询
  1954. $articles = $query
  1955. ->select(
  1956. 'article.id',
  1957. 'article.title',
  1958. 'article.imgurl',
  1959. 'article.author',
  1960. 'article.updated_at',
  1961. 'article.introduce',
  1962. 'article.islink',
  1963. 'article.linkurl',
  1964. 'article.copyfrom',
  1965. 'article.cat_arr_id',
  1966. 'article.catid',
  1967. 'article.department_arr_id',
  1968. 'article.city_arr_id',
  1969. // 'article_ignore.c_show_time',
  1970. // 'article_ignore.is_ignore'
  1971. )
  1972. ->orderBy("updated_at", "desc")
  1973. ->offset(($data['page'] - 1) * $data['pageSize'])
  1974. ->limit($data['pageSize'])
  1975. ->get();
  1976. // return Result::success($articles);
  1977. foreach ($articles as $k => $v) {
  1978. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1979. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1980. }
  1981. if (empty($articles)) {
  1982. return Result::error("没有符合条件的资讯数据");
  1983. }
  1984. $result = [
  1985. 'rows' => $articles,
  1986. 'count' => $count,
  1987. ];
  1988. return Result::success($result);
  1989. }
  1990. /**
  1991. * 模块新闻加强版
  1992. * @param array $data
  1993. * @return array
  1994. */
  1995. public function getWebsiteCatidArticle(array $data): array
  1996. {
  1997. $where = [
  1998. 'website_category.category_id' => $data['catid'],
  1999. 'website_category.website_id' => $data['website_id'],
  2000. ];
  2001. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  2002. $child_catnum = $data['child_catnum'] ?? 1;
  2003. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  2004. $childCategoryIds = array_column($category['child'], 'category_id');
  2005. if (empty($childCategoryIds)) {
  2006. return Result::error("暂无子栏目", 0);
  2007. }
  2008. $imgArticles = [];
  2009. $textArticles = [];
  2010. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2011. // 初始化子分类图片新闻和文字新闻数组
  2012. // 查询所有子级栏目的图文新闻
  2013. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2014. ->where(function ($query) use ($data) {
  2015. $query->where(function ($subQuery) use ($data) {
  2016. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2017. })->orWhereNull("ignore_ids");
  2018. })
  2019. ->where('status', 1)
  2020. ->where('imgurl', '!=', '')
  2021. ->select('*')
  2022. ->orderBy('updated_at', 'desc')
  2023. ->limit($data['child_imgnum'])
  2024. ->get();
  2025. }
  2026. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2027. // 查询所有子级栏目的文字新闻
  2028. $textArticles = Article::where('catid', $childCategoryIds[0])
  2029. ->where('status', 1)
  2030. ->where(function ($query) use ($data) {
  2031. $query->where(function ($subQuery) use ($data) {
  2032. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2033. })->orWhereNull("ignore_ids");
  2034. })
  2035. ->select('*')
  2036. ->orderBy('updated_at', 'desc')
  2037. ->limit($data['child_textnum'])
  2038. ->get();
  2039. }
  2040. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2041. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2042. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2043. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2044. return $child;
  2045. }, $category['child']);
  2046. }
  2047. // }
  2048. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2049. $category['img'] = WebsiteCategory::where($where)
  2050. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2051. ->where('article.status', 1)
  2052. ->where('article.imgurl', '!=', '')
  2053. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2054. ->orderBy('article.updated_at', 'desc')
  2055. ->limit($data['img_num'])
  2056. ->get();
  2057. }
  2058. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2059. $category['text'] = WebsiteCategory::where($where)
  2060. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2061. ->where('article.status', 1)
  2062. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2063. ->orderBy('article.updated_at', 'desc')
  2064. ->limit($data['text_num'])
  2065. ->get();
  2066. }
  2067. // $category = $category->get();
  2068. if (empty($category)) {
  2069. return Result::error("查询失败", 0);
  2070. }
  2071. return Result::success($category);
  2072. }
  2073. /**
  2074. * 模块新闻加强plus版
  2075. * @param array $data
  2076. * @return array
  2077. */
  2078. public function getWebsiteAllArticle(array $data): array
  2079. {
  2080. // return Result::success($data);
  2081. $time1 = microtime(true);
  2082. $wetbsite_id = $data['website_id'] ?? 2;
  2083. $data = json_decode($data['id'], true);
  2084. $website = Website::where('id', $wetbsite_id)->first();
  2085. if (empty($website)) {
  2086. return Result::error("网站不存在", 0);
  2087. }
  2088. // return Result::success($website);
  2089. $website_column = $website['website_column_arr_id'] ?? '[]';
  2090. $website_column = json_decode($website_column, true);
  2091. $categorys = $this->processArticlePro($wetbsite_id);
  2092. $cat_1st_arr = $categorys['cat_1st_arr'];
  2093. $catiall = $categorys['catiall'];
  2094. // return Result::success($catiall);
  2095. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2096. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2097. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2098. }
  2099. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2100. // return Result::success($categorys);
  2101. $parent_category = array_column($data, 'parent');
  2102. $parent_cat = [];
  2103. $child_category = array_column($data, 'child');
  2104. if (!empty($parent_category)) {
  2105. foreach ($parent_category as $key => $value) {
  2106. $arr = array_map('intval', explode(',', $value));
  2107. $parent_cat[$key] = $arr[0] ?? 0;
  2108. $parent_category = $arr[0] ?? 0;
  2109. $article_imgnum = $arr[1] ?? 0;
  2110. $article_textnum = $arr[2] ?? 0;
  2111. if ($parent_category != 0) {
  2112. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2113. // return Result::success($category_arr);
  2114. if ($article_imgnum != 0) {
  2115. $img_article = Article::whereIn('catid', $category_arr)
  2116. ->where('status', 1)
  2117. ->where('imgurl', '!=', '')
  2118. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2119. $query->from('article_ignore')
  2120. ->where('website_id', $wetbsite_id);
  2121. }, 'article_ignore', function ($join) {
  2122. $join->on('article_ignore.article_id', '=', 'article.id');
  2123. })
  2124. ->where(function ($query) {
  2125. $query->whereNull('article_ignore.article_id')
  2126. ->orWhere(function ($subQuery) {
  2127. $subQuery->whereNotNull('article_ignore.article_id')
  2128. ->where('article_ignore.is_ignore', 0)
  2129. ->where(function ($subSubQuery) {
  2130. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2131. ->orWhereNull('article_ignore.c_show_time');
  2132. });
  2133. });
  2134. })
  2135. ->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')
  2136. ->orderBy('updated_at', 'desc')
  2137. ->limit($article_imgnum)
  2138. ->get()->all();
  2139. foreach ($img_article as $k => $v) {
  2140. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2141. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2142. }
  2143. } else {
  2144. $img_article = [];
  2145. }
  2146. if ($article_textnum != 0) {
  2147. $text_article = Article::whereIn('catid', $category_arr)
  2148. ->where('status', 1)
  2149. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2150. $query->from('article_ignore')
  2151. ->where('website_id', $wetbsite_id);
  2152. }, 'article_ignore', function ($join) {
  2153. $join->on('article_ignore.article_id', '=', 'article.id');
  2154. })
  2155. ->where(function ($query) {
  2156. $query->whereNull('article_ignore.article_id')
  2157. ->orWhere(function ($subQuery) {
  2158. $subQuery->whereNotNull('article_ignore.article_id')
  2159. ->where('article_ignore.is_ignore', 0)
  2160. ->where(function ($subSubQuery) {
  2161. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2162. ->orWhereNull('article_ignore.c_show_time');
  2163. });
  2164. });
  2165. })
  2166. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2167. ->orderBy('updated_at', 'desc')
  2168. ->limit($article_textnum)
  2169. ->get()->all();
  2170. foreach ($text_article as $k => $v) {
  2171. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2172. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2173. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2174. }
  2175. } else {
  2176. $text_article = [];
  2177. }
  2178. $catiall[$parent_category]['imgnum'] = $img_article;
  2179. $catiall[$parent_category]['textnum'] = $text_article;
  2180. $parent[$key] = $catiall[$parent_category];
  2181. } else {
  2182. $parent[$key] = '';
  2183. }
  2184. }
  2185. }
  2186. if (!empty($child_category)) {
  2187. foreach ($child_category as $key => $value) {
  2188. $arr = array_map('intval', explode(',', $value));
  2189. $parent_category = $parent_cat[$key];
  2190. $child_category = $arr[0] ?? 0;
  2191. $article_imgnum = $arr[1] ?? 0;
  2192. $article_textnum = $arr[2] ?? 0;
  2193. if ($child_category != 0) {
  2194. $all_childcat = $cat_1st_arr[$parent_category];
  2195. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2196. // 从 $websiteInfoIndexed 中获取对应的数据
  2197. $info = $websiteInfoIndexed[$v];
  2198. // 返回一个包含所需信息的数组
  2199. return [
  2200. 'alias' => $info->alias,
  2201. 'category_id' => $info->category_id,
  2202. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2203. 'pid' => $info->pid,
  2204. 'type' => $info->type,
  2205. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2206. 'pinyin' => $info->pinyin,
  2207. ];
  2208. }, $all_childcat);
  2209. if ($article_imgnum != 0) {
  2210. $img_article = Article::where('catid', $child_category)
  2211. ->where('status', 1)
  2212. ->where('imgurl', '!=', '')
  2213. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2214. $query->from('article_ignore')
  2215. ->where('website_id', $wetbsite_id);
  2216. }, 'article_ignore', function ($join) {
  2217. $join->on('article_ignore.article_id', '=', 'article.id');
  2218. })
  2219. ->where(function ($query) {
  2220. $query->whereNull('article_ignore.article_id')
  2221. ->orWhere(function ($subQuery) {
  2222. $subQuery->whereNotNull('article_ignore.article_id')
  2223. ->where('article_ignore.is_ignore', 0)
  2224. ->where(function ($subSubQuery) {
  2225. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2226. ->orWhereNull('article_ignore.c_show_time');
  2227. });
  2228. });
  2229. })
  2230. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2231. ->orderBy('updated_at', 'desc')
  2232. ->limit($article_imgnum)
  2233. ->get()->all();
  2234. foreach ($img_article as $k => $v) {
  2235. // var_dump($v);
  2236. // var_dump($k);
  2237. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2238. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2239. }
  2240. } else {
  2241. $img_article = [];
  2242. }
  2243. if ($article_textnum != 0) {
  2244. $text_article = Article::where('catid', $child_category)
  2245. ->where('status', 1)
  2246. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2247. $query->from('article_ignore')
  2248. ->where('website_id', $wetbsite_id);
  2249. }, 'article_ignore', function ($join) {
  2250. $join->on('article_ignore.article_id', '=', 'article.id');
  2251. })
  2252. ->where(function ($query) {
  2253. $query->whereNull('article_ignore.article_id')
  2254. ->orWhere(function ($subQuery) {
  2255. $subQuery->whereNotNull('article_ignore.article_id')
  2256. ->where('article_ignore.is_ignore', 0)
  2257. ->where(function ($subSubQuery) {
  2258. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2259. ->orWhereNull('article_ignore.c_show_time');
  2260. });
  2261. });
  2262. })
  2263. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2264. ->orderBy('updated_at', 'desc')
  2265. ->limit($article_textnum)
  2266. ->get()->all();
  2267. foreach ($text_article as $k => $v) {
  2268. // var_dump($v);
  2269. // var_dump($k);
  2270. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2271. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2272. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2273. }
  2274. } else {
  2275. $text_article = [];
  2276. }
  2277. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2278. $catiall[$child_category]['imgnum'] = $img_article;
  2279. $catiall[$child_category]['textnum'] = $text_article;
  2280. $child[$key] = $catiall[$child_category];
  2281. // var_dump($pids);
  2282. } else {
  2283. $child[$key] = '';
  2284. }
  2285. }
  2286. }
  2287. foreach ($parent as $key => $value) {
  2288. $result[$key] = $value;
  2289. if (!empty($child[$key])) {
  2290. // var_dump($child[$key]);
  2291. $result[$key]['child'] = $child[$key];
  2292. // $value[$key]['child'] = $child[$key];
  2293. } else {
  2294. $result[$key]['child'] = [
  2295. "alias" => null,
  2296. "category_id" => null,
  2297. "type" => null,
  2298. "pinyin" => null,
  2299. "all_childcat" => [],
  2300. "imgnum" => [],
  2301. "textnum" => []
  2302. ];
  2303. }
  2304. }
  2305. return Result::success($result);
  2306. }
  2307. /**
  2308. * 辅助方法:获取文章列表
  2309. */
  2310. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2311. {
  2312. sleep(1);
  2313. $query = Article::where('article.status', 1)
  2314. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2315. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2316. ->where(function ($query) use ($website) {
  2317. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2318. })
  2319. ->leftJoin('website_category', function ($join) use ($website) {
  2320. $join->on('article.catid', '=', 'website_category.category_id')
  2321. ->where('website_category.website_id', '=', $website['website_id']);
  2322. })
  2323. ->select(
  2324. 'article.id',
  2325. 'article.title',
  2326. 'article.imgurl',
  2327. 'article.author',
  2328. 'article.updated_at',
  2329. 'article.introduce',
  2330. 'article.islink',
  2331. 'article.linkurl',
  2332. 'article.copyfrom',
  2333. 'article.cat_arr_id',
  2334. 'article.catid',
  2335. 'website_category.alias as category_name'
  2336. )
  2337. ->orderBy('updated_at', 'desc')
  2338. ->limit($limit);
  2339. // 如果是图片文章,添加图片URL条件
  2340. if ($isImageArticle) {
  2341. $query->where('imgurl', '!=', '');
  2342. } else {
  2343. // 文字文章不需要imgurl字段
  2344. $query->addSelect('article.introduce');
  2345. }
  2346. $articles = $query->get();
  2347. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2348. }
  2349. /**
  2350. * 乡村网-获取特殊新闻模块
  2351. * @param array $data
  2352. * @return array
  2353. */
  2354. public function getWebsiteArticles(array $data): array
  2355. {
  2356. $website_id = $data['website_id'];
  2357. $website = Website::where('id', $website_id)->first();
  2358. if (empty($website)) {
  2359. return Result::error("网站不存在", 0);
  2360. }
  2361. // return Result::success($website);
  2362. $website_column = $website['website_column_arr_id'] ?? '[]';
  2363. $website_column = json_decode($website_column, true);
  2364. $catids = json_decode($data['id'], true);
  2365. $parent_category = array_column($catids, 'parent');
  2366. if (!empty($parent_category) && is_array($parent_category)) {
  2367. $categorys = $this->processArticlePro($website_id);
  2368. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2369. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2370. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2371. }
  2372. $catiall = $categorys['catiall'];
  2373. $cat_1st_arr = $categorys['cat_1st_arr'];
  2374. // return Result::success($categorys);
  2375. foreach ($parent_category as $key => $value) {
  2376. $arr = array_map('intval', explode(',', $value));
  2377. $parent_category = $arr[0] ?? 0;
  2378. $article_imgnum = $arr[1] ?? 0;
  2379. $article_textnum = $arr[2] ?? 0;
  2380. if ($parent_category != 0) {
  2381. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2382. // return Result::success($category_arr);
  2383. if ($article_imgnum != 0) {
  2384. $img_article = Article::whereIn('article.catid', $category_arr)
  2385. ->where('article.status', 1)
  2386. ->where('article.imgurl', '!=', '')
  2387. ->leftJoinSub(function ($query) use ($website_id) {
  2388. $query->from('article_ignore')
  2389. ->where('website_id', $website_id);
  2390. }, 'article_ignore', function ($join) {
  2391. $join->on('article_ignore.article_id', '=', 'article.id');
  2392. })
  2393. ->where(function ($query) {
  2394. $query->whereNull('article_ignore.article_id')
  2395. ->orWhere(function ($subQuery) {
  2396. $subQuery->whereNotNull('article_ignore.article_id')
  2397. ->where('article_ignore.is_ignore', 0)
  2398. ->where(function ($subSubQuery) {
  2399. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2400. ->orWhereNull('article_ignore.c_show_time');
  2401. });
  2402. });
  2403. })
  2404. ->select(
  2405. 'article.id',
  2406. 'article.title',
  2407. 'article.imgurl',
  2408. 'article.author',
  2409. 'article.updated_at',
  2410. 'article.introduce',
  2411. 'article.islink',
  2412. 'article.linkurl',
  2413. 'article.copyfrom',
  2414. 'article.cat_arr_id',
  2415. 'article.catid as category_id'
  2416. )
  2417. ->orderBy('updated_at', 'desc')
  2418. ->limit($article_imgnum)
  2419. ->get()->all();
  2420. foreach ($img_article as $k => $v) {
  2421. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2422. // return Result::success($v);
  2423. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2424. }
  2425. } else {
  2426. $img_article = [];
  2427. }
  2428. if ($article_textnum != 0) {
  2429. $text_article = Article::whereIn('article.catid', $category_arr)
  2430. ->where('article.status', 1)
  2431. ->leftJoinSub(function ($query) use ($website_id) {
  2432. $query->from('article_ignore')
  2433. ->where('website_id', $website_id);
  2434. }, 'article_ignore', function ($join) {
  2435. $join->on('article_ignore.article_id', '=', 'article.id');
  2436. })
  2437. ->where(function ($query) {
  2438. $query->whereNull('article_ignore.article_id')
  2439. ->orWhere(function ($subQuery) {
  2440. $subQuery->whereNotNull('article_ignore.article_id')
  2441. ->where('article_ignore.is_ignore', 0)
  2442. ->where(function ($subSubQuery) {
  2443. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2444. ->orWhereNull('article_ignore.c_show_time');
  2445. });
  2446. });
  2447. })
  2448. ->select(
  2449. 'article.id',
  2450. 'article.title',
  2451. 'article.author',
  2452. 'article.updated_at',
  2453. 'article.introduce',
  2454. 'article.islink',
  2455. 'article.linkurl',
  2456. 'article.copyfrom',
  2457. 'article.cat_arr_id',
  2458. 'article.catid as category_id'
  2459. )
  2460. ->orderBy('updated_at', 'desc')
  2461. ->limit($article_textnum)
  2462. ->get()->all();
  2463. foreach ($text_article as $k => $v) {
  2464. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2465. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2466. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2467. }
  2468. } else {
  2469. $text_article = [];
  2470. }
  2471. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2472. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2473. $parent[$key] = $catiall[$parent_category];
  2474. } else {
  2475. $parent[$key] = [];
  2476. }
  2477. }
  2478. }
  2479. return Result::success($parent);
  2480. }
  2481. // 封装处理商品的路由问题
  2482. function processGoods($goods, $data)
  2483. {
  2484. return $goods->map(function ($good) use ($data) {
  2485. $catid = $good->catid ?? 0;
  2486. // $pinyin = '';
  2487. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2488. if (!empty($category->pid) && $category->pid != 0) {
  2489. $level = json_decode($category->category_arr_id, true);
  2490. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2491. ->whereIn('category_id', $level)
  2492. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2493. ->get(['aLIas_pinyin'])
  2494. ->pluck('aLIas_pinyin')
  2495. ->implode('/');
  2496. } else {
  2497. $pinyin = $category->aLIas_pinyin ?? '';
  2498. }
  2499. if (isset($good->city_id) && !empty($good->city_id)) {
  2500. $city = District::where('id', $good->city_id)->first(['name']);
  2501. $good->city_name = $city->name ?? '';
  2502. }
  2503. // 解析imgurl JSON并取第一条数据
  2504. $imgUrls = json_decode($good->imgurl, true);
  2505. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2506. $good->pinyin = $pinyin;
  2507. return $good;
  2508. });
  2509. }
  2510. /**
  2511. * 获取商城首页-根据栏目id
  2512. * @param array $data
  2513. * @return array
  2514. * */
  2515. function getWebsiteCatidshop(array $data): array
  2516. {
  2517. $input['catid'] = $data['catid'];
  2518. $input['website_id'] = $data['website_id'];
  2519. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2520. $result = array_map(function ($item) use ($input) {
  2521. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2522. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2523. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2524. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2525. if (empty($category) || $category->type != 2) {
  2526. return Result::error("暂无此栏目", 0);
  2527. } else {
  2528. $website['website_id'] = $input['website_id'];
  2529. $goods = Good::where('good.status', 2)
  2530. ->where('good.website_id', $website['website_id'])
  2531. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2532. ->select(
  2533. 'good.id',
  2534. 'good.name',
  2535. 'good.imgurl',
  2536. 'good.description',
  2537. 'good.updated_at',
  2538. 'good.catid',
  2539. 'good.type_id',
  2540. 'good.price',
  2541. 'good.com',
  2542. 'good.level',
  2543. 'good.unit'
  2544. )
  2545. ->orderBy('updated_at', 'desc')
  2546. ->offset($goodStart)
  2547. ->limit($goodNum);
  2548. $all_goods = $goods->get();
  2549. $all_goods = $this->processGoods($all_goods, $website);
  2550. }
  2551. return $all_goods ?? [];
  2552. }
  2553. }, $data);
  2554. return Result::success($result);
  2555. }
  2556. /**
  2557. * 获取商品模块
  2558. * @param array $data
  2559. * @return array
  2560. * */
  2561. public function getWebsiteshop(array $data): array
  2562. {
  2563. $input['id'] = $data['id'];
  2564. $input['website_id'] = $data['website_id'];
  2565. $catid = $data['catid'];
  2566. $data = json_decode($input['id'] ?? '', true) ?? [];
  2567. $result['goods'] = array_map(function ($item) use ($input) {
  2568. // 检查parent元素是否存在且不是undefined
  2569. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2570. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2571. $website = $input['website_id'];
  2572. $query = Good::where('good.status', 2)
  2573. ->where('good.website_id', $website);
  2574. switch ($Levelid) {
  2575. case 1:
  2576. case 2:
  2577. case 3:
  2578. $goods = $query->where(function ($q) use ($Levelid) {
  2579. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2580. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2581. });
  2582. break;
  2583. case 4:
  2584. $goods = $query;
  2585. break;
  2586. case 5:
  2587. $goods = $query->where('type_id', 1);
  2588. break;
  2589. case 6:
  2590. $goods = $query->where('type_id', 2);
  2591. break;
  2592. default:
  2593. return [];
  2594. }
  2595. $all_goods = $goods
  2596. ->select(
  2597. 'good.id',
  2598. 'good.name',
  2599. 'good.imgurl',
  2600. 'good.description',
  2601. 'good.updated_at',
  2602. 'good.catid',
  2603. 'good.type_id',
  2604. 'good.price',
  2605. 'good.level',
  2606. 'good.website_id'
  2607. )
  2608. ->orderBy('updated_at', 'desc')
  2609. ->offset($goodStart)
  2610. ->limit($goodNum)
  2611. ->get();
  2612. $web['website_id'] = $website;
  2613. $all_goods = $this->processGoods($all_goods, $web);
  2614. }
  2615. return $all_goods;
  2616. }, $data);
  2617. $website = $input['website_id'];
  2618. $result['article'] = Article::where(function ($query) use ($website) {
  2619. $query->where(function ($subQuery) use ($website) {
  2620. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2621. })->orWhereNull("ignore_ids");
  2622. })
  2623. ->where('catid', $catid)
  2624. ->where('article.status', 1)
  2625. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2626. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2627. ->orderBy('article.updated_at', 'desc')
  2628. ->first();
  2629. return Result::success($result);
  2630. }
  2631. /**
  2632. * 获取商品分类
  2633. * @param array $data
  2634. * @return array
  2635. * */
  2636. public function getWebsiteshopCat(array $data): array
  2637. {
  2638. $website = $data['website_id'];
  2639. $category = WebsiteCategory::where('website_id', $website)
  2640. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2641. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2642. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2643. ->orderBy('sort')
  2644. ->get();
  2645. $cat = $category->map(function ($item) use ($website) {
  2646. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2647. $pid = $item->pid ?? 0;
  2648. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2649. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2650. ->where('website_id', $website)
  2651. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2652. ->get(['aLIas_pinyin'])
  2653. ->pluck('aLIas_pinyin')
  2654. ->implode('/');
  2655. } else {
  2656. $pinyin = $item->aLIas_pinyin ?? '';
  2657. }
  2658. $item->pinyin = $pinyin;
  2659. });
  2660. if (empty($category)) {
  2661. return Result::error("栏目查询失败", 0);
  2662. }
  2663. $cat_tree = Result::buildMenuTree($category);
  2664. $web['website_id'] = $website;
  2665. $goods = Good::where('website_id', $website)
  2666. ->where('status', 2)
  2667. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2668. ->latest('updated_at')
  2669. ->offset(($data['page'] - 1) * $data['pageSize'])
  2670. ->limit($data['pageSize'])
  2671. ->get();
  2672. if (!empty($goods)) {
  2673. if ($goods->count() > 1 && !empty($goods)) {
  2674. $goods = $this->processGoods($goods, $web);
  2675. }
  2676. } else {
  2677. $goods = [];
  2678. }
  2679. $result = [
  2680. 'category' => $cat_tree,
  2681. 'goods' => $goods,
  2682. ];
  2683. // $resul['goods'] = $goods;
  2684. if (empty($result)) {
  2685. return Result::error("查询失败", 0);
  2686. }
  2687. return Result::success($result);
  2688. }
  2689. /*
  2690. * 获取商品列表
  2691. * @param array $data
  2692. * @return array
  2693. * */
  2694. public function getWebsiteshopList(array $data): array
  2695. {
  2696. // return Result::success($data);
  2697. $where = [
  2698. 'status' => 2,
  2699. 'website_id' => $data['website_id'],
  2700. ];
  2701. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2702. // return Result::error("查询失败", 0);
  2703. // }
  2704. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2705. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2706. $data['catid'] = $category->category_id ?? 0;
  2707. }
  2708. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2709. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2710. }
  2711. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2712. array_push($where, ['type_id', $data['type_id']]);
  2713. }
  2714. $query = Good::where($where)
  2715. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2716. $query->where(function ($q) use ($data) {
  2717. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2718. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2719. });
  2720. })
  2721. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2722. $query->where(function ($q) use ($data) {
  2723. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2724. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2725. });
  2726. })
  2727. ->select(
  2728. 'good.id',
  2729. 'good.name',
  2730. 'good.imgurl',
  2731. 'good.description',
  2732. 'good.updated_at',
  2733. 'good.com',
  2734. 'good.catid',
  2735. 'good.type_id',
  2736. 'good.website_id',
  2737. 'good.cat_arr_id',
  2738. 'good.created_at',
  2739. 'good.city_id'
  2740. )
  2741. ->latest('updated_at');
  2742. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2743. $result['count'] = $query->clone()->count();
  2744. $result['goods'] = $this->processGoods(
  2745. $query->clone()
  2746. ->offset(($data['page'] - 1) * $data['pageSize'])
  2747. ->limit($data['pageSize'])
  2748. ->get(),
  2749. $data
  2750. );
  2751. } else {
  2752. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2753. // 获取 type_id 为 1 的数据
  2754. $result['type1'] = $this->processGoods(
  2755. $query->clone()
  2756. ->where('type_id', 1)
  2757. ->offset(($data['page'] - 1) * $data['pageSize'])
  2758. ->limit($data['pageSize'])
  2759. ->get(),
  2760. $data
  2761. );
  2762. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2763. // 获取 type_id 为 2 的数据
  2764. $result['type2'] = $this->processGoods(
  2765. $query->clone()
  2766. ->where('type_id', 2)
  2767. ->offset(($data['page'] - 1) * $data['pageSize'])
  2768. ->limit($data['pageSize'])
  2769. ->get(),
  2770. $data
  2771. );
  2772. }
  2773. if (empty($result)) {
  2774. return Result::error("查询失败", 0);
  2775. }
  2776. return Result::success($result);
  2777. }
  2778. /**
  2779. * 获取商品详情
  2780. * @param array $data
  2781. * @return array
  2782. * */
  2783. public function getWebsiteshopInfo(array $data): array
  2784. {
  2785. $where = [
  2786. 'good.status' => 2,
  2787. 'good.website_id' => $data['website_id'],
  2788. 'good.id' => $data['id'],
  2789. ];
  2790. $goods = Good::where($where)
  2791. ->where('good.id', $data['id'])
  2792. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2793. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2794. ->first();
  2795. if (empty($goods)) {
  2796. return Result::error("查询失败", 0);
  2797. }
  2798. $goods->imgurl = json_decode($goods->imgurl, true);
  2799. return Result::success($goods);
  2800. }
  2801. /**
  2802. * plus pro 处理文章路由问题
  2803. */
  2804. function processArticlePro($website_id)
  2805. {
  2806. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2807. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2808. // // 取出category_id 对应的aLIas_pinyin
  2809. // $categoryIds = array_column($categorys, 'category_id');
  2810. // $categoryPIds = array_column($categorys, 'pid');
  2811. // $aliasPinyins = array_column($categorys, 'path');
  2812. // $alias = array_column($categorys, 'alias');
  2813. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2814. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2815. // // return Result::success($cat_arr);
  2816. // // $catiall = [];
  2817. // //一级所有子级的记录
  2818. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2819. // return [
  2820. // 'cat_1st_arr' => $cat_alias_arr,
  2821. // 'catiall' => $cat_arr,
  2822. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2823. // 'categoryIds' => $categoryIds,
  2824. // ];
  2825. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2826. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2827. // 取出category_id 对应的aLIas_pinyin
  2828. $categoryIds = array_column($categorys, 'category_id');
  2829. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2830. return $pid != 0;
  2831. })));
  2832. $category_path = array_column($categorys, 'path');
  2833. $cat_arr = array_combine($categoryIds, $category_path);
  2834. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2835. $catiall = [];
  2836. //一级所有子级的记录
  2837. $cat_1st_arr = [];
  2838. foreach ($categorys as $key => $value) {
  2839. // $category_arr_id = json_decode($value->category_arr_id);
  2840. // $pinyin_str = '';
  2841. // // 算出一级 并且算出子级
  2842. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2843. $cat_1st_arr[$value->pid][] = $value->category_id;
  2844. }
  2845. // foreach ($category_arr_id as $k => $v) {
  2846. // $pinyin_str .= $cat_arr[$v] . '/';
  2847. // }
  2848. // $pinyin_str = rtrim($pinyin_str, '/');
  2849. $catiall[$value->category_id]['alias'] = $value->alias;
  2850. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2851. $catiall[$value->category_id]['type'] = $value->type;
  2852. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2853. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2854. }
  2855. return [
  2856. 'cat_1st_arr' => $cat_1st_arr,
  2857. 'catiall' => $catiall,
  2858. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2859. 'categoryIds' => $categoryIds,
  2860. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2861. 'categoryPIds' => $categoryPIds,
  2862. ];
  2863. }
  2864. /**
  2865. * 封装处理文章的路由问题
  2866. * */
  2867. function processArticles($articles, $data)
  2868. {
  2869. // 检查 $articles 是否为数组或可迭代对象
  2870. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2871. return $articles->map(function ($article) use ($data) {
  2872. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2873. $catid = $article->cat_arr_id ?? '';
  2874. }
  2875. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2876. $catid = $article->category_arr_id ?? '';
  2877. }
  2878. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2879. $level = json_decode($catid, true);
  2880. if (!is_array($level)) {
  2881. return $article;
  2882. } else {
  2883. $level = array_map('intval', $level);
  2884. }
  2885. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2886. ->where($data)
  2887. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2888. ->pluck('aLIas_pinyin')
  2889. ->implode('/');
  2890. $article->pinyin = $pinyin ?? '';
  2891. return $article;
  2892. });
  2893. } else {
  2894. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2895. $catid = $articles->cat_arr_id ?? '';
  2896. $level = json_decode($catid, true);
  2897. if (!is_array($level)) {
  2898. return $articles;
  2899. } else {
  2900. $level = array_map('intval', $level);
  2901. }
  2902. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2903. ->where($data)
  2904. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2905. ->pluck('aLIas_pinyin')
  2906. ->implode('/');
  2907. $articles->pinyin = $pinyin ?? '';
  2908. return $articles;
  2909. }
  2910. }
  2911. // 封装处理由问题
  2912. function processJob($job, $data)
  2913. {
  2914. return $job->map(function ($job) use ($data) {
  2915. $category = $job->cat_arr_id ?? '';
  2916. $cityid = $job->city_arr_id ?? '';
  2917. $city = json_decode($cityid, true);
  2918. $pinyin = '';
  2919. $level = json_decode($category, true);
  2920. // 路由
  2921. if (!empty($level) && is_array($level)) {
  2922. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2923. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2924. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2925. ->get(['aLIas_pinyin'])
  2926. ->pluck('aLIas_pinyin')
  2927. ->implode('/');
  2928. if (empty($pinyin)) {
  2929. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2930. }
  2931. $job->pinyin = $pinyin;
  2932. }
  2933. // 取职位-城市 市??省
  2934. if (!empty($city) && is_array($city)) {
  2935. if (isset($city[1]) && !empty($city[1])) {
  2936. $city = District::where('id', $city[1])->first(['name']);
  2937. $job->city_name = $city->name ?? '';
  2938. } else if (isset($city[0]) && !empty($city[0])) {
  2939. $city = District::where('id', $city[0])->first(['name']);
  2940. $job->city_name = $city->name ?? '';
  2941. } else {
  2942. $job->city_name = '全国';
  2943. }
  2944. }
  2945. // 获取简历最后一级地区
  2946. if (isset($job->city_id) && !empty($job->city_id)) {
  2947. $city = District::where('id', $job->city_id)->first(['name']);
  2948. $job->hunt_cityname = $city->name ?? '';
  2949. }
  2950. // 组合详细地址
  2951. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2952. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2953. if (is_array($address_id) && !empty($address_id)) {
  2954. $address = District::whereIn('id', $address_id)
  2955. ->orderBy('level', 'asc')
  2956. ->get(['name'])
  2957. ->pluck('name')
  2958. ->implode('');
  2959. // $job->address_name = $address ?? '';
  2960. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2961. }
  2962. }
  2963. // 取行业
  2964. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2965. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2966. if (!empty($job->industry)) {
  2967. $query->where('hyid', $job->industry);
  2968. } else if (!empty($job->hy_id)) {
  2969. $query->where('hyid', $job->hy_id);
  2970. } else if (!empty($job->company_hy_id)) {
  2971. $query->where('hyid', $job->company_hy_id);
  2972. } else {
  2973. $query->where('hyid', $job->job_industry);
  2974. }
  2975. })->first(['hyname']);
  2976. $job->hy_name = $hy_name->hyname ?? '';
  2977. }
  2978. // 取职位类别
  2979. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2980. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2981. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2982. $job->zw_name = $zw_name->zwname ?? '';
  2983. }
  2984. // 取具体职位
  2985. 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))) {
  2986. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2987. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2988. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2989. }
  2990. // 取工作经验
  2991. if (isset($job->experience) && !empty($job->experience)) {
  2992. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2993. $job->experience_name = $experience->ename ?? '';
  2994. }
  2995. // 取学历
  2996. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2997. $education = $job->educational ?? $job->school_education;
  2998. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2999. $job->education_name = $education->ename ?? '';
  3000. }
  3001. // 语言
  3002. if (isset($job->language) && !empty($job->language)) {
  3003. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  3004. $job->language_name = $language->ename ?? '';
  3005. }
  3006. // 薪资
  3007. if (isset($job->salary) && !empty($job->salary)) {
  3008. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3009. $job->salary_name = $salary->ename ?? '';
  3010. }
  3011. // 职位性质
  3012. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3013. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3014. $job->job_nature_name = $job_nature->ename ?? '';
  3015. }
  3016. // 公司规模
  3017. if (isset($job->company_size) && !empty($job->company_size)) {
  3018. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3019. $job->company_size_name = $company_size->ename ?? '';
  3020. }
  3021. // 公司性质
  3022. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3023. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3024. $job->company_nature_name = $company_nature->nature_name ?? '';
  3025. }
  3026. // $job->pinyin = $pinyin;
  3027. return $job;
  3028. });
  3029. }
  3030. /**
  3031. * 获取书籍模块
  3032. * @param array $data
  3033. * @return array
  3034. * */
  3035. public function getWebsiteBook(array $data): array
  3036. {
  3037. $input['id'] = $data['id'];
  3038. $input['website_id'] = $data['website_id'];
  3039. // 将 JSON 字符串转换为 PHP 数组
  3040. $data = json_decode($input['id'], true);
  3041. // 使用 array_map 处理每个元素
  3042. $result = array_map(function ($item) use ($input) {
  3043. // 检查parent元素是否存在且不是undefined
  3044. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3045. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3046. $website = [
  3047. 'website_id' => $input['website_id'],
  3048. ];
  3049. // 查询栏目名称
  3050. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3051. if (empty($category)) {
  3052. $parent_alias = '';
  3053. $parent_pinyin = null;
  3054. $imgBooks = [];
  3055. $textBooks = [];
  3056. } else {
  3057. $parent_alias = $category->alias ?? '';
  3058. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3059. // 查找子分类ID数组
  3060. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3061. array_push($childCategoryIds, $parentCatId);
  3062. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3063. if ($parentImgNum != 0) {
  3064. // 查询图片新闻
  3065. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3066. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3067. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3068. })
  3069. ->where('book.status', 2)
  3070. ->where('book.img_url', '!=', '')
  3071. ->where('book.website_id', $website['website_id'])
  3072. ->leftJoin('website_category', function ($join) use ($website) {
  3073. $join->on('book.cat_id', '=', 'website_category.category_id')
  3074. ->where('website_category.website_id', '=', $website['website_id']);
  3075. })
  3076. ->select(
  3077. 'book.id',
  3078. 'book.title',
  3079. 'book.img_url',
  3080. 'book.price',
  3081. 'book.market_price',
  3082. 'book.description',
  3083. 'book.cat_id',
  3084. 'book.description',
  3085. 'book.updated_at',
  3086. 'website_category.alias as category_name',
  3087. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3088. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3089. )
  3090. ->orderBy('updated_at', 'desc')
  3091. ->limit($parentImgNum)
  3092. ->get()->all();
  3093. // 查询文字新闻
  3094. }
  3095. if ($parentTextNum != 0) {
  3096. $textBooks = [];
  3097. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3098. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3099. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3100. })
  3101. ->where('book.status', 2)
  3102. ->where('book.website_id', $website['website_id'])
  3103. ->leftJoin('website_category', function ($join) use ($website) {
  3104. $join->on('book.cat_id', '=', 'website_category.category_id')
  3105. ->where('website_category.website_id', '=', $website['website_id']);
  3106. })
  3107. ->select(
  3108. 'book.id',
  3109. 'book.title',
  3110. 'book.img_url',
  3111. 'book.price',
  3112. 'book.market_price',
  3113. 'book.description',
  3114. 'book.cat_id',
  3115. 'book.description',
  3116. 'book.updated_at',
  3117. 'website_category.alias as category_name',
  3118. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3119. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3120. )
  3121. ->orderBy('updated_at', 'desc')
  3122. ->limit($parentTextNum)
  3123. ->get()->all();
  3124. }
  3125. }
  3126. }
  3127. $resultItem = [
  3128. 'alias' => $parent_alias ?? '',
  3129. 'category_id' => $parentCatId ?? 0,
  3130. 'pinyin' => $parent_pinyin ?? null,
  3131. 'imgnum' => $imgBooks ?? [],
  3132. 'textnum' => $textBooks ?? [],
  3133. ];
  3134. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3135. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3136. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3137. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3138. ->get()->all();
  3139. if (!empty($childCategory)) {
  3140. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3141. // 查询子栏目名称
  3142. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3143. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3144. ->first();
  3145. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3146. $childImgArticles = [];
  3147. $childTextArticles = [];
  3148. $resultItem['child'] = [];
  3149. } else {
  3150. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3151. // 查询子栏目图片新闻
  3152. $childImgArticles = Book::where('cat_id', $childCatId)
  3153. ->where('status', 2)
  3154. ->where('img_url', '!=', '')
  3155. ->where('book.website_id', $website['website_id'])
  3156. ->leftJoin('website_category', function ($join) use ($website) {
  3157. $join->on('book.cat_id', '=', 'website_category.category_id')
  3158. ->where('website_category.website_id', '=', $website['website_id']);
  3159. })
  3160. ->select(
  3161. 'book.id',
  3162. 'book.title',
  3163. 'book.img_url',
  3164. 'book.price',
  3165. 'book.market_price',
  3166. 'book.description',
  3167. 'book.cat_id',
  3168. 'book.description',
  3169. 'book.updated_at',
  3170. DB::raw("'$child_pinyin' as pinyin")
  3171. )
  3172. ->orderBy('updated_at', 'desc')
  3173. ->limit($childImgNum)
  3174. ->get()->all();
  3175. // 查询子栏目文字新闻
  3176. $childTextArticles = Book::where('cat_id', $childCatId)
  3177. ->where('status', 2)
  3178. ->where('book.website_id', $website['website_id'])
  3179. ->leftJoin('website_category', function ($join) use ($website) {
  3180. $join->on('book.cat_id', '=', 'website_category.category_id')
  3181. ->where('website_category.website_id', '=', $website['website_id']);
  3182. })
  3183. ->select(
  3184. 'book.id',
  3185. 'book.title',
  3186. 'book.img_url',
  3187. 'book.price',
  3188. 'book.market_price',
  3189. 'book.description',
  3190. 'book.cat_id',
  3191. 'book.description',
  3192. 'book.updated_at',
  3193. DB::raw("'$child_pinyin' as pinyin")
  3194. )
  3195. ->orderBy('updated_at', 'desc')
  3196. ->limit($childTextNum)
  3197. ->get()->all();
  3198. $resultItem['child'] = [
  3199. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3200. 'category_id' => $childCatId,
  3201. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3202. 'all_childcat' => $childCategory,
  3203. 'imgnum' => $childImgArticles,
  3204. 'textnum' => $childTextArticles,
  3205. ];
  3206. }
  3207. }
  3208. } else {
  3209. $resultItem['child'] = [];
  3210. }
  3211. return $resultItem;
  3212. }, $data);
  3213. return Result::success($result);
  3214. }
  3215. /**
  3216. * 获取书刊列表
  3217. * @param array $data
  3218. * @return array
  3219. * */
  3220. public function getWebsiteBookList(array $data): array
  3221. {
  3222. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3223. if (empty($web)) {
  3224. return Result::error("查询失败", 0);
  3225. }
  3226. $catid = $data['id'];
  3227. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3228. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3229. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3230. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3231. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3232. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3233. ->where('pid', $category['pid'])
  3234. ->select(
  3235. 'category_id',
  3236. 'alias',
  3237. 'aLIas_pinyin',
  3238. 'pid',
  3239. 'sort',
  3240. 'is_url',
  3241. 'web_url',
  3242. 'seo_title',
  3243. 'seo_keywords',
  3244. 'seo_description',
  3245. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3246. )
  3247. ->orderBy('sort')
  3248. ->get()->all();
  3249. if (empty($category)) {
  3250. return Result::error("查询失败", 0);
  3251. }
  3252. $query = Book::where('book.status', 2)
  3253. ->where('book.website_id', $data['website_id'])
  3254. ->where('book.cat_id', $catid)
  3255. ->select(
  3256. 'book.id',
  3257. 'book.title',
  3258. 'book.img_url',
  3259. 'book.description',
  3260. 'book.updated_at',
  3261. 'book.cat_id',
  3262. DB::raw("'$pinyin' as pinyin")
  3263. )
  3264. ->orderBy('book.updated_at', 'desc');
  3265. $count = $query->count();
  3266. $query = clone $query;
  3267. $Book = $query
  3268. ->limit($data['pageSize'])
  3269. ->offset(($data['page'] - 1) * $data['pageSize'])
  3270. ->get()->all();
  3271. $result = [
  3272. 'category' => $categorys,
  3273. 'books' => $Book,
  3274. 'count' => $count,
  3275. ];
  3276. // if(empty($result)){
  3277. // return Result::error("查询失败", 0);
  3278. // }
  3279. return Result::success($result);
  3280. }
  3281. /**
  3282. * 获取书刊详情
  3283. * @param array $data
  3284. * @return array
  3285. * */
  3286. public function getWebsiteBookInfo(array $data): array
  3287. {
  3288. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3289. if (empty($web)) {
  3290. return Result::error("查询失败", 0);
  3291. }
  3292. $book = Book::where('status', 2)
  3293. ->where('website_id', $data['website_id'])
  3294. ->where('id', $data['id'])
  3295. ->select(
  3296. 'book.*',
  3297. )
  3298. ->orderBy('updated_at', 'desc')
  3299. ->first();
  3300. if (empty($book)) {
  3301. return Result::error("查询失败", 0);
  3302. }
  3303. // 先查询当前分类的 pid
  3304. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3305. ->where('category_id', $book['cat_id'])
  3306. ->first(['pid', 'category_id']);
  3307. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3308. if (!empty($carpid)) {
  3309. if ($carpid->pid != 0) {
  3310. $pid = $carpid['pid'];
  3311. // $parent_pinyin = '';
  3312. } else {
  3313. $pid = $carpid['category_id'];
  3314. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3315. }
  3316. }
  3317. $categorys = $query->where('pid', $pid)
  3318. ->select(
  3319. 'category_id',
  3320. 'alias',
  3321. 'aLIas_pinyin',
  3322. 'pid',
  3323. 'sort',
  3324. 'is_url',
  3325. 'web_url',
  3326. 'category_arr_id as cat_arr_id',
  3327. )
  3328. ->orderBy('sort')
  3329. ->get();
  3330. $category = $this->processArticle($categorys, $data);
  3331. $result = [
  3332. 'category' => $category,
  3333. 'books' => $book,
  3334. ];
  3335. return Result::success($result);
  3336. }
  3337. /**
  3338. * 尝试
  3339. * @param array $data
  3340. * @return array
  3341. * */
  3342. public function test(array $data): array
  3343. {
  3344. $input['id'] = $data['id'];
  3345. $input['website_id'] = $data['website_id'];
  3346. // 将 JSON 字符串转换为 PHP 数组
  3347. $data = json_decode($input['id'], true);
  3348. $result = [];
  3349. $article = $data;
  3350. $result = array_map(function ($item) use ($input) {
  3351. $website = [
  3352. 'website_id' => $input['website_id'],
  3353. ];
  3354. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3355. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3356. $parent = [
  3357. 0 => $category['category_id'] ?? [],
  3358. 1 => $parentImgNum ?? [],
  3359. 2 => $parentTextNum ?? [],
  3360. ];
  3361. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3362. $child = [];
  3363. $resultItem = [
  3364. // 'alias' => $parent_alias ?? '',
  3365. 'category_id' => $parentCatId ?? 0,
  3366. 'pinyin' => $parentImgNum ?? null,
  3367. 'imgnum' => $parentTextNum ?? [],
  3368. // 'textnum' => $textArticles ?? [],
  3369. ];
  3370. return $parent;
  3371. }, $data);
  3372. return Result::success($result);
  3373. // });
  3374. }
  3375. /**
  3376. * 封装处理文章的路由问题
  3377. * */
  3378. function processArticle($article, $data)
  3379. {
  3380. return $article->map(function ($article) use ($data) {
  3381. $catid = $article->cat_arr_id ?? '';
  3382. $level = json_decode($catid, true);
  3383. $pinyin = '';
  3384. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3385. if (!empty($level) && is_array($level)) {
  3386. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3387. ->where('website_id', $data['website_id'])
  3388. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3389. ->get(['aLIas_pinyin'])
  3390. ->pluck('aLIas_pinyin')
  3391. ->implode('/');
  3392. } else {
  3393. $pinyin = '';
  3394. }
  3395. $article->pinyin = $pinyin;
  3396. return $article;
  3397. });
  3398. }
  3399. /**
  3400. * c端-获取招工招聘下拉选框
  3401. * @param array $data
  3402. * @return array
  3403. * */
  3404. public function getWebsiteJobSelect(array $data): array
  3405. {
  3406. $web = Website::where('id', $data['website_id'])->first();
  3407. if (empty($web)) {
  3408. return Result::error("该网站不存在", 0);
  3409. }
  3410. $hy = JobIndustry::get()->all();
  3411. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3412. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3413. $result = [
  3414. 'hy' => $hy,
  3415. 'zw' => $zw,
  3416. 'jtzw' => $jtzw,
  3417. ];
  3418. if (empty($result)) {
  3419. return Result::error("查询失败", 0);
  3420. }
  3421. return Result::success($result);
  3422. }
  3423. /**
  3424. * c端-获取招工招聘
  3425. * @param array $data
  3426. * @return array
  3427. * */
  3428. public function getWebsiteJob(array $data): array
  3429. {
  3430. $web = Website::where('id', $data['website_id'])->first();
  3431. if (empty($web)) {
  3432. return Result::error("该网站不存在", 0);
  3433. }
  3434. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3435. ->where('job_hunting.website_id', $data['website_id'])
  3436. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3437. $query->where(function ($q) use ($data) {
  3438. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3439. });
  3440. })
  3441. ->select(
  3442. 'job_hunting.id',
  3443. 'job_hunting.catid',
  3444. 'job_hunting.cat_arr_id',
  3445. 'job_hunting.job_name_get',
  3446. 'job_hunting.industry',
  3447. 'job_hunting.name',
  3448. 'job_hunting.sexy',
  3449. 'job_hunting.origin',
  3450. 'job_hunting.city_arr_id',
  3451. 'job_hunting.experience',
  3452. 'job_hunting.updated_at',
  3453. 'job_hunting.salary',
  3454. 'job_hunting.skillList',
  3455. 'job_hunting.slelf_evaluation',
  3456. )
  3457. ->orderBy('updated_at', 'desc')
  3458. ->limit($data['job1_num'])
  3459. ->get();
  3460. $web['website_id'] = $data['website_id'];
  3461. if (empty($job_hunting)) {
  3462. $job_huntings = "未查询到相关简历信息";
  3463. } else {
  3464. $job_huntings = $this->processJob($job_hunting, $web);
  3465. }
  3466. // 0:待审核 1:已通过 2:已拒绝
  3467. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3468. ->where('job_recruiting.website_id', $data['website_id'])
  3469. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3470. $query->where(function ($q) use ($data) {
  3471. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3472. });
  3473. })
  3474. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3475. ->select(
  3476. 'job_recruiting.id',
  3477. 'job_recruiting.catid',
  3478. 'job_recruiting.cat_arr_id',
  3479. 'job_recruiting.title',
  3480. 'job_recruiting.jtzw_id',
  3481. 'job_recruiting.hy_id',
  3482. 'job_recruiting.city_arr_id',
  3483. 'job_recruiting.due_data',
  3484. 'job_recruiting.updated_at',
  3485. 'job_recruiting.experience',
  3486. 'job_recruiting.educational',
  3487. 'job_recruiting.salary',
  3488. 'job_recruiting.zw_id',
  3489. 'job_company.business_name',
  3490. 'job_recruiting.keyword',
  3491. 'job_recruiting.description',
  3492. )
  3493. ->orderBy('updated_at', 'desc')
  3494. ->limit($data['job2_num'])
  3495. ->get();
  3496. if (empty($job_recruiting->toArray())) {
  3497. $job_recruitings = "未查询到相关职位信息";
  3498. } else {
  3499. $job_recruitings = $this->processJob($job_recruiting, $web);
  3500. }
  3501. $result = [
  3502. 'job_hunting' => $job_huntings,
  3503. 'job_recuiting' => $job_recruitings,
  3504. ];
  3505. return Result::success($result);
  3506. }
  3507. /**
  3508. * c端-获取招工招聘列表
  3509. * @param array $data
  3510. * @return array
  3511. * */
  3512. public function getWebsiteJobList(array $data): array
  3513. {
  3514. $recruit_where = [];
  3515. $hunt_where = [];
  3516. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3517. if (empty($web)) {
  3518. return Result::error("此网站不存在", 0);
  3519. }
  3520. $website_id['website_id'] = $data['website_id'];
  3521. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3522. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3523. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3524. }
  3525. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3526. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3527. }
  3528. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3529. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3530. }
  3531. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3532. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3533. }
  3534. $query = JobRecruiting::where('job_recruiting.status', 1)
  3535. ->where('job_recruiting.website_id', $data['website_id'])
  3536. ->where($recruit_where)
  3537. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3538. $query->where(function ($q) use ($data) {
  3539. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3540. });
  3541. })
  3542. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3543. $query->where(function ($q) use ($data) {
  3544. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3545. });
  3546. })
  3547. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3548. ->select(
  3549. 'job_recruiting.id',
  3550. 'job_recruiting.catid',
  3551. 'job_recruiting.hy_id',
  3552. 'job_recruiting.title',
  3553. 'job_recruiting.zw_id',
  3554. 'job_recruiting.educational',
  3555. 'job_recruiting.jtzw_id',
  3556. 'job_recruiting.city_arr_id',
  3557. 'job_recruiting.due_data',
  3558. 'job_recruiting.experience',
  3559. 'job_recruiting.cat_arr_id',
  3560. 'job_recruiting.updated_at',
  3561. 'job_company.business_name',
  3562. 'job_recruiting.keyword',
  3563. 'job_recruiting.description',
  3564. )
  3565. ->orderBy('job_recruiting.updated_at', 'desc');
  3566. $recruit_count = $query->count();
  3567. $query = clone $query;
  3568. $JobRecruiting = $query
  3569. ->offset(($data['page'] - 1) * $data['pageSize'])
  3570. ->limit($data['pageSize'])
  3571. ->get();
  3572. if (empty($JobRecruiting)) {
  3573. $JobRecruiting = "暂无相关职位信息";
  3574. } else {
  3575. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3576. }
  3577. }
  3578. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3579. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3580. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3581. }
  3582. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3583. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3584. }
  3585. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3586. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3587. }
  3588. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3589. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3590. }
  3591. $query = JobHunting::where('job_hunting.status', 2)
  3592. ->where('job_hunting.website_id', $data['website_id'])
  3593. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3594. ->where($hunt_where)
  3595. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3596. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3597. // })
  3598. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3599. $query->where(function ($q) use ($data) {
  3600. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3601. });
  3602. })
  3603. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3604. $query->where(function ($q) use ($data) {
  3605. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3606. });
  3607. })
  3608. ->select(
  3609. 'job_hunting.id',
  3610. 'job_hunting.catid',
  3611. 'job_hunting.sexy',
  3612. 'job_hunting.experience',
  3613. 'job_hunting.origin',
  3614. 'job_hunting.industry',
  3615. 'job_hunting.name',
  3616. 'job_hunting.job',
  3617. 'job_hunting.job_name_get',
  3618. 'job_hunting.city_arr_id',
  3619. 'job_hunting.cat_arr_id',
  3620. 'job_hunting.created_at',
  3621. 'job_hunting.updated_at',
  3622. 'job_position.zwname as job_name',
  3623. 'job_hunting.skillList',
  3624. 'job_hunting.slelf_evaluation',
  3625. )
  3626. ->orderBy('job_hunting.updated_at', 'desc');
  3627. $hunt_count = $query->count();
  3628. $query = clone $query;
  3629. $JobHunting = $query
  3630. ->offset(($data['page'] - 1) * $data['pageSize'])
  3631. ->limit($data['pageSize'])
  3632. ->get();
  3633. if (empty($JobHunting)) {
  3634. $JobRecruiting = "暂无相关简历信息";
  3635. } else {
  3636. $JobHunting = $this->processJob($JobHunting, $website_id);
  3637. }
  3638. }
  3639. $result = [
  3640. 'JobRecruiting' => $JobRecruiting ?? [],
  3641. 'recruit_count' => $recruit_count ?? 0,
  3642. 'JobHunting' => $JobHunting ?? [],
  3643. 'hunt_count' => $hunt_count ?? 0,
  3644. ];
  3645. return Result::success($result);
  3646. }
  3647. /**
  3648. * c端-获取招工招聘详情
  3649. * @param array $data
  3650. * @return array
  3651. * */
  3652. public function getWebsiteJobInfo(array $data): array
  3653. {
  3654. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3655. if (empty($web)) {
  3656. return Result::error("该网站不存在", 0);
  3657. }
  3658. $webid = [
  3659. 'website_id' => $data['website_id'],
  3660. ];
  3661. // 职位相关信息
  3662. if ($data['type'] == 1) {
  3663. $query = JobRecruiting::where('status', 1)
  3664. ->where('website_id', $data['website_id'])
  3665. ->select('*');
  3666. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3667. $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();
  3668. if (!empty($company)) {
  3669. $result['company'] = $this->processJob($company, $webid);
  3670. }
  3671. $other_job = JobRecruiting::where('status', 1)
  3672. ->where('website_id', $data['website_id'])
  3673. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3674. ->where('id', '!=', $data['id'])
  3675. ->where('user_id', '=', $job[0]['user_id'])
  3676. ->limit($data['pageSize'])
  3677. ->get();
  3678. if (!empty($other_job)) {
  3679. $result['other_job'] = $this->processJob($other_job, $webid);
  3680. }
  3681. } else {
  3682. // 简历相关信息
  3683. $job = JobHunting::where('job_hunting.status', 2)
  3684. ->where('job_hunting.website_id', $data['website_id'])
  3685. ->where('job_hunting.id', $data['id'])
  3686. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3687. ->select('job_hunting.*', 'user_name')
  3688. ->get();
  3689. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3690. if (!empty($resume->toArray())) {
  3691. $result['resume'] = 1;
  3692. } else {
  3693. $result['resume'] = 0;
  3694. }
  3695. }
  3696. if (empty($job->toArray())) {
  3697. return Result::error("id参数错误", 0);
  3698. }
  3699. if (!empty($job[0]['job_experience'])) {
  3700. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3701. if (!empty($job_experience)) {
  3702. // $hy = [];
  3703. foreach ($job_experience as $key => $value) {
  3704. // $id = $value['id'];
  3705. $hy[$key] = $value['job_industry'];
  3706. $zw_id[$key] = $value['job_typename'];
  3707. $jtzw_id[$key] = $value['job_name'];
  3708. }
  3709. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3710. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3711. // 先将关联表转换为索引数组,提高查找效率
  3712. $hyLookup = [];
  3713. foreach ($hy_table as $item) {
  3714. $hyLookup[$item['hyid']] = $item['hyname'];
  3715. }
  3716. $zwLookup = [];
  3717. foreach ($zw_table as $item) {
  3718. $zwLookup[$item['zwid']] = $item['zwname'];
  3719. }
  3720. foreach ($job_experience as $key => &$value) {
  3721. // 处理行业名称
  3722. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3723. $value['hy_name'] = $hyLookup[$hy[$key]];
  3724. }
  3725. // 处理职位名称
  3726. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3727. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3728. }
  3729. // 处理具体职位名称
  3730. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3731. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3732. }
  3733. }
  3734. // 释放引用,防止意外修改后续代码
  3735. unset($value);
  3736. }
  3737. $result['job_experience'] = $job_experience ?? [];
  3738. }
  3739. if (!empty($job[0]['education_experience'])) {
  3740. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3741. if (!empty($education_experience)) {
  3742. foreach ($education_experience as $key => $value) {
  3743. // $id = $value['id'];
  3744. $education[$key] = $value['school_education'];
  3745. }
  3746. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3747. // // 先将关联表转换为索引数组,提高查找效率
  3748. $educationLookup = [];
  3749. foreach ($education_table as $item) {
  3750. $educationLookup[$item['evalue']] = $item['ename'];
  3751. }
  3752. foreach ($education_experience as $key => &$value) {
  3753. // 处理学历名称
  3754. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3755. $value['education_name'] = $educationLookup[$education[$key]];
  3756. }
  3757. }
  3758. }
  3759. $result['education_experience'] = $job_experience ?? [];
  3760. }
  3761. $result['job'] = $this->processJob($job, $webid);
  3762. // // 返现对应的栏目
  3763. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3764. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3765. ->whereIn('category_id', $catid)
  3766. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3767. ->orderBy('pid')->get()->all();
  3768. if (!empty($category)) {
  3769. $result['category'] = $category;
  3770. }
  3771. $result['job'] = $job;
  3772. $result['job_experience'] = $job_experience ?? [];
  3773. $result['education_experience'] = $education_experience ?? [];
  3774. if (empty($result)) {
  3775. return Result::error("参数错误", 0);
  3776. }
  3777. return Result::success($result);
  3778. }
  3779. /**
  3780. * c端-申请职位
  3781. * @param array $data
  3782. * @return array
  3783. * */
  3784. public function getWebsiteJobApply(array $data): array
  3785. {
  3786. // 首先验证网站是否存在
  3787. // return Result::success($data);
  3788. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3789. if (empty($web)) {
  3790. return Result::error("该网站不存在", 0);
  3791. }
  3792. // 验证用户是否存在且为个人会员/管理员
  3793. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3794. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3795. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3796. return Result::error("用户不存在", 0);
  3797. }
  3798. // 去除重复元素和空元素,并保持原始顺序
  3799. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3800. return !empty($value);
  3801. }));
  3802. // 验证职位是否存在 1:审核通过
  3803. $recruiting = JobRecruiting::where('status', 1)
  3804. ->where('website_id', $data['website_id'])
  3805. ->whereIn('id', $data['recruit_id'])
  3806. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3807. if (empty($recruiting)) {
  3808. return Result::error("该职位不存在", 0);
  3809. }
  3810. // 简历是否存在
  3811. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3812. if (empty($hunt_id)) {
  3813. return Result::error("该简历不存在", 0);
  3814. }
  3815. $data['hunt_id'] = $hunt_id['hunt_id'];
  3816. // // 验证是否已投递过该职位
  3817. $apply = JobApply::where('user_id', $data['user_id'])
  3818. ->where('hunt_id', $data['hunt_id'])
  3819. ->where('website_id', $data['website_id'])
  3820. ->whereIn('recruit_id', $data['recruit_id'])
  3821. ->get(['recruit_id']);
  3822. if (!empty($apply->toArray())) {
  3823. return Result::error("您已投递过该职位!");
  3824. }
  3825. $insertData = array_map(function ($recruiting) use ($data) {
  3826. return [
  3827. 'user_id' => $data['user_id'],
  3828. 'hunt_id' => $data['hunt_id'],
  3829. 'website_id' => $data['website_id'],
  3830. 'recruit_id' => $recruiting['recruit_id'],
  3831. 'receiver_id' => $recruiting['receiver_id'],
  3832. 'status' => 1,
  3833. ];
  3834. }, $recruiting);
  3835. // 批量插入数据
  3836. $result = JobApply::insert($insertData);
  3837. if (empty($result)) {
  3838. return Result::error("投递失败", 0);
  3839. }
  3840. return Result::success($result);
  3841. }
  3842. /**
  3843. * 招工招聘-沟通简历
  3844. * @param array $data
  3845. * @return array
  3846. * */
  3847. public function getWebsiteJobResume(array $data): array
  3848. {
  3849. // 首先验证网站是否存在
  3850. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3851. if (empty($web)) {
  3852. return Result::error("该网站不存在", 0);
  3853. }
  3854. // return Result::success($data);
  3855. // 验证用户是否存在且为企业会员/管理员
  3856. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3857. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3858. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3859. return Result::error("用户不存在", 0);
  3860. }
  3861. // 去除重复元素和空元素,并保持原始顺序
  3862. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3863. return !empty($value);
  3864. }));
  3865. // 验证简历是否存在
  3866. $hunting = JobHunting::where('status', 2)
  3867. ->where('website_id', $data['website_id'])
  3868. ->whereIn('id', $data['hunt_id'])
  3869. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3870. if (empty($hunting)) {
  3871. return Result::error("该简历不存在", 0);
  3872. }
  3873. // 验证是否已沟通过该简历
  3874. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3875. ->where('recruit_id', $data['recruit_id'])
  3876. ->where('website_id', $data['website_id'])
  3877. ->whereIn('hunt_id', $data['hunt_id'])
  3878. ->get(['hunt_id']);
  3879. if (!empty($remuse->toArray())) {
  3880. return Result::error("您已沟通过该简历!");
  3881. }
  3882. // 准备要插入的数据数组
  3883. $insertData = array_map(function ($hunting) use ($data) {
  3884. return [
  3885. 'user_id' => $data['user_id'],
  3886. 'recruit_id' => $data['recruit_id'],
  3887. 'website_id' => $data['website_id'],
  3888. 'hunt_id' => $hunting['hunt_id'],
  3889. 'receiver_id' => $hunting['receiver_id'],
  3890. 'status' => 1,
  3891. ];
  3892. }, $hunting);
  3893. // 批量插入数据
  3894. $result = JobRemuse::insert($insertData);
  3895. if (empty($result)) {
  3896. return Result::error("沟通失败", 0);
  3897. }
  3898. return Result::success($result);
  3899. }
  3900. /**
  3901. * 招工招聘 -我的职位(企业会员)
  3902. * @param array $data
  3903. * @return array
  3904. */
  3905. public function getWebsiteJobRecruiting(array $data): array
  3906. {
  3907. $web = Website::where('id', $data['website_id'])->first('id');
  3908. if (empty($web)) {
  3909. return Result::error("该网站不存在", 0);
  3910. }
  3911. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3912. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3913. return Result::error("用户暂无权限!", 0);
  3914. }
  3915. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3916. $result = JobRecruiting::where('website_id', $data['website_id'])
  3917. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3918. $query->where('user_id', $user['id']);
  3919. })
  3920. ->where('status', 1)
  3921. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3922. ->orderBy('updated_at', 'desc')
  3923. ->limit($data['pageSize'])
  3924. ->get();
  3925. if (empty($result)) {
  3926. return Result::error("暂无相关职位信息", 0);
  3927. }
  3928. return Result::success($result);
  3929. }
  3930. /**
  3931. * c端 - 验证路由
  3932. * @param array $data
  3933. * @return array
  3934. */
  3935. /**
  3936. * c端 - 验证路由
  3937. * @param array $data
  3938. * @return array
  3939. */
  3940. public function checkWebsiteRoute(array $data): array
  3941. {
  3942. // 测试001111111222
  3943. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3944. if (empty($web)) {
  3945. return Result::error("该网站不存在", 0);
  3946. } elseif ($web['status'] != 1) {
  3947. return Result::error("网站已经关闭", 0);
  3948. }
  3949. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3950. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3951. // 验证路由是否存在
  3952. if (empty($whiteRouterInfo)) {
  3953. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3954. }
  3955. if (!empty($whiteRouterInfo)) {
  3956. return Result::success($whiteRouterInfo->toArray());
  3957. }
  3958. }
  3959. // 验证栏目路由
  3960. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3961. ->where('path', $data['all_route'])
  3962. ->get()->all();
  3963. if (count($last_category) == 0) {
  3964. return Result::error("该栏目不存在", 0);
  3965. }
  3966. if (count($last_category) > 1) {
  3967. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3968. }
  3969. if (count($last_category) == 1) {
  3970. $last_category = $last_category[0];
  3971. }
  3972. // return Result::success($last_category);
  3973. if (isset($data['id']) && !empty($data['id'])) {
  3974. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3975. switch ($last_category['type']) {
  3976. case 1:
  3977. // 文章
  3978. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3979. $article = Article::where('status', 1)
  3980. ->where('id', $data['id'])
  3981. ->where(function ($query) use ($data) {
  3982. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3983. ->orWhereNull("ignore_ids");
  3984. })
  3985. ->first(['catid']);
  3986. if (empty($article)) {
  3987. return Result::error("该文章不存在", 0);
  3988. }
  3989. // return Result::success($article);
  3990. break;
  3991. case 2:
  3992. // 商品
  3993. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3994. $article = Good::where('website_id', $data['website_id'])
  3995. ->where('status', 2)
  3996. ->where('id', $data['id'])
  3997. ->first(['cat_arr_id']);
  3998. if (empty($article)) {
  3999. return Result::error("该商品不存在", 0);
  4000. }
  4001. break;
  4002. case 3:
  4003. // 书刊信息
  4004. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4005. $article = Book::where('website_id', $data['website_id'])
  4006. ->where('status', 2)
  4007. ->where('id', $data['id'])
  4008. ->first(['id', 'cat_arr_id']);
  4009. if (empty($article)) {
  4010. return Result::error("该书刊不存在", 0);
  4011. }
  4012. break;
  4013. case 4:
  4014. // 招聘
  4015. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4016. $article = JobRecruiting::where('website_id', $data['website_id'])
  4017. ->where('status', 1)
  4018. ->where('id', $data['id'])
  4019. ->first(['cat_arr_id']);
  4020. if (empty($article)) {
  4021. return Result::error("该招聘不存在", 0);
  4022. }
  4023. break;
  4024. case 5:
  4025. // 求职
  4026. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4027. $article = JobHunting::where('website_id', $data['website_id'])
  4028. ->where('status', 2)
  4029. ->where('id', $data['id'])
  4030. ->first(['cat_arr_id']);
  4031. if (empty($article)) {
  4032. return Result::error("该求职不存在", 0);
  4033. }
  4034. break;
  4035. case 6:
  4036. // 企业
  4037. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4038. $article = Company::
  4039. // where('website_id', $data['website_id'])
  4040. // ->
  4041. where('status', 1)
  4042. ->where('id', $data['id'])
  4043. ->first(['cat_arr_id']);
  4044. if (empty($article)) {
  4045. return Result::error("该企业不存在", 0);
  4046. }
  4047. break;
  4048. case 7:
  4049. // 项目
  4050. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4051. $article = Project::where('website_id', $data['website_id'])
  4052. ->where('status', 1)
  4053. ->where('id', $data['id'])
  4054. ->first(['cat_arr_id']);
  4055. if (empty($article)) {
  4056. return Result::error("该项目不存在", 0);
  4057. }
  4058. break;
  4059. default:
  4060. return Result::error("该数据不存在", 0);
  4061. break;
  4062. }
  4063. // return Result::success($article);
  4064. // $catid =0 ;
  4065. if (!isset($article['cat_arr_id'])) {
  4066. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4067. } else {
  4068. $catidArray = json_decode($article['cat_arr_id'], true);
  4069. $catid = !empty($catidArray) ? end($catidArray) : null;
  4070. }
  4071. // return Result::success($catid);
  4072. // // return Result::success($article['cat_arr_id']);
  4073. if (empty($catid)) {
  4074. return Result::error("该栏目路径不存在", 0);
  4075. }
  4076. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4077. ->where('category_id', $catid)
  4078. ->first('path');
  4079. }
  4080. // else{
  4081. // // if ($last_category['pid'] != 0) {
  4082. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4083. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4084. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4085. // ->where('category_id',$catid)
  4086. // ->where('path',$data['all_route'])
  4087. // ->first('path');
  4088. // // } else {
  4089. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4090. // // }
  4091. // }
  4092. // return Result::success($path);
  4093. if (!empty($path) && $path['path'] != $data['all_route']) {
  4094. return Result::error('非法路径!');
  4095. } else {
  4096. return Result::success($last_category['path']);
  4097. }
  4098. }
  4099. /**
  4100. * 招工招聘 - 获取推荐职位
  4101. * @param array $data
  4102. * @return array
  4103. */
  4104. public function getWebsiteLevelJob(array $data): array
  4105. {
  4106. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4107. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4108. ->where('job_recruiting.status', 1)
  4109. ->where('job_level', $data['job_level'])
  4110. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4111. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4112. ->orderBy('job_recruiting.updated_at', 'desc')
  4113. ->limit($data['pageSize'])
  4114. ->get();
  4115. $web = ['website_id' => $data['website_id']];
  4116. if (!empty($job)) {
  4117. $result = $this->processJob($job, $web);
  4118. }
  4119. if (empty($result)) {
  4120. return Result::error("暂无相关职位信息", 0);
  4121. }
  4122. return Result::success($result);
  4123. }
  4124. /**
  4125. * 验证导航名称是否重复
  4126. * @return void
  4127. */
  4128. //20250226 产品列表
  4129. public function getGoodList(array $data): array
  4130. {
  4131. var_dump($data, '---------1-2--');
  4132. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4133. unset($data['user_type_id']);
  4134. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4135. $where = [];
  4136. if ($type_id != '10000') {
  4137. $where = [
  4138. 'good.user_id' => $user_id,
  4139. ];
  4140. }
  4141. //类型
  4142. if (isset($data['type_id']) && $data['type_id']) {
  4143. $where['good.type_id'] = $data['type_id'];
  4144. }
  4145. //名称
  4146. if (isset($data['name']) && $data['name']) {
  4147. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4148. }
  4149. //status
  4150. if (isset($data['status']) && $data['status'] != '') {
  4151. $where['good.status'] = $data['status'];
  4152. }
  4153. //status1
  4154. // if (isset($data['status1']) && $data['status1'] == 1) {
  4155. // $status1 = 1;
  4156. // }
  4157. $where1 = [];
  4158. //website_id
  4159. // if (isset($data['website_id']) && $data['website_id']) {
  4160. // $where1 = [
  4161. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4162. // ];
  4163. // }
  4164. // website_name
  4165. if (isset($data['website_name']) && $data['website_name']) {
  4166. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4167. }
  4168. // catid
  4169. if (isset($data['category_name']) && $data['category_name']) {
  4170. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4171. }
  4172. // $result = Good::where($where)
  4173. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4174. var_dump($where, '---------1---');
  4175. $result = Good::where($where)
  4176. ->when(!empty($where1), function ($query) use ($where1) {
  4177. return $query->where($where1);
  4178. })
  4179. //status 1待审核2已审核3已拒绝
  4180. ->when(isset($data['status1']), function ($query) {
  4181. return $query->whereIn('good.status', [1, 3]);
  4182. })
  4183. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4184. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4185. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4186. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4187. ->orderBy("updated_at", "desc")
  4188. ->limit($data['page_size'])
  4189. ->offset(($data['page'] - 1) * $data['page_size'])
  4190. ->get();
  4191. $count = Good::where($where)
  4192. ->when(!empty($where1), function ($query) use ($where1) {
  4193. return $query->where($where1);
  4194. })
  4195. //status 1待审核2已审核3已拒绝
  4196. ->when(isset($data['status1']), function ($query) {
  4197. return $query->whereIn('good.status', [1, 3]);
  4198. })
  4199. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4200. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4201. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4202. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4203. ->orderBy("updated_at", "desc")->count();
  4204. $data = [
  4205. 'rows' => $result->toArray(),
  4206. 'count' => $count,
  4207. ];
  4208. if (empty($result)) {
  4209. return Result::error("此栏目暂无相关产品", 0);
  4210. }
  4211. return Result::success($data);
  4212. }
  4213. public function getGoodInfo(array $data): array
  4214. {
  4215. $result = Good::where('id', $data['id'])->first();
  4216. if (empty($result)) {
  4217. return Result::error("此产品不存在", 0);
  4218. }
  4219. return Result::success($result);
  4220. }
  4221. public function addGood(array $data): array
  4222. {
  4223. // unset($data['city_arr_id']);
  4224. // unset($data['cat_arr_id']);
  4225. $data['city_id'] = end($data['city_arr_id']);
  4226. $data['catid'] = end($data['cat_arr_id']);
  4227. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4228. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4229. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4230. unset($data['imgUrl']); //大小写
  4231. if (isset($data['price']) && $data['price'] == '') {
  4232. $data['price'] = 0;
  4233. }
  4234. if ($data['imgurl'] == '') {
  4235. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4236. preg_match_all($reg, $data['detail'], $matches);
  4237. if (isset($matches[1][0])) {
  4238. //截取varchar240
  4239. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4240. }
  4241. }
  4242. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4243. //提取标题+内容中的关键词
  4244. $data['keyword'] = $data['name'];
  4245. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4246. Jieba::init(); // 初始化 jieba-php
  4247. Finalseg::init();
  4248. $segList = Jieba::cut($data['keyword']);
  4249. $segList1 = array_slice($segList, 0, 8);
  4250. $data['keyword'] = implode(',', $segList1);
  4251. }
  4252. if ($data['description'] == '') {
  4253. //提取内容中的描述
  4254. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4255. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4256. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4257. }
  4258. if ($data['status'] == 1) {
  4259. $this->sendMessage([
  4260. 'talk_type' => 200,
  4261. 'title' => $data['name'],
  4262. 'content' => '提交了审核',
  4263. 'messageType' => 3,
  4264. ]);
  4265. }
  4266. $result = Good::insert($data);
  4267. if (empty($result)) {
  4268. return Result::error("添加失败", 0);
  4269. }
  4270. return Result::success($result);
  4271. }
  4272. public function updateGood(array $data): array
  4273. {
  4274. $data['city_id'] = end($data['city_arr_id']);
  4275. $data['catid'] = end($data['cat_arr_id']);
  4276. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4277. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4278. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4279. //设置东八区
  4280. date_default_timezone_set('Asia/Shanghai');
  4281. $data['updated_at'] = date('Y-m-d H:i:s');
  4282. if (isset($data['price']) && $data['price'] == '') {
  4283. $data['price'] = 0;
  4284. }
  4285. if ($data['imgurl'] == '') {
  4286. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4287. preg_match_all($reg, $data['detail'], $matches);
  4288. if (isset($matches[1][0])) {
  4289. //截取varchar240
  4290. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4291. }
  4292. }
  4293. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4294. //提取标题+内容中的关键词
  4295. $data['keyword'] = $data['name'];
  4296. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4297. Jieba::init(); // 初始化 jieba-php
  4298. Finalseg::init();
  4299. $segList = Jieba::cut($data['keyword']);
  4300. $segList1 = array_slice($segList, 0, 8);
  4301. $data['keyword'] = implode(',', $segList1);
  4302. }
  4303. if ($data['description'] == '') {
  4304. //提取内容中的描述
  4305. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4306. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4307. }
  4308. if ($data['status'] == 1) {
  4309. $this->sendMessage([
  4310. 'talk_type' => 200,
  4311. 'title' => $data['name'],
  4312. 'content' => '提交了审核',
  4313. 'messageType' => 3,
  4314. ]);
  4315. }
  4316. $result = Good::where('id', $data['id'])->update($data);
  4317. if (empty($result)) {
  4318. return Result::error("更新失败", 0);
  4319. }
  4320. return Result::success($result);
  4321. }
  4322. public function delGood(array $data): array
  4323. {
  4324. $result = Good::where('id', $data['id'])->delete();
  4325. if (empty($result)) {
  4326. return Result::error("删除失败", 0);
  4327. }
  4328. return Result::success($result);
  4329. }
  4330. //20250226 产品列表
  4331. //20250306 求职信息
  4332. public function getJobHuntingList(array $data): array
  4333. {
  4334. $where = [];
  4335. if (isset($data['username']) && !empty($data['username'])) {
  4336. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4337. }
  4338. //status 1待审核2已审核3已拒绝
  4339. if (isset($data['status']) && $data['status'] != '') {
  4340. $where = [
  4341. 'job_hunting.status' => $data['status'],
  4342. ];
  4343. }
  4344. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4345. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4346. unset($data['type_id']);
  4347. if ($type_id != '10000') {
  4348. $where[] = ['job_hunting.user_id', '=', $user_id];
  4349. }
  4350. $result = JobHunting::where($where)
  4351. ->when(!empty($data['status1']), function ($query) use ($data) {
  4352. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4353. })
  4354. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4355. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4356. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4357. ->orderBy("updated_at", "desc")
  4358. ->limit($data['page_size'])
  4359. ->offset(($data['page'] - 1) * $data['page_size'])
  4360. ->get();
  4361. if (empty($result)) {
  4362. return Result::error("查询失败", 0);
  4363. }
  4364. $count = JobHunting::where($where)
  4365. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4366. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4367. ->count();
  4368. $data = [
  4369. 'rows' => $result->toArray(),
  4370. 'count' => $count,
  4371. ];
  4372. return Result::success($data);
  4373. }
  4374. public function getJobHuntingApply(array $data): array
  4375. {
  4376. var_dump($data, '-----------------test--------1-');
  4377. $where = [];
  4378. if (isset($data['username']) && !empty($data['username'])) {
  4379. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4380. }
  4381. if (isset($data['salary']) && !empty($data['salary'])) {
  4382. $where[] = [
  4383. 'job_hunting.salary',
  4384. '=',
  4385. $data['salary'],
  4386. ];
  4387. }
  4388. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4389. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4390. unset($data['type_id']);
  4391. if ($type_id != '10000') {
  4392. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4393. }
  4394. var_dump($where, '-----------------test---------');
  4395. $result = jobApply::where($where)
  4396. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4397. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4398. // })
  4399. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4400. ->where('job_enum.egroup', '=', 'income')
  4401. ->where('job_hunting.status', 2) //已审核
  4402. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4403. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4404. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4405. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4406. //职位----是申请职位
  4407. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4408. ->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')
  4409. ->orderBy("job_hunting.updated_at", "desc")
  4410. ->limit($data['page_size'])
  4411. ->offset(($data['page'] - 1) * $data['page_size'])
  4412. ->get();
  4413. if (empty($result)) {
  4414. return Result::error("查询失败", 0);
  4415. }
  4416. $count = jobApply::where($where)
  4417. ->where('job_enum.egroup', '=', 'income')
  4418. ->where('job_hunting.status', 2) //已审核
  4419. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4420. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4421. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4422. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4423. //职位----是申请职位
  4424. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4425. ->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')
  4426. ->count();
  4427. $data = [
  4428. 'rows' => $result->toArray(),
  4429. 'count' => $count,
  4430. ];
  4431. return Result::success($data);
  4432. }
  4433. public function addJobHunting(array $data): array
  4434. {
  4435. date_default_timezone_set('Asia/Shanghai');
  4436. unset($data['company_name']);
  4437. unset($data['job_industry']);
  4438. unset($data['job_name']);
  4439. unset($data['department']);
  4440. unset($data['job_timeList']);
  4441. unset($data['job_content']);
  4442. unset($data['job_typename']); //不知道这是啥,
  4443. $data['created_at'] = date('Y-m-d H:i:s');
  4444. $data['updated_at'] = date('Y-m-d H:i:s');
  4445. //根据用户 user_id 只能添加一次
  4446. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4447. if (!empty($result)) {
  4448. return Result::error("您已添加过求职信息", 0);
  4449. }
  4450. var_dump($result, '-----------------test---------');
  4451. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4452. if (is_string($data['city_arr_id'])) {
  4453. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4454. $cityArr = json_decode($data['city_arr_id'], true);
  4455. // 确保 $cityArr 是数组
  4456. if (is_array($cityArr)) {
  4457. $data['city_id'] = end($cityArr);
  4458. }
  4459. } else {
  4460. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4461. if (is_array($data['city_arr_id'])) {
  4462. $data['city_id'] = end($data['city_arr_id']);
  4463. }
  4464. }
  4465. }
  4466. // 处理求职所绑定栏目
  4467. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4468. if (is_string($data['cat_arr_id'])) {
  4469. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4470. // 先清理可能存在的无效 JSON 字符
  4471. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4472. $catArr = json_decode($cleanedCatArrStr, true);
  4473. // 检查 JSON 解码是否成功且结果是数组
  4474. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4475. $data['catid'] = end($catArr);
  4476. }
  4477. } else {
  4478. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4479. if (is_array($data['cat_arr_id'])) {
  4480. $data['catid'] = end($data['cat_arr_id']);
  4481. }
  4482. }
  4483. }
  4484. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4485. $this->sendMessage([
  4486. 'talk_type' => 600,
  4487. 'title' => $data['name'],
  4488. 'content' => '提交了审核',
  4489. 'messageType' => 11,
  4490. ]);
  4491. }
  4492. $result = JobHunting::create($data);
  4493. if (empty($result)) {
  4494. return Result::error("添加失败", 0);
  4495. }
  4496. return Result::success($result);
  4497. }
  4498. public function delJobHunting(array $data): array
  4499. {
  4500. $result = JobHunting::where('id', $data['id'])->delete();
  4501. if (empty($result)) {
  4502. return Result::error("删除失败", 0);
  4503. }
  4504. return Result::success($result);
  4505. }
  4506. public function updateJobHunting(array $data): array
  4507. {
  4508. //设置东八区
  4509. date_default_timezone_set('Asia/Shanghai');
  4510. unset($data['company_name']);
  4511. unset($data['job_industry']);
  4512. unset($data['job_name']);
  4513. unset($data['department']);
  4514. unset($data['job_timeList']);
  4515. unset($data['job_content']);
  4516. unset($data['job_typename']); //不知道这是啥,
  4517. $data['created_at'] = date('Y-m-d H:i:s');
  4518. $data['updated_at'] = date('Y-m-d H:i:s');
  4519. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4520. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4521. $cityArr = json_decode($data['city_arr_id'], true);
  4522. $data['city_id'] = end($cityArr);
  4523. } else {
  4524. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4525. $data['city_id'] = end($data['city_arr_id']);
  4526. }
  4527. // 处理求职所绑定栏目
  4528. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4529. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4530. $catArr = json_decode($data['cat_arr_id'], true);
  4531. $data['catid'] = end($catArr);
  4532. } else {
  4533. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4534. $data['catid'] = end($data['cat_arr_id']);
  4535. }
  4536. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4537. $this->sendMessage([
  4538. 'talk_type' => 600,
  4539. 'title' => $data['name'],
  4540. 'content' => '提交了审核',
  4541. 'messageType' => 11,
  4542. ]);
  4543. }
  4544. $result = JobHunting::where('id', $data['id'])->update($data);
  4545. if (empty($result)) {
  4546. return Result::error("更新失败", 0);
  4547. }
  4548. return Result::success($result);
  4549. }
  4550. public function getJobHuntingInfo(array $data): array
  4551. {
  4552. $result = JobHunting::where('id', $data['id'])->first();
  4553. if (empty($result)) {
  4554. return Result::error("查询失败", 0);
  4555. }
  4556. return Result::success($result);
  4557. }
  4558. public function getJobHuntingData(array $data): array
  4559. {
  4560. $jobEnum = JobEnum::get();
  4561. $jobIndustry = JobIndustry::get();
  4562. $jobNature = JobNature::get();
  4563. $jobPosition = JobPosition::get();
  4564. $data = [
  4565. 'jobEnum' => $jobEnum,
  4566. 'jobIndustry' => $jobIndustry,
  4567. 'jobNature' => $jobNature,
  4568. 'jobPosition' => $jobPosition,
  4569. ];
  4570. return Result::success($data);
  4571. }
  4572. public function delJobHuntingInfo(array $data): array
  4573. {
  4574. $result = JobHunting::where('id', $data['id'])->delete();
  4575. return Result::success();
  4576. }
  4577. //20250324 通知,公告,消息
  4578. public function delNotice(array $data): array
  4579. {
  4580. $result = Notice::where('id', $data['id'])->delete();
  4581. if ($result) {
  4582. return Result::success();
  4583. } else {
  4584. return Result::error("删除失败", 0);
  4585. }
  4586. }
  4587. public function getNoticeInfo(array $data): array
  4588. {
  4589. $result = Notice::where('id', $data['id'])->first();
  4590. // var_dump($result['re_user_ids'], '--------------------');
  4591. if (empty($result)) {
  4592. return Result::error("查询失败", 0);
  4593. }
  4594. return Result::success($result);
  4595. }
  4596. public function readNotice(array $data): array
  4597. {
  4598. $result = Notice::where('id', $data['id'])->first();
  4599. // var_dump($result['re_user_ids'], '--------------------');
  4600. if (empty($result)) {
  4601. return Result::error("查询失败", 0);
  4602. }
  4603. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4604. $re_user_ids = json_decode($result['re_user_ids'], true);
  4605. var_dump($re_user_ids, '--------------1---test---------');
  4606. var_dump($data, '--------------1---test---------');
  4607. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4608. //如果已经存在,就不再添加
  4609. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4610. $read_id = json_decode($result['read_id'], true);
  4611. if (!is_array($read_id)) {
  4612. $read_id = [];
  4613. }
  4614. if (!in_array($data['user_id'], $read_id)) {
  4615. $read_id[] = $data['user_id'];
  4616. $result['read_id'] = json_encode($read_id);
  4617. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4618. }
  4619. } else {
  4620. //如果不存在,就添加
  4621. $result['read_id'] = json_encode([$data['user_id']]);
  4622. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4623. }
  4624. }
  4625. return Result::success($result);
  4626. }
  4627. public function addNotice(array $data): array
  4628. {
  4629. date_default_timezone_set('Asia/Shanghai');
  4630. $data['created_at'] = date('Y-m-d H:i:s');
  4631. $data['updated_at'] = date('Y-m-d H:i:s');
  4632. // $data['level'] = "1,2,3,4,5";
  4633. $level = json_decode($data['level'], true);
  4634. $user_id = UserInfo::
  4635. //city_id不是null
  4636. whereNotNull('city_id')
  4637. ->whereNotNull('department_id')
  4638. ->where(function ($query) use ($data) {
  4639. $query->where(function ($subQuery) use ($data) {
  4640. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4641. });
  4642. })
  4643. ->where(function ($query) use ($data) {
  4644. $query->where(function ($subQuery) use ($data) {
  4645. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4646. });
  4647. })
  4648. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4649. $query->whereIn('level', $level);
  4650. })
  4651. ->pluck('user_id')->toArray();
  4652. $user_id = array_unique($user_id);
  4653. $chat_ids = $user_id;
  4654. $user_id = json_encode($user_id);
  4655. $data['re_user_ids'] = $user_id;
  4656. $this->sendMessage([
  4657. 'talk_type' => 700,
  4658. 'title' => $data['title'],
  4659. 'content' => '提交了审核',
  4660. 'messageType' => 5,
  4661. ]);
  4662. $result = Notice::insertGetId($data);
  4663. if (empty($result)) {
  4664. return Result::error("添加失败", 0);
  4665. }
  4666. return Result::success($result);
  4667. }
  4668. public function updateNotice(array $data): array
  4669. {
  4670. date_default_timezone_set('Asia/Shanghai');
  4671. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4672. $user_id = UserInfo::
  4673. //city_id不是null
  4674. whereNotNull('city_id')
  4675. ->whereNotNull('department_id')
  4676. ->where(function ($query) use ($data) {
  4677. $query->where(function ($subQuery) use ($data) {
  4678. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4679. });
  4680. })
  4681. ->where(function ($query) use ($data) {
  4682. $query->where(function ($subQuery) use ($data) {
  4683. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4684. });
  4685. })
  4686. ->pluck('user_id')->toArray();
  4687. $user_id = array_unique($user_id);
  4688. $user_id = json_encode($user_id);
  4689. $data['re_user_ids'] = $user_id;
  4690. $data['updated_at'] = date('Y-m-d H:i:s');
  4691. $this->sendMessage([
  4692. 'talk_type' => 700,
  4693. 'title' => $data['title'],
  4694. 'content' => '提交了审核',
  4695. 'messageType' => 5,
  4696. ]);
  4697. $result = Notice::where('id', $data['id'])->update($data);
  4698. return Result::success($result);
  4699. }
  4700. public function getNoticeList(array $data): array
  4701. {
  4702. $where = [];
  4703. //title
  4704. if (isset($data['title']) && !empty($data['title'])) {
  4705. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4706. }
  4707. //level
  4708. if (isset($data['level']) && !empty($data['level'])) {
  4709. $where[] = ['notice.level', '=', $data['level']];
  4710. }
  4711. //status
  4712. if (isset($data['status']) && !empty($data['status'])) {
  4713. $where[] = ['notice.status', '=', $data['status']];
  4714. }
  4715. //type
  4716. if (isset($data['type']) && !empty($data['type'])) {
  4717. $where[] = ['notice.type', '=', $data['type']];
  4718. }
  4719. var_dump($data, '------------11111-2----test---------');
  4720. if ($data['type_id'] == 10000) {
  4721. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4722. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4723. })
  4724. ->where($where)
  4725. ->orderBy('updated_at', 'desc')
  4726. ->limit($data['page_size'])
  4727. ->offset(($data['page'] - 1) * $data['page_size'])
  4728. ->get();
  4729. $total = 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. ->count();
  4735. } else {
  4736. $result = Notice::where($where)
  4737. // ->where('user_id', $data['user_id'])
  4738. ->Where(function ($query) use ($data) {
  4739. $query->Where(function ($q) use ($data) {
  4740. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4741. ->orWhere('notice.user_id', $data['user_id']);
  4742. });
  4743. })
  4744. ->when(!empty($data['status1']), function ($query) use ($data) {
  4745. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4746. })
  4747. ->orderBy('updated_at', 'desc')
  4748. ->limit($data['page_size'])
  4749. ->offset(($data['page'] - 1) * $data['page_size'])
  4750. ->get();
  4751. $total = Notice::where($where)
  4752. ->when(!empty($data['status1']), function ($query) use ($data) {
  4753. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4754. })
  4755. // ->where('user_id', $data['user_id'])
  4756. ->Where(function ($query) use ($data) {
  4757. $query->Where(function ($q) use ($data) {
  4758. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4759. ->orWhere('notice.user_id', $data['user_id']);
  4760. });
  4761. })
  4762. ->count();
  4763. }
  4764. if (empty($result)) {
  4765. return Result::error("查询失败", 0);
  4766. }
  4767. $data = [
  4768. 'rows' => $result,
  4769. 'count' => $total,
  4770. ];
  4771. return Result::success($data);
  4772. }
  4773. public function noticeList(array $data): array
  4774. {
  4775. $where = [];
  4776. //title
  4777. if (isset($data['title']) && !empty($data['title'])) {
  4778. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4779. }
  4780. //level
  4781. if (isset($data['level']) && !empty($data['level'])) {
  4782. $where[] = ['notice.level', '=', $data['level']];
  4783. }
  4784. //status
  4785. if (isset($data['status']) && !empty($data['status'])) {
  4786. $where[] = ['notice.status', '=', $data['status']];
  4787. }
  4788. //type
  4789. if (isset($data['type']) && !empty($data['type'])) {
  4790. $where[] = ['notice.type', '=', $data['type']];
  4791. }
  4792. var_dump($data, '------------11111-2----test---------');
  4793. if ($data['type_id'] == 10000) {
  4794. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4795. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4796. })
  4797. ->where($where)
  4798. ->orderBy('updated_at', 'desc')
  4799. ->limit($data['page_size'])
  4800. ->offset(($data['page'] - 1) * $data['page_size'])
  4801. ->get();
  4802. $total = 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. ->count();
  4808. } else {
  4809. $result = Notice::where($where)
  4810. // ->where('user_id', $data['user_id'])
  4811. ->Where(function ($query) use ($data) {
  4812. $query->Where(function ($q) use ($data) {
  4813. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4814. ->orWhere('notice.user_id', $data['user_id']);
  4815. });
  4816. })
  4817. ->when(!empty($data['status1']), function ($query) use ($data) {
  4818. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4819. })
  4820. ->orderBy('updated_at', 'desc')
  4821. ->limit($data['page_size'])
  4822. ->offset(($data['page'] - 1) * $data['page_size'])
  4823. ->get();
  4824. $total = Notice::where($where)
  4825. ->when(!empty($data['status1']), function ($query) use ($data) {
  4826. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4827. })
  4828. // ->where('user_id', $data['user_id'])
  4829. ->Where(function ($query) use ($data) {
  4830. $query->Where(function ($q) use ($data) {
  4831. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4832. ->orWhere('notice.user_id', $data['user_id']);
  4833. });
  4834. })
  4835. ->count();
  4836. }
  4837. if (empty($result)) {
  4838. return Result::error("查询失败", 0);
  4839. }
  4840. $data = [
  4841. 'rows' => $result,
  4842. 'count' => $total,
  4843. ];
  4844. return Result::success($data);
  4845. }
  4846. public function getNoticeDetail(array $data): array
  4847. {
  4848. $result = Notice::where('id', $data['id'])->first();
  4849. if (empty($result)) {
  4850. return Result::error("查询失败", 0);
  4851. }
  4852. return Result::success($result);
  4853. }
  4854. public function deleteNotice(array $data): array
  4855. {
  4856. $notice = Notice::where('id', $data['id'])->first();
  4857. if (empty($notice)) {
  4858. return Result::error("删除失败", 0);
  4859. }
  4860. $chat_group_id = $notice->group_id;
  4861. if ($chat_group_id) {
  4862. //删除群聊
  4863. ChatGroups::where('id', $chat_group_id)->delete();
  4864. //删除群成员
  4865. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4866. //删除群聊记录
  4867. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4868. }
  4869. $result = Notice::where('id', $data['id'])->delete();
  4870. return Result::success($result);
  4871. }
  4872. public function complaintList(array $data): array
  4873. {
  4874. var_dump($data, '---------1---------');
  4875. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4876. unset($data['type_id']);
  4877. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4878. $where = [];
  4879. if ($type_id != 10000 && empty($data['deal_user'])) {
  4880. // $where['complaint.user_id'] = $user_id;
  4881. }
  4882. if (!empty($data['title'])) {
  4883. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4884. }
  4885. if (!empty($data['department_id'])) {
  4886. $where['complaint.department_id'] = $data['department_id'];
  4887. }
  4888. if (!empty($data['deal'])) {
  4889. $where['complaint.deal'] = $data['deal'];
  4890. }
  4891. if (!empty($data['status'])) {
  4892. $where['complaint.status'] = $data['status'];
  4893. }
  4894. var_dump(!empty($data['deal_user']), '----------1');
  4895. var_dump($where, '----------2');
  4896. $result = Complaint::where($where)
  4897. ->when(!empty($data['status1']), function ($query) use ($data) {
  4898. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4899. })
  4900. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4901. //json re_user_ids data[user_id]是不是在里面
  4902. $query->Where(function ($q) use ($data) {
  4903. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4904. ->where('complaint.status', 2);
  4905. });
  4906. })
  4907. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4908. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4909. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4910. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4911. ->orderBy('updated_at', 'desc')
  4912. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4913. //sql输出
  4914. if (empty($result)) {
  4915. return Result::error("暂无投诉信息", 0);
  4916. }
  4917. // 取出数据
  4918. $rows = $result->items();
  4919. $count = $result->total();
  4920. $responseData = [
  4921. 'rows' => $rows,
  4922. 'count' => $count,
  4923. ];
  4924. return Result::success($responseData);
  4925. }
  4926. public function getComplaintList(array $data): array
  4927. {
  4928. var_dump($data, '00000001000000000000');
  4929. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4930. unset($data['type_id']);
  4931. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4932. $where = [];
  4933. if ($type_id != 10000 && empty($data['deal_user'])) {
  4934. $where['complaint.user_id'] = $user_id;
  4935. }
  4936. if (!empty($data['title'])) {
  4937. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4938. }
  4939. if (!empty($data['department_id'])) {
  4940. $where['complaint.department_id'] = $data['department_id'];
  4941. }
  4942. if (!empty($data['deal'])) {
  4943. $where['complaint.deal'] = $data['deal'];
  4944. }
  4945. if (!empty($data['status'])) {
  4946. $where['complaint.status'] = $data['status'];
  4947. }
  4948. var_dump(!empty($data['deal_user']), '----------1');
  4949. var_dump($where, '----------2');
  4950. $result = Complaint::where($where)
  4951. ->when(!empty($data['status1']), function ($query) use ($data) {
  4952. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4953. })
  4954. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4955. // //json re_user_ids data[user_id]是不是在里面
  4956. // $query->Where(function ($q) use ($data) {
  4957. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4958. // ->where('complaint.status', 2);
  4959. // });
  4960. // })
  4961. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4962. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4963. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4964. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4965. ->orderBy('updated_at', 'desc')
  4966. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4967. //sql输出
  4968. if (empty($result)) {
  4969. return Result::error("暂无投诉信息", 0);
  4970. }
  4971. // 取出数据
  4972. $rows = $result->items();
  4973. $count = $result->total();
  4974. $responseData = [
  4975. 'rows' => $rows,
  4976. 'count' => $count,
  4977. ];
  4978. return Result::success($responseData);
  4979. }
  4980. public function getComplaintInfo(array $data): array
  4981. {
  4982. $result = Complaint::where('id', $data['id'])->first();
  4983. if (empty($result)) {
  4984. return Result::error("查询失败", 0);
  4985. }
  4986. return Result::success($result);
  4987. }
  4988. public function readComplaint(array $data): array
  4989. {
  4990. $result = Complaint::where('id', $data['id'])->first();
  4991. if (empty($result)) {
  4992. return Result::error("查询失败", 0);
  4993. }
  4994. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4995. $re_user_ids = json_decode($result['re_user_ids'], true);
  4996. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4997. //如果已经存在,就不再添加
  4998. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4999. $read_id = json_decode($result['read_id'], true);
  5000. if (!is_array($read_id)) {
  5001. $read_id = [];
  5002. }
  5003. if (!in_array($data['user_id'], $read_id)) {
  5004. $read_id[] = $data['user_id'];
  5005. $result['read_id'] = json_encode($read_id);
  5006. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  5007. }
  5008. } else {
  5009. //如果不存在,就添加
  5010. $result['read_id'] = json_encode([$data['user_id']]);
  5011. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  5012. }
  5013. }
  5014. return Result::success($result);
  5015. }
  5016. public function addComplaint(array $data): array
  5017. {
  5018. date_default_timezone_set('Asia/Shanghai');
  5019. $data['created_at'] = date('Y-m-d H:i:s');
  5020. $data['updated_at'] = date('Y-m-d H:i:s');
  5021. $this->sendMessage([
  5022. 'talk_type' => 800,
  5023. 'title' => $data['title'],
  5024. 'content' => '提交了审核',
  5025. 'messageType' => 6,
  5026. ]);
  5027. $result = Complaint::create($data);
  5028. return Result::success($result);
  5029. }
  5030. public function updateComplaint(array $data): array
  5031. {
  5032. date_default_timezone_set('Asia/Shanghai');
  5033. $data['updated_at'] = date('Y-m-d H:i:s');
  5034. $user_id = $data['user_id'] ?? 0;
  5035. $type_id = $data['type_id'] ?? 0;
  5036. unset($data['user_id']);
  5037. unset($data['type_id']);
  5038. $this->sendMessage([
  5039. 'talk_type' => 800,
  5040. 'title' => $data['title'],
  5041. 'content' => '提交了审核',
  5042. 'messageType' => 6,
  5043. ]);
  5044. $result = Complaint::where('id', $data['id'])->update($data);
  5045. return Result::success($result);
  5046. }
  5047. public function deleteComplaint(array $data): array
  5048. {
  5049. $result = Complaint::where('id', $data['id'])->delete();
  5050. return Result::success($result);
  5051. }
  5052. public function getComplainInfo(array $data): array
  5053. {
  5054. $result = Complaint::where('id', $data['id'])->first();
  5055. if (empty($result)) {
  5056. return Result::error("查询失败", 0);
  5057. }
  5058. return Result::success($result);
  5059. }
  5060. public function updateComplaintStatus(array $data): array
  5061. {
  5062. date_default_timezone_set('Asia/Shanghai');
  5063. $data['updated_at'] = date('Y-m-d H:i:s');
  5064. $user_id = $data['user_id'] ?? 0;
  5065. $type_id = $data['type_id'] ?? 0;
  5066. unset($data['user_id']);
  5067. unset($data['type_id']);
  5068. //处理, 写入处理人
  5069. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5070. $data['real_deal_user'] = $user_id;
  5071. }
  5072. //如果是deal 23,则判断是不是处理人
  5073. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5074. $complaintInof = Complaint::where('id', $data['id'])
  5075. ->where('real_deal_user', $user_id)
  5076. ->first();
  5077. if (empty($complaintInof)) {
  5078. return Result::error("处理人错误", 0);
  5079. }
  5080. }
  5081. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5082. if ($data['status'] == 1) {
  5083. $this->sendMessage([
  5084. 'talk_type' => 800,
  5085. 'title' => $complaintInfo['title'],
  5086. 'content' => '提交了审核',
  5087. 'messageType' => 6,
  5088. ]);
  5089. }
  5090. if ($data['status'] == 2 && !isset($data['deal'])) {
  5091. $this->sendMessage([
  5092. 'talk_type' => 801,
  5093. 'title' => $complaintInfo['title'],
  5094. 'content' => '审核通过',
  5095. 'messageType' => 6,
  5096. 'user_id' => $complaintInfo['user_id'],
  5097. ]);
  5098. $this->sendMessage([
  5099. 'talk_type' => 802,
  5100. 'title' => $complaintInfo['title'],
  5101. 'content' => '待处理',
  5102. 'messageType' => 6,
  5103. 'user_id' => $complaintInfo['re_user_ids'],
  5104. ]);
  5105. }
  5106. if ($data['status'] == 3 && !isset($data['deal'])) {
  5107. $this->sendMessage([
  5108. 'talk_type' => 801,
  5109. 'title' => $complaintInfo['title'],
  5110. 'content' => '审核拒绝',
  5111. 'messageType' => 6,
  5112. 'user_id' => $complaintInfo['user_id'],
  5113. ]);
  5114. }
  5115. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5116. $this->sendMessage([
  5117. 'talk_type' => 802,
  5118. 'title' => $complaintInfo['title'],
  5119. 'content' => '处理中',
  5120. 'messageType' => 6,
  5121. 'user_id' => $complaintInfo['re_user_ids'],
  5122. ]);
  5123. }
  5124. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5125. $this->sendMessage([
  5126. 'talk_type' => 802,
  5127. 'title' => $complaintInfo['title'],
  5128. 'content' => '不予处理',
  5129. 'messageType' => 6,
  5130. 'user_id' => $complaintInfo['re_user_ids'],
  5131. ]);
  5132. }
  5133. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5134. $this->sendMessage([
  5135. 'talk_type' => 802,
  5136. 'title' => $complaintInfo['title'],
  5137. 'content' => '已完结',
  5138. 'messageType' => 6,
  5139. 'user_id' => $complaintInfo['re_user_ids'],
  5140. ]);
  5141. }
  5142. $result = complaint::where('id', $data['id'])->update($data);
  5143. return Result::success($result);
  5144. }
  5145. public function updateGoodStatus(array $data): array
  5146. {
  5147. $user_id = $data['user_id'] ?? 0;
  5148. $type_id = $data['type_id'] ?? 0;
  5149. unset($data['user_id']);
  5150. unset($data['type_id']);
  5151. $goodInfo = Good::where('id', $data['id'])->first();
  5152. if ($data['status'] == 2) {
  5153. $this->sendMessage([
  5154. 'talk_type' => 201,
  5155. 'title' => $goodInfo['name'],
  5156. 'content' => '审核通过',
  5157. 'messageType' => 3,
  5158. 'user_id' => $goodInfo['user_id'],
  5159. ]);
  5160. }
  5161. if ($data['status'] == 3) {
  5162. $this->sendMessage([
  5163. 'talk_type' => 201,
  5164. 'title' => $goodInfo['name'],
  5165. 'content' => '审核拒绝',
  5166. 'messageType' => 3,
  5167. 'user_id' => $goodInfo['user_id'],
  5168. ]);
  5169. }
  5170. if ($data['status'] == 1) {
  5171. $this->sendMessage([
  5172. 'talk_type' => 200,
  5173. 'title' => $goodInfo['name'],
  5174. 'content' => '提交了审核',
  5175. 'messageType' => 3,
  5176. ]);
  5177. }
  5178. $result = Good::where('id', $data['id'])->update($data);
  5179. return Result::success($result);
  5180. }
  5181. public function updateJobHuntingStatus(array $data): array
  5182. {
  5183. $user_id = $data['user_id'] ?? 0;
  5184. $type_id = $data['type_id'] ?? 0;
  5185. unset($data['user_id']);
  5186. unset($data['type_id']);
  5187. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5188. if ($data['status'] == 2) {
  5189. $this->sendMessage([
  5190. 'talk_type' => 601,
  5191. 'title' => $jogHuntingInfo['name'],
  5192. 'content' => '审核通过',
  5193. 'messageType' => 11,
  5194. 'user_id' => $jogHuntingInfo['user_id'],
  5195. ]);
  5196. }
  5197. if ($data['status'] == 3) {
  5198. $this->sendMessage([
  5199. 'talk_type' => 601,
  5200. 'title' => $jogHuntingInfo['name'],
  5201. 'content' => '审核拒绝',
  5202. 'messageType' => 11,
  5203. 'user_id' => $jogHuntingInfo['user_id'],
  5204. ]);
  5205. }
  5206. if ($data['status'] == 1) {
  5207. $this->sendMessage([
  5208. 'talk_type' => 600,
  5209. 'title' => $jogHuntingInfo['name'],
  5210. 'content' => '提交了审核',
  5211. 'messageType' => 11,
  5212. ]);
  5213. }
  5214. $result = JobHunting::where('id', $data['id'])->update($data);
  5215. return Result::success($result);
  5216. }
  5217. public function updateNoticeStatus(array $data): array
  5218. {
  5219. $user_id = $data['user_id'] ?? 0;
  5220. $type_id = $data['type_id'] ?? 0;
  5221. unset($data['user_id']);
  5222. unset($data['type_id']);
  5223. //查询公告
  5224. $notice = Notice::where('id', $data['id'])->first();
  5225. if (empty($notice)) {
  5226. return Result::error("公告不存在", 0);
  5227. }
  5228. //$chat_ids 去除掉$data['user_id']
  5229. $chat_ids = json_decode($notice['re_user_ids'], true);
  5230. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5231. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5232. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5233. //chat_group
  5234. $group_id = PublicData::uuid();
  5235. $groupData = [
  5236. 'id' => $group_id,
  5237. 'creator_id' => $notice['user_id'],
  5238. 'group_name' => $notice['group_name'] ?? '',
  5239. 'profile' => $notice['profile'] ?? 0,
  5240. ];
  5241. var_dump($groupData, '-----------------groupData-------');
  5242. $groupResult = ChatGroups::insertGetId($groupData);
  5243. var_dump($groupResult, '-----------------groupid-------');
  5244. $groupMemberData = [
  5245. 'id' => PublicData::uuid(),
  5246. 'user_id' => $notice['user_id'],
  5247. 'group_id' => $group_id,
  5248. 'leader' => 2,
  5249. ];
  5250. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5251. //插入群成员表
  5252. $groupMemberDataUser = [];
  5253. $chatData = [];
  5254. foreach ($chat_ids as $key => $value) {
  5255. $groupMemberDataUser[] = [
  5256. 'id' => PublicData::uuid(),
  5257. 'user_id' => $value,
  5258. 'group_id' => $group_id,
  5259. 'leader' => 1,
  5260. ];
  5261. $chatData[] = [
  5262. 'user_id' => $value,
  5263. 'msg_type' => 1,
  5264. 'receiver_id' => $group_id,
  5265. 'content' => '通过通知创建群聊',
  5266. 'group_receiver_id' => $notice['user_id'],
  5267. 'action' => 'recieved',
  5268. 'created_at' => date('Y-m-d H:i:s'),
  5269. ];
  5270. }
  5271. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5272. ChatGroupsMember::insert($groupMemberDataUser);
  5273. //插入一条管理员聊天记录
  5274. $chatData[] = [
  5275. 'user_id' => $notice['user_id'],
  5276. 'msg_type' => 1,
  5277. 'receiver_id' => $group_id,
  5278. 'content' => '通过通知创建群聊',
  5279. 'group_receiver_id' => $notice['user_id'],
  5280. 'action' => 'said',
  5281. 'created_at' => date('Y-m-d H:i:s'),
  5282. ];
  5283. var_dump($chatData, '-----------------chatData-------');
  5284. $chatResult = ChatRecords::insert($chatData);
  5285. //处理imp
  5286. $group = [
  5287. 'type' => 1,
  5288. 'name' => $notice['group_name'] ?? '',
  5289. 'profile' => '',
  5290. 'avatar' => '',
  5291. 'creator_id' => $notice['user_id'],
  5292. ];
  5293. $groupResult = GroupImp::insertGetId($group);
  5294. var_dump($groupResult, '获取imp group_id');
  5295. $groupMember = [
  5296. 'user_id' => $notice['user_id'],
  5297. 'group_id' => $groupResult,
  5298. 'leader' => 1,
  5299. 'join_time' => Date('Y-m-d H:i:s')
  5300. ];
  5301. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5302. $talk_session = [
  5303. 'user_id' => $notice['user_id'],
  5304. 'to_from_id' => $groupResult,
  5305. 'talk_mode' => 2,
  5306. 'created_at' => Date('Y-m-d H:i:s'),
  5307. 'updated_at' => Date('Y-m-d H:i:s'),
  5308. ];
  5309. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5310. //被通知人员处理
  5311. foreach ($chat_ids as $key => $value) {
  5312. $groupMemberdata[] = [
  5313. 'user_id' => $value,
  5314. 'group_id' => $groupResult,
  5315. 'leader' => 3,
  5316. 'join_time' => Date('Y-m-d H:i:s')
  5317. ];
  5318. $talk_sessionData[] = [
  5319. 'user_id' => $value,
  5320. 'to_from_id' => $groupResult,
  5321. 'talk_mode' => 2,
  5322. 'created_at' => Date('Y-m-d H:i:s'),
  5323. 'updated_at' => Date('Y-m-d H:i:s'),
  5324. ];
  5325. }
  5326. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5327. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5328. $group_id = $groupResult;
  5329. //更新result的 group_id
  5330. $data['group_id'] = $group_id;
  5331. Notice::where(['id' => $data['id']])->update($data);
  5332. }
  5333. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5334. //删除掉信息
  5335. GroupImp::where('id', $notice['group_id'])->delete();
  5336. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5337. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5338. foreach ($chat_ids as $key => $value) {
  5339. }
  5340. //聊天记录删除
  5341. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5342. $data['group_id'] = null;
  5343. Notice::where(['id' => $data['id']])->update($data);
  5344. }
  5345. $result = Notice::where('id', $data['id'])->update($data);
  5346. $noticeInfo = Notice::where('id', $data['id'])->first();
  5347. if ($data['status'] == 2) {
  5348. $this->sendMessage([
  5349. 'talk_type' => 701,
  5350. 'title' => $noticeInfo['title'],
  5351. 'content' => '审核通过',
  5352. 'messageType' => 3,
  5353. 'user_id' => $noticeInfo['user_id'],
  5354. ]);
  5355. }
  5356. if ($data['status'] == 3) {
  5357. $this->sendMessage([
  5358. 'talk_type' => 701,
  5359. 'title' => $noticeInfo['title'],
  5360. 'content' => '审核拒绝',
  5361. 'messageType' => 3,
  5362. 'user_id' => $noticeInfo['user_id'],
  5363. ]);
  5364. }
  5365. if ($data['status'] == 1) {
  5366. $this->sendMessage([
  5367. 'talk_type' => 700,
  5368. 'title' => $noticeInfo['title'],
  5369. 'content' => '提交了审核',
  5370. 'messageType' => 3,
  5371. ]);
  5372. }
  5373. return Result::success($result);
  5374. }
  5375. public function getDUser(array $data): array
  5376. {
  5377. if (!empty($data['ids'])) {
  5378. $user = User::whereIn('id', $data['ids'])->getall();
  5379. if (empty($user)) {
  5380. return Result::error('无数据', 0);
  5381. }
  5382. return Result::success($user);
  5383. }
  5384. $where = [];
  5385. if (!empty($data['department_id'])) {
  5386. $where['department_id'] = $data['department_id'];
  5387. }
  5388. if (!empty($data['city_id'])) {
  5389. $where['city_id'] = $data['city_id'];
  5390. }
  5391. $result = User::where('type_id', 2)
  5392. ->where('status', 1)
  5393. ->where($where)
  5394. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5395. ->get();
  5396. if (empty($result)) {
  5397. return Result::error("查询失败", 0);
  5398. }
  5399. return Result::success($result);
  5400. }
  5401. /**
  5402. * 验证导航名称是否重复
  5403. * @return void
  5404. */
  5405. public function checkCategoryName(array $data): array
  5406. {
  5407. $result = Category::when($data, function ($query) use ($data) {
  5408. if (isset($data['name']) && $data['name']) {
  5409. $query->where("name", $data['name']);
  5410. }
  5411. if (isset($data['id']) && $data['id']) {
  5412. $query->where("id", "!=", $data['id']);
  5413. }
  5414. })->first();
  5415. if ($result) {
  5416. return Result::error("已存在");
  5417. } else {
  5418. return Result::success();
  5419. }
  5420. }
  5421. //20250226 产品列表
  5422. // 20250306 -------招聘--------fr
  5423. /*
  5424. * 招聘列表
  5425. * */
  5426. public function getJobRecruitingList(array $data): array
  5427. {
  5428. $where = [];
  5429. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5430. if ($data['checkout'] == 0) {
  5431. $job_status = [0, 2];
  5432. } else {
  5433. $job_status = [1];
  5434. }
  5435. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5436. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5437. }
  5438. $user = User::where('id', $data['user_id'])->first();
  5439. if (empty($user)) {
  5440. return Result::error("用户不存在", 0);
  5441. }
  5442. // 3:企业会员
  5443. if ($user['type_id'] == 3) {
  5444. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5445. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5446. }
  5447. // 如果 $where 为空,则不添加 where 条件
  5448. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5449. return $query->where($where);
  5450. })
  5451. ->whereIn('job_recruiting.status', $job_status)
  5452. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5453. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5454. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5455. ->orderBy("updated_at", "desc")
  5456. ->offset(($data['page'] - 1) * $data['page_size'])
  5457. ->limit($data['page_size'])
  5458. ->get()
  5459. ->all();
  5460. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5461. return $query->where($where);
  5462. })
  5463. ->whereIn('job_recruiting.status', $job_status)
  5464. ->count();
  5465. if (empty($result)) {
  5466. return Result::error("暂无招聘信息", 0);
  5467. }
  5468. return Result::success($result);
  5469. }
  5470. /*
  5471. * 招聘信息添加
  5472. * */
  5473. public function addJobRecruiting(array $data): array
  5474. {
  5475. // var_dump('添加招聘进入news------data',$data);
  5476. // return Result::success($data);
  5477. $user = User::where('user.id', $data['user_id'])
  5478. ->where('user.status', 1)
  5479. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5480. ->select(
  5481. 'user.type_id',
  5482. 'user.mobile',
  5483. 'user.email',
  5484. 'user_info.business_name',
  5485. 'user_info.company_hy_id',
  5486. 'user_info.company_nature',
  5487. 'user_info.company_size',
  5488. 'user_info.introduction',
  5489. 'user_info.real_name',
  5490. 'user_info.company_url',
  5491. 'user_info.address_arr_id',
  5492. 'user_info.address'
  5493. )
  5494. ->first();
  5495. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5496. return Result::error("用户不存在", 0);
  5497. }
  5498. $web = Website::where('id', $data['website_id'])->first();
  5499. if (empty($web)) {
  5500. return Result::error("网站不存在", 0);
  5501. }
  5502. // var_dump('添加招聘进入news---user---user',$user);
  5503. // 处理招聘关键词
  5504. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5505. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5506. } else {
  5507. Jieba::init(); // 初始化 jieba-php
  5508. Finalseg::init();
  5509. $segList = Jieba::cut($data['title']);
  5510. $segList1 = array_slice($segList, 0, 8);
  5511. $data['keyword'] = implode(',', $segList1);
  5512. }
  5513. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5514. $content = $data['description'];
  5515. // 去除 <style> 和 <script> 标签及其内容
  5516. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5517. // 去除所有 HTML 标签
  5518. $content = strip_tags($content);
  5519. // 去除 HTML 实体
  5520. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5521. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5522. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5523. // 去除多余空白
  5524. $content = preg_replace('/\s+/u', '', $content);
  5525. // 截取 100 个字符
  5526. $data['seo_description'] = mb_substr($content, 0, 100);
  5527. }
  5528. // return Result::success($user);
  5529. $data['action_id'] = $data['user_id'] ?? null;
  5530. $data['user_type'] = $user['type_id'] ?? null;
  5531. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5532. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5533. $data['catid'] = end($data['cat_arr_id']);
  5534. } else {
  5535. $data['catid'] = 0;
  5536. }
  5537. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5538. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5539. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5540. // 公司地址 管理员必填
  5541. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5542. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5543. // 管理员-企业相关信息
  5544. $company = [
  5545. // 'user_id' => $data['user_id']?? null,
  5546. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5547. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5548. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5549. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5550. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5551. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5552. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5553. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5554. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5555. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5556. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5557. ];
  5558. //去掉相关企业信息
  5559. $job = array_diff_key($data, array_flip(array_keys($company)));
  5560. // var_dump('添加招聘进入news---job---user',$job);
  5561. Db::beginTransaction();
  5562. try {
  5563. // // 先添加职位相关信息
  5564. if ($user['type_id'] == 10000) {
  5565. $job['status'] = 1;
  5566. }
  5567. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5568. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5569. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5570. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5571. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5572. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5573. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5574. // return Result::success($job);
  5575. $jobId = JobRecruiting::insertGetId($job);
  5576. if (empty($jobId)) {
  5577. Db::rollBack();
  5578. return Result::error("添加失败");
  5579. }
  5580. // 添加公司信息
  5581. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5582. $company['job_id'] = $jobId;
  5583. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5584. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5585. if ($user['type_id'] == 10000) {
  5586. // 管理员添加企业信息
  5587. $companyId = JobCompany::insertGetId($company);
  5588. if (empty($companyId)) {
  5589. Db::rollBack();
  5590. return Result::error("添加失败");
  5591. }
  5592. } else {
  5593. // 企业会员添加企业信息
  5594. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5595. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5596. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5597. $company['job_id'] = $jobId;
  5598. $companyId = JobCompany::insertGetId($company);
  5599. if (empty($companyId)) {
  5600. Db::rollBack();
  5601. return Result::error("添加失败");
  5602. }
  5603. }
  5604. Db::commit();
  5605. $result = [
  5606. 'job_id' => $jobId,
  5607. 'company_id' => $companyId,
  5608. ];
  5609. return Result::success($result);
  5610. } catch (\Exception $e) {
  5611. Db::rollBack();
  5612. return Result::error($e->getMessage(), 0);
  5613. }
  5614. // return Result::success($result);
  5615. }
  5616. /*
  5617. * 获取招聘信息详情
  5618. * */
  5619. public function getJobRecruitingInfo(array $data): array
  5620. {
  5621. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5622. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5623. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5624. ->select(
  5625. 'job_recruiting.*',
  5626. 'website.website_name as website_name',
  5627. 'job_company.business_name',
  5628. 'job_company.company_hy_id',
  5629. 'job_company.company_size',
  5630. 'job_company.company_nature',
  5631. 'job_company.introduction',
  5632. 'job_company.real_name',
  5633. 'job_company.mobile',
  5634. 'job_company.company_url',
  5635. 'job_company.address_arr_id',
  5636. 'job_company.address',
  5637. 'job_company.email'
  5638. )
  5639. ->first();
  5640. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5641. if (!empty($cityId)) {
  5642. if (isset($cityId[1]) && $cityId[1] != null) {
  5643. $city = District::where('id', $cityId[1])->first(['name']);
  5644. } else {
  5645. $city = District::where('id', $cityId[0])->first(['name']);
  5646. }
  5647. $result['city'] = $city['name'] ?? '';
  5648. }
  5649. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5650. if (is_array($addressId) && !empty($addressId)) {
  5651. $address = District::whereIn('id', $addressId)
  5652. ->orderBy('level', 'asc')
  5653. ->get(['name'])
  5654. ->pluck('name')
  5655. ->implode('');
  5656. // $job->address_name = $address ?? '';
  5657. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5658. }
  5659. if (empty($result)) {
  5660. return Result::error("招聘信息不存在", 0);
  5661. }
  5662. // return Result::success($job);
  5663. return Result::success($result);
  5664. }
  5665. /*
  5666. * 修改招聘信息
  5667. * */
  5668. public function upJobRecruiting(array $data): array
  5669. {
  5670. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5671. // return Result::success($job);
  5672. if (empty($job)) {
  5673. return Result::error("招聘信息不存在", 0);
  5674. }
  5675. $user = User::where('id', $data['user_id'])->first();
  5676. // return Result::success($user);
  5677. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5678. return Result::error("用户不存在", 0);
  5679. }
  5680. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5681. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5682. }
  5683. // 处理招聘关键词
  5684. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5685. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5686. } else {
  5687. Jieba::init(); // 初始化 jieba-php
  5688. Finalseg::init();
  5689. $segList = Jieba::cut($data['title']);
  5690. $segList1 = array_slice($segList, 0, 8);
  5691. $data['keyword'] = implode(',', $segList1);
  5692. }
  5693. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5694. $content = $data['description'];
  5695. // 去除 <style> 和 <script> 标签及其内容
  5696. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5697. // 去除所有 HTML 标签
  5698. $content = strip_tags($content);
  5699. // 去除 HTML 实体
  5700. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5701. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5702. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5703. // 去除多余空白
  5704. $content = preg_replace('/\s+/u', '', $content);
  5705. // 截取 100 个字符
  5706. $data['seo_description'] = mb_substr($content, 0, 100);
  5707. }
  5708. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5709. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5710. $data['catid'] = end($data['cat_arr_id']);
  5711. } else {
  5712. }
  5713. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5714. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5715. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5716. // 公司地址 管理员必填
  5717. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5718. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5719. // 管理员-企业相关信息
  5720. $company = [
  5721. // 'user_id' => $data['user_id']?? null,
  5722. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5723. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5724. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5725. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5726. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5727. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5728. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5729. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5730. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5731. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5732. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5733. ];
  5734. //去掉相关企业信息
  5735. $data = array_diff_key($data, array_flip(array_keys($company)));
  5736. $jobId = $data['id'];
  5737. $web = $data['website_id'];
  5738. $data['action_id'] = $data['user_id'];
  5739. unset($data['user_id']);
  5740. unset($data['user_type']);
  5741. unset($data['id']);
  5742. unset($data['website_id']);
  5743. // return Result::success($data);
  5744. Db::beginTransaction();
  5745. try {
  5746. // 管理员修改招聘信息
  5747. if ($user['type_id'] == 10000) {
  5748. $data['website_id'] = $web;
  5749. $company['website_id'] = $data['website_id'];
  5750. $data['status'] = 1;
  5751. } else {
  5752. $data['status'] = 0;
  5753. }
  5754. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5755. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5756. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5757. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5758. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5759. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5760. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5761. // return Result::success($job);
  5762. // Db::rollBack();
  5763. // return Result::success($company);
  5764. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5765. $this->sendMessage([
  5766. 'talk_type' => 500,
  5767. 'title' => $data['title'],
  5768. 'content' => '提交了审核',
  5769. 'messageType' => 10,
  5770. ]);
  5771. }
  5772. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5773. if (empty($result['job'])) {
  5774. Db::rollBack();
  5775. return Result::error("修改招聘信息失败");
  5776. }
  5777. // 管理员修改企业相关信息
  5778. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5779. if (empty($result['company'])) {
  5780. Db::rollBack();
  5781. return Result::error("修改企业相关信息失败");
  5782. }
  5783. Db::commit();
  5784. // return Result::success($result);
  5785. } catch (\Exception $e) {
  5786. Db::rollBack();
  5787. return Result::error($e->getMessage(), 0);
  5788. }
  5789. return Result::success($result);
  5790. }
  5791. /*
  5792. * 招聘信息删除
  5793. * */
  5794. public function delJobRecruiting(array $data): array
  5795. {
  5796. $user = User::where('id', $data['user_id'])->first();
  5797. if (empty($user)) {
  5798. return Result::error("用户不存在", 0);
  5799. }
  5800. $job = JobRecruiting::where('id', $data['id'])->first();
  5801. if (empty($job)) {
  5802. return Result::error("招聘信息不存在", 0);
  5803. }
  5804. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5805. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5806. }
  5807. Db::beginTransaction();
  5808. try {
  5809. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5810. if (empty($result['job'])) {
  5811. Db::rollBack();
  5812. return Result::error("删除招聘信息失败");
  5813. }
  5814. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5815. if (empty($result['company'])) {
  5816. Db::rollBack();
  5817. return Result::error("删除企业相关信息失败");
  5818. }
  5819. Db::commit();
  5820. } catch (\Exception $e) {
  5821. Db::rollBack();
  5822. return Result::error($e->getMessage(), 0);
  5823. }
  5824. return Result::success($result);
  5825. }
  5826. /*
  5827. * 获取公司信息
  5828. * */
  5829. public function getJobCompany(array $data): array
  5830. {
  5831. $user = User::where('user.id', $data['user_id'])
  5832. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5833. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5834. ->first();
  5835. // return Result::success($user);
  5836. if (empty($user)) {
  5837. return Result::error("用户不存在", 0);
  5838. }
  5839. if ($user['type_id'] == 3) {
  5840. $result = [
  5841. // 'id' => 0,
  5842. 'user_id' => $data['user_id'],
  5843. 'website_id' => $data['website_id'],
  5844. 'business_name' => $user['business_name'], // 企业名称
  5845. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5846. 'company_nature' => $user['company_nature'], // 公司性质
  5847. 'company_size' => $user['company_size'], // 公司规模
  5848. 'introduction' => $user['introduction'], // 公司简介
  5849. 'real_name' => $user['real_name'], // 企业联系人
  5850. 'mobile' => $user['mobile'], // 企业联系电话
  5851. 'company_url' => $user['company_url'], // 企业网址
  5852. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5853. 'address' => $user['address'], // 企业地址
  5854. 'email' => $user['email'], // 企业邮箱
  5855. ];
  5856. } else {
  5857. return Result::error("用户类型错误", 0);
  5858. }
  5859. if (empty($result)) {
  5860. return Result::error("公司信息不存在", 0);
  5861. }
  5862. return Result::success($result);
  5863. }
  5864. /*
  5865. * 修改公司信息
  5866. * */
  5867. public function upJobCompany(array $data): array
  5868. {
  5869. // return Result::success($data);
  5870. $user = User::where('user.id', $data['user_id'])
  5871. ->where('user.status', 1)
  5872. ->select('user.user_name', 'user.type_id')
  5873. ->first();
  5874. if (empty($user)) {
  5875. return Result::error("用户不存在", 0);
  5876. }
  5877. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5878. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5879. $company = [
  5880. 'business_name' => $data['business_name'], // 企业名称
  5881. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5882. 'company_nature' => $data['company_nature'], // 公司性质
  5883. 'company_size' => $data['company_size'], // 公司规模
  5884. 'introduction' => $data['introduction'], // 公司简介
  5885. // 'real_name' => $data['real_name'], // 企业联系人
  5886. 'company_url' => $data['company_url'], // 企业网址
  5887. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5888. 'address' => $data['address'], // 企业详细地址
  5889. // 'email' => $data['email'], // 企业邮箱
  5890. ];
  5891. if ($user['type_id'] == 3) {
  5892. Db::beginTransaction();
  5893. try {
  5894. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5895. 'business_name' => $data['business_name'], // 企业名称
  5896. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5897. 'company_nature' => $data['company_nature'], // 公司性质
  5898. 'company_size' => $data['company_size'], // 公司规模
  5899. 'introduction' => $data['introduction'], // 公司简介
  5900. // 'real_name' => $data['real_name'], // 企业联系人
  5901. 'company_url' => $data['company_url'], // 企业网址
  5902. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5903. 'address' => $data['address'], // 企业详细地址
  5904. ]);
  5905. if (empty($result['userinfo'])) {
  5906. Db::rollBack();
  5907. return Result::error('修改企业会员信息失败!');
  5908. }
  5909. $result['user'] = User::where('id', $data['user_id'])->update([
  5910. 'email' => $data['email'], // 企业邮箱
  5911. ]);
  5912. if (empty($result['user'])) {
  5913. Db::rollBack();
  5914. return Result::error('修改个人中心信息失败!');
  5915. }
  5916. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5917. if (!empty($job_company)) {
  5918. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5919. if (empty($result['job_company'])) {
  5920. Db::rollBack();
  5921. return Result::error('修改企业会员信息失败!');
  5922. }
  5923. }
  5924. Db::commit();
  5925. return Result::success($result);
  5926. } catch (\Exception $e) {
  5927. Db::rollBack();
  5928. return Result::error($e->getMessage(), 0);
  5929. }
  5930. } else {
  5931. return Result::error("用户类型错误", 0);
  5932. }
  5933. }
  5934. /*
  5935. * 获取省-市
  5936. * */
  5937. public function getJobRecruitingArea(array $data): array
  5938. {
  5939. if (isset($data['pid']) && $data['pid'] != null) {
  5940. $result = District::where('pid', $data['pid'])->get()->all();
  5941. } else {
  5942. $result = District::where('level', 1)->get()->all();
  5943. }
  5944. if (empty($result)) {
  5945. return Result::error("暂无此省市", 0);
  5946. }
  5947. return Result::success($result);
  5948. }
  5949. /*
  5950. * 获取行业分类
  5951. * */
  5952. public function getIndustry(array $data): array
  5953. {
  5954. $result = JobIndustry::get()->all();
  5955. if (empty($result)) {
  5956. return Result::error("暂无行业分类", 0);
  5957. }
  5958. return Result::success($result);
  5959. }
  5960. /*
  5961. * 获取职位
  5962. * */
  5963. public function getPositionList(array $data): array
  5964. {
  5965. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5966. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5967. } else {
  5968. $result = JobPosition::where('zwpid', 0)->get()->all();
  5969. }
  5970. if (empty($result)) {
  5971. return Result::error("暂无此职位", 0);
  5972. }
  5973. return Result::success($result);
  5974. }
  5975. /*
  5976. * 获取工作性质-菜单
  5977. * */
  5978. public function getJobNature(array $data): array
  5979. {
  5980. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5981. if (empty($result)) {
  5982. return Result::error("暂无工作性质", 0);
  5983. }
  5984. return Result::success($result);
  5985. }
  5986. /*
  5987. * 获取工作经验-菜单
  5988. * */
  5989. public function getExperience(array $data): array
  5990. {
  5991. $result = JobEnum::where('egroup', 'years')->get()->all();
  5992. if (empty($result)) {
  5993. return Result::error("暂无工作经验", 0);
  5994. }
  5995. return Result::success($result);
  5996. }
  5997. /*
  5998. * 获取学历-菜单
  5999. * */
  6000. public function getEducation(array $data): array
  6001. {
  6002. $result = JobEnum::where('egroup', 'education')->get()->all();
  6003. if (empty($result)) {
  6004. return Result::error("暂无学历", 0);
  6005. }
  6006. return Result::success($result);
  6007. }
  6008. /*
  6009. * 获取薪资-菜单
  6010. * */
  6011. public function getSalary(array $data): array
  6012. {
  6013. $result = JobEnum::where('egroup', 'income')->get()->all();
  6014. if (empty($result)) {
  6015. return Result::error("暂无薪资", 0);
  6016. }
  6017. return Result::success($result);
  6018. }
  6019. /*
  6020. * 获取语言-菜单
  6021. * */
  6022. public function getLanguage(array $data): array
  6023. {
  6024. $result = JobEnum::where('egroup', 'language')->get()->all();
  6025. if (empty($result)) {
  6026. return Result::error("暂无语言", 0);
  6027. }
  6028. return Result::success($result);
  6029. }
  6030. /*
  6031. * 获取掌握程度-菜单
  6032. * */
  6033. public function getLevel(array $data): array
  6034. {
  6035. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6036. if (empty($result)) {
  6037. return Result::error("暂无工作性质", 0);
  6038. }
  6039. return Result::success($result);
  6040. }
  6041. // 公司信息
  6042. /*
  6043. * 获取公司性质-菜单
  6044. * */
  6045. public function getCompanyNature(array $data): array
  6046. {
  6047. $result = JobNature::get()->all();
  6048. if (empty($result)) {
  6049. return Result::error("暂无公司性质", 0);
  6050. }
  6051. return Result::success($result);
  6052. }
  6053. /*
  6054. * 获取公司规模-菜单
  6055. * */
  6056. public function getCompanySize(array $data): array
  6057. {
  6058. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6059. if (empty($result)) {
  6060. return Result::error("暂无公司规模", 0);
  6061. }
  6062. return Result::success($result);
  6063. }
  6064. /*
  6065. * 招聘信息审核
  6066. * */
  6067. public function checkJobRecruiting(array $data): array
  6068. {
  6069. $user = User::where('id', $data['user_id'])->first();
  6070. if (empty($user)) {
  6071. return Result::error("用户不存在", 0);
  6072. }
  6073. $job = JobRecruiting::where('id', $data['id'])->first();
  6074. if (empty($job)) {
  6075. return Result::error("招聘信息不存在", 0);
  6076. }
  6077. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6078. if ($user['type_id'] != 10000) {
  6079. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6080. }
  6081. // 驳回原因
  6082. if ($data['status'] == 2) {
  6083. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6084. }
  6085. $data['action_id'] = $data['user_id'];
  6086. unset($data['user_id']);
  6087. if ($data['status'] == 1) {
  6088. $this->sendMessage([
  6089. 'talk_type' => 501,
  6090. 'title' => $job['title'],
  6091. 'content' => '审核通过',
  6092. 'messageType' => 10,
  6093. 'user_id' => $job['user_id'],
  6094. ]);
  6095. }
  6096. if ($data['status'] == 2) {
  6097. $this->sendMessage([
  6098. 'talk_type' => 501,
  6099. 'title' => $job['title'],
  6100. 'content' => '审核拒绝',
  6101. 'messageType' => 10,
  6102. 'user_id' => $job['user_id'],
  6103. ]);
  6104. }
  6105. if ($data['status'] == 0) {
  6106. $this->sendMessage([
  6107. 'talk_type' => 500,
  6108. 'title' => $job['title'],
  6109. 'content' => '提交了审核',
  6110. 'messageType' => 10,
  6111. ]);
  6112. }
  6113. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6114. if (empty($result)) {
  6115. return Result::error("审核失败", 0);
  6116. }
  6117. return Result::success($result);
  6118. }
  6119. public function myApplyList(array $data): array
  6120. {
  6121. var_dump($data, '------参数');
  6122. $user = User::where('id', $data['user_id'])->first();
  6123. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6124. return Result::error("用户不存在", 0);
  6125. }
  6126. // 1:个人会员 职场机会
  6127. if ($user['type_id'] == 1) {
  6128. $where['user_id'] = $user['id'];
  6129. }
  6130. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6131. $query->where('user_id', $user['id']);
  6132. })
  6133. ->pluck('recruit_id');
  6134. $where = [];
  6135. if (isset($data['salary']) && $data['salary'] != null) {
  6136. $where['job_recruiting.salary'] = $data['salary'];
  6137. }
  6138. if (isset($data['experience']) && $data['experience'] != null) {
  6139. $where['job_recruiting.experience'] = $data['experience'];
  6140. }
  6141. if (isset($data['business_name']) && $data['business_name'] != null) {
  6142. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6143. }
  6144. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6145. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6146. ->where($where);
  6147. // ->count();
  6148. $count = $query->count();
  6149. $query = clone $query;
  6150. $job = $query
  6151. ->leftJoin('job_enum as income_enum', function ($join) {
  6152. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6153. ->where('income_enum.egroup', 'income');
  6154. })
  6155. ->leftJoin('job_enum as years_enum', function ($join) {
  6156. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6157. ->where('years_enum.egroup', 'years');
  6158. })
  6159. // ->where($where)
  6160. ->orderBy('job_recruiting.updated_at', 'desc')
  6161. ->select(
  6162. 'job_recruiting.id',
  6163. 'job_recruiting.title',
  6164. 'job_company.business_name',
  6165. 'income_enum.evalue as salary_evalue',
  6166. 'income_enum.ename as salary_ename',
  6167. 'years_enum.evalue as experience_evalue',
  6168. 'years_enum.ename as experience_ename',
  6169. 'job_recruiting.updated_at'
  6170. )
  6171. ->offset(($data['page'] - 1) * $data['pageSize'])
  6172. ->limit($data['pageSize'])
  6173. ->get()
  6174. ->all();
  6175. if (empty($job)) {
  6176. return Result::error("暂无招聘信息", 0);
  6177. }
  6178. $result = [
  6179. 'row' => $job,
  6180. 'count' => $count,
  6181. ];
  6182. return Result::success($result);
  6183. }
  6184. public function readJobApply(array $data): array
  6185. {
  6186. $result = JobApply::where('id', $data['id'])->first();
  6187. if (empty($result)) {
  6188. return Result::error("查询失败", 0);
  6189. }
  6190. $result = JobApply::where('id', $data['id'])->update([
  6191. 'status' => 2,
  6192. ]);
  6193. return Result::success($result);
  6194. }
  6195. /*
  6196. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6197. * */
  6198. public function getRecruitingList(array $data): array
  6199. {
  6200. $user = User::where('id', $data['user_id'])->first();
  6201. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6202. return Result::error("用户不存在", 0);
  6203. }
  6204. // 1:个人会员 职场机会
  6205. if ($user['type_id'] == 1) {
  6206. $where['user_id'] = $user['id'];
  6207. }
  6208. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6209. $query->where('receiver_id', $user['id']);
  6210. })
  6211. ->pluck('recruit_id');
  6212. // return Result::success($recruitingId);
  6213. $where = [];
  6214. if (isset($data['salary']) && $data['salary'] != null) {
  6215. $where['job_recruiting.salary'] = $data['salary'];
  6216. }
  6217. if (isset($data['experience']) && $data['experience'] != null) {
  6218. $where['job_recruiting.experience'] = $data['experience'];
  6219. }
  6220. if (isset($data['business_name']) && $data['business_name'] != null) {
  6221. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6222. }
  6223. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6224. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6225. ->where($where);
  6226. // ->count();
  6227. $count = $query->count();
  6228. $query = clone $query;
  6229. $job = $query
  6230. ->leftJoin('job_enum as income_enum', function ($join) {
  6231. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6232. ->where('income_enum.egroup', 'income');
  6233. })
  6234. ->leftJoin('job_enum as years_enum', function ($join) {
  6235. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6236. ->where('years_enum.egroup', 'years');
  6237. })
  6238. // ->where($where)
  6239. ->orderBy('job_recruiting.updated_at', 'desc')
  6240. ->select(
  6241. 'job_recruiting.id',
  6242. 'job_recruiting.title',
  6243. 'job_company.business_name',
  6244. 'income_enum.evalue as salary_evalue',
  6245. 'income_enum.ename as salary_ename',
  6246. 'years_enum.evalue as experience_evalue',
  6247. 'years_enum.ename as experience_ename',
  6248. 'job_recruiting.updated_at'
  6249. )
  6250. ->offset(($data['page'] - 1) * $data['pageSize'])
  6251. ->limit($data['pageSize'])
  6252. ->get()
  6253. ->all();
  6254. if (empty($job)) {
  6255. return Result::error("暂无招聘信息", 0);
  6256. }
  6257. $result = [
  6258. 'row' => $job,
  6259. 'count' => $count,
  6260. ];
  6261. return Result::success($result);
  6262. }
  6263. /*
  6264. * 获取企业会员-招聘信息列表
  6265. * */
  6266. public function getRecruitingInfo(array $data): array
  6267. {
  6268. $user = User::where('id', $data['user_id'])->first();
  6269. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6270. return Result::error("用户不存在", 0);
  6271. }
  6272. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6273. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6274. ->select(
  6275. 'job_recruiting.*',
  6276. 'job_company.business_name',
  6277. 'job_company.company_hy_id',
  6278. 'job_company.company_size',
  6279. 'job_company.company_nature',
  6280. 'job_company.introduction',
  6281. 'job_company.real_name',
  6282. 'job_company.mobile',
  6283. 'job_company.company_url',
  6284. 'job_company.address_arr_id',
  6285. 'job_company.address',
  6286. 'job_company.email'
  6287. )
  6288. ->get();
  6289. if (empty($recruiting)) {
  6290. return Result::error("暂无招聘信息", 0);
  6291. }
  6292. return Result::success($recruiting);
  6293. }
  6294. /*
  6295. * 获取企业会员-我的沟通
  6296. * */
  6297. public function getJobResumeList(array $data): array
  6298. {
  6299. $user = User::where('id', $data['user_id'])->first();
  6300. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6301. return Result::error("用户不存在", 0);
  6302. }
  6303. $where = [];
  6304. if (isset($data['salary']) && $data['salary'] != null) {
  6305. $where['job_hunting.salary'] = $data['salary'];
  6306. }
  6307. if (isset($data['user_name']) && $data['user_name'] != null) {
  6308. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6309. }
  6310. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6311. $query->where('job_resume.user_id', $user['id']);
  6312. })
  6313. ->when(!empty($where), function ($query) use ($where) {
  6314. $query->where($where);
  6315. })
  6316. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6317. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6318. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6319. ->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');
  6320. $count = $job->count();
  6321. if ($count == 0) {
  6322. return Result::error("暂无沟通记录", 0);
  6323. }
  6324. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6325. ->offset(($data['page'] - 1) * $data['pageSize'])
  6326. ->limit($data['pageSize'])
  6327. ->get();
  6328. if (empty($jobs)) {
  6329. return Result::error("暂无沟通记录", 0);
  6330. }
  6331. $result['row'] = $this->processJob($jobs, '');
  6332. $result['count'] = $count;
  6333. return Result::success($result);
  6334. }
  6335. public function readJobResume(array $data): array
  6336. {
  6337. $result = JobResume::where('id', $data['id'])->first();
  6338. if (empty($result)) {
  6339. return Result::error("查询失败", 0);
  6340. }
  6341. $result = JobResume::where('id', $data['id'])->update([
  6342. 'status' => 2,
  6343. ]);
  6344. return Result::success($result);
  6345. }
  6346. // 20250306 招聘
  6347. //20250422 书刊音像
  6348. public function addBook(array $data): array
  6349. {
  6350. $user_id = $data['user_id'] ?? 0;
  6351. $type_id = $data['type_id'] ?? 0;
  6352. // $website_id = $data['website_id'] ?? 0;
  6353. // unset($data['user_id']);
  6354. unset($data['type_id']);
  6355. // unset($data['website_id']);
  6356. //处理数组
  6357. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6358. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6359. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6360. if ($data['img_url'] == '') {
  6361. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6362. preg_match_all($reg, $data['detail'], $matches);
  6363. if (isset($matches[1][0])) {
  6364. //截取varchar240
  6365. $data['img_url'] = substr($matches[1][0], 0, 240);
  6366. }
  6367. }
  6368. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6369. //提取标题+内容中的关键词
  6370. $data['keyword'] = $data['title'];
  6371. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6372. Jieba::init(); // 初始化 jieba-php
  6373. Finalseg::init();
  6374. $segList = Jieba::cut($data['keyword']);
  6375. $segList1 = array_slice($segList, 0, 8);
  6376. $data['keyword'] = implode(',', $segList1);
  6377. }
  6378. if ($data['description'] == '') {
  6379. //提取内容中的描述
  6380. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6381. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6382. }
  6383. var_dump($data, '--');
  6384. if ($data['status'] == 1) {
  6385. $this->sendMessage([
  6386. 'talk_type' => 400,
  6387. 'title' => $data['title'],
  6388. 'content' => '提交了审核',
  6389. 'messageType' => 7,
  6390. ]);
  6391. }
  6392. $result = Book::insertGetId($data);
  6393. if (empty($result)) {
  6394. return Result::error("添加失败", 0);
  6395. }
  6396. return Result::success($result);
  6397. }
  6398. public function getBookList(array $data): array
  6399. {
  6400. $where = [];
  6401. if (!empty($data["title"])) {
  6402. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6403. }
  6404. if (!empty($data['website_name'])) {
  6405. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6406. }
  6407. if (!empty($data['status'])) {
  6408. $where[] = ['book.status', '=', $data['status']];
  6409. }
  6410. $user_id = $data['user_id'];
  6411. $type_id = $data['type_id'];
  6412. // $type_id = 4;
  6413. var_dump($type_id, '------1--------');
  6414. if ($type_id != 10000) {
  6415. $where[] = ['book.user_id', '=', $user_id];
  6416. }
  6417. var_dump(!empty($data['status1']), '=-===1');
  6418. $result = Book::where($where)
  6419. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6420. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6421. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6422. ->when(isset($data['status1']), function ($query) use ($data) {
  6423. $query->whereIn('book.status', [1, 3]);
  6424. })
  6425. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6426. ->orderBy("updated_at", "desc")
  6427. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6428. if (empty($result)) {
  6429. return Result::error("暂无数据", 0);
  6430. }
  6431. // 取出数据
  6432. $rows = $result->items();
  6433. $count = $result->total();
  6434. $responseData = [
  6435. 'rows' => $rows,
  6436. 'count' => $count,
  6437. ];
  6438. return Result::success($responseData);
  6439. }
  6440. public function deleteBook(array $data): array
  6441. {
  6442. $result = Book::where('id', $data['id'])->delete();
  6443. if (empty($result)) {
  6444. return Result::error("删除失败", 0);
  6445. }
  6446. return Result::success($result);
  6447. }
  6448. public function updateBook(array $data): array
  6449. {
  6450. // $user_id = $data['user_id'] ?? 0;
  6451. $type_id = $data['type_id'] ?? 0;
  6452. // $website_id = $data['website_id'] ?? 0;
  6453. unset($data['user_id']);
  6454. unset($data['type_id']);
  6455. // unset($data['website_id']);
  6456. //处理数组
  6457. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6458. if ($data['img_url'] == '') {
  6459. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6460. preg_match_all($reg, $data['detail'], $matches);
  6461. if (isset($matches[1][0])) {
  6462. //截取varchar240
  6463. $data['img_url'] = substr($matches[1][0], 0, 240);
  6464. }
  6465. }
  6466. if ($data['keyword'] == '') {
  6467. //提取标题+内容中的关键词
  6468. $data['keyword'] = $data['title'];
  6469. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6470. Jieba::init(); // 初始化 jieba-php
  6471. Finalseg::init();
  6472. $segList = Jieba::cut($data['keyword']);
  6473. $segList1 = array_slice($segList, 0, 8);
  6474. $data['keyword'] = implode(',', $segList1);
  6475. }
  6476. if ($data['description'] == '') {
  6477. //提取内容中的描述
  6478. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6479. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6480. }
  6481. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6482. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6483. if ($data['status'] == 1) {
  6484. $this->sendMessage([
  6485. 'talk_type' => 400,
  6486. 'title' => $data['title'],
  6487. 'content' => '提交了审核',
  6488. 'messageType' => 7,
  6489. ]);
  6490. }
  6491. $result = Book::where("id", $data["id"])->update($data);
  6492. if (empty($result)) {
  6493. return Result::error("更新失败", 0);
  6494. }
  6495. return Result::success($result);
  6496. }
  6497. public function getBookInfo(array $data): array
  6498. {
  6499. $result = Book::where("id", $data["id"])->first();
  6500. if (empty($result)) {
  6501. return Result::error("获取失败", 0);
  6502. }
  6503. return Result::success($result);
  6504. }
  6505. public function updateBookStatus(array $data): array
  6506. {
  6507. //审核
  6508. unset($data['user_id']);
  6509. $bookInfo = Book::where("id", $data["id"])->first();
  6510. var_dump($bookInfo, '----');
  6511. if ($data['status'] == 2) {
  6512. $this->sendMessage([
  6513. 'talk_type' => 401,
  6514. 'title' => $bookInfo['title'],
  6515. 'content' => '审核通过',
  6516. 'messageType' => 7,
  6517. 'user_id' => $bookInfo['user_id'],
  6518. ]);
  6519. }
  6520. if ($data['status'] == 3) {
  6521. $this->sendMessage([
  6522. 'talk_type' => 401,
  6523. 'title' => $bookInfo['title'],
  6524. 'content' => '审核拒绝',
  6525. 'messageType' => 7,
  6526. 'user_id' => $bookInfo['user_id'],
  6527. ]);
  6528. }
  6529. if ($data['status'] == 1) {
  6530. $this->sendMessage([
  6531. 'talk_type' => 400,
  6532. 'title' => $bookInfo['title'],
  6533. 'content' => '提交了审核',
  6534. 'messageType' => 7,
  6535. // 'user_id'=>$bookInfo['user_id'],
  6536. ]);
  6537. }
  6538. $result = Book::where("id", $data["id"])->update($data);
  6539. if (empty($result)) {
  6540. return Result::error("更新失败", 0);
  6541. }
  6542. return Result::success($result);
  6543. }
  6544. //20250422 书刊音像
  6545. /**
  6546. * 贴身宝贝
  6547. * @param array $data
  6548. * @return array
  6549. */
  6550. public function getWebsiteTsbb(array $data): array
  6551. {
  6552. $month = $data['month'] ?? date('m');
  6553. $day = $data['day'] ?? date('d');
  6554. // 使用缓存键
  6555. $cacheKey = "tsbb_data_{$month}_{$day}";
  6556. // 尝试从缓存获取数据
  6557. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6558. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6559. if ($cachedData = $cache->get($cacheKey)) {
  6560. return Result::success(unserialize($cachedData));
  6561. }
  6562. //查询老黄历
  6563. try {
  6564. $date = date('Y-m-d');
  6565. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6566. // 使用 curl 替代 file_get_contents
  6567. $ch = curl_init();
  6568. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6569. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6570. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6571. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6572. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6573. 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');
  6574. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6575. 'Accept: application/json',
  6576. 'Content-Type: application/json',
  6577. 'Referer: https://www.36jxs.com/'
  6578. ]);
  6579. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6580. curl_setopt($ch, CURLOPT_ENCODING, '');
  6581. $almanacResponse = curl_exec($ch);
  6582. var_dump("====:", $almanacResponse);
  6583. if (curl_errno($ch)) {
  6584. var_dump('Curl error:', curl_error($ch));
  6585. throw new \Exception('Curl error: ' . curl_error($ch));
  6586. }
  6587. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6588. curl_close($ch);
  6589. if ($almanacResponse === false) {
  6590. throw new \Exception('Failed to fetch almanac data');
  6591. }
  6592. $almanacData = json_decode($almanacResponse, true);
  6593. if (json_last_error() !== JSON_ERROR_NONE) {
  6594. throw new \Exception('Failed to parse almanac data');
  6595. }
  6596. $almanacInfo = $almanacData['data'] ?? [];
  6597. } catch (\Exception $e) {
  6598. var_dump('Exception:', $e->getMessage());
  6599. $almanacInfo = [];
  6600. }
  6601. // 获取历史上的今天数据
  6602. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6603. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6604. ->orderBy('year', 'asc')
  6605. ->select("title", "id", "year", DB::raw('1 as type'))
  6606. ->limit(16)
  6607. ->get();
  6608. // 获取节日数据 - 从今天开始获取未来4条
  6609. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6610. ->orderBy('showtime', 'asc')
  6611. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6612. ->limit(16)
  6613. ->get();
  6614. //说文解字
  6615. $chartacterList = Character::orderBy('updated_at', 'desc')
  6616. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6617. ->limit(6)
  6618. ->get();
  6619. //谜语沙龙
  6620. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6621. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6622. ->limit(4)
  6623. ->get();
  6624. //成语欣赏
  6625. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6626. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6627. ->limit(32)
  6628. ->get();
  6629. //名联赏析
  6630. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6631. ->select("id", "first", "second", DB::raw('6 as type'))
  6632. ->limit(6)
  6633. ->get();
  6634. // 获取分类文章数据
  6635. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6636. ->pluck('category_id')
  6637. ->toArray();
  6638. $articlesList = [];
  6639. foreach ($categoryIds as $catid) {
  6640. // 先查有图片的
  6641. $withImg = DB::table('article')
  6642. ->where('status', 1)
  6643. ->where('catid', $catid)
  6644. ->whereNotNull('imgurl')
  6645. ->where('imgurl', '!=', '')
  6646. ->orderBy('updated_at', 'desc')
  6647. ->limit(6)
  6648. ->get();
  6649. $count = $withImg->count();
  6650. if ($count < 6) {
  6651. // 不足6条再查无图片的补足
  6652. $withoutImg = DB::table('article')
  6653. ->where('status', 1)
  6654. ->where('catid', $catid)
  6655. ->where(function ($q) {
  6656. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6657. })
  6658. ->orderBy('updated_at', 'desc')
  6659. ->limit(6 - $count)
  6660. ->get();
  6661. $articles = $withImg->concat($withoutImg);
  6662. } else {
  6663. $articles = $withImg;
  6664. }
  6665. // 组装
  6666. $category = \App\Model\Category::find($catid);
  6667. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6668. $articlesList[] = [
  6669. 'category_name' => $category ? $category->name : '',
  6670. 'catid' => $catid,
  6671. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6672. 'type' => 100,
  6673. 'list' => $articles->map(function ($item) {
  6674. return [
  6675. 'id' => $item->id,
  6676. 'title' => $item->title,
  6677. 'imgurl' => $item->imgurl,
  6678. 'created_at' => $item->created_at
  6679. ];
  6680. })->values()
  6681. ];
  6682. }
  6683. $result = [
  6684. 'almanac' => $almanacInfo,
  6685. 'historyTodayList' => [
  6686. 'category_name' => '历史上的今天',
  6687. 'list' => $historyTodayList,
  6688. 'type' => 1
  6689. ],
  6690. 'festivalList' => [
  6691. 'category_name' => '节日预告',
  6692. 'list' => $festivalList,
  6693. 'type' => 2
  6694. ],
  6695. 'chartacterList' => [
  6696. 'category_name' => '说文解字',
  6697. 'list' => $chartacterList,
  6698. 'type' => 3
  6699. ],
  6700. 'coupletList' => [
  6701. 'category_name' => '名联赏析',
  6702. 'list' => $coupletList,
  6703. 'type' => 6
  6704. ],
  6705. 'riddletList' => [
  6706. 'category_name' => '谜语沙龙',
  6707. 'list' => $riddletList,
  6708. 'type' => 4
  6709. ],
  6710. 'idiomList' => [
  6711. 'category_name' => '成语欣赏',
  6712. 'list' => $idiomList,
  6713. 'type' => 5
  6714. ],
  6715. 'articlesList' => $articlesList
  6716. ];
  6717. // 缓存结果,设置1小时过期
  6718. $cache->set($cacheKey, serialize($result), 3600);
  6719. return Result::success($result);
  6720. }
  6721. /**
  6722. * 获取资讯列表
  6723. */
  6724. public function getWebsiteTsbbList(array $data): array
  6725. {
  6726. $page = $data['page'] ?? 1;
  6727. $pageSize = $data['pageSize'] ?? 10;
  6728. // 如果没有传入月份和日期,则使用今天的日期
  6729. $month = $data['month'] ?? date('m');
  6730. $day = $data['day'] ?? date('d');
  6731. $total = 0;
  6732. $result = [];
  6733. $data['type'] = intval($data['type']);
  6734. var_dump("接收参数:", $data);
  6735. switch ($data['type']) {
  6736. case 1:
  6737. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6738. // 当前月份之后的数据
  6739. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6740. // 或者当前月份且日期大于等于当前日期的数据
  6741. ->orWhere(function ($q) use ($month, $day) {
  6742. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6743. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6744. });
  6745. })
  6746. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6747. $total = $query->count();
  6748. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6749. ->offset(($page - 1) * $pageSize)
  6750. ->limit($pageSize)
  6751. ->get();
  6752. break;
  6753. case 2:
  6754. $query = Festival::where(function ($q) use ($month, $day) {
  6755. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6756. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6757. ->orWhere(function ($q) use ($month, $day) {
  6758. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6759. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6760. });
  6761. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6762. $total = $query->count();
  6763. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6764. ->offset(($page - 1) * $pageSize)
  6765. ->limit($pageSize)
  6766. ->get();
  6767. break;
  6768. case 3:
  6769. $query = Character::orderBy("updated_at", "desc");
  6770. $total = $query->count();
  6771. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6772. ->offset(($page - 1) * $pageSize)
  6773. ->limit($pageSize)
  6774. ->get();
  6775. break;
  6776. case 4:
  6777. $query = Riddle::orderBy("updated_at", "desc");
  6778. $total = $query->count();
  6779. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6780. ->offset(($page - 1) * $pageSize)
  6781. ->limit($pageSize)
  6782. ->get();
  6783. break;
  6784. case 5:
  6785. $query = Idiom::orderBy("updated_at", "desc");
  6786. $total = $query->count();
  6787. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6788. ->offset(($page - 1) * $pageSize)
  6789. ->limit($pageSize)
  6790. ->get();
  6791. break;
  6792. case 6:
  6793. $query = Couplet::orderBy("updated_at", "desc");
  6794. $total = $query->count();
  6795. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6796. ->offset(($page - 1) * $pageSize)
  6797. ->limit($pageSize)
  6798. ->get();
  6799. break;
  6800. default:
  6801. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6802. $total = $query->count();
  6803. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6804. ->offset(($page - 1) * $pageSize)
  6805. ->limit($pageSize)
  6806. ->get();
  6807. }
  6808. return Result::success([
  6809. 'list' => $result,
  6810. 'total' => $total,
  6811. 'page' => (int)$page,
  6812. 'pageSize' => (int)$pageSize,
  6813. 'month' => $month,
  6814. 'day' => $day
  6815. ]);
  6816. }
  6817. /**
  6818. * 1:历史上的今天
  6819. * 2:节日
  6820. * 3:文章
  6821. *
  6822. * 资讯详情信息
  6823. */
  6824. public function getWebsiteTsbbDetail(array $data): array
  6825. {
  6826. $data['type'] = intval($data['type']);
  6827. switch ($data['type']) {
  6828. case 1:
  6829. $result = HistoryToday::where("id", $data['id'])->first();
  6830. break;
  6831. case 2:
  6832. $result = Festival::where("id", $data['id'])->first();
  6833. break;
  6834. case 3:
  6835. $result = Character::where("id", $data['id'])->first();
  6836. break;
  6837. case 4:
  6838. $result = Riddle::where("id", $data['id'])->first();
  6839. break;
  6840. case 5:
  6841. $result = Idiom::where("id", $data['id'])->first();
  6842. break;
  6843. case 6:
  6844. $result = Couplet::where("id", $data['id'])->first();
  6845. break;
  6846. default:
  6847. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6848. break;
  6849. }
  6850. return Result::success($result);
  6851. }
  6852. /**
  6853. * 农网导航首页数据
  6854. */
  6855. public function getWebsiteNwHomeList(array $data): array
  6856. {
  6857. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6858. ->pluck('category_id')
  6859. ->toArray();
  6860. // 使用子查询优化
  6861. $articlesList = DB::table('article')
  6862. ->select([
  6863. 'article.id',
  6864. 'article.title',
  6865. 'article.imgurl',
  6866. 'article.created_at',
  6867. 'category.name as category_name',
  6868. 'category.id as category_id',
  6869. 'website_category.aLIas_pinyin as pinyin',
  6870. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6871. DB::raw('100 as type')
  6872. ])
  6873. ->join('category', 'article.catid', '=', 'category.id')
  6874. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6875. ->leftJoin('website_category as parent_wc', function ($join) {
  6876. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6877. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6878. })
  6879. ->where('website_category.website_id', $data['website_id'])
  6880. ->where('article.status', 1)
  6881. ->whereIn('category.id', $categoryIds)
  6882. ->orderBy('article.created_at', 'desc')
  6883. ->get()
  6884. ->groupBy('category_id')
  6885. ->map(function ($group) {
  6886. // 确保第一条数据有图片
  6887. $firstWithImage = $group->first(function ($item) {
  6888. return !empty($item->imgurl);
  6889. });
  6890. if ($firstWithImage) {
  6891. // 如果有带图片的文章,将其放在第一位
  6892. $group = $group->filter(function ($item) use ($firstWithImage) {
  6893. return $item->id !== $firstWithImage->id;
  6894. })->prepend($firstWithImage);
  6895. }
  6896. return [
  6897. 'category_name' => $group->first()->category_name,
  6898. 'catid' => $group->first()->category_id,
  6899. 'pinyin' => $group->first()->pinyin,
  6900. 'parent_pinyin' => $group->first()->parent_pinyin,
  6901. 'list' => $group->take(4)->map(function ($item) {
  6902. return [
  6903. 'id' => $item->id,
  6904. 'title' => $item->title,
  6905. ];
  6906. })->values()
  6907. ];
  6908. })
  6909. ->values()
  6910. ->toArray();
  6911. return Result::success($articlesList);
  6912. }
  6913. /**
  6914. * 企业管理
  6915. * @param array $data
  6916. * @return array
  6917. */
  6918. public function getCompanyList(array $data): array
  6919. {
  6920. // return Result::success($data);
  6921. $where = [];
  6922. $user = User::where('id', $data['user_id'])->first();
  6923. if (empty($user)) {
  6924. return Result::error('用户不存在!');
  6925. }
  6926. if ($user['type_id'] != 10000) {
  6927. $where['user_id'] = $data['user_id'];
  6928. }
  6929. if (isset($data['title']) && !empty($data['title'])) {
  6930. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6931. }
  6932. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6933. array_push($where, ['website.id', $data['website_id']]);
  6934. }
  6935. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6936. if ($data['ischeck'] == 1) {
  6937. if (isset($data['status']) && $data['status'] != '') {
  6938. array_push($where, ['company.status', $data['status']]);
  6939. $query = Company::where($where);
  6940. } else {
  6941. $query = Company::whereIn('company.status', [0, 2]);
  6942. }
  6943. } else {
  6944. $query = Company::where('company.status', 1);
  6945. }
  6946. }
  6947. $result = $query->where($where)
  6948. ->leftJoin('website_category', function ($query) {
  6949. $query->on('website_category.category_id', '=', 'company.category_id')
  6950. ->on('website_category.website_id', '=', 'company.website_id');
  6951. })
  6952. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6953. ->select(
  6954. 'company.id',
  6955. 'company.title',
  6956. 'company.website_id',
  6957. 'company.category_id',
  6958. 'website.website_name',
  6959. 'website_category.alias as category_name',
  6960. 'company.status',
  6961. 'company.updated_at',
  6962. 'company.user_id'
  6963. )
  6964. ->orderBy('company.updated_at', 'desc')
  6965. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6966. if ($result->isEmpty()) {
  6967. return Result::error("暂无企业", 0);
  6968. }
  6969. return Result::success($result);
  6970. }
  6971. /**
  6972. * 添加企业
  6973. * @param array $data
  6974. * @return array
  6975. */
  6976. public function addCompany(array $data): array
  6977. {
  6978. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6979. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6980. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6981. $data['cat_arr_id'] = json_encode($car_arr_id);
  6982. } else {
  6983. $data['cat_arr_id'] = '';
  6984. }
  6985. if ($data['imgurl'] == '') {
  6986. //content中提取图片第一个图,正则提取
  6987. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6988. preg_match_all($reg, $data['content'], $matches);
  6989. if (isset($matches[1][0])) {
  6990. //截取varchar240
  6991. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6992. }
  6993. }
  6994. if ($data['keyword'] == '') {
  6995. //提取标题+内容中的关键词
  6996. $data['keyword'] = $data['title'];
  6997. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6998. Jieba::init(); // 初始化 jieba-php
  6999. Finalseg::init();
  7000. $segList = Jieba::cut($data['keyword']);
  7001. $segList1 = array_slice($segList, 0, 8);
  7002. $data['keyword'] = implode(',', $segList1);
  7003. }
  7004. if ($data['introduce'] == '' || empty($data['introduce'])) {
  7005. //提取内容中的描述
  7006. $content = $data['content'];
  7007. // 去除 <style> 和 <script> 标签及其内容
  7008. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7009. // 去除所有 HTML 标签
  7010. $content = strip_tags($content);
  7011. // 去除 HTML 实体
  7012. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7013. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7014. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7015. // 去除多余空白
  7016. $content = preg_replace('/\s+/u', '', $content);
  7017. // 截取 100 个字符
  7018. $data['introduce'] = mb_substr($content, 0, 100);
  7019. }
  7020. $user = User::where('id', $data['user_id'])->first();
  7021. if (empty($user)) {
  7022. return Result::error('用户不存在!');
  7023. }
  7024. if ($user['type_id'] == 10000) {
  7025. $data['status'] = 1;
  7026. }
  7027. if (isset($data['level']) && $data['level'] != null) {
  7028. $data['level'] = intval($data['level']);
  7029. } else {
  7030. $data['level'] = null;
  7031. }
  7032. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7033. $this->sendMessage([
  7034. 'talk_type' => 900,
  7035. 'title' => $data['title'],
  7036. 'content' => '提交了审核',
  7037. 'messageType' => 8,
  7038. ]);
  7039. }
  7040. $result = Company::insertGetId($data);
  7041. if ($result) {
  7042. return Result::success($result);
  7043. } else {
  7044. return Result::error('添加失败');
  7045. }
  7046. }
  7047. /**
  7048. * 更新企业
  7049. * @param array $data
  7050. * @return array
  7051. */
  7052. public function upCompany(array $data): array
  7053. {
  7054. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7055. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7056. $data['cat_arr_id'] = json_encode($car_arr_id);
  7057. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7058. } else {
  7059. $data['cat_arr_id'] = '';
  7060. }
  7061. if ($data['imgurl'] == '') {
  7062. //content中提取图片第一个图,正则提取
  7063. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7064. preg_match_all($reg, $data['content'], $matches);
  7065. if (isset($matches[1][0])) {
  7066. //截取varchar
  7067. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7068. }
  7069. }
  7070. if ($data['keyword'] == '') {
  7071. //提取标题+内容中的关键词
  7072. $data['keyword'] = $data['title'];
  7073. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7074. Jieba::init(); // 初始化 jieba-php
  7075. Finalseg::init();
  7076. $segList = Jieba::cut($data['keyword']);
  7077. $segList1 = array_slice($segList, 0, 8);
  7078. $data['keyword'] = implode(',', $segList1);
  7079. }
  7080. if ($data['introduce'] == '') {
  7081. //提取内容中的描述
  7082. $content = $data['content'];
  7083. // 去除 <style> 和 <script> 标签及其内容
  7084. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7085. // 去除所有 HTML 标签
  7086. $content = strip_tags($content);
  7087. // 去除 HTML 实体
  7088. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7089. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7090. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7091. // 去除多余空白
  7092. $content = preg_replace('/\s+/u', '', $content);
  7093. // 截取 100 个字符
  7094. $data['introduce'] = mb_substr($content, 0, 100);
  7095. }
  7096. if (isset($data['level']) && $data['level'] != null) {
  7097. $data['level'] = intval($data['level']);
  7098. } else {
  7099. $data['level'] = null;
  7100. }
  7101. $user = User::where('id', $data['user_id'])->first();
  7102. if (empty($user)) {
  7103. return Result::error('用户不存在!');
  7104. }
  7105. if ($user['type_id'] == 10000) {
  7106. $data['status'] = 1;
  7107. } else {
  7108. $data['status'] = 0;
  7109. }
  7110. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7111. $this->sendMessage([
  7112. 'talk_type' => 900,
  7113. 'title' => $data['title'],
  7114. 'content' => '提交了审核',
  7115. 'messageType' => 8,
  7116. ]);
  7117. }
  7118. $result = Company::where('id', $data['id'])->update($data);
  7119. if ($result) {
  7120. return Result::success($result);
  7121. } else {
  7122. return Result::error('修改失败');
  7123. }
  7124. }
  7125. /**
  7126. * 删除企业
  7127. * @param array $data
  7128. * @return array
  7129. */
  7130. public function delCompany(array $data): array
  7131. {
  7132. $result = Company::where('id', $data['id'])->delete();
  7133. if ($result) {
  7134. return Result::success($result);
  7135. } else {
  7136. return Result::error('删除失败');
  7137. }
  7138. }
  7139. /**
  7140. * 审核企业
  7141. * @param array $data
  7142. * @return array
  7143. */
  7144. public function checkCompany(array $data): array
  7145. {
  7146. $user = User::where('id', $data['user_id'])->first();
  7147. if (empty($user)) {
  7148. return Result::error('用户不存在!');
  7149. }
  7150. $company = Company::where('id', $data['id'])->first();
  7151. if (empty($company)) {
  7152. return Result::error('企业不存在!');
  7153. }
  7154. // 状态:0:未审核 1:已审核 2:已拒绝
  7155. if ($data['status'] == 2 || $data['status'] == '2') {
  7156. $this->sendMessage([
  7157. 'talk_type' => 901,
  7158. 'title' => $company['title'],
  7159. 'content' => '审核拒绝',
  7160. 'messageType' => 8,
  7161. 'user_id' => $company['user_id'],
  7162. ]);
  7163. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7164. } else {
  7165. if ($data['status'] == 1) {
  7166. $this->sendMessage([
  7167. 'talk_type' => 901,
  7168. 'title' => $company['title'],
  7169. 'content' => '审核通过',
  7170. 'messageType' => 8,
  7171. 'user_id' => $company['user_id'],
  7172. ]);
  7173. } else if ($data['status'] == 0) {
  7174. $this->sendMessage([
  7175. 'talk_type' => 900,
  7176. 'title' => $company['title'],
  7177. 'content' => '提交了审核',
  7178. 'messageType' => 8,
  7179. ]);
  7180. }
  7181. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7182. }
  7183. if (empty($result)) {
  7184. return Result::error('审核失败!');
  7185. } else {
  7186. return Result::success($result);
  7187. }
  7188. }
  7189. /**
  7190. * 获取企业信息
  7191. * @param array $data
  7192. * @return array
  7193. */
  7194. public function getCompanyInfo(array $data): array
  7195. {
  7196. $result = Company::where('id', $data['id'])->first();
  7197. $city_arr = json_decode($result['city_arr_id']);
  7198. $result['city_name'] = District::whereIn('id', $city_arr)
  7199. ->pluck('name')
  7200. ->implode('-');
  7201. if (empty($result)) {
  7202. return Result::error('企业不存在!');
  7203. } else {
  7204. return Result::success($result);
  7205. }
  7206. }
  7207. /**
  7208. * @param array $data
  7209. * @return array
  7210. */
  7211. public function getWebsiteCompany(array $data): array
  7212. {
  7213. $categorys = json_decode($data['id'], true);
  7214. $category_arr = $this->processArticlePro($data['website_id']);
  7215. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7216. $catiall = $category_arr['catiall'];
  7217. $categoryIds = $category_arr['categoryIds'];
  7218. // return Result::success($category_arr);
  7219. foreach ($categorys as $key => $value) {
  7220. if (array_key_exists('level', $value)) {
  7221. $parts = explode(',', $value['level']);
  7222. $level = $parts[0] ?? null;
  7223. $imgnum = $parts[1] ?? null;
  7224. $textnum = $parts[2] ?? null;
  7225. if (!empty($textnum) && $textnum > 0) {
  7226. $text_num = Company::where('level', $level)
  7227. ->whereIn('category_id', $categoryIds)
  7228. ->where('status', 1)
  7229. ->select(
  7230. 'company.id',
  7231. 'company.title',
  7232. 'company.description',
  7233. 'company.updated_at',
  7234. 'company.category_id',
  7235. 'company.cat_arr_id'
  7236. )
  7237. ->orderBy('updated_at', 'desc')
  7238. ->limit($textnum)
  7239. ->get()->all();
  7240. }
  7241. if (!empty($imgnum) && $imgnum > 0) {
  7242. $img_num = Company::where('level', $level)
  7243. ->whereIn('category_id', $categoryIds)
  7244. ->where('status', 1)
  7245. ->where('imgurl', '!=', '')
  7246. ->whereNotNull('imgurl')
  7247. ->select(
  7248. 'company.id',
  7249. 'company.title',
  7250. 'company.description',
  7251. 'company.updated_at',
  7252. 'company.imgurl as imgs',
  7253. 'company.category_id',
  7254. 'company.cat_arr_id'
  7255. )
  7256. ->orderBy('updated_at', 'desc')
  7257. ->limit($imgnum)
  7258. ->get()->all();
  7259. }
  7260. }
  7261. if (array_key_exists('id', $value)) {
  7262. $parts = explode(',', $value['id']);
  7263. $category_id = $parts[0] ?? null;
  7264. $imgnum = $parts[1] ?? null;
  7265. $textnum = $parts[2] ?? null;
  7266. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7267. if (!empty($textnum) && $textnum > 0) {
  7268. $text_num = Company::whereIn('category_id', $category_arr)
  7269. // ->where('website_id', $data['website_id'])
  7270. ->where('status', 1)
  7271. ->select(
  7272. 'company.id',
  7273. 'company.title',
  7274. 'company.description',
  7275. 'company.updated_at',
  7276. 'company.category_id',
  7277. 'company.cat_arr_id'
  7278. )
  7279. ->orderBy('updated_at', 'desc')
  7280. ->limit($textnum)
  7281. ->get()->all();
  7282. }
  7283. if (!empty($imgnum) && $imgnum > 0) {
  7284. $img_num = Company::whereIn('category_id', $category_arr)
  7285. // ->where('website_id', $data['website_id'])
  7286. ->where('status', 1)
  7287. ->where('imgurl', '!=', '')
  7288. ->whereNotNull('imgurl')
  7289. ->select(
  7290. 'company.id',
  7291. 'company.title',
  7292. 'company.description',
  7293. 'company.updated_at',
  7294. 'company.imgurl as imgs',
  7295. 'company.category_id',
  7296. 'company.cat_arr_id'
  7297. )
  7298. ->orderBy('updated_at', 'desc')
  7299. ->limit($imgnum)
  7300. ->get()->all();
  7301. }
  7302. }
  7303. if (!empty($text_num)) {
  7304. foreach ($text_num as $k => $v) {
  7305. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7306. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7307. }
  7308. }
  7309. if (!empty($img_num)) {
  7310. foreach ($img_num as $k => $v) {
  7311. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7312. $imgurl = json_decode($v['imgs'], true);
  7313. if (!empty($imgurl)) {
  7314. $img_num[$k]->imgurl = $imgurl[0];
  7315. }
  7316. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7317. }
  7318. }
  7319. $company[$key]['img_num'] = $img_num ?? [];
  7320. $company[$key]['text_num'] = $text_num ?? [];
  7321. }
  7322. if (empty($company)) {
  7323. return Result::error("暂无相关企业信息", 0);
  7324. }
  7325. return Result::success($company);
  7326. }
  7327. /**
  7328. * @param array $data
  7329. * @return array
  7330. */
  7331. public function getWebsiteCompanyList(array $data): array
  7332. {
  7333. $where['website_id'] = $data['website_id'];
  7334. $where['status'] = 1;
  7335. $categoryIds = [];
  7336. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7337. $category_id = $data['category_id'];
  7338. }
  7339. $category_arr = $this->processArticlePro($data['website_id']);
  7340. $categoryIds = $category_arr['categoryIds'];
  7341. // return Result::success($cat_1st_arr);
  7342. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7343. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7344. })
  7345. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7346. $query->whereIn('category_id', $categoryIds);
  7347. })
  7348. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7349. $query->where('category_id', $category_id);
  7350. })
  7351. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7352. ->orderBy('updated_at', 'desc')
  7353. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7354. if (empty($company)) {
  7355. return Result::error("暂无相关公司信息", 0);
  7356. }
  7357. $result = [
  7358. 'count' => $company->total(),
  7359. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7360. ];
  7361. return Result::success($result);
  7362. }
  7363. /**
  7364. * 获取项目列表
  7365. * @param array $data
  7366. * @return array
  7367. */
  7368. public function getProjectList(array $data): array
  7369. {
  7370. $where = [];
  7371. $user = User::where('id', $data['user_id'])->first();
  7372. if (empty($user)) {
  7373. return Result::error('用户不存在!');
  7374. }
  7375. if ($user->type_id != 10000) {
  7376. array_push($where, ['project.user_id', $data['user_id']]);
  7377. }
  7378. $query = Project::query();
  7379. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7380. array_push($where, ['project.website_id', $data['website_id']]);
  7381. }
  7382. if (isset($data['title']) && !empty($data['title'])) {
  7383. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7384. }
  7385. if ($data['status'] != 3) {
  7386. array_push($where, ['project.status', $data['status']]);
  7387. }
  7388. $query = Project::where($where)
  7389. ->when($data['status'] == 3, function ($query) {
  7390. $query->whereIn('project.status', [0, 2]);
  7391. });
  7392. $count = $query->clone()
  7393. ->count();
  7394. $rows = $query->clone()
  7395. ->leftJoin('website', 'project.website_id', 'website.id')
  7396. ->leftJoin('website_category', function ($join) {
  7397. $join->on('project.website_id', '=', 'website_category.website_id')
  7398. ->on('project.category_id', '=', 'website_category.category_id');
  7399. })
  7400. ->select(
  7401. 'project.id',
  7402. 'project.title',
  7403. 'project.updated_at',
  7404. 'project.status',
  7405. 'website.website_name',
  7406. 'website_category.alias as category_name',
  7407. 'project.website_id',
  7408. 'project.user_id'
  7409. )
  7410. ->orderBy('project.updated_at', 'desc')
  7411. ->offset(($data['page'] - 1) * $data['pageSize'])
  7412. ->limit($data['pageSize'])
  7413. ->get();
  7414. if ($rows->isEmpty()) {
  7415. return Result::error("暂无相关项目信息", 0);
  7416. }
  7417. $result = [
  7418. 'count' => $count,
  7419. 'rows' => $rows,
  7420. ];
  7421. return Result::success($result);
  7422. }
  7423. /**
  7424. * 添加项目
  7425. * @param array $data
  7426. * @return array
  7427. */
  7428. public function addProject(array $data): array
  7429. {
  7430. $user = User::where('id', $data['user_id'])->first();
  7431. if (empty($user)) {
  7432. return Result::error("暂无相关用户信息", 0);
  7433. }
  7434. if ($user->type_id == 10000) {
  7435. $data['status'] = 1;
  7436. } else {
  7437. $data['status'] = 0;
  7438. }
  7439. if ($data['keyword'] == '') {
  7440. //提取标题+内容中的关键词
  7441. $data['keyword'] = $data['title'];
  7442. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7443. Jieba::init(); // 初始化 jieba-php
  7444. Finalseg::init();
  7445. $segList = Jieba::cut($data['keyword']);
  7446. $segList1 = array_slice($segList, 0, 8);
  7447. $data['keyword'] = implode(',', $segList1);
  7448. }
  7449. if ($data['description'] == '') {
  7450. //提取内容中的描述
  7451. // var_dump(11111);
  7452. //提取内容中的描述
  7453. $content = $data['introduce'];
  7454. // 去除 <style> 和 <script> 标签及其内容
  7455. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7456. // 去除所有 HTML 标签
  7457. $content = strip_tags($content);
  7458. // 去除 HTML 实体
  7459. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7460. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7461. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7462. // 去除多余空白
  7463. $content = preg_replace('/\s+/u', '', $content);
  7464. // 截取 100 个字符
  7465. $data['description'] = mb_substr($content, 0, 100);
  7466. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7467. }
  7468. if ($data['status'] == 0) {
  7469. $this->sendMessage([
  7470. 'talk_type' => 1000,
  7471. 'title' => $data['title'],
  7472. 'content' => '提交了审核',
  7473. 'messageType' => 9,
  7474. ]);
  7475. }
  7476. $project = Project::insertGetId($data);
  7477. if (empty($project)) {
  7478. return Result::error("暂无相关项目信息", 0);
  7479. }
  7480. return Result::success($project);
  7481. }
  7482. /**
  7483. * 更新项目
  7484. * @param array $data
  7485. * @return array
  7486. */
  7487. public function upProject(array $data): array
  7488. {
  7489. $project = Project::where('id', $data['id'])->first();
  7490. if (empty($project)) {
  7491. return Result::error("暂无相关项目信息", 0);
  7492. }
  7493. $id = $data['id'];
  7494. unset($data['id']);
  7495. $user = User::where('id', $data['user_id'])->first();
  7496. if (empty($user)) {
  7497. return Result::error("暂无相关用户信息", 0);
  7498. }
  7499. if ($user->type_id == 10000) {
  7500. $data['status'] = 1;
  7501. } else {
  7502. $data['status'] = 0;
  7503. }
  7504. unset($data['user_id']);
  7505. if ($data['keyword'] == '') {
  7506. //提取标题+内容中的关键词
  7507. $data['keyword'] = $data['title'];
  7508. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7509. Jieba::init(); // 初始化 jieba-php
  7510. Finalseg::init();
  7511. $segList = Jieba::cut($data['keyword']);
  7512. $segList1 = array_slice($segList, 0, 8);
  7513. $data['keyword'] = implode(',', $segList1);
  7514. }
  7515. if ($data['description'] == '') {
  7516. //提取内容中的描述
  7517. // var_dump(11111);
  7518. //提取内容中的描述
  7519. $content = $data['introduce'];
  7520. // 去除 <style> 和 <script> 标签及其内容
  7521. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7522. // 去除所有 HTML 标签
  7523. $content = strip_tags($content);
  7524. // 去除 HTML 实体
  7525. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7526. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7527. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7528. // 去除多余空白
  7529. $content = preg_replace('/\s+/u', '', $content);
  7530. // 截取 100 个字符
  7531. $data['description'] = mb_substr($content, 0, 100);
  7532. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7533. }
  7534. if ($data['status'] == 0) {
  7535. $this->sendMessage([
  7536. 'talk_type' => 1000,
  7537. 'title' => $data['title'],
  7538. 'content' => '提交了审核',
  7539. 'messageType' => 9,
  7540. ]);
  7541. }
  7542. $result = Project::where('id', $id)->update($data);
  7543. if (empty($result)) {
  7544. return Result::error("更新失败", 0);
  7545. }
  7546. return Result::success($result);
  7547. }
  7548. /**
  7549. * 删除项目
  7550. * @param array $data
  7551. * @return array
  7552. */
  7553. public function delProject(array $data): array
  7554. {
  7555. $user = User::where('id', $data['user_id'])->first();
  7556. if (empty($user)) {
  7557. return Result::error("暂无相关用户信息", 0);
  7558. }
  7559. $project = Project::where('id', $data['id'])->first();
  7560. if (empty($project)) {
  7561. return Result::error("暂无相关项目信息", 0);
  7562. }
  7563. $result = Project::where('id', $data['id'])->delete();
  7564. if (empty($result)) {
  7565. return Result::error("删除失败", 0);
  7566. }
  7567. return Result::success($result);
  7568. }
  7569. /**
  7570. * 审核项目
  7571. * @param array $data
  7572. * @return array
  7573. */
  7574. public function checkProject(array $data): array
  7575. {
  7576. $user = User::where('id', $data['user_id'])->first();
  7577. if (empty($user)) {
  7578. return Result::error("暂无相关用户信息", 0);
  7579. }
  7580. // 0:未审核; 1:已审核; 2:已拒绝;
  7581. if ($user->type_id != 10000) {
  7582. if ($data['status'] == 1 || $data['status'] == 2) {
  7583. return Result::error("此用户权限不足", 0);
  7584. }
  7585. }
  7586. $project = Project::where('id', $data['id'])->first();
  7587. if (empty($project)) {
  7588. return Result::error("暂无相关项目信息", 0);
  7589. }
  7590. if ($data['status'] == 2) {
  7591. $this->sendMessage([
  7592. 'talk_type' => 1001,
  7593. 'title' => $project['title'],
  7594. 'content' => '审核拒绝',
  7595. 'messageType' => 9,
  7596. 'user_id' => $project['user_id'],
  7597. ]);
  7598. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7599. } else {
  7600. if ($data['status'] == 1) {
  7601. $this->sendMessage([
  7602. 'talk_type' => 1001,
  7603. 'title' => $project['title'],
  7604. 'content' => '审核通过',
  7605. 'messageType' => 9,
  7606. 'user_id' => $project['user_id'],
  7607. ]);
  7608. } else if ($data['status'] == 0) {
  7609. $this->sendMessage([
  7610. 'talk_type' => 1000,
  7611. 'title' => $project['title'],
  7612. 'content' => '提交了审核',
  7613. 'messageType' => 9,
  7614. ]);
  7615. }
  7616. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7617. }
  7618. if (empty($result)) {
  7619. return Result::error("审核失败", 0);
  7620. }
  7621. return Result::success($result);
  7622. }
  7623. /**
  7624. * 获取项目详情
  7625. * @param array $data
  7626. * @return array
  7627. */
  7628. public function getProjectInfo(array $data): array
  7629. {
  7630. $project = Project::where('id', $data['id'])->first();
  7631. if (empty($project)) {
  7632. return Result::error("暂无相关项目信息", 0);
  7633. }
  7634. return Result::success($project);
  7635. }
  7636. public function getWebsiteCompanyInfo(array $data): array
  7637. {
  7638. $company = Company::where('id', $data['id'])
  7639. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7640. ->where('status', 1)
  7641. // ->where('website_id', $data['website_id'])
  7642. ->select('company.*', 'job_industry.hyname as hy_name')
  7643. ->first();
  7644. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7645. $jobnature_id = $company['jobnature_id'] ?? null;
  7646. if ($jobnature_id !== null) {
  7647. switch ($jobnature_id) {
  7648. case 0:
  7649. $company->jobnature_name = '市场监督';
  7650. break;
  7651. case 1:
  7652. $company->jobnature_name = '信访纪检';
  7653. break;
  7654. case 2:
  7655. $company->jobnature_name = '公检法司';
  7656. break;
  7657. case 3:
  7658. $company->jobnature_name = '高关注机构';
  7659. break;
  7660. default:
  7661. $company->jobnature_name = '';
  7662. break;
  7663. }
  7664. } else {
  7665. $company->jobnature_name = '';
  7666. }
  7667. $city_arr = $company->city_arr_id;
  7668. if (!empty($city_arr)) {
  7669. $city_arr = json_decode($city_arr, true);
  7670. $cityNames = District::whereIn('id', $city_arr)
  7671. ->pluck('name')
  7672. ->implode('-');
  7673. $company->city_name = $cityNames;
  7674. } else {
  7675. $company->city_name = '';
  7676. }
  7677. if (empty($company)) {
  7678. return Result::error("暂无相关公司信息", 0);
  7679. }
  7680. return Result::success($company);
  7681. }
  7682. public function getMSG(array $data): array
  7683. {
  7684. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7685. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7686. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7687. $result = [];
  7688. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7689. //最近的5篇已审的文章
  7690. $apply_articale = Article::where('status', 1)
  7691. ->where('admin_user_id', $user_id)
  7692. ->orderBy('updated_at', 'desc')
  7693. // ->limit(5)
  7694. ->get();
  7695. //获取5条用户的已审核商品
  7696. $good = Good::where('status', 2)
  7697. ->where('user_id', $user_id)
  7698. ->orderBy('updated_at', 'desc')
  7699. // ->limit(5)
  7700. ->get();
  7701. //获取5条用户待审核的公告
  7702. $notice = Notice::where('status', 2)
  7703. ->where('user_id', $user_id)
  7704. ->orderBy('updated_at', 'desc')
  7705. ->limit(5)->get();
  7706. //获取5条用户的待审核投诉
  7707. $complaint = Complaint::where('status', 2)
  7708. ->where('user_id', $user_id)
  7709. ->orderBy('updated_at', 'desc')
  7710. // ->limit(5)
  7711. ->get();
  7712. //获取5条用户的book
  7713. $book = Book::where('status', 2)
  7714. ->where('user_id', $user_id)
  7715. ->orderBy('updated_at', 'desc')
  7716. // ->limit(5)
  7717. ->get();
  7718. //获取5条用户的求职
  7719. //获取5条用户的求职 1
  7720. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7721. ->where('job_hunting.user_id', $user_id)
  7722. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7723. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7724. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7725. ->orderBy('updated_at', 'desc')
  7726. // ->limit(5)
  7727. ->get();
  7728. //获取5条用户的求职 2
  7729. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7730. ->where('job_recruiting.user_id', $user_id)
  7731. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7732. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7733. ->select('job_recruiting.*', '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. //人才库 1
  7738. $job_apply = JobApply::where('job_apply.status', 1)
  7739. ->where('job_apply.receiver_id', $user_id)
  7740. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7741. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7742. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7743. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7744. ->select('job_recruiting', 'job_recruiting.', '', '')
  7745. ->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')
  7746. ->orderBy('updated_at', 'desc')
  7747. // ->limit(5)
  7748. ->get();
  7749. // 职场机会 2
  7750. $job_resume = JobResume::where('job_resume.status', 1)
  7751. ->where('job_resume.receiver_id', $user_id)
  7752. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7753. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7754. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7755. ->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')
  7756. ->orderBy('updated_at', 'desc')
  7757. // ->limit(5)
  7758. ->get();
  7759. //获取5条用户待处理的投诉
  7760. $complaint_deal = Complaint::where('status', 2)
  7761. ->where('deal', 1)
  7762. ->whereJsonContains('re_user_ids', $user_id)
  7763. ->orderBy('updated_at', 'desc')
  7764. // ->limit(5)
  7765. ->get();
  7766. //获取 被通知者未读信息
  7767. $notice_unread = Notice::where('status', 2)
  7768. ->whereJsonContains('re_user_ids', $user_id)
  7769. //未读消息
  7770. ->where(function ($query) use ($user_id) {
  7771. $query->whereJsonDoesntContain('read_id', $user_id)
  7772. ->orWhereNull('read_id');
  7773. })
  7774. ->orderBy('updated_at', 'desc')
  7775. ->get();
  7776. $complaint_unread = Complaint::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. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7786. $complany = Company::where('status', 1)
  7787. ->where('user_id', $user_id)
  7788. ->orderBy('updated_at', 'desc')
  7789. // ->limit(5)
  7790. ->get();
  7791. //获取5条单聊未读聊天消息
  7792. // $chat = ChatRecords::where('is_read', 0)
  7793. // ->where('user_id', $user_id)
  7794. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7795. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7796. // ->where('action', 'recieved')
  7797. // ->where('talk_type', 1)
  7798. // ->orderBy('created_at', 'desc')
  7799. // // ->limit(5)
  7800. // ->get();
  7801. //获取5条未读群聊信息
  7802. // $chat_group = ChatRecords::where('is_read', 0)
  7803. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7804. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7805. // ->where('user_id', $user_id)
  7806. // ->where('talk_type', 2)
  7807. // ->orderBy('created_at', 'desc')
  7808. // // ->limit(5)
  7809. // ->get();
  7810. //获取5条用户的待审核项目
  7811. $project = Project::where('status', 1)
  7812. ->where('user_id', $user_id)
  7813. ->orderBy('updated_at', 'desc')
  7814. // ->limit(5)
  7815. ->get();
  7816. // count($chat) + count($chat_group) +
  7817. $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)
  7818. + count($complany)
  7819. + count($project)
  7820. + count($notice_unread)
  7821. + count($complaint_unread)
  7822. // + count($chat) + count($chat_group)
  7823. ;
  7824. $result = [
  7825. 'apply_articale' => $apply_articale,
  7826. // 'chat' => $chat,
  7827. // 'chat_group' => $chat_group,
  7828. 'good' => $good,
  7829. 'notice' => $notice,
  7830. 'complaint' => $complaint,
  7831. 'book' => $book,
  7832. 'job_hunting' => $job_hunting,
  7833. 'job_recruiting' => $job_recruiting,
  7834. 'job_apply' => $job_apply,
  7835. 'job_resume' => $job_resume,
  7836. 'complaint_deal' => $complaint_deal,
  7837. 'complany' => $complany,
  7838. 'project' => $project,
  7839. 'notice_unread' => $notice_unread,
  7840. 'complaint_unread' => $complaint_unread,
  7841. 'count' => $count,
  7842. ];
  7843. } elseif ($type_id == 12) {
  7844. //最近的5篇已审的文章
  7845. $apply_articale = Article::where('status', 1)
  7846. ->where('admin_user_id', $user_id)
  7847. ->limit(5)->get();
  7848. //获取5条单聊未读聊天消息
  7849. $chat = ChatRecords::where('is_read', 0)
  7850. ->where('user_id', $user_id)
  7851. ->where('talk_type', 1)
  7852. ->orderBy('created_at', 'desc')
  7853. ->limit(5)->get();
  7854. //获取5条未读群聊信息
  7855. $chat_group = ChatRecords::where('is_read', 0)
  7856. ->where('user_id', $user_id)
  7857. ->where('talk_type', 2)
  7858. ->orderBy('created_at', 'desc')
  7859. ->limit(5)->get();
  7860. //获取5条用户的已审核商品
  7861. $good = Good::where('status', 2)
  7862. ->where('user_id', $user_id)
  7863. ->orderBy('updated_at', 'desc')
  7864. ->limit(5)->get();
  7865. //获取5条用户的book
  7866. $book = Book::where('status', 2)
  7867. ->where('user_id', $user_id)
  7868. ->orderBy('updated_at', 'desc')
  7869. ->limit(5)->get();
  7870. //获取5条用户的求职
  7871. //获取5条用户的求职 1
  7872. //count($chat) + count($chat_group)
  7873. $count = count($apply_articale) + count($good);
  7874. $result = [
  7875. 'apply_articale' => $apply_articale,
  7876. 'chat' => $chat,
  7877. 'chat_group' => $chat_group,
  7878. 'good' => $good,
  7879. 'book' => $book,
  7880. 'count' => $count,
  7881. ];
  7882. } elseif ($type_id == 13) {
  7883. //最近的5篇已审的文章
  7884. $apply_articale = Article::where('status', 1)
  7885. ->where('admin_user_id', $user_id)
  7886. ->limit(5)->get();
  7887. //获取5条单聊未读聊天消息
  7888. $chat = ChatRecords::where('is_read', 0)
  7889. ->where('user_id', $user_id)
  7890. ->where('talk_type', 1)
  7891. ->orderBy('created_at', 'desc')
  7892. ->limit(5)->get();
  7893. //获取5条未读群聊信息
  7894. $chat_group = ChatRecords::where('is_read', 0)
  7895. ->where('user_id', $user_id)
  7896. ->where('talk_type', 2)
  7897. ->orderBy('created_at', 'desc')
  7898. ->limit(5)->get();
  7899. //获取5条用户的已审核商品
  7900. $good = Good::where('status', 2)
  7901. ->where('user_id', $user_id)
  7902. ->orderBy('updated_at', 'desc')
  7903. ->limit(5)->get();
  7904. //count($chat) + count($chat_group) +
  7905. $count = count($apply_articale) + count($good);
  7906. $result = [
  7907. 'apply_articale' => $apply_articale,
  7908. 'chat' => $chat,
  7909. 'chat_group' => $chat_group,
  7910. 'good' => $good,
  7911. 'count' => $count,
  7912. ];
  7913. } elseif ($type_id == 14) {
  7914. //最近的5篇已审的文章
  7915. $apply_articale = Article::where('status', 1)
  7916. ->where('admin_user_id', $user_id)
  7917. // ->limit(5)
  7918. ->get();
  7919. //获取5条用户的已审核商品
  7920. $good = Good::where('status', 2)
  7921. ->where('user_id', $user_id)
  7922. ->orderBy('updated_at', 'desc')
  7923. // ->limit(5)
  7924. ->get();
  7925. $count = count($apply_articale) + count($good);
  7926. $result = [
  7927. 'apply_articale' => $apply_articale,
  7928. 'chat' => '',
  7929. 'chat_group' => '',
  7930. 'good' => $good,
  7931. 'count' => $count,
  7932. ];
  7933. } elseif ($type_id == 10000) {
  7934. //获取未审核的5篇文章
  7935. $apply_articale = Article::where('status', 0)
  7936. ->orderBy('updated_at', 'desc')
  7937. // ->limit(5)
  7938. ->get();
  7939. //获取5条单聊未读聊天消息
  7940. //获取5条单聊未读聊天消息
  7941. // $chat = ChatRecords::where('is_read', 0)
  7942. // ->where('user_id', $user_id)
  7943. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7944. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7945. // ->where('action', 'recieved')
  7946. // ->where('talk_type', 1)
  7947. // ->orderBy('created_at', 'desc')
  7948. // // ->limit(5)
  7949. // ->get();
  7950. // //获取5条未读群聊信息
  7951. // $chat_group = ChatRecords::where('is_read', 0)
  7952. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7953. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7954. // ->where('user_id', $user_id)
  7955. // ->where('talk_type', 2)
  7956. // ->orderBy('created_at', 'desc')
  7957. // // ->limit(5)
  7958. // ->get();
  7959. //获取5条用户的已审核商品
  7960. $good = Good::where('status', 1)
  7961. // ->where('user_id', $user_id)
  7962. ->orderBy('updated_at', 'desc')
  7963. // ->limit(5)
  7964. ->get();
  7965. //获取5条用户待审核的公告
  7966. $notice = Notice::where('status', 1)
  7967. ->orderBy('updated_at', 'desc')
  7968. // ->limit(5)
  7969. ->get();
  7970. //获取5条用户的待审核投诉
  7971. $complaint = Complaint::where('status', 1)
  7972. ->orderBy('updated_at', 'desc')
  7973. // ->limit(5)
  7974. ->get();
  7975. //获取5条用户的book
  7976. $book = Book::where('status', 1)
  7977. ->orderBy('updated_at', 'desc')
  7978. // ->limit(5)
  7979. ->get();
  7980. //获取5条用户的求职 1
  7981. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7982. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7983. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7984. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7985. ->orderBy('updated_at', 'desc')
  7986. // ->limit(5)
  7987. ->get();
  7988. //获取5条用户的求职 2
  7989. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7990. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7991. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7992. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7993. ->orderBy('updated_at', 'desc')
  7994. // ->limit(5)
  7995. ->get();
  7996. //人才库 1
  7997. $job_apply = JobApply::where('job_apply.status', 1)
  7998. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7999. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  8000. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  8001. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  8002. ->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')
  8003. ->orderBy('updated_at', 'desc')
  8004. // ->limit(5)
  8005. ->get();
  8006. // 职场机会 2
  8007. $job_resume = JobResume::where('job_resume.status', 1)
  8008. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  8009. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  8010. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  8011. ->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')
  8012. ->orderBy('updated_at', 'desc')
  8013. // ->limit(5)
  8014. ->get();
  8015. //待审核数据com pro
  8016. $complany = Company::where('status', 0)
  8017. ->orderBy('updated_at', 'desc')
  8018. // ->limit(5)
  8019. ->get();
  8020. $project = Project::where('status', 0)
  8021. ->orderBy('updated_at', 'desc')
  8022. // ->limit(5)
  8023. ->get();
  8024. $count =
  8025. // count($chat) +
  8026. // count($chat_group) +
  8027. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8028. // + count($job_apply)
  8029. // + count($job_resume)
  8030. + count($complany)
  8031. + count($project);
  8032. $result = [
  8033. 'apply_articale' => $apply_articale,
  8034. // 'chat' => $chat,
  8035. // 'chat_group' => $chat_group,
  8036. 'good' => $good,
  8037. 'notice' => $notice,
  8038. 'complaint' => $complaint,
  8039. 'book' => $book,
  8040. 'job_hunting' => $job_hunting,
  8041. 'job_recruiting' => $job_recruiting,
  8042. // 'job_apply' => $job_apply,
  8043. // 'job_resume' => $job_resume,
  8044. 'complany' => $complany,
  8045. 'project' => $project,
  8046. 'count' => $count,
  8047. ];
  8048. } elseif ($type_id == 20000) {
  8049. }
  8050. var_dump($type_id, '-----------------test---------');
  8051. return Result::success($result);
  8052. }
  8053. /**
  8054. * @param array $data
  8055. * @return array
  8056. */
  8057. public function getWebsiteProject(array $data): array
  8058. {
  8059. $categorys = json_decode($data['id'], true);
  8060. if (!empty($categorys)) {
  8061. $category_arr = $this->processArticlePro($data['website_id']);
  8062. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8063. $catiall = $category_arr['catiall'];
  8064. // return Result::success($catiall);
  8065. foreach ($categorys as $key => $val) {
  8066. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8067. $level = explode(',', $val['level'])[0];
  8068. $imgnum = explode(',', $val['level'])[1] ?? null;
  8069. $textnum = explode(',', $val['level'])[2] ?? null;
  8070. if ($level == 1) {
  8071. if (!empty($textnum) && $textnum > 0) {
  8072. $text_num = Project::where('level', $level)
  8073. ->where('website_id', $data['website_id'])
  8074. ->where('status', 1)
  8075. ->select(
  8076. 'project.id',
  8077. 'project.title',
  8078. 'project.description',
  8079. 'project.updated_at',
  8080. 'project.category_id',
  8081. 'project.cat_arr_id'
  8082. )
  8083. ->orderBy('updated_at', 'desc')
  8084. ->limit($textnum)
  8085. ->get()->all();
  8086. }
  8087. if (!empty($imgnum) && $imgnum > 0) {
  8088. $img_num = Project::where('level', $level)
  8089. ->where('website_id', $data['website_id'])
  8090. ->where('status', 1)
  8091. ->where('imgurl', '!=', '')
  8092. ->whereNotNull('imgurl')
  8093. ->select(
  8094. 'project.id',
  8095. 'project.title',
  8096. 'project.description',
  8097. 'project.updated_at',
  8098. 'project.imgurl as imgs',
  8099. 'project.category_id',
  8100. 'project.cat_arr_id'
  8101. )
  8102. ->orderBy('updated_at', 'desc')
  8103. ->limit($imgnum)
  8104. ->get()->all();
  8105. }
  8106. } else {
  8107. if (!empty($textnum) && $textnum > 0) {
  8108. $text_num = Project::where('website_id', $data['website_id'])
  8109. ->where('status', 1)
  8110. ->select(
  8111. 'project.id',
  8112. 'project.title',
  8113. 'project.description',
  8114. 'project.updated_at',
  8115. 'project.category_id',
  8116. 'project.cat_arr_id',
  8117. 'project.website_id',
  8118. 'project.updated_at',
  8119. 'project.created_at'
  8120. )
  8121. ->orderBy('updated_at', 'desc')
  8122. ->limit($textnum)
  8123. ->get()->all();
  8124. }
  8125. if (!empty($imgnum) && $imgnum > 0) {
  8126. $img_num = Project::where('website_id', $data['website_id'])
  8127. ->where('status', 1)
  8128. ->where('imgurl', '!=', '')
  8129. ->whereNotNull('imgurl')
  8130. ->select(
  8131. 'project.id',
  8132. 'project.title',
  8133. 'project.description',
  8134. 'project.updated_at',
  8135. 'project.imgurl as imgs',
  8136. 'project.category_id',
  8137. 'project.cat_arr_id'
  8138. )
  8139. ->orderBy('updated_at', 'desc')
  8140. ->limit($imgnum)
  8141. ->get()->all();
  8142. }
  8143. }
  8144. }
  8145. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8146. $category_ids = explode(',', $val['id'])[0];
  8147. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8148. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8149. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8150. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8151. $text_num = Project::whereIn('category_id', $category_arr)
  8152. ->where('website_id', $data['website_id'])
  8153. ->where('status', 1)
  8154. ->select(
  8155. 'project.id',
  8156. 'project.title',
  8157. 'project.description',
  8158. 'project.updated_at',
  8159. 'project.category_id',
  8160. 'project.cat_arr_id'
  8161. )
  8162. ->orderBy('updated_at', 'desc')
  8163. ->limit($cat_textnum)
  8164. ->get()->all();
  8165. }
  8166. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8167. $img_num = Project::whereIn('category_id', $category_arr)
  8168. ->where('website_id', $data['website_id'])
  8169. ->where('status', 1)
  8170. ->where('imgurl', '!=', '')
  8171. ->whereNotNull('imgurl')
  8172. ->select(
  8173. 'project.id',
  8174. 'project.title',
  8175. 'project.description',
  8176. 'project.updated_at',
  8177. 'project.imgurl as imgs',
  8178. 'project.category_id',
  8179. 'project.cat_arr_id'
  8180. )
  8181. ->orderBy('updated_at', 'desc')
  8182. ->limit($cat_imgnum)
  8183. ->get()->all();
  8184. }
  8185. }
  8186. if (!empty($img_num)) {
  8187. foreach ($img_num as $k => $v) {
  8188. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8189. $imgurl = json_decode($v['imgs'], true);
  8190. if (!empty($imgurl)) {
  8191. $img_num[$k]->imgurl = $imgurl[0];
  8192. }
  8193. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8194. }
  8195. }
  8196. if (!empty($text_num)) {
  8197. foreach ($text_num as $k => $v) {
  8198. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8199. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8200. }
  8201. }
  8202. $project[$key]['img_num'] = $img_num ?? [];
  8203. $project[$key]['text_num'] = $text_num ?? [];
  8204. }
  8205. }
  8206. if (empty($project)) {
  8207. return Result::error("暂无相关项目信息", 0);
  8208. }
  8209. return Result::success($project);
  8210. }
  8211. /**
  8212. * @param array $data
  8213. * @return array
  8214. */
  8215. public function getWebsiteProjectInfo(array $data): array
  8216. {
  8217. $project = Project::where('id', $data['id'])
  8218. ->where('status', 1)
  8219. ->where('website_id', $data['website_id'])
  8220. ->select('project.*')
  8221. ->first();
  8222. if (empty($project)) {
  8223. return Result::error("暂无相关项目信息", 0);
  8224. }
  8225. return Result::success($project);
  8226. }
  8227. /**
  8228. * @param array $data
  8229. * @return array
  8230. */
  8231. public function getWebsiteProjectList(array $data): array
  8232. {
  8233. $where = [];
  8234. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8235. $where['category_id'] = $data['category_id'];
  8236. }
  8237. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8238. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8239. }
  8240. $query = Project::where($where)
  8241. ->where('status', 1)
  8242. ->where('website_id', $data['website_id'])
  8243. ->select(
  8244. 'project.id',
  8245. 'project.title',
  8246. 'project.description',
  8247. 'project.imgurl as imgs',
  8248. 'project.category_id',
  8249. 'project.cat_arr_id'
  8250. )
  8251. ->orderBy('updated_at', 'desc');
  8252. $count = $query->count();
  8253. $project = $query->clone()
  8254. ->offset(($data['page'] - 1) * $data['pageSize'])
  8255. ->limit($data['pageSize'])
  8256. ->get()->all();
  8257. if (empty($project)) {
  8258. return Result::error("暂无相关项目信息", 0);
  8259. }
  8260. $categorys = $this->processArticlePro($data['website_id']);
  8261. $catiall = $categorys['catiall'];
  8262. foreach ($project as $key => $val) {
  8263. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8264. if (!empty($val['imgs'])) {
  8265. $imgurl = json_decode($val['imgs'], true);
  8266. if (!empty($imgurl)) {
  8267. $project[$key]->imgurl = $imgurl[0];
  8268. }
  8269. } else {
  8270. $project[$key]->imgurl = '';
  8271. }
  8272. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8273. }
  8274. $result = [
  8275. 'rows' => $project,
  8276. 'count' => $count,
  8277. ];
  8278. return Result::success($result);
  8279. }
  8280. /**
  8281. * @param array $data
  8282. * @return array
  8283. */
  8284. public function getWebsiteCategoryJob(array $data): array
  8285. {
  8286. $categorys = json_decode($data['id'], true);
  8287. if (!empty($categorys)) {
  8288. $category_arr = $this->processArticlePro($data['website_id']);
  8289. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8290. $catiall = $category_arr['catiall'];
  8291. foreach ($categorys as $key => $val) {
  8292. if (isset($val['id']) && !empty($val['id'])) {
  8293. $catid = explode(',', $val['id'])[0] ?? null;
  8294. $type = explode(',', $val['id'])[1] ?? null;
  8295. $textnum = explode(',', $val['id'])[2] ?? null;
  8296. }
  8297. // 4:招聘;5:求职;
  8298. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8299. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8300. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8301. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8302. ->where('job_recruiting.status', 1)
  8303. ->where('job_recruiting.website_id', $data['website_id'])
  8304. ->select(
  8305. 'job_recruiting.id',
  8306. 'job_recruiting.title',
  8307. 'job_company.business_name',
  8308. 'job_recruiting.updated_at',
  8309. 'job_recruiting.cat_arr_id',
  8310. 'job_recruiting.keyword',
  8311. 'job_recruiting.description'
  8312. )
  8313. ->orderBy('job_recruiting.updated_at', 'desc')
  8314. ->limit($textnum)
  8315. ->get()->all();
  8316. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8317. // 状态 审核状态,1待审核2已审核3已拒绝
  8318. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8319. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8320. ->where('job_hunting.status', 2)
  8321. ->where('job_hunting.website_id', $data['website_id'])
  8322. ->select(
  8323. 'job_hunting.id',
  8324. 'job_hunting.name',
  8325. 'job_hunting.cat_arr_id',
  8326. 'job_position.zwname as job_name',
  8327. 'job_hunting.updated_at',
  8328. // 'job_hunting.keyword',
  8329. 'job_hunting.slelf_evaluation'
  8330. )
  8331. ->orderBy('updated_at', 'desc')
  8332. ->limit($textnum)
  8333. ->get()->all();
  8334. } else {
  8335. $job = [];
  8336. }
  8337. // var_dump($catid.'222uuuuuuu'.$key);
  8338. if (!empty($job)) {
  8339. foreach ($job as $k => $value) {
  8340. if (isset($value->cat_arr_id)) {
  8341. $catArr = json_decode($value->cat_arr_id, true);
  8342. $catId = end($catArr);
  8343. } else {
  8344. continue;
  8345. }
  8346. if (isset($catiall[$catId])) {
  8347. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8348. }
  8349. }
  8350. }
  8351. // var_dump($catid.'xxxxx'.$key);
  8352. $result[$key] = $job ?? [];
  8353. }
  8354. }
  8355. if (empty($result)) {
  8356. return Result::error("暂无相关分类信息", 0);
  8357. }
  8358. return Result::success($result);
  8359. }
  8360. /**
  8361. * 发送消息
  8362. * @param array $messageData
  8363. * @return void
  8364. */
  8365. public function sendMessage($messageData)
  8366. {
  8367. $msg = [
  8368. 'talk_type' => $messageData['talk_type'],
  8369. 'title' => $messageData['title'],
  8370. 'content' => $messageData['content'],
  8371. 'messageType' => $messageData['messageType'],
  8372. 'user_id' => $messageData['user_id'] ?? '',
  8373. 'time' => microtime(),
  8374. ];
  8375. $message = new MqProducer($msg);
  8376. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8377. $producer->produce($message);
  8378. }
  8379. /**
  8380. * 行业分类管理 ------1121
  8381. * @param array $data
  8382. * @return array
  8383. */
  8384. public function getJobIndustryList(array $data): array
  8385. {
  8386. $page = $data['page'] ?? 1;
  8387. $page_size = $data['page_size'] ?? 10;
  8388. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8389. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8390. } else {
  8391. $where = [];
  8392. }
  8393. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8394. $query->where([$where]); // 修复:将条件包装成二维数组
  8395. })
  8396. ->orderBy('updated_at', 'desc');
  8397. $count = $rs_query->count();
  8398. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8399. $result = [
  8400. 'count' => $count,
  8401. 'list' => $hy,
  8402. ];
  8403. if (empty($hy)) {
  8404. return Result::success('暂无数据');
  8405. }
  8406. return Result::success($result);
  8407. }
  8408. /**
  8409. * 添加行业分类
  8410. * @param array $data
  8411. * @return array
  8412. */
  8413. public function addJobIndustry(array $data): array
  8414. {
  8415. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8416. if (!empty($hy_name)) {
  8417. return Result::error('行业分类已存在');
  8418. }
  8419. $hy = JobIndustry::insertGetId($data);
  8420. if (empty($hy)) {
  8421. return Result::error('添加失败');
  8422. }
  8423. return Result::success($hy);
  8424. }
  8425. /**
  8426. * 更新行业分类
  8427. * @param array $data
  8428. * @return array
  8429. */
  8430. public function upJobIndustry(array $data): array
  8431. {
  8432. $hy_query = JobIndustry::get();
  8433. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8434. $hy_names = $hy_query->pluck('hyname')->toArray();
  8435. if (!in_array($data['hyid'], $hy_ids)) {
  8436. return Result::error('行业分类不存在');
  8437. }
  8438. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8439. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8440. // return Result::success($other_key_hy);
  8441. unset($hy_names[$other_key_hy]);
  8442. if (in_array($data['hyname'], $hy_names)) {
  8443. return Result::error('行业分类名称已存在');
  8444. }
  8445. }
  8446. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8447. if (empty($hy)) {
  8448. return Result::error('更新失败');
  8449. }
  8450. return Result::success($hy);
  8451. }
  8452. /**
  8453. * 删除行业分类
  8454. * @param array $data
  8455. * @return array
  8456. */
  8457. public function delJobIndustry(array $data): array
  8458. {
  8459. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8460. if (empty($hy_id)) {
  8461. return Result::error('行业分类不存在');
  8462. }
  8463. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  8464. if (empty($hy)) {
  8465. return Result::error('删除失败');
  8466. }
  8467. return Result::success($hy);
  8468. }
  8469. /**
  8470. * 职位分类-列表
  8471. * @param array $data
  8472. * @return array
  8473. */
  8474. public function getJobPositionList(array $data): array
  8475. {
  8476. $page = $data['page'] ?? 1;
  8477. $page_size = $data['page_size'] ?? 10;
  8478. $where = [];
  8479. if (isset($data['zwname']) && !empty($data['zwname'])) {
  8480. $zwids = JobPosition::where('zwpid', 0)
  8481. ->when(!empty($data['zwname']), function ($query) use ($data) {
  8482. $query->where('zwname', 'like', '%' . $data['zwname'] . '%');
  8483. })
  8484. ->orderBy('updated_at', 'desc')
  8485. ->pluck('zwid')
  8486. // ->get()
  8487. ->toArray();
  8488. }
  8489. if (isset($data['childname']) && !empty($data['childname'])) {
  8490. $child_zwids = JobPosition::where('zwpid', '!=', 0)
  8491. ->when(!empty($data['childname']), function ($query) use ($data) {
  8492. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8493. })
  8494. ->orderBy('updated_at', 'desc')
  8495. ->pluck('zwpid')
  8496. // ->get()
  8497. ->toArray();
  8498. if (isset($zwids) && is_array($zwids) && is_array($child_zwids)) {
  8499. $child_zwids = array_intersect($zwids, $child_zwids);
  8500. }
  8501. $zwids = array_values(array_unique($child_zwids));
  8502. }
  8503. $zwids = $zwids ?? null;
  8504. $count = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8505. $query->whereIn('zwid', $zwids);
  8506. })
  8507. ->where('zwpid', 0)
  8508. ->count();
  8509. $position = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8510. $query->whereIn('zwid', $zwids);
  8511. })
  8512. ->where('zwpid', 0)
  8513. ->orderBy('updated_at', 'desc')
  8514. ->offset(($page - 1) * $page_size)
  8515. ->limit($page_size)->get()
  8516. ->map(function ($item) use ($data) {
  8517. $item->children = $item->where('zwpid', $item->zwid)
  8518. ->when(!empty($data['childname']), function ($query) use ($data) {
  8519. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8520. })
  8521. ->orderBy('updated_at', 'desc')
  8522. ->get();
  8523. return $item;
  8524. })
  8525. ->all();
  8526. $result = [
  8527. 'count' => $count,
  8528. 'list' => $position,
  8529. ];
  8530. if (empty($result)) {
  8531. return Result::success('暂无数据');
  8532. }
  8533. return Result::success($result);
  8534. }
  8535. /**
  8536. * 职位分类-添加
  8537. * @param array $data
  8538. * @return array
  8539. */
  8540. public function addJobPosition(array $data): array
  8541. {
  8542. $zw_name = JobPosition::where('zwpid', $data['zwpid'])
  8543. ->where('zwname', $data['zwname'])->first(['zwid']);
  8544. if (!empty($zw_name)) {
  8545. return Result::error('职位分类已存在');
  8546. }
  8547. $zw = JobPosition::insertGetId($data);
  8548. if(empty($zw)){
  8549. return Result::error('添加失败');
  8550. }
  8551. return Result::success($zw);
  8552. }
  8553. /**
  8554. * 更新职位分类
  8555. * @param array $data
  8556. * @return array
  8557. */
  8558. public function upJobPosition(array $data): array
  8559. {
  8560. $zw_position = JobPosition::get();
  8561. if (!in_array($data['zwid'], $zw_position->pluck('zwid')->toArray())) {
  8562. return Result::error('职位分类不存在');
  8563. }
  8564. $zw_name = $zw_position->where('zwid', '!=', $data['zwid'])
  8565. ->where('zwpid', $data['zwpid'])
  8566. ->where('zwname', $data['zwname'])->first();
  8567. if (!empty($zw_name)) {
  8568. return Result::error('职位分类已存在');
  8569. }
  8570. $result = JobPosition::where('zwid', $data['zwid'])->update($data);
  8571. if (empty($result)) {
  8572. return Result::error('更新失败');
  8573. }
  8574. return Result::success($result);
  8575. }
  8576. /**
  8577. * 删除职位分类
  8578. * @param array $data
  8579. * @return array
  8580. */
  8581. public function delJobPosition(array $data): array
  8582. {
  8583. $zw_jobposition = JobPosition::get();
  8584. $zw_id = $zw_jobposition->where('zwid', $data['zwid'])->first();
  8585. if (empty($zw_id)) {
  8586. return Result::error('职位分类不存在');
  8587. }
  8588. if($zw_id->zwpid == 0){
  8589. $zw_job = JobPosition::where('zwpid', $zw_id->zwid)->first();
  8590. if(!empty($zw_job)){
  8591. return Result::error('请先删除子分类');
  8592. }
  8593. }
  8594. $result = JobPosition::where('zwid', $data['zwid'])->delete();
  8595. if (empty($result)) {
  8596. return Result::error('删除失败');
  8597. }
  8598. return Result::success($result);
  8599. }
  8600. }