NewsService.php 296 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172
  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 think\controller\Rest;
  69. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  70. class NewsService implements NewsServiceInterface
  71. {
  72. #[Inject]
  73. protected Redis $redis;
  74. /**
  75. * 获取导航池列表
  76. * @param array $data
  77. * @return array
  78. */
  79. public function getCategoryList(array $data): array
  80. {
  81. $search = $data['name'] ?? '';
  82. $page = (int)($data['page'] ?? 1);
  83. $perPage = (int)($data['pageSize'] ?? 10);
  84. // 1. 查出所有匹配的分类id
  85. if ($search) {
  86. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  87. if (empty($matchedIds)) {
  88. return Result::success(['rows' => [], 'total' => 0]);
  89. }
  90. // 2. 递归查所有父级,直到一级分类
  91. $idsStr = implode(',', $matchedIds);
  92. $sql = "
  93. WITH RECURSIVE parents AS (
  94. SELECT * FROM category WHERE id IN ($idsStr)
  95. UNION ALL
  96. SELECT c.* FROM category c
  97. INNER JOIN parents p ON c.id = p.pid
  98. )
  99. SELECT * FROM parents
  100. ";
  101. $parents = Db::select($sql);
  102. $parentIds = [];
  103. foreach ($parents as $row) {
  104. if ($row->pid == 0) {
  105. $parentIds[] = $row->id;
  106. }
  107. }
  108. $parentIds = array_unique($parentIds);
  109. } else {
  110. // 没有搜索,一级分类就是根
  111. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  112. }
  113. // 3. 一级分类分页
  114. $total = count($parentIds);
  115. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  116. if (empty($parentIds)) {
  117. return Result::success(['rows' => [], 'total' => $total]);
  118. }
  119. // 4. 递归查所有子孙
  120. $idsStr = implode(',', $parentIds);
  121. $sql = "
  122. WITH RECURSIVE subcategories AS (
  123. SELECT * FROM category WHERE id IN ($idsStr)
  124. UNION ALL
  125. SELECT c.* FROM category c
  126. INNER JOIN subcategories s ON c.pid = s.id
  127. )
  128. SELECT * FROM subcategories ORDER BY updated_at DESC
  129. ";
  130. $allCategories = Db::select($sql);
  131. // 5. 组装树结构
  132. $categoryMap = [];
  133. foreach ($allCategories as $cat) {
  134. $cat = (array)$cat;
  135. $cat['children'] = [];
  136. $categoryMap[$cat['id']] = $cat;
  137. }
  138. foreach ($categoryMap as $id => &$cat) {
  139. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  140. $categoryMap[$cat['pid']]['children'][] = &$cat;
  141. }
  142. }
  143. unset($cat);
  144. $categoryTree = [];
  145. foreach ($parentIds as $id) {
  146. if (isset($categoryMap[$id])) {
  147. $categoryTree[] = $categoryMap[$id];
  148. }
  149. }
  150. return Result::success([
  151. 'rows' => $categoryTree,
  152. 'total' => $total,
  153. ]);
  154. }
  155. private function findMatchedCategories($search)
  156. {
  157. if ($search) {
  158. return Category::where('name', 'like', "%{$search}%")
  159. ->orderBy('updated_at', 'desc')
  160. ->get();
  161. }
  162. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  163. ->get();
  164. }
  165. private function findAllParents($categories)
  166. {
  167. $allCategories = [];
  168. foreach ($categories as $category) {
  169. $parentId = $category->pid;
  170. while ($parentId > 0) {
  171. $parent = Category::find($parentId);
  172. if ($parent) {
  173. $allCategories[$parent->id] = $parent;
  174. $parentId = $parent->pid;
  175. } else {
  176. break;
  177. }
  178. }
  179. $allCategories[$category->id] = $category;
  180. }
  181. return array_values($allCategories);
  182. }
  183. private function buildCategoryTree($category, $allRequiredCategories)
  184. {
  185. $categoryData = $category->toArray();
  186. $children = [];
  187. foreach ($allRequiredCategories as $c) {
  188. if ($c->pid === $category->id) {
  189. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  190. }
  191. }
  192. if (!empty($children)) {
  193. $categoryData['children'] = $children;
  194. }
  195. return $categoryData;
  196. }
  197. public function myCategoryList(array $data): array
  198. {
  199. $sszq = $data['sszq'] ?? '';
  200. unset($data['sszq']);
  201. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  202. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  203. $where[] = [
  204. 'pid',
  205. '=',
  206. $data['pid'],
  207. ];
  208. if (isset($data['name'])) {
  209. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  210. }
  211. var_dump($where);
  212. //根据分类id,从category表中取出分类信息
  213. $result = Category::where($where)
  214. ->whereIn('category.id', $catorytids)
  215. ->select('category.*', 'category.id as category_id')->get();
  216. if (empty($result)) {
  217. return Result::error("没有栏目数据");
  218. }
  219. return Result::success($result);
  220. }
  221. /**
  222. * @param array $data
  223. * @return array
  224. */
  225. public function categoryList(array $data): array
  226. {
  227. $where[] = [
  228. 'pid',
  229. '=',
  230. $data['pid']
  231. ];
  232. if (isset($data['name'])) {
  233. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  234. }
  235. var_dump($where);
  236. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  237. if (empty($result)) {
  238. return Result::error("没有栏目数据");
  239. }
  240. return Result::success($result);
  241. }
  242. /**
  243. * @param array $data
  244. * @return array
  245. */
  246. public function addCategory(array $data): array
  247. {
  248. if (isset($data['id'])) {
  249. unset($data['id']);
  250. }
  251. $id = Category::insertGetId($data);
  252. if (empty($id)) {
  253. return Result::error("添加失败");
  254. }
  255. return Result::success(['id' => $id]);
  256. }
  257. /**
  258. * @param array $data
  259. * @return array
  260. */
  261. public function delCategory(array $data): array
  262. {
  263. Db::beginTransaction();
  264. try {
  265. $categoryList = Category::where(['pid' => $data['id']])->get();
  266. if ($categoryList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有子分类不能删除");
  269. }
  270. $articleList = Article::where(['catid' => $data['id']])->get();
  271. if ($articleList->toArray()) {
  272. Db::rollBack();
  273. return Result::error("分类下面有资讯不能删除");
  274. }
  275. $result = Category::where($data)->delete();
  276. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  277. if (!$result) {
  278. Db::rollBack();
  279. return Result::error("删除失败");
  280. }
  281. Db::commit();
  282. return Result::success($result);
  283. } catch (\Exception $e) {
  284. Db::rollBack();
  285. return Result::error("删除失败" . $e->getMessage());
  286. }
  287. }
  288. /**
  289. * @param array $data
  290. * @return array
  291. */
  292. public function updateCategory(array $data): array
  293. {
  294. $where = [
  295. 'id' => $data['id'],
  296. ];
  297. $result = Category::where($where)->update($data);
  298. if ($result) {
  299. return Result::success($result);
  300. } else {
  301. return Result::error("更新失败");
  302. }
  303. }
  304. /**
  305. * 获取导航池信息
  306. * @param array $data
  307. * @return array
  308. */
  309. public function getCategoryInfo(array $data): array
  310. {
  311. $where = [
  312. 'id' => $data['id'],
  313. ];
  314. $result = Category::where($where)->first();
  315. if ($result) {
  316. return Result::success($result);
  317. } else {
  318. return Result::error("更新失败");
  319. }
  320. }
  321. public function getArticleCommend(array $data): array
  322. {
  323. $where = [
  324. 'website_id' => $data['website_id'],
  325. ];
  326. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  327. var_dump($ids);
  328. if (empty($ids)) {
  329. return Result::error("没有推荐数据");
  330. }
  331. //id
  332. $whereArticle = [];
  333. if (isset($data['id'])) {
  334. $whereArticle['id'] = $data['id'];
  335. }
  336. //title like
  337. if (isset($data['title'])) {
  338. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  339. }
  340. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  341. ->where($whereArticle)
  342. ->orderBy('id', 'desc')
  343. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  344. if ($article) {
  345. $data = [
  346. 'rows' => $article->items(),
  347. 'count' => $article->total(),
  348. ];
  349. return Result::success($data);
  350. } else {
  351. return Result::error("获取失败失败");
  352. }
  353. }
  354. /**
  355. * @param array $data
  356. * @return array
  357. */
  358. public function getArticleList(array $data): array
  359. {
  360. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  361. $type_id = $data['type_id'];
  362. unset($data['type_id']);
  363. $user_id = $data['user_id'];
  364. unset($data['user_id']);
  365. $where = [];
  366. $status1 = [];
  367. if (isset($data['id']) && $data['id']) {
  368. array_push($where, ['article.id', '=', $data['id']]);
  369. }
  370. if (isset($data['title']) && $data['title']) {
  371. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  372. }
  373. if (isset($data['category_name']) && $data['category_name']) {
  374. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  375. }
  376. if (isset($data['catid']) && $data['catid']) {
  377. array_push($where, ['article.catid', '=', $data['catid']]);
  378. }
  379. if (isset($data['author']) && $data['author']) {
  380. array_push($where, ['article.author', '=', $data['author']]);
  381. }
  382. if (isset($data['islink']) && $data['islink'] !== "") {
  383. array_push($where, ['article.islink', '=', $data['islink']]);
  384. }
  385. if (isset($data['status']) && $data['status'] !== "") {
  386. array_push($where, ['article.status', '=', $data['status']]);
  387. }
  388. if (isset($data['status1'])) {
  389. $status1 = json_decode(($data['status1']));
  390. }
  391. //不是管理员展示个人数据;
  392. if ($type_id != 10000) {
  393. $where[] = ['article.admin_user_id', '=', $user_id];
  394. }
  395. $rep = Article::where($where)
  396. ->whereNotIn('article.status', [404])
  397. ->when($status1, function ($query) use ($status1) {
  398. if (isset($status1) && $status1) {
  399. $query->whereIn('article.status', $status1);
  400. }
  401. })
  402. ->leftJoin('category', 'article.catid', 'category.id')
  403. ->leftJoin('website_category', function ($join) {
  404. $join->on('article.web_site_id', '=', 'website_category.website_id')
  405. ->on('article.catid', '=', 'website_category.category_id');
  406. })
  407. ->select("article.*", "category.name as category_name", "website_category.alias")
  408. ->orderBy("article.updated_at", "desc")
  409. ->limit($data['pageSize'])
  410. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  411. $count = Article::where($where)->whereNotIn('article.status', [404])
  412. ->when($status1, function ($query) use ($status1) {
  413. if (isset($status1) && $status1) {
  414. $query->whereIn('article.status', $status1);
  415. }
  416. })
  417. ->leftJoin('category', 'article.catid', 'category.id')->count();
  418. $data = [
  419. 'rows' => $rep->toArray(),
  420. 'count' => $count,
  421. ];
  422. if (empty($rep)) {
  423. return Result::error("没有信息数据");
  424. }
  425. return Result::success($data);
  426. }
  427. /**
  428. * @param array $data
  429. * @return array
  430. */
  431. public function addArticle(array $data): array
  432. {
  433. var_dump($data, '----------12-----------1');
  434. if(isset($data['is_collect'])){
  435. $is_collect = $data['is_collect'];
  436. unset($data['is_collect']);
  437. }
  438. unset($data['user_type']);
  439. unset($data['nav_add_pool_id']);
  440. // unset($data['commend_id']);
  441. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  442. Db::beginTransaction();
  443. try {
  444. //处理投票
  445. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  446. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  447. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  448. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  449. unset($data['is_survey']);
  450. unset($data['survey_name']);
  451. unset($data['suvey_array']);
  452. // unset($data['website_id']);
  453. // unset($data['web_site_id']);
  454. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  455. if ($data['hits'] == '') {
  456. $data['hits'] = 0;
  457. }
  458. if ($data['is_original'] == '') {
  459. $data['is_original'] = 0;
  460. }
  461. if ($data['status'] == '') {
  462. $data['status'] = 0;
  463. }
  464. $articleData = $data;
  465. unset($articleData['content']);
  466. //自动处理缩略图、关键字、描述
  467. if ($articleData['imgurl'] == '') {
  468. //如果没有图,设置level=0
  469. $levelArr = json_decode($articleData['level'], true);
  470. var_dump($levelArr, '----------levelArr-----------1');
  471. //content中提取图片第一个图,正则提取
  472. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  473. if(isset($is_collect) && $is_collect == 1){
  474. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  475. }else{
  476. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  477. }
  478. preg_match_all($reg, $data['content'], $matches);
  479. if (isset($matches[1][0])) {
  480. //截取varchar240
  481. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  482. //如果有图,设置level=3
  483. if (!in_array(3, $levelArr)) {
  484. $levelArr[] = 3;
  485. }
  486. $articleData['level'] = json_encode($levelArr);
  487. } else {
  488. if (!in_array(0, $levelArr)) {
  489. $levelArr[] = 0;
  490. }
  491. $articleData['level'] = json_encode($levelArr);
  492. }
  493. }
  494. var_dump($articleData['level'], '----------$articleData[level]----------1');
  495. if ($articleData['keyword'] == '') {
  496. //提取标题+内容中的关键词
  497. $articleData['keyword'] = $data['title'];
  498. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  499. Jieba::init(); // 初始化 jieba-php
  500. Finalseg::init();
  501. $segList = Jieba::cut($articleData['keyword']);
  502. $segList1 = array_slice($segList, 0, 8);
  503. $articleData['keyword'] = implode(',', $segList1);
  504. }
  505. if ($articleData['introduce'] == '') {
  506. //提取内容中的描述
  507. $content = $data['content'];
  508. // 去除 <style> 和 <script> 标签及其内容
  509. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  510. // 去除所有 HTML 标签
  511. $content = strip_tags($content);
  512. // 去除 HTML 实体
  513. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  514. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  515. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  516. // 去除多余空白
  517. $content = preg_replace('/\s+/u', '', $content);
  518. // 截取 100 个字符
  519. $articleData['introduce'] = mb_substr($content, 0, 100);
  520. }
  521. if ($articleData['status'] == 0) {
  522. $this->sendMessage([
  523. 'talk_type' => 100,
  524. 'title' => $articleData['title'],
  525. 'content' => '提交了审核',
  526. 'messageType' => 2,
  527. ]);
  528. }
  529. $id = Article::insertGetId($articleData);
  530. $articleDataContent = [
  531. 'article_id' => $id,
  532. 'content' => $data['content'],
  533. ];
  534. ArticleData::insertGetId($articleDataContent);
  535. //处理投票
  536. if ($is_survey == 1) {
  537. //生成年月日时分秒+8位随机数
  538. $uuid = date('YmdHis') . rand(10000000, 99999999);
  539. var_dump($suvey_array, 'suvey_array________');
  540. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  541. var_dump($suveys_array, '---------------------1');
  542. var_dump($suvey_array, '---------------------2');
  543. $suvey_data = [];
  544. foreach ($suveys_array as $key => $value) {
  545. if ($value == '') {
  546. continue;
  547. }
  548. if (is_array($value)) {
  549. $suvey_data[] = [
  550. 'sur_id' => $uuid,
  551. 'art_id' => $id,
  552. 'website_id' => $website_id ?? 2,
  553. 'survey_name' => $survey_name,
  554. 'choice_name' => $value[1],
  555. 'is_other' => 1,
  556. 'other_id' => 0,
  557. 'results' => 0,
  558. ];
  559. } else {
  560. $suvey_data[] = [
  561. 'sur_id' => $uuid,
  562. 'art_id' => $id,
  563. 'website_id' => $website_id ?? 2,
  564. 'survey_name' => $survey_name,
  565. 'choice_name' => $value,
  566. 'is_other' => 0,
  567. 'other_id' => 0,
  568. 'results' => 0,
  569. ];
  570. }
  571. if (empty($suvey_data)) {
  572. throw new \Exception("投票数据为空");
  573. }
  574. }
  575. $result = ArticleSurvey::insert($suvey_data);
  576. if (!$result) {
  577. throw new \Exception("投票失败,ArticleSurvey插入失败");
  578. }
  579. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  580. if (!$result) {
  581. throw new \Exception("投票失败,更新主表失败");
  582. }
  583. }
  584. Db::commit();
  585. return Result::success(['id' => $id]);
  586. } catch (\Throwable $ex) {
  587. Db::rollBack();
  588. var_dump($ex->getMessage());
  589. return Result::error("创建失败", 0);
  590. }
  591. }
  592. /**
  593. * @param array $data
  594. * @return array
  595. */
  596. public function delArticle(array $data): array
  597. {
  598. $result = Article::where($data)->delete();
  599. //survey投票删除
  600. articleSurvey::where(['art_id' => $data['id']])->delete();
  601. if (!$result) {
  602. return Result::error("删除失败");
  603. }
  604. return Result::success($result);
  605. }
  606. /**
  607. * @param array $data
  608. * @return array
  609. */
  610. public function updateArticle(array $data): array
  611. {
  612. var_dump($data, '----------12-----------1');
  613. Db::beginTransaction();
  614. unset($data['user_type']);
  615. // unset($data['web_site_id']);
  616. unset($data['nav_add_pool_id']);
  617. try {
  618. //处理投票
  619. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  620. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  621. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  622. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  623. unset($data['is_survey']);
  624. unset($data['survey_name']);
  625. unset($data['suvey_array']);
  626. unset($data['website_id']);
  627. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  628. if ($data['hits'] == '') {
  629. $data['hits'] = 0;
  630. }
  631. if ($data['is_original'] == '') {
  632. $data['is_original'] = 0;
  633. }
  634. if ($data['status'] == '') {
  635. $data['status'] = 0;
  636. }
  637. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  638. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  639. $articleData = $data;
  640. unset($articleData['content']);
  641. unset($articleData['status_name']);
  642. unset($articleData['name']);
  643. unset($articleData['content']);
  644. unset($articleData['pid_arr']);
  645. unset($articleData['pid']);
  646. //自动处理缩略图、关键字、描述
  647. if ($articleData['imgurl'] == '') {
  648. //如果没有图,设置level=0
  649. $levelArr = json_decode($articleData['level'], true);
  650. var_dump($levelArr, '----------levelArr-----------1');
  651. //content中提取图片第一个图,正则提取
  652. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  653. preg_match_all($reg, $data['content'], $matches);
  654. if (isset($matches[1][0])) {
  655. //截取varchar240
  656. // 截取到第一个<
  657. $articleData['imgurl'] = $matches[1][0];
  658. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  659. $pos = strpos($articleData['imgurl'], '"');
  660. if ($pos !== false) {
  661. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  662. }
  663. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  664. //如果有图,设置level=3
  665. if (!in_array(3, $levelArr)) {
  666. $levelArr[] = 3;
  667. }
  668. $articleData['level'] = json_encode($levelArr);
  669. } else {
  670. if (!in_array(0, $levelArr)) {
  671. $levelArr[] = 0;
  672. }
  673. $articleData['level'] = json_encode($levelArr);
  674. }
  675. }
  676. var_dump($articleData['level'], '----------$articleData[level]----------1');
  677. if ($articleData['keyword'] == '') {
  678. //提取标题+内容中的关键词
  679. $articleData['keyword'] = $data['title'];
  680. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  681. Jieba::init(); // 初始化 jieba-php
  682. Finalseg::init();
  683. $segList = Jieba::cut($articleData['keyword']);
  684. $segList1 = array_slice($segList, 0, 8);
  685. $articleData['keyword'] = implode(',', $segList1);
  686. }
  687. if ($articleData['introduce'] == '') {
  688. //提取内容中的描述
  689. $content = $data['content'];
  690. // 去除 <style> 和 <script> 标签及其内容
  691. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  692. // 去除所有 HTML 标签
  693. $content = strip_tags($content);
  694. // 去除 HTML 实体
  695. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  696. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  697. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  698. // 去除多余空白
  699. $content = preg_replace('/\s+/u', '', $content);
  700. // 截取 100 个字符
  701. $articleData['introduce'] = mb_substr($content, 0, 100);
  702. }
  703. if ($articleData['status'] == 0) {
  704. $this->sendMessage([
  705. 'talk_type' => 100,
  706. 'title' => $articleData['title'],
  707. 'content' => '提交了审核',
  708. 'messageType' => 2,
  709. ]);
  710. }
  711. $id = Article::where(['id' => $data['id']])->update($articleData);
  712. $articleDataContent = [
  713. 'content' => $data['content'],
  714. ];
  715. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  716. //处理投票
  717. $id = $data['id'];
  718. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  719. var_dump($suvey_array, 'suvey_array________delete');
  720. //处理投票
  721. if ($is_survey == 1) {
  722. //生成年月日时分秒+8位随机数
  723. $uuid = date('YmdHis') . rand(10000000, 99999999);
  724. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  725. var_dump($suveys_array, '---------------------1');
  726. $suvey_data = [];
  727. if (is_array($suveys_array)) {
  728. foreach ($suveys_array as $key => $value) {
  729. if ($value == '') {
  730. continue;
  731. }
  732. if (is_array($value)) {
  733. $suvey_data[] = [
  734. 'sur_id' => $uuid,
  735. 'art_id' => $id,
  736. 'website_id' => $website_id ?? 2,
  737. 'survey_name' => $survey_name,
  738. 'choice_name' => $value[1],
  739. 'is_other' => 1,
  740. 'other_id' => 0,
  741. 'results' => 0,
  742. ];
  743. } else {
  744. $suvey_data[] = [
  745. 'sur_id' => $uuid,
  746. 'art_id' => $id,
  747. 'website_id' => $website_id ?? 2,
  748. 'survey_name' => $survey_name,
  749. 'choice_name' => $value,
  750. 'is_other' => 0,
  751. 'other_id' => 0,
  752. 'results' => 0,
  753. ];
  754. }
  755. if (empty($suvey_data)) {
  756. throw new \Exception("投票数据为空");
  757. }
  758. }
  759. }
  760. $result = ArticleSurvey::insert($suvey_data);
  761. if (!$result) {
  762. throw new \Exception("投票失败");
  763. }
  764. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  765. if (!$result) {
  766. throw new \Exception("投票失败");
  767. }
  768. } else {
  769. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  770. }
  771. Db::commit();
  772. return Result::success([]);
  773. } catch (\Throwable $ex) {
  774. Db::rollBack();
  775. var_dump($ex->getMessage());
  776. return Result::error("更新失败" . $ex->getMessage(), 0);
  777. }
  778. }
  779. /**
  780. * 更新资讯状态
  781. * @param array $data
  782. * @return array
  783. */
  784. public function upArticleStatus(array $data): array
  785. {
  786. $articleData = Article::where(['id' => $data['id']])->first();
  787. //发送10次
  788. for ($i = 0; $i < 10; $i++) {
  789. $this->sendMessage([
  790. 'talk_type' => 100,
  791. 'title' => $i . $articleData['title'],
  792. 'content' => '审核通过',
  793. 'messageType' => 2,
  794. 'user_id' => $articleData['admin_user_id'],
  795. ]);
  796. }
  797. var_dump($data['status'], 'status');
  798. return Result::success();
  799. if ($data['status'] == 1) {
  800. $this->sendMessage([
  801. 'talk_type' => 101,
  802. 'title' => $articleData['title'],
  803. 'content' => '审核通过',
  804. 'messageType' => 2,
  805. 'user_id' => $articleData['admin_user_id'],
  806. ]);
  807. }
  808. if ($data['status'] == 2) {
  809. $this->sendMessage([
  810. 'talk_type' => 101,
  811. 'title' => $articleData['title'],
  812. 'content' => '审核拒绝',
  813. 'messageType' => 2,
  814. 'user_id' => $articleData['admin_user_id'],
  815. ]);
  816. }
  817. if ($data['status'] == 0) {
  818. $this->sendMessage([
  819. 'talk_type' => 100,
  820. 'title' => $articleData['title'],
  821. 'content' => '提交了审核',
  822. 'messageType' => 2,
  823. ]);
  824. }
  825. $result = Article::where(['id' => $data['id']])->update($data);
  826. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  827. //article_ignore 表插入数据 db操作
  828. //转成数组
  829. //删掉数据重新写入
  830. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  831. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  832. $insert_data = [];
  833. foreach ($website_ids as $key => $value) {
  834. $insert_data[] = [
  835. 'article_id' => $data['id'],
  836. 'website_id' => $value,
  837. ];
  838. }
  839. DB::table('article_ignore')->insert($insert_data);
  840. }
  841. if ($result) {
  842. return Result::success();
  843. } else {
  844. return Result::error("更新状态失败", 0);
  845. }
  846. }
  847. /**
  848. * 获取新闻详情
  849. * @param array $data
  850. * @return array
  851. */
  852. public function getArticleInfo(array $data): array
  853. {
  854. $where = [
  855. 'article.id' => $data['id'],
  856. // 'article.status' => 1,
  857. ];
  858. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  859. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  860. $info = $result;
  861. // var_dump($info, 'info');
  862. $info['survey_array'] = $articleSurvey;
  863. if ($result) {
  864. return Result::success($info);
  865. } else {
  866. return Result::error("查询失败", 0);
  867. }
  868. }
  869. /**
  870. * 获取头条新闻
  871. * @param array $data
  872. * @return array
  873. */
  874. public function getWebsiteArticlett(array $data): array
  875. {
  876. $website_id = $data['website_id'];
  877. $website = Website::where('id', $data['website_id'])->first();
  878. if(empty($website)){
  879. return Result::error("网站不存在",0);
  880. }
  881. $categorys = $this->processArticlePro($website_id);
  882. $catiall = $categorys['catiall'];
  883. $categoryIds = $categorys['categoryIds'];
  884. $where = [
  885. 'status' => 1
  886. ];
  887. // $website_column = $website['column'];
  888. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  889. $website_column = json_decode($website['website_column_arr_id'],true);
  890. }
  891. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  892. // return Result::success($diff_pid_categoryIds);
  893. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  894. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  895. }
  896. // $website_id = $data['website_id'];
  897. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  898. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  899. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  900. switch ($data['level']) {
  901. case 1:
  902. case 2:
  903. case 3:
  904. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  905. $query = Article::where($where)
  906. ->where('level', 'like', '%' . $data['level'] . '%')
  907. ->orderBy('updated_at', 'desc');
  908. break;
  909. case 4: //最新资讯
  910. $query = Article::where($where)->orderBy('updated_at', 'desc');
  911. break;
  912. case 5: //资讯推荐
  913. $query = Article::where($where)
  914. ->where('updated_at', '>', $month);
  915. break;
  916. case 7: //资讯分类
  917. if (isset($data['id']) && !empty($data['id'])) {
  918. $keyword = Article::where('id', $data['id'])->value('keyword');
  919. $keywordArray = explode(',', $keyword);
  920. $whereL7 = [];
  921. foreach ($keywordArray as $k => $v) {
  922. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  923. }
  924. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  925. break;
  926. } else {
  927. return Result::error("请输入资讯ID", 0);
  928. break;
  929. }
  930. default:
  931. break;
  932. }
  933. // $whereL7 = [];
  934. // if(isset($data['id']) && !empty($data['id'])){
  935. // $keyword = Article::where('id', $data['id'])->value('keyword');
  936. // $keywordArray = explode(',', $keyword);
  937. // foreach ($keywordArray as $k => $v) {
  938. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  939. // }
  940. // }
  941. // $query = Article::where($where)
  942. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  943. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  944. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  945. // }
  946. // if($data['level'] == 7){
  947. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  948. // }
  949. // if($data['level'] == 4){
  950. // $query = $query->inRandomOrder()
  951. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  952. // }
  953. // if($data['level'] == 5){
  954. // $query = $query->orderBy('updated_at','desc');
  955. // }
  956. // });
  957. if ($data['textnum'] > 0) {
  958. $query = clone $query;
  959. $result['text'] = $query
  960. ->whereIn('catid', $categoryIds)
  961. ->leftJoinSub(function ($query) use ($website_id) {
  962. $query->from('article_ignore')
  963. ->where('website_id', $website_id);
  964. }, 'article_ignore', function ($join) {
  965. $join->on('article_ignore.article_id', '=', 'article.id');
  966. })
  967. ->where(function ($query) use ($website_id) {
  968. $query->whereNull('article_ignore.article_id')
  969. ->orWhere('article_ignore.website_id', '!=', $website_id);
  970. })
  971. ->select(
  972. 'article.id',
  973. 'article.title',
  974. 'article.author',
  975. 'article.updated_at',
  976. 'article.introduce',
  977. 'article.islink',
  978. 'article.linkurl',
  979. 'article.copyfrom',
  980. 'article.cat_arr_id',
  981. 'article.catid',
  982. 'article.level'
  983. )
  984. ->offset($data['placeid'])
  985. ->limit($data['textnum'])
  986. ->get()->all();
  987. foreach ($result['text'] as $k => $v) {
  988. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  989. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  990. }
  991. }
  992. if ($data['imgnum'] > 0) {
  993. $query = clone $query;
  994. $result['img'] = $query
  995. ->whereIn('catid', $categoryIds)
  996. ->where('article.imgurl', '!=', '')
  997. ->select(
  998. 'article.id',
  999. 'article.title',
  1000. 'article.imgurl',
  1001. 'article.author',
  1002. 'article.updated_at',
  1003. 'article.introduce',
  1004. 'article.islink',
  1005. 'article.linkurl',
  1006. 'article.copyfrom',
  1007. 'article.cat_arr_id',
  1008. 'article.catid',
  1009. 'article.level'
  1010. )
  1011. ->offset($data['placeid'])
  1012. ->limit($data['imgnum'])
  1013. ->get()->all();
  1014. foreach ($result['img'] as $k => $v) {
  1015. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1016. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1017. }
  1018. }
  1019. if (empty($result)) {
  1020. return Result::error("暂无相关资讯", 0);
  1021. }
  1022. return Result::success($result);
  1023. }
  1024. /**
  1025. * 获取模块新闻
  1026. * @param array $data
  1027. * @return array
  1028. */
  1029. public function getWebsiteModelArticles(array $data): array
  1030. {
  1031. $catid = $data['catid'];
  1032. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1033. $category = $category->toArray();
  1034. if (!empty($category)) {
  1035. $where = [
  1036. 'status' => 1,
  1037. 'catid' => $catid,
  1038. ];
  1039. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1040. // 1:文字新闻;2:轮播图;3:图文;
  1041. // 级别:0:未分类
  1042. // 3:推荐图片
  1043. if ($data['level'] == 1) {
  1044. $data['level'] = 0;
  1045. }
  1046. $result = Article::where($where)
  1047. ->where(function ($query) use ($data) {
  1048. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1049. ->orWhereNull("level")
  1050. ->orWhereRaw("level = '[]'");
  1051. })
  1052. ->where(function ($query) use ($data) {
  1053. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1054. ->orWhereNull("ignore_ids");
  1055. })
  1056. ->orderBy("updated_at", "desc")
  1057. ->offset($placeid)
  1058. ->limit($data['pagesize'])
  1059. ->get();
  1060. if (empty($result)) {
  1061. return Result::error("此栏目暂无相关新闻", 0);
  1062. }
  1063. } else {
  1064. return Result::error("此网站暂无此栏目", 0);
  1065. }
  1066. return Result::success($result);
  1067. }
  1068. /**
  1069. *获取新闻列表
  1070. * @param array $data
  1071. * @return array
  1072. */
  1073. public function getWebsiteArticleList(array $data): array
  1074. {
  1075. // return Result::success($data);
  1076. $where[] = ['status', '=', 1];
  1077. $website_id = $data['website_id'];
  1078. $website = Website::where('id', $data['website_id'])->first();
  1079. if(empty($website)){
  1080. return Result::error("网站不存在",0);
  1081. }
  1082. // $website_column = $website['column'];
  1083. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  1084. $website_column = json_decode($website['website_column_arr_id'],true);
  1085. }
  1086. $categorys = $this->processArticlePro($website_id);
  1087. $cat_1st_arr = $categorys['cat_1st_arr'];
  1088. $catiall = $categorys['catiall'];
  1089. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1090. // return Result::success($diff_pid_categoryIds);
  1091. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1092. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1093. }
  1094. if (isset($data['catid']) && !empty($data['catid'])) {
  1095. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1096. if (empty($category)) {
  1097. return Result::error("此网站暂无此栏目", 0);
  1098. }
  1099. array_push($where, ['catid', '=', $data['catid']]);
  1100. }
  1101. // return Result::success($where);
  1102. $query = Article::where($where)
  1103. ->leftJoinSub(function ($query) use ($website_id) {
  1104. $query->from('article_ignore')
  1105. ->where('website_id', $website_id);
  1106. }, 'article_ignore', function ($join) {
  1107. $join->on('article_ignore.article_id', '=', 'article.id');
  1108. })
  1109. ->where(function ($query) use ($website_id) {
  1110. $query->whereNull('article_ignore.article_id')
  1111. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1112. })
  1113. ->select(
  1114. 'article.id',
  1115. 'article.title',
  1116. 'article.imgurl',
  1117. 'article.author',
  1118. 'article.updated_at',
  1119. 'article.introduce',
  1120. 'article.islink',
  1121. 'article.linkurl',
  1122. 'article.copyfrom',
  1123. 'article.cat_arr_id',
  1124. 'article.catid'
  1125. );
  1126. $count = $query->count();
  1127. $rep = $query->orderBy("updated_at", "desc")
  1128. ->offset(($data['page'] - 1) * $data['pageSize'])
  1129. ->limit($data['pageSize'])
  1130. ->get()->all();
  1131. $categorys = $this->processArticlePro($website_id);
  1132. $cat_1st_arr = $categorys['cat_1st_arr'];
  1133. $catiall = $categorys['catiall'];
  1134. // $web['website_id'] = $data['website_id'];
  1135. foreach ($rep as $k => $v) {
  1136. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1137. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1138. }
  1139. // $rep = $this->processArticles($rep,$web);
  1140. $data = [
  1141. 'rows' => $rep,
  1142. 'count' => $count,
  1143. ];
  1144. if (empty($rep)) {
  1145. return Result::error("没有信息数据");
  1146. }
  1147. return Result::success($data);
  1148. }
  1149. /**
  1150. * 前端-获取新闻详情
  1151. * @param array $data
  1152. * @return array
  1153. */
  1154. public function selectWebsiteArticleInfo(array $data): array
  1155. {
  1156. $where = [
  1157. 'article.id' => $data['id'],
  1158. 'article.status' => 1,
  1159. ];
  1160. $result = Article::where($where)
  1161. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1162. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1163. ->where(function ($query) use ($data) {
  1164. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1165. ->orWhereNull("ignore_ids");
  1166. })
  1167. ->select(
  1168. 'article.*',
  1169. 'article_data.content',
  1170. 'article_data.article_id',
  1171. 'article_extend.website_url',
  1172. 'article_extend.email',
  1173. 'article_extend.contacts',
  1174. 'article_extend.contacts_mobile',
  1175. 'article_extend.contacts_address',
  1176. 'article_extend.zip_code',
  1177. 'article_extend.enterprise_name'
  1178. )
  1179. ->first();
  1180. if (empty($result)) {
  1181. return Result::error("暂无此新闻!", 0);
  1182. }
  1183. if (!empty($result['publiced_at'])) {
  1184. $result['updated_at'] = $result['publiced_at'];
  1185. }
  1186. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1187. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1188. ->where('website_category.website_id', $data['website_id'])
  1189. ->where(['website_category.category_id' => $result['catid']])
  1190. ->first();
  1191. if (empty($category)) {
  1192. return Result::error("查询失败", 0);
  1193. }
  1194. //手动推荐文章
  1195. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1196. if (empty($commend_ids)) {
  1197. $commendArticle = [];
  1198. } else {
  1199. //去除不存在的文章ID
  1200. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1201. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1202. ->where('article.status', 1)
  1203. ->where('website_category.website_id', $data['website_id'])
  1204. ->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')
  1205. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1206. // ->orderBy('article.updated_at', 'desc')
  1207. ->limit(5)
  1208. ->get();
  1209. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1210. foreach ($commendArticle as $k => $v) {
  1211. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1212. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1213. $cat_arr_id = array_unique($cat_arr_id);
  1214. // 从website_category取出alias_pinyin
  1215. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1216. ->whereIn('category_id', $cat_arr_id)
  1217. ->pluck('alias_pinyin', 'category_id')
  1218. ->toArray();
  1219. // 将cat_arr_id的json转成路径/隔开
  1220. $path_parts = [];
  1221. foreach ($cat_arr_id as $cat_id) {
  1222. if (isset($cat_arr[$cat_id])) {
  1223. $path_parts[] = $cat_arr[$cat_id];
  1224. }
  1225. }
  1226. $v->alias_pinyin = implode('/', $path_parts);
  1227. } else {
  1228. $v->alias_pinyin = '';
  1229. }
  1230. }
  1231. }
  1232. $result['category_id'] = $category['category_id'];
  1233. $result['cat_name'] = $category['alias'];
  1234. $result['website_name'] = $category['website_name'] ?? "";
  1235. $result['suffix'] = $category['suffix'] ?? "";
  1236. $result['commendArticle'] = $commendArticle;
  1237. $result['commend_ids'] = $commend_ids;
  1238. return Result::success($result);
  1239. }
  1240. /**
  1241. * 前端-获取网站调查问卷
  1242. * @param array $data
  1243. * @return array
  1244. */
  1245. public function getWebsiteSurvey(array $data): array
  1246. {
  1247. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1248. $website = Website::where('id', $data['website_id'])->first();
  1249. if (empty($website)) {
  1250. return Result::error("暂无此网站", 0);
  1251. }
  1252. }
  1253. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1254. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1255. if (empty($article)) {
  1256. return Result::error("暂无此文章", 0);
  1257. }
  1258. // return Result::error($data,0);
  1259. $where['art_id'] = $data['art_id'];
  1260. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1261. } else {
  1262. $survey = Article::where(function ($query) {
  1263. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1264. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1265. })
  1266. ->where('status', 1)
  1267. ->where('is_survey', 1)
  1268. ->select('survey_id')
  1269. ->orderBy('updated_at', 'desc')
  1270. ->first();
  1271. if (empty($survey)) {
  1272. return Result::error("暂无调查问卷", 0);
  1273. }
  1274. $where['sur_id'] = $survey['survey_id'];
  1275. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1276. }
  1277. // return Result::success($where);
  1278. $result = ArticleSurvey::where($where)
  1279. ->where(function ($query) {
  1280. $query->where('is_other', 0)
  1281. ->orWhere(function ($subQuery) {
  1282. $subQuery->where('is_other', 1)
  1283. ->where('other_id', 0);
  1284. });
  1285. })
  1286. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1287. ->select('article_survey.*', 'article.survey_type')
  1288. ->get()->all();
  1289. if (empty($result)) {
  1290. return Result::error("此文章暂无调查问卷", 0);
  1291. }
  1292. return Result::success($result);
  1293. }
  1294. /**
  1295. * 前端-添加网站调查问卷选项
  1296. * @param array $data
  1297. * @return array
  1298. */
  1299. public function addWebsiteSurveyOption(array $data): array
  1300. {
  1301. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1302. $website = Website::where('id', $data['website_id'])->first();
  1303. if (empty($website)) {
  1304. return Result::error("暂无此网站", 0);
  1305. }
  1306. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1307. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1308. if (empty($survey)) {
  1309. return Result::error("此调查问卷不可添加选项", 0);
  1310. }
  1311. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1312. $choice = [
  1313. 'art_id' => $survey['art_id'],
  1314. 'website_id' => $data['website_id'],
  1315. 'survey_name' => $survey['survey_name'],
  1316. 'choice_name' => $data['choice_name'],
  1317. 'sur_id' => $survey['sur_id'],
  1318. 'is_other' => 1,
  1319. 'other_id' => $survey['id'],
  1320. ];
  1321. $result = ArticleSurvey::insertGetId($choice);
  1322. if (empty($result)) {
  1323. return Result::error("添加失败", 0);
  1324. }
  1325. return Result::success($result);
  1326. }
  1327. }
  1328. return Result::error("添加失败", 0);
  1329. }
  1330. return Result::error("添加失败", 0);
  1331. }
  1332. /**
  1333. * 前端-调查问卷投票
  1334. * @param array $data
  1335. * @return array
  1336. */
  1337. public function addWebsiteSurveyVote(array $data): array
  1338. {
  1339. // return Result::success($data);
  1340. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1341. $website = Website::where('id', $data['website_id'])->first();
  1342. if (empty($website)) {
  1343. return Result::error("暂无此网站", 0);
  1344. }
  1345. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1346. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1347. // return Result::success($survey);
  1348. if (empty($is_survey)) {
  1349. return Result::error("此调查问卷不存在", 0);
  1350. }
  1351. // return Result::success($survey);
  1352. // 调查问卷类型
  1353. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1354. //多选 若是json型则转化成数组类型
  1355. if (strpos($data['choice_id'], '[') === 0) {
  1356. $data['choice_id'] = json_decode($data['choice_id'], true);
  1357. } else {
  1358. // 单选 也转换成数组
  1359. $data['choice_id'] = [$data['choice_id']];
  1360. }
  1361. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1362. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1363. // ->where('website_id',$data['website_id'])
  1364. ->where('is_other', 1)
  1365. ->where('other_id', 0)
  1366. ->first();
  1367. if (!empty($other)) {
  1368. return Result::error("请选择已有的选项!", 0);
  1369. }
  1370. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1371. // ->where('website_id',$data['website_id'])
  1372. ->where('is_other', 1)
  1373. ->where('other_id', '!=', 0)
  1374. ->first();
  1375. // return Result::success($choice['other']);
  1376. $choice_id = $data['choice_id'];
  1377. if (!empty($choice['other'])) {
  1378. // array_push($data['choice_id'],$choice['other']['other_id']);
  1379. if (!empty($choice_id)) {
  1380. $key = array_search($choice['other']['id'], $choice_id);
  1381. if ($key !== false) {
  1382. unset($choice_id[$key]);
  1383. $choice_id = array_values($choice_id);
  1384. }
  1385. array_push($choice_id, $choice['other']['other_id']);
  1386. } else {
  1387. $choice_id[0] = $choice['other']['other_id'];
  1388. }
  1389. array_push($data['choice_id'], $choice['other']['other_id']);
  1390. }
  1391. // return Result::success($data);
  1392. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1393. // ->where('website_id',$data['website_id'])
  1394. ->increment('results', 1);
  1395. if (empty($choice)) {
  1396. return Result::error("请选择已有的选项!", 0);
  1397. }
  1398. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1399. // ->where('website_id',$data['website_id'])
  1400. ->where('other_id', 0)
  1401. ->get();
  1402. $survey['choice'] = $choice_id;
  1403. return Result::success($survey);
  1404. }
  1405. return Result::error("参数必填!");
  1406. }
  1407. return Result::error("此调查问卷不存在", 0);
  1408. }
  1409. return Result::error("参数必填!");
  1410. }
  1411. /**
  1412. * 后端-获取网站调查问卷列表
  1413. * @param array $data
  1414. * @return array
  1415. */
  1416. public function getSurveyList(array $data): array
  1417. {
  1418. $where = [];
  1419. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1420. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1421. }
  1422. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1423. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1424. }
  1425. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1426. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1427. }
  1428. // return Result::success($where);
  1429. if (!empty($where)) {
  1430. $query = Article::where($where)->where(function ($q) {
  1431. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1432. });
  1433. } else {
  1434. $query = Article::where(function ($q) {
  1435. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1436. });
  1437. }
  1438. $count = $query->count();
  1439. $survey = $query->orderByDesc('id')
  1440. ->limit($data['pageSize'])
  1441. ->offset(($data['page'] - 1) * $data['pageSize'])
  1442. ->get();
  1443. if (empty($survey->toArray())) {
  1444. return Result::error("暂无调查问卷!", 0);
  1445. }
  1446. $result = [
  1447. 'rows' => $survey,
  1448. 'count' => $count,
  1449. ];
  1450. return Result::success($result);
  1451. }
  1452. /**
  1453. * 后端-获取网站调查问卷详情
  1454. * @param array $data
  1455. * @return array
  1456. */
  1457. public function getSurveyInfo(array $data): array
  1458. {
  1459. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1460. $where = ['sur_id' => $data['sur_id']];
  1461. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1462. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1463. ->select('article_survey.*', 'article.survey_type')
  1464. ->get()->all();
  1465. if (empty($choose)) {
  1466. return Result::error("此调查问卷不存在", 0);
  1467. }
  1468. $resultsArray = array_column($choose, 'results');
  1469. $total = array_sum($resultsArray);
  1470. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1471. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1472. // $total = 0;
  1473. if (!empty($other)) {
  1474. $total = $total + $other['results'];
  1475. $other['choice_name'] = '(其他)';
  1476. if (!empty($others)) {
  1477. $other['hasChildren'] = true;
  1478. // array_push($other,['hasChildren','=',true]);
  1479. $other['children'] = $others;
  1480. $other_choices = [$other->toArray()];
  1481. $mer_choice = array_merge($choose, $other_choices);
  1482. $value_choice = array_values($mer_choice);
  1483. } else {
  1484. // return Result::error('1111');
  1485. $other_choices = [$other->toArray()];
  1486. $other_choices = array_merge($choose, $other_choices);
  1487. $value_choice = array_values($other_choices);
  1488. // return Result::success($result);
  1489. }
  1490. } else {
  1491. $value_choice = $choose;
  1492. }
  1493. $result = [
  1494. 'choose' => $value_choice,
  1495. 'total' => $total,
  1496. ];
  1497. }
  1498. return Result::success($result);
  1499. }
  1500. /**
  1501. * 前端-搜索新闻列表
  1502. * @param array $data
  1503. * @return array
  1504. */
  1505. public function selectWebsiteArticle(array $data): array
  1506. {
  1507. $website = Website::where('id', $data['website_id'])->first();
  1508. if(empty($website)){
  1509. return Result::error("网站不存在",0);
  1510. }
  1511. // $website_column = $website['column'];
  1512. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  1513. $website_column = json_decode($website['website_column_arr_id'],true);
  1514. }
  1515. $website_id = $data['website_id'];
  1516. $categorys = $this->processArticlePro($website_id);
  1517. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1518. // return Result::success($diff_pid_categoryIds);
  1519. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1520. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1521. }
  1522. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1523. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1524. $catiall = $categorys['catiall'];
  1525. $categoryIds = $categorys['categoryIds'];
  1526. // return Result::success($categoryIds);
  1527. $query = Article::where('status', 1)
  1528. ->whereIn('catid', $categoryIds)
  1529. ->leftJoinSub(function ($query) use ($website_id) {
  1530. $query->from('article_ignore')
  1531. ->where('website_id', $website_id);
  1532. }, 'article_ignore', function ($join) {
  1533. $join->on('article_ignore.article_id', '=', 'article.id');
  1534. })
  1535. ->where(function ($query) use ($website_id) {
  1536. $query->whereNull('article_ignore.article_id')
  1537. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1538. });
  1539. // ->get()->all();
  1540. // return Result::success($query);
  1541. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1542. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1543. }
  1544. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1545. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1546. }
  1547. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1548. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1549. }
  1550. // 计算总数
  1551. $count = $query->count();
  1552. // return Result::success($count);
  1553. // 分页查询
  1554. $articles = $query
  1555. ->select(
  1556. 'article.id',
  1557. 'article.title',
  1558. 'article.imgurl',
  1559. 'article.author',
  1560. 'article.updated_at',
  1561. 'article.introduce',
  1562. 'article.islink',
  1563. 'article.linkurl',
  1564. 'article.copyfrom',
  1565. 'article.cat_arr_id',
  1566. 'article.catid',
  1567. 'article.department_arr_id',
  1568. 'article.city_arr_id',
  1569. )
  1570. ->orderBy("updated_at", "desc")
  1571. ->offset(($data['page'] - 1) * $data['pageSize'])
  1572. ->limit($data['pageSize'])
  1573. ->get();
  1574. // return Result::success($articles);
  1575. foreach ($articles as $k => $v) {
  1576. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1577. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1578. }
  1579. if (empty($articles)) {
  1580. return Result::error("没有符合条件的资讯数据");
  1581. }
  1582. $result = [
  1583. 'rows' => $articles,
  1584. 'count' => $count,
  1585. ];
  1586. return Result::success($result);
  1587. }
  1588. /**
  1589. * 模块新闻加强版
  1590. * @param array $data
  1591. * @return array
  1592. */
  1593. public function getWebsiteCatidArticle(array $data): array
  1594. {
  1595. $where = [
  1596. 'website_category.category_id' => $data['catid'],
  1597. 'website_category.website_id' => $data['website_id'],
  1598. ];
  1599. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1600. $child_catnum = $data['child_catnum'] ?? 1;
  1601. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1602. $childCategoryIds = array_column($category['child'], 'category_id');
  1603. if (empty($childCategoryIds)) {
  1604. return Result::error("暂无子栏目", 0);
  1605. }
  1606. $imgArticles = [];
  1607. $textArticles = [];
  1608. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1609. // 初始化子分类图片新闻和文字新闻数组
  1610. // 查询所有子级栏目的图文新闻
  1611. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1612. ->where(function ($query) use ($data) {
  1613. $query->where(function ($subQuery) use ($data) {
  1614. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1615. })->orWhereNull("ignore_ids");
  1616. })
  1617. ->where('status', 1)
  1618. ->where('imgurl', '!=', '')
  1619. ->select('*')
  1620. ->orderBy('updated_at', 'desc')
  1621. ->limit($data['child_imgnum'])
  1622. ->get();
  1623. }
  1624. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1625. // 查询所有子级栏目的文字新闻
  1626. $textArticles = Article::where('catid', $childCategoryIds[0])
  1627. ->where('status', 1)
  1628. ->where(function ($query) use ($data) {
  1629. $query->where(function ($subQuery) use ($data) {
  1630. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1631. })->orWhereNull("ignore_ids");
  1632. })
  1633. ->select('*')
  1634. ->orderBy('updated_at', 'desc')
  1635. ->limit($data['child_textnum'])
  1636. ->get();
  1637. }
  1638. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1639. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1640. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1641. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1642. return $child;
  1643. }, $category['child']);
  1644. }
  1645. // }
  1646. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1647. $category['img'] = WebsiteCategory::where($where)
  1648. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1649. ->where('article.status', 1)
  1650. ->where('article.imgurl', '!=', '')
  1651. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1652. ->orderBy('article.updated_at', 'desc')
  1653. ->limit($data['img_num'])
  1654. ->get();
  1655. }
  1656. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1657. $category['text'] = WebsiteCategory::where($where)
  1658. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1659. ->where('article.status', 1)
  1660. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1661. ->orderBy('article.updated_at', 'desc')
  1662. ->limit($data['text_num'])
  1663. ->get();
  1664. }
  1665. // $category = $category->get();
  1666. if (empty($category)) {
  1667. return Result::error("查询失败", 0);
  1668. }
  1669. return Result::success($category);
  1670. }
  1671. /**
  1672. * 模块新闻加强plus版
  1673. * @param array $data
  1674. * @return array
  1675. */
  1676. public function getWebsiteAllArticle(array $data): array
  1677. {
  1678. // return Result::success($data);
  1679. $time1 = microtime(true);
  1680. $wetbsite_id = $data['website_id'] ?? 2;
  1681. $data = json_decode($data['id'], true);
  1682. $website = Website::where('id', $wetbsite_id)->first();
  1683. if(empty($website)){
  1684. return Result::error("网站不存在",0);
  1685. }
  1686. // return Result::success($website);
  1687. $website_column = $website['website_column_arr_id'] ?? '[]';
  1688. $website_column = json_decode($website_column,true);
  1689. $categorys = $this->processArticlePro($wetbsite_id);
  1690. $cat_1st_arr = $categorys['cat_1st_arr'];
  1691. $catiall = $categorys['catiall'];
  1692. // return Result::success($catiall);
  1693. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1694. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1695. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1696. }
  1697. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1698. // return Result::success($categorys);
  1699. $parent_category = array_column($data, 'parent');
  1700. $parent_cat = [];
  1701. $child_category = array_column($data, 'child');
  1702. if (!empty($parent_category)) {
  1703. foreach ($parent_category as $key => $value) {
  1704. $arr = array_map('intval', explode(',', $value));
  1705. $parent_cat[$key] = $arr[0] ?? 0;
  1706. $parent_category = $arr[0] ?? 0;
  1707. $article_imgnum = $arr[1] ?? 0;
  1708. $article_textnum = $arr[2] ?? 0;
  1709. if ($parent_category != 0) {
  1710. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1711. // return Result::success($category_arr);
  1712. if ($article_imgnum != 0) {
  1713. $img_article = Article::whereIn('catid', $category_arr)
  1714. ->where('status', 1)
  1715. ->where('imgurl', '!=', '')
  1716. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1717. $query->from('article_ignore')
  1718. ->where('website_id', $wetbsite_id);
  1719. }, 'article_ignore', function ($join) {
  1720. $join->on('article_ignore.article_id', '=', 'article.id');
  1721. })
  1722. ->where(function ($query) use ($wetbsite_id) {
  1723. $query->whereNull('article_ignore.article_id')
  1724. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1725. })
  1726. ->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')
  1727. ->orderBy('updated_at', 'desc')
  1728. ->limit($article_imgnum)
  1729. ->get()->all();
  1730. foreach ($img_article as $k => $v) {
  1731. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1732. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1733. }
  1734. } else {
  1735. $img_article = [];
  1736. }
  1737. if ($article_textnum != 0) {
  1738. $text_article = Article::whereIn('catid', $category_arr)
  1739. ->where('status', 1)
  1740. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1741. $query->from('article_ignore')
  1742. ->where('website_id', $wetbsite_id);
  1743. }, 'article_ignore', function ($join) {
  1744. $join->on('article_ignore.article_id', '=', 'article.id');
  1745. })
  1746. ->where(function ($query) use ($wetbsite_id) {
  1747. $query->whereNull('article_ignore.article_id')
  1748. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1749. })
  1750. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1751. ->orderBy('updated_at', 'desc')
  1752. ->limit($article_textnum)
  1753. ->get()->all();
  1754. foreach ($text_article as $k => $v) {
  1755. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1756. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1757. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1758. }
  1759. } else {
  1760. $text_article = [];
  1761. }
  1762. $catiall[$parent_category]['imgnum'] = $img_article;
  1763. $catiall[$parent_category]['textnum'] = $text_article;
  1764. $parent[$key] = $catiall[$parent_category];
  1765. } else {
  1766. $parent[$key] = '';
  1767. }
  1768. }
  1769. }
  1770. if (!empty($child_category)) {
  1771. foreach ($child_category as $key => $value) {
  1772. $arr = array_map('intval', explode(',', $value));
  1773. $parent_category = $parent_cat[$key];
  1774. $child_category = $arr[0] ?? 0;
  1775. $article_imgnum = $arr[1] ?? 0;
  1776. $article_textnum = $arr[2] ?? 0;
  1777. if ($child_category != 0) {
  1778. $all_childcat = $cat_1st_arr[$parent_category];
  1779. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1780. // 从 $websiteInfoIndexed 中获取对应的数据
  1781. $info = $websiteInfoIndexed[$v];
  1782. // 返回一个包含所需信息的数组
  1783. return [
  1784. 'alias' => $info->alias,
  1785. 'category_id' => $info->category_id,
  1786. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1787. 'pid' => $info->pid,
  1788. 'type' => $info->type,
  1789. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1790. 'pinyin' => $info->pinyin,
  1791. ];
  1792. }, $all_childcat);
  1793. if ($article_imgnum != 0) {
  1794. $img_article = Article::where('catid', $child_category)
  1795. ->where('status', 1)
  1796. ->where('imgurl', '!=', '')
  1797. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1798. $query->from('article_ignore')
  1799. ->where('website_id', $wetbsite_id);
  1800. }, 'article_ignore', function ($join) {
  1801. $join->on('article_ignore.article_id', '=', 'article.id');
  1802. })
  1803. ->where(function ($query) use ($wetbsite_id) {
  1804. $query->whereNull('article_ignore.article_id')
  1805. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1806. })
  1807. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1808. ->orderBy('updated_at', 'desc')
  1809. ->limit($article_imgnum)
  1810. ->get()->all();
  1811. foreach ($img_article as $k => $v) {
  1812. // var_dump($v);
  1813. // var_dump($k);
  1814. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1815. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1816. }
  1817. } else {
  1818. $img_article = [];
  1819. }
  1820. if ($article_textnum != 0) {
  1821. $text_article = Article::where('catid', $child_category)
  1822. ->where('status', 1)
  1823. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1824. $query->from('article_ignore')
  1825. ->where('website_id', $wetbsite_id);
  1826. }, 'article_ignore', function ($join) {
  1827. $join->on('article_ignore.article_id', '=', 'article.id');
  1828. })
  1829. ->where(function ($query) use ($wetbsite_id) {
  1830. $query->whereNull('article_ignore.article_id')
  1831. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1832. })
  1833. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1834. ->orderBy('updated_at', 'desc')
  1835. ->limit($article_textnum)
  1836. ->get()->all();
  1837. foreach ($text_article as $k => $v) {
  1838. // var_dump($v);
  1839. // var_dump($k);
  1840. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1841. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1842. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1843. }
  1844. } else {
  1845. $text_article = [];
  1846. }
  1847. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1848. $catiall[$child_category]['imgnum'] = $img_article;
  1849. $catiall[$child_category]['textnum'] = $text_article;
  1850. $child[$key] = $catiall[$child_category];
  1851. // var_dump($pids);
  1852. } else {
  1853. $child[$key] = '';
  1854. }
  1855. }
  1856. }
  1857. foreach ($parent as $key => $value) {
  1858. $result[$key] = $value;
  1859. if (!empty($child[$key])) {
  1860. // var_dump($child[$key]);
  1861. $result[$key]['child'] = $child[$key];
  1862. // $value[$key]['child'] = $child[$key];
  1863. } else {
  1864. $result[$key]['child'] = [
  1865. "alias" => null,
  1866. "category_id" => null,
  1867. "type" => null,
  1868. "pinyin" => null,
  1869. "all_childcat" => [],
  1870. "imgnum" => [],
  1871. "textnum" => []
  1872. ];
  1873. }
  1874. }
  1875. return Result::success($result);
  1876. }
  1877. /**
  1878. * 辅助方法:获取文章列表
  1879. */
  1880. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1881. {
  1882. sleep(1);
  1883. $query = Article::where('article.status', 1)
  1884. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1885. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1886. ->where(function ($query) use ($website) {
  1887. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1888. })
  1889. ->leftJoin('website_category', function ($join) use ($website) {
  1890. $join->on('article.catid', '=', 'website_category.category_id')
  1891. ->where('website_category.website_id', '=', $website['website_id']);
  1892. })
  1893. ->select(
  1894. 'article.id',
  1895. 'article.title',
  1896. 'article.imgurl',
  1897. 'article.author',
  1898. 'article.updated_at',
  1899. 'article.introduce',
  1900. 'article.islink',
  1901. 'article.linkurl',
  1902. 'article.copyfrom',
  1903. 'article.cat_arr_id',
  1904. 'article.catid',
  1905. 'website_category.alias as category_name'
  1906. )
  1907. ->orderBy('updated_at', 'desc')
  1908. ->limit($limit);
  1909. // 如果是图片文章,添加图片URL条件
  1910. if ($isImageArticle) {
  1911. $query->where('imgurl', '!=', '');
  1912. } else {
  1913. // 文字文章不需要imgurl字段
  1914. $query->addSelect('article.introduce');
  1915. }
  1916. $articles = $query->get();
  1917. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1918. }
  1919. /**
  1920. * 乡村网-获取特殊新闻模块
  1921. * @param array $data
  1922. * @return array
  1923. */
  1924. public function getWebsiteArticles(array $data): array
  1925. {
  1926. $website_id = $data['website_id'];
  1927. $website = Website::where('id', $website_id)->first();
  1928. if(empty($website)){
  1929. return Result::error("网站不存在",0);
  1930. }
  1931. // return Result::success($website);
  1932. $website_column = $website['website_column_arr_id'] ?? '[]';
  1933. $website_column = json_decode($website_column, true);
  1934. $catids = json_decode($data['id'], true);
  1935. $parent_category = array_column($catids, 'parent');
  1936. if(!empty($parent_category) && is_array($parent_category)) {
  1937. $categorys = $this->processArticlePro($website_id);
  1938. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1939. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1940. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1941. }
  1942. $catiall = $categorys['catiall'];
  1943. $cat_1st_arr = $categorys['cat_1st_arr'];
  1944. // return Result::success($categorys);
  1945. foreach ($parent_category as $key => $value) {
  1946. $arr = array_map('intval', explode(',', $value));
  1947. $parent_category = $arr[0] ?? 0;
  1948. $article_imgnum = $arr[1] ?? 0;
  1949. $article_textnum = $arr[2] ?? 0;
  1950. if ($parent_category != 0) {
  1951. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1952. // return Result::success($category_arr);
  1953. if ($article_imgnum != 0) {
  1954. $img_article = Article::whereIn('catid', $category_arr)
  1955. ->where('status', 1)
  1956. ->where('imgurl', '!=', '')
  1957. ->leftJoinSub(function ($query) use ($website_id) {
  1958. $query->from('article_ignore')
  1959. ->where('website_id', $website_id);
  1960. }, 'article_ignore', function ($join) {
  1961. $join->on('article_ignore.article_id', '=', 'article.id');
  1962. })
  1963. ->where(function ($query) use ($website_id) {
  1964. $query->whereNull('article_ignore.article_id')
  1965. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1966. })
  1967. ->select(
  1968. 'id',
  1969. 'title',
  1970. 'imgurl',
  1971. 'author',
  1972. 'updated_at',
  1973. 'introduce',
  1974. 'islink',
  1975. 'linkurl',
  1976. 'copyfrom',
  1977. 'cat_arr_id',
  1978. 'catid as category_id'
  1979. )
  1980. ->orderBy('updated_at', 'desc')
  1981. ->limit($article_imgnum)
  1982. ->get()->all();
  1983. foreach ($img_article as $k => $v) {
  1984. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1985. // return Result::success($v);
  1986. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1987. }
  1988. } else {
  1989. $img_article = [];
  1990. }
  1991. if ($article_textnum != 0) {
  1992. $text_article = Article::whereIn('catid', $category_arr)
  1993. ->where('status', 1)
  1994. ->leftJoinSub(function ($query) use ($website_id) {
  1995. $query->from('article_ignore')
  1996. ->where('website_id', $website_id);
  1997. }, 'article_ignore', function ($join) {
  1998. $join->on('article_ignore.article_id', '=', 'article.id');
  1999. })
  2000. ->where(function ($query) use ($website_id) {
  2001. $query->whereNull('article_ignore.article_id')
  2002. ->orWhere('article_ignore.website_id', '!=', $website_id);
  2003. })
  2004. ->select(
  2005. 'id',
  2006. 'title',
  2007. 'author',
  2008. 'updated_at',
  2009. 'introduce',
  2010. 'islink',
  2011. 'linkurl',
  2012. 'copyfrom',
  2013. 'cat_arr_id',
  2014. 'catid as category_id'
  2015. )
  2016. ->orderBy('updated_at', 'desc')
  2017. ->limit($article_textnum)
  2018. ->get()->all();
  2019. foreach ($text_article as $k => $v) {
  2020. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2021. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2022. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2023. }
  2024. } else {
  2025. $text_article = [];
  2026. }
  2027. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2028. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2029. $parent[$key] = $catiall[$parent_category];
  2030. } else {
  2031. $parent[$key] = [];
  2032. }
  2033. }
  2034. }
  2035. return Result::success($parent);
  2036. }
  2037. // 封装处理商品的路由问题
  2038. function processGoods($goods, $data)
  2039. {
  2040. return $goods->map(function ($good) use ($data) {
  2041. $catid = $good->catid ?? 0;
  2042. // $pinyin = '';
  2043. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2044. if (!empty($category->pid) && $category->pid != 0) {
  2045. $level = json_decode($category->category_arr_id, true);
  2046. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2047. ->whereIn('category_id', $level)
  2048. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2049. ->get(['aLIas_pinyin'])
  2050. ->pluck('aLIas_pinyin')
  2051. ->implode('/');
  2052. } else {
  2053. $pinyin = $category->aLIas_pinyin ?? '';
  2054. }
  2055. if (isset($good->city_id) && !empty($good->city_id)) {
  2056. $city = District::where('id', $good->city_id)->first(['name']);
  2057. $good->city_name = $city->name ?? '';
  2058. }
  2059. // 解析imgurl JSON并取第一条数据
  2060. $imgUrls = json_decode($good->imgurl, true);
  2061. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2062. $good->pinyin = $pinyin;
  2063. return $good;
  2064. });
  2065. }
  2066. /**
  2067. * 获取商城首页-根据栏目id
  2068. * @param array $data
  2069. * @return array
  2070. * */
  2071. function getWebsiteCatidshop(array $data): array
  2072. {
  2073. $input['catid'] = $data['catid'];
  2074. $input['website_id'] = $data['website_id'];
  2075. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2076. $result = array_map(function ($item) use ($input) {
  2077. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2078. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2079. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2080. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2081. if (empty($category) || $category->type != 2) {
  2082. return Result::error("暂无此栏目", 0);
  2083. } else {
  2084. $website['website_id'] = $input['website_id'];
  2085. $goods = Good::where('good.status', 2)
  2086. ->where('good.website_id', $website['website_id'])
  2087. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2088. ->select(
  2089. 'good.id',
  2090. 'good.name',
  2091. 'good.imgurl',
  2092. 'good.description',
  2093. 'good.updated_at',
  2094. 'good.catid',
  2095. 'good.type_id',
  2096. 'good.price',
  2097. 'good.com',
  2098. 'good.level',
  2099. 'good.unit'
  2100. )
  2101. ->orderBy('updated_at', 'desc')
  2102. ->offset($goodStart)
  2103. ->limit($goodNum);
  2104. $all_goods = $goods->get();
  2105. $all_goods = $this->processGoods($all_goods, $website);
  2106. }
  2107. return $all_goods ?? [];
  2108. }
  2109. }, $data);
  2110. return Result::success($result);
  2111. }
  2112. /**
  2113. * 获取商品模块
  2114. * @param array $data
  2115. * @return array
  2116. * */
  2117. public function getWebsiteshop(array $data): array
  2118. {
  2119. $input['id'] = $data['id'];
  2120. $input['website_id'] = $data['website_id'];
  2121. $catid = $data['catid'];
  2122. $data = json_decode($input['id'] ?? '', true) ?? [];
  2123. $result['goods'] = array_map(function ($item) use ($input) {
  2124. // 检查parent元素是否存在且不是undefined
  2125. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2126. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2127. $website = $input['website_id'];
  2128. $query = Good::where('good.status', 2)
  2129. ->where('good.website_id', $website);
  2130. switch ($Levelid) {
  2131. case 1:
  2132. case 2:
  2133. case 3:
  2134. $goods = $query->where(function ($q) use ($Levelid) {
  2135. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2136. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2137. });
  2138. break;
  2139. case 4:
  2140. $goods = $query;
  2141. break;
  2142. case 5:
  2143. $goods = $query->where('type_id', 1);
  2144. break;
  2145. case 6:
  2146. $goods = $query->where('type_id', 2);
  2147. break;
  2148. default:
  2149. return [];
  2150. }
  2151. $all_goods = $goods
  2152. ->select(
  2153. 'good.id',
  2154. 'good.name',
  2155. 'good.imgurl',
  2156. 'good.description',
  2157. 'good.updated_at',
  2158. 'good.catid',
  2159. 'good.type_id',
  2160. 'good.price',
  2161. 'good.level',
  2162. 'good.website_id'
  2163. )
  2164. ->orderBy('updated_at', 'desc')
  2165. ->offset($goodStart)
  2166. ->limit($goodNum)
  2167. ->get();
  2168. $web['website_id'] = $website;
  2169. $all_goods = $this->processGoods($all_goods, $web);
  2170. }
  2171. return $all_goods;
  2172. }, $data);
  2173. $website = $input['website_id'];
  2174. $result['article'] = Article::where(function ($query) use ($website) {
  2175. $query->where(function ($subQuery) use ($website) {
  2176. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2177. })->orWhereNull("ignore_ids");
  2178. })
  2179. ->where('catid', $catid)
  2180. ->where('article.status', 1)
  2181. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2182. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2183. ->orderBy('article.updated_at', 'desc')
  2184. ->first();
  2185. return Result::success($result);
  2186. }
  2187. /**
  2188. * 获取商品分类
  2189. * @param array $data
  2190. * @return array
  2191. * */
  2192. public function getWebsiteshopCat(array $data): array
  2193. {
  2194. $website = $data['website_id'];
  2195. $category = WebsiteCategory::where('website_id', $website)
  2196. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2197. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2198. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2199. ->orderBy('sort')
  2200. ->get();
  2201. $cat = $category->map(function ($item) use ($website) {
  2202. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2203. $pid = $item->pid ?? 0;
  2204. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2205. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2206. ->where('website_id', $website)
  2207. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2208. ->get(['aLIas_pinyin'])
  2209. ->pluck('aLIas_pinyin')
  2210. ->implode('/');
  2211. } else {
  2212. $pinyin = $item->aLIas_pinyin ?? '';
  2213. }
  2214. $item->pinyin = $pinyin;
  2215. });
  2216. if (empty($category)) {
  2217. return Result::error("栏目查询失败", 0);
  2218. }
  2219. $cat_tree = Result::buildMenuTree($category);
  2220. $web['website_id'] = $website;
  2221. $goods = Good::where('website_id', $website)
  2222. ->where('status', 2)
  2223. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2224. ->latest('updated_at')
  2225. ->offset(($data['page'] - 1) * $data['pageSize'])
  2226. ->limit($data['pageSize'])
  2227. ->get();
  2228. if (!empty($goods)) {
  2229. if ($goods->count() > 1 && !empty($goods)) {
  2230. $goods = $this->processGoods($goods, $web);
  2231. }
  2232. } else {
  2233. $goods = [];
  2234. }
  2235. $result = [
  2236. 'category' => $cat_tree,
  2237. 'goods' => $goods,
  2238. ];
  2239. // $resul['goods'] = $goods;
  2240. if (empty($result)) {
  2241. return Result::error("查询失败", 0);
  2242. }
  2243. return Result::success($result);
  2244. }
  2245. /*
  2246. * 获取商品列表
  2247. * @param array $data
  2248. * @return array
  2249. * */
  2250. public function getWebsiteshopList(array $data): array
  2251. {
  2252. // return Result::success($data);
  2253. $where = [
  2254. 'status' => 2,
  2255. 'website_id' => $data['website_id'],
  2256. ];
  2257. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2258. // return Result::error("查询失败", 0);
  2259. // }
  2260. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2261. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2262. $data['catid'] = $category->category_id ?? 0;
  2263. }
  2264. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2265. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2266. }
  2267. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2268. array_push($where, ['type_id', $data['type_id']]);
  2269. }
  2270. $query = Good::where($where)
  2271. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2272. $query->where(function ($q) use ($data) {
  2273. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2274. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2275. });
  2276. })
  2277. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2278. $query->where(function ($q) use ($data) {
  2279. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2280. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2281. });
  2282. })
  2283. ->select(
  2284. 'good.id',
  2285. 'good.name',
  2286. 'good.imgurl',
  2287. 'good.description',
  2288. 'good.updated_at',
  2289. 'good.com',
  2290. 'good.catid',
  2291. 'good.type_id',
  2292. 'good.website_id',
  2293. 'good.cat_arr_id',
  2294. 'good.created_at',
  2295. 'good.city_id'
  2296. )
  2297. ->latest('updated_at');
  2298. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2299. $result['count'] = $query->clone()->count();
  2300. $result['goods'] = $this->processGoods(
  2301. $query->clone()
  2302. ->offset(($data['page'] - 1) * $data['pageSize'])
  2303. ->limit($data['pageSize'])
  2304. ->get(),
  2305. $data
  2306. );
  2307. } else {
  2308. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2309. // 获取 type_id 为 1 的数据
  2310. $result['type1'] = $this->processGoods(
  2311. $query->clone()
  2312. ->where('type_id', 1)
  2313. ->offset(($data['page'] - 1) * $data['pageSize'])
  2314. ->limit($data['pageSize'])
  2315. ->get(),
  2316. $data
  2317. );
  2318. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2319. // 获取 type_id 为 2 的数据
  2320. $result['type2'] = $this->processGoods(
  2321. $query->clone()
  2322. ->where('type_id', 2)
  2323. ->offset(($data['page'] - 1) * $data['pageSize'])
  2324. ->limit($data['pageSize'])
  2325. ->get(),
  2326. $data
  2327. );
  2328. }
  2329. if (empty($result)) {
  2330. return Result::error("查询失败", 0);
  2331. }
  2332. return Result::success($result);
  2333. }
  2334. /**
  2335. * 获取商品详情
  2336. * @param array $data
  2337. * @return array
  2338. * */
  2339. public function getWebsiteshopInfo(array $data): array
  2340. {
  2341. $where = [
  2342. 'good.status' => 2,
  2343. 'good.website_id' => $data['website_id'],
  2344. 'good.id' => $data['id'],
  2345. ];
  2346. $goods = Good::where($where)
  2347. ->where('good.id', $data['id'])
  2348. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2349. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2350. ->first();
  2351. if (empty($goods)) {
  2352. return Result::error("查询失败", 0);
  2353. }
  2354. $goods->imgurl = json_decode($goods->imgurl, true);
  2355. return Result::success($goods);
  2356. }
  2357. /**
  2358. * plus pro 处理文章路由问题
  2359. */
  2360. function processArticlePro($website_id)
  2361. {
  2362. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2363. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2364. // // 取出category_id 对应的aLIas_pinyin
  2365. // $categoryIds = array_column($categorys, 'category_id');
  2366. // $categoryPIds = array_column($categorys, 'pid');
  2367. // $aliasPinyins = array_column($categorys, 'path');
  2368. // $alias = array_column($categorys, 'alias');
  2369. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2370. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2371. // // return Result::success($cat_arr);
  2372. // // $catiall = [];
  2373. // //一级所有子级的记录
  2374. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2375. // return [
  2376. // 'cat_1st_arr' => $cat_alias_arr,
  2377. // 'catiall' => $cat_arr,
  2378. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2379. // 'categoryIds' => $categoryIds,
  2380. // ];
  2381. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2382. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2383. // 取出category_id 对应的aLIas_pinyin
  2384. $categoryIds = array_column($categorys, 'category_id');
  2385. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function($pid) {
  2386. return $pid != 0;
  2387. })));
  2388. $category_path = array_column($categorys, 'path');
  2389. $cat_arr = array_combine($categoryIds, $category_path);
  2390. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2391. $catiall = [];
  2392. //一级所有子级的记录
  2393. $cat_1st_arr = [];
  2394. foreach ($categorys as $key => $value) {
  2395. // $category_arr_id = json_decode($value->category_arr_id);
  2396. // $pinyin_str = '';
  2397. // // 算出一级 并且算出子级
  2398. if ($value->pid != 0 && in_array($value->pid,$categoryIds)) {
  2399. $cat_1st_arr[$value->pid][] = $value->category_id;
  2400. }
  2401. // foreach ($category_arr_id as $k => $v) {
  2402. // $pinyin_str .= $cat_arr[$v] . '/';
  2403. // }
  2404. // $pinyin_str = rtrim($pinyin_str, '/');
  2405. $catiall[$value->category_id]['alias'] = $value->alias;
  2406. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2407. $catiall[$value->category_id]['type'] = $value->type;
  2408. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2409. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2410. }
  2411. return [
  2412. 'cat_1st_arr' => $cat_1st_arr,
  2413. 'catiall' => $catiall,
  2414. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2415. 'categoryIds' => $categoryIds,
  2416. 'diff_pid_categoryIds' => array_diff($categoryPIds,$categoryIds),
  2417. 'categoryPIds' => $categoryPIds,
  2418. ];
  2419. }
  2420. /**
  2421. * 封装处理文章的路由问题
  2422. * */
  2423. function processArticles($articles, $data)
  2424. {
  2425. // 检查 $articles 是否为数组或可迭代对象
  2426. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2427. return $articles->map(function ($article) use ($data) {
  2428. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2429. $catid = $article->cat_arr_id ?? '';
  2430. }
  2431. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2432. $catid = $article->category_arr_id ?? '';
  2433. }
  2434. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2435. $level = json_decode($catid, true);
  2436. if (!is_array($level)) {
  2437. return $article;
  2438. } else {
  2439. $level = array_map('intval', $level);
  2440. }
  2441. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2442. ->where($data)
  2443. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2444. ->pluck('aLIas_pinyin')
  2445. ->implode('/');
  2446. $article->pinyin = $pinyin ?? '';
  2447. return $article;
  2448. });
  2449. } else {
  2450. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2451. $catid = $articles->cat_arr_id ?? '';
  2452. $level = json_decode($catid, true);
  2453. if (!is_array($level)) {
  2454. return $articles;
  2455. } else {
  2456. $level = array_map('intval', $level);
  2457. }
  2458. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2459. ->where($data)
  2460. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2461. ->pluck('aLIas_pinyin')
  2462. ->implode('/');
  2463. $articles->pinyin = $pinyin ?? '';
  2464. return $articles;
  2465. }
  2466. }
  2467. // 封装处理由问题
  2468. function processJob($job, $data)
  2469. {
  2470. return $job->map(function ($job) use ($data) {
  2471. $category = $job->cat_arr_id ?? '';
  2472. $cityid = $job->city_arr_id ?? '';
  2473. $city = json_decode($cityid, true);
  2474. $pinyin = '';
  2475. $level = json_decode($category, true);
  2476. // 路由
  2477. if (!empty($level) && is_array($level)) {
  2478. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2479. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2480. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2481. ->get(['aLIas_pinyin'])
  2482. ->pluck('aLIas_pinyin')
  2483. ->implode('/');
  2484. if (empty($pinyin)) {
  2485. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2486. }
  2487. $job->pinyin = $pinyin;
  2488. }
  2489. // 取职位-城市 市??省
  2490. if (!empty($city) && is_array($city)) {
  2491. if (isset($city[1]) && !empty($city[1])) {
  2492. $city = District::where('id', $city[1])->first(['name']);
  2493. $job->city_name = $city->name ?? '';
  2494. } else if (isset($city[0]) && !empty($city[0])) {
  2495. $city = District::where('id', $city[0])->first(['name']);
  2496. $job->city_name = $city->name ?? '';
  2497. } else {
  2498. $job->city_name = '全国';
  2499. }
  2500. }
  2501. // 获取简历最后一级地区
  2502. if (isset($job->city_id) && !empty($job->city_id)) {
  2503. $city = District::where('id', $job->city_id)->first(['name']);
  2504. $job->hunt_cityname = $city->name ?? '';
  2505. }
  2506. // 组合详细地址
  2507. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2508. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2509. if (is_array($address_id) && !empty($address_id)) {
  2510. $address = District::whereIn('id', $address_id)
  2511. ->orderBy('level', 'asc')
  2512. ->get(['name'])
  2513. ->pluck('name')
  2514. ->implode('');
  2515. // $job->address_name = $address ?? '';
  2516. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2517. }
  2518. }
  2519. // 取行业
  2520. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2521. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2522. if (!empty($job->industry)) {
  2523. $query->where('hyid', $job->industry);
  2524. } else if (!empty($job->hy_id)) {
  2525. $query->where('hyid', $job->hy_id);
  2526. } else if (!empty($job->company_hy_id)) {
  2527. $query->where('hyid', $job->company_hy_id);
  2528. } else {
  2529. $query->where('hyid', $job->job_industry);
  2530. }
  2531. })->first(['hyname']);
  2532. $job->hy_name = $hy_name->hyname ?? '';
  2533. }
  2534. // 取职位类别
  2535. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2536. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2537. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2538. $job->zw_name = $zw_name->zwname ?? '';
  2539. }
  2540. // 取具体职位
  2541. 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))) {
  2542. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2543. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2544. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2545. }
  2546. // 取工作经验
  2547. if (isset($job->experience) && !empty($job->experience)) {
  2548. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2549. $job->experience_name = $experience->ename ?? '';
  2550. }
  2551. // 取学历
  2552. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2553. $education = $job->educational ?? $job->school_education;
  2554. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2555. $job->education_name = $education->ename ?? '';
  2556. }
  2557. // 语言
  2558. if (isset($job->language) && !empty($job->language)) {
  2559. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2560. $job->language_name = $language->ename ?? '';
  2561. }
  2562. // 薪资
  2563. if (isset($job->salary) && !empty($job->salary)) {
  2564. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2565. $job->salary_name = $salary->ename ?? '';
  2566. }
  2567. // 职位性质
  2568. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2569. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2570. $job->job_nature_name = $job_nature->ename ?? '';
  2571. }
  2572. // 公司规模
  2573. if (isset($job->company_size) && !empty($job->company_size)) {
  2574. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2575. $job->company_size_name = $company_size->ename ?? '';
  2576. }
  2577. // 公司性质
  2578. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2579. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2580. $job->company_nature_name = $company_nature->nature_name ?? '';
  2581. }
  2582. // $job->pinyin = $pinyin;
  2583. return $job;
  2584. });
  2585. }
  2586. /**
  2587. * 获取书籍模块
  2588. * @param array $data
  2589. * @return array
  2590. * */
  2591. public function getWebsiteBook(array $data): array
  2592. {
  2593. $input['id'] = $data['id'];
  2594. $input['website_id'] = $data['website_id'];
  2595. // 将 JSON 字符串转换为 PHP 数组
  2596. $data = json_decode($input['id'], true);
  2597. // 使用 array_map 处理每个元素
  2598. $result = array_map(function ($item) use ($input) {
  2599. // 检查parent元素是否存在且不是undefined
  2600. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2601. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2602. $website = [
  2603. 'website_id' => $input['website_id'],
  2604. ];
  2605. // 查询栏目名称
  2606. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2607. if (empty($category)) {
  2608. $parent_alias = '';
  2609. $parent_pinyin = null;
  2610. $imgBooks = [];
  2611. $textBooks = [];
  2612. } else {
  2613. $parent_alias = $category->alias ?? '';
  2614. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2615. // 查找子分类ID数组
  2616. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2617. array_push($childCategoryIds, $parentCatId);
  2618. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2619. if ($parentImgNum != 0) {
  2620. // 查询图片新闻
  2621. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2622. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2623. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2624. })
  2625. ->where('book.status', 2)
  2626. ->where('book.img_url', '!=', '')
  2627. ->where('book.website_id', $website['website_id'])
  2628. ->leftJoin('website_category', function ($join) use ($website) {
  2629. $join->on('book.cat_id', '=', 'website_category.category_id')
  2630. ->where('website_category.website_id', '=', $website['website_id']);
  2631. })
  2632. ->select(
  2633. 'book.id',
  2634. 'book.title',
  2635. 'book.img_url',
  2636. 'book.price',
  2637. 'book.market_price',
  2638. 'book.description',
  2639. 'book.cat_id',
  2640. 'book.description',
  2641. 'book.updated_at',
  2642. 'website_category.alias as category_name',
  2643. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2644. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2645. )
  2646. ->orderBy('updated_at', 'desc')
  2647. ->limit($parentImgNum)
  2648. ->get()->all();
  2649. // 查询文字新闻
  2650. }
  2651. if ($parentTextNum != 0) {
  2652. $textBooks = [];
  2653. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2654. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2655. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2656. })
  2657. ->where('book.status', 2)
  2658. ->where('book.website_id', $website['website_id'])
  2659. ->leftJoin('website_category', function ($join) use ($website) {
  2660. $join->on('book.cat_id', '=', 'website_category.category_id')
  2661. ->where('website_category.website_id', '=', $website['website_id']);
  2662. })
  2663. ->select(
  2664. 'book.id',
  2665. 'book.title',
  2666. 'book.img_url',
  2667. 'book.price',
  2668. 'book.market_price',
  2669. 'book.description',
  2670. 'book.cat_id',
  2671. 'book.description',
  2672. 'book.updated_at',
  2673. 'website_category.alias as category_name',
  2674. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2675. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2676. )
  2677. ->orderBy('updated_at', 'desc')
  2678. ->limit($parentTextNum)
  2679. ->get()->all();
  2680. }
  2681. }
  2682. }
  2683. $resultItem = [
  2684. 'alias' => $parent_alias ?? '',
  2685. 'category_id' => $parentCatId ?? 0,
  2686. 'pinyin' => $parent_pinyin ?? null,
  2687. 'imgnum' => $imgBooks ?? [],
  2688. 'textnum' => $textBooks ?? [],
  2689. ];
  2690. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2691. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2692. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2693. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2694. ->get()->all();
  2695. if (!empty($childCategory)) {
  2696. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2697. // 查询子栏目名称
  2698. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2699. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2700. ->first();
  2701. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2702. $childImgArticles = [];
  2703. $childTextArticles = [];
  2704. $resultItem['child'] = [];
  2705. } else {
  2706. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2707. // 查询子栏目图片新闻
  2708. $childImgArticles = Book::where('cat_id', $childCatId)
  2709. ->where('status', 2)
  2710. ->where('img_url', '!=', '')
  2711. ->where('book.website_id', $website['website_id'])
  2712. ->leftJoin('website_category', function ($join) use ($website) {
  2713. $join->on('book.cat_id', '=', 'website_category.category_id')
  2714. ->where('website_category.website_id', '=', $website['website_id']);
  2715. })
  2716. ->select(
  2717. 'book.id',
  2718. 'book.title',
  2719. 'book.img_url',
  2720. 'book.price',
  2721. 'book.market_price',
  2722. 'book.description',
  2723. 'book.cat_id',
  2724. 'book.description',
  2725. 'book.updated_at',
  2726. DB::raw("'$child_pinyin' as pinyin")
  2727. )
  2728. ->orderBy('updated_at', 'desc')
  2729. ->limit($childImgNum)
  2730. ->get()->all();
  2731. // 查询子栏目文字新闻
  2732. $childTextArticles = Book::where('cat_id', $childCatId)
  2733. ->where('status', 2)
  2734. ->where('book.website_id', $website['website_id'])
  2735. ->leftJoin('website_category', function ($join) use ($website) {
  2736. $join->on('book.cat_id', '=', 'website_category.category_id')
  2737. ->where('website_category.website_id', '=', $website['website_id']);
  2738. })
  2739. ->select(
  2740. 'book.id',
  2741. 'book.title',
  2742. 'book.img_url',
  2743. 'book.price',
  2744. 'book.market_price',
  2745. 'book.description',
  2746. 'book.cat_id',
  2747. 'book.description',
  2748. 'book.updated_at',
  2749. DB::raw("'$child_pinyin' as pinyin")
  2750. )
  2751. ->orderBy('updated_at', 'desc')
  2752. ->limit($childTextNum)
  2753. ->get()->all();
  2754. $resultItem['child'] = [
  2755. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2756. 'category_id' => $childCatId,
  2757. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2758. 'all_childcat' => $childCategory,
  2759. 'imgnum' => $childImgArticles,
  2760. 'textnum' => $childTextArticles,
  2761. ];
  2762. }
  2763. }
  2764. } else {
  2765. $resultItem['child'] = [];
  2766. }
  2767. return $resultItem;
  2768. }, $data);
  2769. return Result::success($result);
  2770. }
  2771. /**
  2772. * 获取书刊列表
  2773. * @param array $data
  2774. * @return array
  2775. * */
  2776. public function getWebsiteBookList(array $data): array
  2777. {
  2778. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2779. if (empty($web)) {
  2780. return Result::error("查询失败", 0);
  2781. }
  2782. $catid = $data['id'];
  2783. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2784. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2785. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2786. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2787. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2788. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2789. ->where('pid', $category['pid'])
  2790. ->select(
  2791. 'category_id',
  2792. 'alias',
  2793. 'aLIas_pinyin',
  2794. 'pid',
  2795. 'sort',
  2796. 'is_url',
  2797. 'web_url',
  2798. 'seo_title',
  2799. 'seo_keywords',
  2800. 'seo_description',
  2801. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2802. )
  2803. ->orderBy('sort')
  2804. ->get()->all();
  2805. if (empty($category)) {
  2806. return Result::error("查询失败", 0);
  2807. }
  2808. $query = Book::where('book.status', 2)
  2809. ->where('book.website_id', $data['website_id'])
  2810. ->where('book.cat_id', $catid)
  2811. ->select(
  2812. 'book.id',
  2813. 'book.title',
  2814. 'book.img_url',
  2815. 'book.description',
  2816. 'book.updated_at',
  2817. 'book.cat_id',
  2818. DB::raw("'$pinyin' as pinyin")
  2819. )
  2820. ->orderBy('book.updated_at', 'desc');
  2821. $count = $query->count();
  2822. $query = clone $query;
  2823. $Book = $query
  2824. ->limit($data['pageSize'])
  2825. ->offset(($data['page'] - 1) * $data['pageSize'])
  2826. ->get()->all();
  2827. $result = [
  2828. 'category' => $categorys,
  2829. 'books' => $Book,
  2830. 'count' => $count,
  2831. ];
  2832. // if(empty($result)){
  2833. // return Result::error("查询失败", 0);
  2834. // }
  2835. return Result::success($result);
  2836. }
  2837. /**
  2838. * 获取书刊详情
  2839. * @param array $data
  2840. * @return array
  2841. * */
  2842. public function getWebsiteBookInfo(array $data): array
  2843. {
  2844. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2845. if (empty($web)) {
  2846. return Result::error("查询失败", 0);
  2847. }
  2848. $book = Book::where('status', 2)
  2849. ->where('website_id', $data['website_id'])
  2850. ->where('id', $data['id'])
  2851. ->select(
  2852. 'book.*',
  2853. )
  2854. ->orderBy('updated_at', 'desc')
  2855. ->first();
  2856. if (empty($book)) {
  2857. return Result::error("查询失败", 0);
  2858. }
  2859. // 先查询当前分类的 pid
  2860. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2861. ->where('category_id', $book['cat_id'])
  2862. ->first(['pid', 'category_id']);
  2863. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2864. if (!empty($carpid)) {
  2865. if ($carpid->pid != 0) {
  2866. $pid = $carpid['pid'];
  2867. // $parent_pinyin = '';
  2868. } else {
  2869. $pid = $carpid['category_id'];
  2870. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2871. }
  2872. }
  2873. $categorys = $query->where('pid', $pid)
  2874. ->select(
  2875. 'category_id',
  2876. 'alias',
  2877. 'aLIas_pinyin',
  2878. 'pid',
  2879. 'sort',
  2880. 'is_url',
  2881. 'web_url',
  2882. 'category_arr_id as cat_arr_id',
  2883. )
  2884. ->orderBy('sort')
  2885. ->get();
  2886. $category = $this->processArticle($categorys, $data);
  2887. $result = [
  2888. 'category' => $category,
  2889. 'books' => $book,
  2890. ];
  2891. return Result::success($result);
  2892. }
  2893. /**
  2894. * 尝试
  2895. * @param array $data
  2896. * @return array
  2897. * */
  2898. public function test(array $data): array
  2899. {
  2900. $input['id'] = $data['id'];
  2901. $input['website_id'] = $data['website_id'];
  2902. // 将 JSON 字符串转换为 PHP 数组
  2903. $data = json_decode($input['id'], true);
  2904. $result = [];
  2905. $article = $data;
  2906. $result = array_map(function ($item) use ($input) {
  2907. $website = [
  2908. 'website_id' => $input['website_id'],
  2909. ];
  2910. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2911. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2912. $parent = [
  2913. 0 => $category['category_id'] ?? [],
  2914. 1 => $parentImgNum ?? [],
  2915. 2 => $parentTextNum ?? [],
  2916. ];
  2917. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2918. $child = [];
  2919. $resultItem = [
  2920. // 'alias' => $parent_alias ?? '',
  2921. 'category_id' => $parentCatId ?? 0,
  2922. 'pinyin' => $parentImgNum ?? null,
  2923. 'imgnum' => $parentTextNum ?? [],
  2924. // 'textnum' => $textArticles ?? [],
  2925. ];
  2926. return $parent;
  2927. }, $data);
  2928. return Result::success($result);
  2929. // });
  2930. }
  2931. /**
  2932. * 封装处理文章的路由问题
  2933. * */
  2934. function processArticle($article, $data)
  2935. {
  2936. return $article->map(function ($article) use ($data) {
  2937. $catid = $article->cat_arr_id ?? '';
  2938. $level = json_decode($catid, true);
  2939. $pinyin = '';
  2940. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2941. if (!empty($level) && is_array($level)) {
  2942. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2943. ->where('website_id', $data['website_id'])
  2944. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2945. ->get(['aLIas_pinyin'])
  2946. ->pluck('aLIas_pinyin')
  2947. ->implode('/');
  2948. } else {
  2949. $pinyin = '';
  2950. }
  2951. $article->pinyin = $pinyin;
  2952. return $article;
  2953. });
  2954. }
  2955. /**
  2956. * c端-获取招工招聘下拉选框
  2957. * @param array $data
  2958. * @return array
  2959. * */
  2960. public function getWebsiteJobSelect(array $data): array
  2961. {
  2962. $web = Website::where('id', $data['website_id'])->first();
  2963. if (empty($web)) {
  2964. return Result::error("该网站不存在", 0);
  2965. }
  2966. $hy = JobIndustry::get()->all();
  2967. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2968. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2969. $result = [
  2970. 'hy' => $hy,
  2971. 'zw' => $zw,
  2972. 'jtzw' => $jtzw,
  2973. ];
  2974. if (empty($result)) {
  2975. return Result::error("查询失败", 0);
  2976. }
  2977. return Result::success($result);
  2978. }
  2979. /**
  2980. * c端-获取招工招聘
  2981. * @param array $data
  2982. * @return array
  2983. * */
  2984. public function getWebsiteJob(array $data): array
  2985. {
  2986. $web = Website::where('id', $data['website_id'])->first();
  2987. if (empty($web)) {
  2988. return Result::error("该网站不存在", 0);
  2989. }
  2990. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2991. ->where('job_hunting.website_id', $data['website_id'])
  2992. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2993. $query->where(function ($q) use ($data) {
  2994. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2995. });
  2996. })
  2997. ->select(
  2998. 'job_hunting.id',
  2999. 'job_hunting.catid',
  3000. 'job_hunting.cat_arr_id',
  3001. 'job_hunting.job_name_get',
  3002. 'job_hunting.industry',
  3003. 'job_hunting.name',
  3004. 'job_hunting.sexy',
  3005. 'job_hunting.origin',
  3006. 'job_hunting.city_arr_id',
  3007. 'job_hunting.experience',
  3008. 'job_hunting.updated_at',
  3009. 'job_hunting.salary',
  3010. 'job_hunting.skillList',
  3011. 'job_hunting.slelf_evaluation',
  3012. )
  3013. ->orderBy('updated_at', 'desc')
  3014. ->limit($data['job1_num'])
  3015. ->get();
  3016. $web['website_id'] = $data['website_id'];
  3017. if (empty($job_hunting)) {
  3018. $job_huntings = "未查询到相关简历信息";
  3019. } else {
  3020. $job_huntings = $this->processJob($job_hunting, $web);
  3021. }
  3022. // 0:待审核 1:已通过 2:已拒绝
  3023. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3024. ->where('job_recruiting.website_id', $data['website_id'])
  3025. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3026. $query->where(function ($q) use ($data) {
  3027. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3028. });
  3029. })
  3030. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3031. ->select(
  3032. 'job_recruiting.id',
  3033. 'job_recruiting.catid',
  3034. 'job_recruiting.cat_arr_id',
  3035. 'job_recruiting.title',
  3036. 'job_recruiting.jtzw_id',
  3037. 'job_recruiting.hy_id',
  3038. 'job_recruiting.city_arr_id',
  3039. 'job_recruiting.due_data',
  3040. 'job_recruiting.updated_at',
  3041. 'job_recruiting.experience',
  3042. 'job_recruiting.educational',
  3043. 'job_recruiting.salary',
  3044. 'job_recruiting.zw_id',
  3045. 'job_company.business_name',
  3046. 'job_recruiting.keyword',
  3047. 'job_recruiting.description',
  3048. 'job_recruiting.seo_description',
  3049. )
  3050. ->orderBy('updated_at', 'desc')
  3051. ->limit($data['job2_num'])
  3052. ->get();
  3053. if (empty($job_recruiting->toArray())) {
  3054. $job_recruitings = "未查询到相关职位信息";
  3055. } else {
  3056. $job_recruitings = $this->processJob($job_recruiting, $web);
  3057. }
  3058. $result = [
  3059. 'job_hunting' => $job_huntings,
  3060. 'job_recuiting' => $job_recruitings,
  3061. ];
  3062. return Result::success($result);
  3063. }
  3064. /**
  3065. * c端-获取招工招聘列表
  3066. * @param array $data
  3067. * @return array
  3068. * */
  3069. public function getWebsiteJobList(array $data): array
  3070. {
  3071. $recruit_where = [];
  3072. $hunt_where = [];
  3073. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3074. if (empty($web)) {
  3075. return Result::error("此网站不存在", 0);
  3076. }
  3077. $website_id['website_id'] = $data['website_id'];
  3078. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3079. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3080. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3081. }
  3082. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3083. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3084. }
  3085. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3086. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3087. }
  3088. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3089. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3090. }
  3091. $query = JobRecruiting::where('job_recruiting.status', 1)
  3092. ->where('job_recruiting.website_id', $data['website_id'])
  3093. ->where($recruit_where)
  3094. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3095. $query->where(function ($q) use ($data) {
  3096. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3097. });
  3098. })
  3099. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3100. $query->where(function ($q) use ($data) {
  3101. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3102. });
  3103. })
  3104. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3105. ->select(
  3106. 'job_recruiting.id',
  3107. 'job_recruiting.catid',
  3108. 'job_recruiting.hy_id',
  3109. 'job_recruiting.title',
  3110. 'job_recruiting.zw_id',
  3111. 'job_recruiting.educational',
  3112. 'job_recruiting.jtzw_id',
  3113. 'job_recruiting.city_arr_id',
  3114. 'job_recruiting.due_data',
  3115. 'job_recruiting.experience',
  3116. 'job_recruiting.cat_arr_id',
  3117. 'job_recruiting.updated_at',
  3118. 'job_company.business_name',
  3119. 'job_recruiting.keyword',
  3120. 'job_recruiting.description',
  3121. 'job_recruiting.seo_description',
  3122. )
  3123. ->orderBy('job_recruiting.updated_at', 'desc');
  3124. $recruit_count = $query->count();
  3125. $query = clone $query;
  3126. $JobRecruiting = $query
  3127. ->offset(($data['page'] - 1) * $data['pageSize'])
  3128. ->limit($data['pageSize'])
  3129. ->get();
  3130. if (empty($JobRecruiting)) {
  3131. $JobRecruiting = "暂无相关职位信息";
  3132. } else {
  3133. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3134. }
  3135. }
  3136. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3137. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3138. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3139. }
  3140. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3141. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3142. }
  3143. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3144. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3145. }
  3146. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3147. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3148. }
  3149. $query = JobHunting::where('job_hunting.status', 2)
  3150. ->where('job_hunting.website_id', $data['website_id'])
  3151. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3152. ->where($hunt_where)
  3153. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3154. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3155. // })
  3156. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3157. $query->where(function ($q) use ($data) {
  3158. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3159. });
  3160. })
  3161. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3162. $query->where(function ($q) use ($data) {
  3163. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3164. });
  3165. })
  3166. ->select(
  3167. 'job_hunting.id',
  3168. 'job_hunting.catid',
  3169. 'job_hunting.sexy',
  3170. 'job_hunting.experience',
  3171. 'job_hunting.origin',
  3172. 'job_hunting.industry',
  3173. 'job_hunting.name',
  3174. 'job_hunting.job',
  3175. 'job_hunting.job_name_get',
  3176. 'job_hunting.city_arr_id',
  3177. 'job_hunting.cat_arr_id',
  3178. 'job_hunting.created_at',
  3179. 'job_hunting.updated_at',
  3180. 'job_position.zwname as job_name',
  3181. 'job_hunting.skillList',
  3182. 'job_hunting.slelf_evaluation',
  3183. )
  3184. ->orderBy('job_hunting.updated_at', 'desc');
  3185. $hunt_count = $query->count();
  3186. $query = clone $query;
  3187. $JobHunting = $query
  3188. ->offset(($data['page'] - 1) * $data['pageSize'])
  3189. ->limit($data['pageSize'])
  3190. ->get();
  3191. if (empty($JobHunting)) {
  3192. $JobRecruiting = "暂无相关简历信息";
  3193. } else {
  3194. $JobHunting = $this->processJob($JobHunting, $website_id);
  3195. }
  3196. }
  3197. $result = [
  3198. 'JobRecruiting' => $JobRecruiting ?? [],
  3199. 'recruit_count' => $recruit_count ?? 0,
  3200. 'JobHunting' => $JobHunting ?? [],
  3201. 'hunt_count' => $hunt_count ?? 0,
  3202. ];
  3203. return Result::success($result);
  3204. }
  3205. /**
  3206. * c端-获取招工招聘详情
  3207. * @param array $data
  3208. * @return array
  3209. * */
  3210. public function getWebsiteJobInfo(array $data): array
  3211. {
  3212. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3213. if (empty($web)) {
  3214. return Result::error("该网站不存在", 0);
  3215. }
  3216. $webid = [
  3217. 'website_id' => $data['website_id'],
  3218. ];
  3219. // 职位相关信息
  3220. if ($data['type'] == 1) {
  3221. $query = JobRecruiting::where('status', 1)
  3222. ->where('website_id', $data['website_id'])
  3223. ->select('*');
  3224. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3225. $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();
  3226. if (!empty($company)) {
  3227. $result['company'] = $this->processJob($company, $webid);
  3228. }
  3229. $other_job = JobRecruiting::where('status', 1)
  3230. ->where('website_id', $data['website_id'])
  3231. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3232. ->where('id', '!=', $data['id'])
  3233. ->where('user_id', '=', $job[0]['user_id'])
  3234. ->limit($data['pageSize'])
  3235. ->get();
  3236. if (!empty($other_job)) {
  3237. $result['other_job'] = $this->processJob($other_job, $webid);
  3238. }
  3239. } else {
  3240. // 简历相关信息
  3241. $job = JobHunting::where('job_hunting.status', 2)
  3242. ->where('job_hunting.website_id', $data['website_id'])
  3243. ->where('job_hunting.id', $data['id'])
  3244. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3245. ->select('job_hunting.*', 'user_name')
  3246. ->get();
  3247. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3248. if (!empty($resume->toArray())) {
  3249. $result['resume'] = 1;
  3250. } else {
  3251. $result['resume'] = 0;
  3252. }
  3253. }
  3254. if (empty($job->toArray())) {
  3255. return Result::error("id参数错误", 0);
  3256. }
  3257. if (!empty($job[0]['job_experience'])) {
  3258. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3259. if (!empty($job_experience)) {
  3260. // $hy = [];
  3261. foreach ($job_experience as $key => $value) {
  3262. // $id = $value['id'];
  3263. $hy[$key] = $value['job_industry'];
  3264. $zw_id[$key] = $value['job_typename'];
  3265. $jtzw_id[$key] = $value['job_name'];
  3266. }
  3267. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3268. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3269. // 先将关联表转换为索引数组,提高查找效率
  3270. $hyLookup = [];
  3271. foreach ($hy_table as $item) {
  3272. $hyLookup[$item['hyid']] = $item['hyname'];
  3273. }
  3274. $zwLookup = [];
  3275. foreach ($zw_table as $item) {
  3276. $zwLookup[$item['zwid']] = $item['zwname'];
  3277. }
  3278. foreach ($job_experience as $key => &$value) {
  3279. // 处理行业名称
  3280. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3281. $value['hy_name'] = $hyLookup[$hy[$key]];
  3282. }
  3283. // 处理职位名称
  3284. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3285. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3286. }
  3287. // 处理具体职位名称
  3288. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3289. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3290. }
  3291. }
  3292. // 释放引用,防止意外修改后续代码
  3293. unset($value);
  3294. }
  3295. $result['job_experience'] = $job_experience ?? [];
  3296. }
  3297. if (!empty($job[0]['education_experience'])) {
  3298. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3299. if (!empty($education_experience)) {
  3300. foreach ($education_experience as $key => $value) {
  3301. // $id = $value['id'];
  3302. $education[$key] = $value['school_education'];
  3303. }
  3304. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3305. // // 先将关联表转换为索引数组,提高查找效率
  3306. $educationLookup = [];
  3307. foreach ($education_table as $item) {
  3308. $educationLookup[$item['evalue']] = $item['ename'];
  3309. }
  3310. foreach ($education_experience as $key => &$value) {
  3311. // 处理学历名称
  3312. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3313. $value['education_name'] = $educationLookup[$education[$key]];
  3314. }
  3315. }
  3316. }
  3317. $result['education_experience'] = $job_experience ?? [];
  3318. }
  3319. $result['job'] = $this->processJob($job, $webid);
  3320. // // 返现对应的栏目
  3321. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3322. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3323. ->whereIn('category_id', $catid)
  3324. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3325. ->orderBy('pid')->get()->all();
  3326. if (!empty($category)) {
  3327. $result['category'] = $category;
  3328. }
  3329. $result['job'] = $job;
  3330. $result['job_experience'] = $job_experience ?? [];
  3331. $result['education_experience'] = $education_experience ?? [];
  3332. if (empty($result)) {
  3333. return Result::error("参数错误", 0);
  3334. }
  3335. return Result::success($result);
  3336. }
  3337. /**
  3338. * c端-申请职位
  3339. * @param array $data
  3340. * @return array
  3341. * */
  3342. public function getWebsiteJobApply(array $data): array
  3343. {
  3344. // 首先验证网站是否存在
  3345. // return Result::success($data);
  3346. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3347. if (empty($web)) {
  3348. return Result::error("该网站不存在", 0);
  3349. }
  3350. // 验证用户是否存在且为个人会员/管理员
  3351. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3352. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3353. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3354. return Result::error("用户不存在", 0);
  3355. }
  3356. // 去除重复元素和空元素,并保持原始顺序
  3357. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3358. return !empty($value);
  3359. }));
  3360. // 验证职位是否存在 1:审核通过
  3361. $recruiting = JobRecruiting::where('status', 1)
  3362. ->where('website_id', $data['website_id'])
  3363. ->whereIn('id', $data['recruit_id'])
  3364. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3365. if (empty($recruiting)) {
  3366. return Result::error("该职位不存在", 0);
  3367. }
  3368. // 简历是否存在
  3369. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3370. if (empty($hunt_id)) {
  3371. return Result::error("该简历不存在", 0);
  3372. }
  3373. $data['hunt_id'] = $hunt_id['hunt_id'];
  3374. // // 验证是否已投递过该职位
  3375. $apply = JobApply::where('user_id', $data['user_id'])
  3376. ->where('hunt_id', $data['hunt_id'])
  3377. ->where('website_id', $data['website_id'])
  3378. ->whereIn('recruit_id', $data['recruit_id'])
  3379. ->get(['recruit_id']);
  3380. if (!empty($apply->toArray())) {
  3381. return Result::error("您已投递过该职位!");
  3382. }
  3383. $insertData = array_map(function ($recruiting) use ($data) {
  3384. return [
  3385. 'user_id' => $data['user_id'],
  3386. 'hunt_id' => $data['hunt_id'],
  3387. 'website_id' => $data['website_id'],
  3388. 'recruit_id' => $recruiting['recruit_id'],
  3389. 'receiver_id' => $recruiting['receiver_id'],
  3390. 'status' => 1,
  3391. ];
  3392. }, $recruiting);
  3393. // 批量插入数据
  3394. $result = JobApply::insert($insertData);
  3395. if (empty($result)) {
  3396. return Result::error("投递失败", 0);
  3397. }
  3398. return Result::success($result);
  3399. }
  3400. /**
  3401. * 招工招聘-沟通简历
  3402. * @param array $data
  3403. * @return array
  3404. * */
  3405. public function getWebsiteJobResume(array $data): array
  3406. {
  3407. // 首先验证网站是否存在
  3408. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3409. if (empty($web)) {
  3410. return Result::error("该网站不存在", 0);
  3411. }
  3412. // return Result::success($data);
  3413. // 验证用户是否存在且为企业会员/管理员
  3414. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3415. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3416. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3417. return Result::error("用户不存在", 0);
  3418. }
  3419. // 去除重复元素和空元素,并保持原始顺序
  3420. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3421. return !empty($value);
  3422. }));
  3423. // 验证简历是否存在
  3424. $hunting = JobHunting::where('status', 2)
  3425. ->where('website_id', $data['website_id'])
  3426. ->whereIn('id', $data['hunt_id'])
  3427. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3428. if (empty($hunting)) {
  3429. return Result::error("该简历不存在", 0);
  3430. }
  3431. // 验证是否已沟通过该简历
  3432. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3433. ->where('recruit_id', $data['recruit_id'])
  3434. ->where('website_id', $data['website_id'])
  3435. ->whereIn('hunt_id', $data['hunt_id'])
  3436. ->get(['hunt_id']);
  3437. if (!empty($remuse->toArray())) {
  3438. return Result::error("您已沟通过该简历!");
  3439. }
  3440. // 准备要插入的数据数组
  3441. $insertData = array_map(function ($hunting) use ($data) {
  3442. return [
  3443. 'user_id' => $data['user_id'],
  3444. 'recruit_id' => $data['recruit_id'],
  3445. 'website_id' => $data['website_id'],
  3446. 'hunt_id' => $hunting['hunt_id'],
  3447. 'receiver_id' => $hunting['receiver_id'],
  3448. 'status' => 1,
  3449. ];
  3450. }, $hunting);
  3451. // 批量插入数据
  3452. $result = JobRemuse::insert($insertData);
  3453. if (empty($result)) {
  3454. return Result::error("沟通失败", 0);
  3455. }
  3456. return Result::success($result);
  3457. }
  3458. /**
  3459. * 招工招聘 -我的职位(企业会员)
  3460. * @param array $data
  3461. * @return array
  3462. */
  3463. public function getWebsiteJobRecruiting(array $data): array
  3464. {
  3465. $web = Website::where('id', $data['website_id'])->first('id');
  3466. if (empty($web)) {
  3467. return Result::error("该网站不存在", 0);
  3468. }
  3469. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3470. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3471. return Result::error("用户暂无权限!", 0);
  3472. }
  3473. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3474. $result = JobRecruiting::where('website_id', $data['website_id'])
  3475. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3476. $query->where('user_id', $user['id']);
  3477. })
  3478. ->where('status', 1)
  3479. ->select('id', 'title', 'website_id', 'user_id', 'updated_at','keyword','catid','description','seo_description')
  3480. ->orderBy('updated_at', 'desc')
  3481. ->limit($data['pageSize'])
  3482. ->get();
  3483. if (empty($result)) {
  3484. return Result::error("暂无相关职位信息", 0);
  3485. }
  3486. return Result::success($result);
  3487. }
  3488. /**
  3489. * c端 - 验证路由
  3490. * @param array $data
  3491. * @return array
  3492. */
  3493. /**
  3494. * c端 - 验证路由
  3495. * @param array $data
  3496. * @return array
  3497. */
  3498. public function checkWebsiteRoute(array $data): array
  3499. {
  3500. // 测试001111111222
  3501. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3502. if (empty($web)) {
  3503. return Result::error("该网站不存在", 0);
  3504. } elseif ($web['status'] != 1) {
  3505. return Result::error("网站已经关闭", 0);
  3506. }
  3507. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3508. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3509. // 验证路由是否存在
  3510. if (empty($whiteRouterInfo)) {
  3511. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3512. }
  3513. if (!empty($whiteRouterInfo)) {
  3514. return Result::success($whiteRouterInfo->toArray());
  3515. }
  3516. }
  3517. // 验证栏目路由
  3518. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3519. ->where('path', $data['all_route'])
  3520. ->get()->all();
  3521. if (count($last_category) == 0) {
  3522. return Result::error("该栏目不存在", 0);
  3523. }
  3524. if(count($last_category) > 1){
  3525. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3526. }
  3527. if (count($last_category) == 1) {
  3528. $last_category = $last_category[0];
  3529. }
  3530. // return Result::success($last_category);
  3531. if (isset($data['id']) && !empty($data['id'])) {
  3532. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3533. switch ($last_category['type']) {
  3534. case 1:
  3535. // 文章
  3536. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3537. $article = Article::where('status', 1)
  3538. ->where('id', $data['id'])
  3539. ->where(function ($query) use ($data) {
  3540. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3541. ->orWhereNull("ignore_ids");
  3542. })
  3543. ->first(['catid']);
  3544. if (empty($article)) {
  3545. return Result::error("该文章不存在", 0);
  3546. }
  3547. // return Result::success($article);
  3548. break;
  3549. case 2:
  3550. // 商品
  3551. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3552. $article = Good::where('website_id', $data['website_id'])
  3553. ->where('status', 2)
  3554. ->where('id', $data['id'])
  3555. ->first(['cat_arr_id']);
  3556. if (empty($article)) {
  3557. return Result::error("该商品不存在", 0);
  3558. }
  3559. break;
  3560. case 3:
  3561. // 书刊信息
  3562. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3563. $article = Book::where('website_id', $data['website_id'])
  3564. ->where('status', 2)
  3565. ->where('id', $data['id'])
  3566. ->first(['id', 'cat_arr_id']);
  3567. if (empty($article)) {
  3568. return Result::error("该书刊不存在", 0);
  3569. }
  3570. break;
  3571. case 4:
  3572. // 招聘
  3573. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3574. $article = JobRecruiting::where('website_id', $data['website_id'])
  3575. ->where('status', 1)
  3576. ->where('id', $data['id'])
  3577. ->first(['cat_arr_id']);
  3578. if (empty($article)) {
  3579. return Result::error("该招聘不存在", 0);
  3580. }
  3581. break;
  3582. case 5:
  3583. // 求职
  3584. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3585. $article = JobHunting::where('website_id', $data['website_id'])
  3586. ->where('status', 2)
  3587. ->where('id', $data['id'])
  3588. ->first(['cat_arr_id']);
  3589. if (empty($article)) {
  3590. return Result::error("该求职不存在", 0);
  3591. }
  3592. break;
  3593. case 6:
  3594. // 企业
  3595. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3596. $article = Company::
  3597. // where('website_id', $data['website_id'])
  3598. // ->
  3599. where('status', 1)
  3600. ->where('id', $data['id'])
  3601. ->first(['cat_arr_id']);
  3602. if (empty($article)) {
  3603. return Result::error("该企业不存在", 0);
  3604. }
  3605. break;
  3606. case 7:
  3607. // 项目
  3608. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3609. $article = Project::where('website_id', $data['website_id'])
  3610. ->where('status', 1)
  3611. ->where('id', $data['id'])
  3612. ->first(['cat_arr_id']);
  3613. if (empty($article)) {
  3614. return Result::error("该项目不存在", 0);
  3615. }
  3616. break;
  3617. default:
  3618. return Result::error("该数据不存在", 0);
  3619. break;
  3620. }
  3621. // return Result::success($article);
  3622. // $catid =0 ;
  3623. if(!isset($article['cat_arr_id'])){
  3624. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  3625. }else{
  3626. $catidArray = json_decode($article['cat_arr_id'], true);
  3627. $catid = !empty($catidArray) ? end($catidArray) : null;
  3628. }
  3629. // return Result::success($catid);
  3630. // // return Result::success($article['cat_arr_id']);
  3631. if (empty($catid)) {
  3632. return Result::error("该栏目路径不存在", 0);
  3633. }
  3634. $path = WebsiteCategory::where('website_id', $data['website_id'])
  3635. ->where('category_id',$catid)
  3636. ->first('path');
  3637. }
  3638. // else{
  3639. // // if ($last_category['pid'] != 0) {
  3640. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  3641. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  3642. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3643. // ->where('category_id',$catid)
  3644. // ->where('path',$data['all_route'])
  3645. // ->first('path');
  3646. // // } else {
  3647. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  3648. // // }
  3649. // }
  3650. // return Result::success($path);
  3651. if (!empty($path) && $path['path'] != $data['all_route']) {
  3652. return Result::error('非法路径!');
  3653. } else {
  3654. return Result::success( $last_category['path']);
  3655. }
  3656. }
  3657. /**
  3658. * 招工招聘 - 获取推荐职位
  3659. * @param array $data
  3660. * @return array
  3661. */
  3662. public function getWebsiteLevelJob(array $data): array
  3663. {
  3664. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3665. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3666. ->where('job_recruiting.status', 1)
  3667. ->where('job_level', $data['job_level'])
  3668. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3669. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3670. ->orderBy('job_recruiting.updated_at', 'desc')
  3671. ->limit($data['pageSize'])
  3672. ->get();
  3673. $web = ['website_id' => $data['website_id']];
  3674. if (!empty($job)) {
  3675. $result = $this->processJob($job, $web);
  3676. }
  3677. if (empty($result)) {
  3678. return Result::error("暂无相关职位信息", 0);
  3679. }
  3680. return Result::success($result);
  3681. }
  3682. /**
  3683. * 验证导航名称是否重复
  3684. * @return void
  3685. */
  3686. //20250226 产品列表
  3687. public function getGoodList(array $data): array
  3688. {
  3689. var_dump($data, '---------1-2--');
  3690. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3691. unset($data['user_type_id']);
  3692. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3693. $where = [];
  3694. if ($type_id != '10000') {
  3695. $where = [
  3696. 'good.user_id' => $user_id,
  3697. ];
  3698. }
  3699. //类型
  3700. if (isset($data['type_id']) && $data['type_id']) {
  3701. $where['good.type_id'] = $data['type_id'];
  3702. }
  3703. //名称
  3704. if (isset($data['name']) && $data['name']) {
  3705. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3706. }
  3707. //status
  3708. if (isset($data['status']) && $data['status'] != '') {
  3709. $where['good.status'] = $data['status'];
  3710. }
  3711. //status1
  3712. // if (isset($data['status1']) && $data['status1'] == 1) {
  3713. // $status1 = 1;
  3714. // }
  3715. $where1 = [];
  3716. //website_id
  3717. // if (isset($data['website_id']) && $data['website_id']) {
  3718. // $where1 = [
  3719. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3720. // ];
  3721. // }
  3722. // website_name
  3723. if (isset($data['website_name']) && $data['website_name']) {
  3724. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3725. }
  3726. // catid
  3727. if (isset($data['category_name']) && $data['category_name']) {
  3728. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3729. }
  3730. // $result = Good::where($where)
  3731. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3732. var_dump($where, '---------1---');
  3733. $result = Good::where($where)
  3734. ->when(!empty($where1), function ($query) use ($where1) {
  3735. return $query->where($where1);
  3736. })
  3737. //status 1待审核2已审核3已拒绝
  3738. ->when(isset($data['status1']), function ($query) {
  3739. return $query->whereIn('good.status', [1, 3]);
  3740. })
  3741. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3742. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3743. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3744. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3745. ->orderBy("updated_at", "desc")
  3746. ->limit($data['page_size'])
  3747. ->offset(($data['page'] - 1) * $data['page_size'])
  3748. ->get();
  3749. $count = Good::where($where)
  3750. ->when(!empty($where1), function ($query) use ($where1) {
  3751. return $query->where($where1);
  3752. })
  3753. //status 1待审核2已审核3已拒绝
  3754. ->when(isset($data['status1']), function ($query) {
  3755. return $query->whereIn('good.status', [1, 3]);
  3756. })
  3757. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3758. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3759. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3760. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3761. ->orderBy("updated_at", "desc")->count();
  3762. $data = [
  3763. 'rows' => $result->toArray(),
  3764. 'count' => $count,
  3765. ];
  3766. if (empty($result)) {
  3767. return Result::error("此栏目暂无相关产品", 0);
  3768. }
  3769. return Result::success($data);
  3770. }
  3771. public function getGoodInfo(array $data): array
  3772. {
  3773. $result = Good::where('id', $data['id'])->first();
  3774. if (empty($result)) {
  3775. return Result::error("此产品不存在", 0);
  3776. }
  3777. return Result::success($result);
  3778. }
  3779. public function addGood(array $data): array
  3780. {
  3781. // unset($data['city_arr_id']);
  3782. // unset($data['cat_arr_id']);
  3783. $data['city_id'] = end($data['city_arr_id']);
  3784. $data['catid'] = end($data['cat_arr_id']);
  3785. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3786. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3787. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3788. unset($data['imgUrl']); //大小写
  3789. if (isset($data['price']) && $data['price'] == '') {
  3790. $data['price'] = 0;
  3791. }
  3792. if ($data['imgurl'] == '') {
  3793. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3794. preg_match_all($reg, $data['detail'], $matches);
  3795. if (isset($matches[1][0])) {
  3796. //截取varchar240
  3797. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3798. }
  3799. }
  3800. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3801. //提取标题+内容中的关键词
  3802. $data['keyword'] = $data['name'];
  3803. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3804. Jieba::init(); // 初始化 jieba-php
  3805. Finalseg::init();
  3806. $segList = Jieba::cut($data['keyword']);
  3807. $segList1 = array_slice($segList, 0, 8);
  3808. $data['keyword'] = implode(',', $segList1);
  3809. }
  3810. if ($data['description'] == '') {
  3811. //提取内容中的描述
  3812. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3813. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3814. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3815. }
  3816. if ($data['status'] == 1) {
  3817. $this->sendMessage([
  3818. 'talk_type' => 200,
  3819. 'title' => $data['name'],
  3820. 'content' => '提交了审核',
  3821. 'messageType' => 3,
  3822. ]);
  3823. }
  3824. $result = Good::insert($data);
  3825. if (empty($result)) {
  3826. return Result::error("添加失败", 0);
  3827. }
  3828. return Result::success($result);
  3829. }
  3830. public function updateGood(array $data): array
  3831. {
  3832. $data['city_id'] = end($data['city_arr_id']);
  3833. $data['catid'] = end($data['cat_arr_id']);
  3834. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3835. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3836. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3837. //设置东八区
  3838. date_default_timezone_set('Asia/Shanghai');
  3839. $data['updated_at'] = date('Y-m-d H:i:s');
  3840. if (isset($data['price']) && $data['price'] == '') {
  3841. $data['price'] = 0;
  3842. }
  3843. if ($data['imgurl'] == '') {
  3844. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3845. preg_match_all($reg, $data['detail'], $matches);
  3846. if (isset($matches[1][0])) {
  3847. //截取varchar240
  3848. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3849. }
  3850. }
  3851. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3852. //提取标题+内容中的关键词
  3853. $data['keyword'] = $data['name'];
  3854. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3855. Jieba::init(); // 初始化 jieba-php
  3856. Finalseg::init();
  3857. $segList = Jieba::cut($data['keyword']);
  3858. $segList1 = array_slice($segList, 0, 8);
  3859. $data['keyword'] = implode(',', $segList1);
  3860. }
  3861. if ($data['description'] == '') {
  3862. //提取内容中的描述
  3863. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3864. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3865. }
  3866. if ($data['status'] == 1) {
  3867. $this->sendMessage([
  3868. 'talk_type' => 200,
  3869. 'title' => $data['name'],
  3870. 'content' => '提交了审核',
  3871. 'messageType' => 3,
  3872. ]);
  3873. }
  3874. $result = Good::where('id', $data['id'])->update($data);
  3875. if (empty($result)) {
  3876. return Result::error("更新失败", 0);
  3877. }
  3878. return Result::success($result);
  3879. }
  3880. public function delGood(array $data): array
  3881. {
  3882. $result = Good::where('id', $data['id'])->delete();
  3883. if (empty($result)) {
  3884. return Result::error("删除失败", 0);
  3885. }
  3886. return Result::success($result);
  3887. }
  3888. //20250226 产品列表
  3889. //20250306 求职信息
  3890. public function getJobHuntingList(array $data): array
  3891. {
  3892. $where = [];
  3893. if (isset($data['username']) && !empty($data['username'])) {
  3894. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3895. }
  3896. //status 1待审核2已审核3已拒绝
  3897. if (isset($data['status']) && $data['status'] != '') {
  3898. $where = [
  3899. 'job_hunting.status' => $data['status'],
  3900. ];
  3901. }
  3902. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3903. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3904. unset($data['type_id']);
  3905. if ($type_id != '10000') {
  3906. $where[] = ['job_hunting.user_id', '=', $user_id];
  3907. }
  3908. $result = JobHunting::where($where)
  3909. ->when(!empty($data['status1']), function ($query) use ($data) {
  3910. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3911. })
  3912. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3913. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3914. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3915. ->orderBy("updated_at", "desc")
  3916. ->limit($data['page_size'])
  3917. ->offset(($data['page'] - 1) * $data['page_size'])
  3918. ->get();
  3919. if (empty($result)) {
  3920. return Result::error("查询失败", 0);
  3921. }
  3922. $count = JobHunting::where($where)
  3923. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3924. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3925. ->count();
  3926. $data = [
  3927. 'rows' => $result->toArray(),
  3928. 'count' => $count,
  3929. ];
  3930. return Result::success($data);
  3931. }
  3932. public function getJobHuntingApply(array $data): array
  3933. {
  3934. var_dump($data, '-----------------test--------1-');
  3935. $where = [];
  3936. if (isset($data['username']) && !empty($data['username'])) {
  3937. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3938. }
  3939. if (isset($data['salary']) && !empty($data['salary'])) {
  3940. $where[] = [
  3941. 'job_hunting.salary',
  3942. '=',
  3943. $data['salary'],
  3944. ];
  3945. }
  3946. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3947. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3948. unset($data['type_id']);
  3949. if ($type_id != '10000') {
  3950. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3951. }
  3952. var_dump($where, '-----------------test---------');
  3953. $result = jobApply::where($where)
  3954. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3955. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3956. // })
  3957. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3958. ->where('job_enum.egroup', '=', 'income')
  3959. ->where('job_hunting.status', 2) //已审核
  3960. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3961. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3962. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3963. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3964. //职位----是申请职位
  3965. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3966. ->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')
  3967. ->orderBy("job_hunting.updated_at", "desc")
  3968. ->limit($data['page_size'])
  3969. ->offset(($data['page'] - 1) * $data['page_size'])
  3970. ->get();
  3971. if (empty($result)) {
  3972. return Result::error("查询失败", 0);
  3973. }
  3974. $count = jobApply::where($where)
  3975. ->where('job_enum.egroup', '=', 'income')
  3976. ->where('job_hunting.status', 2) //已审核
  3977. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3978. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3979. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3980. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3981. //职位----是申请职位
  3982. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3983. ->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')
  3984. ->count();
  3985. $data = [
  3986. 'rows' => $result->toArray(),
  3987. 'count' => $count,
  3988. ];
  3989. return Result::success($data);
  3990. }
  3991. public function addJobHunting(array $data): array
  3992. {
  3993. date_default_timezone_set('Asia/Shanghai');
  3994. unset($data['company_name']);
  3995. unset($data['job_industry']);
  3996. unset($data['job_name']);
  3997. unset($data['department']);
  3998. unset($data['job_timeList']);
  3999. unset($data['job_content']);
  4000. unset($data['job_typename']); //不知道这是啥,
  4001. $data['created_at'] = date('Y-m-d H:i:s');
  4002. $data['updated_at'] = date('Y-m-d H:i:s');
  4003. //根据用户 user_id 只能添加一次
  4004. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4005. if (!empty($result)) {
  4006. return Result::error("您已添加过求职信息", 0);
  4007. }
  4008. var_dump($result, '-----------------test---------');
  4009. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4010. if (is_string($data['city_arr_id'])) {
  4011. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4012. $cityArr = json_decode($data['city_arr_id'], true);
  4013. // 确保 $cityArr 是数组
  4014. if (is_array($cityArr)) {
  4015. $data['city_id'] = end($cityArr);
  4016. }
  4017. } else {
  4018. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4019. if (is_array($data['city_arr_id'])) {
  4020. $data['city_id'] = end($data['city_arr_id']);
  4021. }
  4022. }
  4023. }
  4024. // 处理求职所绑定栏目
  4025. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4026. if (is_string($data['cat_arr_id'])) {
  4027. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4028. // 先清理可能存在的无效 JSON 字符
  4029. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4030. $catArr = json_decode($cleanedCatArrStr, true);
  4031. // 检查 JSON 解码是否成功且结果是数组
  4032. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4033. $data['catid'] = end($catArr);
  4034. }
  4035. } else {
  4036. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4037. if (is_array($data['cat_arr_id'])) {
  4038. $data['catid'] = end($data['cat_arr_id']);
  4039. }
  4040. }
  4041. }
  4042. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4043. $this->sendMessage([
  4044. 'talk_type' => 600,
  4045. 'title' => $data['name'],
  4046. 'content' => '提交了审核',
  4047. 'messageType' => 11,
  4048. ]);
  4049. }
  4050. $result = JobHunting::create($data);
  4051. if (empty($result)) {
  4052. return Result::error("添加失败", 0);
  4053. }
  4054. return Result::success($result);
  4055. }
  4056. public function delJobHunting(array $data): array
  4057. {
  4058. $result = JobHunting::where('id', $data['id'])->delete();
  4059. if (empty($result)) {
  4060. return Result::error("删除失败", 0);
  4061. }
  4062. return Result::success($result);
  4063. }
  4064. public function updateJobHunting(array $data): array
  4065. {
  4066. //设置东八区
  4067. date_default_timezone_set('Asia/Shanghai');
  4068. unset($data['company_name']);
  4069. unset($data['job_industry']);
  4070. unset($data['job_name']);
  4071. unset($data['department']);
  4072. unset($data['job_timeList']);
  4073. unset($data['job_content']);
  4074. unset($data['job_typename']); //不知道这是啥,
  4075. $data['created_at'] = date('Y-m-d H:i:s');
  4076. $data['updated_at'] = date('Y-m-d H:i:s');
  4077. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4078. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4079. $cityArr = json_decode($data['city_arr_id'], true);
  4080. $data['city_id'] = end($cityArr);
  4081. } else {
  4082. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4083. $data['city_id'] = end($data['city_arr_id']);
  4084. }
  4085. // 处理求职所绑定栏目
  4086. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4087. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4088. $catArr = json_decode($data['cat_arr_id'], true);
  4089. $data['catid'] = end($catArr);
  4090. } else {
  4091. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4092. $data['catid'] = end($data['cat_arr_id']);
  4093. }
  4094. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4095. $this->sendMessage([
  4096. 'talk_type' => 600,
  4097. 'title' => $data['name'],
  4098. 'content' => '提交了审核',
  4099. 'messageType' => 11,
  4100. ]);
  4101. }
  4102. $result = JobHunting::where('id', $data['id'])->update($data);
  4103. if (empty($result)) {
  4104. return Result::error("更新失败", 0);
  4105. }
  4106. return Result::success($result);
  4107. }
  4108. public function getJobHuntingInfo(array $data): array
  4109. {
  4110. $result = JobHunting::where('id', $data['id'])->first();
  4111. if (empty($result)) {
  4112. return Result::error("查询失败", 0);
  4113. }
  4114. return Result::success($result);
  4115. }
  4116. public function getJobHuntingData(array $data): array
  4117. {
  4118. $jobEnum = JobEnum::get();
  4119. $jobIndustry = JobIndustry::get();
  4120. $jobNature = JobNature::get();
  4121. $jobPosition = JobPosition::get();
  4122. $data = [
  4123. 'jobEnum' => $jobEnum,
  4124. 'jobIndustry' => $jobIndustry,
  4125. 'jobNature' => $jobNature,
  4126. 'jobPosition' => $jobPosition,
  4127. ];
  4128. return Result::success($data);
  4129. }
  4130. public function delJobHuntingInfo(array $data): array
  4131. {
  4132. $result = JobHunting::where('id', $data['id'])->delete();
  4133. return Result::success();
  4134. }
  4135. //20250324 通知,公告,消息
  4136. public function delNotice(array $data): array
  4137. {
  4138. $result = Notice::where('id', $data['id'])->delete();
  4139. if ($result) {
  4140. return Result::success();
  4141. } else {
  4142. return Result::error("删除失败", 0);
  4143. }
  4144. }
  4145. public function getNoticeInfo(array $data): array
  4146. {
  4147. $result = Notice::where('id', $data['id'])->first();
  4148. // var_dump($result['re_user_ids'], '--------------------');
  4149. if (empty($result)) {
  4150. return Result::error("查询失败", 0);
  4151. }
  4152. return Result::success($result);
  4153. }
  4154. public function readNotice(array $data): array
  4155. {
  4156. $result = Notice::where('id', $data['id'])->first();
  4157. // var_dump($result['re_user_ids'], '--------------------');
  4158. if (empty($result)) {
  4159. return Result::error("查询失败", 0);
  4160. }
  4161. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4162. $re_user_ids = json_decode($result['re_user_ids'], true);
  4163. var_dump($re_user_ids, '--------------1---test---------');
  4164. var_dump($data, '--------------1---test---------');
  4165. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4166. //如果已经存在,就不再添加
  4167. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4168. $read_id = json_decode($result['read_id'], true);
  4169. if (!is_array($read_id)) {
  4170. $read_id = [];
  4171. }
  4172. if (!in_array($data['user_id'], $read_id)) {
  4173. $read_id[] = $data['user_id'];
  4174. $result['read_id'] = json_encode($read_id);
  4175. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4176. }
  4177. } else {
  4178. //如果不存在,就添加
  4179. $result['read_id'] = json_encode([$data['user_id']]);
  4180. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4181. }
  4182. }
  4183. return Result::success($result);
  4184. }
  4185. public function addNotice(array $data): array
  4186. {
  4187. date_default_timezone_set('Asia/Shanghai');
  4188. $data['created_at'] = date('Y-m-d H:i:s');
  4189. $data['updated_at'] = date('Y-m-d H:i:s');
  4190. $user_id = UserInfo::
  4191. //city_id不是null
  4192. whereNotNull('city_id')
  4193. ->whereNotNull('department_id')
  4194. ->where(function ($query) use ($data) {
  4195. $query->where(function ($subQuery) use ($data) {
  4196. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4197. });
  4198. })
  4199. ->where(function ($query) use ($data) {
  4200. $query->where(function ($subQuery) use ($data) {
  4201. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4202. });
  4203. })
  4204. ->pluck('user_id')->toArray();
  4205. $user_id = array_unique($user_id);
  4206. $chat_ids = $user_id;
  4207. $user_id = json_encode($user_id);
  4208. $data['re_user_ids'] = $user_id;
  4209. $this->sendMessage([
  4210. 'talk_type' => 700,
  4211. 'title' => $data['title'],
  4212. 'content' => '提交了审核',
  4213. 'messageType' => 5,
  4214. ]);
  4215. $result = Notice::insertGetId($data);
  4216. if (empty($result)) {
  4217. return Result::error("添加失败", 0);
  4218. }
  4219. return Result::success($result);
  4220. }
  4221. public function updateNotice(array $data): array
  4222. {
  4223. date_default_timezone_set('Asia/Shanghai');
  4224. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4225. $user_id = UserInfo::
  4226. //city_id不是null
  4227. whereNotNull('city_id')
  4228. ->whereNotNull('department_id')
  4229. ->where(function ($query) use ($data) {
  4230. $query->where(function ($subQuery) use ($data) {
  4231. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4232. });
  4233. })
  4234. ->where(function ($query) use ($data) {
  4235. $query->where(function ($subQuery) use ($data) {
  4236. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4237. });
  4238. })
  4239. ->pluck('user_id')->toArray();
  4240. $user_id = array_unique($user_id);
  4241. $user_id = json_encode($user_id);
  4242. $data['re_user_ids'] = $user_id;
  4243. $data['updated_at'] = date('Y-m-d H:i:s');
  4244. $this->sendMessage([
  4245. 'talk_type' => 700,
  4246. 'title' => $data['title'],
  4247. 'content' => '提交了审核',
  4248. 'messageType' => 5,
  4249. ]);
  4250. $result = Notice::where('id', $data['id'])->update($data);
  4251. return Result::success($result);
  4252. }
  4253. public function getNoticeList(array $data): array
  4254. {
  4255. $where = [];
  4256. //title
  4257. if (isset($data['title']) && !empty($data['title'])) {
  4258. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4259. }
  4260. //level
  4261. if (isset($data['level']) && !empty($data['level'])) {
  4262. $where[] = ['notice.level', '=', $data['level']];
  4263. }
  4264. //status
  4265. if (isset($data['status']) && !empty($data['status'])) {
  4266. $where[] = ['notice.status', '=', $data['status']];
  4267. }
  4268. //type
  4269. if (isset($data['type']) && !empty($data['type'])) {
  4270. $where[] = ['notice.type', '=', $data['type']];
  4271. }
  4272. var_dump($data, '------------11111-2----test---------');
  4273. if ($data['type_id'] == 10000) {
  4274. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4275. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4276. })
  4277. ->where($where)
  4278. ->orderBy('updated_at', 'desc')
  4279. ->limit($data['page_size'])
  4280. ->offset(($data['page'] - 1) * $data['page_size'])
  4281. ->get();
  4282. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4283. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4284. })
  4285. ->where($where)
  4286. ->orderBy('updated_at', 'desc')
  4287. ->count();
  4288. } else {
  4289. $result = Notice::where($where)
  4290. // ->where('user_id', $data['user_id'])
  4291. ->Where(function ($query) use ($data) {
  4292. $query->Where(function ($q) use ($data) {
  4293. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4294. ->orWhere('notice.user_id', $data['user_id']);
  4295. });
  4296. })
  4297. ->when(!empty($data['status1']), function ($query) use ($data) {
  4298. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4299. })
  4300. ->orderBy('updated_at', 'desc')
  4301. ->limit($data['page_size'])
  4302. ->offset(($data['page'] - 1) * $data['page_size'])
  4303. ->get();
  4304. $total = Notice::where($where)
  4305. ->when(!empty($data['status1']), function ($query) use ($data) {
  4306. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4307. })
  4308. // ->where('user_id', $data['user_id'])
  4309. ->Where(function ($query) use ($data) {
  4310. $query->Where(function ($q) use ($data) {
  4311. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4312. ->orWhere('notice.user_id', $data['user_id']);
  4313. });
  4314. })
  4315. ->count();
  4316. }
  4317. if (empty($result)) {
  4318. return Result::error("查询失败", 0);
  4319. }
  4320. $data = [
  4321. 'rows' => $result,
  4322. 'count' => $total,
  4323. ];
  4324. return Result::success($data);
  4325. }
  4326. public function noticeList(array $data): array
  4327. {
  4328. $where = [];
  4329. //title
  4330. if (isset($data['title']) && !empty($data['title'])) {
  4331. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4332. }
  4333. //level
  4334. if (isset($data['level']) && !empty($data['level'])) {
  4335. $where[] = ['notice.level', '=', $data['level']];
  4336. }
  4337. //status
  4338. if (isset($data['status']) && !empty($data['status'])) {
  4339. $where[] = ['notice.status', '=', $data['status']];
  4340. }
  4341. //type
  4342. if (isset($data['type']) && !empty($data['type'])) {
  4343. $where[] = ['notice.type', '=', $data['type']];
  4344. }
  4345. var_dump($data, '------------11111-2----test---------');
  4346. if ($data['type_id'] == 10000) {
  4347. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4348. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4349. })
  4350. ->where($where)
  4351. ->orderBy('updated_at', 'desc')
  4352. ->limit($data['page_size'])
  4353. ->offset(($data['page'] - 1) * $data['page_size'])
  4354. ->get();
  4355. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4356. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4357. })
  4358. ->where($where)
  4359. ->orderBy('updated_at', 'desc')
  4360. ->count();
  4361. } else {
  4362. $result = Notice::where($where)
  4363. // ->where('user_id', $data['user_id'])
  4364. ->Where(function ($query) use ($data) {
  4365. $query->Where(function ($q) use ($data) {
  4366. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4367. ->orWhere('notice.user_id', $data['user_id']);
  4368. });
  4369. })
  4370. ->when(!empty($data['status1']), function ($query) use ($data) {
  4371. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4372. })
  4373. ->orderBy('updated_at', 'desc')
  4374. ->limit($data['page_size'])
  4375. ->offset(($data['page'] - 1) * $data['page_size'])
  4376. ->get();
  4377. $total = Notice::where($where)
  4378. ->when(!empty($data['status1']), function ($query) use ($data) {
  4379. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4380. })
  4381. // ->where('user_id', $data['user_id'])
  4382. ->Where(function ($query) use ($data) {
  4383. $query->Where(function ($q) use ($data) {
  4384. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4385. ->orWhere('notice.user_id', $data['user_id']);
  4386. });
  4387. })
  4388. ->count();
  4389. }
  4390. if (empty($result)) {
  4391. return Result::error("查询失败", 0);
  4392. }
  4393. $data = [
  4394. 'rows' => $result,
  4395. 'count' => $total,
  4396. ];
  4397. return Result::success($data);
  4398. }
  4399. public function getNoticeDetail(array $data): array
  4400. {
  4401. $result = Notice::where('id', $data['id'])->first();
  4402. if (empty($result)) {
  4403. return Result::error("查询失败", 0);
  4404. }
  4405. return Result::success($result);
  4406. }
  4407. public function deleteNotice(array $data): array
  4408. {
  4409. $notice = Notice::where('id', $data['id'])->first();
  4410. if (empty($notice)) {
  4411. return Result::error("删除失败", 0);
  4412. }
  4413. $chat_group_id = $notice->group_id;
  4414. if ($chat_group_id) {
  4415. //删除群聊
  4416. ChatGroups::where('id', $chat_group_id)->delete();
  4417. //删除群成员
  4418. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4419. //删除群聊记录
  4420. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4421. }
  4422. $result = Notice::where('id', $data['id'])->delete();
  4423. return Result::success($result);
  4424. }
  4425. public function complaintList(array $data): array
  4426. {
  4427. var_dump($data, '---------1---------');
  4428. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4429. unset($data['type_id']);
  4430. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4431. $where = [];
  4432. if ($type_id != 10000 && empty($data['deal_user'])) {
  4433. // $where['complaint.user_id'] = $user_id;
  4434. }
  4435. if (!empty($data['title'])) {
  4436. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4437. }
  4438. if (!empty($data['department_id'])) {
  4439. $where['complaint.department_id'] = $data['department_id'];
  4440. }
  4441. if (!empty($data['deal'])) {
  4442. $where['complaint.deal'] = $data['deal'];
  4443. }
  4444. if (!empty($data['status'])) {
  4445. $where['complaint.status'] = $data['status'];
  4446. }
  4447. var_dump(!empty($data['deal_user']), '----------1');
  4448. var_dump($where, '----------2');
  4449. $result = Complaint::where($where)
  4450. ->when(!empty($data['status1']), function ($query) use ($data) {
  4451. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4452. })
  4453. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4454. //json re_user_ids data[user_id]是不是在里面
  4455. $query->Where(function ($q) use ($data) {
  4456. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4457. ->where('complaint.status', 2);
  4458. });
  4459. })
  4460. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4461. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4462. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4463. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4464. ->orderBy('updated_at', 'desc')
  4465. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4466. //sql输出
  4467. if (empty($result)) {
  4468. return Result::error("暂无投诉信息", 0);
  4469. }
  4470. // 取出数据
  4471. $rows = $result->items();
  4472. $count = $result->total();
  4473. $responseData = [
  4474. 'rows' => $rows,
  4475. 'count' => $count,
  4476. ];
  4477. return Result::success($responseData);
  4478. }
  4479. public function getComplaintList(array $data): array
  4480. {
  4481. var_dump($data, '00000001000000000000');
  4482. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4483. unset($data['type_id']);
  4484. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4485. $where = [];
  4486. if ($type_id != 10000 && empty($data['deal_user'])) {
  4487. $where['complaint.user_id'] = $user_id;
  4488. }
  4489. if (!empty($data['title'])) {
  4490. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4491. }
  4492. if (!empty($data['department_id'])) {
  4493. $where['complaint.department_id'] = $data['department_id'];
  4494. }
  4495. if (!empty($data['deal'])) {
  4496. $where['complaint.deal'] = $data['deal'];
  4497. }
  4498. if (!empty($data['status'])) {
  4499. $where['complaint.status'] = $data['status'];
  4500. }
  4501. var_dump(!empty($data['deal_user']), '----------1');
  4502. var_dump($where, '----------2');
  4503. $result = Complaint::where($where)
  4504. ->when(!empty($data['status1']), function ($query) use ($data) {
  4505. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4506. })
  4507. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4508. // //json re_user_ids data[user_id]是不是在里面
  4509. // $query->Where(function ($q) use ($data) {
  4510. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4511. // ->where('complaint.status', 2);
  4512. // });
  4513. // })
  4514. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4515. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4516. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4517. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4518. ->orderBy('updated_at', 'desc')
  4519. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4520. //sql输出
  4521. if (empty($result)) {
  4522. return Result::error("暂无投诉信息", 0);
  4523. }
  4524. // 取出数据
  4525. $rows = $result->items();
  4526. $count = $result->total();
  4527. $responseData = [
  4528. 'rows' => $rows,
  4529. 'count' => $count,
  4530. ];
  4531. return Result::success($responseData);
  4532. }
  4533. public function getComplaintInfo(array $data): array
  4534. {
  4535. $result = Complaint::where('id', $data['id'])->first();
  4536. if (empty($result)) {
  4537. return Result::error("查询失败", 0);
  4538. }
  4539. return Result::success($result);
  4540. }
  4541. public function readComplaint(array $data): array
  4542. {
  4543. $result = Complaint::where('id', $data['id'])->first();
  4544. if (empty($result)) {
  4545. return Result::error("查询失败", 0);
  4546. }
  4547. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4548. $re_user_ids = json_decode($result['re_user_ids'], true);
  4549. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4550. //如果已经存在,就不再添加
  4551. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4552. $read_id = json_decode($result['read_id'], true);
  4553. if (!is_array($read_id)) {
  4554. $read_id = [];
  4555. }
  4556. if (!in_array($data['user_id'], $read_id)) {
  4557. $read_id[] = $data['user_id'];
  4558. $result['read_id'] = json_encode($read_id);
  4559. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4560. }
  4561. } else {
  4562. //如果不存在,就添加
  4563. $result['read_id'] = json_encode([$data['user_id']]);
  4564. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4565. }
  4566. }
  4567. return Result::success($result);
  4568. }
  4569. public function addComplaint(array $data): array
  4570. {
  4571. date_default_timezone_set('Asia/Shanghai');
  4572. $data['created_at'] = date('Y-m-d H:i:s');
  4573. $data['updated_at'] = date('Y-m-d H:i:s');
  4574. $this->sendMessage([
  4575. 'talk_type' => 800,
  4576. 'title' => $data['title'],
  4577. 'content' => '提交了审核',
  4578. 'messageType' => 6,
  4579. ]);
  4580. $result = Complaint::create($data);
  4581. return Result::success($result);
  4582. }
  4583. public function updateComplaint(array $data): array
  4584. {
  4585. date_default_timezone_set('Asia/Shanghai');
  4586. $data['updated_at'] = date('Y-m-d H:i:s');
  4587. $user_id = $data['user_id'] ?? 0;
  4588. $type_id = $data['type_id'] ?? 0;
  4589. unset($data['user_id']);
  4590. unset($data['type_id']);
  4591. $this->sendMessage([
  4592. 'talk_type' => 800,
  4593. 'title' => $data['title'],
  4594. 'content' => '提交了审核',
  4595. 'messageType' => 6,
  4596. ]);
  4597. $result = Complaint::where('id', $data['id'])->update($data);
  4598. return Result::success($result);
  4599. }
  4600. public function deleteComplaint(array $data): array
  4601. {
  4602. $result = Complaint::where('id', $data['id'])->delete();
  4603. return Result::success($result);
  4604. }
  4605. public function getComplainInfo(array $data): array
  4606. {
  4607. $result = Complaint::where('id', $data['id'])->first();
  4608. if (empty($result)) {
  4609. return Result::error("查询失败", 0);
  4610. }
  4611. return Result::success($result);
  4612. }
  4613. public function updateComplaintStatus(array $data): array
  4614. {
  4615. date_default_timezone_set('Asia/Shanghai');
  4616. $data['updated_at'] = date('Y-m-d H:i:s');
  4617. $user_id = $data['user_id'] ?? 0;
  4618. $type_id = $data['type_id'] ?? 0;
  4619. unset($data['user_id']);
  4620. unset($data['type_id']);
  4621. //处理, 写入处理人
  4622. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4623. $data['real_deal_user'] = $user_id;
  4624. }
  4625. //如果是deal 23,则判断是不是处理人
  4626. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4627. $complaintInof = Complaint::where('id', $data['id'])
  4628. ->where('real_deal_user', $user_id)
  4629. ->first();
  4630. if (empty($complaintInof)) {
  4631. return Result::error("处理人错误", 0);
  4632. }
  4633. }
  4634. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4635. if ($data['status'] == 1) {
  4636. $this->sendMessage([
  4637. 'talk_type' => 800,
  4638. 'title' => $complaintInfo['title'],
  4639. 'content' => '提交了审核',
  4640. 'messageType' => 6,
  4641. ]);
  4642. }
  4643. if ($data['status'] == 2 && !isset($data['deal'])) {
  4644. $this->sendMessage([
  4645. 'talk_type' => 801,
  4646. 'title' => $complaintInfo['title'],
  4647. 'content' => '审核通过',
  4648. 'messageType' => 6,
  4649. 'user_id' => $complaintInfo['user_id'],
  4650. ]);
  4651. $this->sendMessage([
  4652. 'talk_type' => 802,
  4653. 'title' => $complaintInfo['title'],
  4654. 'content' => '待处理',
  4655. 'messageType' => 6,
  4656. 'user_id' => $complaintInfo['re_user_ids'],
  4657. ]);
  4658. }
  4659. if ($data['status'] == 3 && !isset($data['deal'])) {
  4660. $this->sendMessage([
  4661. 'talk_type' => 801,
  4662. 'title' => $complaintInfo['title'],
  4663. 'content' => '审核拒绝',
  4664. 'messageType' => 6,
  4665. 'user_id' => $complaintInfo['user_id'],
  4666. ]);
  4667. }
  4668. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4669. $this->sendMessage([
  4670. 'talk_type' => 802,
  4671. 'title' => $complaintInfo['title'],
  4672. 'content' => '处理中',
  4673. 'messageType' => 6,
  4674. 'user_id' => $complaintInfo['re_user_ids'],
  4675. ]);
  4676. }
  4677. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4678. $this->sendMessage([
  4679. 'talk_type' => 802,
  4680. 'title' => $complaintInfo['title'],
  4681. 'content' => '不予处理',
  4682. 'messageType' => 6,
  4683. 'user_id' => $complaintInfo['re_user_ids'],
  4684. ]);
  4685. }
  4686. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4687. $this->sendMessage([
  4688. 'talk_type' => 802,
  4689. 'title' => $complaintInfo['title'],
  4690. 'content' => '已完结',
  4691. 'messageType' => 6,
  4692. 'user_id' => $complaintInfo['re_user_ids'],
  4693. ]);
  4694. }
  4695. $result = complaint::where('id', $data['id'])->update($data);
  4696. return Result::success($result);
  4697. }
  4698. public function updateGoodStatus(array $data): array
  4699. {
  4700. $user_id = $data['user_id'] ?? 0;
  4701. $type_id = $data['type_id'] ?? 0;
  4702. unset($data['user_id']);
  4703. unset($data['type_id']);
  4704. $goodInfo = Good::where('id', $data['id'])->first();
  4705. if ($data['status'] == 2) {
  4706. $this->sendMessage([
  4707. 'talk_type' => 201,
  4708. 'title' => $goodInfo['name'],
  4709. 'content' => '审核通过',
  4710. 'messageType' => 3,
  4711. 'user_id' => $goodInfo['user_id'],
  4712. ]);
  4713. }
  4714. if ($data['status'] == 3) {
  4715. $this->sendMessage([
  4716. 'talk_type' => 201,
  4717. 'title' => $goodInfo['name'],
  4718. 'content' => '审核拒绝',
  4719. 'messageType' => 3,
  4720. 'user_id' => $goodInfo['user_id'],
  4721. ]);
  4722. }
  4723. if ($data['status'] == 1) {
  4724. $this->sendMessage([
  4725. 'talk_type' => 200,
  4726. 'title' => $goodInfo['name'],
  4727. 'content' => '提交了审核',
  4728. 'messageType' => 3,
  4729. ]);
  4730. }
  4731. $result = Good::where('id', $data['id'])->update($data);
  4732. return Result::success($result);
  4733. }
  4734. public function updateJobHuntingStatus(array $data): array
  4735. {
  4736. $user_id = $data['user_id'] ?? 0;
  4737. $type_id = $data['type_id'] ?? 0;
  4738. unset($data['user_id']);
  4739. unset($data['type_id']);
  4740. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4741. if ($data['status'] == 2) {
  4742. $this->sendMessage([
  4743. 'talk_type' => 601,
  4744. 'title' => $jogHuntingInfo['name'],
  4745. 'content' => '审核通过',
  4746. 'messageType' => 11,
  4747. 'user_id' => $jogHuntingInfo['user_id'],
  4748. ]);
  4749. }
  4750. if ($data['status'] == 3) {
  4751. $this->sendMessage([
  4752. 'talk_type' => 601,
  4753. 'title' => $jogHuntingInfo['name'],
  4754. 'content' => '审核拒绝',
  4755. 'messageType' => 11,
  4756. 'user_id' => $jogHuntingInfo['user_id'],
  4757. ]);
  4758. }
  4759. if ($data['status'] == 1) {
  4760. $this->sendMessage([
  4761. 'talk_type' => 600,
  4762. 'title' => $jogHuntingInfo['name'],
  4763. 'content' => '提交了审核',
  4764. 'messageType' => 11,
  4765. ]);
  4766. }
  4767. $result = JobHunting::where('id', $data['id'])->update($data);
  4768. return Result::success($result);
  4769. }
  4770. public function updateNoticeStatus(array $data): array
  4771. {
  4772. $user_id = $data['user_id'] ?? 0;
  4773. $type_id = $data['type_id'] ?? 0;
  4774. unset($data['user_id']);
  4775. unset($data['type_id']);
  4776. //查询公告
  4777. $notice = Notice::where('id', $data['id'])->first();
  4778. if (empty($notice)) {
  4779. return Result::error("公告不存在", 0);
  4780. }
  4781. //$chat_ids 去除掉$data['user_id']
  4782. $chat_ids = json_decode($notice['re_user_ids'], true);
  4783. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4784. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4785. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  4786. //chat_group
  4787. $group_id = PublicData::uuid();
  4788. $groupData = [
  4789. 'id' => $group_id,
  4790. 'creator_id' => $notice['user_id'],
  4791. 'group_name' => $notice['group_name'] ?? '',
  4792. 'profile' => $notice['profile'] ?? 0,
  4793. ];
  4794. var_dump($groupData, '-----------------groupData-------');
  4795. $groupResult = ChatGroups::insertGetId($groupData);
  4796. var_dump($groupResult, '-----------------groupid-------');
  4797. $groupMemberData = [
  4798. 'id' => PublicData::uuid(),
  4799. 'user_id' => $notice['user_id'],
  4800. 'group_id' => $group_id,
  4801. 'leader' => 2,
  4802. ];
  4803. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4804. //插入群成员表
  4805. $groupMemberDataUser = [];
  4806. $chatData = [];
  4807. foreach ($chat_ids as $key => $value) {
  4808. $groupMemberDataUser[] = [
  4809. 'id' => PublicData::uuid(),
  4810. 'user_id' => $value,
  4811. 'group_id' => $group_id,
  4812. 'leader' => 1,
  4813. ];
  4814. $chatData[] = [
  4815. 'user_id' => $value,
  4816. 'msg_type' => 1,
  4817. 'receiver_id' => $group_id,
  4818. 'content' => '通过通知创建群聊',
  4819. 'group_receiver_id' => $notice['user_id'],
  4820. 'action' => 'recieved',
  4821. 'created_at' => date('Y-m-d H:i:s'),
  4822. ];
  4823. }
  4824. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4825. ChatGroupsMember::insert($groupMemberDataUser);
  4826. //插入一条管理员聊天记录
  4827. $chatData[] = [
  4828. 'user_id' => $notice['user_id'],
  4829. 'msg_type' => 1,
  4830. 'receiver_id' => $group_id,
  4831. 'content' => '通过通知创建群聊',
  4832. 'group_receiver_id' => $notice['user_id'],
  4833. 'action' => 'said',
  4834. 'created_at' => date('Y-m-d H:i:s'),
  4835. ];
  4836. var_dump($chatData, '-----------------chatData-------');
  4837. $chatResult = ChatRecords::insert($chatData);
  4838. //处理imp
  4839. $group = [
  4840. 'type' => 1,
  4841. 'name' => $notice['group_name'] ?? '',
  4842. 'profile' => '',
  4843. 'avatar' => '',
  4844. 'creator_id' => $notice['user_id'],
  4845. ];
  4846. $groupResult = GroupImp::insertGetId($group);
  4847. var_dump($groupResult, '获取imp group_id');
  4848. $groupMember = [
  4849. 'user_id' => $notice['user_id'],
  4850. 'group_id' => $groupResult,
  4851. 'leader' => 1,
  4852. 'join_time' => Date('Y-m-d H:i:s')
  4853. ];
  4854. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  4855. $talk_session = [
  4856. 'user_id' => $notice['user_id'],
  4857. 'to_from_id' => $groupResult,
  4858. 'talk_mode' => 2,
  4859. 'created_at' => Date('Y-m-d H:i:s'),
  4860. 'updated_at' => Date('Y-m-d H:i:s'),
  4861. ];
  4862. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  4863. //被通知人员处理
  4864. foreach ($chat_ids as $key => $value) {
  4865. $groupMemberdata[] = [
  4866. 'user_id' => $value,
  4867. 'group_id' => $groupResult,
  4868. 'leader' => 3,
  4869. 'join_time' => Date('Y-m-d H:i:s')
  4870. ];
  4871. $talk_sessionData[] = [
  4872. 'user_id' => $value,
  4873. 'to_from_id' => $groupResult,
  4874. 'talk_mode' => 2,
  4875. 'created_at' => Date('Y-m-d H:i:s'),
  4876. 'updated_at' => Date('Y-m-d H:i:s'),
  4877. ];
  4878. }
  4879. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  4880. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  4881. $group_id = $groupResult;
  4882. //更新result的 group_id
  4883. $data['group_id'] = $group_id;
  4884. Notice::where(['id' => $data['id']])->update($data);
  4885. }
  4886. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  4887. //删除掉信息
  4888. GroupImp::where('id', $notice['group_id'])->delete();
  4889. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  4890. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  4891. foreach ($chat_ids as $key => $value) {
  4892. }
  4893. //聊天记录删除
  4894. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  4895. $data['group_id'] = null;
  4896. Notice::where(['id' => $data['id']])->update($data);
  4897. }
  4898. $result = Notice::where('id', $data['id'])->update($data);
  4899. $noticeInfo = Notice::where('id', $data['id'])->first();
  4900. if ($data['status'] == 2) {
  4901. $this->sendMessage([
  4902. 'talk_type' => 701,
  4903. 'title' => $noticeInfo['title'],
  4904. 'content' => '审核通过',
  4905. 'messageType' => 3,
  4906. 'user_id' => $noticeInfo['user_id'],
  4907. ]);
  4908. }
  4909. if ($data['status'] == 3) {
  4910. $this->sendMessage([
  4911. 'talk_type' => 701,
  4912. 'title' => $noticeInfo['title'],
  4913. 'content' => '审核拒绝',
  4914. 'messageType' => 3,
  4915. 'user_id' => $noticeInfo['user_id'],
  4916. ]);
  4917. }
  4918. if ($data['status'] == 1) {
  4919. $this->sendMessage([
  4920. 'talk_type' => 700,
  4921. 'title' => $noticeInfo['title'],
  4922. 'content' => '提交了审核',
  4923. 'messageType' => 3,
  4924. ]);
  4925. }
  4926. return Result::success($result);
  4927. }
  4928. public function getDUser(array $data): array
  4929. {
  4930. if (!empty($data['ids'])) {
  4931. $user = User::whereIn('id', $data['ids'])->getall();
  4932. if (empty($user)) {
  4933. return Result::error('无数据', 0);
  4934. }
  4935. return Result::success($user);
  4936. }
  4937. $where = [];
  4938. if (!empty($data['department_id'])) {
  4939. $where['department_id'] = $data['department_id'];
  4940. }
  4941. if (!empty($data['city_id'])) {
  4942. $where['city_id'] = $data['city_id'];
  4943. }
  4944. $result = User::where('type_id', 2)
  4945. ->where('status', 1)
  4946. ->where($where)
  4947. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4948. ->get();
  4949. if (empty($result)) {
  4950. return Result::error("查询失败", 0);
  4951. }
  4952. return Result::success($result);
  4953. }
  4954. /**
  4955. * 验证导航名称是否重复
  4956. * @return void
  4957. */
  4958. public function checkCategoryName(array $data): array
  4959. {
  4960. $result = Category::when($data, function ($query) use ($data) {
  4961. if (isset($data['name']) && $data['name']) {
  4962. $query->where("name", $data['name']);
  4963. }
  4964. if (isset($data['id']) && $data['id']) {
  4965. $query->where("id", "!=", $data['id']);
  4966. }
  4967. })->first();
  4968. if ($result) {
  4969. return Result::error("已存在");
  4970. } else {
  4971. return Result::success();
  4972. }
  4973. }
  4974. //20250226 产品列表
  4975. // 20250306 -------招聘--------fr
  4976. /*
  4977. * 招聘列表
  4978. * */
  4979. public function getJobRecruitingList(array $data): array
  4980. {
  4981. $where = [];
  4982. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4983. if ($data['checkout'] == 0) {
  4984. $job_status = [0, 2];
  4985. } else {
  4986. $job_status = [1];
  4987. }
  4988. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4989. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4990. }
  4991. $user = User::where('id', $data['user_id'])->first();
  4992. if (empty($user)) {
  4993. return Result::error("用户不存在", 0);
  4994. }
  4995. // 3:企业会员
  4996. if ($user['type_id'] == 3) {
  4997. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4998. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4999. }
  5000. // 如果 $where 为空,则不添加 where 条件
  5001. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5002. return $query->where($where);
  5003. })
  5004. ->whereIn('job_recruiting.status', $job_status)
  5005. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5006. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5007. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5008. ->orderBy("updated_at", "desc")
  5009. ->offset(($data['page'] - 1) * $data['page_size'])
  5010. ->limit($data['page_size'])
  5011. ->get()
  5012. ->all();
  5013. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5014. return $query->where($where);
  5015. })
  5016. ->whereIn('job_recruiting.status', $job_status)
  5017. ->count();
  5018. if (empty($result)) {
  5019. return Result::error("暂无招聘信息", 0);
  5020. }
  5021. return Result::success($result);
  5022. }
  5023. /*
  5024. * 招聘信息添加
  5025. * */
  5026. public function addJobRecruiting(array $data): array
  5027. {
  5028. // var_dump('添加招聘进入news------data',$data);
  5029. // return Result::success($data);
  5030. $user = User::where('user.id', $data['user_id'])
  5031. ->where('user.status', 1)
  5032. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5033. ->select(
  5034. 'user.type_id',
  5035. 'user.mobile',
  5036. 'user.email',
  5037. 'user_info.business_name',
  5038. 'user_info.company_hy_id',
  5039. 'user_info.company_nature',
  5040. 'user_info.company_size',
  5041. 'user_info.introduction',
  5042. 'user_info.real_name',
  5043. 'user_info.company_url',
  5044. 'user_info.address_arr_id',
  5045. 'user_info.address'
  5046. )
  5047. ->first();
  5048. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5049. return Result::error("用户不存在", 0);
  5050. }
  5051. $web = Website::where('id', $data['website_id'])->first();
  5052. if (empty($web)) {
  5053. return Result::error("网站不存在", 0);
  5054. }
  5055. // var_dump('添加招聘进入news---user---user',$user);
  5056. // 处理招聘关键词
  5057. if(isset($data['keyword']) && !empty($data['keyword'])){
  5058. $data['keyword'] = str_replace(',',',',$data['keyword']);
  5059. }else{
  5060. Jieba::init(); // 初始化 jieba-php
  5061. Finalseg::init();
  5062. $segList = Jieba::cut($data['title']);
  5063. $segList1 = array_slice($segList, 0, 8);
  5064. $data['keyword'] = implode(',', $segList1);
  5065. }
  5066. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5067. $content = $data['description'];
  5068. // 去除 <style> 和 <script> 标签及其内容
  5069. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5070. // 去除所有 HTML 标签
  5071. $content = strip_tags($content);
  5072. // 去除 HTML 实体
  5073. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5074. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5075. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5076. // 去除多余空白
  5077. $content = preg_replace('/\s+/u', '', $content);
  5078. // 截取 100 个字符
  5079. $data['seo_description'] = mb_substr($content, 0, 100);
  5080. }
  5081. // return Result::success($user);
  5082. $data['action_id'] = $data['user_id'] ?? null;
  5083. $data['user_type'] = $user['type_id'] ?? null;
  5084. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5085. if(isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])){
  5086. $data['catid'] = end($data['cat_arr_id']);
  5087. }else{
  5088. $data['catid'] = 0;
  5089. }
  5090. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5091. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5092. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5093. // 公司地址 管理员必填
  5094. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5095. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5096. // 管理员-企业相关信息
  5097. $company = [
  5098. // 'user_id' => $data['user_id']?? null,
  5099. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5100. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5101. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5102. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5103. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5104. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5105. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5106. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5107. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5108. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5109. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5110. ];
  5111. //去掉相关企业信息
  5112. $job = array_diff_key($data, array_flip(array_keys($company)));
  5113. // var_dump('添加招聘进入news---job---user',$job);
  5114. Db::beginTransaction();
  5115. try {
  5116. // // 先添加职位相关信息
  5117. if ($user['type_id'] == 10000) {
  5118. $job['status'] = 1;
  5119. }
  5120. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5121. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5122. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5123. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5124. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5125. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5126. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5127. // return Result::success($job);
  5128. $jobId = JobRecruiting::insertGetId($job);
  5129. if (empty($jobId)) {
  5130. Db::rollBack();
  5131. return Result::error("添加失败");
  5132. }
  5133. // 添加公司信息
  5134. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5135. $company['job_id'] = $jobId;
  5136. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5137. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5138. if ($user['type_id'] == 10000) {
  5139. // 管理员添加企业信息
  5140. $companyId = JobCompany::insertGetId($company);
  5141. if (empty($companyId)) {
  5142. Db::rollBack();
  5143. return Result::error("添加失败");
  5144. }
  5145. } else {
  5146. // 企业会员添加企业信息
  5147. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5148. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5149. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5150. $company['job_id'] = $jobId;
  5151. $companyId = JobCompany::insertGetId($company);
  5152. if (empty($companyId)) {
  5153. Db::rollBack();
  5154. return Result::error("添加失败");
  5155. }
  5156. }
  5157. Db::commit();
  5158. $result = [
  5159. 'job_id' => $jobId,
  5160. 'company_id' => $companyId,
  5161. ];
  5162. return Result::success($result);
  5163. } catch (\Exception $e) {
  5164. Db::rollBack();
  5165. return Result::error($e->getMessage(), 0);
  5166. }
  5167. // return Result::success($result);
  5168. }
  5169. /*
  5170. * 获取招聘信息详情
  5171. * */
  5172. public function getJobRecruitingInfo(array $data): array
  5173. {
  5174. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5175. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5176. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5177. ->select(
  5178. 'job_recruiting.*',
  5179. 'website.website_name as website_name',
  5180. 'job_company.business_name',
  5181. 'job_company.company_hy_id',
  5182. 'job_company.company_size',
  5183. 'job_company.company_nature',
  5184. 'job_company.introduction',
  5185. 'job_company.real_name',
  5186. 'job_company.mobile',
  5187. 'job_company.company_url',
  5188. 'job_company.address_arr_id',
  5189. 'job_company.address',
  5190. 'job_company.email'
  5191. )
  5192. ->first();
  5193. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5194. if (!empty($cityId)) {
  5195. if (isset($cityId[1]) && $cityId[1] != null) {
  5196. $city = District::where('id', $cityId[1])->first(['name']);
  5197. } else {
  5198. $city = District::where('id', $cityId[0])->first(['name']);
  5199. }
  5200. $result['city'] = $city['name'] ?? '';
  5201. }
  5202. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5203. if (is_array($addressId) && !empty($addressId)) {
  5204. $address = District::whereIn('id', $addressId)
  5205. ->orderBy('level', 'asc')
  5206. ->get(['name'])
  5207. ->pluck('name')
  5208. ->implode('');
  5209. // $job->address_name = $address ?? '';
  5210. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5211. }
  5212. if (empty($result)) {
  5213. return Result::error("招聘信息不存在", 0);
  5214. }
  5215. // return Result::success($job);
  5216. return Result::success($result);
  5217. }
  5218. /*
  5219. * 修改招聘信息
  5220. * */
  5221. public function upJobRecruiting(array $data): array
  5222. {
  5223. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5224. // return Result::success($job);
  5225. if (empty($job)) {
  5226. return Result::error("招聘信息不存在", 0);
  5227. }
  5228. $user = User::where('id', $data['user_id'])->first();
  5229. // return Result::success($user);
  5230. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5231. return Result::error("用户不存在", 0);
  5232. }
  5233. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5234. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5235. }
  5236. // 处理招聘关键词
  5237. if(isset($data['keyword']) && !empty($data['keyword'])){
  5238. $data['keyword'] = str_replace(',',',',$data['keyword']);
  5239. }else{
  5240. Jieba::init(); // 初始化 jieba-php
  5241. Finalseg::init();
  5242. $segList = Jieba::cut($data['title']);
  5243. $segList1 = array_slice($segList, 0, 8);
  5244. $data['keyword'] = implode(',', $segList1);
  5245. }
  5246. if(!isset($data['seo_description']) || empty($data['seo_description'])){
  5247. $content = $data['description'];
  5248. // 去除 <style> 和 <script> 标签及其内容
  5249. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5250. // 去除所有 HTML 标签
  5251. $content = strip_tags($content);
  5252. // 去除 HTML 实体
  5253. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5254. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5255. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5256. // 去除多余空白
  5257. $content = preg_replace('/\s+/u', '', $content);
  5258. // 截取 100 个字符
  5259. $data['seo_description'] = mb_substr($content, 0, 100);
  5260. }
  5261. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5262. if(isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])){
  5263. $data['catid'] = end($data['cat_arr_id']);
  5264. }else{
  5265. }
  5266. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5267. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5268. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5269. // 公司地址 管理员必填
  5270. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5271. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5272. // 管理员-企业相关信息
  5273. $company = [
  5274. // 'user_id' => $data['user_id']?? null,
  5275. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5276. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5277. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5278. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5279. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5280. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5281. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5282. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5283. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5284. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5285. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5286. ];
  5287. //去掉相关企业信息
  5288. $data = array_diff_key($data, array_flip(array_keys($company)));
  5289. $jobId = $data['id'];
  5290. $web = $data['website_id'];
  5291. $data['action_id'] = $data['user_id'];
  5292. unset($data['user_id']);
  5293. unset($data['user_type']);
  5294. unset($data['id']);
  5295. unset($data['website_id']);
  5296. // return Result::success($data);
  5297. Db::beginTransaction();
  5298. try {
  5299. // 管理员修改招聘信息
  5300. if ($user['type_id'] == 10000) {
  5301. $data['website_id'] = $web;
  5302. $company['website_id'] = $data['website_id'];
  5303. $data['status'] = 1;
  5304. } else {
  5305. $data['status'] = 0;
  5306. }
  5307. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5308. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5309. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5310. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5311. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5312. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5313. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5314. // return Result::success($job);
  5315. // Db::rollBack();
  5316. // return Result::success($company);
  5317. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5318. $this->sendMessage([
  5319. 'talk_type' => 500,
  5320. 'title' => $data['title'],
  5321. 'content' => '提交了审核',
  5322. 'messageType' => 10,
  5323. ]);
  5324. }
  5325. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5326. if (empty($result['job'])) {
  5327. Db::rollBack();
  5328. return Result::error("修改招聘信息失败");
  5329. }
  5330. // 管理员修改企业相关信息
  5331. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5332. if (empty($result['company'])) {
  5333. Db::rollBack();
  5334. return Result::error("修改企业相关信息失败");
  5335. }
  5336. Db::commit();
  5337. // return Result::success($result);
  5338. } catch (\Exception $e) {
  5339. Db::rollBack();
  5340. return Result::error($e->getMessage(), 0);
  5341. }
  5342. return Result::success($result);
  5343. }
  5344. /*
  5345. * 招聘信息删除
  5346. * */
  5347. public function delJobRecruiting(array $data): array
  5348. {
  5349. $user = User::where('id', $data['user_id'])->first();
  5350. if (empty($user)) {
  5351. return Result::error("用户不存在", 0);
  5352. }
  5353. $job = JobRecruiting::where('id', $data['id'])->first();
  5354. if (empty($job)) {
  5355. return Result::error("招聘信息不存在", 0);
  5356. }
  5357. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5358. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5359. }
  5360. Db::beginTransaction();
  5361. try {
  5362. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5363. if (empty($result['job'])) {
  5364. Db::rollBack();
  5365. return Result::error("删除招聘信息失败");
  5366. }
  5367. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5368. if (empty($result['company'])) {
  5369. Db::rollBack();
  5370. return Result::error("删除企业相关信息失败");
  5371. }
  5372. Db::commit();
  5373. } catch (\Exception $e) {
  5374. Db::rollBack();
  5375. return Result::error($e->getMessage(), 0);
  5376. }
  5377. return Result::success($result);
  5378. }
  5379. /*
  5380. * 获取公司信息
  5381. * */
  5382. public function getJobCompany(array $data): array
  5383. {
  5384. $user = User::where('user.id', $data['user_id'])
  5385. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5386. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5387. ->first();
  5388. // return Result::success($user);
  5389. if (empty($user)) {
  5390. return Result::error("用户不存在", 0);
  5391. }
  5392. if ($user['type_id'] == 3) {
  5393. $result = [
  5394. // 'id' => 0,
  5395. 'user_id' => $data['user_id'],
  5396. 'website_id' => $data['website_id'],
  5397. 'business_name' => $user['business_name'], // 企业名称
  5398. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5399. 'company_nature' => $user['company_nature'], // 公司性质
  5400. 'company_size' => $user['company_size'], // 公司规模
  5401. 'introduction' => $user['introduction'], // 公司简介
  5402. 'real_name' => $user['real_name'], // 企业联系人
  5403. 'mobile' => $user['mobile'], // 企业联系电话
  5404. 'company_url' => $user['company_url'], // 企业网址
  5405. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5406. 'address' => $user['address'], // 企业地址
  5407. 'email' => $user['email'], // 企业邮箱
  5408. ];
  5409. } else {
  5410. return Result::error("用户类型错误", 0);
  5411. }
  5412. if (empty($result)) {
  5413. return Result::error("公司信息不存在", 0);
  5414. }
  5415. return Result::success($result);
  5416. }
  5417. /*
  5418. * 修改公司信息
  5419. * */
  5420. public function upJobCompany(array $data): array
  5421. {
  5422. // return Result::success($data);
  5423. $user = User::where('user.id', $data['user_id'])
  5424. ->where('user.status', 1)
  5425. ->select('user.user_name', 'user.type_id')
  5426. ->first();
  5427. if (empty($user)) {
  5428. return Result::error("用户不存在", 0);
  5429. }
  5430. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5431. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5432. $company = [
  5433. 'business_name' => $data['business_name'], // 企业名称
  5434. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5435. 'company_nature' => $data['company_nature'], // 公司性质
  5436. 'company_size' => $data['company_size'], // 公司规模
  5437. 'introduction' => $data['introduction'], // 公司简介
  5438. // 'real_name' => $data['real_name'], // 企业联系人
  5439. 'company_url' => $data['company_url'], // 企业网址
  5440. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5441. 'address' => $data['address'], // 企业详细地址
  5442. // 'email' => $data['email'], // 企业邮箱
  5443. ];
  5444. if ($user['type_id'] == 3) {
  5445. Db::beginTransaction();
  5446. try {
  5447. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5448. 'business_name' => $data['business_name'], // 企业名称
  5449. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5450. 'company_nature' => $data['company_nature'], // 公司性质
  5451. 'company_size' => $data['company_size'], // 公司规模
  5452. 'introduction' => $data['introduction'], // 公司简介
  5453. // 'real_name' => $data['real_name'], // 企业联系人
  5454. 'company_url' => $data['company_url'], // 企业网址
  5455. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5456. 'address' => $data['address'], // 企业详细地址
  5457. ]);
  5458. if (empty($result['userinfo'])) {
  5459. Db::rollBack();
  5460. return Result::error('修改企业会员信息失败!');
  5461. }
  5462. $result['user'] = User::where('id', $data['user_id'])->update([
  5463. 'email' => $data['email'], // 企业邮箱
  5464. ]);
  5465. if (empty($result['user'])) {
  5466. Db::rollBack();
  5467. return Result::error('修改个人中心信息失败!');
  5468. }
  5469. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5470. if (!empty($job_company)) {
  5471. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5472. if (empty($result['job_company'])) {
  5473. Db::rollBack();
  5474. return Result::error('修改企业会员信息失败!');
  5475. }
  5476. }
  5477. Db::commit();
  5478. return Result::success($result);
  5479. } catch (\Exception $e) {
  5480. Db::rollBack();
  5481. return Result::error($e->getMessage(), 0);
  5482. }
  5483. } else {
  5484. return Result::error("用户类型错误", 0);
  5485. }
  5486. }
  5487. /*
  5488. * 获取省-市
  5489. * */
  5490. public function getJobRecruitingArea(array $data): array
  5491. {
  5492. if (isset($data['pid']) && $data['pid'] != null) {
  5493. $result = District::where('pid', $data['pid'])->get()->all();
  5494. } else {
  5495. $result = District::where('level', 1)->get()->all();
  5496. }
  5497. if (empty($result)) {
  5498. return Result::error("暂无此省市", 0);
  5499. }
  5500. return Result::success($result);
  5501. }
  5502. /*
  5503. * 获取行业分类
  5504. * */
  5505. public function getIndustry(array $data): array
  5506. {
  5507. $result = JobIndustry::get()->all();
  5508. if (empty($result)) {
  5509. return Result::error("暂无行业分类", 0);
  5510. }
  5511. return Result::success($result);
  5512. }
  5513. /*
  5514. * 获取职位
  5515. * */
  5516. public function getPositionList(array $data): array
  5517. {
  5518. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5519. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5520. } else {
  5521. $result = JobPosition::where('zwpid', 0)->get()->all();
  5522. }
  5523. if (empty($result)) {
  5524. return Result::error("暂无此职位", 0);
  5525. }
  5526. return Result::success($result);
  5527. }
  5528. /*
  5529. * 获取工作性质-菜单
  5530. * */
  5531. public function getJobNature(array $data): array
  5532. {
  5533. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5534. if (empty($result)) {
  5535. return Result::error("暂无工作性质", 0);
  5536. }
  5537. return Result::success($result);
  5538. }
  5539. /*
  5540. * 获取工作经验-菜单
  5541. * */
  5542. public function getExperience(array $data): array
  5543. {
  5544. $result = JobEnum::where('egroup', 'years')->get()->all();
  5545. if (empty($result)) {
  5546. return Result::error("暂无工作经验", 0);
  5547. }
  5548. return Result::success($result);
  5549. }
  5550. /*
  5551. * 获取学历-菜单
  5552. * */
  5553. public function getEducation(array $data): array
  5554. {
  5555. $result = JobEnum::where('egroup', 'education')->get()->all();
  5556. if (empty($result)) {
  5557. return Result::error("暂无学历", 0);
  5558. }
  5559. return Result::success($result);
  5560. }
  5561. /*
  5562. * 获取薪资-菜单
  5563. * */
  5564. public function getSalary(array $data): array
  5565. {
  5566. $result = JobEnum::where('egroup', 'income')->get()->all();
  5567. if (empty($result)) {
  5568. return Result::error("暂无薪资", 0);
  5569. }
  5570. return Result::success($result);
  5571. }
  5572. /*
  5573. * 获取语言-菜单
  5574. * */
  5575. public function getLanguage(array $data): array
  5576. {
  5577. $result = JobEnum::where('egroup', 'language')->get()->all();
  5578. if (empty($result)) {
  5579. return Result::error("暂无语言", 0);
  5580. }
  5581. return Result::success($result);
  5582. }
  5583. /*
  5584. * 获取掌握程度-菜单
  5585. * */
  5586. public function getLevel(array $data): array
  5587. {
  5588. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5589. if (empty($result)) {
  5590. return Result::error("暂无工作性质", 0);
  5591. }
  5592. return Result::success($result);
  5593. }
  5594. // 公司信息
  5595. /*
  5596. * 获取公司性质-菜单
  5597. * */
  5598. public function getCompanyNature(array $data): array
  5599. {
  5600. $result = JobNature::get()->all();
  5601. if (empty($result)) {
  5602. return Result::error("暂无公司性质", 0);
  5603. }
  5604. return Result::success($result);
  5605. }
  5606. /*
  5607. * 获取公司规模-菜单
  5608. * */
  5609. public function getCompanySize(array $data): array
  5610. {
  5611. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5612. if (empty($result)) {
  5613. return Result::error("暂无公司规模", 0);
  5614. }
  5615. return Result::success($result);
  5616. }
  5617. /*
  5618. * 招聘信息审核
  5619. * */
  5620. public function checkJobRecruiting(array $data): array
  5621. {
  5622. $user = User::where('id', $data['user_id'])->first();
  5623. if (empty($user)) {
  5624. return Result::error("用户不存在", 0);
  5625. }
  5626. $job = JobRecruiting::where('id', $data['id'])->first();
  5627. if (empty($job)) {
  5628. return Result::error("招聘信息不存在", 0);
  5629. }
  5630. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5631. if ($user['type_id'] != 10000) {
  5632. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5633. }
  5634. // 驳回原因
  5635. if ($data['status'] == 2) {
  5636. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5637. }
  5638. $data['action_id'] = $data['user_id'];
  5639. unset($data['user_id']);
  5640. if ($data['status'] == 1) {
  5641. $this->sendMessage([
  5642. 'talk_type' => 501,
  5643. 'title' => $job['title'],
  5644. 'content' => '审核通过',
  5645. 'messageType' => 10,
  5646. 'user_id' => $job['user_id'],
  5647. ]);
  5648. }
  5649. if ($data['status'] == 2) {
  5650. $this->sendMessage([
  5651. 'talk_type' => 501,
  5652. 'title' => $job['title'],
  5653. 'content' => '审核拒绝',
  5654. 'messageType' => 10,
  5655. 'user_id' => $job['user_id'],
  5656. ]);
  5657. }
  5658. if ($data['status'] == 0) {
  5659. $this->sendMessage([
  5660. 'talk_type' => 500,
  5661. 'title' => $job['title'],
  5662. 'content' => '提交了审核',
  5663. 'messageType' => 10,
  5664. ]);
  5665. }
  5666. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5667. if (empty($result)) {
  5668. return Result::error("审核失败", 0);
  5669. }
  5670. return Result::success($result);
  5671. }
  5672. public function myApplyList(array $data): array
  5673. {
  5674. var_dump($data, '------参数');
  5675. $user = User::where('id', $data['user_id'])->first();
  5676. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5677. return Result::error("用户不存在", 0);
  5678. }
  5679. // 1:个人会员 职场机会
  5680. if ($user['type_id'] == 1) {
  5681. $where['user_id'] = $user['id'];
  5682. }
  5683. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5684. $query->where('user_id', $user['id']);
  5685. })
  5686. ->pluck('recruit_id');
  5687. $where = [];
  5688. if (isset($data['salary']) && $data['salary'] != null) {
  5689. $where['job_recruiting.salary'] = $data['salary'];
  5690. }
  5691. if (isset($data['experience']) && $data['experience'] != null) {
  5692. $where['job_recruiting.experience'] = $data['experience'];
  5693. }
  5694. if (isset($data['business_name']) && $data['business_name'] != null) {
  5695. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5696. }
  5697. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5698. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5699. ->where($where);
  5700. // ->count();
  5701. $count = $query->count();
  5702. $query = clone $query;
  5703. $job = $query
  5704. ->leftJoin('job_enum as income_enum', function ($join) {
  5705. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5706. ->where('income_enum.egroup', 'income');
  5707. })
  5708. ->leftJoin('job_enum as years_enum', function ($join) {
  5709. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5710. ->where('years_enum.egroup', 'years');
  5711. })
  5712. // ->where($where)
  5713. ->orderBy('job_recruiting.updated_at', 'desc')
  5714. ->select(
  5715. 'job_recruiting.id',
  5716. 'job_recruiting.title',
  5717. 'job_company.business_name',
  5718. 'income_enum.evalue as salary_evalue',
  5719. 'income_enum.ename as salary_ename',
  5720. 'years_enum.evalue as experience_evalue',
  5721. 'years_enum.ename as experience_ename',
  5722. 'job_recruiting.updated_at'
  5723. )
  5724. ->offset(($data['page'] - 1) * $data['pageSize'])
  5725. ->limit($data['pageSize'])
  5726. ->get()
  5727. ->all();
  5728. if (empty($job)) {
  5729. return Result::error("暂无招聘信息", 0);
  5730. }
  5731. $result = [
  5732. 'row' => $job,
  5733. 'count' => $count,
  5734. ];
  5735. return Result::success($result);
  5736. }
  5737. public function readJobApply(array $data): array
  5738. {
  5739. $result = JobApply::where('id', $data['id'])->first();
  5740. if (empty($result)) {
  5741. return Result::error("查询失败", 0);
  5742. }
  5743. $result = JobApply::where('id', $data['id'])->update([
  5744. 'status' => 2,
  5745. ]);
  5746. return Result::success($result);
  5747. }
  5748. /*
  5749. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5750. * */
  5751. public function getRecruitingList(array $data): array
  5752. {
  5753. $user = User::where('id', $data['user_id'])->first();
  5754. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5755. return Result::error("用户不存在", 0);
  5756. }
  5757. // 1:个人会员 职场机会
  5758. if ($user['type_id'] == 1) {
  5759. $where['user_id'] = $user['id'];
  5760. }
  5761. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5762. $query->where('receiver_id', $user['id']);
  5763. })
  5764. ->pluck('recruit_id');
  5765. // return Result::success($recruitingId);
  5766. $where = [];
  5767. if (isset($data['salary']) && $data['salary'] != null) {
  5768. $where['job_recruiting.salary'] = $data['salary'];
  5769. }
  5770. if (isset($data['experience']) && $data['experience'] != null) {
  5771. $where['job_recruiting.experience'] = $data['experience'];
  5772. }
  5773. if (isset($data['business_name']) && $data['business_name'] != null) {
  5774. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5775. }
  5776. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5777. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5778. ->where($where);
  5779. // ->count();
  5780. $count = $query->count();
  5781. $query = clone $query;
  5782. $job = $query
  5783. ->leftJoin('job_enum as income_enum', function ($join) {
  5784. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5785. ->where('income_enum.egroup', 'income');
  5786. })
  5787. ->leftJoin('job_enum as years_enum', function ($join) {
  5788. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5789. ->where('years_enum.egroup', 'years');
  5790. })
  5791. // ->where($where)
  5792. ->orderBy('job_recruiting.updated_at', 'desc')
  5793. ->select(
  5794. 'job_recruiting.id',
  5795. 'job_recruiting.title',
  5796. 'job_company.business_name',
  5797. 'income_enum.evalue as salary_evalue',
  5798. 'income_enum.ename as salary_ename',
  5799. 'years_enum.evalue as experience_evalue',
  5800. 'years_enum.ename as experience_ename',
  5801. 'job_recruiting.updated_at'
  5802. )
  5803. ->offset(($data['page'] - 1) * $data['pageSize'])
  5804. ->limit($data['pageSize'])
  5805. ->get()
  5806. ->all();
  5807. if (empty($job)) {
  5808. return Result::error("暂无招聘信息", 0);
  5809. }
  5810. $result = [
  5811. 'row' => $job,
  5812. 'count' => $count,
  5813. ];
  5814. return Result::success($result);
  5815. }
  5816. /*
  5817. * 获取企业会员-招聘信息列表
  5818. * */
  5819. public function getRecruitingInfo(array $data): array
  5820. {
  5821. $user = User::where('id', $data['user_id'])->first();
  5822. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5823. return Result::error("用户不存在", 0);
  5824. }
  5825. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5826. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5827. ->select(
  5828. 'job_recruiting.*',
  5829. 'job_company.business_name',
  5830. 'job_company.company_hy_id',
  5831. 'job_company.company_size',
  5832. 'job_company.company_nature',
  5833. 'job_company.introduction',
  5834. 'job_company.real_name',
  5835. 'job_company.mobile',
  5836. 'job_company.company_url',
  5837. 'job_company.address_arr_id',
  5838. 'job_company.address',
  5839. 'job_company.email'
  5840. )
  5841. ->get();
  5842. if (empty($recruiting)) {
  5843. return Result::error("暂无招聘信息", 0);
  5844. }
  5845. return Result::success($recruiting);
  5846. }
  5847. /*
  5848. * 获取企业会员-我的沟通
  5849. * */
  5850. public function getJobResumeList(array $data): array
  5851. {
  5852. $user = User::where('id', $data['user_id'])->first();
  5853. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5854. return Result::error("用户不存在", 0);
  5855. }
  5856. $where = [];
  5857. if (isset($data['salary']) && $data['salary'] != null) {
  5858. $where['job_hunting.salary'] = $data['salary'];
  5859. }
  5860. if (isset($data['user_name']) && $data['user_name'] != null) {
  5861. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5862. }
  5863. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5864. $query->where('job_resume.user_id', $user['id']);
  5865. })
  5866. ->when(!empty($where), function ($query) use ($where) {
  5867. $query->where($where);
  5868. })
  5869. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5870. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5871. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5872. ->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');
  5873. $count = $job->count();
  5874. if ($count == 0) {
  5875. return Result::error("暂无沟通记录", 0);
  5876. }
  5877. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5878. ->offset(($data['page'] - 1) * $data['pageSize'])
  5879. ->limit($data['pageSize'])
  5880. ->get();
  5881. if (empty($jobs)) {
  5882. return Result::error("暂无沟通记录", 0);
  5883. }
  5884. $result['row'] = $this->processJob($jobs, '');
  5885. $result['count'] = $count;
  5886. return Result::success($result);
  5887. }
  5888. public function readJobResume(array $data): array
  5889. {
  5890. $result = JobResume::where('id', $data['id'])->first();
  5891. if (empty($result)) {
  5892. return Result::error("查询失败", 0);
  5893. }
  5894. $result = JobResume::where('id', $data['id'])->update([
  5895. 'status' => 2,
  5896. ]);
  5897. return Result::success($result);
  5898. }
  5899. // 20250306 招聘
  5900. //20250422 书刊音像
  5901. public function addBook(array $data): array
  5902. {
  5903. $user_id = $data['user_id'] ?? 0;
  5904. $type_id = $data['type_id'] ?? 0;
  5905. // $website_id = $data['website_id'] ?? 0;
  5906. // unset($data['user_id']);
  5907. unset($data['type_id']);
  5908. // unset($data['website_id']);
  5909. //处理数组
  5910. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5911. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5912. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5913. if ($data['img_url'] == '') {
  5914. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5915. preg_match_all($reg, $data['detail'], $matches);
  5916. if (isset($matches[1][0])) {
  5917. //截取varchar240
  5918. $data['img_url'] = substr($matches[1][0], 0, 240);
  5919. }
  5920. }
  5921. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5922. //提取标题+内容中的关键词
  5923. $data['keyword'] = $data['title'];
  5924. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5925. Jieba::init(); // 初始化 jieba-php
  5926. Finalseg::init();
  5927. $segList = Jieba::cut($data['keyword']);
  5928. $segList1 = array_slice($segList, 0, 8);
  5929. $data['keyword'] = implode(',', $segList1);
  5930. }
  5931. if ($data['description'] == '') {
  5932. //提取内容中的描述
  5933. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5934. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5935. }
  5936. var_dump($data, '--');
  5937. if ($data['status'] == 1) {
  5938. $this->sendMessage([
  5939. 'talk_type' => 400,
  5940. 'title' => $data['title'],
  5941. 'content' => '提交了审核',
  5942. 'messageType' => 7,
  5943. ]);
  5944. }
  5945. $result = Book::insertGetId($data);
  5946. if (empty($result)) {
  5947. return Result::error("添加失败", 0);
  5948. }
  5949. return Result::success($result);
  5950. }
  5951. public function getBookList(array $data): array
  5952. {
  5953. $where = [];
  5954. if (!empty($data["title"])) {
  5955. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5956. }
  5957. if (!empty($data['website_name'])) {
  5958. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5959. }
  5960. if (!empty($data['status'])) {
  5961. $where[] = ['book.status', '=', $data['status']];
  5962. }
  5963. $user_id = $data['user_id'];
  5964. $type_id = $data['type_id'];
  5965. // $type_id = 4;
  5966. var_dump($type_id, '------1--------');
  5967. if ($type_id != 10000) {
  5968. $where[] = ['book.user_id', '=', $user_id];
  5969. }
  5970. var_dump(!empty($data['status1']), '=-===1');
  5971. $result = Book::where($where)
  5972. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5973. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5974. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5975. ->when(isset($data['status1']), function ($query) use ($data) {
  5976. $query->whereIn('book.status', [1, 3]);
  5977. })
  5978. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5979. ->orderBy("updated_at", "desc")
  5980. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5981. if (empty($result)) {
  5982. return Result::error("暂无数据", 0);
  5983. }
  5984. // 取出数据
  5985. $rows = $result->items();
  5986. $count = $result->total();
  5987. $responseData = [
  5988. 'rows' => $rows,
  5989. 'count' => $count,
  5990. ];
  5991. return Result::success($responseData);
  5992. }
  5993. public function deleteBook(array $data): array
  5994. {
  5995. $result = Book::where('id', $data['id'])->delete();
  5996. if (empty($result)) {
  5997. return Result::error("删除失败", 0);
  5998. }
  5999. return Result::success($result);
  6000. }
  6001. public function updateBook(array $data): array
  6002. {
  6003. // $user_id = $data['user_id'] ?? 0;
  6004. $type_id = $data['type_id'] ?? 0;
  6005. // $website_id = $data['website_id'] ?? 0;
  6006. unset($data['user_id']);
  6007. unset($data['type_id']);
  6008. // unset($data['website_id']);
  6009. //处理数组
  6010. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6011. if ($data['img_url'] == '') {
  6012. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6013. preg_match_all($reg, $data['detail'], $matches);
  6014. if (isset($matches[1][0])) {
  6015. //截取varchar240
  6016. $data['img_url'] = substr($matches[1][0], 0, 240);
  6017. }
  6018. }
  6019. if ($data['keyword'] == '') {
  6020. //提取标题+内容中的关键词
  6021. $data['keyword'] = $data['title'];
  6022. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6023. Jieba::init(); // 初始化 jieba-php
  6024. Finalseg::init();
  6025. $segList = Jieba::cut($data['keyword']);
  6026. $segList1 = array_slice($segList, 0, 8);
  6027. $data['keyword'] = implode(',', $segList1);
  6028. }
  6029. if ($data['description'] == '') {
  6030. //提取内容中的描述
  6031. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6032. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6033. }
  6034. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6035. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6036. if ($data['status'] == 1) {
  6037. $this->sendMessage([
  6038. 'talk_type' => 400,
  6039. 'title' => $data['title'],
  6040. 'content' => '提交了审核',
  6041. 'messageType' => 7,
  6042. ]);
  6043. }
  6044. $result = Book::where("id", $data["id"])->update($data);
  6045. if (empty($result)) {
  6046. return Result::error("更新失败", 0);
  6047. }
  6048. return Result::success($result);
  6049. }
  6050. public function getBookInfo(array $data): array
  6051. {
  6052. $result = Book::where("id", $data["id"])->first();
  6053. if (empty($result)) {
  6054. return Result::error("获取失败", 0);
  6055. }
  6056. return Result::success($result);
  6057. }
  6058. public function updateBookStatus(array $data): array
  6059. {
  6060. //审核
  6061. unset($data['user_id']);
  6062. $bookInfo = Book::where("id", $data["id"])->first();
  6063. var_dump($bookInfo, '----');
  6064. if ($data['status'] == 2) {
  6065. $this->sendMessage([
  6066. 'talk_type' => 401,
  6067. 'title' => $bookInfo['title'],
  6068. 'content' => '审核通过',
  6069. 'messageType' => 7,
  6070. 'user_id' => $bookInfo['user_id'],
  6071. ]);
  6072. }
  6073. if ($data['status'] == 3) {
  6074. $this->sendMessage([
  6075. 'talk_type' => 401,
  6076. 'title' => $bookInfo['title'],
  6077. 'content' => '审核拒绝',
  6078. 'messageType' => 7,
  6079. 'user_id' => $bookInfo['user_id'],
  6080. ]);
  6081. }
  6082. if ($data['status'] == 1) {
  6083. $this->sendMessage([
  6084. 'talk_type' => 400,
  6085. 'title' => $bookInfo['title'],
  6086. 'content' => '提交了审核',
  6087. 'messageType' => 7,
  6088. // 'user_id'=>$bookInfo['user_id'],
  6089. ]);
  6090. }
  6091. $result = Book::where("id", $data["id"])->update($data);
  6092. if (empty($result)) {
  6093. return Result::error("更新失败", 0);
  6094. }
  6095. return Result::success($result);
  6096. }
  6097. //20250422 书刊音像
  6098. /**
  6099. * 贴身宝贝
  6100. * @param array $data
  6101. * @return array
  6102. */
  6103. public function getWebsiteTsbb(array $data): array
  6104. {
  6105. $month = $data['month'] ?? date('m');
  6106. $day = $data['day'] ?? date('d');
  6107. // 使用缓存键
  6108. $cacheKey = "tsbb_data_{$month}_{$day}";
  6109. // 尝试从缓存获取数据
  6110. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6111. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6112. if ($cachedData = $cache->get($cacheKey)) {
  6113. return Result::success(unserialize($cachedData));
  6114. }
  6115. //查询老黄历
  6116. try {
  6117. $date = date('Y-m-d');
  6118. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6119. // 使用 curl 替代 file_get_contents
  6120. $ch = curl_init();
  6121. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6122. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6123. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6124. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6125. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6126. 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');
  6127. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6128. 'Accept: application/json',
  6129. 'Content-Type: application/json',
  6130. 'Referer: https://www.36jxs.com/'
  6131. ]);
  6132. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6133. curl_setopt($ch, CURLOPT_ENCODING, '');
  6134. $almanacResponse = curl_exec($ch);
  6135. var_dump("====:", $almanacResponse);
  6136. if (curl_errno($ch)) {
  6137. var_dump('Curl error:', curl_error($ch));
  6138. throw new \Exception('Curl error: ' . curl_error($ch));
  6139. }
  6140. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6141. curl_close($ch);
  6142. if ($almanacResponse === false) {
  6143. throw new \Exception('Failed to fetch almanac data');
  6144. }
  6145. $almanacData = json_decode($almanacResponse, true);
  6146. if (json_last_error() !== JSON_ERROR_NONE) {
  6147. throw new \Exception('Failed to parse almanac data');
  6148. }
  6149. $almanacInfo = $almanacData['data'] ?? [];
  6150. } catch (\Exception $e) {
  6151. var_dump('Exception:', $e->getMessage());
  6152. $almanacInfo = [];
  6153. }
  6154. // 获取历史上的今天数据
  6155. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6156. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6157. ->orderBy('year', 'asc')
  6158. ->select("title", "id", "year", DB::raw('1 as type'))
  6159. ->limit(16)
  6160. ->get();
  6161. // 获取节日数据 - 从今天开始获取未来4条
  6162. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6163. ->orderBy('showtime', 'asc')
  6164. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6165. ->limit(16)
  6166. ->get();
  6167. //说文解字
  6168. $chartacterList = Character::orderBy('updated_at', 'desc')
  6169. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6170. ->limit(6)
  6171. ->get();
  6172. //谜语沙龙
  6173. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6174. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6175. ->limit(4)
  6176. ->get();
  6177. //成语欣赏
  6178. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6179. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6180. ->limit(32)
  6181. ->get();
  6182. //名联赏析
  6183. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6184. ->select("id", "first", "second", DB::raw('6 as type'))
  6185. ->limit(6)
  6186. ->get();
  6187. // 获取分类文章数据
  6188. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6189. ->pluck('category_id')
  6190. ->toArray();
  6191. $articlesList = [];
  6192. foreach ($categoryIds as $catid) {
  6193. // 先查有图片的
  6194. $withImg = DB::table('article')
  6195. ->where('status', 1)
  6196. ->where('catid', $catid)
  6197. ->whereNotNull('imgurl')
  6198. ->where('imgurl', '!=', '')
  6199. ->orderBy('updated_at', 'desc')
  6200. ->limit(6)
  6201. ->get();
  6202. $count = $withImg->count();
  6203. if ($count < 6) {
  6204. // 不足6条再查无图片的补足
  6205. $withoutImg = DB::table('article')
  6206. ->where('status', 1)
  6207. ->where('catid', $catid)
  6208. ->where(function ($q) {
  6209. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6210. })
  6211. ->orderBy('updated_at', 'desc')
  6212. ->limit(6 - $count)
  6213. ->get();
  6214. $articles = $withImg->concat($withoutImg);
  6215. } else {
  6216. $articles = $withImg;
  6217. }
  6218. // 组装
  6219. $category = \App\Model\Category::find($catid);
  6220. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6221. $articlesList[] = [
  6222. 'category_name' => $category ? $category->name : '',
  6223. 'catid' => $catid,
  6224. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6225. 'type' => 100,
  6226. 'list' => $articles->map(function ($item) {
  6227. return [
  6228. 'id' => $item->id,
  6229. 'title' => $item->title,
  6230. 'imgurl' => $item->imgurl,
  6231. 'created_at' => $item->created_at
  6232. ];
  6233. })->values()
  6234. ];
  6235. }
  6236. $result = [
  6237. 'almanac' => $almanacInfo,
  6238. 'historyTodayList' => [
  6239. 'category_name' => '历史上的今天',
  6240. 'list' => $historyTodayList,
  6241. 'type' => 1
  6242. ],
  6243. 'festivalList' => [
  6244. 'category_name' => '节日预告',
  6245. 'list' => $festivalList,
  6246. 'type' => 2
  6247. ],
  6248. 'chartacterList' => [
  6249. 'category_name' => '说文解字',
  6250. 'list' => $chartacterList,
  6251. 'type' => 3
  6252. ],
  6253. 'coupletList' => [
  6254. 'category_name' => '名联赏析',
  6255. 'list' => $coupletList,
  6256. 'type' => 6
  6257. ],
  6258. 'riddletList' => [
  6259. 'category_name' => '谜语沙龙',
  6260. 'list' => $riddletList,
  6261. 'type' => 4
  6262. ],
  6263. 'idiomList' => [
  6264. 'category_name' => '成语欣赏',
  6265. 'list' => $idiomList,
  6266. 'type' => 5
  6267. ],
  6268. 'articlesList' => $articlesList
  6269. ];
  6270. // 缓存结果,设置1小时过期
  6271. $cache->set($cacheKey, serialize($result), 3600);
  6272. return Result::success($result);
  6273. }
  6274. /**
  6275. * 获取资讯列表
  6276. */
  6277. public function getWebsiteTsbbList(array $data): array
  6278. {
  6279. $page = $data['page'] ?? 1;
  6280. $pageSize = $data['pageSize'] ?? 10;
  6281. // 如果没有传入月份和日期,则使用今天的日期
  6282. $month = $data['month'] ?? date('m');
  6283. $day = $data['day'] ?? date('d');
  6284. $total = 0;
  6285. $result = [];
  6286. $data['type'] = intval($data['type']);
  6287. var_dump("接收参数:", $data);
  6288. switch ($data['type']) {
  6289. case 1:
  6290. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6291. // 当前月份之后的数据
  6292. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6293. // 或者当前月份且日期大于等于当前日期的数据
  6294. ->orWhere(function ($q) use ($month, $day) {
  6295. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6296. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6297. });
  6298. })
  6299. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6300. $total = $query->count();
  6301. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6302. ->offset(($page - 1) * $pageSize)
  6303. ->limit($pageSize)
  6304. ->get();
  6305. break;
  6306. case 2:
  6307. $query = Festival::where(function ($q) use ($month, $day) {
  6308. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6309. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6310. ->orWhere(function ($q) use ($month, $day) {
  6311. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6312. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6313. });
  6314. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6315. $total = $query->count();
  6316. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6317. ->offset(($page - 1) * $pageSize)
  6318. ->limit($pageSize)
  6319. ->get();
  6320. break;
  6321. case 3:
  6322. $query = Character::orderBy("updated_at", "desc");
  6323. $total = $query->count();
  6324. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6325. ->offset(($page - 1) * $pageSize)
  6326. ->limit($pageSize)
  6327. ->get();
  6328. break;
  6329. case 4:
  6330. $query = Riddle::orderBy("updated_at", "desc");
  6331. $total = $query->count();
  6332. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6333. ->offset(($page - 1) * $pageSize)
  6334. ->limit($pageSize)
  6335. ->get();
  6336. break;
  6337. case 5:
  6338. $query = Idiom::orderBy("updated_at", "desc");
  6339. $total = $query->count();
  6340. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6341. ->offset(($page - 1) * $pageSize)
  6342. ->limit($pageSize)
  6343. ->get();
  6344. break;
  6345. case 6:
  6346. $query = Couplet::orderBy("updated_at", "desc");
  6347. $total = $query->count();
  6348. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6349. ->offset(($page - 1) * $pageSize)
  6350. ->limit($pageSize)
  6351. ->get();
  6352. break;
  6353. default:
  6354. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6355. $total = $query->count();
  6356. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6357. ->offset(($page - 1) * $pageSize)
  6358. ->limit($pageSize)
  6359. ->get();
  6360. }
  6361. return Result::success([
  6362. 'list' => $result,
  6363. 'total' => $total,
  6364. 'page' => (int)$page,
  6365. 'pageSize' => (int)$pageSize,
  6366. 'month' => $month,
  6367. 'day' => $day
  6368. ]);
  6369. }
  6370. /**
  6371. * 1:历史上的今天
  6372. * 2:节日
  6373. * 3:文章
  6374. *
  6375. * 资讯详情信息
  6376. */
  6377. public function getWebsiteTsbbDetail(array $data): array
  6378. {
  6379. $data['type'] = intval($data['type']);
  6380. switch ($data['type']) {
  6381. case 1:
  6382. $result = HistoryToday::where("id", $data['id'])->first();
  6383. break;
  6384. case 2:
  6385. $result = Festival::where("id", $data['id'])->first();
  6386. break;
  6387. case 3:
  6388. $result = Character::where("id", $data['id'])->first();
  6389. break;
  6390. case 4:
  6391. $result = Riddle::where("id", $data['id'])->first();
  6392. break;
  6393. case 5:
  6394. $result = Idiom::where("id", $data['id'])->first();
  6395. break;
  6396. case 6:
  6397. $result = Couplet::where("id", $data['id'])->first();
  6398. break;
  6399. default:
  6400. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6401. break;
  6402. }
  6403. return Result::success($result);
  6404. }
  6405. /**
  6406. * 农网导航首页数据
  6407. */
  6408. public function getWebsiteNwHomeList(array $data): array
  6409. {
  6410. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6411. ->pluck('category_id')
  6412. ->toArray();
  6413. // 使用子查询优化
  6414. $articlesList = DB::table('article')
  6415. ->select([
  6416. 'article.id',
  6417. 'article.title',
  6418. 'article.imgurl',
  6419. 'article.created_at',
  6420. 'category.name as category_name',
  6421. 'category.id as category_id',
  6422. 'website_category.aLIas_pinyin as pinyin',
  6423. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6424. DB::raw('100 as type')
  6425. ])
  6426. ->join('category', 'article.catid', '=', 'category.id')
  6427. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6428. ->leftJoin('website_category as parent_wc', function ($join) {
  6429. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6430. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6431. })
  6432. ->where('website_category.website_id', $data['website_id'])
  6433. ->where('article.status', 1)
  6434. ->whereIn('category.id', $categoryIds)
  6435. ->orderBy('article.created_at', 'desc')
  6436. ->get()
  6437. ->groupBy('category_id')
  6438. ->map(function ($group) {
  6439. // 确保第一条数据有图片
  6440. $firstWithImage = $group->first(function ($item) {
  6441. return !empty($item->imgurl);
  6442. });
  6443. if ($firstWithImage) {
  6444. // 如果有带图片的文章,将其放在第一位
  6445. $group = $group->filter(function ($item) use ($firstWithImage) {
  6446. return $item->id !== $firstWithImage->id;
  6447. })->prepend($firstWithImage);
  6448. }
  6449. return [
  6450. 'category_name' => $group->first()->category_name,
  6451. 'catid' => $group->first()->category_id,
  6452. 'pinyin' => $group->first()->pinyin,
  6453. 'parent_pinyin' => $group->first()->parent_pinyin,
  6454. 'list' => $group->take(4)->map(function ($item) {
  6455. return [
  6456. 'id' => $item->id,
  6457. 'title' => $item->title,
  6458. ];
  6459. })->values()
  6460. ];
  6461. })
  6462. ->values()
  6463. ->toArray();
  6464. return Result::success($articlesList);
  6465. }
  6466. /**
  6467. * 企业管理
  6468. * @param array $data
  6469. * @return array
  6470. */
  6471. public function getCompanyList(array $data): array
  6472. {
  6473. // return Result::success($data);
  6474. $where = [];
  6475. $user = User::where('id', $data['user_id'])->first();
  6476. if (empty($user)) {
  6477. return Result::error('用户不存在!');
  6478. }
  6479. if ($user['type_id'] != 10000) {
  6480. $where['user_id'] = $data['user_id'];
  6481. }
  6482. if (isset($data['title']) && !empty($data['title'])) {
  6483. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6484. }
  6485. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6486. array_push($where, ['website.id', $data['website_id']]);
  6487. }
  6488. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6489. if ($data['ischeck'] == 1) {
  6490. if (isset($data['status']) && $data['status'] != '') {
  6491. array_push($where, ['company.status', $data['status']]);
  6492. $query = Company::where($where);
  6493. } else {
  6494. $query = Company::whereIn('company.status', [0, 2]);
  6495. }
  6496. } else {
  6497. $query = Company::where('company.status', 1);
  6498. }
  6499. }
  6500. $result = $query->where($where)
  6501. ->leftJoin('website_category', function ($query) {
  6502. $query->on('website_category.category_id', '=', 'company.category_id')
  6503. ->on('website_category.website_id', '=', 'company.website_id');
  6504. })
  6505. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6506. ->select(
  6507. 'company.id',
  6508. 'company.title',
  6509. 'company.website_id',
  6510. 'company.category_id',
  6511. 'website.website_name',
  6512. 'website_category.alias as category_name',
  6513. 'company.status',
  6514. 'company.updated_at',
  6515. 'company.user_id'
  6516. )
  6517. ->orderBy('company.updated_at', 'desc')
  6518. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6519. if ($result->isEmpty()) {
  6520. return Result::error("暂无企业", 0);
  6521. }
  6522. return Result::success($result);
  6523. }
  6524. /**
  6525. * 添加企业
  6526. * @param array $data
  6527. * @return array
  6528. */
  6529. public function addCompany(array $data): array
  6530. {
  6531. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6532. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6533. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6534. $data['cat_arr_id'] = json_encode($car_arr_id);
  6535. } else {
  6536. $data['cat_arr_id'] = '';
  6537. }
  6538. if ($data['imgurl'] == '') {
  6539. //content中提取图片第一个图,正则提取
  6540. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6541. preg_match_all($reg, $data['content'], $matches);
  6542. if (isset($matches[1][0])) {
  6543. //截取varchar240
  6544. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6545. }
  6546. }
  6547. if ($data['keyword'] == '') {
  6548. //提取标题+内容中的关键词
  6549. $data['keyword'] = $data['title'];
  6550. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6551. Jieba::init(); // 初始化 jieba-php
  6552. Finalseg::init();
  6553. $segList = Jieba::cut($data['keyword']);
  6554. $segList1 = array_slice($segList, 0, 8);
  6555. $data['keyword'] = implode(',', $segList1);
  6556. }
  6557. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6558. //提取内容中的描述
  6559. $content = $data['content'];
  6560. // 去除 <style> 和 <script> 标签及其内容
  6561. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6562. // 去除所有 HTML 标签
  6563. $content = strip_tags($content);
  6564. // 去除 HTML 实体
  6565. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6566. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6567. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6568. // 去除多余空白
  6569. $content = preg_replace('/\s+/u', '', $content);
  6570. // 截取 100 个字符
  6571. $data['introduce'] = mb_substr($content, 0, 100);
  6572. }
  6573. $user = User::where('id', $data['user_id'])->first();
  6574. if (empty($user)) {
  6575. return Result::error('用户不存在!');
  6576. }
  6577. if ($user['type_id'] == 10000) {
  6578. $data['status'] = 1;
  6579. }
  6580. if (isset($data['level']) && $data['level'] != null) {
  6581. $data['level'] = intval($data['level']);
  6582. } else {
  6583. $data['level'] = null;
  6584. }
  6585. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6586. $this->sendMessage([
  6587. 'talk_type' => 900,
  6588. 'title' => $data['title'],
  6589. 'content' => '提交了审核',
  6590. 'messageType' => 8,
  6591. ]);
  6592. }
  6593. $result = Company::insertGetId($data);
  6594. if ($result) {
  6595. return Result::success($result);
  6596. } else {
  6597. return Result::error('添加失败');
  6598. }
  6599. }
  6600. /**
  6601. * 更新企业
  6602. * @param array $data
  6603. * @return array
  6604. */
  6605. public function upCompany(array $data): array
  6606. {
  6607. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6608. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6609. $data['cat_arr_id'] = json_encode($car_arr_id);
  6610. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6611. } else {
  6612. $data['cat_arr_id'] = '';
  6613. }
  6614. if ($data['imgurl'] == '') {
  6615. //content中提取图片第一个图,正则提取
  6616. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6617. preg_match_all($reg, $data['content'], $matches);
  6618. if (isset($matches[1][0])) {
  6619. //截取varchar
  6620. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6621. }
  6622. }
  6623. if ($data['keyword'] == '') {
  6624. //提取标题+内容中的关键词
  6625. $data['keyword'] = $data['title'];
  6626. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6627. Jieba::init(); // 初始化 jieba-php
  6628. Finalseg::init();
  6629. $segList = Jieba::cut($data['keyword']);
  6630. $segList1 = array_slice($segList, 0, 8);
  6631. $data['keyword'] = implode(',', $segList1);
  6632. }
  6633. if ($data['introduce'] == '') {
  6634. //提取内容中的描述
  6635. $content = $data['content'];
  6636. // 去除 <style> 和 <script> 标签及其内容
  6637. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6638. // 去除所有 HTML 标签
  6639. $content = strip_tags($content);
  6640. // 去除 HTML 实体
  6641. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6642. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6643. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6644. // 去除多余空白
  6645. $content = preg_replace('/\s+/u', '', $content);
  6646. // 截取 100 个字符
  6647. $data['introduce'] = mb_substr($content, 0, 100);
  6648. }
  6649. if (isset($data['level']) && $data['level'] != null) {
  6650. $data['level'] = intval($data['level']);
  6651. } else {
  6652. $data['level'] = null;
  6653. }
  6654. $user = User::where('id', $data['user_id'])->first();
  6655. if (empty($user)) {
  6656. return Result::error('用户不存在!');
  6657. }
  6658. if ($user['type_id'] == 10000) {
  6659. $data['status'] = 1;
  6660. } else {
  6661. $data['status'] = 0;
  6662. }
  6663. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6664. $this->sendMessage([
  6665. 'talk_type' => 900,
  6666. 'title' => $data['title'],
  6667. 'content' => '提交了审核',
  6668. 'messageType' => 8,
  6669. ]);
  6670. }
  6671. $result = Company::where('id', $data['id'])->update($data);
  6672. if ($result) {
  6673. return Result::success($result);
  6674. } else {
  6675. return Result::error('修改失败');
  6676. }
  6677. }
  6678. /**
  6679. * 删除企业
  6680. * @param array $data
  6681. * @return array
  6682. */
  6683. public function delCompany(array $data): array
  6684. {
  6685. $result = Company::where('id', $data['id'])->delete();
  6686. if ($result) {
  6687. return Result::success($result);
  6688. } else {
  6689. return Result::error('删除失败');
  6690. }
  6691. }
  6692. /**
  6693. * 审核企业
  6694. * @param array $data
  6695. * @return array
  6696. */
  6697. public function checkCompany(array $data): array
  6698. {
  6699. $user = User::where('id', $data['user_id'])->first();
  6700. if (empty($user)) {
  6701. return Result::error('用户不存在!');
  6702. }
  6703. $company = Company::where('id', $data['id'])->first();
  6704. if (empty($company)) {
  6705. return Result::error('企业不存在!');
  6706. }
  6707. // 状态:0:未审核 1:已审核 2:已拒绝
  6708. if ($data['status'] == 2 || $data['status'] == '2') {
  6709. $this->sendMessage([
  6710. 'talk_type' => 901,
  6711. 'title' => $company['title'],
  6712. 'content' => '审核拒绝',
  6713. 'messageType' => 8,
  6714. 'user_id' => $company['user_id'],
  6715. ]);
  6716. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6717. } else {
  6718. if ($data['status'] == 1) {
  6719. $this->sendMessage([
  6720. 'talk_type' => 901,
  6721. 'title' => $company['title'],
  6722. 'content' => '审核通过',
  6723. 'messageType' => 8,
  6724. 'user_id' => $company['user_id'],
  6725. ]);
  6726. } else if ($data['status'] == 0) {
  6727. $this->sendMessage([
  6728. 'talk_type' => 900,
  6729. 'title' => $company['title'],
  6730. 'content' => '提交了审核',
  6731. 'messageType' => 8,
  6732. ]);
  6733. }
  6734. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6735. }
  6736. if (empty($result)) {
  6737. return Result::error('审核失败!');
  6738. } else {
  6739. return Result::success($result);
  6740. }
  6741. }
  6742. /**
  6743. * 获取企业信息
  6744. * @param array $data
  6745. * @return array
  6746. */
  6747. public function getCompanyInfo(array $data): array
  6748. {
  6749. $result = Company::where('id', $data['id'])->first();
  6750. $city_arr = json_decode($result['city_arr_id']);
  6751. $result['city_name'] = District::whereIn('id', $city_arr)
  6752. ->pluck('name')
  6753. ->implode('-');
  6754. if (empty($result)) {
  6755. return Result::error('企业不存在!');
  6756. } else {
  6757. return Result::success($result);
  6758. }
  6759. }
  6760. /**
  6761. * @param array $data
  6762. * @return array
  6763. */
  6764. public function getWebsiteCompany(array $data): array
  6765. {
  6766. $categorys = json_decode($data['id'], true);
  6767. $category_arr = $this->processArticlePro($data['website_id']);
  6768. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6769. $catiall = $category_arr['catiall'];
  6770. $categoryIds = $category_arr['categoryIds'];
  6771. // return Result::success($category_arr);
  6772. foreach ($categorys as $key => $value) {
  6773. if (array_key_exists('level', $value)) {
  6774. $parts = explode(',', $value['level']);
  6775. $level = $parts[0] ?? null;
  6776. $imgnum = $parts[1] ?? null;
  6777. $textnum = $parts[2] ?? null;
  6778. if (!empty($textnum) && $textnum > 0) {
  6779. $text_num = Company::where('level', $level)
  6780. ->whereIn('category_id', $categoryIds)
  6781. ->where('status', 1)
  6782. ->select(
  6783. 'company.id',
  6784. 'company.title',
  6785. 'company.description',
  6786. 'company.updated_at',
  6787. 'company.category_id',
  6788. 'company.cat_arr_id'
  6789. )
  6790. ->orderBy('updated_at', 'desc')
  6791. ->limit($textnum)
  6792. ->get()->all();
  6793. }
  6794. if (!empty($imgnum) && $imgnum > 0) {
  6795. $img_num = Company::where('level', $level)
  6796. ->whereIn('category_id', $categoryIds)
  6797. ->where('status', 1)
  6798. ->where('imgurl', '!=', '')
  6799. ->whereNotNull('imgurl')
  6800. ->select(
  6801. 'company.id',
  6802. 'company.title',
  6803. 'company.description',
  6804. 'company.updated_at',
  6805. 'company.imgurl as imgs',
  6806. 'company.category_id',
  6807. 'company.cat_arr_id'
  6808. )
  6809. ->orderBy('updated_at', 'desc')
  6810. ->limit($imgnum)
  6811. ->get()->all();
  6812. }
  6813. }
  6814. if (array_key_exists('id', $value)) {
  6815. $parts = explode(',', $value['id']);
  6816. $category_id = $parts[0] ?? null;
  6817. $imgnum = $parts[1] ?? null;
  6818. $textnum = $parts[2] ?? null;
  6819. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6820. if (!empty($textnum) && $textnum > 0) {
  6821. $text_num = Company::whereIn('category_id', $category_arr)
  6822. // ->where('website_id', $data['website_id'])
  6823. ->where('status', 1)
  6824. ->select(
  6825. 'company.id',
  6826. 'company.title',
  6827. 'company.description',
  6828. 'company.updated_at',
  6829. 'company.category_id',
  6830. 'company.cat_arr_id'
  6831. )
  6832. ->orderBy('updated_at', 'desc')
  6833. ->limit($textnum)
  6834. ->get()->all();
  6835. }
  6836. if (!empty($imgnum) && $imgnum > 0) {
  6837. $img_num = Company::whereIn('category_id', $category_arr)
  6838. // ->where('website_id', $data['website_id'])
  6839. ->where('status', 1)
  6840. ->where('imgurl', '!=', '')
  6841. ->whereNotNull('imgurl')
  6842. ->select(
  6843. 'company.id',
  6844. 'company.title',
  6845. 'company.description',
  6846. 'company.updated_at',
  6847. 'company.imgurl as imgs',
  6848. 'company.category_id',
  6849. 'company.cat_arr_id'
  6850. )
  6851. ->orderBy('updated_at', 'desc')
  6852. ->limit($imgnum)
  6853. ->get()->all();
  6854. }
  6855. }
  6856. if (!empty($text_num)) {
  6857. foreach ($text_num as $k => $v) {
  6858. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6859. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6860. }
  6861. }
  6862. if (!empty($img_num)) {
  6863. foreach ($img_num as $k => $v) {
  6864. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6865. $imgurl = json_decode($v['imgs'], true);
  6866. if (!empty($imgurl)) {
  6867. $img_num[$k]->imgurl = $imgurl[0];
  6868. }
  6869. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6870. }
  6871. }
  6872. $company[$key]['img_num'] = $img_num ?? [];
  6873. $company[$key]['text_num'] = $text_num ?? [];
  6874. }
  6875. if (empty($company)) {
  6876. return Result::error("暂无相关企业信息", 0);
  6877. }
  6878. return Result::success($company);
  6879. }
  6880. /**
  6881. * @param array $data
  6882. * @return array
  6883. */
  6884. public function getWebsiteCompanyList(array $data): array
  6885. {
  6886. $where['website_id'] = $data['website_id'];
  6887. $where['status'] = 1;
  6888. $categoryIds = [];
  6889. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6890. $category_id = $data['category_id'];
  6891. }
  6892. $category_arr = $this->processArticlePro($data['website_id']);
  6893. $categoryIds = $category_arr['categoryIds'];
  6894. // return Result::success($cat_1st_arr);
  6895. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  6896. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  6897. })
  6898. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  6899. $query->whereIn('category_id', $categoryIds);
  6900. })
  6901. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  6902. $query->where('category_id', $category_id);
  6903. })
  6904. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6905. ->orderBy('updated_at', 'desc')
  6906. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6907. if (empty($company)) {
  6908. return Result::error("暂无相关公司信息", 0);
  6909. }
  6910. $result = [
  6911. 'count' => $company->total(),
  6912. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  6913. ];
  6914. return Result::success($result);
  6915. }
  6916. /**
  6917. * 获取项目列表
  6918. * @param array $data
  6919. * @return array
  6920. */
  6921. public function getProjectList(array $data): array
  6922. {
  6923. $where = [];
  6924. $user = User::where('id', $data['user_id'])->first();
  6925. if (empty($user)) {
  6926. return Result::error('用户不存在!');
  6927. }
  6928. if ($user->type_id != 10000) {
  6929. array_push($where, ['project.user_id', $data['user_id']]);
  6930. }
  6931. $query = Project::query();
  6932. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6933. array_push($where, ['project.website_id', $data['website_id']]);
  6934. }
  6935. if (isset($data['title']) && !empty($data['title'])) {
  6936. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6937. }
  6938. if ($data['status'] != 3) {
  6939. array_push($where, ['project.status', $data['status']]);
  6940. }
  6941. $query = Project::where($where)
  6942. ->when($data['status'] == 3, function ($query) {
  6943. $query->whereIn('project.status', [0, 2]);
  6944. });
  6945. $count = $query->clone()
  6946. ->count();
  6947. $rows = $query->clone()
  6948. ->leftJoin('website', 'project.website_id', 'website.id')
  6949. ->leftJoin('website_category', function ($join) {
  6950. $join->on('project.website_id', '=', 'website_category.website_id')
  6951. ->on('project.category_id', '=', 'website_category.category_id');
  6952. })
  6953. ->select(
  6954. 'project.id',
  6955. 'project.title',
  6956. 'project.updated_at',
  6957. 'project.status',
  6958. 'website.website_name',
  6959. 'website_category.alias as category_name',
  6960. 'project.website_id',
  6961. 'project.user_id'
  6962. )
  6963. ->orderBy('project.updated_at', 'desc')
  6964. ->offset(($data['page'] - 1) * $data['pageSize'])
  6965. ->limit($data['pageSize'])
  6966. ->get();
  6967. if ($rows->isEmpty()) {
  6968. return Result::error("暂无相关项目信息", 0);
  6969. }
  6970. $result = [
  6971. 'count' => $count,
  6972. 'rows' => $rows,
  6973. ];
  6974. return Result::success($result);
  6975. }
  6976. /**
  6977. * 添加项目
  6978. * @param array $data
  6979. * @return array
  6980. */
  6981. public function addProject(array $data): array
  6982. {
  6983. $user = User::where('id', $data['user_id'])->first();
  6984. if (empty($user)) {
  6985. return Result::error("暂无相关用户信息", 0);
  6986. }
  6987. if ($user->type_id == 10000) {
  6988. $data['status'] = 1;
  6989. } else {
  6990. $data['status'] = 0;
  6991. }
  6992. if ($data['keyword'] == '') {
  6993. //提取标题+内容中的关键词
  6994. $data['keyword'] = $data['title'];
  6995. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6996. Jieba::init(); // 初始化 jieba-php
  6997. Finalseg::init();
  6998. $segList = Jieba::cut($data['keyword']);
  6999. $segList1 = array_slice($segList, 0, 8);
  7000. $data['keyword'] = implode(',', $segList1);
  7001. }
  7002. if ($data['description'] == '') {
  7003. //提取内容中的描述
  7004. // var_dump(11111);
  7005. //提取内容中的描述
  7006. $content = $data['introduce'];
  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['description'] = mb_substr($content, 0, 100);
  7019. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7020. }
  7021. if ($data['status'] == 0) {
  7022. $this->sendMessage([
  7023. 'talk_type' => 1000,
  7024. 'title' => $data['title'],
  7025. 'content' => '提交了审核',
  7026. 'messageType' => 9,
  7027. ]);
  7028. }
  7029. $project = Project::insertGetId($data);
  7030. if (empty($project)) {
  7031. return Result::error("暂无相关项目信息", 0);
  7032. }
  7033. return Result::success($project);
  7034. }
  7035. /**
  7036. * 更新项目
  7037. * @param array $data
  7038. * @return array
  7039. */
  7040. public function upProject(array $data): array
  7041. {
  7042. $project = Project::where('id', $data['id'])->first();
  7043. if (empty($project)) {
  7044. return Result::error("暂无相关项目信息", 0);
  7045. }
  7046. $id = $data['id'];
  7047. unset($data['id']);
  7048. $user = User::where('id', $data['user_id'])->first();
  7049. if (empty($user)) {
  7050. return Result::error("暂无相关用户信息", 0);
  7051. }
  7052. if ($user->type_id == 10000) {
  7053. $data['status'] = 1;
  7054. } else {
  7055. $data['status'] = 0;
  7056. }
  7057. unset($data['user_id']);
  7058. if ($data['keyword'] == '') {
  7059. //提取标题+内容中的关键词
  7060. $data['keyword'] = $data['title'];
  7061. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7062. Jieba::init(); // 初始化 jieba-php
  7063. Finalseg::init();
  7064. $segList = Jieba::cut($data['keyword']);
  7065. $segList1 = array_slice($segList, 0, 8);
  7066. $data['keyword'] = implode(',', $segList1);
  7067. }
  7068. if ($data['description'] == '') {
  7069. //提取内容中的描述
  7070. // var_dump(11111);
  7071. //提取内容中的描述
  7072. $content = $data['introduce'];
  7073. // 去除 <style> 和 <script> 标签及其内容
  7074. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7075. // 去除所有 HTML 标签
  7076. $content = strip_tags($content);
  7077. // 去除 HTML 实体
  7078. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7079. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7080. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7081. // 去除多余空白
  7082. $content = preg_replace('/\s+/u', '', $content);
  7083. // 截取 100 个字符
  7084. $data['description'] = mb_substr($content, 0, 100);
  7085. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7086. }
  7087. if ($data['status'] == 0) {
  7088. $this->sendMessage([
  7089. 'talk_type' => 1000,
  7090. 'title' => $data['title'],
  7091. 'content' => '提交了审核',
  7092. 'messageType' => 9,
  7093. ]);
  7094. }
  7095. $result = Project::where('id', $id)->update($data);
  7096. if (empty($result)) {
  7097. return Result::error("更新失败", 0);
  7098. }
  7099. return Result::success($result);
  7100. }
  7101. /**
  7102. * 删除项目
  7103. * @param array $data
  7104. * @return array
  7105. */
  7106. public function delProject(array $data): array
  7107. {
  7108. $user = User::where('id', $data['user_id'])->first();
  7109. if (empty($user)) {
  7110. return Result::error("暂无相关用户信息", 0);
  7111. }
  7112. $project = Project::where('id', $data['id'])->first();
  7113. if (empty($project)) {
  7114. return Result::error("暂无相关项目信息", 0);
  7115. }
  7116. $result = Project::where('id', $data['id'])->delete();
  7117. if (empty($result)) {
  7118. return Result::error("删除失败", 0);
  7119. }
  7120. return Result::success($result);
  7121. }
  7122. /**
  7123. * 审核项目
  7124. * @param array $data
  7125. * @return array
  7126. */
  7127. public function checkProject(array $data): array
  7128. {
  7129. $user = User::where('id', $data['user_id'])->first();
  7130. if (empty($user)) {
  7131. return Result::error("暂无相关用户信息", 0);
  7132. }
  7133. // 0:未审核; 1:已审核; 2:已拒绝;
  7134. if ($user->type_id != 10000) {
  7135. if ($data['status'] == 1 || $data['status'] == 2) {
  7136. return Result::error("此用户权限不足", 0);
  7137. }
  7138. }
  7139. $project = Project::where('id', $data['id'])->first();
  7140. if (empty($project)) {
  7141. return Result::error("暂无相关项目信息", 0);
  7142. }
  7143. if ($data['status'] == 2) {
  7144. $this->sendMessage([
  7145. 'talk_type' => 1001,
  7146. 'title' => $project['title'],
  7147. 'content' => '审核拒绝',
  7148. 'messageType' => 9,
  7149. 'user_id' => $project['user_id'],
  7150. ]);
  7151. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7152. } else {
  7153. if ($data['status'] == 1) {
  7154. $this->sendMessage([
  7155. 'talk_type' => 1001,
  7156. 'title' => $project['title'],
  7157. 'content' => '审核通过',
  7158. 'messageType' => 9,
  7159. 'user_id' => $project['user_id'],
  7160. ]);
  7161. } else if ($data['status'] == 0) {
  7162. $this->sendMessage([
  7163. 'talk_type' => 1000,
  7164. 'title' => $project['title'],
  7165. 'content' => '提交了审核',
  7166. 'messageType' => 9,
  7167. ]);
  7168. }
  7169. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7170. }
  7171. if (empty($result)) {
  7172. return Result::error("审核失败", 0);
  7173. }
  7174. return Result::success($result);
  7175. }
  7176. /**
  7177. * 获取项目详情
  7178. * @param array $data
  7179. * @return array
  7180. */
  7181. public function getProjectInfo(array $data): array
  7182. {
  7183. $project = Project::where('id', $data['id'])->first();
  7184. if (empty($project)) {
  7185. return Result::error("暂无相关项目信息", 0);
  7186. }
  7187. return Result::success($project);
  7188. }
  7189. public function getWebsiteCompanyInfo(array $data): array
  7190. {
  7191. $company = Company::where('id', $data['id'])
  7192. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7193. ->where('status', 1)
  7194. // ->where('website_id', $data['website_id'])
  7195. ->select('company.*', 'job_industry.hyname as hy_name')
  7196. ->first();
  7197. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7198. switch ($company->jobnature_id) {
  7199. case null:
  7200. $company->jobnature_name = '';
  7201. break;
  7202. case 0:
  7203. $company->jobnature_name = '市场监督';
  7204. break;
  7205. case 1:
  7206. $company->jobnature_name = '信访纪检';
  7207. break;
  7208. case 2:
  7209. $company->jobnature_name = '公检法司';
  7210. break;
  7211. case 3:
  7212. $company->jobnature_name = '高关注机构';
  7213. break;
  7214. default:
  7215. $company->jobnature_name = '';
  7216. break;
  7217. }
  7218. $city_arr = $company->city_arr_id;
  7219. if (!empty($city_arr)) {
  7220. $city_arr = json_decode($city_arr, true);
  7221. $cityNames = District::whereIn('id', $city_arr)
  7222. ->pluck('name')
  7223. ->implode('-');
  7224. $company->city_name = $cityNames;
  7225. } else {
  7226. $company->city_name = '';
  7227. }
  7228. if (empty($company)) {
  7229. return Result::error("暂无相关公司信息", 0);
  7230. }
  7231. return Result::success($company);
  7232. }
  7233. public function getMSG(array $data): array
  7234. {
  7235. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7236. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7237. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7238. $result = [];
  7239. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7240. //最近的5篇已审的文章
  7241. $apply_articale = Article::where('status', 1)
  7242. ->where('admin_user_id', $user_id)
  7243. ->orderBy('updated_at', 'desc')
  7244. // ->limit(5)
  7245. ->get();
  7246. //获取5条用户的已审核商品
  7247. $good = Good::where('status', 2)
  7248. ->where('user_id', $user_id)
  7249. ->orderBy('updated_at', 'desc')
  7250. // ->limit(5)
  7251. ->get();
  7252. //获取5条用户待审核的公告
  7253. $notice = Notice::where('status', 2)
  7254. ->where('user_id', $user_id)
  7255. ->orderBy('updated_at', 'desc')
  7256. ->limit(5)->get();
  7257. //获取5条用户的待审核投诉
  7258. $complaint = Complaint::where('status', 2)
  7259. ->where('user_id', $user_id)
  7260. ->orderBy('updated_at', 'desc')
  7261. // ->limit(5)
  7262. ->get();
  7263. //获取5条用户的book
  7264. $book = Book::where('status', 2)
  7265. ->where('user_id', $user_id)
  7266. ->orderBy('updated_at', 'desc')
  7267. // ->limit(5)
  7268. ->get();
  7269. //获取5条用户的求职
  7270. //获取5条用户的求职 1
  7271. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7272. ->where('job_hunting.user_id', $user_id)
  7273. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7274. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7275. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7276. ->orderBy('updated_at', 'desc')
  7277. // ->limit(5)
  7278. ->get();
  7279. //获取5条用户的求职 2
  7280. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7281. ->where('job_recruiting.user_id', $user_id)
  7282. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7283. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7284. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7285. ->orderBy('updated_at', 'desc')
  7286. // ->limit(5)
  7287. ->get();
  7288. //人才库 1
  7289. $job_apply = JobApply::where('job_apply.status', 1)
  7290. ->where('job_apply.receiver_id', $user_id)
  7291. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7292. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7293. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7294. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7295. ->select('job_recruiting', 'job_recruiting.', '', '')
  7296. ->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')
  7297. ->orderBy('updated_at', 'desc')
  7298. // ->limit(5)
  7299. ->get();
  7300. // 职场机会 2
  7301. $job_resume = JobResume::where('job_resume.status', 1)
  7302. ->where('job_resume.receiver_id', $user_id)
  7303. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7304. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7305. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7306. ->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')
  7307. ->orderBy('updated_at', 'desc')
  7308. // ->limit(5)
  7309. ->get();
  7310. //获取5条用户待处理的投诉
  7311. $complaint_deal = Complaint::where('status', 2)
  7312. ->where('deal', 1)
  7313. ->whereJsonContains('re_user_ids', $user_id)
  7314. ->orderBy('updated_at', 'desc')
  7315. // ->limit(5)
  7316. ->get();
  7317. //获取 被通知者未读信息
  7318. $notice_unread = Notice::where('status', 2)
  7319. ->whereJsonContains('re_user_ids', $user_id)
  7320. //未读消息
  7321. ->where(function ($query) use ($user_id) {
  7322. $query->whereJsonDoesntContain('read_id', $user_id)
  7323. ->orWhereNull('read_id');
  7324. })
  7325. ->orderBy('updated_at', 'desc')
  7326. ->get();
  7327. $complaint_unread = Complaint::where('status', 2)
  7328. ->whereJsonContains('re_user_ids', $user_id)
  7329. //未读消息
  7330. ->where(function ($query) use ($user_id) {
  7331. $query->whereJsonDoesntContain('read_id', $user_id)
  7332. ->orWhereNull('read_id');
  7333. })
  7334. ->orderBy('updated_at', 'desc')
  7335. ->get();
  7336. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7337. $complany = Company::where('status', 1)
  7338. ->where('user_id', $user_id)
  7339. ->orderBy('updated_at', 'desc')
  7340. // ->limit(5)
  7341. ->get();
  7342. //获取5条单聊未读聊天消息
  7343. // $chat = ChatRecords::where('is_read', 0)
  7344. // ->where('user_id', $user_id)
  7345. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7346. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7347. // ->where('action', 'recieved')
  7348. // ->where('talk_type', 1)
  7349. // ->orderBy('created_at', 'desc')
  7350. // // ->limit(5)
  7351. // ->get();
  7352. //获取5条未读群聊信息
  7353. // $chat_group = ChatRecords::where('is_read', 0)
  7354. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7355. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7356. // ->where('user_id', $user_id)
  7357. // ->where('talk_type', 2)
  7358. // ->orderBy('created_at', 'desc')
  7359. // // ->limit(5)
  7360. // ->get();
  7361. //获取5条用户的待审核项目
  7362. $project = Project::where('status', 1)
  7363. ->where('user_id', $user_id)
  7364. ->orderBy('updated_at', 'desc')
  7365. // ->limit(5)
  7366. ->get();
  7367. // count($chat) + count($chat_group) +
  7368. $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)
  7369. + count($complany)
  7370. + count($project)
  7371. + count($notice_unread)
  7372. + count($complaint_unread)
  7373. // + count($chat) + count($chat_group)
  7374. ;
  7375. $result = [
  7376. 'apply_articale' => $apply_articale,
  7377. // 'chat' => $chat,
  7378. // 'chat_group' => $chat_group,
  7379. 'good' => $good,
  7380. 'notice' => $notice,
  7381. 'complaint' => $complaint,
  7382. 'book' => $book,
  7383. 'job_hunting' => $job_hunting,
  7384. 'job_recruiting' => $job_recruiting,
  7385. 'job_apply' => $job_apply,
  7386. 'job_resume' => $job_resume,
  7387. 'complaint_deal' => $complaint_deal,
  7388. 'complany' => $complany,
  7389. 'project' => $project,
  7390. 'notice_unread' => $notice_unread,
  7391. 'complaint_unread' => $complaint_unread,
  7392. 'count' => $count,
  7393. ];
  7394. } elseif ($type_id == 12) {
  7395. //最近的5篇已审的文章
  7396. $apply_articale = Article::where('status', 1)
  7397. ->where('admin_user_id', $user_id)
  7398. ->limit(5)->get();
  7399. //获取5条单聊未读聊天消息
  7400. $chat = ChatRecords::where('is_read', 0)
  7401. ->where('user_id', $user_id)
  7402. ->where('talk_type', 1)
  7403. ->orderBy('created_at', 'desc')
  7404. ->limit(5)->get();
  7405. //获取5条未读群聊信息
  7406. $chat_group = ChatRecords::where('is_read', 0)
  7407. ->where('user_id', $user_id)
  7408. ->where('talk_type', 2)
  7409. ->orderBy('created_at', 'desc')
  7410. ->limit(5)->get();
  7411. //获取5条用户的已审核商品
  7412. $good = Good::where('status', 2)
  7413. ->where('user_id', $user_id)
  7414. ->orderBy('updated_at', 'desc')
  7415. ->limit(5)->get();
  7416. //获取5条用户的book
  7417. $book = Book::where('status', 2)
  7418. ->where('user_id', $user_id)
  7419. ->orderBy('updated_at', 'desc')
  7420. ->limit(5)->get();
  7421. //获取5条用户的求职
  7422. //获取5条用户的求职 1
  7423. //count($chat) + count($chat_group)
  7424. $count = count($apply_articale) + count($good);
  7425. $result = [
  7426. 'apply_articale' => $apply_articale,
  7427. 'chat' => $chat,
  7428. 'chat_group' => $chat_group,
  7429. 'good' => $good,
  7430. 'book' => $book,
  7431. 'count' => $count,
  7432. ];
  7433. } elseif ($type_id == 13) {
  7434. //最近的5篇已审的文章
  7435. $apply_articale = Article::where('status', 1)
  7436. ->where('admin_user_id', $user_id)
  7437. ->limit(5)->get();
  7438. //获取5条单聊未读聊天消息
  7439. $chat = ChatRecords::where('is_read', 0)
  7440. ->where('user_id', $user_id)
  7441. ->where('talk_type', 1)
  7442. ->orderBy('created_at', 'desc')
  7443. ->limit(5)->get();
  7444. //获取5条未读群聊信息
  7445. $chat_group = ChatRecords::where('is_read', 0)
  7446. ->where('user_id', $user_id)
  7447. ->where('talk_type', 2)
  7448. ->orderBy('created_at', 'desc')
  7449. ->limit(5)->get();
  7450. //获取5条用户的已审核商品
  7451. $good = Good::where('status', 2)
  7452. ->where('user_id', $user_id)
  7453. ->orderBy('updated_at', 'desc')
  7454. ->limit(5)->get();
  7455. //count($chat) + count($chat_group) +
  7456. $count = count($apply_articale) + count($good);
  7457. $result = [
  7458. 'apply_articale' => $apply_articale,
  7459. 'chat' => $chat,
  7460. 'chat_group' => $chat_group,
  7461. 'good' => $good,
  7462. 'count' => $count,
  7463. ];
  7464. } elseif ($type_id == 14) {
  7465. //最近的5篇已审的文章
  7466. $apply_articale = Article::where('status', 1)
  7467. ->where('admin_user_id', $user_id)
  7468. // ->limit(5)
  7469. ->get();
  7470. //获取5条用户的已审核商品
  7471. $good = Good::where('status', 2)
  7472. ->where('user_id', $user_id)
  7473. ->orderBy('updated_at', 'desc')
  7474. // ->limit(5)
  7475. ->get();
  7476. $count = count($apply_articale) + count($good);
  7477. $result = [
  7478. 'apply_articale' => $apply_articale,
  7479. 'chat' => '',
  7480. 'chat_group' => '',
  7481. 'good' => $good,
  7482. 'count' => $count,
  7483. ];
  7484. } elseif ($type_id == 10000) {
  7485. //获取未审核的5篇文章
  7486. $apply_articale = Article::where('status', 0)
  7487. ->orderBy('updated_at', 'desc')
  7488. // ->limit(5)
  7489. ->get();
  7490. //获取5条单聊未读聊天消息
  7491. //获取5条单聊未读聊天消息
  7492. // $chat = ChatRecords::where('is_read', 0)
  7493. // ->where('user_id', $user_id)
  7494. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7495. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7496. // ->where('action', 'recieved')
  7497. // ->where('talk_type', 1)
  7498. // ->orderBy('created_at', 'desc')
  7499. // // ->limit(5)
  7500. // ->get();
  7501. // //获取5条未读群聊信息
  7502. // $chat_group = ChatRecords::where('is_read', 0)
  7503. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7504. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7505. // ->where('user_id', $user_id)
  7506. // ->where('talk_type', 2)
  7507. // ->orderBy('created_at', 'desc')
  7508. // // ->limit(5)
  7509. // ->get();
  7510. //获取5条用户的已审核商品
  7511. $good = Good::where('status', 1)
  7512. // ->where('user_id', $user_id)
  7513. ->orderBy('updated_at', 'desc')
  7514. // ->limit(5)
  7515. ->get();
  7516. //获取5条用户待审核的公告
  7517. $notice = Notice::where('status', 1)
  7518. ->orderBy('updated_at', 'desc')
  7519. // ->limit(5)
  7520. ->get();
  7521. //获取5条用户的待审核投诉
  7522. $complaint = Complaint::where('status', 1)
  7523. ->orderBy('updated_at', 'desc')
  7524. // ->limit(5)
  7525. ->get();
  7526. //获取5条用户的book
  7527. $book = Book::where('status', 1)
  7528. ->orderBy('updated_at', 'desc')
  7529. // ->limit(5)
  7530. ->get();
  7531. //获取5条用户的求职 1
  7532. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7533. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7534. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7535. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7536. ->orderBy('updated_at', 'desc')
  7537. // ->limit(5)
  7538. ->get();
  7539. //获取5条用户的求职 2
  7540. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7541. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7542. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7543. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7544. ->orderBy('updated_at', 'desc')
  7545. // ->limit(5)
  7546. ->get();
  7547. //人才库 1
  7548. $job_apply = JobApply::where('job_apply.status', 1)
  7549. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7550. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7551. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7552. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7553. ->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')
  7554. ->orderBy('updated_at', 'desc')
  7555. // ->limit(5)
  7556. ->get();
  7557. // 职场机会 2
  7558. $job_resume = JobResume::where('job_resume.status', 1)
  7559. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7560. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7561. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7562. ->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')
  7563. ->orderBy('updated_at', 'desc')
  7564. // ->limit(5)
  7565. ->get();
  7566. //待审核数据com pro
  7567. $complany = Company::where('status', 0)
  7568. ->orderBy('updated_at', 'desc')
  7569. // ->limit(5)
  7570. ->get();
  7571. $project = Project::where('status', 0)
  7572. ->orderBy('updated_at', 'desc')
  7573. // ->limit(5)
  7574. ->get();
  7575. $count =
  7576. // count($chat) +
  7577. // count($chat_group) +
  7578. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7579. // + count($job_apply)
  7580. // + count($job_resume)
  7581. + count($complany)
  7582. + count($project);
  7583. $result = [
  7584. 'apply_articale' => $apply_articale,
  7585. // 'chat' => $chat,
  7586. // 'chat_group' => $chat_group,
  7587. 'good' => $good,
  7588. 'notice' => $notice,
  7589. 'complaint' => $complaint,
  7590. 'book' => $book,
  7591. 'job_hunting' => $job_hunting,
  7592. 'job_recruiting' => $job_recruiting,
  7593. // 'job_apply' => $job_apply,
  7594. // 'job_resume' => $job_resume,
  7595. 'complany' => $complany,
  7596. 'project' => $project,
  7597. 'count' => $count,
  7598. ];
  7599. } elseif ($type_id == 20000) {
  7600. }
  7601. var_dump($type_id, '-----------------test---------');
  7602. return Result::success($result);
  7603. }
  7604. /**
  7605. * @param array $data
  7606. * @return array
  7607. */
  7608. public function getWebsiteProject(array $data): array
  7609. {
  7610. $categorys = json_decode($data['id'], true);
  7611. if (!empty($categorys)) {
  7612. $category_arr = $this->processArticlePro($data['website_id']);
  7613. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7614. $catiall = $category_arr['catiall'];
  7615. // return Result::success($catiall);
  7616. foreach ($categorys as $key => $val) {
  7617. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7618. $level = explode(',', $val['level'])[0];
  7619. $imgnum = explode(',', $val['level'])[1] ?? null;
  7620. $textnum = explode(',', $val['level'])[2] ?? null;
  7621. if ($level == 1) {
  7622. if (!empty($textnum) && $textnum > 0) {
  7623. $text_num = Project::where('level', $level)
  7624. ->where('website_id', $data['website_id'])
  7625. ->where('status', 1)
  7626. ->select(
  7627. 'project.id',
  7628. 'project.title',
  7629. 'project.description',
  7630. 'project.updated_at',
  7631. 'project.category_id',
  7632. 'project.cat_arr_id'
  7633. )
  7634. ->orderBy('updated_at', 'desc')
  7635. ->limit($textnum)
  7636. ->get()->all();
  7637. }
  7638. if (!empty($imgnum) && $imgnum > 0) {
  7639. $img_num = Project::where('level', $level)
  7640. ->where('website_id', $data['website_id'])
  7641. ->where('status', 1)
  7642. ->where('imgurl', '!=', '')
  7643. ->whereNotNull('imgurl')
  7644. ->select(
  7645. 'project.id',
  7646. 'project.title',
  7647. 'project.description',
  7648. 'project.updated_at',
  7649. 'project.imgurl as imgs',
  7650. 'project.category_id',
  7651. 'project.cat_arr_id'
  7652. )
  7653. ->orderBy('updated_at', 'desc')
  7654. ->limit($imgnum)
  7655. ->get()->all();
  7656. }
  7657. } else {
  7658. if (!empty($textnum) && $textnum > 0) {
  7659. $text_num = Project::where('website_id', $data['website_id'])
  7660. ->where('status', 1)
  7661. ->select(
  7662. 'project.id',
  7663. 'project.title',
  7664. 'project.description',
  7665. 'project.updated_at',
  7666. 'project.category_id',
  7667. 'project.cat_arr_id',
  7668. 'project.website_id',
  7669. 'project.updated_at',
  7670. 'project.created_at'
  7671. )
  7672. ->orderBy('updated_at', 'desc')
  7673. ->limit($textnum)
  7674. ->get()->all();
  7675. }
  7676. if (!empty($imgnum) && $imgnum > 0) {
  7677. $img_num = Project::where('website_id', $data['website_id'])
  7678. ->where('status', 1)
  7679. ->where('imgurl', '!=', '')
  7680. ->whereNotNull('imgurl')
  7681. ->select(
  7682. 'project.id',
  7683. 'project.title',
  7684. 'project.description',
  7685. 'project.updated_at',
  7686. 'project.imgurl as imgs',
  7687. 'project.category_id',
  7688. 'project.cat_arr_id'
  7689. )
  7690. ->orderBy('updated_at', 'desc')
  7691. ->limit($imgnum)
  7692. ->get()->all();
  7693. }
  7694. }
  7695. }
  7696. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7697. $category_ids = explode(',', $val['id'])[0];
  7698. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7699. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7700. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7701. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7702. $text_num = Project::whereIn('category_id', $category_arr)
  7703. ->where('website_id', $data['website_id'])
  7704. ->where('status', 1)
  7705. ->select(
  7706. 'project.id',
  7707. 'project.title',
  7708. 'project.description',
  7709. 'project.updated_at',
  7710. 'project.category_id',
  7711. 'project.cat_arr_id'
  7712. )
  7713. ->orderBy('updated_at', 'desc')
  7714. ->limit($cat_textnum)
  7715. ->get()->all();
  7716. }
  7717. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7718. $img_num = Project::whereIn('category_id', $category_arr)
  7719. ->where('website_id', $data['website_id'])
  7720. ->where('status', 1)
  7721. ->where('imgurl', '!=', '')
  7722. ->whereNotNull('imgurl')
  7723. ->select(
  7724. 'project.id',
  7725. 'project.title',
  7726. 'project.description',
  7727. 'project.updated_at',
  7728. 'project.imgurl as imgs',
  7729. 'project.category_id',
  7730. 'project.cat_arr_id'
  7731. )
  7732. ->orderBy('updated_at', 'desc')
  7733. ->limit($cat_imgnum)
  7734. ->get()->all();
  7735. }
  7736. }
  7737. if (!empty($img_num)) {
  7738. foreach ($img_num as $k => $v) {
  7739. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7740. $imgurl = json_decode($v['imgs'], true);
  7741. if (!empty($imgurl)) {
  7742. $img_num[$k]->imgurl = $imgurl[0];
  7743. }
  7744. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7745. }
  7746. }
  7747. if (!empty($text_num)) {
  7748. foreach ($text_num as $k => $v) {
  7749. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7750. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7751. }
  7752. }
  7753. $project[$key]['img_num'] = $img_num ?? [];
  7754. $project[$key]['text_num'] = $text_num ?? [];
  7755. }
  7756. }
  7757. if (empty($project)) {
  7758. return Result::error("暂无相关项目信息", 0);
  7759. }
  7760. return Result::success($project);
  7761. }
  7762. /**
  7763. * @param array $data
  7764. * @return array
  7765. */
  7766. public function getWebsiteProjectInfo(array $data): array
  7767. {
  7768. $project = Project::where('id', $data['id'])
  7769. ->where('status', 1)
  7770. ->where('website_id', $data['website_id'])
  7771. ->select('project.*')
  7772. ->first();
  7773. if (empty($project)) {
  7774. return Result::error("暂无相关项目信息", 0);
  7775. }
  7776. return Result::success($project);
  7777. }
  7778. /**
  7779. * @param array $data
  7780. * @return array
  7781. */
  7782. public function getWebsiteProjectList(array $data): array
  7783. {
  7784. $where = [];
  7785. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7786. $where['category_id'] = $data['category_id'];
  7787. }
  7788. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7789. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7790. }
  7791. $query = Project::where($where)
  7792. ->where('status', 1)
  7793. ->where('website_id', $data['website_id'])
  7794. ->select(
  7795. 'project.id',
  7796. 'project.title',
  7797. 'project.description',
  7798. 'project.imgurl as imgs',
  7799. 'project.category_id',
  7800. 'project.cat_arr_id'
  7801. )
  7802. ->orderBy('updated_at', 'desc');
  7803. $count = $query->count();
  7804. $project = $query->clone()
  7805. ->offset(($data['page'] - 1) * $data['pageSize'])
  7806. ->limit($data['pageSize'])
  7807. ->get()->all();
  7808. if (empty($project)) {
  7809. return Result::error("暂无相关项目信息", 0);
  7810. }
  7811. $categorys = $this->processArticlePro($data['website_id']);
  7812. $catiall = $categorys['catiall'];
  7813. foreach ($project as $key => $val) {
  7814. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7815. if (!empty($val['imgs'])) {
  7816. $imgurl = json_decode($val['imgs'], true);
  7817. if (!empty($imgurl)) {
  7818. $project[$key]->imgurl = $imgurl[0];
  7819. }
  7820. } else {
  7821. $project[$key]->imgurl = '';
  7822. }
  7823. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7824. }
  7825. $result = [
  7826. 'rows' => $project,
  7827. 'count' => $count,
  7828. ];
  7829. return Result::success($result);
  7830. }
  7831. /**
  7832. * @param array $data
  7833. * @return array
  7834. */
  7835. public function getWebsiteCategoryJob(array $data): array
  7836. {
  7837. $categorys = json_decode($data['id'], true);
  7838. if (!empty($categorys)) {
  7839. $category_arr = $this->processArticlePro($data['website_id']);
  7840. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7841. $catiall = $category_arr['catiall'];
  7842. foreach ($categorys as $key => $val) {
  7843. if (isset($val['id']) && !empty($val['id'])) {
  7844. $catid = explode(',', $val['id'])[0] ?? null;
  7845. $type = explode(',', $val['id'])[1] ?? null;
  7846. $textnum = explode(',', $val['id'])[2] ?? null;
  7847. }
  7848. // 4:招聘;5:求职;
  7849. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7850. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7851. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7852. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7853. ->where('job_recruiting.status', 1)
  7854. ->where('job_recruiting.website_id', $data['website_id'])
  7855. ->select(
  7856. 'job_recruiting.id',
  7857. 'job_recruiting.title',
  7858. 'job_company.business_name',
  7859. 'job_recruiting.updated_at',
  7860. 'job_recruiting.cat_arr_id',
  7861. 'job_recruiting.keyword',
  7862. 'job_recruiting.description'
  7863. )
  7864. ->orderBy('job_recruiting.updated_at', 'desc')
  7865. ->limit($textnum)
  7866. ->get()->all();
  7867. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7868. // 状态 审核状态,1待审核2已审核3已拒绝
  7869. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7870. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7871. ->where('job_hunting.status', 2)
  7872. ->where('job_hunting.website_id', $data['website_id'])
  7873. ->select(
  7874. 'job_hunting.id',
  7875. 'job_hunting.name',
  7876. 'job_hunting.cat_arr_id',
  7877. 'job_position.zwname as job_name',
  7878. 'job_hunting.updated_at',
  7879. 'job_hunting.keyword',
  7880. 'job_hunting.slelf_evaluation'
  7881. )
  7882. ->orderBy('updated_at', 'desc')
  7883. ->limit($textnum)
  7884. ->get()->all();
  7885. } else {
  7886. $job = [];
  7887. }
  7888. // var_dump($catid.'222uuuuuuu'.$key);
  7889. if (!empty($job)) {
  7890. foreach ($job as $k => $value) {
  7891. if (isset($value->cat_arr_id)) {
  7892. $catArr = json_decode($value->cat_arr_id, true);
  7893. $catId = end($catArr);
  7894. } else {
  7895. continue;
  7896. }
  7897. if (isset($catiall[$catId])) {
  7898. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7899. }
  7900. }
  7901. }
  7902. // var_dump($catid.'xxxxx'.$key);
  7903. $result[$key] = $job ?? [];
  7904. }
  7905. }
  7906. if (empty($result)) {
  7907. return Result::error("暂无相关分类信息", 0);
  7908. }
  7909. return Result::success($result);
  7910. }
  7911. /**
  7912. * 发送消息
  7913. * @param array $messageData
  7914. * @return void
  7915. */
  7916. public function sendMessage($messageData)
  7917. {
  7918. $msg = [
  7919. 'talk_type' => $messageData['talk_type'],
  7920. 'title' => $messageData['title'],
  7921. 'content' => $messageData['content'],
  7922. 'messageType' => $messageData['messageType'],
  7923. 'user_id' => $messageData['user_id'] ?? '',
  7924. 'time' => microtime(),
  7925. ];
  7926. $message = new MqProducer($msg);
  7927. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7928. $producer->produce($message);
  7929. }
  7930. }