NewsService.php 296 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163
  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. unset($data['user_type']);
  435. unset($data['nav_add_pool_id']);
  436. // unset($data['commend_id']);
  437. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  438. Db::beginTransaction();
  439. try {
  440. //处理投票
  441. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  442. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  443. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  444. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  445. unset($data['is_survey']);
  446. unset($data['survey_name']);
  447. unset($data['suvey_array']);
  448. // unset($data['website_id']);
  449. // unset($data['web_site_id']);
  450. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  451. if ($data['hits'] == '') {
  452. $data['hits'] = 0;
  453. }
  454. if ($data['is_original'] == '') {
  455. $data['is_original'] = 0;
  456. }
  457. if ($data['status'] == '') {
  458. $data['status'] = 0;
  459. }
  460. $articleData = $data;
  461. unset($articleData['content']);
  462. //自动处理缩略图、关键字、描述
  463. if ($articleData['imgurl'] == '') {
  464. //如果没有图,设置level=0
  465. $levelArr = json_decode($articleData['level'], true);
  466. var_dump($levelArr, '----------levelArr-----------1');
  467. //content中提取图片第一个图,正则提取
  468. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  469. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  470. preg_match_all($reg, $data['content'], $matches);
  471. if (isset($matches[1][0])) {
  472. //截取varchar240
  473. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  474. //如果有图,设置level=3
  475. if (!in_array(3, $levelArr)) {
  476. $levelArr[] = 3;
  477. }
  478. $articleData['level'] = json_encode($levelArr);
  479. } else {
  480. if (!in_array(0, $levelArr)) {
  481. $levelArr[] = 0;
  482. }
  483. $articleData['level'] = json_encode($levelArr);
  484. }
  485. }
  486. var_dump($articleData['level'], '----------$articleData[level]----------1');
  487. if ($articleData['keyword'] == '') {
  488. //提取标题+内容中的关键词
  489. $articleData['keyword'] = $data['title'];
  490. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  491. Jieba::init(); // 初始化 jieba-php
  492. Finalseg::init();
  493. $segList = Jieba::cut($articleData['keyword']);
  494. $segList1 = array_slice($segList, 0, 8);
  495. $articleData['keyword'] = implode(',', $segList1);
  496. }
  497. if ($articleData['introduce'] == '') {
  498. //提取内容中的描述
  499. $content = $data['content'];
  500. // 去除 <style> 和 <script> 标签及其内容
  501. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  502. // 去除所有 HTML 标签
  503. $content = strip_tags($content);
  504. // 去除 HTML 实体
  505. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  506. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  507. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  508. // 去除多余空白
  509. $content = preg_replace('/\s+/u', '', $content);
  510. // 截取 100 个字符
  511. $articleData['introduce'] = mb_substr($content, 0, 100);
  512. }
  513. if ($articleData['status'] == 0) {
  514. $this->sendMessage([
  515. 'talk_type' => 100,
  516. 'title' => $articleData['title'],
  517. 'content' => '提交了审核',
  518. 'messageType' => 2,
  519. ]);
  520. }
  521. $id = Article::insertGetId($articleData);
  522. $articleDataContent = [
  523. 'article_id' => $id,
  524. 'content' => $data['content'],
  525. ];
  526. ArticleData::insertGetId($articleDataContent);
  527. //处理投票
  528. if ($is_survey == 1) {
  529. //生成年月日时分秒+8位随机数
  530. $uuid = date('YmdHis') . rand(10000000, 99999999);
  531. var_dump($suvey_array, 'suvey_array________');
  532. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  533. var_dump($suveys_array, '---------------------1');
  534. var_dump($suvey_array, '---------------------2');
  535. $suvey_data = [];
  536. foreach ($suveys_array as $key => $value) {
  537. if ($value == '') {
  538. continue;
  539. }
  540. if (is_array($value)) {
  541. $suvey_data[] = [
  542. 'sur_id' => $uuid,
  543. 'art_id' => $id,
  544. 'website_id' => $website_id ?? 2,
  545. 'survey_name' => $survey_name,
  546. 'choice_name' => $value[1],
  547. 'is_other' => 1,
  548. 'other_id' => 0,
  549. 'results' => 0,
  550. ];
  551. } else {
  552. $suvey_data[] = [
  553. 'sur_id' => $uuid,
  554. 'art_id' => $id,
  555. 'website_id' => $website_id ?? 2,
  556. 'survey_name' => $survey_name,
  557. 'choice_name' => $value,
  558. 'is_other' => 0,
  559. 'other_id' => 0,
  560. 'results' => 0,
  561. ];
  562. }
  563. if (empty($suvey_data)) {
  564. throw new \Exception("投票数据为空");
  565. }
  566. }
  567. $result = ArticleSurvey::insert($suvey_data);
  568. if (!$result) {
  569. throw new \Exception("投票失败,ArticleSurvey插入失败");
  570. }
  571. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  572. if (!$result) {
  573. throw new \Exception("投票失败,更新主表失败");
  574. }
  575. }
  576. Db::commit();
  577. return Result::success(['id' => $id]);
  578. } catch (\Throwable $ex) {
  579. Db::rollBack();
  580. var_dump($ex->getMessage());
  581. return Result::error("创建失败", 0);
  582. }
  583. }
  584. /**
  585. * @param array $data
  586. * @return array
  587. */
  588. public function delArticle(array $data): array
  589. {
  590. $result = Article::where($data)->delete();
  591. //survey投票删除
  592. articleSurvey::where(['art_id' => $data['id']])->delete();
  593. if (!$result) {
  594. return Result::error("删除失败");
  595. }
  596. return Result::success($result);
  597. }
  598. /**
  599. * @param array $data
  600. * @return array
  601. */
  602. public function updateArticle(array $data): array
  603. {
  604. var_dump($data, '----------12-----------1');
  605. Db::beginTransaction();
  606. unset($data['user_type']);
  607. // unset($data['web_site_id']);
  608. unset($data['nav_add_pool_id']);
  609. try {
  610. //处理投票
  611. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  612. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  613. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  614. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  615. unset($data['is_survey']);
  616. unset($data['survey_name']);
  617. unset($data['suvey_array']);
  618. unset($data['website_id']);
  619. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  620. if ($data['hits'] == '') {
  621. $data['hits'] = 0;
  622. }
  623. if ($data['is_original'] == '') {
  624. $data['is_original'] = 0;
  625. }
  626. if ($data['status'] == '') {
  627. $data['status'] = 0;
  628. }
  629. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  630. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  631. $articleData = $data;
  632. unset($articleData['content']);
  633. unset($articleData['status_name']);
  634. unset($articleData['name']);
  635. unset($articleData['content']);
  636. unset($articleData['pid_arr']);
  637. unset($articleData['pid']);
  638. //自动处理缩略图、关键字、描述
  639. if ($articleData['imgurl'] == '') {
  640. //如果没有图,设置level=0
  641. $levelArr = json_decode($articleData['level'], true);
  642. var_dump($levelArr, '----------levelArr-----------1');
  643. //content中提取图片第一个图,正则提取
  644. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  645. preg_match_all($reg, $data['content'], $matches);
  646. if (isset($matches[1][0])) {
  647. //截取varchar240
  648. // 截取到第一个<
  649. $articleData['imgurl'] = $matches[1][0];
  650. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  651. $pos = strpos($articleData['imgurl'], '"');
  652. if ($pos !== false) {
  653. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  654. }
  655. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  656. //如果有图,设置level=3
  657. if (!in_array(3, $levelArr)) {
  658. $levelArr[] = 3;
  659. }
  660. $articleData['level'] = json_encode($levelArr);
  661. } else {
  662. if (!in_array(0, $levelArr)) {
  663. $levelArr[] = 0;
  664. }
  665. $articleData['level'] = json_encode($levelArr);
  666. }
  667. }
  668. var_dump($articleData['level'], '----------$articleData[level]----------1');
  669. if ($articleData['keyword'] == '') {
  670. //提取标题+内容中的关键词
  671. $articleData['keyword'] = $data['title'];
  672. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  673. Jieba::init(); // 初始化 jieba-php
  674. Finalseg::init();
  675. $segList = Jieba::cut($articleData['keyword']);
  676. $segList1 = array_slice($segList, 0, 8);
  677. $articleData['keyword'] = implode(',', $segList1);
  678. }
  679. if ($articleData['introduce'] == '') {
  680. //提取内容中的描述
  681. $content = $data['content'];
  682. // 去除 <style> 和 <script> 标签及其内容
  683. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  684. // 去除所有 HTML 标签
  685. $content = strip_tags($content);
  686. // 去除 HTML 实体
  687. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  688. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  689. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  690. // 去除多余空白
  691. $content = preg_replace('/\s+/u', '', $content);
  692. // 截取 100 个字符
  693. $articleData['introduce'] = mb_substr($content, 0, 100);
  694. }
  695. if ($articleData['status'] == 0) {
  696. $this->sendMessage([
  697. 'talk_type' => 100,
  698. 'title' => $articleData['title'],
  699. 'content' => '提交了审核',
  700. 'messageType' => 2,
  701. ]);
  702. }
  703. $id = Article::where(['id' => $data['id']])->update($articleData);
  704. $articleDataContent = [
  705. 'content' => $data['content'],
  706. ];
  707. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  708. //处理投票
  709. $id = $data['id'];
  710. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  711. var_dump($suvey_array, 'suvey_array________delete');
  712. //处理投票
  713. if ($is_survey == 1) {
  714. //生成年月日时分秒+8位随机数
  715. $uuid = date('YmdHis') . rand(10000000, 99999999);
  716. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  717. var_dump($suveys_array, '---------------------1');
  718. $suvey_data = [];
  719. if (is_array($suveys_array)) {
  720. foreach ($suveys_array as $key => $value) {
  721. if ($value == '') {
  722. continue;
  723. }
  724. if (is_array($value)) {
  725. $suvey_data[] = [
  726. 'sur_id' => $uuid,
  727. 'art_id' => $id,
  728. 'website_id' => $website_id ?? 2,
  729. 'survey_name' => $survey_name,
  730. 'choice_name' => $value[1],
  731. 'is_other' => 1,
  732. 'other_id' => 0,
  733. 'results' => 0,
  734. ];
  735. } else {
  736. $suvey_data[] = [
  737. 'sur_id' => $uuid,
  738. 'art_id' => $id,
  739. 'website_id' => $website_id ?? 2,
  740. 'survey_name' => $survey_name,
  741. 'choice_name' => $value,
  742. 'is_other' => 0,
  743. 'other_id' => 0,
  744. 'results' => 0,
  745. ];
  746. }
  747. if (empty($suvey_data)) {
  748. throw new \Exception("投票数据为空");
  749. }
  750. }
  751. }
  752. $result = ArticleSurvey::insert($suvey_data);
  753. if (!$result) {
  754. throw new \Exception("投票失败");
  755. }
  756. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  757. if (!$result) {
  758. throw new \Exception("投票失败");
  759. }
  760. } else {
  761. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  762. }
  763. Db::commit();
  764. return Result::success([]);
  765. } catch (\Throwable $ex) {
  766. Db::rollBack();
  767. var_dump($ex->getMessage());
  768. return Result::error("更新失败" . $ex->getMessage(), 0);
  769. }
  770. }
  771. /**
  772. * 更新资讯状态
  773. * @param array $data
  774. * @return array
  775. */
  776. public function upArticleStatus(array $data): array
  777. {
  778. $articleData = Article::where(['id' => $data['id']])->first();
  779. //发送10次
  780. for ($i = 0; $i < 10; $i++) {
  781. $this->sendMessage([
  782. 'talk_type' => 100,
  783. 'title' => $i . $articleData['title'],
  784. 'content' => '审核通过',
  785. 'messageType' => 2,
  786. 'user_id' => $articleData['admin_user_id'],
  787. ]);
  788. }
  789. var_dump($data['status'], 'status');
  790. return Result::success();
  791. if ($data['status'] == 1) {
  792. $this->sendMessage([
  793. 'talk_type' => 101,
  794. 'title' => $articleData['title'],
  795. 'content' => '审核通过',
  796. 'messageType' => 2,
  797. 'user_id' => $articleData['admin_user_id'],
  798. ]);
  799. }
  800. if ($data['status'] == 2) {
  801. $this->sendMessage([
  802. 'talk_type' => 101,
  803. 'title' => $articleData['title'],
  804. 'content' => '审核拒绝',
  805. 'messageType' => 2,
  806. 'user_id' => $articleData['admin_user_id'],
  807. ]);
  808. }
  809. if ($data['status'] == 0) {
  810. $this->sendMessage([
  811. 'talk_type' => 100,
  812. 'title' => $articleData['title'],
  813. 'content' => '提交了审核',
  814. 'messageType' => 2,
  815. ]);
  816. }
  817. $result = Article::where(['id' => $data['id']])->update($data);
  818. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  819. //article_ignore 表插入数据 db操作
  820. //转成数组
  821. //删掉数据重新写入
  822. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  823. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  824. $insert_data = [];
  825. foreach ($website_ids as $key => $value) {
  826. $insert_data[] = [
  827. 'article_id' => $data['id'],
  828. 'website_id' => $value,
  829. ];
  830. }
  831. DB::table('article_ignore')->insert($insert_data);
  832. }
  833. if ($result) {
  834. return Result::success();
  835. } else {
  836. return Result::error("更新状态失败", 0);
  837. }
  838. }
  839. /**
  840. * 获取新闻详情
  841. * @param array $data
  842. * @return array
  843. */
  844. public function getArticleInfo(array $data): array
  845. {
  846. $where = [
  847. 'article.id' => $data['id'],
  848. // 'article.status' => 1,
  849. ];
  850. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  851. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  852. $info = $result;
  853. // var_dump($info, 'info');
  854. $info['survey_array'] = $articleSurvey;
  855. if ($result) {
  856. return Result::success($info);
  857. } else {
  858. return Result::error("查询失败", 0);
  859. }
  860. }
  861. /**
  862. * 获取头条新闻
  863. * @param array $data
  864. * @return array
  865. */
  866. public function getWebsiteArticlett(array $data): array
  867. {
  868. $website_id = $data['website_id'];
  869. $website = Website::where('id', $data['website_id'])->first();
  870. if(empty($website)){
  871. return Result::error("网站不存在",0);
  872. }
  873. $categorys = $this->processArticlePro($website_id);
  874. $catiall = $categorys['catiall'];
  875. $categoryIds = $categorys['categoryIds'];
  876. $where = [
  877. 'status' => 1
  878. ];
  879. // $website_column = $website['column'];
  880. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  881. $website_column = json_decode($website['website_column_arr_id'],true);
  882. }
  883. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  884. // return Result::success($diff_pid_categoryIds);
  885. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  886. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  887. }
  888. // $website_id = $data['website_id'];
  889. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  890. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  891. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  892. switch ($data['level']) {
  893. case 1:
  894. case 2:
  895. case 3:
  896. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  897. $query = Article::where($where)
  898. ->where('level', 'like', '%' . $data['level'] . '%')
  899. ->orderBy('updated_at', 'desc');
  900. break;
  901. case 4: //最新资讯
  902. $query = Article::where($where)->orderBy('updated_at', 'desc');
  903. break;
  904. case 5: //资讯推荐
  905. $query = Article::where($where)
  906. ->where('updated_at', '>', $month);
  907. break;
  908. case 7: //资讯分类
  909. if (isset($data['id']) && !empty($data['id'])) {
  910. $keyword = Article::where('id', $data['id'])->value('keyword');
  911. $keywordArray = explode(',', $keyword);
  912. $whereL7 = [];
  913. foreach ($keywordArray as $k => $v) {
  914. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  915. }
  916. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  917. break;
  918. } else {
  919. return Result::error("请输入资讯ID", 0);
  920. break;
  921. }
  922. default:
  923. break;
  924. }
  925. // $whereL7 = [];
  926. // if(isset($data['id']) && !empty($data['id'])){
  927. // $keyword = Article::where('id', $data['id'])->value('keyword');
  928. // $keywordArray = explode(',', $keyword);
  929. // foreach ($keywordArray as $k => $v) {
  930. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  931. // }
  932. // }
  933. // $query = Article::where($where)
  934. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  935. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  936. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  937. // }
  938. // if($data['level'] == 7){
  939. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  940. // }
  941. // if($data['level'] == 4){
  942. // $query = $query->inRandomOrder()
  943. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  944. // }
  945. // if($data['level'] == 5){
  946. // $query = $query->orderBy('updated_at','desc');
  947. // }
  948. // });
  949. if ($data['textnum'] > 0) {
  950. $query = clone $query;
  951. $result['text'] = $query
  952. ->whereIn('catid', $categoryIds)
  953. ->leftJoinSub(function ($query) use ($website_id) {
  954. $query->from('article_ignore')
  955. ->where('website_id', $website_id);
  956. }, 'article_ignore', function ($join) {
  957. $join->on('article_ignore.article_id', '=', 'article.id');
  958. })
  959. ->where(function ($query) use ($website_id) {
  960. $query->whereNull('article_ignore.article_id')
  961. ->orWhere('article_ignore.website_id', '!=', $website_id);
  962. })
  963. ->select(
  964. 'article.id',
  965. 'article.title',
  966. 'article.author',
  967. 'article.updated_at',
  968. 'article.introduce',
  969. 'article.islink',
  970. 'article.linkurl',
  971. 'article.copyfrom',
  972. 'article.cat_arr_id',
  973. 'article.catid',
  974. 'article.level'
  975. )
  976. ->offset($data['placeid'])
  977. ->limit($data['textnum'])
  978. ->get()->all();
  979. foreach ($result['text'] as $k => $v) {
  980. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  981. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  982. }
  983. }
  984. if ($data['imgnum'] > 0) {
  985. $query = clone $query;
  986. $result['img'] = $query
  987. ->whereIn('catid', $categoryIds)
  988. ->where('article.imgurl', '!=', '')
  989. ->select(
  990. 'article.id',
  991. 'article.title',
  992. 'article.imgurl',
  993. 'article.author',
  994. 'article.updated_at',
  995. 'article.introduce',
  996. 'article.islink',
  997. 'article.linkurl',
  998. 'article.copyfrom',
  999. 'article.cat_arr_id',
  1000. 'article.catid',
  1001. 'article.level'
  1002. )
  1003. ->offset($data['placeid'])
  1004. ->limit($data['imgnum'])
  1005. ->get()->all();
  1006. foreach ($result['img'] as $k => $v) {
  1007. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1008. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1009. }
  1010. }
  1011. if (empty($result)) {
  1012. return Result::error("暂无相关资讯", 0);
  1013. }
  1014. return Result::success($result);
  1015. }
  1016. /**
  1017. * 获取模块新闻
  1018. * @param array $data
  1019. * @return array
  1020. */
  1021. public function getWebsiteModelArticles(array $data): array
  1022. {
  1023. $catid = $data['catid'];
  1024. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1025. $category = $category->toArray();
  1026. if (!empty($category)) {
  1027. $where = [
  1028. 'status' => 1,
  1029. 'catid' => $catid,
  1030. ];
  1031. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1032. // 1:文字新闻;2:轮播图;3:图文;
  1033. // 级别:0:未分类
  1034. // 3:推荐图片
  1035. if ($data['level'] == 1) {
  1036. $data['level'] = 0;
  1037. }
  1038. $result = Article::where($where)
  1039. ->where(function ($query) use ($data) {
  1040. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1041. ->orWhereNull("level")
  1042. ->orWhereRaw("level = '[]'");
  1043. })
  1044. ->where(function ($query) use ($data) {
  1045. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1046. ->orWhereNull("ignore_ids");
  1047. })
  1048. ->orderBy("updated_at", "desc")
  1049. ->offset($placeid)
  1050. ->limit($data['pagesize'])
  1051. ->get();
  1052. if (empty($result)) {
  1053. return Result::error("此栏目暂无相关新闻", 0);
  1054. }
  1055. } else {
  1056. return Result::error("此网站暂无此栏目", 0);
  1057. }
  1058. return Result::success($result);
  1059. }
  1060. /**
  1061. *获取新闻列表
  1062. * @param array $data
  1063. * @return array
  1064. */
  1065. public function getWebsiteArticleList(array $data): array
  1066. {
  1067. // return Result::success($data);
  1068. $where[] = ['status', '=', 1];
  1069. $website_id = $data['website_id'];
  1070. $website = Website::where('id', $data['website_id'])->first();
  1071. if(empty($website)){
  1072. return Result::error("网站不存在",0);
  1073. }
  1074. // $website_column = $website['column'];
  1075. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  1076. $website_column = json_decode($website['website_column_arr_id'],true);
  1077. }
  1078. $categorys = $this->processArticlePro($website_id);
  1079. $cat_1st_arr = $categorys['cat_1st_arr'];
  1080. $catiall = $categorys['catiall'];
  1081. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1082. // return Result::success($diff_pid_categoryIds);
  1083. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1084. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1085. }
  1086. if (isset($data['catid']) && !empty($data['catid'])) {
  1087. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1088. if (empty($category)) {
  1089. return Result::error("此网站暂无此栏目", 0);
  1090. }
  1091. array_push($where, ['catid', '=', $data['catid']]);
  1092. }
  1093. // return Result::success($where);
  1094. $query = Article::where($where)
  1095. ->leftJoinSub(function ($query) use ($website_id) {
  1096. $query->from('article_ignore')
  1097. ->where('website_id', $website_id);
  1098. }, 'article_ignore', function ($join) {
  1099. $join->on('article_ignore.article_id', '=', 'article.id');
  1100. })
  1101. ->where(function ($query) use ($website_id) {
  1102. $query->whereNull('article_ignore.article_id')
  1103. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1104. })
  1105. ->select(
  1106. 'article.id',
  1107. 'article.title',
  1108. 'article.imgurl',
  1109. 'article.author',
  1110. 'article.updated_at',
  1111. 'article.introduce',
  1112. 'article.islink',
  1113. 'article.linkurl',
  1114. 'article.copyfrom',
  1115. 'article.cat_arr_id',
  1116. 'article.catid'
  1117. );
  1118. $count = $query->count();
  1119. $rep = $query->orderBy("updated_at", "desc")
  1120. ->offset(($data['page'] - 1) * $data['pageSize'])
  1121. ->limit($data['pageSize'])
  1122. ->get()->all();
  1123. $categorys = $this->processArticlePro($website_id);
  1124. $cat_1st_arr = $categorys['cat_1st_arr'];
  1125. $catiall = $categorys['catiall'];
  1126. // $web['website_id'] = $data['website_id'];
  1127. foreach ($rep as $k => $v) {
  1128. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1129. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1130. }
  1131. // $rep = $this->processArticles($rep,$web);
  1132. $data = [
  1133. 'rows' => $rep,
  1134. 'count' => $count,
  1135. ];
  1136. if (empty($rep)) {
  1137. return Result::error("没有信息数据");
  1138. }
  1139. return Result::success($data);
  1140. }
  1141. /**
  1142. * 前端-获取新闻详情
  1143. * @param array $data
  1144. * @return array
  1145. */
  1146. public function selectWebsiteArticleInfo(array $data): array
  1147. {
  1148. $where = [
  1149. 'article.id' => $data['id'],
  1150. 'article.status' => 1,
  1151. ];
  1152. $result = Article::where($where)
  1153. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1154. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1155. ->where(function ($query) use ($data) {
  1156. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1157. ->orWhereNull("ignore_ids");
  1158. })
  1159. ->select(
  1160. 'article.*',
  1161. 'article_data.content',
  1162. 'article_data.article_id',
  1163. 'article_extend.website_url',
  1164. 'article_extend.email',
  1165. 'article_extend.contacts',
  1166. 'article_extend.contacts_mobile',
  1167. 'article_extend.contacts_address',
  1168. 'article_extend.zip_code',
  1169. 'article_extend.enterprise_name'
  1170. )
  1171. ->first();
  1172. if (empty($result)) {
  1173. return Result::error("暂无此新闻!", 0);
  1174. }
  1175. if (!empty($result['publiced_at'])) {
  1176. $result['updated_at'] = $result['publiced_at'];
  1177. }
  1178. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1179. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1180. ->where('website_category.website_id', $data['website_id'])
  1181. ->where(['website_category.category_id' => $result['catid']])
  1182. ->first();
  1183. if (empty($category)) {
  1184. return Result::error("查询失败", 0);
  1185. }
  1186. //手动推荐文章
  1187. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1188. if (empty($commend_ids)) {
  1189. $commendArticle = [];
  1190. } else {
  1191. //去除不存在的文章ID
  1192. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1193. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1194. ->where('article.status', 1)
  1195. ->where('website_category.website_id', $data['website_id'])
  1196. ->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')
  1197. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1198. // ->orderBy('article.updated_at', 'desc')
  1199. ->limit(5)
  1200. ->get();
  1201. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1202. foreach ($commendArticle as $k => $v) {
  1203. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1204. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1205. $cat_arr_id = array_unique($cat_arr_id);
  1206. // 从website_category取出alias_pinyin
  1207. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1208. ->whereIn('category_id', $cat_arr_id)
  1209. ->pluck('alias_pinyin', 'category_id')
  1210. ->toArray();
  1211. // 将cat_arr_id的json转成路径/隔开
  1212. $path_parts = [];
  1213. foreach ($cat_arr_id as $cat_id) {
  1214. if (isset($cat_arr[$cat_id])) {
  1215. $path_parts[] = $cat_arr[$cat_id];
  1216. }
  1217. }
  1218. $v->alias_pinyin = implode('/', $path_parts);
  1219. } else {
  1220. $v->alias_pinyin = '';
  1221. }
  1222. }
  1223. }
  1224. $result['category_id'] = $category['category_id'];
  1225. $result['cat_name'] = $category['alias'];
  1226. $result['website_name'] = $category['website_name'] ?? "";
  1227. $result['suffix'] = $category['suffix'] ?? "";
  1228. $result['commendArticle'] = $commendArticle;
  1229. $result['commend_ids'] = $commend_ids;
  1230. return Result::success($result);
  1231. }
  1232. /**
  1233. * 前端-获取网站调查问卷
  1234. * @param array $data
  1235. * @return array
  1236. */
  1237. public function getWebsiteSurvey(array $data): array
  1238. {
  1239. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1240. $website = Website::where('id', $data['website_id'])->first();
  1241. if (empty($website)) {
  1242. return Result::error("暂无此网站", 0);
  1243. }
  1244. }
  1245. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1246. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1247. if (empty($article)) {
  1248. return Result::error("暂无此文章", 0);
  1249. }
  1250. // return Result::error($data,0);
  1251. $where['art_id'] = $data['art_id'];
  1252. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1253. } else {
  1254. $survey = Article::where(function ($query) {
  1255. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1256. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1257. })
  1258. ->where('status', 1)
  1259. ->where('is_survey', 1)
  1260. ->select('survey_id')
  1261. ->orderBy('updated_at', 'desc')
  1262. ->first();
  1263. if (empty($survey)) {
  1264. return Result::error("暂无调查问卷", 0);
  1265. }
  1266. $where['sur_id'] = $survey['survey_id'];
  1267. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1268. }
  1269. // return Result::success($where);
  1270. $result = ArticleSurvey::where($where)
  1271. ->where(function ($query) {
  1272. $query->where('is_other', 0)
  1273. ->orWhere(function ($subQuery) {
  1274. $subQuery->where('is_other', 1)
  1275. ->where('other_id', 0);
  1276. });
  1277. })
  1278. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1279. ->select('article_survey.*', 'article.survey_type')
  1280. ->get()->all();
  1281. if (empty($result)) {
  1282. return Result::error("此文章暂无调查问卷", 0);
  1283. }
  1284. return Result::success($result);
  1285. }
  1286. /**
  1287. * 前端-添加网站调查问卷选项
  1288. * @param array $data
  1289. * @return array
  1290. */
  1291. public function addWebsiteSurveyOption(array $data): array
  1292. {
  1293. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1294. $website = Website::where('id', $data['website_id'])->first();
  1295. if (empty($website)) {
  1296. return Result::error("暂无此网站", 0);
  1297. }
  1298. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1299. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1300. if (empty($survey)) {
  1301. return Result::error("此调查问卷不可添加选项", 0);
  1302. }
  1303. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1304. $choice = [
  1305. 'art_id' => $survey['art_id'],
  1306. 'website_id' => $data['website_id'],
  1307. 'survey_name' => $survey['survey_name'],
  1308. 'choice_name' => $data['choice_name'],
  1309. 'sur_id' => $survey['sur_id'],
  1310. 'is_other' => 1,
  1311. 'other_id' => $survey['id'],
  1312. ];
  1313. $result = ArticleSurvey::insertGetId($choice);
  1314. if (empty($result)) {
  1315. return Result::error("添加失败", 0);
  1316. }
  1317. return Result::success($result);
  1318. }
  1319. }
  1320. return Result::error("添加失败", 0);
  1321. }
  1322. return Result::error("添加失败", 0);
  1323. }
  1324. /**
  1325. * 前端-调查问卷投票
  1326. * @param array $data
  1327. * @return array
  1328. */
  1329. public function addWebsiteSurveyVote(array $data): array
  1330. {
  1331. // return Result::success($data);
  1332. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1333. $website = Website::where('id', $data['website_id'])->first();
  1334. if (empty($website)) {
  1335. return Result::error("暂无此网站", 0);
  1336. }
  1337. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1338. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1339. // return Result::success($survey);
  1340. if (empty($is_survey)) {
  1341. return Result::error("此调查问卷不存在", 0);
  1342. }
  1343. // return Result::success($survey);
  1344. // 调查问卷类型
  1345. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1346. //多选 若是json型则转化成数组类型
  1347. if (strpos($data['choice_id'], '[') === 0) {
  1348. $data['choice_id'] = json_decode($data['choice_id'], true);
  1349. } else {
  1350. // 单选 也转换成数组
  1351. $data['choice_id'] = [$data['choice_id']];
  1352. }
  1353. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1354. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1355. // ->where('website_id',$data['website_id'])
  1356. ->where('is_other', 1)
  1357. ->where('other_id', 0)
  1358. ->first();
  1359. if (!empty($other)) {
  1360. return Result::error("请选择已有的选项!", 0);
  1361. }
  1362. $choice['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. // return Result::success($choice['other']);
  1368. $choice_id = $data['choice_id'];
  1369. if (!empty($choice['other'])) {
  1370. // array_push($data['choice_id'],$choice['other']['other_id']);
  1371. if (!empty($choice_id)) {
  1372. $key = array_search($choice['other']['id'], $choice_id);
  1373. if ($key !== false) {
  1374. unset($choice_id[$key]);
  1375. $choice_id = array_values($choice_id);
  1376. }
  1377. array_push($choice_id, $choice['other']['other_id']);
  1378. } else {
  1379. $choice_id[0] = $choice['other']['other_id'];
  1380. }
  1381. array_push($data['choice_id'], $choice['other']['other_id']);
  1382. }
  1383. // return Result::success($data);
  1384. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1385. // ->where('website_id',$data['website_id'])
  1386. ->increment('results', 1);
  1387. if (empty($choice)) {
  1388. return Result::error("请选择已有的选项!", 0);
  1389. }
  1390. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1391. // ->where('website_id',$data['website_id'])
  1392. ->where('other_id', 0)
  1393. ->get();
  1394. $survey['choice'] = $choice_id;
  1395. return Result::success($survey);
  1396. }
  1397. return Result::error("参数必填!");
  1398. }
  1399. return Result::error("此调查问卷不存在", 0);
  1400. }
  1401. return Result::error("参数必填!");
  1402. }
  1403. /**
  1404. * 后端-获取网站调查问卷列表
  1405. * @param array $data
  1406. * @return array
  1407. */
  1408. public function getSurveyList(array $data): array
  1409. {
  1410. $where = [];
  1411. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1412. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1413. }
  1414. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1415. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1416. }
  1417. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1418. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1419. }
  1420. // return Result::success($where);
  1421. if (!empty($where)) {
  1422. $query = Article::where($where)->where(function ($q) {
  1423. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1424. });
  1425. } else {
  1426. $query = Article::where(function ($q) {
  1427. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1428. });
  1429. }
  1430. $count = $query->count();
  1431. $survey = $query->orderByDesc('id')
  1432. ->limit($data['pageSize'])
  1433. ->offset(($data['page'] - 1) * $data['pageSize'])
  1434. ->get();
  1435. if (empty($survey->toArray())) {
  1436. return Result::error("暂无调查问卷!", 0);
  1437. }
  1438. $result = [
  1439. 'rows' => $survey,
  1440. 'count' => $count,
  1441. ];
  1442. return Result::success($result);
  1443. }
  1444. /**
  1445. * 后端-获取网站调查问卷详情
  1446. * @param array $data
  1447. * @return array
  1448. */
  1449. public function getSurveyInfo(array $data): array
  1450. {
  1451. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1452. $where = ['sur_id' => $data['sur_id']];
  1453. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1454. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1455. ->select('article_survey.*', 'article.survey_type')
  1456. ->get()->all();
  1457. if (empty($choose)) {
  1458. return Result::error("此调查问卷不存在", 0);
  1459. }
  1460. $resultsArray = array_column($choose, 'results');
  1461. $total = array_sum($resultsArray);
  1462. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1463. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1464. // $total = 0;
  1465. if (!empty($other)) {
  1466. $total = $total + $other['results'];
  1467. $other['choice_name'] = '(其他)';
  1468. if (!empty($others)) {
  1469. $other['hasChildren'] = true;
  1470. // array_push($other,['hasChildren','=',true]);
  1471. $other['children'] = $others;
  1472. $other_choices = [$other->toArray()];
  1473. $mer_choice = array_merge($choose, $other_choices);
  1474. $value_choice = array_values($mer_choice);
  1475. } else {
  1476. // return Result::error('1111');
  1477. $other_choices = [$other->toArray()];
  1478. $other_choices = array_merge($choose, $other_choices);
  1479. $value_choice = array_values($other_choices);
  1480. // return Result::success($result);
  1481. }
  1482. } else {
  1483. $value_choice = $choose;
  1484. }
  1485. $result = [
  1486. 'choose' => $value_choice,
  1487. 'total' => $total,
  1488. ];
  1489. }
  1490. return Result::success($result);
  1491. }
  1492. /**
  1493. * 前端-搜索新闻列表
  1494. * @param array $data
  1495. * @return array
  1496. */
  1497. public function selectWebsiteArticle(array $data): array
  1498. {
  1499. $website = Website::where('id', $data['website_id'])->first();
  1500. if(empty($website)){
  1501. return Result::error("网站不存在",0);
  1502. }
  1503. // $website_column = $website['column'];
  1504. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  1505. $website_column = json_decode($website['website_column_arr_id'],true);
  1506. }
  1507. $website_id = $data['website_id'];
  1508. $categorys = $this->processArticlePro($website_id);
  1509. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1510. // return Result::success($diff_pid_categoryIds);
  1511. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1512. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1513. }
  1514. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1515. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1516. $catiall = $categorys['catiall'];
  1517. $categoryIds = $categorys['categoryIds'];
  1518. // return Result::success($categoryIds);
  1519. $query = Article::where('status', 1)
  1520. ->whereIn('catid', $categoryIds)
  1521. ->leftJoinSub(function ($query) use ($website_id) {
  1522. $query->from('article_ignore')
  1523. ->where('website_id', $website_id);
  1524. }, 'article_ignore', function ($join) {
  1525. $join->on('article_ignore.article_id', '=', 'article.id');
  1526. })
  1527. ->where(function ($query) use ($website_id) {
  1528. $query->whereNull('article_ignore.article_id')
  1529. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1530. });
  1531. // ->get()->all();
  1532. // return Result::success($query);
  1533. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1534. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1535. }
  1536. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1537. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1538. }
  1539. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1540. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1541. }
  1542. // 计算总数
  1543. $count = $query->count();
  1544. // return Result::success($count);
  1545. // 分页查询
  1546. $articles = $query
  1547. ->select(
  1548. 'article.id',
  1549. 'article.title',
  1550. 'article.imgurl',
  1551. 'article.author',
  1552. 'article.updated_at',
  1553. 'article.introduce',
  1554. 'article.islink',
  1555. 'article.linkurl',
  1556. 'article.copyfrom',
  1557. 'article.cat_arr_id',
  1558. 'article.catid',
  1559. 'article.department_arr_id',
  1560. 'article.city_arr_id',
  1561. )
  1562. ->orderBy("updated_at", "desc")
  1563. ->offset(($data['page'] - 1) * $data['pageSize'])
  1564. ->limit($data['pageSize'])
  1565. ->get();
  1566. // return Result::success($articles);
  1567. foreach ($articles as $k => $v) {
  1568. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1569. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1570. }
  1571. if (empty($articles)) {
  1572. return Result::error("没有符合条件的资讯数据");
  1573. }
  1574. $result = [
  1575. 'rows' => $articles,
  1576. 'count' => $count,
  1577. ];
  1578. return Result::success($result);
  1579. }
  1580. /**
  1581. * 模块新闻加强版
  1582. * @param array $data
  1583. * @return array
  1584. */
  1585. public function getWebsiteCatidArticle(array $data): array
  1586. {
  1587. $where = [
  1588. 'website_category.category_id' => $data['catid'],
  1589. 'website_category.website_id' => $data['website_id'],
  1590. ];
  1591. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1592. $child_catnum = $data['child_catnum'] ?? 1;
  1593. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1594. $childCategoryIds = array_column($category['child'], 'category_id');
  1595. if (empty($childCategoryIds)) {
  1596. return Result::error("暂无子栏目", 0);
  1597. }
  1598. $imgArticles = [];
  1599. $textArticles = [];
  1600. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1601. // 初始化子分类图片新闻和文字新闻数组
  1602. // 查询所有子级栏目的图文新闻
  1603. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1604. ->where(function ($query) use ($data) {
  1605. $query->where(function ($subQuery) use ($data) {
  1606. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1607. })->orWhereNull("ignore_ids");
  1608. })
  1609. ->where('status', 1)
  1610. ->where('imgurl', '!=', '')
  1611. ->select('*')
  1612. ->orderBy('updated_at', 'desc')
  1613. ->limit($data['child_imgnum'])
  1614. ->get();
  1615. }
  1616. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1617. // 查询所有子级栏目的文字新闻
  1618. $textArticles = Article::where('catid', $childCategoryIds[0])
  1619. ->where('status', 1)
  1620. ->where(function ($query) use ($data) {
  1621. $query->where(function ($subQuery) use ($data) {
  1622. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1623. })->orWhereNull("ignore_ids");
  1624. })
  1625. ->select('*')
  1626. ->orderBy('updated_at', 'desc')
  1627. ->limit($data['child_textnum'])
  1628. ->get();
  1629. }
  1630. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1631. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1632. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1633. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1634. return $child;
  1635. }, $category['child']);
  1636. }
  1637. // }
  1638. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1639. $category['img'] = WebsiteCategory::where($where)
  1640. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1641. ->where('article.status', 1)
  1642. ->where('article.imgurl', '!=', '')
  1643. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1644. ->orderBy('article.updated_at', 'desc')
  1645. ->limit($data['img_num'])
  1646. ->get();
  1647. }
  1648. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1649. $category['text'] = WebsiteCategory::where($where)
  1650. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1651. ->where('article.status', 1)
  1652. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1653. ->orderBy('article.updated_at', 'desc')
  1654. ->limit($data['text_num'])
  1655. ->get();
  1656. }
  1657. // $category = $category->get();
  1658. if (empty($category)) {
  1659. return Result::error("查询失败", 0);
  1660. }
  1661. return Result::success($category);
  1662. }
  1663. /**
  1664. * 模块新闻加强plus版
  1665. * @param array $data
  1666. * @return array
  1667. */
  1668. public function getWebsiteAllArticle(array $data): array
  1669. {
  1670. // return Result::success($data);
  1671. $time1 = microtime(true);
  1672. $wetbsite_id = $data['website_id'] ?? 2;
  1673. $data = json_decode($data['id'], true);
  1674. $website = Website::where('id', $wetbsite_id)->first();
  1675. if(empty($website)){
  1676. return Result::error("网站不存在",0);
  1677. }
  1678. // return Result::success($website);
  1679. $website_column = $website['website_column_arr_id'] ?? '[]';
  1680. $website_column = json_decode($website_column,true);
  1681. $categorys = $this->processArticlePro($wetbsite_id);
  1682. $cat_1st_arr = $categorys['cat_1st_arr'];
  1683. $catiall = $categorys['catiall'];
  1684. // return Result::success($catiall);
  1685. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1686. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1687. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1688. }
  1689. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1690. // return Result::success($categorys);
  1691. $parent_category = array_column($data, 'parent');
  1692. $parent_cat = [];
  1693. $child_category = array_column($data, 'child');
  1694. if (!empty($parent_category)) {
  1695. foreach ($parent_category as $key => $value) {
  1696. $arr = array_map('intval', explode(',', $value));
  1697. $parent_cat[$key] = $arr[0] ?? 0;
  1698. $parent_category = $arr[0] ?? 0;
  1699. $article_imgnum = $arr[1] ?? 0;
  1700. $article_textnum = $arr[2] ?? 0;
  1701. if ($parent_category != 0) {
  1702. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1703. // return Result::success($category_arr);
  1704. if ($article_imgnum != 0) {
  1705. $img_article = Article::whereIn('catid', $category_arr)
  1706. ->where('status', 1)
  1707. ->where('imgurl', '!=', '')
  1708. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1709. $query->from('article_ignore')
  1710. ->where('website_id', $wetbsite_id);
  1711. }, 'article_ignore', function ($join) {
  1712. $join->on('article_ignore.article_id', '=', 'article.id');
  1713. })
  1714. ->where(function ($query) use ($wetbsite_id) {
  1715. $query->whereNull('article_ignore.article_id')
  1716. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1717. })
  1718. ->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')
  1719. ->orderBy('updated_at', 'desc')
  1720. ->limit($article_imgnum)
  1721. ->get()->all();
  1722. foreach ($img_article as $k => $v) {
  1723. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1724. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1725. }
  1726. } else {
  1727. $img_article = [];
  1728. }
  1729. if ($article_textnum != 0) {
  1730. $text_article = Article::whereIn('catid', $category_arr)
  1731. ->where('status', 1)
  1732. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1733. $query->from('article_ignore')
  1734. ->where('website_id', $wetbsite_id);
  1735. }, 'article_ignore', function ($join) {
  1736. $join->on('article_ignore.article_id', '=', 'article.id');
  1737. })
  1738. ->where(function ($query) use ($wetbsite_id) {
  1739. $query->whereNull('article_ignore.article_id')
  1740. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1741. })
  1742. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1743. ->orderBy('updated_at', 'desc')
  1744. ->limit($article_textnum)
  1745. ->get()->all();
  1746. foreach ($text_article as $k => $v) {
  1747. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1748. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1749. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1750. }
  1751. } else {
  1752. $text_article = [];
  1753. }
  1754. $catiall[$parent_category]['imgnum'] = $img_article;
  1755. $catiall[$parent_category]['textnum'] = $text_article;
  1756. $parent[$key] = $catiall[$parent_category];
  1757. } else {
  1758. $parent[$key] = '';
  1759. }
  1760. }
  1761. }
  1762. if (!empty($child_category)) {
  1763. foreach ($child_category as $key => $value) {
  1764. $arr = array_map('intval', explode(',', $value));
  1765. $parent_category = $parent_cat[$key];
  1766. $child_category = $arr[0] ?? 0;
  1767. $article_imgnum = $arr[1] ?? 0;
  1768. $article_textnum = $arr[2] ?? 0;
  1769. if ($child_category != 0) {
  1770. $all_childcat = $cat_1st_arr[$parent_category];
  1771. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1772. // 从 $websiteInfoIndexed 中获取对应的数据
  1773. $info = $websiteInfoIndexed[$v];
  1774. // 返回一个包含所需信息的数组
  1775. return [
  1776. 'alias' => $info->alias,
  1777. 'category_id' => $info->category_id,
  1778. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1779. 'pid' => $info->pid,
  1780. 'type' => $info->type,
  1781. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1782. 'pinyin' => $info->pinyin,
  1783. ];
  1784. }, $all_childcat);
  1785. if ($article_imgnum != 0) {
  1786. $img_article = Article::where('catid', $child_category)
  1787. ->where('status', 1)
  1788. ->where('imgurl', '!=', '')
  1789. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1790. $query->from('article_ignore')
  1791. ->where('website_id', $wetbsite_id);
  1792. }, 'article_ignore', function ($join) {
  1793. $join->on('article_ignore.article_id', '=', 'article.id');
  1794. })
  1795. ->where(function ($query) use ($wetbsite_id) {
  1796. $query->whereNull('article_ignore.article_id')
  1797. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1798. })
  1799. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1800. ->orderBy('updated_at', 'desc')
  1801. ->limit($article_imgnum)
  1802. ->get()->all();
  1803. foreach ($img_article as $k => $v) {
  1804. // var_dump($v);
  1805. // var_dump($k);
  1806. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1807. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1808. }
  1809. } else {
  1810. $img_article = [];
  1811. }
  1812. if ($article_textnum != 0) {
  1813. $text_article = Article::where('catid', $child_category)
  1814. ->where('status', 1)
  1815. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1816. $query->from('article_ignore')
  1817. ->where('website_id', $wetbsite_id);
  1818. }, 'article_ignore', function ($join) {
  1819. $join->on('article_ignore.article_id', '=', 'article.id');
  1820. })
  1821. ->where(function ($query) use ($wetbsite_id) {
  1822. $query->whereNull('article_ignore.article_id')
  1823. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1824. })
  1825. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1826. ->orderBy('updated_at', 'desc')
  1827. ->limit($article_textnum)
  1828. ->get()->all();
  1829. foreach ($text_article as $k => $v) {
  1830. // var_dump($v);
  1831. // var_dump($k);
  1832. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1833. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1834. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1835. }
  1836. } else {
  1837. $text_article = [];
  1838. }
  1839. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1840. $catiall[$child_category]['imgnum'] = $img_article;
  1841. $catiall[$child_category]['textnum'] = $text_article;
  1842. $child[$key] = $catiall[$child_category];
  1843. // var_dump($pids);
  1844. } else {
  1845. $child[$key] = '';
  1846. }
  1847. }
  1848. }
  1849. foreach ($parent as $key => $value) {
  1850. $result[$key] = $value;
  1851. if (!empty($child[$key])) {
  1852. // var_dump($child[$key]);
  1853. $result[$key]['child'] = $child[$key];
  1854. // $value[$key]['child'] = $child[$key];
  1855. } else {
  1856. $result[$key]['child'] = [
  1857. "alias" => null,
  1858. "category_id" => null,
  1859. "type" => null,
  1860. "pinyin" => null,
  1861. "all_childcat" => [],
  1862. "imgnum" => [],
  1863. "textnum" => []
  1864. ];
  1865. }
  1866. }
  1867. return Result::success($result);
  1868. }
  1869. /**
  1870. * 辅助方法:获取文章列表
  1871. */
  1872. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1873. {
  1874. sleep(1);
  1875. $query = Article::where('article.status', 1)
  1876. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1877. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1878. ->where(function ($query) use ($website) {
  1879. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1880. })
  1881. ->leftJoin('website_category', function ($join) use ($website) {
  1882. $join->on('article.catid', '=', 'website_category.category_id')
  1883. ->where('website_category.website_id', '=', $website['website_id']);
  1884. })
  1885. ->select(
  1886. 'article.id',
  1887. 'article.title',
  1888. 'article.imgurl',
  1889. 'article.author',
  1890. 'article.updated_at',
  1891. 'article.introduce',
  1892. 'article.islink',
  1893. 'article.linkurl',
  1894. 'article.copyfrom',
  1895. 'article.cat_arr_id',
  1896. 'article.catid',
  1897. 'website_category.alias as category_name'
  1898. )
  1899. ->orderBy('updated_at', 'desc')
  1900. ->limit($limit);
  1901. // 如果是图片文章,添加图片URL条件
  1902. if ($isImageArticle) {
  1903. $query->where('imgurl', '!=', '');
  1904. } else {
  1905. // 文字文章不需要imgurl字段
  1906. $query->addSelect('article.introduce');
  1907. }
  1908. $articles = $query->get();
  1909. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1910. }
  1911. /**
  1912. * 乡村网-获取特殊新闻模块
  1913. * @param array $data
  1914. * @return array
  1915. */
  1916. public function getWebsiteArticles(array $data): array
  1917. {
  1918. $website_id = $data['website_id'];
  1919. $website = Website::where('id', $website_id)->first();
  1920. if(empty($website)){
  1921. return Result::error("网站不存在",0);
  1922. }
  1923. // return Result::success($website);
  1924. $website_column = $website['website_column_arr_id'] ?? '[]';
  1925. $website_column = json_decode($website_column, true);
  1926. $catids = json_decode($data['id'], true);
  1927. $parent_category = array_column($catids, 'parent');
  1928. if(!empty($parent_category) && is_array($parent_category)) {
  1929. $categorys = $this->processArticlePro($website_id);
  1930. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1931. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1932. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1933. }
  1934. $catiall = $categorys['catiall'];
  1935. $cat_1st_arr = $categorys['cat_1st_arr'];
  1936. // return Result::success($categorys);
  1937. foreach ($parent_category as $key => $value) {
  1938. $arr = array_map('intval', explode(',', $value));
  1939. $parent_category = $arr[0] ?? 0;
  1940. $article_imgnum = $arr[1] ?? 0;
  1941. $article_textnum = $arr[2] ?? 0;
  1942. if ($parent_category != 0) {
  1943. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1944. // return Result::success($category_arr);
  1945. if ($article_imgnum != 0) {
  1946. $img_article = Article::whereIn('catid', $category_arr)
  1947. ->where('status', 1)
  1948. ->where('imgurl', '!=', '')
  1949. ->leftJoinSub(function ($query) use ($website_id) {
  1950. $query->from('article_ignore')
  1951. ->where('website_id', $website_id);
  1952. }, 'article_ignore', function ($join) {
  1953. $join->on('article_ignore.article_id', '=', 'article.id');
  1954. })
  1955. ->where(function ($query) use ($website_id) {
  1956. $query->whereNull('article_ignore.article_id')
  1957. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1958. })
  1959. ->select(
  1960. 'id',
  1961. 'title',
  1962. 'imgurl',
  1963. 'author',
  1964. 'updated_at',
  1965. 'introduce',
  1966. 'islink',
  1967. 'linkurl',
  1968. 'copyfrom',
  1969. 'cat_arr_id',
  1970. 'catid as category_id'
  1971. )
  1972. ->orderBy('updated_at', 'desc')
  1973. ->limit($article_imgnum)
  1974. ->get()->all();
  1975. foreach ($img_article as $k => $v) {
  1976. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1977. // return Result::success($v);
  1978. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1979. }
  1980. } else {
  1981. $img_article = [];
  1982. }
  1983. if ($article_textnum != 0) {
  1984. $text_article = Article::whereIn('catid', $category_arr)
  1985. ->where('status', 1)
  1986. ->leftJoinSub(function ($query) use ($website_id) {
  1987. $query->from('article_ignore')
  1988. ->where('website_id', $website_id);
  1989. }, 'article_ignore', function ($join) {
  1990. $join->on('article_ignore.article_id', '=', 'article.id');
  1991. })
  1992. ->where(function ($query) use ($website_id) {
  1993. $query->whereNull('article_ignore.article_id')
  1994. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1995. })
  1996. ->select(
  1997. 'id',
  1998. 'title',
  1999. 'author',
  2000. 'updated_at',
  2001. 'introduce',
  2002. 'islink',
  2003. 'linkurl',
  2004. 'copyfrom',
  2005. 'cat_arr_id',
  2006. 'catid as category_id'
  2007. )
  2008. ->orderBy('updated_at', 'desc')
  2009. ->limit($article_textnum)
  2010. ->get()->all();
  2011. foreach ($text_article as $k => $v) {
  2012. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2013. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2014. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2015. }
  2016. } else {
  2017. $text_article = [];
  2018. }
  2019. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2020. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2021. $parent[$key] = $catiall[$parent_category];
  2022. } else {
  2023. $parent[$key] = [];
  2024. }
  2025. }
  2026. }
  2027. return Result::success($parent);
  2028. }
  2029. // 封装处理商品的路由问题
  2030. function processGoods($goods, $data)
  2031. {
  2032. return $goods->map(function ($good) use ($data) {
  2033. $catid = $good->catid ?? 0;
  2034. // $pinyin = '';
  2035. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2036. if (!empty($category->pid) && $category->pid != 0) {
  2037. $level = json_decode($category->category_arr_id, true);
  2038. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2039. ->whereIn('category_id', $level)
  2040. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2041. ->get(['aLIas_pinyin'])
  2042. ->pluck('aLIas_pinyin')
  2043. ->implode('/');
  2044. } else {
  2045. $pinyin = $category->aLIas_pinyin ?? '';
  2046. }
  2047. if (isset($good->city_id) && !empty($good->city_id)) {
  2048. $city = District::where('id', $good->city_id)->first(['name']);
  2049. $good->city_name = $city->name ?? '';
  2050. }
  2051. // 解析imgurl JSON并取第一条数据
  2052. $imgUrls = json_decode($good->imgurl, true);
  2053. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2054. $good->pinyin = $pinyin;
  2055. return $good;
  2056. });
  2057. }
  2058. /**
  2059. * 获取商城首页-根据栏目id
  2060. * @param array $data
  2061. * @return array
  2062. * */
  2063. function getWebsiteCatidshop(array $data): array
  2064. {
  2065. $input['catid'] = $data['catid'];
  2066. $input['website_id'] = $data['website_id'];
  2067. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2068. $result = array_map(function ($item) use ($input) {
  2069. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2070. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2071. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2072. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2073. if (empty($category) || $category->type != 2) {
  2074. return Result::error("暂无此栏目", 0);
  2075. } else {
  2076. $website['website_id'] = $input['website_id'];
  2077. $goods = Good::where('good.status', 2)
  2078. ->where('good.website_id', $website['website_id'])
  2079. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2080. ->select(
  2081. 'good.id',
  2082. 'good.name',
  2083. 'good.imgurl',
  2084. 'good.description',
  2085. 'good.updated_at',
  2086. 'good.catid',
  2087. 'good.type_id',
  2088. 'good.price',
  2089. 'good.com',
  2090. 'good.level',
  2091. 'good.unit'
  2092. )
  2093. ->orderBy('updated_at', 'desc')
  2094. ->offset($goodStart)
  2095. ->limit($goodNum);
  2096. $all_goods = $goods->get();
  2097. $all_goods = $this->processGoods($all_goods, $website);
  2098. }
  2099. return $all_goods ?? [];
  2100. }
  2101. }, $data);
  2102. return Result::success($result);
  2103. }
  2104. /**
  2105. * 获取商品模块
  2106. * @param array $data
  2107. * @return array
  2108. * */
  2109. public function getWebsiteshop(array $data): array
  2110. {
  2111. $input['id'] = $data['id'];
  2112. $input['website_id'] = $data['website_id'];
  2113. $catid = $data['catid'];
  2114. $data = json_decode($input['id'] ?? '', true) ?? [];
  2115. $result['goods'] = array_map(function ($item) use ($input) {
  2116. // 检查parent元素是否存在且不是undefined
  2117. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2118. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2119. $website = $input['website_id'];
  2120. $query = Good::where('good.status', 2)
  2121. ->where('good.website_id', $website);
  2122. switch ($Levelid) {
  2123. case 1:
  2124. case 2:
  2125. case 3:
  2126. $goods = $query->where(function ($q) use ($Levelid) {
  2127. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2128. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2129. });
  2130. break;
  2131. case 4:
  2132. $goods = $query;
  2133. break;
  2134. case 5:
  2135. $goods = $query->where('type_id', 1);
  2136. break;
  2137. case 6:
  2138. $goods = $query->where('type_id', 2);
  2139. break;
  2140. default:
  2141. return [];
  2142. }
  2143. $all_goods = $goods
  2144. ->select(
  2145. 'good.id',
  2146. 'good.name',
  2147. 'good.imgurl',
  2148. 'good.description',
  2149. 'good.updated_at',
  2150. 'good.catid',
  2151. 'good.type_id',
  2152. 'good.price',
  2153. 'good.level',
  2154. 'good.website_id'
  2155. )
  2156. ->orderBy('updated_at', 'desc')
  2157. ->offset($goodStart)
  2158. ->limit($goodNum)
  2159. ->get();
  2160. $web['website_id'] = $website;
  2161. $all_goods = $this->processGoods($all_goods, $web);
  2162. }
  2163. return $all_goods;
  2164. }, $data);
  2165. $website = $input['website_id'];
  2166. $result['article'] = Article::where(function ($query) use ($website) {
  2167. $query->where(function ($subQuery) use ($website) {
  2168. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2169. })->orWhereNull("ignore_ids");
  2170. })
  2171. ->where('catid', $catid)
  2172. ->where('article.status', 1)
  2173. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2174. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2175. ->orderBy('article.updated_at', 'desc')
  2176. ->first();
  2177. return Result::success($result);
  2178. }
  2179. /**
  2180. * 获取商品分类
  2181. * @param array $data
  2182. * @return array
  2183. * */
  2184. public function getWebsiteshopCat(array $data): array
  2185. {
  2186. $website = $data['website_id'];
  2187. $category = WebsiteCategory::where('website_id', $website)
  2188. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2189. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2190. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2191. ->orderBy('sort')
  2192. ->get();
  2193. $cat = $category->map(function ($item) use ($website) {
  2194. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2195. $pid = $item->pid ?? 0;
  2196. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2197. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2198. ->where('website_id', $website)
  2199. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2200. ->get(['aLIas_pinyin'])
  2201. ->pluck('aLIas_pinyin')
  2202. ->implode('/');
  2203. } else {
  2204. $pinyin = $item->aLIas_pinyin ?? '';
  2205. }
  2206. $item->pinyin = $pinyin;
  2207. });
  2208. if (empty($category)) {
  2209. return Result::error("栏目查询失败", 0);
  2210. }
  2211. $cat_tree = Result::buildMenuTree($category);
  2212. $web['website_id'] = $website;
  2213. $goods = Good::where('website_id', $website)
  2214. ->where('status', 2)
  2215. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2216. ->latest('updated_at')
  2217. ->offset(($data['page'] - 1) * $data['pageSize'])
  2218. ->limit($data['pageSize'])
  2219. ->get();
  2220. if (!empty($goods)) {
  2221. if ($goods->count() > 1 && !empty($goods)) {
  2222. $goods = $this->processGoods($goods, $web);
  2223. }
  2224. } else {
  2225. $goods = [];
  2226. }
  2227. $result = [
  2228. 'category' => $cat_tree,
  2229. 'goods' => $goods,
  2230. ];
  2231. // $resul['goods'] = $goods;
  2232. if (empty($result)) {
  2233. return Result::error("查询失败", 0);
  2234. }
  2235. return Result::success($result);
  2236. }
  2237. /*
  2238. * 获取商品列表
  2239. * @param array $data
  2240. * @return array
  2241. * */
  2242. public function getWebsiteshopList(array $data): array
  2243. {
  2244. // return Result::success($data);
  2245. $where = [
  2246. 'status' => 2,
  2247. 'website_id' => $data['website_id'],
  2248. ];
  2249. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2250. // return Result::error("查询失败", 0);
  2251. // }
  2252. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2253. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2254. $data['catid'] = $category->category_id ?? 0;
  2255. }
  2256. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2257. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2258. }
  2259. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2260. array_push($where, ['type_id', $data['type_id']]);
  2261. }
  2262. $query = Good::where($where)
  2263. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2264. $query->where(function ($q) use ($data) {
  2265. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2266. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2267. });
  2268. })
  2269. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2270. $query->where(function ($q) use ($data) {
  2271. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2272. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2273. });
  2274. })
  2275. ->select(
  2276. 'good.id',
  2277. 'good.name',
  2278. 'good.imgurl',
  2279. 'good.description',
  2280. 'good.updated_at',
  2281. 'good.com',
  2282. 'good.catid',
  2283. 'good.type_id',
  2284. 'good.website_id',
  2285. 'good.cat_arr_id',
  2286. 'good.created_at',
  2287. 'good.city_id'
  2288. )
  2289. ->latest('updated_at');
  2290. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2291. $result['count'] = $query->clone()->count();
  2292. $result['goods'] = $this->processGoods(
  2293. $query->clone()
  2294. ->offset(($data['page'] - 1) * $data['pageSize'])
  2295. ->limit($data['pageSize'])
  2296. ->get(),
  2297. $data
  2298. );
  2299. } else {
  2300. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2301. // 获取 type_id 为 1 的数据
  2302. $result['type1'] = $this->processGoods(
  2303. $query->clone()
  2304. ->where('type_id', 1)
  2305. ->offset(($data['page'] - 1) * $data['pageSize'])
  2306. ->limit($data['pageSize'])
  2307. ->get(),
  2308. $data
  2309. );
  2310. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2311. // 获取 type_id 为 2 的数据
  2312. $result['type2'] = $this->processGoods(
  2313. $query->clone()
  2314. ->where('type_id', 2)
  2315. ->offset(($data['page'] - 1) * $data['pageSize'])
  2316. ->limit($data['pageSize'])
  2317. ->get(),
  2318. $data
  2319. );
  2320. }
  2321. if (empty($result)) {
  2322. return Result::error("查询失败", 0);
  2323. }
  2324. return Result::success($result);
  2325. }
  2326. /**
  2327. * 获取商品详情
  2328. * @param array $data
  2329. * @return array
  2330. * */
  2331. public function getWebsiteshopInfo(array $data): array
  2332. {
  2333. $where = [
  2334. 'good.status' => 2,
  2335. 'good.website_id' => $data['website_id'],
  2336. 'good.id' => $data['id'],
  2337. ];
  2338. $goods = Good::where($where)
  2339. ->where('good.id', $data['id'])
  2340. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2341. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2342. ->first();
  2343. if (empty($goods)) {
  2344. return Result::error("查询失败", 0);
  2345. }
  2346. $goods->imgurl = json_decode($goods->imgurl, true);
  2347. return Result::success($goods);
  2348. }
  2349. /**
  2350. * plus pro 处理文章路由问题
  2351. */
  2352. function processArticlePro($website_id)
  2353. {
  2354. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2355. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2356. // // 取出category_id 对应的aLIas_pinyin
  2357. // $categoryIds = array_column($categorys, 'category_id');
  2358. // $categoryPIds = array_column($categorys, 'pid');
  2359. // $aliasPinyins = array_column($categorys, 'path');
  2360. // $alias = array_column($categorys, 'alias');
  2361. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2362. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2363. // // return Result::success($cat_arr);
  2364. // // $catiall = [];
  2365. // //一级所有子级的记录
  2366. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2367. // return [
  2368. // 'cat_1st_arr' => $cat_alias_arr,
  2369. // 'catiall' => $cat_arr,
  2370. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2371. // 'categoryIds' => $categoryIds,
  2372. // ];
  2373. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2374. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2375. // 取出category_id 对应的aLIas_pinyin
  2376. $categoryIds = array_column($categorys, 'category_id');
  2377. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function($pid) {
  2378. return $pid != 0;
  2379. })));
  2380. $category_path = array_column($categorys, 'path');
  2381. $cat_arr = array_combine($categoryIds, $category_path);
  2382. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2383. $catiall = [];
  2384. //一级所有子级的记录
  2385. $cat_1st_arr = [];
  2386. foreach ($categorys as $key => $value) {
  2387. // $category_arr_id = json_decode($value->category_arr_id);
  2388. // $pinyin_str = '';
  2389. // // 算出一级 并且算出子级
  2390. if ($value->pid != 0 && in_array($value->pid,$categoryIds)) {
  2391. $cat_1st_arr[$value->pid][] = $value->category_id;
  2392. }
  2393. // foreach ($category_arr_id as $k => $v) {
  2394. // $pinyin_str .= $cat_arr[$v] . '/';
  2395. // }
  2396. // $pinyin_str = rtrim($pinyin_str, '/');
  2397. $catiall[$value->category_id]['alias'] = $value->alias;
  2398. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2399. $catiall[$value->category_id]['type'] = $value->type;
  2400. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2401. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2402. }
  2403. return [
  2404. 'cat_1st_arr' => $cat_1st_arr,
  2405. 'catiall' => $catiall,
  2406. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2407. 'categoryIds' => $categoryIds,
  2408. 'diff_pid_categoryIds' => array_diff($categoryPIds,$categoryIds),
  2409. 'categoryPIds' => $categoryPIds,
  2410. ];
  2411. }
  2412. /**
  2413. * 封装处理文章的路由问题
  2414. * */
  2415. function processArticles($articles, $data)
  2416. {
  2417. // 检查 $articles 是否为数组或可迭代对象
  2418. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2419. return $articles->map(function ($article) use ($data) {
  2420. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2421. $catid = $article->cat_arr_id ?? '';
  2422. }
  2423. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2424. $catid = $article->category_arr_id ?? '';
  2425. }
  2426. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2427. $level = json_decode($catid, true);
  2428. if (!is_array($level)) {
  2429. return $article;
  2430. } else {
  2431. $level = array_map('intval', $level);
  2432. }
  2433. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2434. ->where($data)
  2435. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2436. ->pluck('aLIas_pinyin')
  2437. ->implode('/');
  2438. $article->pinyin = $pinyin ?? '';
  2439. return $article;
  2440. });
  2441. } else {
  2442. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2443. $catid = $articles->cat_arr_id ?? '';
  2444. $level = json_decode($catid, true);
  2445. if (!is_array($level)) {
  2446. return $articles;
  2447. } else {
  2448. $level = array_map('intval', $level);
  2449. }
  2450. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2451. ->where($data)
  2452. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2453. ->pluck('aLIas_pinyin')
  2454. ->implode('/');
  2455. $articles->pinyin = $pinyin ?? '';
  2456. return $articles;
  2457. }
  2458. }
  2459. // 封装处理由问题
  2460. function processJob($job, $data)
  2461. {
  2462. return $job->map(function ($job) use ($data) {
  2463. $category = $job->cat_arr_id ?? '';
  2464. $cityid = $job->city_arr_id ?? '';
  2465. $city = json_decode($cityid, true);
  2466. $pinyin = '';
  2467. $level = json_decode($category, true);
  2468. // 路由
  2469. if (!empty($level) && is_array($level)) {
  2470. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2471. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2472. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2473. ->get(['aLIas_pinyin'])
  2474. ->pluck('aLIas_pinyin')
  2475. ->implode('/');
  2476. if (empty($pinyin)) {
  2477. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2478. }
  2479. $job->pinyin = $pinyin;
  2480. }
  2481. // 取职位-城市 市??省
  2482. if (!empty($city) && is_array($city)) {
  2483. if (isset($city[1]) && !empty($city[1])) {
  2484. $city = District::where('id', $city[1])->first(['name']);
  2485. $job->city_name = $city->name ?? '';
  2486. } else if (isset($city[0]) && !empty($city[0])) {
  2487. $city = District::where('id', $city[0])->first(['name']);
  2488. $job->city_name = $city->name ?? '';
  2489. } else {
  2490. $job->city_name = '全国';
  2491. }
  2492. }
  2493. // 获取简历最后一级地区
  2494. if (isset($job->city_id) && !empty($job->city_id)) {
  2495. $city = District::where('id', $job->city_id)->first(['name']);
  2496. $job->hunt_cityname = $city->name ?? '';
  2497. }
  2498. // 组合详细地址
  2499. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2500. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2501. if (is_array($address_id) && !empty($address_id)) {
  2502. $address = District::whereIn('id', $address_id)
  2503. ->orderBy('level', 'asc')
  2504. ->get(['name'])
  2505. ->pluck('name')
  2506. ->implode('');
  2507. // $job->address_name = $address ?? '';
  2508. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2509. }
  2510. }
  2511. // 取行业
  2512. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2513. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2514. if (!empty($job->industry)) {
  2515. $query->where('hyid', $job->industry);
  2516. } else if (!empty($job->hy_id)) {
  2517. $query->where('hyid', $job->hy_id);
  2518. } else if (!empty($job->company_hy_id)) {
  2519. $query->where('hyid', $job->company_hy_id);
  2520. } else {
  2521. $query->where('hyid', $job->job_industry);
  2522. }
  2523. })->first(['hyname']);
  2524. $job->hy_name = $hy_name->hyname ?? '';
  2525. }
  2526. // 取职位类别
  2527. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2528. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2529. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2530. $job->zw_name = $zw_name->zwname ?? '';
  2531. }
  2532. // 取具体职位
  2533. 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))) {
  2534. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2535. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2536. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2537. }
  2538. // 取工作经验
  2539. if (isset($job->experience) && !empty($job->experience)) {
  2540. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2541. $job->experience_name = $experience->ename ?? '';
  2542. }
  2543. // 取学历
  2544. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2545. $education = $job->educational ?? $job->school_education;
  2546. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2547. $job->education_name = $education->ename ?? '';
  2548. }
  2549. // 语言
  2550. if (isset($job->language) && !empty($job->language)) {
  2551. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2552. $job->language_name = $language->ename ?? '';
  2553. }
  2554. // 薪资
  2555. if (isset($job->salary) && !empty($job->salary)) {
  2556. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2557. $job->salary_name = $salary->ename ?? '';
  2558. }
  2559. // 职位性质
  2560. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2561. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2562. $job->job_nature_name = $job_nature->ename ?? '';
  2563. }
  2564. // 公司规模
  2565. if (isset($job->company_size) && !empty($job->company_size)) {
  2566. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2567. $job->company_size_name = $company_size->ename ?? '';
  2568. }
  2569. // 公司性质
  2570. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2571. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2572. $job->company_nature_name = $company_nature->nature_name ?? '';
  2573. }
  2574. // $job->pinyin = $pinyin;
  2575. return $job;
  2576. });
  2577. }
  2578. /**
  2579. * 获取书籍模块
  2580. * @param array $data
  2581. * @return array
  2582. * */
  2583. public function getWebsiteBook(array $data): array
  2584. {
  2585. $input['id'] = $data['id'];
  2586. $input['website_id'] = $data['website_id'];
  2587. // 将 JSON 字符串转换为 PHP 数组
  2588. $data = json_decode($input['id'], true);
  2589. // 使用 array_map 处理每个元素
  2590. $result = array_map(function ($item) use ($input) {
  2591. // 检查parent元素是否存在且不是undefined
  2592. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2593. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2594. $website = [
  2595. 'website_id' => $input['website_id'],
  2596. ];
  2597. // 查询栏目名称
  2598. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2599. if (empty($category)) {
  2600. $parent_alias = '';
  2601. $parent_pinyin = null;
  2602. $imgBooks = [];
  2603. $textBooks = [];
  2604. } else {
  2605. $parent_alias = $category->alias ?? '';
  2606. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2607. // 查找子分类ID数组
  2608. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2609. array_push($childCategoryIds, $parentCatId);
  2610. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2611. if ($parentImgNum != 0) {
  2612. // 查询图片新闻
  2613. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2614. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2615. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2616. })
  2617. ->where('book.status', 2)
  2618. ->where('book.img_url', '!=', '')
  2619. ->where('book.website_id', $website['website_id'])
  2620. ->leftJoin('website_category', function ($join) use ($website) {
  2621. $join->on('book.cat_id', '=', 'website_category.category_id')
  2622. ->where('website_category.website_id', '=', $website['website_id']);
  2623. })
  2624. ->select(
  2625. 'book.id',
  2626. 'book.title',
  2627. 'book.img_url',
  2628. 'book.price',
  2629. 'book.market_price',
  2630. 'book.description',
  2631. 'book.cat_id',
  2632. 'book.description',
  2633. 'book.updated_at',
  2634. 'website_category.alias as category_name',
  2635. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2636. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2637. )
  2638. ->orderBy('updated_at', 'desc')
  2639. ->limit($parentImgNum)
  2640. ->get()->all();
  2641. // 查询文字新闻
  2642. }
  2643. if ($parentTextNum != 0) {
  2644. $textBooks = [];
  2645. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2646. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2647. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2648. })
  2649. ->where('book.status', 2)
  2650. ->where('book.website_id', $website['website_id'])
  2651. ->leftJoin('website_category', function ($join) use ($website) {
  2652. $join->on('book.cat_id', '=', 'website_category.category_id')
  2653. ->where('website_category.website_id', '=', $website['website_id']);
  2654. })
  2655. ->select(
  2656. 'book.id',
  2657. 'book.title',
  2658. 'book.img_url',
  2659. 'book.price',
  2660. 'book.market_price',
  2661. 'book.description',
  2662. 'book.cat_id',
  2663. 'book.description',
  2664. 'book.updated_at',
  2665. 'website_category.alias as category_name',
  2666. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2667. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2668. )
  2669. ->orderBy('updated_at', 'desc')
  2670. ->limit($parentTextNum)
  2671. ->get()->all();
  2672. }
  2673. }
  2674. }
  2675. $resultItem = [
  2676. 'alias' => $parent_alias ?? '',
  2677. 'category_id' => $parentCatId ?? 0,
  2678. 'pinyin' => $parent_pinyin ?? null,
  2679. 'imgnum' => $imgBooks ?? [],
  2680. 'textnum' => $textBooks ?? [],
  2681. ];
  2682. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2683. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2684. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2685. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2686. ->get()->all();
  2687. if (!empty($childCategory)) {
  2688. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2689. // 查询子栏目名称
  2690. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2691. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2692. ->first();
  2693. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2694. $childImgArticles = [];
  2695. $childTextArticles = [];
  2696. $resultItem['child'] = [];
  2697. } else {
  2698. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2699. // 查询子栏目图片新闻
  2700. $childImgArticles = Book::where('cat_id', $childCatId)
  2701. ->where('status', 2)
  2702. ->where('img_url', '!=', '')
  2703. ->where('book.website_id', $website['website_id'])
  2704. ->leftJoin('website_category', function ($join) use ($website) {
  2705. $join->on('book.cat_id', '=', 'website_category.category_id')
  2706. ->where('website_category.website_id', '=', $website['website_id']);
  2707. })
  2708. ->select(
  2709. 'book.id',
  2710. 'book.title',
  2711. 'book.img_url',
  2712. 'book.price',
  2713. 'book.market_price',
  2714. 'book.description',
  2715. 'book.cat_id',
  2716. 'book.description',
  2717. 'book.updated_at',
  2718. DB::raw("'$child_pinyin' as pinyin")
  2719. )
  2720. ->orderBy('updated_at', 'desc')
  2721. ->limit($childImgNum)
  2722. ->get()->all();
  2723. // 查询子栏目文字新闻
  2724. $childTextArticles = Book::where('cat_id', $childCatId)
  2725. ->where('status', 2)
  2726. ->where('book.website_id', $website['website_id'])
  2727. ->leftJoin('website_category', function ($join) use ($website) {
  2728. $join->on('book.cat_id', '=', 'website_category.category_id')
  2729. ->where('website_category.website_id', '=', $website['website_id']);
  2730. })
  2731. ->select(
  2732. 'book.id',
  2733. 'book.title',
  2734. 'book.img_url',
  2735. 'book.price',
  2736. 'book.market_price',
  2737. 'book.description',
  2738. 'book.cat_id',
  2739. 'book.description',
  2740. 'book.updated_at',
  2741. DB::raw("'$child_pinyin' as pinyin")
  2742. )
  2743. ->orderBy('updated_at', 'desc')
  2744. ->limit($childTextNum)
  2745. ->get()->all();
  2746. $resultItem['child'] = [
  2747. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2748. 'category_id' => $childCatId,
  2749. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2750. 'all_childcat' => $childCategory,
  2751. 'imgnum' => $childImgArticles,
  2752. 'textnum' => $childTextArticles,
  2753. ];
  2754. }
  2755. }
  2756. } else {
  2757. $resultItem['child'] = [];
  2758. }
  2759. return $resultItem;
  2760. }, $data);
  2761. return Result::success($result);
  2762. }
  2763. /**
  2764. * 获取书刊列表
  2765. * @param array $data
  2766. * @return array
  2767. * */
  2768. public function getWebsiteBookList(array $data): array
  2769. {
  2770. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2771. if (empty($web)) {
  2772. return Result::error("查询失败", 0);
  2773. }
  2774. $catid = $data['id'];
  2775. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2776. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2777. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2778. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2779. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2780. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2781. ->where('pid', $category['pid'])
  2782. ->select(
  2783. 'category_id',
  2784. 'alias',
  2785. 'aLIas_pinyin',
  2786. 'pid',
  2787. 'sort',
  2788. 'is_url',
  2789. 'web_url',
  2790. 'seo_title',
  2791. 'seo_keywords',
  2792. 'seo_description',
  2793. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2794. )
  2795. ->orderBy('sort')
  2796. ->get()->all();
  2797. if (empty($category)) {
  2798. return Result::error("查询失败", 0);
  2799. }
  2800. $query = Book::where('book.status', 2)
  2801. ->where('book.website_id', $data['website_id'])
  2802. ->where('book.cat_id', $catid)
  2803. ->select(
  2804. 'book.id',
  2805. 'book.title',
  2806. 'book.img_url',
  2807. 'book.description',
  2808. 'book.updated_at',
  2809. 'book.cat_id',
  2810. DB::raw("'$pinyin' as pinyin")
  2811. )
  2812. ->orderBy('book.updated_at', 'desc');
  2813. $count = $query->count();
  2814. $query = clone $query;
  2815. $Book = $query
  2816. ->limit($data['pageSize'])
  2817. ->offset(($data['page'] - 1) * $data['pageSize'])
  2818. ->get()->all();
  2819. $result = [
  2820. 'category' => $categorys,
  2821. 'books' => $Book,
  2822. 'count' => $count,
  2823. ];
  2824. // if(empty($result)){
  2825. // return Result::error("查询失败", 0);
  2826. // }
  2827. return Result::success($result);
  2828. }
  2829. /**
  2830. * 获取书刊详情
  2831. * @param array $data
  2832. * @return array
  2833. * */
  2834. public function getWebsiteBookInfo(array $data): array
  2835. {
  2836. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2837. if (empty($web)) {
  2838. return Result::error("查询失败", 0);
  2839. }
  2840. $book = Book::where('status', 2)
  2841. ->where('website_id', $data['website_id'])
  2842. ->where('id', $data['id'])
  2843. ->select(
  2844. 'book.*',
  2845. )
  2846. ->orderBy('updated_at', 'desc')
  2847. ->first();
  2848. if (empty($book)) {
  2849. return Result::error("查询失败", 0);
  2850. }
  2851. // 先查询当前分类的 pid
  2852. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2853. ->where('category_id', $book['cat_id'])
  2854. ->first(['pid', 'category_id']);
  2855. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2856. if (!empty($carpid)) {
  2857. if ($carpid->pid != 0) {
  2858. $pid = $carpid['pid'];
  2859. // $parent_pinyin = '';
  2860. } else {
  2861. $pid = $carpid['category_id'];
  2862. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2863. }
  2864. }
  2865. $categorys = $query->where('pid', $pid)
  2866. ->select(
  2867. 'category_id',
  2868. 'alias',
  2869. 'aLIas_pinyin',
  2870. 'pid',
  2871. 'sort',
  2872. 'is_url',
  2873. 'web_url',
  2874. 'category_arr_id as cat_arr_id',
  2875. )
  2876. ->orderBy('sort')
  2877. ->get();
  2878. $category = $this->processArticle($categorys, $data);
  2879. $result = [
  2880. 'category' => $category,
  2881. 'books' => $book,
  2882. ];
  2883. return Result::success($result);
  2884. }
  2885. /**
  2886. * 尝试
  2887. * @param array $data
  2888. * @return array
  2889. * */
  2890. public function test(array $data): array
  2891. {
  2892. $input['id'] = $data['id'];
  2893. $input['website_id'] = $data['website_id'];
  2894. // 将 JSON 字符串转换为 PHP 数组
  2895. $data = json_decode($input['id'], true);
  2896. $result = [];
  2897. $article = $data;
  2898. $result = array_map(function ($item) use ($input) {
  2899. $website = [
  2900. 'website_id' => $input['website_id'],
  2901. ];
  2902. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2903. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2904. $parent = [
  2905. 0 => $category['category_id'] ?? [],
  2906. 1 => $parentImgNum ?? [],
  2907. 2 => $parentTextNum ?? [],
  2908. ];
  2909. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2910. $child = [];
  2911. $resultItem = [
  2912. // 'alias' => $parent_alias ?? '',
  2913. 'category_id' => $parentCatId ?? 0,
  2914. 'pinyin' => $parentImgNum ?? null,
  2915. 'imgnum' => $parentTextNum ?? [],
  2916. // 'textnum' => $textArticles ?? [],
  2917. ];
  2918. return $parent;
  2919. }, $data);
  2920. return Result::success($result);
  2921. // });
  2922. }
  2923. /**
  2924. * 封装处理文章的路由问题
  2925. * */
  2926. function processArticle($article, $data)
  2927. {
  2928. return $article->map(function ($article) use ($data) {
  2929. $catid = $article->cat_arr_id ?? '';
  2930. $level = json_decode($catid, true);
  2931. $pinyin = '';
  2932. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2933. if (!empty($level) && is_array($level)) {
  2934. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2935. ->where('website_id', $data['website_id'])
  2936. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2937. ->get(['aLIas_pinyin'])
  2938. ->pluck('aLIas_pinyin')
  2939. ->implode('/');
  2940. } else {
  2941. $pinyin = '';
  2942. }
  2943. $article->pinyin = $pinyin;
  2944. return $article;
  2945. });
  2946. }
  2947. /**
  2948. * c端-获取招工招聘下拉选框
  2949. * @param array $data
  2950. * @return array
  2951. * */
  2952. public function getWebsiteJobSelect(array $data): array
  2953. {
  2954. $web = Website::where('id', $data['website_id'])->first();
  2955. if (empty($web)) {
  2956. return Result::error("该网站不存在", 0);
  2957. }
  2958. $hy = JobIndustry::get()->all();
  2959. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2960. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2961. $result = [
  2962. 'hy' => $hy,
  2963. 'zw' => $zw,
  2964. 'jtzw' => $jtzw,
  2965. ];
  2966. if (empty($result)) {
  2967. return Result::error("查询失败", 0);
  2968. }
  2969. return Result::success($result);
  2970. }
  2971. /**
  2972. * c端-获取招工招聘
  2973. * @param array $data
  2974. * @return array
  2975. * */
  2976. public function getWebsiteJob(array $data): array
  2977. {
  2978. $web = Website::where('id', $data['website_id'])->first();
  2979. if (empty($web)) {
  2980. return Result::error("该网站不存在", 0);
  2981. }
  2982. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2983. ->where('job_hunting.website_id', $data['website_id'])
  2984. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2985. $query->where(function ($q) use ($data) {
  2986. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2987. });
  2988. })
  2989. ->select(
  2990. 'job_hunting.id',
  2991. 'job_hunting.catid',
  2992. 'job_hunting.cat_arr_id',
  2993. 'job_hunting.job_name_get',
  2994. 'job_hunting.industry',
  2995. 'job_hunting.name',
  2996. 'job_hunting.sexy',
  2997. 'job_hunting.origin',
  2998. 'job_hunting.city_arr_id',
  2999. 'job_hunting.experience',
  3000. 'job_hunting.updated_at',
  3001. 'job_hunting.salary',
  3002. 'job_hunting.skillList',
  3003. 'job_hunting.slelf_evaluation',
  3004. )
  3005. ->orderBy('updated_at', 'desc')
  3006. ->limit($data['job1_num'])
  3007. ->get();
  3008. $web['website_id'] = $data['website_id'];
  3009. if (empty($job_hunting)) {
  3010. $job_huntings = "未查询到相关简历信息";
  3011. } else {
  3012. $job_huntings = $this->processJob($job_hunting, $web);
  3013. }
  3014. // 0:待审核 1:已通过 2:已拒绝
  3015. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3016. ->where('job_recruiting.website_id', $data['website_id'])
  3017. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3018. $query->where(function ($q) use ($data) {
  3019. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3020. });
  3021. })
  3022. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3023. ->select(
  3024. 'job_recruiting.id',
  3025. 'job_recruiting.catid',
  3026. 'job_recruiting.cat_arr_id',
  3027. 'job_recruiting.title',
  3028. 'job_recruiting.jtzw_id',
  3029. 'job_recruiting.hy_id',
  3030. 'job_recruiting.city_arr_id',
  3031. 'job_recruiting.due_data',
  3032. 'job_recruiting.updated_at',
  3033. 'job_recruiting.experience',
  3034. 'job_recruiting.educational',
  3035. 'job_recruiting.salary',
  3036. 'job_recruiting.zw_id',
  3037. 'job_company.business_name',
  3038. 'job_recruiting.keyword',
  3039. 'job_recruiting.description',
  3040. 'job_recruiting.seo_description',
  3041. )
  3042. ->orderBy('updated_at', 'desc')
  3043. ->limit($data['job2_num'])
  3044. ->get();
  3045. if (empty($job_recruiting->toArray())) {
  3046. $job_recruitings = "未查询到相关职位信息";
  3047. } else {
  3048. $job_recruitings = $this->processJob($job_recruiting, $web);
  3049. }
  3050. $result = [
  3051. 'job_hunting' => $job_huntings,
  3052. 'job_recuiting' => $job_recruitings,
  3053. ];
  3054. return Result::success($result);
  3055. }
  3056. /**
  3057. * c端-获取招工招聘列表
  3058. * @param array $data
  3059. * @return array
  3060. * */
  3061. public function getWebsiteJobList(array $data): array
  3062. {
  3063. $recruit_where = [];
  3064. $hunt_where = [];
  3065. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3066. if (empty($web)) {
  3067. return Result::error("此网站不存在", 0);
  3068. }
  3069. $website_id['website_id'] = $data['website_id'];
  3070. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3071. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3072. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3073. }
  3074. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3075. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3076. }
  3077. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3078. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3079. }
  3080. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3081. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3082. }
  3083. $query = JobRecruiting::where('job_recruiting.status', 1)
  3084. ->where('job_recruiting.website_id', $data['website_id'])
  3085. ->where($recruit_where)
  3086. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3087. $query->where(function ($q) use ($data) {
  3088. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3089. });
  3090. })
  3091. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3092. $query->where(function ($q) use ($data) {
  3093. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3094. });
  3095. })
  3096. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3097. ->select(
  3098. 'job_recruiting.id',
  3099. 'job_recruiting.catid',
  3100. 'job_recruiting.hy_id',
  3101. 'job_recruiting.title',
  3102. 'job_recruiting.zw_id',
  3103. 'job_recruiting.educational',
  3104. 'job_recruiting.jtzw_id',
  3105. 'job_recruiting.city_arr_id',
  3106. 'job_recruiting.due_data',
  3107. 'job_recruiting.experience',
  3108. 'job_recruiting.cat_arr_id',
  3109. 'job_recruiting.updated_at',
  3110. 'job_company.business_name',
  3111. 'job_recruiting.keyword',
  3112. 'job_recruiting.description',
  3113. 'job_recruiting.seo_description',
  3114. )
  3115. ->orderBy('job_recruiting.updated_at', 'desc');
  3116. $recruit_count = $query->count();
  3117. $query = clone $query;
  3118. $JobRecruiting = $query
  3119. ->offset(($data['page'] - 1) * $data['pageSize'])
  3120. ->limit($data['pageSize'])
  3121. ->get();
  3122. if (empty($JobRecruiting)) {
  3123. $JobRecruiting = "暂无相关职位信息";
  3124. } else {
  3125. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3126. }
  3127. }
  3128. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3129. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3130. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3131. }
  3132. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3133. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3134. }
  3135. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3136. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3137. }
  3138. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3139. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3140. }
  3141. $query = JobHunting::where('job_hunting.status', 2)
  3142. ->where('job_hunting.website_id', $data['website_id'])
  3143. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3144. ->where($hunt_where)
  3145. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3146. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3147. // })
  3148. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3149. $query->where(function ($q) use ($data) {
  3150. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3151. });
  3152. })
  3153. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3154. $query->where(function ($q) use ($data) {
  3155. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3156. });
  3157. })
  3158. ->select(
  3159. 'job_hunting.id',
  3160. 'job_hunting.catid',
  3161. 'job_hunting.sexy',
  3162. 'job_hunting.experience',
  3163. 'job_hunting.origin',
  3164. 'job_hunting.industry',
  3165. 'job_hunting.name',
  3166. 'job_hunting.job',
  3167. 'job_hunting.job_name_get',
  3168. 'job_hunting.city_arr_id',
  3169. 'job_hunting.cat_arr_id',
  3170. 'job_hunting.created_at',
  3171. 'job_hunting.updated_at',
  3172. 'job_position.zwname as job_name',
  3173. 'job_hunting.skillList',
  3174. 'job_hunting.slelf_evaluation',
  3175. )
  3176. ->orderBy('job_hunting.updated_at', 'desc');
  3177. $hunt_count = $query->count();
  3178. $query = clone $query;
  3179. $JobHunting = $query
  3180. ->offset(($data['page'] - 1) * $data['pageSize'])
  3181. ->limit($data['pageSize'])
  3182. ->get();
  3183. if (empty($JobHunting)) {
  3184. $JobRecruiting = "暂无相关简历信息";
  3185. } else {
  3186. $JobHunting = $this->processJob($JobHunting, $website_id);
  3187. }
  3188. }
  3189. $result = [
  3190. 'JobRecruiting' => $JobRecruiting ?? [],
  3191. 'recruit_count' => $recruit_count ?? 0,
  3192. 'JobHunting' => $JobHunting ?? [],
  3193. 'hunt_count' => $hunt_count ?? 0,
  3194. ];
  3195. return Result::success($result);
  3196. }
  3197. /**
  3198. * c端-获取招工招聘详情
  3199. * @param array $data
  3200. * @return array
  3201. * */
  3202. public function getWebsiteJobInfo(array $data): array
  3203. {
  3204. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3205. if (empty($web)) {
  3206. return Result::error("该网站不存在", 0);
  3207. }
  3208. $webid = [
  3209. 'website_id' => $data['website_id'],
  3210. ];
  3211. // 职位相关信息
  3212. if ($data['type'] == 1) {
  3213. $query = JobRecruiting::where('status', 1)
  3214. ->where('website_id', $data['website_id'])
  3215. ->select('*');
  3216. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3217. $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();
  3218. if (!empty($company)) {
  3219. $result['company'] = $this->processJob($company, $webid);
  3220. }
  3221. $other_job = JobRecruiting::where('status', 1)
  3222. ->where('website_id', $data['website_id'])
  3223. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3224. ->where('id', '!=', $data['id'])
  3225. ->where('user_id', '=', $job[0]['user_id'])
  3226. ->limit($data['pageSize'])
  3227. ->get();
  3228. if (!empty($other_job)) {
  3229. $result['other_job'] = $this->processJob($other_job, $webid);
  3230. }
  3231. } else {
  3232. // 简历相关信息
  3233. $job = JobHunting::where('job_hunting.status', 2)
  3234. ->where('job_hunting.website_id', $data['website_id'])
  3235. ->where('job_hunting.id', $data['id'])
  3236. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3237. ->select('job_hunting.*', 'user_name')
  3238. ->get();
  3239. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3240. if (!empty($resume->toArray())) {
  3241. $result['resume'] = 1;
  3242. } else {
  3243. $result['resume'] = 0;
  3244. }
  3245. }
  3246. if (empty($job->toArray())) {
  3247. return Result::error("id参数错误", 0);
  3248. }
  3249. if (!empty($job[0]['job_experience'])) {
  3250. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3251. if (!empty($job_experience)) {
  3252. // $hy = [];
  3253. foreach ($job_experience as $key => $value) {
  3254. // $id = $value['id'];
  3255. $hy[$key] = $value['job_industry'];
  3256. $zw_id[$key] = $value['job_typename'];
  3257. $jtzw_id[$key] = $value['job_name'];
  3258. }
  3259. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3260. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3261. // 先将关联表转换为索引数组,提高查找效率
  3262. $hyLookup = [];
  3263. foreach ($hy_table as $item) {
  3264. $hyLookup[$item['hyid']] = $item['hyname'];
  3265. }
  3266. $zwLookup = [];
  3267. foreach ($zw_table as $item) {
  3268. $zwLookup[$item['zwid']] = $item['zwname'];
  3269. }
  3270. foreach ($job_experience as $key => &$value) {
  3271. // 处理行业名称
  3272. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3273. $value['hy_name'] = $hyLookup[$hy[$key]];
  3274. }
  3275. // 处理职位名称
  3276. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3277. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3278. }
  3279. // 处理具体职位名称
  3280. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3281. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3282. }
  3283. }
  3284. // 释放引用,防止意外修改后续代码
  3285. unset($value);
  3286. }
  3287. $result['job_experience'] = $job_experience ?? [];
  3288. }
  3289. if (!empty($job[0]['education_experience'])) {
  3290. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3291. if (!empty($education_experience)) {
  3292. foreach ($education_experience as $key => $value) {
  3293. // $id = $value['id'];
  3294. $education[$key] = $value['school_education'];
  3295. }
  3296. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3297. // // 先将关联表转换为索引数组,提高查找效率
  3298. $educationLookup = [];
  3299. foreach ($education_table as $item) {
  3300. $educationLookup[$item['evalue']] = $item['ename'];
  3301. }
  3302. foreach ($education_experience as $key => &$value) {
  3303. // 处理学历名称
  3304. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3305. $value['education_name'] = $educationLookup[$education[$key]];
  3306. }
  3307. }
  3308. }
  3309. $result['education_experience'] = $job_experience ?? [];
  3310. }
  3311. $result['job'] = $this->processJob($job, $webid);
  3312. // // 返现对应的栏目
  3313. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3314. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3315. ->whereIn('category_id', $catid)
  3316. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3317. ->orderBy('pid')->get()->all();
  3318. if (!empty($category)) {
  3319. $result['category'] = $category;
  3320. }
  3321. $result['job'] = $job;
  3322. $result['job_experience'] = $job_experience ?? [];
  3323. $result['education_experience'] = $education_experience ?? [];
  3324. if (empty($result)) {
  3325. return Result::error("参数错误", 0);
  3326. }
  3327. return Result::success($result);
  3328. }
  3329. /**
  3330. * c端-申请职位
  3331. * @param array $data
  3332. * @return array
  3333. * */
  3334. public function getWebsiteJobApply(array $data): array
  3335. {
  3336. // 首先验证网站是否存在
  3337. // return Result::success($data);
  3338. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3339. if (empty($web)) {
  3340. return Result::error("该网站不存在", 0);
  3341. }
  3342. // 验证用户是否存在且为个人会员/管理员
  3343. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3344. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3345. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3346. return Result::error("用户不存在", 0);
  3347. }
  3348. // 去除重复元素和空元素,并保持原始顺序
  3349. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3350. return !empty($value);
  3351. }));
  3352. // 验证职位是否存在 1:审核通过
  3353. $recruiting = JobRecruiting::where('status', 1)
  3354. ->where('website_id', $data['website_id'])
  3355. ->whereIn('id', $data['recruit_id'])
  3356. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3357. if (empty($recruiting)) {
  3358. return Result::error("该职位不存在", 0);
  3359. }
  3360. // 简历是否存在
  3361. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3362. if (empty($hunt_id)) {
  3363. return Result::error("该简历不存在", 0);
  3364. }
  3365. $data['hunt_id'] = $hunt_id['hunt_id'];
  3366. // // 验证是否已投递过该职位
  3367. $apply = JobApply::where('user_id', $data['user_id'])
  3368. ->where('hunt_id', $data['hunt_id'])
  3369. ->where('website_id', $data['website_id'])
  3370. ->whereIn('recruit_id', $data['recruit_id'])
  3371. ->get(['recruit_id']);
  3372. if (!empty($apply->toArray())) {
  3373. return Result::error("您已投递过该职位!");
  3374. }
  3375. $insertData = array_map(function ($recruiting) use ($data) {
  3376. return [
  3377. 'user_id' => $data['user_id'],
  3378. 'hunt_id' => $data['hunt_id'],
  3379. 'website_id' => $data['website_id'],
  3380. 'recruit_id' => $recruiting['recruit_id'],
  3381. 'receiver_id' => $recruiting['receiver_id'],
  3382. 'status' => 1,
  3383. ];
  3384. }, $recruiting);
  3385. // 批量插入数据
  3386. $result = JobApply::insert($insertData);
  3387. if (empty($result)) {
  3388. return Result::error("投递失败", 0);
  3389. }
  3390. return Result::success($result);
  3391. }
  3392. /**
  3393. * 招工招聘-沟通简历
  3394. * @param array $data
  3395. * @return array
  3396. * */
  3397. public function getWebsiteJobResume(array $data): array
  3398. {
  3399. // 首先验证网站是否存在
  3400. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3401. if (empty($web)) {
  3402. return Result::error("该网站不存在", 0);
  3403. }
  3404. // return Result::success($data);
  3405. // 验证用户是否存在且为企业会员/管理员
  3406. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3407. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3408. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3409. return Result::error("用户不存在", 0);
  3410. }
  3411. // 去除重复元素和空元素,并保持原始顺序
  3412. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3413. return !empty($value);
  3414. }));
  3415. // 验证简历是否存在
  3416. $hunting = JobHunting::where('status', 2)
  3417. ->where('website_id', $data['website_id'])
  3418. ->whereIn('id', $data['hunt_id'])
  3419. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3420. if (empty($hunting)) {
  3421. return Result::error("该简历不存在", 0);
  3422. }
  3423. // 验证是否已沟通过该简历
  3424. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3425. ->where('recruit_id', $data['recruit_id'])
  3426. ->where('website_id', $data['website_id'])
  3427. ->whereIn('hunt_id', $data['hunt_id'])
  3428. ->get(['hunt_id']);
  3429. if (!empty($remuse->toArray())) {
  3430. return Result::error("您已沟通过该简历!");
  3431. }
  3432. // 准备要插入的数据数组
  3433. $insertData = array_map(function ($hunting) use ($data) {
  3434. return [
  3435. 'user_id' => $data['user_id'],
  3436. 'recruit_id' => $data['recruit_id'],
  3437. 'website_id' => $data['website_id'],
  3438. 'hunt_id' => $hunting['hunt_id'],
  3439. 'receiver_id' => $hunting['receiver_id'],
  3440. 'status' => 1,
  3441. ];
  3442. }, $hunting);
  3443. // 批量插入数据
  3444. $result = JobRemuse::insert($insertData);
  3445. if (empty($result)) {
  3446. return Result::error("沟通失败", 0);
  3447. }
  3448. return Result::success($result);
  3449. }
  3450. /**
  3451. * 招工招聘 -我的职位(企业会员)
  3452. * @param array $data
  3453. * @return array
  3454. */
  3455. public function getWebsiteJobRecruiting(array $data): array
  3456. {
  3457. $web = Website::where('id', $data['website_id'])->first('id');
  3458. if (empty($web)) {
  3459. return Result::error("该网站不存在", 0);
  3460. }
  3461. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3462. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3463. return Result::error("用户暂无权限!", 0);
  3464. }
  3465. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3466. $result = JobRecruiting::where('website_id', $data['website_id'])
  3467. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3468. $query->where('user_id', $user['id']);
  3469. })
  3470. ->where('status', 1)
  3471. ->select('id', 'title', 'website_id', 'user_id', 'updated_at','keyword','catid','description','seo_description')
  3472. ->orderBy('updated_at', 'desc')
  3473. ->limit($data['pageSize'])
  3474. ->get();
  3475. if (empty($result)) {
  3476. return Result::error("暂无相关职位信息", 0);
  3477. }
  3478. return Result::success($result);
  3479. }
  3480. /**
  3481. * c端 - 验证路由
  3482. * @param array $data
  3483. * @return array
  3484. */
  3485. /**
  3486. * c端 - 验证路由
  3487. * @param array $data
  3488. * @return array
  3489. */
  3490. public function checkWebsiteRoute(array $data): array
  3491. {
  3492. // 测试001111111222
  3493. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3494. if (empty($web)) {
  3495. return Result::error("该网站不存在", 0);
  3496. } elseif ($web['status'] != 1) {
  3497. return Result::error("网站已经关闭", 0);
  3498. }
  3499. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3500. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3501. // 验证路由是否存在
  3502. if (empty($whiteRouterInfo)) {
  3503. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3504. }
  3505. if (!empty($whiteRouterInfo)) {
  3506. return Result::success($whiteRouterInfo->toArray());
  3507. }
  3508. }
  3509. // 验证栏目路由
  3510. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3511. ->where('path', $data['all_route'])
  3512. ->get()->all();
  3513. if (count($last_category) == 0) {
  3514. return Result::error("该栏目不存在", 0);
  3515. }
  3516. if(count($last_category) > 1){
  3517. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3518. }
  3519. if (count($last_category) == 1) {
  3520. $last_category = $last_category[0];
  3521. }
  3522. // return Result::success($last_category);
  3523. if (isset($data['id']) && !empty($data['id'])) {
  3524. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3525. switch ($last_category['type']) {
  3526. case 1:
  3527. // 文章
  3528. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3529. $article = Article::where('status', 1)
  3530. ->where('id', $data['id'])
  3531. ->where(function ($query) use ($data) {
  3532. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3533. ->orWhereNull("ignore_ids");
  3534. })
  3535. ->first(['catid']);
  3536. if (empty($article)) {
  3537. return Result::error("该文章不存在", 0);
  3538. }
  3539. // return Result::success($article);
  3540. break;
  3541. case 2:
  3542. // 商品
  3543. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3544. $article = Good::where('website_id', $data['website_id'])
  3545. ->where('status', 2)
  3546. ->where('id', $data['id'])
  3547. ->first(['cat_arr_id']);
  3548. if (empty($article)) {
  3549. return Result::error("该商品不存在", 0);
  3550. }
  3551. break;
  3552. case 3:
  3553. // 书刊信息
  3554. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3555. $article = Book::where('website_id', $data['website_id'])
  3556. ->where('status', 2)
  3557. ->where('id', $data['id'])
  3558. ->first(['id', 'cat_arr_id']);
  3559. if (empty($article)) {
  3560. return Result::error("该书刊不存在", 0);
  3561. }
  3562. break;
  3563. case 4:
  3564. // 招聘
  3565. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3566. $article = JobRecruiting::where('website_id', $data['website_id'])
  3567. ->where('status', 1)
  3568. ->where('id', $data['id'])
  3569. ->first(['cat_arr_id']);
  3570. if (empty($article)) {
  3571. return Result::error("该招聘不存在", 0);
  3572. }
  3573. break;
  3574. case 5:
  3575. // 求职
  3576. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3577. $article = JobHunting::where('website_id', $data['website_id'])
  3578. ->where('status', 2)
  3579. ->where('id', $data['id'])
  3580. ->first(['cat_arr_id']);
  3581. if (empty($article)) {
  3582. return Result::error("该求职不存在", 0);
  3583. }
  3584. break;
  3585. case 6:
  3586. // 企业
  3587. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3588. $article = Company::
  3589. // where('website_id', $data['website_id'])
  3590. // ->
  3591. where('status', 1)
  3592. ->where('id', $data['id'])
  3593. ->first(['cat_arr_id']);
  3594. if (empty($article)) {
  3595. return Result::error("该企业不存在", 0);
  3596. }
  3597. break;
  3598. case 7:
  3599. // 项目
  3600. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3601. $article = Project::where('website_id', $data['website_id'])
  3602. ->where('status', 1)
  3603. ->where('id', $data['id'])
  3604. ->first(['cat_arr_id']);
  3605. if (empty($article)) {
  3606. return Result::error("该项目不存在", 0);
  3607. }
  3608. break;
  3609. default:
  3610. return Result::error("该数据不存在", 0);
  3611. break;
  3612. }
  3613. // return Result::success($article);
  3614. // $catid =0 ;
  3615. if(!isset($article['cat_arr_id'])){
  3616. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  3617. }else{
  3618. $catidArray = json_decode($article['cat_arr_id'], true);
  3619. $catid = !empty($catidArray) ? end($catidArray) : null;
  3620. }
  3621. // return Result::success($catid);
  3622. // // return Result::success($article['cat_arr_id']);
  3623. if (empty($catid)) {
  3624. return Result::error("该栏目路径不存在", 0);
  3625. }
  3626. $path = WebsiteCategory::where('website_id', $data['website_id'])
  3627. ->where('category_id',$catid)
  3628. ->first('path');
  3629. }
  3630. // else{
  3631. // // if ($last_category['pid'] != 0) {
  3632. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  3633. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  3634. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3635. // ->where('category_id',$catid)
  3636. // ->where('path',$data['all_route'])
  3637. // ->first('path');
  3638. // // } else {
  3639. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  3640. // // }
  3641. // }
  3642. // return Result::success($path);
  3643. if (!empty($path) && $path['path'] != $data['all_route']) {
  3644. return Result::error('非法路径!');
  3645. } else {
  3646. return Result::success( $last_category['path']);
  3647. }
  3648. }
  3649. /**
  3650. * 招工招聘 - 获取推荐职位
  3651. * @param array $data
  3652. * @return array
  3653. */
  3654. public function getWebsiteLevelJob(array $data): array
  3655. {
  3656. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3657. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3658. ->where('job_recruiting.status', 1)
  3659. ->where('job_level', $data['job_level'])
  3660. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3661. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3662. ->orderBy('job_recruiting.updated_at', 'desc')
  3663. ->limit($data['pageSize'])
  3664. ->get();
  3665. $web = ['website_id' => $data['website_id']];
  3666. if (!empty($job)) {
  3667. $result = $this->processJob($job, $web);
  3668. }
  3669. if (empty($result)) {
  3670. return Result::error("暂无相关职位信息", 0);
  3671. }
  3672. return Result::success($result);
  3673. }
  3674. /**
  3675. * 验证导航名称是否重复
  3676. * @return void
  3677. */
  3678. //20250226 产品列表
  3679. public function getGoodList(array $data): array
  3680. {
  3681. var_dump($data, '---------1-2--');
  3682. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3683. unset($data['user_type_id']);
  3684. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3685. $where = [];
  3686. if ($type_id != '10000') {
  3687. $where = [
  3688. 'good.user_id' => $user_id,
  3689. ];
  3690. }
  3691. //类型
  3692. if (isset($data['type_id']) && $data['type_id']) {
  3693. $where['good.type_id'] = $data['type_id'];
  3694. }
  3695. //名称
  3696. if (isset($data['name']) && $data['name']) {
  3697. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3698. }
  3699. //status
  3700. if (isset($data['status']) && $data['status'] != '') {
  3701. $where['good.status'] = $data['status'];
  3702. }
  3703. //status1
  3704. // if (isset($data['status1']) && $data['status1'] == 1) {
  3705. // $status1 = 1;
  3706. // }
  3707. $where1 = [];
  3708. //website_id
  3709. // if (isset($data['website_id']) && $data['website_id']) {
  3710. // $where1 = [
  3711. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3712. // ];
  3713. // }
  3714. // website_name
  3715. if (isset($data['website_name']) && $data['website_name']) {
  3716. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3717. }
  3718. // catid
  3719. if (isset($data['category_name']) && $data['category_name']) {
  3720. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3721. }
  3722. // $result = Good::where($where)
  3723. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3724. var_dump($where, '---------1---');
  3725. $result = Good::where($where)
  3726. ->when(!empty($where1), function ($query) use ($where1) {
  3727. return $query->where($where1);
  3728. })
  3729. //status 1待审核2已审核3已拒绝
  3730. ->when(isset($data['status1']), function ($query) {
  3731. return $query->whereIn('good.status', [1, 3]);
  3732. })
  3733. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3734. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3735. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3736. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3737. ->orderBy("updated_at", "desc")
  3738. ->limit($data['page_size'])
  3739. ->offset(($data['page'] - 1) * $data['page_size'])
  3740. ->get();
  3741. $count = Good::where($where)
  3742. ->when(!empty($where1), function ($query) use ($where1) {
  3743. return $query->where($where1);
  3744. })
  3745. //status 1待审核2已审核3已拒绝
  3746. ->when(isset($data['status1']), function ($query) {
  3747. return $query->whereIn('good.status', [1, 3]);
  3748. })
  3749. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3750. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3751. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3752. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3753. ->orderBy("updated_at", "desc")->count();
  3754. $data = [
  3755. 'rows' => $result->toArray(),
  3756. 'count' => $count,
  3757. ];
  3758. if (empty($result)) {
  3759. return Result::error("此栏目暂无相关产品", 0);
  3760. }
  3761. return Result::success($data);
  3762. }
  3763. public function getGoodInfo(array $data): array
  3764. {
  3765. $result = Good::where('id', $data['id'])->first();
  3766. if (empty($result)) {
  3767. return Result::error("此产品不存在", 0);
  3768. }
  3769. return Result::success($result);
  3770. }
  3771. public function addGood(array $data): array
  3772. {
  3773. // unset($data['city_arr_id']);
  3774. // unset($data['cat_arr_id']);
  3775. $data['city_id'] = end($data['city_arr_id']);
  3776. $data['catid'] = end($data['cat_arr_id']);
  3777. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3778. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3779. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3780. unset($data['imgUrl']); //大小写
  3781. if (isset($data['price']) && $data['price'] == '') {
  3782. $data['price'] = 0;
  3783. }
  3784. if ($data['imgurl'] == '') {
  3785. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3786. preg_match_all($reg, $data['detail'], $matches);
  3787. if (isset($matches[1][0])) {
  3788. //截取varchar240
  3789. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3790. }
  3791. }
  3792. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3793. //提取标题+内容中的关键词
  3794. $data['keyword'] = $data['name'];
  3795. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3796. Jieba::init(); // 初始化 jieba-php
  3797. Finalseg::init();
  3798. $segList = Jieba::cut($data['keyword']);
  3799. $segList1 = array_slice($segList, 0, 8);
  3800. $data['keyword'] = implode(',', $segList1);
  3801. }
  3802. if ($data['description'] == '') {
  3803. //提取内容中的描述
  3804. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3805. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3806. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3807. }
  3808. if ($data['status'] == 1) {
  3809. $this->sendMessage([
  3810. 'talk_type' => 200,
  3811. 'title' => $data['name'],
  3812. 'content' => '提交了审核',
  3813. 'messageType' => 3,
  3814. ]);
  3815. }
  3816. $result = Good::insert($data);
  3817. if (empty($result)) {
  3818. return Result::error("添加失败", 0);
  3819. }
  3820. return Result::success($result);
  3821. }
  3822. public function updateGood(array $data): array
  3823. {
  3824. $data['city_id'] = end($data['city_arr_id']);
  3825. $data['catid'] = end($data['cat_arr_id']);
  3826. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3827. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3828. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3829. //设置东八区
  3830. date_default_timezone_set('Asia/Shanghai');
  3831. $data['updated_at'] = date('Y-m-d H:i:s');
  3832. if (isset($data['price']) && $data['price'] == '') {
  3833. $data['price'] = 0;
  3834. }
  3835. if ($data['imgurl'] == '') {
  3836. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3837. preg_match_all($reg, $data['detail'], $matches);
  3838. if (isset($matches[1][0])) {
  3839. //截取varchar240
  3840. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3841. }
  3842. }
  3843. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3844. //提取标题+内容中的关键词
  3845. $data['keyword'] = $data['name'];
  3846. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3847. Jieba::init(); // 初始化 jieba-php
  3848. Finalseg::init();
  3849. $segList = Jieba::cut($data['keyword']);
  3850. $segList1 = array_slice($segList, 0, 8);
  3851. $data['keyword'] = implode(',', $segList1);
  3852. }
  3853. if ($data['description'] == '') {
  3854. //提取内容中的描述
  3855. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3856. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3857. }
  3858. if ($data['status'] == 1) {
  3859. $this->sendMessage([
  3860. 'talk_type' => 200,
  3861. 'title' => $data['name'],
  3862. 'content' => '提交了审核',
  3863. 'messageType' => 3,
  3864. ]);
  3865. }
  3866. $result = Good::where('id', $data['id'])->update($data);
  3867. if (empty($result)) {
  3868. return Result::error("更新失败", 0);
  3869. }
  3870. return Result::success($result);
  3871. }
  3872. public function delGood(array $data): array
  3873. {
  3874. $result = Good::where('id', $data['id'])->delete();
  3875. if (empty($result)) {
  3876. return Result::error("删除失败", 0);
  3877. }
  3878. return Result::success($result);
  3879. }
  3880. //20250226 产品列表
  3881. //20250306 求职信息
  3882. public function getJobHuntingList(array $data): array
  3883. {
  3884. $where = [];
  3885. if (isset($data['username']) && !empty($data['username'])) {
  3886. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3887. }
  3888. //status 1待审核2已审核3已拒绝
  3889. if (isset($data['status']) && $data['status'] != '') {
  3890. $where = [
  3891. 'job_hunting.status' => $data['status'],
  3892. ];
  3893. }
  3894. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3895. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3896. unset($data['type_id']);
  3897. if ($type_id != '10000') {
  3898. $where[] = ['job_hunting.user_id', '=', $user_id];
  3899. }
  3900. $result = JobHunting::where($where)
  3901. ->when(!empty($data['status1']), function ($query) use ($data) {
  3902. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3903. })
  3904. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3905. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3906. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3907. ->orderBy("updated_at", "desc")
  3908. ->limit($data['page_size'])
  3909. ->offset(($data['page'] - 1) * $data['page_size'])
  3910. ->get();
  3911. if (empty($result)) {
  3912. return Result::error("查询失败", 0);
  3913. }
  3914. $count = JobHunting::where($where)
  3915. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3916. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3917. ->count();
  3918. $data = [
  3919. 'rows' => $result->toArray(),
  3920. 'count' => $count,
  3921. ];
  3922. return Result::success($data);
  3923. }
  3924. public function getJobHuntingApply(array $data): array
  3925. {
  3926. var_dump($data, '-----------------test--------1-');
  3927. $where = [];
  3928. if (isset($data['username']) && !empty($data['username'])) {
  3929. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3930. }
  3931. if (isset($data['salary']) && !empty($data['salary'])) {
  3932. $where[] = [
  3933. 'job_hunting.salary',
  3934. '=',
  3935. $data['salary'],
  3936. ];
  3937. }
  3938. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3939. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3940. unset($data['type_id']);
  3941. if ($type_id != '10000') {
  3942. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3943. }
  3944. var_dump($where, '-----------------test---------');
  3945. $result = jobApply::where($where)
  3946. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3947. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3948. // })
  3949. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3950. ->where('job_enum.egroup', '=', 'income')
  3951. ->where('job_hunting.status', 2) //已审核
  3952. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3953. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3954. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3955. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3956. //职位----是申请职位
  3957. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3958. ->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')
  3959. ->orderBy("job_hunting.updated_at", "desc")
  3960. ->limit($data['page_size'])
  3961. ->offset(($data['page'] - 1) * $data['page_size'])
  3962. ->get();
  3963. if (empty($result)) {
  3964. return Result::error("查询失败", 0);
  3965. }
  3966. $count = jobApply::where($where)
  3967. ->where('job_enum.egroup', '=', 'income')
  3968. ->where('job_hunting.status', 2) //已审核
  3969. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3970. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3971. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3972. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3973. //职位----是申请职位
  3974. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3975. ->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')
  3976. ->count();
  3977. $data = [
  3978. 'rows' => $result->toArray(),
  3979. 'count' => $count,
  3980. ];
  3981. return Result::success($data);
  3982. }
  3983. public function addJobHunting(array $data): array
  3984. {
  3985. date_default_timezone_set('Asia/Shanghai');
  3986. unset($data['company_name']);
  3987. unset($data['job_industry']);
  3988. unset($data['job_name']);
  3989. unset($data['department']);
  3990. unset($data['job_timeList']);
  3991. unset($data['job_content']);
  3992. unset($data['job_typename']); //不知道这是啥,
  3993. $data['created_at'] = date('Y-m-d H:i:s');
  3994. $data['updated_at'] = date('Y-m-d H:i:s');
  3995. //根据用户 user_id 只能添加一次
  3996. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3997. if (!empty($result)) {
  3998. return Result::error("您已添加过求职信息", 0);
  3999. }
  4000. var_dump($result, '-----------------test---------');
  4001. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4002. if (is_string($data['city_arr_id'])) {
  4003. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4004. $cityArr = json_decode($data['city_arr_id'], true);
  4005. // 确保 $cityArr 是数组
  4006. if (is_array($cityArr)) {
  4007. $data['city_id'] = end($cityArr);
  4008. }
  4009. } else {
  4010. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4011. if (is_array($data['city_arr_id'])) {
  4012. $data['city_id'] = end($data['city_arr_id']);
  4013. }
  4014. }
  4015. }
  4016. // 处理求职所绑定栏目
  4017. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4018. if (is_string($data['cat_arr_id'])) {
  4019. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4020. // 先清理可能存在的无效 JSON 字符
  4021. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4022. $catArr = json_decode($cleanedCatArrStr, true);
  4023. // 检查 JSON 解码是否成功且结果是数组
  4024. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4025. $data['catid'] = end($catArr);
  4026. }
  4027. } else {
  4028. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4029. if (is_array($data['cat_arr_id'])) {
  4030. $data['catid'] = end($data['cat_arr_id']);
  4031. }
  4032. }
  4033. }
  4034. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4035. $this->sendMessage([
  4036. 'talk_type' => 600,
  4037. 'title' => $data['name'],
  4038. 'content' => '提交了审核',
  4039. 'messageType' => 11,
  4040. ]);
  4041. }
  4042. $result = JobHunting::create($data);
  4043. if (empty($result)) {
  4044. return Result::error("添加失败", 0);
  4045. }
  4046. return Result::success($result);
  4047. }
  4048. public function delJobHunting(array $data): array
  4049. {
  4050. $result = JobHunting::where('id', $data['id'])->delete();
  4051. if (empty($result)) {
  4052. return Result::error("删除失败", 0);
  4053. }
  4054. return Result::success($result);
  4055. }
  4056. public function updateJobHunting(array $data): array
  4057. {
  4058. //设置东八区
  4059. date_default_timezone_set('Asia/Shanghai');
  4060. unset($data['company_name']);
  4061. unset($data['job_industry']);
  4062. unset($data['job_name']);
  4063. unset($data['department']);
  4064. unset($data['job_timeList']);
  4065. unset($data['job_content']);
  4066. unset($data['job_typename']); //不知道这是啥,
  4067. $data['created_at'] = date('Y-m-d H:i:s');
  4068. $data['updated_at'] = date('Y-m-d H:i:s');
  4069. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4070. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4071. $cityArr = json_decode($data['city_arr_id'], true);
  4072. $data['city_id'] = end($cityArr);
  4073. } else {
  4074. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4075. $data['city_id'] = end($data['city_arr_id']);
  4076. }
  4077. // 处理求职所绑定栏目
  4078. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4079. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4080. $catArr = json_decode($data['cat_arr_id'], true);
  4081. $data['catid'] = end($catArr);
  4082. } else {
  4083. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4084. $data['catid'] = end($data['cat_arr_id']);
  4085. }
  4086. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4087. $this->sendMessage([
  4088. 'talk_type' => 600,
  4089. 'title' => $data['name'],
  4090. 'content' => '提交了审核',
  4091. 'messageType' => 11,
  4092. ]);
  4093. }
  4094. $result = JobHunting::where('id', $data['id'])->update($data);
  4095. if (empty($result)) {
  4096. return Result::error("更新失败", 0);
  4097. }
  4098. return Result::success($result);
  4099. }
  4100. public function getJobHuntingInfo(array $data): array
  4101. {
  4102. $result = JobHunting::where('id', $data['id'])->first();
  4103. if (empty($result)) {
  4104. return Result::error("查询失败", 0);
  4105. }
  4106. return Result::success($result);
  4107. }
  4108. public function getJobHuntingData(array $data): array
  4109. {
  4110. $jobEnum = JobEnum::get();
  4111. $jobIndustry = JobIndustry::get();
  4112. $jobNature = JobNature::get();
  4113. $jobPosition = JobPosition::get();
  4114. $data = [
  4115. 'jobEnum' => $jobEnum,
  4116. 'jobIndustry' => $jobIndustry,
  4117. 'jobNature' => $jobNature,
  4118. 'jobPosition' => $jobPosition,
  4119. ];
  4120. return Result::success($data);
  4121. }
  4122. public function delJobHuntingInfo(array $data): array
  4123. {
  4124. $result = JobHunting::where('id', $data['id'])->delete();
  4125. return Result::success();
  4126. }
  4127. //20250324 通知,公告,消息
  4128. public function delNotice(array $data): array
  4129. {
  4130. $result = Notice::where('id', $data['id'])->delete();
  4131. if ($result) {
  4132. return Result::success();
  4133. } else {
  4134. return Result::error("删除失败", 0);
  4135. }
  4136. }
  4137. public function getNoticeInfo(array $data): array
  4138. {
  4139. $result = Notice::where('id', $data['id'])->first();
  4140. // var_dump($result['re_user_ids'], '--------------------');
  4141. if (empty($result)) {
  4142. return Result::error("查询失败", 0);
  4143. }
  4144. return Result::success($result);
  4145. }
  4146. public function readNotice(array $data): array
  4147. {
  4148. $result = Notice::where('id', $data['id'])->first();
  4149. // var_dump($result['re_user_ids'], '--------------------');
  4150. if (empty($result)) {
  4151. return Result::error("查询失败", 0);
  4152. }
  4153. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4154. $re_user_ids = json_decode($result['re_user_ids'], true);
  4155. var_dump($re_user_ids, '--------------1---test---------');
  4156. var_dump($data, '--------------1---test---------');
  4157. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4158. //如果已经存在,就不再添加
  4159. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4160. $read_id = json_decode($result['read_id'], true);
  4161. if (!is_array($read_id)) {
  4162. $read_id = [];
  4163. }
  4164. if (!in_array($data['user_id'], $read_id)) {
  4165. $read_id[] = $data['user_id'];
  4166. $result['read_id'] = json_encode($read_id);
  4167. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4168. }
  4169. } else {
  4170. //如果不存在,就添加
  4171. $result['read_id'] = json_encode([$data['user_id']]);
  4172. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4173. }
  4174. }
  4175. return Result::success($result);
  4176. }
  4177. public function addNotice(array $data): array
  4178. {
  4179. date_default_timezone_set('Asia/Shanghai');
  4180. $data['created_at'] = date('Y-m-d H:i:s');
  4181. $data['updated_at'] = date('Y-m-d H:i:s');
  4182. $user_id = UserInfo::
  4183. //city_id不是null
  4184. whereNotNull('city_id')
  4185. ->whereNotNull('department_id')
  4186. ->where(function ($query) use ($data) {
  4187. $query->where(function ($subQuery) use ($data) {
  4188. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4189. });
  4190. })
  4191. ->where(function ($query) use ($data) {
  4192. $query->where(function ($subQuery) use ($data) {
  4193. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4194. });
  4195. })
  4196. ->pluck('user_id')->toArray();
  4197. $user_id = array_unique($user_id);
  4198. $chat_ids = $user_id;
  4199. $user_id = json_encode($user_id);
  4200. $data['re_user_ids'] = $user_id;
  4201. $this->sendMessage([
  4202. 'talk_type' => 700,
  4203. 'title' => $data['title'],
  4204. 'content' => '提交了审核',
  4205. 'messageType' => 5,
  4206. ]);
  4207. $result = Notice::insertGetId($data);
  4208. if (empty($result)) {
  4209. return Result::error("添加失败", 0);
  4210. }
  4211. return Result::success($result);
  4212. }
  4213. public function updateNotice(array $data): array
  4214. {
  4215. date_default_timezone_set('Asia/Shanghai');
  4216. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4217. $user_id = UserInfo::
  4218. //city_id不是null
  4219. whereNotNull('city_id')
  4220. ->whereNotNull('department_id')
  4221. ->where(function ($query) use ($data) {
  4222. $query->where(function ($subQuery) use ($data) {
  4223. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4224. });
  4225. })
  4226. ->where(function ($query) use ($data) {
  4227. $query->where(function ($subQuery) use ($data) {
  4228. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4229. });
  4230. })
  4231. ->pluck('user_id')->toArray();
  4232. $user_id = array_unique($user_id);
  4233. $user_id = json_encode($user_id);
  4234. $data['re_user_ids'] = $user_id;
  4235. $data['updated_at'] = date('Y-m-d H:i:s');
  4236. $this->sendMessage([
  4237. 'talk_type' => 700,
  4238. 'title' => $data['title'],
  4239. 'content' => '提交了审核',
  4240. 'messageType' => 5,
  4241. ]);
  4242. $result = Notice::where('id', $data['id'])->update($data);
  4243. return Result::success($result);
  4244. }
  4245. public function getNoticeList(array $data): array
  4246. {
  4247. $where = [];
  4248. //title
  4249. if (isset($data['title']) && !empty($data['title'])) {
  4250. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4251. }
  4252. //level
  4253. if (isset($data['level']) && !empty($data['level'])) {
  4254. $where[] = ['notice.level', '=', $data['level']];
  4255. }
  4256. //status
  4257. if (isset($data['status']) && !empty($data['status'])) {
  4258. $where[] = ['notice.status', '=', $data['status']];
  4259. }
  4260. //type
  4261. if (isset($data['type']) && !empty($data['type'])) {
  4262. $where[] = ['notice.type', '=', $data['type']];
  4263. }
  4264. var_dump($data, '------------11111-2----test---------');
  4265. if ($data['type_id'] == 10000) {
  4266. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4267. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4268. })
  4269. ->where($where)
  4270. ->orderBy('updated_at', 'desc')
  4271. ->limit($data['page_size'])
  4272. ->offset(($data['page'] - 1) * $data['page_size'])
  4273. ->get();
  4274. $total = 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. ->count();
  4280. } else {
  4281. $result = Notice::where($where)
  4282. // ->where('user_id', $data['user_id'])
  4283. ->Where(function ($query) use ($data) {
  4284. $query->Where(function ($q) use ($data) {
  4285. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4286. ->orWhere('notice.user_id', $data['user_id']);
  4287. });
  4288. })
  4289. ->when(!empty($data['status1']), function ($query) use ($data) {
  4290. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4291. })
  4292. ->orderBy('updated_at', 'desc')
  4293. ->limit($data['page_size'])
  4294. ->offset(($data['page'] - 1) * $data['page_size'])
  4295. ->get();
  4296. $total = Notice::where($where)
  4297. ->when(!empty($data['status1']), function ($query) use ($data) {
  4298. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4299. })
  4300. // ->where('user_id', $data['user_id'])
  4301. ->Where(function ($query) use ($data) {
  4302. $query->Where(function ($q) use ($data) {
  4303. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4304. ->orWhere('notice.user_id', $data['user_id']);
  4305. });
  4306. })
  4307. ->count();
  4308. }
  4309. if (empty($result)) {
  4310. return Result::error("查询失败", 0);
  4311. }
  4312. $data = [
  4313. 'rows' => $result,
  4314. 'count' => $total,
  4315. ];
  4316. return Result::success($data);
  4317. }
  4318. public function noticeList(array $data): array
  4319. {
  4320. $where = [];
  4321. //title
  4322. if (isset($data['title']) && !empty($data['title'])) {
  4323. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4324. }
  4325. //level
  4326. if (isset($data['level']) && !empty($data['level'])) {
  4327. $where[] = ['notice.level', '=', $data['level']];
  4328. }
  4329. //status
  4330. if (isset($data['status']) && !empty($data['status'])) {
  4331. $where[] = ['notice.status', '=', $data['status']];
  4332. }
  4333. //type
  4334. if (isset($data['type']) && !empty($data['type'])) {
  4335. $where[] = ['notice.type', '=', $data['type']];
  4336. }
  4337. var_dump($data, '------------11111-2----test---------');
  4338. if ($data['type_id'] == 10000) {
  4339. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4340. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4341. })
  4342. ->where($where)
  4343. ->orderBy('updated_at', 'desc')
  4344. ->limit($data['page_size'])
  4345. ->offset(($data['page'] - 1) * $data['page_size'])
  4346. ->get();
  4347. $total = 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. ->count();
  4353. } else {
  4354. $result = Notice::where($where)
  4355. // ->where('user_id', $data['user_id'])
  4356. ->Where(function ($query) use ($data) {
  4357. $query->Where(function ($q) use ($data) {
  4358. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4359. ->orWhere('notice.user_id', $data['user_id']);
  4360. });
  4361. })
  4362. ->when(!empty($data['status1']), function ($query) use ($data) {
  4363. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4364. })
  4365. ->orderBy('updated_at', 'desc')
  4366. ->limit($data['page_size'])
  4367. ->offset(($data['page'] - 1) * $data['page_size'])
  4368. ->get();
  4369. $total = Notice::where($where)
  4370. ->when(!empty($data['status1']), function ($query) use ($data) {
  4371. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4372. })
  4373. // ->where('user_id', $data['user_id'])
  4374. ->Where(function ($query) use ($data) {
  4375. $query->Where(function ($q) use ($data) {
  4376. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4377. ->orWhere('notice.user_id', $data['user_id']);
  4378. });
  4379. })
  4380. ->count();
  4381. }
  4382. if (empty($result)) {
  4383. return Result::error("查询失败", 0);
  4384. }
  4385. $data = [
  4386. 'rows' => $result,
  4387. 'count' => $total,
  4388. ];
  4389. return Result::success($data);
  4390. }
  4391. public function getNoticeDetail(array $data): array
  4392. {
  4393. $result = Notice::where('id', $data['id'])->first();
  4394. if (empty($result)) {
  4395. return Result::error("查询失败", 0);
  4396. }
  4397. return Result::success($result);
  4398. }
  4399. public function deleteNotice(array $data): array
  4400. {
  4401. $notice = Notice::where('id', $data['id'])->first();
  4402. if (empty($notice)) {
  4403. return Result::error("删除失败", 0);
  4404. }
  4405. $chat_group_id = $notice->group_id;
  4406. if ($chat_group_id) {
  4407. //删除群聊
  4408. ChatGroups::where('id', $chat_group_id)->delete();
  4409. //删除群成员
  4410. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4411. //删除群聊记录
  4412. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4413. }
  4414. $result = Notice::where('id', $data['id'])->delete();
  4415. return Result::success($result);
  4416. }
  4417. public function complaintList(array $data): array
  4418. {
  4419. var_dump($data, '---------1---------');
  4420. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4421. unset($data['type_id']);
  4422. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4423. $where = [];
  4424. if ($type_id != 10000 && empty($data['deal_user'])) {
  4425. // $where['complaint.user_id'] = $user_id;
  4426. }
  4427. if (!empty($data['title'])) {
  4428. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4429. }
  4430. if (!empty($data['department_id'])) {
  4431. $where['complaint.department_id'] = $data['department_id'];
  4432. }
  4433. if (!empty($data['deal'])) {
  4434. $where['complaint.deal'] = $data['deal'];
  4435. }
  4436. if (!empty($data['status'])) {
  4437. $where['complaint.status'] = $data['status'];
  4438. }
  4439. var_dump(!empty($data['deal_user']), '----------1');
  4440. var_dump($where, '----------2');
  4441. $result = Complaint::where($where)
  4442. ->when(!empty($data['status1']), function ($query) use ($data) {
  4443. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4444. })
  4445. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4446. //json re_user_ids data[user_id]是不是在里面
  4447. $query->Where(function ($q) use ($data) {
  4448. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4449. ->where('complaint.status', 2);
  4450. });
  4451. })
  4452. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4453. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4454. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4455. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4456. ->orderBy('updated_at', 'desc')
  4457. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4458. //sql输出
  4459. if (empty($result)) {
  4460. return Result::error("暂无投诉信息", 0);
  4461. }
  4462. // 取出数据
  4463. $rows = $result->items();
  4464. $count = $result->total();
  4465. $responseData = [
  4466. 'rows' => $rows,
  4467. 'count' => $count,
  4468. ];
  4469. return Result::success($responseData);
  4470. }
  4471. public function getComplaintList(array $data): array
  4472. {
  4473. var_dump($data, '00000001000000000000');
  4474. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4475. unset($data['type_id']);
  4476. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4477. $where = [];
  4478. if ($type_id != 10000 && empty($data['deal_user'])) {
  4479. $where['complaint.user_id'] = $user_id;
  4480. }
  4481. if (!empty($data['title'])) {
  4482. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4483. }
  4484. if (!empty($data['department_id'])) {
  4485. $where['complaint.department_id'] = $data['department_id'];
  4486. }
  4487. if (!empty($data['deal'])) {
  4488. $where['complaint.deal'] = $data['deal'];
  4489. }
  4490. if (!empty($data['status'])) {
  4491. $where['complaint.status'] = $data['status'];
  4492. }
  4493. var_dump(!empty($data['deal_user']), '----------1');
  4494. var_dump($where, '----------2');
  4495. $result = Complaint::where($where)
  4496. ->when(!empty($data['status1']), function ($query) use ($data) {
  4497. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4498. })
  4499. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4500. // //json re_user_ids data[user_id]是不是在里面
  4501. // $query->Where(function ($q) use ($data) {
  4502. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4503. // ->where('complaint.status', 2);
  4504. // });
  4505. // })
  4506. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4507. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4508. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4509. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4510. ->orderBy('updated_at', 'desc')
  4511. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4512. //sql输出
  4513. if (empty($result)) {
  4514. return Result::error("暂无投诉信息", 0);
  4515. }
  4516. // 取出数据
  4517. $rows = $result->items();
  4518. $count = $result->total();
  4519. $responseData = [
  4520. 'rows' => $rows,
  4521. 'count' => $count,
  4522. ];
  4523. return Result::success($responseData);
  4524. }
  4525. public function getComplaintInfo(array $data): array
  4526. {
  4527. $result = Complaint::where('id', $data['id'])->first();
  4528. if (empty($result)) {
  4529. return Result::error("查询失败", 0);
  4530. }
  4531. return Result::success($result);
  4532. }
  4533. public function readComplaint(array $data): array
  4534. {
  4535. $result = Complaint::where('id', $data['id'])->first();
  4536. if (empty($result)) {
  4537. return Result::error("查询失败", 0);
  4538. }
  4539. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4540. $re_user_ids = json_decode($result['re_user_ids'], true);
  4541. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4542. //如果已经存在,就不再添加
  4543. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4544. $read_id = json_decode($result['read_id'], true);
  4545. if (!is_array($read_id)) {
  4546. $read_id = [];
  4547. }
  4548. if (!in_array($data['user_id'], $read_id)) {
  4549. $read_id[] = $data['user_id'];
  4550. $result['read_id'] = json_encode($read_id);
  4551. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4552. }
  4553. } else {
  4554. //如果不存在,就添加
  4555. $result['read_id'] = json_encode([$data['user_id']]);
  4556. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4557. }
  4558. }
  4559. return Result::success($result);
  4560. }
  4561. public function addComplaint(array $data): array
  4562. {
  4563. date_default_timezone_set('Asia/Shanghai');
  4564. $data['created_at'] = date('Y-m-d H:i:s');
  4565. $data['updated_at'] = date('Y-m-d H:i:s');
  4566. $this->sendMessage([
  4567. 'talk_type' => 800,
  4568. 'title' => $data['title'],
  4569. 'content' => '提交了审核',
  4570. 'messageType' => 6,
  4571. ]);
  4572. $result = Complaint::create($data);
  4573. return Result::success($result);
  4574. }
  4575. public function updateComplaint(array $data): array
  4576. {
  4577. date_default_timezone_set('Asia/Shanghai');
  4578. $data['updated_at'] = date('Y-m-d H:i:s');
  4579. $user_id = $data['user_id'] ?? 0;
  4580. $type_id = $data['type_id'] ?? 0;
  4581. unset($data['user_id']);
  4582. unset($data['type_id']);
  4583. $this->sendMessage([
  4584. 'talk_type' => 800,
  4585. 'title' => $data['title'],
  4586. 'content' => '提交了审核',
  4587. 'messageType' => 6,
  4588. ]);
  4589. $result = Complaint::where('id', $data['id'])->update($data);
  4590. return Result::success($result);
  4591. }
  4592. public function deleteComplaint(array $data): array
  4593. {
  4594. $result = Complaint::where('id', $data['id'])->delete();
  4595. return Result::success($result);
  4596. }
  4597. public function getComplainInfo(array $data): array
  4598. {
  4599. $result = Complaint::where('id', $data['id'])->first();
  4600. if (empty($result)) {
  4601. return Result::error("查询失败", 0);
  4602. }
  4603. return Result::success($result);
  4604. }
  4605. public function updateComplaintStatus(array $data): array
  4606. {
  4607. date_default_timezone_set('Asia/Shanghai');
  4608. $data['updated_at'] = date('Y-m-d H:i:s');
  4609. $user_id = $data['user_id'] ?? 0;
  4610. $type_id = $data['type_id'] ?? 0;
  4611. unset($data['user_id']);
  4612. unset($data['type_id']);
  4613. //处理, 写入处理人
  4614. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4615. $data['real_deal_user'] = $user_id;
  4616. }
  4617. //如果是deal 23,则判断是不是处理人
  4618. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4619. $complaintInof = Complaint::where('id', $data['id'])
  4620. ->where('real_deal_user', $user_id)
  4621. ->first();
  4622. if (empty($complaintInof)) {
  4623. return Result::error("处理人错误", 0);
  4624. }
  4625. }
  4626. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4627. if ($data['status'] == 1) {
  4628. $this->sendMessage([
  4629. 'talk_type' => 800,
  4630. 'title' => $complaintInfo['title'],
  4631. 'content' => '提交了审核',
  4632. 'messageType' => 6,
  4633. ]);
  4634. }
  4635. if ($data['status'] == 2 && !isset($data['deal'])) {
  4636. $this->sendMessage([
  4637. 'talk_type' => 801,
  4638. 'title' => $complaintInfo['title'],
  4639. 'content' => '审核通过',
  4640. 'messageType' => 6,
  4641. 'user_id' => $complaintInfo['user_id'],
  4642. ]);
  4643. $this->sendMessage([
  4644. 'talk_type' => 802,
  4645. 'title' => $complaintInfo['title'],
  4646. 'content' => '待处理',
  4647. 'messageType' => 6,
  4648. 'user_id' => $complaintInfo['re_user_ids'],
  4649. ]);
  4650. }
  4651. if ($data['status'] == 3 && !isset($data['deal'])) {
  4652. $this->sendMessage([
  4653. 'talk_type' => 801,
  4654. 'title' => $complaintInfo['title'],
  4655. 'content' => '审核拒绝',
  4656. 'messageType' => 6,
  4657. 'user_id' => $complaintInfo['user_id'],
  4658. ]);
  4659. }
  4660. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4661. $this->sendMessage([
  4662. 'talk_type' => 802,
  4663. 'title' => $complaintInfo['title'],
  4664. 'content' => '处理中',
  4665. 'messageType' => 6,
  4666. 'user_id' => $complaintInfo['re_user_ids'],
  4667. ]);
  4668. }
  4669. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4670. $this->sendMessage([
  4671. 'talk_type' => 802,
  4672. 'title' => $complaintInfo['title'],
  4673. 'content' => '不予处理',
  4674. 'messageType' => 6,
  4675. 'user_id' => $complaintInfo['re_user_ids'],
  4676. ]);
  4677. }
  4678. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4679. $this->sendMessage([
  4680. 'talk_type' => 802,
  4681. 'title' => $complaintInfo['title'],
  4682. 'content' => '已完结',
  4683. 'messageType' => 6,
  4684. 'user_id' => $complaintInfo['re_user_ids'],
  4685. ]);
  4686. }
  4687. $result = complaint::where('id', $data['id'])->update($data);
  4688. return Result::success($result);
  4689. }
  4690. public function updateGoodStatus(array $data): array
  4691. {
  4692. $user_id = $data['user_id'] ?? 0;
  4693. $type_id = $data['type_id'] ?? 0;
  4694. unset($data['user_id']);
  4695. unset($data['type_id']);
  4696. $goodInfo = Good::where('id', $data['id'])->first();
  4697. if ($data['status'] == 2) {
  4698. $this->sendMessage([
  4699. 'talk_type' => 201,
  4700. 'title' => $goodInfo['name'],
  4701. 'content' => '审核通过',
  4702. 'messageType' => 3,
  4703. 'user_id' => $goodInfo['user_id'],
  4704. ]);
  4705. }
  4706. if ($data['status'] == 3) {
  4707. $this->sendMessage([
  4708. 'talk_type' => 201,
  4709. 'title' => $goodInfo['name'],
  4710. 'content' => '审核拒绝',
  4711. 'messageType' => 3,
  4712. 'user_id' => $goodInfo['user_id'],
  4713. ]);
  4714. }
  4715. if ($data['status'] == 1) {
  4716. $this->sendMessage([
  4717. 'talk_type' => 200,
  4718. 'title' => $goodInfo['name'],
  4719. 'content' => '提交了审核',
  4720. 'messageType' => 3,
  4721. ]);
  4722. }
  4723. $result = Good::where('id', $data['id'])->update($data);
  4724. return Result::success($result);
  4725. }
  4726. public function updateJobHuntingStatus(array $data): array
  4727. {
  4728. $user_id = $data['user_id'] ?? 0;
  4729. $type_id = $data['type_id'] ?? 0;
  4730. unset($data['user_id']);
  4731. unset($data['type_id']);
  4732. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4733. if ($data['status'] == 2) {
  4734. $this->sendMessage([
  4735. 'talk_type' => 601,
  4736. 'title' => $jogHuntingInfo['name'],
  4737. 'content' => '审核通过',
  4738. 'messageType' => 11,
  4739. 'user_id' => $jogHuntingInfo['user_id'],
  4740. ]);
  4741. }
  4742. if ($data['status'] == 3) {
  4743. $this->sendMessage([
  4744. 'talk_type' => 601,
  4745. 'title' => $jogHuntingInfo['name'],
  4746. 'content' => '审核拒绝',
  4747. 'messageType' => 11,
  4748. 'user_id' => $jogHuntingInfo['user_id'],
  4749. ]);
  4750. }
  4751. if ($data['status'] == 1) {
  4752. $this->sendMessage([
  4753. 'talk_type' => 600,
  4754. 'title' => $jogHuntingInfo['name'],
  4755. 'content' => '提交了审核',
  4756. 'messageType' => 11,
  4757. ]);
  4758. }
  4759. $result = JobHunting::where('id', $data['id'])->update($data);
  4760. return Result::success($result);
  4761. }
  4762. public function updateNoticeStatus(array $data): array
  4763. {
  4764. $user_id = $data['user_id'] ?? 0;
  4765. $type_id = $data['type_id'] ?? 0;
  4766. unset($data['user_id']);
  4767. unset($data['type_id']);
  4768. //查询公告
  4769. $notice = Notice::where('id', $data['id'])->first();
  4770. if (empty($notice)) {
  4771. return Result::error("公告不存在", 0);
  4772. }
  4773. //$chat_ids 去除掉$data['user_id']
  4774. $chat_ids = json_decode($notice['re_user_ids'], true);
  4775. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4776. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4777. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  4778. //chat_group
  4779. $group_id = PublicData::uuid();
  4780. $groupData = [
  4781. 'id' => $group_id,
  4782. 'creator_id' => $notice['user_id'],
  4783. 'group_name' => $notice['group_name'] ?? '',
  4784. 'profile' => $notice['profile'] ?? 0,
  4785. ];
  4786. var_dump($groupData, '-----------------groupData-------');
  4787. $groupResult = ChatGroups::insertGetId($groupData);
  4788. var_dump($groupResult, '-----------------groupid-------');
  4789. $groupMemberData = [
  4790. 'id' => PublicData::uuid(),
  4791. 'user_id' => $notice['user_id'],
  4792. 'group_id' => $group_id,
  4793. 'leader' => 2,
  4794. ];
  4795. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4796. //插入群成员表
  4797. $groupMemberDataUser = [];
  4798. $chatData = [];
  4799. foreach ($chat_ids as $key => $value) {
  4800. $groupMemberDataUser[] = [
  4801. 'id' => PublicData::uuid(),
  4802. 'user_id' => $value,
  4803. 'group_id' => $group_id,
  4804. 'leader' => 1,
  4805. ];
  4806. $chatData[] = [
  4807. 'user_id' => $value,
  4808. 'msg_type' => 1,
  4809. 'receiver_id' => $group_id,
  4810. 'content' => '通过通知创建群聊',
  4811. 'group_receiver_id' => $notice['user_id'],
  4812. 'action' => 'recieved',
  4813. 'created_at' => date('Y-m-d H:i:s'),
  4814. ];
  4815. }
  4816. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4817. ChatGroupsMember::insert($groupMemberDataUser);
  4818. //插入一条管理员聊天记录
  4819. $chatData[] = [
  4820. 'user_id' => $notice['user_id'],
  4821. 'msg_type' => 1,
  4822. 'receiver_id' => $group_id,
  4823. 'content' => '通过通知创建群聊',
  4824. 'group_receiver_id' => $notice['user_id'],
  4825. 'action' => 'said',
  4826. 'created_at' => date('Y-m-d H:i:s'),
  4827. ];
  4828. var_dump($chatData, '-----------------chatData-------');
  4829. $chatResult = ChatRecords::insert($chatData);
  4830. //处理imp
  4831. $group = [
  4832. 'type' => 1,
  4833. 'name' => $notice['group_name'] ?? '',
  4834. 'profile' => '',
  4835. 'avatar' => '',
  4836. 'creator_id' => $notice['user_id'],
  4837. ];
  4838. $groupResult = GroupImp::insertGetId($group);
  4839. var_dump($groupResult, '获取imp group_id');
  4840. $groupMember = [
  4841. 'user_id' => $notice['user_id'],
  4842. 'group_id' => $groupResult,
  4843. 'leader' => 1,
  4844. 'join_time' => Date('Y-m-d H:i:s')
  4845. ];
  4846. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  4847. $talk_session = [
  4848. 'user_id' => $notice['user_id'],
  4849. 'to_from_id' => $groupResult,
  4850. 'talk_mode' => 2,
  4851. 'created_at' => Date('Y-m-d H:i:s'),
  4852. 'updated_at' => Date('Y-m-d H:i:s'),
  4853. ];
  4854. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  4855. //被通知人员处理
  4856. foreach ($chat_ids as $key => $value) {
  4857. $groupMemberdata[] = [
  4858. 'user_id' => $value,
  4859. 'group_id' => $groupResult,
  4860. 'leader' => 3,
  4861. 'join_time' => Date('Y-m-d H:i:s')
  4862. ];
  4863. $talk_sessionData[] = [
  4864. 'user_id' => $value,
  4865. 'to_from_id' => $groupResult,
  4866. 'talk_mode' => 2,
  4867. 'created_at' => Date('Y-m-d H:i:s'),
  4868. 'updated_at' => Date('Y-m-d H:i:s'),
  4869. ];
  4870. }
  4871. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  4872. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  4873. $group_id = $groupResult;
  4874. //更新result的 group_id
  4875. $data['group_id'] = $group_id;
  4876. Notice::where(['id' => $data['id']])->update($data);
  4877. }
  4878. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  4879. //删除掉信息
  4880. GroupImp::where('id', $notice['group_id'])->delete();
  4881. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  4882. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  4883. foreach ($chat_ids as $key => $value) {
  4884. }
  4885. //聊天记录删除
  4886. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  4887. $data['group_id'] = null;
  4888. Notice::where(['id' => $data['id']])->update($data);
  4889. }
  4890. $result = Notice::where('id', $data['id'])->update($data);
  4891. $noticeInfo = Notice::where('id', $data['id'])->first();
  4892. if ($data['status'] == 2) {
  4893. $this->sendMessage([
  4894. 'talk_type' => 701,
  4895. 'title' => $noticeInfo['title'],
  4896. 'content' => '审核通过',
  4897. 'messageType' => 3,
  4898. 'user_id' => $noticeInfo['user_id'],
  4899. ]);
  4900. }
  4901. if ($data['status'] == 3) {
  4902. $this->sendMessage([
  4903. 'talk_type' => 701,
  4904. 'title' => $noticeInfo['title'],
  4905. 'content' => '审核拒绝',
  4906. 'messageType' => 3,
  4907. 'user_id' => $noticeInfo['user_id'],
  4908. ]);
  4909. }
  4910. if ($data['status'] == 1) {
  4911. $this->sendMessage([
  4912. 'talk_type' => 700,
  4913. 'title' => $noticeInfo['title'],
  4914. 'content' => '提交了审核',
  4915. 'messageType' => 3,
  4916. ]);
  4917. }
  4918. return Result::success($result);
  4919. }
  4920. public function getDUser(array $data): array
  4921. {
  4922. if (!empty($data['ids'])) {
  4923. $user = User::whereIn('id', $data['ids'])->getall();
  4924. if (empty($user)) {
  4925. return Result::error('无数据', 0);
  4926. }
  4927. return Result::success($user);
  4928. }
  4929. $where = [];
  4930. if (!empty($data['department_id'])) {
  4931. $where['department_id'] = $data['department_id'];
  4932. }
  4933. if (!empty($data['city_id'])) {
  4934. $where['city_id'] = $data['city_id'];
  4935. }
  4936. $result = User::where('type_id', 2)
  4937. ->where('status', 1)
  4938. ->where($where)
  4939. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4940. ->get();
  4941. if (empty($result)) {
  4942. return Result::error("查询失败", 0);
  4943. }
  4944. return Result::success($result);
  4945. }
  4946. /**
  4947. * 验证导航名称是否重复
  4948. * @return void
  4949. */
  4950. public function checkCategoryName(array $data): array
  4951. {
  4952. $result = Category::when($data, function ($query) use ($data) {
  4953. if (isset($data['name']) && $data['name']) {
  4954. $query->where("name", $data['name']);
  4955. }
  4956. if (isset($data['id']) && $data['id']) {
  4957. $query->where("id", "!=", $data['id']);
  4958. }
  4959. })->first();
  4960. if ($result) {
  4961. return Result::error("已存在");
  4962. } else {
  4963. return Result::success();
  4964. }
  4965. }
  4966. //20250226 产品列表
  4967. // 20250306 -------招聘--------fr
  4968. /*
  4969. * 招聘列表
  4970. * */
  4971. public function getJobRecruitingList(array $data): array
  4972. {
  4973. $where = [];
  4974. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4975. if ($data['checkout'] == 0) {
  4976. $job_status = [0, 2];
  4977. } else {
  4978. $job_status = [1];
  4979. }
  4980. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4981. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4982. }
  4983. $user = User::where('id', $data['user_id'])->first();
  4984. if (empty($user)) {
  4985. return Result::error("用户不存在", 0);
  4986. }
  4987. // 3:企业会员
  4988. if ($user['type_id'] == 3) {
  4989. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4990. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4991. }
  4992. // 如果 $where 为空,则不添加 where 条件
  4993. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4994. return $query->where($where);
  4995. })
  4996. ->whereIn('job_recruiting.status', $job_status)
  4997. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4998. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4999. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5000. ->orderBy("updated_at", "desc")
  5001. ->offset(($data['page'] - 1) * $data['page_size'])
  5002. ->limit($data['page_size'])
  5003. ->get()
  5004. ->all();
  5005. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5006. return $query->where($where);
  5007. })
  5008. ->whereIn('job_recruiting.status', $job_status)
  5009. ->count();
  5010. if (empty($result)) {
  5011. return Result::error("暂无招聘信息", 0);
  5012. }
  5013. return Result::success($result);
  5014. }
  5015. /*
  5016. * 招聘信息添加
  5017. * */
  5018. public function addJobRecruiting(array $data): array
  5019. {
  5020. // var_dump('添加招聘进入news------data',$data);
  5021. // return Result::success($data);
  5022. $user = User::where('user.id', $data['user_id'])
  5023. ->where('user.status', 1)
  5024. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5025. ->select(
  5026. 'user.type_id',
  5027. 'user.mobile',
  5028. 'user.email',
  5029. 'user_info.business_name',
  5030. 'user_info.company_hy_id',
  5031. 'user_info.company_nature',
  5032. 'user_info.company_size',
  5033. 'user_info.introduction',
  5034. 'user_info.real_name',
  5035. 'user_info.company_url',
  5036. 'user_info.address_arr_id',
  5037. 'user_info.address'
  5038. )
  5039. ->first();
  5040. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5041. return Result::error("用户不存在", 0);
  5042. }
  5043. $web = Website::where('id', $data['website_id'])->first();
  5044. if (empty($web)) {
  5045. return Result::error("网站不存在", 0);
  5046. }
  5047. // var_dump('添加招聘进入news---user---user',$user);
  5048. // 处理招聘关键词
  5049. if(isset($data['keyword']) && !empty($data['keyword'])){
  5050. $data['keyword'] = str_replace(',',',',$data['keyword']);
  5051. }else{
  5052. Jieba::init(); // 初始化 jieba-php
  5053. Finalseg::init();
  5054. $segList = Jieba::cut($data['title']);
  5055. $segList1 = array_slice($segList, 0, 8);
  5056. $data['keyword'] = implode(',', $segList1);
  5057. }
  5058. if(!isset($data['eso_description']) || empty($data['eso_description'])){
  5059. $content = $data['description'];
  5060. // 去除 <style> 和 <script> 标签及其内容
  5061. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5062. // 去除所有 HTML 标签
  5063. $content = strip_tags($content);
  5064. // 去除 HTML 实体
  5065. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5066. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5067. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5068. // 去除多余空白
  5069. $content = preg_replace('/\s+/u', '', $content);
  5070. // 截取 100 个字符
  5071. $data['eso_descriprion'] = mb_substr($content, 0, 100);
  5072. }
  5073. // return Result::success($user);
  5074. $data['action_id'] = $data['user_id'] ?? null;
  5075. $data['user_type'] = $user['type_id'] ?? null;
  5076. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5077. if(isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])){
  5078. $data['catid'] = end($data['cat_arr_id']);
  5079. }else{
  5080. $data['catid'] = 0;
  5081. }
  5082. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5083. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5084. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5085. // 公司地址 管理员必填
  5086. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5087. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5088. // 管理员-企业相关信息
  5089. $company = [
  5090. // 'user_id' => $data['user_id']?? null,
  5091. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5092. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5093. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5094. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5095. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5096. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5097. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5098. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5099. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5100. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5101. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5102. ];
  5103. //去掉相关企业信息
  5104. $job = array_diff_key($data, array_flip(array_keys($company)));
  5105. // var_dump('添加招聘进入news---job---user',$job);
  5106. Db::beginTransaction();
  5107. try {
  5108. // // 先添加职位相关信息
  5109. if ($user['type_id'] == 10000) {
  5110. $job['status'] = 1;
  5111. }
  5112. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5113. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5114. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5115. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5116. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5117. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5118. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5119. // return Result::success($job);
  5120. $jobId = JobRecruiting::insertGetId($job);
  5121. if (empty($jobId)) {
  5122. Db::rollBack();
  5123. return Result::error("添加失败");
  5124. }
  5125. // 添加公司信息
  5126. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5127. $company['job_id'] = $jobId;
  5128. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5129. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5130. if ($user['type_id'] == 10000) {
  5131. // 管理员添加企业信息
  5132. $companyId = JobCompany::insertGetId($company);
  5133. if (empty($companyId)) {
  5134. Db::rollBack();
  5135. return Result::error("添加失败");
  5136. }
  5137. } else {
  5138. // 企业会员添加企业信息
  5139. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5140. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5141. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5142. $company['job_id'] = $jobId;
  5143. $companyId = JobCompany::insertGetId($company);
  5144. if (empty($companyId)) {
  5145. Db::rollBack();
  5146. return Result::error("添加失败");
  5147. }
  5148. }
  5149. Db::commit();
  5150. $result = [
  5151. 'job_id' => $jobId,
  5152. 'company_id' => $companyId,
  5153. ];
  5154. return Result::success($result);
  5155. } catch (\Exception $e) {
  5156. Db::rollBack();
  5157. return Result::error($e->getMessage(), 0);
  5158. }
  5159. // return Result::success($result);
  5160. }
  5161. /*
  5162. * 获取招聘信息详情
  5163. * */
  5164. public function getJobRecruitingInfo(array $data): array
  5165. {
  5166. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5167. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5168. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5169. ->select(
  5170. 'job_recruiting.*',
  5171. 'website.website_name as website_name',
  5172. 'job_company.business_name',
  5173. 'job_company.company_hy_id',
  5174. 'job_company.company_size',
  5175. 'job_company.company_nature',
  5176. 'job_company.introduction',
  5177. 'job_company.real_name',
  5178. 'job_company.mobile',
  5179. 'job_company.company_url',
  5180. 'job_company.address_arr_id',
  5181. 'job_company.address',
  5182. 'job_company.email'
  5183. )
  5184. ->first();
  5185. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5186. if (!empty($cityId)) {
  5187. if (isset($cityId[1]) && $cityId[1] != null) {
  5188. $city = District::where('id', $cityId[1])->first(['name']);
  5189. } else {
  5190. $city = District::where('id', $cityId[0])->first(['name']);
  5191. }
  5192. $result['city'] = $city['name'] ?? '';
  5193. }
  5194. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5195. if (is_array($addressId) && !empty($addressId)) {
  5196. $address = District::whereIn('id', $addressId)
  5197. ->orderBy('level', 'asc')
  5198. ->get(['name'])
  5199. ->pluck('name')
  5200. ->implode('');
  5201. // $job->address_name = $address ?? '';
  5202. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5203. }
  5204. if (empty($result)) {
  5205. return Result::error("招聘信息不存在", 0);
  5206. }
  5207. // return Result::success($job);
  5208. return Result::success($result);
  5209. }
  5210. /*
  5211. * 修改招聘信息
  5212. * */
  5213. public function upJobRecruiting(array $data): array
  5214. {
  5215. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5216. // return Result::success($job);
  5217. if (empty($job)) {
  5218. return Result::error("招聘信息不存在", 0);
  5219. }
  5220. $user = User::where('id', $data['user_id'])->first();
  5221. // return Result::success($user);
  5222. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5223. return Result::error("用户不存在", 0);
  5224. }
  5225. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5226. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5227. }
  5228. // 处理招聘关键词
  5229. if(isset($data['keyword']) && !empty($data['keyword'])){
  5230. $data['keyword'] = str_replace(',',',',$data['keyword']);
  5231. }else{
  5232. Jieba::init(); // 初始化 jieba-php
  5233. Finalseg::init();
  5234. $segList = Jieba::cut($data['title']);
  5235. $segList1 = array_slice($segList, 0, 8);
  5236. $data['keyword'] = implode(',', $segList1);
  5237. }
  5238. if(!isset($data['eso_description']) || empty($data['eso_description'])){
  5239. $content = $data['description'];
  5240. // 去除 <style> 和 <script> 标签及其内容
  5241. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5242. // 去除所有 HTML 标签
  5243. $content = strip_tags($content);
  5244. // 去除 HTML 实体
  5245. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5246. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5247. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5248. // 去除多余空白
  5249. $content = preg_replace('/\s+/u', '', $content);
  5250. // 截取 100 个字符
  5251. $data['eso_descriprion'] = mb_substr($content, 0, 100);
  5252. }
  5253. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5254. if(isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])){
  5255. $data['catid'] = end($data['cat_arr_id']);
  5256. }else{
  5257. }
  5258. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5259. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5260. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5261. // 公司地址 管理员必填
  5262. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5263. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5264. // 管理员-企业相关信息
  5265. $company = [
  5266. // 'user_id' => $data['user_id']?? null,
  5267. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5268. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5269. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5270. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5271. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5272. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5273. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5274. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5275. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5276. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5277. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5278. ];
  5279. //去掉相关企业信息
  5280. $data = array_diff_key($data, array_flip(array_keys($company)));
  5281. $jobId = $data['id'];
  5282. $web = $data['website_id'];
  5283. $data['action_id'] = $data['user_id'];
  5284. unset($data['user_id']);
  5285. unset($data['user_type']);
  5286. unset($data['id']);
  5287. unset($data['website_id']);
  5288. // return Result::success($data);
  5289. Db::beginTransaction();
  5290. try {
  5291. // 管理员修改招聘信息
  5292. if ($user['type_id'] == 10000) {
  5293. $data['website_id'] = $web;
  5294. $company['website_id'] = $data['website_id'];
  5295. $data['status'] = 1;
  5296. } else {
  5297. $data['status'] = 0;
  5298. }
  5299. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5300. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5301. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5302. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5303. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5304. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5305. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5306. // return Result::success($job);
  5307. // Db::rollBack();
  5308. // return Result::success($company);
  5309. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5310. $this->sendMessage([
  5311. 'talk_type' => 500,
  5312. 'title' => $data['title'],
  5313. 'content' => '提交了审核',
  5314. 'messageType' => 10,
  5315. ]);
  5316. }
  5317. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5318. if (empty($result['job'])) {
  5319. Db::rollBack();
  5320. return Result::error("修改招聘信息失败");
  5321. }
  5322. // 管理员修改企业相关信息
  5323. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5324. if (empty($result['company'])) {
  5325. Db::rollBack();
  5326. return Result::error("修改企业相关信息失败");
  5327. }
  5328. Db::commit();
  5329. // return Result::success($result);
  5330. } catch (\Exception $e) {
  5331. Db::rollBack();
  5332. return Result::error($e->getMessage(), 0);
  5333. }
  5334. return Result::success($result);
  5335. }
  5336. /*
  5337. * 招聘信息删除
  5338. * */
  5339. public function delJobRecruiting(array $data): array
  5340. {
  5341. $user = User::where('id', $data['user_id'])->first();
  5342. if (empty($user)) {
  5343. return Result::error("用户不存在", 0);
  5344. }
  5345. $job = JobRecruiting::where('id', $data['id'])->first();
  5346. if (empty($job)) {
  5347. return Result::error("招聘信息不存在", 0);
  5348. }
  5349. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5350. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5351. }
  5352. Db::beginTransaction();
  5353. try {
  5354. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5355. if (empty($result['job'])) {
  5356. Db::rollBack();
  5357. return Result::error("删除招聘信息失败");
  5358. }
  5359. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5360. if (empty($result['company'])) {
  5361. Db::rollBack();
  5362. return Result::error("删除企业相关信息失败");
  5363. }
  5364. Db::commit();
  5365. } catch (\Exception $e) {
  5366. Db::rollBack();
  5367. return Result::error($e->getMessage(), 0);
  5368. }
  5369. return Result::success($result);
  5370. }
  5371. /*
  5372. * 获取公司信息
  5373. * */
  5374. public function getJobCompany(array $data): array
  5375. {
  5376. $user = User::where('user.id', $data['user_id'])
  5377. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5378. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5379. ->first();
  5380. // return Result::success($user);
  5381. if (empty($user)) {
  5382. return Result::error("用户不存在", 0);
  5383. }
  5384. if ($user['type_id'] == 3) {
  5385. $result = [
  5386. // 'id' => 0,
  5387. 'user_id' => $data['user_id'],
  5388. 'website_id' => $data['website_id'],
  5389. 'business_name' => $user['business_name'], // 企业名称
  5390. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5391. 'company_nature' => $user['company_nature'], // 公司性质
  5392. 'company_size' => $user['company_size'], // 公司规模
  5393. 'introduction' => $user['introduction'], // 公司简介
  5394. 'real_name' => $user['real_name'], // 企业联系人
  5395. 'mobile' => $user['mobile'], // 企业联系电话
  5396. 'company_url' => $user['company_url'], // 企业网址
  5397. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5398. 'address' => $user['address'], // 企业地址
  5399. 'email' => $user['email'], // 企业邮箱
  5400. ];
  5401. } else {
  5402. return Result::error("用户类型错误", 0);
  5403. }
  5404. if (empty($result)) {
  5405. return Result::error("公司信息不存在", 0);
  5406. }
  5407. return Result::success($result);
  5408. }
  5409. /*
  5410. * 修改公司信息
  5411. * */
  5412. public function upJobCompany(array $data): array
  5413. {
  5414. // return Result::success($data);
  5415. $user = User::where('user.id', $data['user_id'])
  5416. ->where('user.status', 1)
  5417. ->select('user.user_name', 'user.type_id')
  5418. ->first();
  5419. if (empty($user)) {
  5420. return Result::error("用户不存在", 0);
  5421. }
  5422. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5423. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5424. $company = [
  5425. 'business_name' => $data['business_name'], // 企业名称
  5426. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5427. 'company_nature' => $data['company_nature'], // 公司性质
  5428. 'company_size' => $data['company_size'], // 公司规模
  5429. 'introduction' => $data['introduction'], // 公司简介
  5430. // 'real_name' => $data['real_name'], // 企业联系人
  5431. 'company_url' => $data['company_url'], // 企业网址
  5432. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5433. 'address' => $data['address'], // 企业详细地址
  5434. // 'email' => $data['email'], // 企业邮箱
  5435. ];
  5436. if ($user['type_id'] == 3) {
  5437. Db::beginTransaction();
  5438. try {
  5439. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5440. 'business_name' => $data['business_name'], // 企业名称
  5441. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5442. 'company_nature' => $data['company_nature'], // 公司性质
  5443. 'company_size' => $data['company_size'], // 公司规模
  5444. 'introduction' => $data['introduction'], // 公司简介
  5445. // 'real_name' => $data['real_name'], // 企业联系人
  5446. 'company_url' => $data['company_url'], // 企业网址
  5447. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5448. 'address' => $data['address'], // 企业详细地址
  5449. ]);
  5450. if (empty($result['userinfo'])) {
  5451. Db::rollBack();
  5452. return Result::error('修改企业会员信息失败!');
  5453. }
  5454. $result['user'] = User::where('id', $data['user_id'])->update([
  5455. 'email' => $data['email'], // 企业邮箱
  5456. ]);
  5457. if (empty($result['user'])) {
  5458. Db::rollBack();
  5459. return Result::error('修改个人中心信息失败!');
  5460. }
  5461. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5462. if (!empty($job_company)) {
  5463. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5464. if (empty($result['job_company'])) {
  5465. Db::rollBack();
  5466. return Result::error('修改企业会员信息失败!');
  5467. }
  5468. }
  5469. Db::commit();
  5470. return Result::success($result);
  5471. } catch (\Exception $e) {
  5472. Db::rollBack();
  5473. return Result::error($e->getMessage(), 0);
  5474. }
  5475. } else {
  5476. return Result::error("用户类型错误", 0);
  5477. }
  5478. }
  5479. /*
  5480. * 获取省-市
  5481. * */
  5482. public function getJobRecruitingArea(array $data): array
  5483. {
  5484. if (isset($data['pid']) && $data['pid'] != null) {
  5485. $result = District::where('pid', $data['pid'])->get()->all();
  5486. } else {
  5487. $result = District::where('level', 1)->get()->all();
  5488. }
  5489. if (empty($result)) {
  5490. return Result::error("暂无此省市", 0);
  5491. }
  5492. return Result::success($result);
  5493. }
  5494. /*
  5495. * 获取行业分类
  5496. * */
  5497. public function getIndustry(array $data): array
  5498. {
  5499. $result = JobIndustry::get()->all();
  5500. if (empty($result)) {
  5501. return Result::error("暂无行业分类", 0);
  5502. }
  5503. return Result::success($result);
  5504. }
  5505. /*
  5506. * 获取职位
  5507. * */
  5508. public function getPositionList(array $data): array
  5509. {
  5510. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5511. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5512. } else {
  5513. $result = JobPosition::where('zwpid', 0)->get()->all();
  5514. }
  5515. if (empty($result)) {
  5516. return Result::error("暂无此职位", 0);
  5517. }
  5518. return Result::success($result);
  5519. }
  5520. /*
  5521. * 获取工作性质-菜单
  5522. * */
  5523. public function getJobNature(array $data): array
  5524. {
  5525. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5526. if (empty($result)) {
  5527. return Result::error("暂无工作性质", 0);
  5528. }
  5529. return Result::success($result);
  5530. }
  5531. /*
  5532. * 获取工作经验-菜单
  5533. * */
  5534. public function getExperience(array $data): array
  5535. {
  5536. $result = JobEnum::where('egroup', 'years')->get()->all();
  5537. if (empty($result)) {
  5538. return Result::error("暂无工作经验", 0);
  5539. }
  5540. return Result::success($result);
  5541. }
  5542. /*
  5543. * 获取学历-菜单
  5544. * */
  5545. public function getEducation(array $data): array
  5546. {
  5547. $result = JobEnum::where('egroup', 'education')->get()->all();
  5548. if (empty($result)) {
  5549. return Result::error("暂无学历", 0);
  5550. }
  5551. return Result::success($result);
  5552. }
  5553. /*
  5554. * 获取薪资-菜单
  5555. * */
  5556. public function getSalary(array $data): array
  5557. {
  5558. $result = JobEnum::where('egroup', 'income')->get()->all();
  5559. if (empty($result)) {
  5560. return Result::error("暂无薪资", 0);
  5561. }
  5562. return Result::success($result);
  5563. }
  5564. /*
  5565. * 获取语言-菜单
  5566. * */
  5567. public function getLanguage(array $data): array
  5568. {
  5569. $result = JobEnum::where('egroup', 'language')->get()->all();
  5570. if (empty($result)) {
  5571. return Result::error("暂无语言", 0);
  5572. }
  5573. return Result::success($result);
  5574. }
  5575. /*
  5576. * 获取掌握程度-菜单
  5577. * */
  5578. public function getLevel(array $data): array
  5579. {
  5580. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5581. if (empty($result)) {
  5582. return Result::error("暂无工作性质", 0);
  5583. }
  5584. return Result::success($result);
  5585. }
  5586. // 公司信息
  5587. /*
  5588. * 获取公司性质-菜单
  5589. * */
  5590. public function getCompanyNature(array $data): array
  5591. {
  5592. $result = JobNature::get()->all();
  5593. if (empty($result)) {
  5594. return Result::error("暂无公司性质", 0);
  5595. }
  5596. return Result::success($result);
  5597. }
  5598. /*
  5599. * 获取公司规模-菜单
  5600. * */
  5601. public function getCompanySize(array $data): array
  5602. {
  5603. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5604. if (empty($result)) {
  5605. return Result::error("暂无公司规模", 0);
  5606. }
  5607. return Result::success($result);
  5608. }
  5609. /*
  5610. * 招聘信息审核
  5611. * */
  5612. public function checkJobRecruiting(array $data): array
  5613. {
  5614. $user = User::where('id', $data['user_id'])->first();
  5615. if (empty($user)) {
  5616. return Result::error("用户不存在", 0);
  5617. }
  5618. $job = JobRecruiting::where('id', $data['id'])->first();
  5619. if (empty($job)) {
  5620. return Result::error("招聘信息不存在", 0);
  5621. }
  5622. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5623. if ($user['type_id'] != 10000) {
  5624. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5625. }
  5626. // 驳回原因
  5627. if ($data['status'] == 2) {
  5628. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5629. }
  5630. $data['action_id'] = $data['user_id'];
  5631. unset($data['user_id']);
  5632. if ($data['status'] == 1) {
  5633. $this->sendMessage([
  5634. 'talk_type' => 501,
  5635. 'title' => $job['title'],
  5636. 'content' => '审核通过',
  5637. 'messageType' => 10,
  5638. 'user_id' => $job['user_id'],
  5639. ]);
  5640. }
  5641. if ($data['status'] == 2) {
  5642. $this->sendMessage([
  5643. 'talk_type' => 501,
  5644. 'title' => $job['title'],
  5645. 'content' => '审核拒绝',
  5646. 'messageType' => 10,
  5647. 'user_id' => $job['user_id'],
  5648. ]);
  5649. }
  5650. if ($data['status'] == 0) {
  5651. $this->sendMessage([
  5652. 'talk_type' => 500,
  5653. 'title' => $job['title'],
  5654. 'content' => '提交了审核',
  5655. 'messageType' => 10,
  5656. ]);
  5657. }
  5658. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5659. if (empty($result)) {
  5660. return Result::error("审核失败", 0);
  5661. }
  5662. return Result::success($result);
  5663. }
  5664. public function myApplyList(array $data): array
  5665. {
  5666. var_dump($data, '------参数');
  5667. $user = User::where('id', $data['user_id'])->first();
  5668. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5669. return Result::error("用户不存在", 0);
  5670. }
  5671. // 1:个人会员 职场机会
  5672. if ($user['type_id'] == 1) {
  5673. $where['user_id'] = $user['id'];
  5674. }
  5675. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5676. $query->where('user_id', $user['id']);
  5677. })
  5678. ->pluck('recruit_id');
  5679. $where = [];
  5680. if (isset($data['salary']) && $data['salary'] != null) {
  5681. $where['job_recruiting.salary'] = $data['salary'];
  5682. }
  5683. if (isset($data['experience']) && $data['experience'] != null) {
  5684. $where['job_recruiting.experience'] = $data['experience'];
  5685. }
  5686. if (isset($data['business_name']) && $data['business_name'] != null) {
  5687. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5688. }
  5689. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5690. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5691. ->where($where);
  5692. // ->count();
  5693. $count = $query->count();
  5694. $query = clone $query;
  5695. $job = $query
  5696. ->leftJoin('job_enum as income_enum', function ($join) {
  5697. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5698. ->where('income_enum.egroup', 'income');
  5699. })
  5700. ->leftJoin('job_enum as years_enum', function ($join) {
  5701. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5702. ->where('years_enum.egroup', 'years');
  5703. })
  5704. // ->where($where)
  5705. ->orderBy('job_recruiting.updated_at', 'desc')
  5706. ->select(
  5707. 'job_recruiting.id',
  5708. 'job_recruiting.title',
  5709. 'job_company.business_name',
  5710. 'income_enum.evalue as salary_evalue',
  5711. 'income_enum.ename as salary_ename',
  5712. 'years_enum.evalue as experience_evalue',
  5713. 'years_enum.ename as experience_ename',
  5714. 'job_recruiting.updated_at'
  5715. )
  5716. ->offset(($data['page'] - 1) * $data['pageSize'])
  5717. ->limit($data['pageSize'])
  5718. ->get()
  5719. ->all();
  5720. if (empty($job)) {
  5721. return Result::error("暂无招聘信息", 0);
  5722. }
  5723. $result = [
  5724. 'row' => $job,
  5725. 'count' => $count,
  5726. ];
  5727. return Result::success($result);
  5728. }
  5729. public function readJobApply(array $data): array
  5730. {
  5731. $result = JobApply::where('id', $data['id'])->first();
  5732. if (empty($result)) {
  5733. return Result::error("查询失败", 0);
  5734. }
  5735. $result = JobApply::where('id', $data['id'])->update([
  5736. 'status' => 2,
  5737. ]);
  5738. return Result::success($result);
  5739. }
  5740. /*
  5741. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5742. * */
  5743. public function getRecruitingList(array $data): array
  5744. {
  5745. $user = User::where('id', $data['user_id'])->first();
  5746. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5747. return Result::error("用户不存在", 0);
  5748. }
  5749. // 1:个人会员 职场机会
  5750. if ($user['type_id'] == 1) {
  5751. $where['user_id'] = $user['id'];
  5752. }
  5753. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5754. $query->where('receiver_id', $user['id']);
  5755. })
  5756. ->pluck('recruit_id');
  5757. // return Result::success($recruitingId);
  5758. $where = [];
  5759. if (isset($data['salary']) && $data['salary'] != null) {
  5760. $where['job_recruiting.salary'] = $data['salary'];
  5761. }
  5762. if (isset($data['experience']) && $data['experience'] != null) {
  5763. $where['job_recruiting.experience'] = $data['experience'];
  5764. }
  5765. if (isset($data['business_name']) && $data['business_name'] != null) {
  5766. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5767. }
  5768. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5769. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5770. ->where($where);
  5771. // ->count();
  5772. $count = $query->count();
  5773. $query = clone $query;
  5774. $job = $query
  5775. ->leftJoin('job_enum as income_enum', function ($join) {
  5776. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5777. ->where('income_enum.egroup', 'income');
  5778. })
  5779. ->leftJoin('job_enum as years_enum', function ($join) {
  5780. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5781. ->where('years_enum.egroup', 'years');
  5782. })
  5783. // ->where($where)
  5784. ->orderBy('job_recruiting.updated_at', 'desc')
  5785. ->select(
  5786. 'job_recruiting.id',
  5787. 'job_recruiting.title',
  5788. 'job_company.business_name',
  5789. 'income_enum.evalue as salary_evalue',
  5790. 'income_enum.ename as salary_ename',
  5791. 'years_enum.evalue as experience_evalue',
  5792. 'years_enum.ename as experience_ename',
  5793. 'job_recruiting.updated_at'
  5794. )
  5795. ->offset(($data['page'] - 1) * $data['pageSize'])
  5796. ->limit($data['pageSize'])
  5797. ->get()
  5798. ->all();
  5799. if (empty($job)) {
  5800. return Result::error("暂无招聘信息", 0);
  5801. }
  5802. $result = [
  5803. 'row' => $job,
  5804. 'count' => $count,
  5805. ];
  5806. return Result::success($result);
  5807. }
  5808. /*
  5809. * 获取企业会员-招聘信息列表
  5810. * */
  5811. public function getRecruitingInfo(array $data): array
  5812. {
  5813. $user = User::where('id', $data['user_id'])->first();
  5814. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5815. return Result::error("用户不存在", 0);
  5816. }
  5817. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5818. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5819. ->select(
  5820. 'job_recruiting.*',
  5821. 'job_company.business_name',
  5822. 'job_company.company_hy_id',
  5823. 'job_company.company_size',
  5824. 'job_company.company_nature',
  5825. 'job_company.introduction',
  5826. 'job_company.real_name',
  5827. 'job_company.mobile',
  5828. 'job_company.company_url',
  5829. 'job_company.address_arr_id',
  5830. 'job_company.address',
  5831. 'job_company.email'
  5832. )
  5833. ->get();
  5834. if (empty($recruiting)) {
  5835. return Result::error("暂无招聘信息", 0);
  5836. }
  5837. return Result::success($recruiting);
  5838. }
  5839. /*
  5840. * 获取企业会员-我的沟通
  5841. * */
  5842. public function getJobResumeList(array $data): array
  5843. {
  5844. $user = User::where('id', $data['user_id'])->first();
  5845. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5846. return Result::error("用户不存在", 0);
  5847. }
  5848. $where = [];
  5849. if (isset($data['salary']) && $data['salary'] != null) {
  5850. $where['job_hunting.salary'] = $data['salary'];
  5851. }
  5852. if (isset($data['user_name']) && $data['user_name'] != null) {
  5853. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5854. }
  5855. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5856. $query->where('job_resume.user_id', $user['id']);
  5857. })
  5858. ->when(!empty($where), function ($query) use ($where) {
  5859. $query->where($where);
  5860. })
  5861. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5862. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5863. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5864. ->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');
  5865. $count = $job->count();
  5866. if ($count == 0) {
  5867. return Result::error("暂无沟通记录", 0);
  5868. }
  5869. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5870. ->offset(($data['page'] - 1) * $data['pageSize'])
  5871. ->limit($data['pageSize'])
  5872. ->get();
  5873. if (empty($jobs)) {
  5874. return Result::error("暂无沟通记录", 0);
  5875. }
  5876. $result['row'] = $this->processJob($jobs, '');
  5877. $result['count'] = $count;
  5878. return Result::success($result);
  5879. }
  5880. public function readJobResume(array $data): array
  5881. {
  5882. $result = JobResume::where('id', $data['id'])->first();
  5883. if (empty($result)) {
  5884. return Result::error("查询失败", 0);
  5885. }
  5886. $result = JobResume::where('id', $data['id'])->update([
  5887. 'status' => 2,
  5888. ]);
  5889. return Result::success($result);
  5890. }
  5891. // 20250306 招聘
  5892. //20250422 书刊音像
  5893. public function addBook(array $data): array
  5894. {
  5895. $user_id = $data['user_id'] ?? 0;
  5896. $type_id = $data['type_id'] ?? 0;
  5897. // $website_id = $data['website_id'] ?? 0;
  5898. // unset($data['user_id']);
  5899. unset($data['type_id']);
  5900. // unset($data['website_id']);
  5901. //处理数组
  5902. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5903. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5904. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5905. if ($data['img_url'] == '') {
  5906. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5907. preg_match_all($reg, $data['detail'], $matches);
  5908. if (isset($matches[1][0])) {
  5909. //截取varchar240
  5910. $data['img_url'] = substr($matches[1][0], 0, 240);
  5911. }
  5912. }
  5913. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5914. //提取标题+内容中的关键词
  5915. $data['keyword'] = $data['title'];
  5916. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5917. Jieba::init(); // 初始化 jieba-php
  5918. Finalseg::init();
  5919. $segList = Jieba::cut($data['keyword']);
  5920. $segList1 = array_slice($segList, 0, 8);
  5921. $data['keyword'] = implode(',', $segList1);
  5922. }
  5923. if ($data['description'] == '') {
  5924. //提取内容中的描述
  5925. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5926. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5927. }
  5928. var_dump($data, '--');
  5929. if ($data['status'] == 1) {
  5930. $this->sendMessage([
  5931. 'talk_type' => 400,
  5932. 'title' => $data['title'],
  5933. 'content' => '提交了审核',
  5934. 'messageType' => 7,
  5935. ]);
  5936. }
  5937. $result = Book::insertGetId($data);
  5938. if (empty($result)) {
  5939. return Result::error("添加失败", 0);
  5940. }
  5941. return Result::success($result);
  5942. }
  5943. public function getBookList(array $data): array
  5944. {
  5945. $where = [];
  5946. if (!empty($data["title"])) {
  5947. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5948. }
  5949. if (!empty($data['website_name'])) {
  5950. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5951. }
  5952. if (!empty($data['status'])) {
  5953. $where[] = ['book.status', '=', $data['status']];
  5954. }
  5955. $user_id = $data['user_id'];
  5956. $type_id = $data['type_id'];
  5957. // $type_id = 4;
  5958. var_dump($type_id, '------1--------');
  5959. if ($type_id != 10000) {
  5960. $where[] = ['book.user_id', '=', $user_id];
  5961. }
  5962. var_dump(!empty($data['status1']), '=-===1');
  5963. $result = Book::where($where)
  5964. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5965. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5966. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5967. ->when(isset($data['status1']), function ($query) use ($data) {
  5968. $query->whereIn('book.status', [1, 3]);
  5969. })
  5970. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5971. ->orderBy("updated_at", "desc")
  5972. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5973. if (empty($result)) {
  5974. return Result::error("暂无数据", 0);
  5975. }
  5976. // 取出数据
  5977. $rows = $result->items();
  5978. $count = $result->total();
  5979. $responseData = [
  5980. 'rows' => $rows,
  5981. 'count' => $count,
  5982. ];
  5983. return Result::success($responseData);
  5984. }
  5985. public function deleteBook(array $data): array
  5986. {
  5987. $result = Book::where('id', $data['id'])->delete();
  5988. if (empty($result)) {
  5989. return Result::error("删除失败", 0);
  5990. }
  5991. return Result::success($result);
  5992. }
  5993. public function updateBook(array $data): array
  5994. {
  5995. // $user_id = $data['user_id'] ?? 0;
  5996. $type_id = $data['type_id'] ?? 0;
  5997. // $website_id = $data['website_id'] ?? 0;
  5998. unset($data['user_id']);
  5999. unset($data['type_id']);
  6000. // unset($data['website_id']);
  6001. //处理数组
  6002. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6003. if ($data['img_url'] == '') {
  6004. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6005. preg_match_all($reg, $data['detail'], $matches);
  6006. if (isset($matches[1][0])) {
  6007. //截取varchar240
  6008. $data['img_url'] = substr($matches[1][0], 0, 240);
  6009. }
  6010. }
  6011. if ($data['keyword'] == '') {
  6012. //提取标题+内容中的关键词
  6013. $data['keyword'] = $data['title'];
  6014. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6015. Jieba::init(); // 初始化 jieba-php
  6016. Finalseg::init();
  6017. $segList = Jieba::cut($data['keyword']);
  6018. $segList1 = array_slice($segList, 0, 8);
  6019. $data['keyword'] = implode(',', $segList1);
  6020. }
  6021. if ($data['description'] == '') {
  6022. //提取内容中的描述
  6023. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6024. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6025. }
  6026. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6027. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6028. if ($data['status'] == 1) {
  6029. $this->sendMessage([
  6030. 'talk_type' => 400,
  6031. 'title' => $data['title'],
  6032. 'content' => '提交了审核',
  6033. 'messageType' => 7,
  6034. ]);
  6035. }
  6036. $result = Book::where("id", $data["id"])->update($data);
  6037. if (empty($result)) {
  6038. return Result::error("更新失败", 0);
  6039. }
  6040. return Result::success($result);
  6041. }
  6042. public function getBookInfo(array $data): array
  6043. {
  6044. $result = Book::where("id", $data["id"])->first();
  6045. if (empty($result)) {
  6046. return Result::error("获取失败", 0);
  6047. }
  6048. return Result::success($result);
  6049. }
  6050. public function updateBookStatus(array $data): array
  6051. {
  6052. //审核
  6053. unset($data['user_id']);
  6054. $bookInfo = Book::where("id", $data["id"])->first();
  6055. var_dump($bookInfo, '----');
  6056. if ($data['status'] == 2) {
  6057. $this->sendMessage([
  6058. 'talk_type' => 401,
  6059. 'title' => $bookInfo['title'],
  6060. 'content' => '审核通过',
  6061. 'messageType' => 7,
  6062. 'user_id' => $bookInfo['user_id'],
  6063. ]);
  6064. }
  6065. if ($data['status'] == 3) {
  6066. $this->sendMessage([
  6067. 'talk_type' => 401,
  6068. 'title' => $bookInfo['title'],
  6069. 'content' => '审核拒绝',
  6070. 'messageType' => 7,
  6071. 'user_id' => $bookInfo['user_id'],
  6072. ]);
  6073. }
  6074. if ($data['status'] == 1) {
  6075. $this->sendMessage([
  6076. 'talk_type' => 400,
  6077. 'title' => $bookInfo['title'],
  6078. 'content' => '提交了审核',
  6079. 'messageType' => 7,
  6080. // 'user_id'=>$bookInfo['user_id'],
  6081. ]);
  6082. }
  6083. $result = Book::where("id", $data["id"])->update($data);
  6084. if (empty($result)) {
  6085. return Result::error("更新失败", 0);
  6086. }
  6087. return Result::success($result);
  6088. }
  6089. //20250422 书刊音像
  6090. /**
  6091. * 贴身宝贝
  6092. * @param array $data
  6093. * @return array
  6094. */
  6095. public function getWebsiteTsbb(array $data): array
  6096. {
  6097. $month = $data['month'] ?? date('m');
  6098. $day = $data['day'] ?? date('d');
  6099. // 使用缓存键
  6100. $cacheKey = "tsbb_data_{$month}_{$day}";
  6101. // 尝试从缓存获取数据
  6102. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6103. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6104. if ($cachedData = $cache->get($cacheKey)) {
  6105. return Result::success(unserialize($cachedData));
  6106. }
  6107. //查询老黄历
  6108. try {
  6109. $date = date('Y-m-d');
  6110. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6111. // 使用 curl 替代 file_get_contents
  6112. $ch = curl_init();
  6113. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6114. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6115. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6116. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6117. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6118. 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');
  6119. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6120. 'Accept: application/json',
  6121. 'Content-Type: application/json',
  6122. 'Referer: https://www.36jxs.com/'
  6123. ]);
  6124. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6125. curl_setopt($ch, CURLOPT_ENCODING, '');
  6126. $almanacResponse = curl_exec($ch);
  6127. var_dump("====:", $almanacResponse);
  6128. if (curl_errno($ch)) {
  6129. var_dump('Curl error:', curl_error($ch));
  6130. throw new \Exception('Curl error: ' . curl_error($ch));
  6131. }
  6132. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6133. curl_close($ch);
  6134. if ($almanacResponse === false) {
  6135. throw new \Exception('Failed to fetch almanac data');
  6136. }
  6137. $almanacData = json_decode($almanacResponse, true);
  6138. if (json_last_error() !== JSON_ERROR_NONE) {
  6139. throw new \Exception('Failed to parse almanac data');
  6140. }
  6141. $almanacInfo = $almanacData['data'] ?? [];
  6142. } catch (\Exception $e) {
  6143. var_dump('Exception:', $e->getMessage());
  6144. $almanacInfo = [];
  6145. }
  6146. // 获取历史上的今天数据
  6147. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6148. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6149. ->orderBy('year', 'asc')
  6150. ->select("title", "id", "year", DB::raw('1 as type'))
  6151. ->limit(16)
  6152. ->get();
  6153. // 获取节日数据 - 从今天开始获取未来4条
  6154. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6155. ->orderBy('showtime', 'asc')
  6156. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6157. ->limit(16)
  6158. ->get();
  6159. //说文解字
  6160. $chartacterList = Character::orderBy('updated_at', 'desc')
  6161. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6162. ->limit(6)
  6163. ->get();
  6164. //谜语沙龙
  6165. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6166. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6167. ->limit(4)
  6168. ->get();
  6169. //成语欣赏
  6170. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6171. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6172. ->limit(32)
  6173. ->get();
  6174. //名联赏析
  6175. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6176. ->select("id", "first", "second", DB::raw('6 as type'))
  6177. ->limit(6)
  6178. ->get();
  6179. // 获取分类文章数据
  6180. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6181. ->pluck('category_id')
  6182. ->toArray();
  6183. $articlesList = [];
  6184. foreach ($categoryIds as $catid) {
  6185. // 先查有图片的
  6186. $withImg = DB::table('article')
  6187. ->where('status', 1)
  6188. ->where('catid', $catid)
  6189. ->whereNotNull('imgurl')
  6190. ->where('imgurl', '!=', '')
  6191. ->orderBy('updated_at', 'desc')
  6192. ->limit(6)
  6193. ->get();
  6194. $count = $withImg->count();
  6195. if ($count < 6) {
  6196. // 不足6条再查无图片的补足
  6197. $withoutImg = DB::table('article')
  6198. ->where('status', 1)
  6199. ->where('catid', $catid)
  6200. ->where(function ($q) {
  6201. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6202. })
  6203. ->orderBy('updated_at', 'desc')
  6204. ->limit(6 - $count)
  6205. ->get();
  6206. $articles = $withImg->concat($withoutImg);
  6207. } else {
  6208. $articles = $withImg;
  6209. }
  6210. // 组装
  6211. $category = \App\Model\Category::find($catid);
  6212. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6213. $articlesList[] = [
  6214. 'category_name' => $category ? $category->name : '',
  6215. 'catid' => $catid,
  6216. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6217. 'type' => 100,
  6218. 'list' => $articles->map(function ($item) {
  6219. return [
  6220. 'id' => $item->id,
  6221. 'title' => $item->title,
  6222. 'imgurl' => $item->imgurl,
  6223. 'created_at' => $item->created_at
  6224. ];
  6225. })->values()
  6226. ];
  6227. }
  6228. $result = [
  6229. 'almanac' => $almanacInfo,
  6230. 'historyTodayList' => [
  6231. 'category_name' => '历史上的今天',
  6232. 'list' => $historyTodayList,
  6233. 'type' => 1
  6234. ],
  6235. 'festivalList' => [
  6236. 'category_name' => '节日预告',
  6237. 'list' => $festivalList,
  6238. 'type' => 2
  6239. ],
  6240. 'chartacterList' => [
  6241. 'category_name' => '说文解字',
  6242. 'list' => $chartacterList,
  6243. 'type' => 3
  6244. ],
  6245. 'coupletList' => [
  6246. 'category_name' => '名联赏析',
  6247. 'list' => $coupletList,
  6248. 'type' => 6
  6249. ],
  6250. 'riddletList' => [
  6251. 'category_name' => '谜语沙龙',
  6252. 'list' => $riddletList,
  6253. 'type' => 4
  6254. ],
  6255. 'idiomList' => [
  6256. 'category_name' => '成语欣赏',
  6257. 'list' => $idiomList,
  6258. 'type' => 5
  6259. ],
  6260. 'articlesList' => $articlesList
  6261. ];
  6262. // 缓存结果,设置1小时过期
  6263. $cache->set($cacheKey, serialize($result), 3600);
  6264. return Result::success($result);
  6265. }
  6266. /**
  6267. * 获取资讯列表
  6268. */
  6269. public function getWebsiteTsbbList(array $data): array
  6270. {
  6271. $page = $data['page'] ?? 1;
  6272. $pageSize = $data['pageSize'] ?? 10;
  6273. // 如果没有传入月份和日期,则使用今天的日期
  6274. $month = $data['month'] ?? date('m');
  6275. $day = $data['day'] ?? date('d');
  6276. $total = 0;
  6277. $result = [];
  6278. $data['type'] = intval($data['type']);
  6279. var_dump("接收参数:", $data);
  6280. switch ($data['type']) {
  6281. case 1:
  6282. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6283. // 当前月份之后的数据
  6284. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6285. // 或者当前月份且日期大于等于当前日期的数据
  6286. ->orWhere(function ($q) use ($month, $day) {
  6287. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6288. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6289. });
  6290. })
  6291. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6292. $total = $query->count();
  6293. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6294. ->offset(($page - 1) * $pageSize)
  6295. ->limit($pageSize)
  6296. ->get();
  6297. break;
  6298. case 2:
  6299. $query = Festival::where(function ($q) use ($month, $day) {
  6300. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6301. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6302. ->orWhere(function ($q) use ($month, $day) {
  6303. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6304. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6305. });
  6306. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6307. $total = $query->count();
  6308. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6309. ->offset(($page - 1) * $pageSize)
  6310. ->limit($pageSize)
  6311. ->get();
  6312. break;
  6313. case 3:
  6314. $query = Character::orderBy("updated_at", "desc");
  6315. $total = $query->count();
  6316. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6317. ->offset(($page - 1) * $pageSize)
  6318. ->limit($pageSize)
  6319. ->get();
  6320. break;
  6321. case 4:
  6322. $query = Riddle::orderBy("updated_at", "desc");
  6323. $total = $query->count();
  6324. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6325. ->offset(($page - 1) * $pageSize)
  6326. ->limit($pageSize)
  6327. ->get();
  6328. break;
  6329. case 5:
  6330. $query = Idiom::orderBy("updated_at", "desc");
  6331. $total = $query->count();
  6332. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6333. ->offset(($page - 1) * $pageSize)
  6334. ->limit($pageSize)
  6335. ->get();
  6336. break;
  6337. case 6:
  6338. $query = Couplet::orderBy("updated_at", "desc");
  6339. $total = $query->count();
  6340. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6341. ->offset(($page - 1) * $pageSize)
  6342. ->limit($pageSize)
  6343. ->get();
  6344. break;
  6345. default:
  6346. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6347. $total = $query->count();
  6348. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6349. ->offset(($page - 1) * $pageSize)
  6350. ->limit($pageSize)
  6351. ->get();
  6352. }
  6353. return Result::success([
  6354. 'list' => $result,
  6355. 'total' => $total,
  6356. 'page' => (int)$page,
  6357. 'pageSize' => (int)$pageSize,
  6358. 'month' => $month,
  6359. 'day' => $day
  6360. ]);
  6361. }
  6362. /**
  6363. * 1:历史上的今天
  6364. * 2:节日
  6365. * 3:文章
  6366. *
  6367. * 资讯详情信息
  6368. */
  6369. public function getWebsiteTsbbDetail(array $data): array
  6370. {
  6371. $data['type'] = intval($data['type']);
  6372. switch ($data['type']) {
  6373. case 1:
  6374. $result = HistoryToday::where("id", $data['id'])->first();
  6375. break;
  6376. case 2:
  6377. $result = Festival::where("id", $data['id'])->first();
  6378. break;
  6379. case 3:
  6380. $result = Character::where("id", $data['id'])->first();
  6381. break;
  6382. case 4:
  6383. $result = Riddle::where("id", $data['id'])->first();
  6384. break;
  6385. case 5:
  6386. $result = Idiom::where("id", $data['id'])->first();
  6387. break;
  6388. case 6:
  6389. $result = Couplet::where("id", $data['id'])->first();
  6390. break;
  6391. default:
  6392. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6393. break;
  6394. }
  6395. return Result::success($result);
  6396. }
  6397. /**
  6398. * 农网导航首页数据
  6399. */
  6400. public function getWebsiteNwHomeList(array $data): array
  6401. {
  6402. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6403. ->pluck('category_id')
  6404. ->toArray();
  6405. // 使用子查询优化
  6406. $articlesList = DB::table('article')
  6407. ->select([
  6408. 'article.id',
  6409. 'article.title',
  6410. 'article.imgurl',
  6411. 'article.created_at',
  6412. 'category.name as category_name',
  6413. 'category.id as category_id',
  6414. 'website_category.aLIas_pinyin as pinyin',
  6415. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6416. DB::raw('100 as type')
  6417. ])
  6418. ->join('category', 'article.catid', '=', 'category.id')
  6419. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6420. ->leftJoin('website_category as parent_wc', function ($join) {
  6421. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6422. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6423. })
  6424. ->where('website_category.website_id', $data['website_id'])
  6425. ->where('article.status', 1)
  6426. ->whereIn('category.id', $categoryIds)
  6427. ->orderBy('article.created_at', 'desc')
  6428. ->get()
  6429. ->groupBy('category_id')
  6430. ->map(function ($group) {
  6431. // 确保第一条数据有图片
  6432. $firstWithImage = $group->first(function ($item) {
  6433. return !empty($item->imgurl);
  6434. });
  6435. if ($firstWithImage) {
  6436. // 如果有带图片的文章,将其放在第一位
  6437. $group = $group->filter(function ($item) use ($firstWithImage) {
  6438. return $item->id !== $firstWithImage->id;
  6439. })->prepend($firstWithImage);
  6440. }
  6441. return [
  6442. 'category_name' => $group->first()->category_name,
  6443. 'catid' => $group->first()->category_id,
  6444. 'pinyin' => $group->first()->pinyin,
  6445. 'parent_pinyin' => $group->first()->parent_pinyin,
  6446. 'list' => $group->take(4)->map(function ($item) {
  6447. return [
  6448. 'id' => $item->id,
  6449. 'title' => $item->title,
  6450. ];
  6451. })->values()
  6452. ];
  6453. })
  6454. ->values()
  6455. ->toArray();
  6456. return Result::success($articlesList);
  6457. }
  6458. /**
  6459. * 企业管理
  6460. * @param array $data
  6461. * @return array
  6462. */
  6463. public function getCompanyList(array $data): array
  6464. {
  6465. // return Result::success($data);
  6466. $where = [];
  6467. $user = User::where('id', $data['user_id'])->first();
  6468. if (empty($user)) {
  6469. return Result::error('用户不存在!');
  6470. }
  6471. if ($user['type_id'] != 10000) {
  6472. $where['user_id'] = $data['user_id'];
  6473. }
  6474. if (isset($data['title']) && !empty($data['title'])) {
  6475. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6476. }
  6477. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6478. array_push($where, ['website.id', $data['website_id']]);
  6479. }
  6480. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6481. if ($data['ischeck'] == 1) {
  6482. if (isset($data['status']) && $data['status'] != '') {
  6483. array_push($where, ['company.status', $data['status']]);
  6484. $query = Company::where($where);
  6485. } else {
  6486. $query = Company::whereIn('company.status', [0, 2]);
  6487. }
  6488. } else {
  6489. $query = Company::where('company.status', 1);
  6490. }
  6491. }
  6492. $result = $query->where($where)
  6493. ->leftJoin('website_category', function ($query) {
  6494. $query->on('website_category.category_id', '=', 'company.category_id')
  6495. ->on('website_category.website_id', '=', 'company.website_id');
  6496. })
  6497. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6498. ->select(
  6499. 'company.id',
  6500. 'company.title',
  6501. 'company.website_id',
  6502. 'company.category_id',
  6503. 'website.website_name',
  6504. 'website_category.alias as category_name',
  6505. 'company.status',
  6506. 'company.updated_at',
  6507. 'company.user_id'
  6508. )
  6509. ->orderBy('company.updated_at', 'desc')
  6510. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6511. if ($result->isEmpty()) {
  6512. return Result::error("暂无企业", 0);
  6513. }
  6514. return Result::success($result);
  6515. }
  6516. /**
  6517. * 添加企业
  6518. * @param array $data
  6519. * @return array
  6520. */
  6521. public function addCompany(array $data): array
  6522. {
  6523. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6524. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6525. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6526. $data['cat_arr_id'] = json_encode($car_arr_id);
  6527. } else {
  6528. $data['cat_arr_id'] = '';
  6529. }
  6530. if ($data['imgurl'] == '') {
  6531. //content中提取图片第一个图,正则提取
  6532. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6533. preg_match_all($reg, $data['content'], $matches);
  6534. if (isset($matches[1][0])) {
  6535. //截取varchar240
  6536. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6537. }
  6538. }
  6539. if ($data['keyword'] == '') {
  6540. //提取标题+内容中的关键词
  6541. $data['keyword'] = $data['title'];
  6542. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6543. Jieba::init(); // 初始化 jieba-php
  6544. Finalseg::init();
  6545. $segList = Jieba::cut($data['keyword']);
  6546. $segList1 = array_slice($segList, 0, 8);
  6547. $data['keyword'] = implode(',', $segList1);
  6548. }
  6549. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6550. //提取内容中的描述
  6551. $content = $data['content'];
  6552. // 去除 <style> 和 <script> 标签及其内容
  6553. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6554. // 去除所有 HTML 标签
  6555. $content = strip_tags($content);
  6556. // 去除 HTML 实体
  6557. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6558. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6559. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6560. // 去除多余空白
  6561. $content = preg_replace('/\s+/u', '', $content);
  6562. // 截取 100 个字符
  6563. $data['introduce'] = mb_substr($content, 0, 100);
  6564. }
  6565. $user = User::where('id', $data['user_id'])->first();
  6566. if (empty($user)) {
  6567. return Result::error('用户不存在!');
  6568. }
  6569. if ($user['type_id'] == 10000) {
  6570. $data['status'] = 1;
  6571. }
  6572. if (isset($data['level']) && $data['level'] != null) {
  6573. $data['level'] = intval($data['level']);
  6574. } else {
  6575. $data['level'] = null;
  6576. }
  6577. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6578. $this->sendMessage([
  6579. 'talk_type' => 900,
  6580. 'title' => $data['title'],
  6581. 'content' => '提交了审核',
  6582. 'messageType' => 8,
  6583. ]);
  6584. }
  6585. $result = Company::insertGetId($data);
  6586. if ($result) {
  6587. return Result::success($result);
  6588. } else {
  6589. return Result::error('添加失败');
  6590. }
  6591. }
  6592. /**
  6593. * 更新企业
  6594. * @param array $data
  6595. * @return array
  6596. */
  6597. public function upCompany(array $data): array
  6598. {
  6599. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6600. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6601. $data['cat_arr_id'] = json_encode($car_arr_id);
  6602. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6603. } else {
  6604. $data['cat_arr_id'] = '';
  6605. }
  6606. if ($data['imgurl'] == '') {
  6607. //content中提取图片第一个图,正则提取
  6608. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6609. preg_match_all($reg, $data['content'], $matches);
  6610. if (isset($matches[1][0])) {
  6611. //截取varchar
  6612. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6613. }
  6614. }
  6615. if ($data['keyword'] == '') {
  6616. //提取标题+内容中的关键词
  6617. $data['keyword'] = $data['title'];
  6618. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6619. Jieba::init(); // 初始化 jieba-php
  6620. Finalseg::init();
  6621. $segList = Jieba::cut($data['keyword']);
  6622. $segList1 = array_slice($segList, 0, 8);
  6623. $data['keyword'] = implode(',', $segList1);
  6624. }
  6625. if ($data['introduce'] == '') {
  6626. //提取内容中的描述
  6627. $content = $data['content'];
  6628. // 去除 <style> 和 <script> 标签及其内容
  6629. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6630. // 去除所有 HTML 标签
  6631. $content = strip_tags($content);
  6632. // 去除 HTML 实体
  6633. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6634. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6635. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6636. // 去除多余空白
  6637. $content = preg_replace('/\s+/u', '', $content);
  6638. // 截取 100 个字符
  6639. $data['introduce'] = mb_substr($content, 0, 100);
  6640. }
  6641. if (isset($data['level']) && $data['level'] != null) {
  6642. $data['level'] = intval($data['level']);
  6643. } else {
  6644. $data['level'] = null;
  6645. }
  6646. $user = User::where('id', $data['user_id'])->first();
  6647. if (empty($user)) {
  6648. return Result::error('用户不存在!');
  6649. }
  6650. if ($user['type_id'] == 10000) {
  6651. $data['status'] = 1;
  6652. } else {
  6653. $data['status'] = 0;
  6654. }
  6655. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6656. $this->sendMessage([
  6657. 'talk_type' => 900,
  6658. 'title' => $data['title'],
  6659. 'content' => '提交了审核',
  6660. 'messageType' => 8,
  6661. ]);
  6662. }
  6663. $result = Company::where('id', $data['id'])->update($data);
  6664. if ($result) {
  6665. return Result::success($result);
  6666. } else {
  6667. return Result::error('修改失败');
  6668. }
  6669. }
  6670. /**
  6671. * 删除企业
  6672. * @param array $data
  6673. * @return array
  6674. */
  6675. public function delCompany(array $data): array
  6676. {
  6677. $result = Company::where('id', $data['id'])->delete();
  6678. if ($result) {
  6679. return Result::success($result);
  6680. } else {
  6681. return Result::error('删除失败');
  6682. }
  6683. }
  6684. /**
  6685. * 审核企业
  6686. * @param array $data
  6687. * @return array
  6688. */
  6689. public function checkCompany(array $data): array
  6690. {
  6691. $user = User::where('id', $data['user_id'])->first();
  6692. if (empty($user)) {
  6693. return Result::error('用户不存在!');
  6694. }
  6695. $company = Company::where('id', $data['id'])->first();
  6696. if (empty($company)) {
  6697. return Result::error('企业不存在!');
  6698. }
  6699. // 状态:0:未审核 1:已审核 2:已拒绝
  6700. if ($data['status'] == 2 || $data['status'] == '2') {
  6701. $this->sendMessage([
  6702. 'talk_type' => 901,
  6703. 'title' => $company['title'],
  6704. 'content' => '审核拒绝',
  6705. 'messageType' => 8,
  6706. 'user_id' => $company['user_id'],
  6707. ]);
  6708. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6709. } else {
  6710. if ($data['status'] == 1) {
  6711. $this->sendMessage([
  6712. 'talk_type' => 901,
  6713. 'title' => $company['title'],
  6714. 'content' => '审核通过',
  6715. 'messageType' => 8,
  6716. 'user_id' => $company['user_id'],
  6717. ]);
  6718. } else if ($data['status'] == 0) {
  6719. $this->sendMessage([
  6720. 'talk_type' => 900,
  6721. 'title' => $company['title'],
  6722. 'content' => '提交了审核',
  6723. 'messageType' => 8,
  6724. ]);
  6725. }
  6726. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6727. }
  6728. if (empty($result)) {
  6729. return Result::error('审核失败!');
  6730. } else {
  6731. return Result::success($result);
  6732. }
  6733. }
  6734. /**
  6735. * 获取企业信息
  6736. * @param array $data
  6737. * @return array
  6738. */
  6739. public function getCompanyInfo(array $data): array
  6740. {
  6741. $result = Company::where('id', $data['id'])->first();
  6742. $city_arr = json_decode($result['city_arr_id']);
  6743. $result['city_name'] = District::whereIn('id', $city_arr)
  6744. ->pluck('name')
  6745. ->implode('-');
  6746. if (empty($result)) {
  6747. return Result::error('企业不存在!');
  6748. } else {
  6749. return Result::success($result);
  6750. }
  6751. }
  6752. /**
  6753. * @param array $data
  6754. * @return array
  6755. */
  6756. public function getWebsiteCompany(array $data): array
  6757. {
  6758. $categorys = json_decode($data['id'], true);
  6759. $category_arr = $this->processArticlePro($data['website_id']);
  6760. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6761. $catiall = $category_arr['catiall'];
  6762. $categoryIds = $category_arr['categoryIds'];
  6763. // return Result::success($category_arr);
  6764. foreach ($categorys as $key => $value) {
  6765. if (array_key_exists('level', $value)) {
  6766. $parts = explode(',', $value['level']);
  6767. $level = $parts[0] ?? null;
  6768. $imgnum = $parts[1] ?? null;
  6769. $textnum = $parts[2] ?? null;
  6770. if (!empty($textnum) && $textnum > 0) {
  6771. $text_num = Company::where('level', $level)
  6772. ->whereIn('category_id', $categoryIds)
  6773. ->where('status', 1)
  6774. ->select(
  6775. 'company.id',
  6776. 'company.title',
  6777. 'company.description',
  6778. 'company.updated_at',
  6779. 'company.category_id',
  6780. 'company.cat_arr_id'
  6781. )
  6782. ->orderBy('updated_at', 'desc')
  6783. ->limit($textnum)
  6784. ->get()->all();
  6785. }
  6786. if (!empty($imgnum) && $imgnum > 0) {
  6787. $img_num = Company::where('level', $level)
  6788. ->whereIn('category_id', $categoryIds)
  6789. ->where('status', 1)
  6790. ->where('imgurl', '!=', '')
  6791. ->whereNotNull('imgurl')
  6792. ->select(
  6793. 'company.id',
  6794. 'company.title',
  6795. 'company.description',
  6796. 'company.updated_at',
  6797. 'company.imgurl as imgs',
  6798. 'company.category_id',
  6799. 'company.cat_arr_id'
  6800. )
  6801. ->orderBy('updated_at', 'desc')
  6802. ->limit($imgnum)
  6803. ->get()->all();
  6804. }
  6805. }
  6806. if (array_key_exists('id', $value)) {
  6807. $parts = explode(',', $value['id']);
  6808. $category_id = $parts[0] ?? null;
  6809. $imgnum = $parts[1] ?? null;
  6810. $textnum = $parts[2] ?? null;
  6811. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6812. if (!empty($textnum) && $textnum > 0) {
  6813. $text_num = Company::whereIn('category_id', $category_arr)
  6814. // ->where('website_id', $data['website_id'])
  6815. ->where('status', 1)
  6816. ->select(
  6817. 'company.id',
  6818. 'company.title',
  6819. 'company.description',
  6820. 'company.updated_at',
  6821. 'company.category_id',
  6822. 'company.cat_arr_id'
  6823. )
  6824. ->orderBy('updated_at', 'desc')
  6825. ->limit($textnum)
  6826. ->get()->all();
  6827. }
  6828. if (!empty($imgnum) && $imgnum > 0) {
  6829. $img_num = Company::whereIn('category_id', $category_arr)
  6830. // ->where('website_id', $data['website_id'])
  6831. ->where('status', 1)
  6832. ->where('imgurl', '!=', '')
  6833. ->whereNotNull('imgurl')
  6834. ->select(
  6835. 'company.id',
  6836. 'company.title',
  6837. 'company.description',
  6838. 'company.updated_at',
  6839. 'company.imgurl as imgs',
  6840. 'company.category_id',
  6841. 'company.cat_arr_id'
  6842. )
  6843. ->orderBy('updated_at', 'desc')
  6844. ->limit($imgnum)
  6845. ->get()->all();
  6846. }
  6847. }
  6848. if (!empty($text_num)) {
  6849. foreach ($text_num as $k => $v) {
  6850. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6851. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6852. }
  6853. }
  6854. if (!empty($img_num)) {
  6855. foreach ($img_num as $k => $v) {
  6856. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6857. $imgurl = json_decode($v['imgs'], true);
  6858. if (!empty($imgurl)) {
  6859. $img_num[$k]->imgurl = $imgurl[0];
  6860. }
  6861. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6862. }
  6863. }
  6864. $company[$key]['img_num'] = $img_num ?? [];
  6865. $company[$key]['text_num'] = $text_num ?? [];
  6866. }
  6867. if (empty($company)) {
  6868. return Result::error("暂无相关企业信息", 0);
  6869. }
  6870. return Result::success($company);
  6871. }
  6872. /**
  6873. * @param array $data
  6874. * @return array
  6875. */
  6876. public function getWebsiteCompanyList(array $data): array
  6877. {
  6878. $where['website_id'] = $data['website_id'];
  6879. $where['status'] = 1;
  6880. $categoryIds = [];
  6881. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6882. $category_id = $data['category_id'];
  6883. }
  6884. $category_arr = $this->processArticlePro($data['website_id']);
  6885. $categoryIds = $category_arr['categoryIds'];
  6886. // return Result::success($cat_1st_arr);
  6887. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  6888. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  6889. })
  6890. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  6891. $query->whereIn('category_id', $categoryIds);
  6892. })
  6893. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  6894. $query->where('category_id', $category_id);
  6895. })
  6896. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6897. ->orderBy('updated_at', 'desc')
  6898. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6899. if (empty($company)) {
  6900. return Result::error("暂无相关公司信息", 0);
  6901. }
  6902. $result = [
  6903. 'count' => $company->total(),
  6904. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  6905. ];
  6906. return Result::success($result);
  6907. }
  6908. /**
  6909. * 获取项目列表
  6910. * @param array $data
  6911. * @return array
  6912. */
  6913. public function getProjectList(array $data): array
  6914. {
  6915. $where = [];
  6916. $user = User::where('id', $data['user_id'])->first();
  6917. if (empty($user)) {
  6918. return Result::error('用户不存在!');
  6919. }
  6920. if ($user->type_id != 10000) {
  6921. array_push($where, ['project.user_id', $data['user_id']]);
  6922. }
  6923. $query = Project::query();
  6924. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6925. array_push($where, ['project.website_id', $data['website_id']]);
  6926. }
  6927. if (isset($data['title']) && !empty($data['title'])) {
  6928. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6929. }
  6930. if ($data['status'] != 3) {
  6931. array_push($where, ['project.status', $data['status']]);
  6932. }
  6933. $query = Project::where($where)
  6934. ->when($data['status'] == 3, function ($query) {
  6935. $query->whereIn('project.status', [0, 2]);
  6936. });
  6937. $count = $query->clone()
  6938. ->count();
  6939. $rows = $query->clone()
  6940. ->leftJoin('website', 'project.website_id', 'website.id')
  6941. ->leftJoin('website_category', function ($join) {
  6942. $join->on('project.website_id', '=', 'website_category.website_id')
  6943. ->on('project.category_id', '=', 'website_category.category_id');
  6944. })
  6945. ->select(
  6946. 'project.id',
  6947. 'project.title',
  6948. 'project.updated_at',
  6949. 'project.status',
  6950. 'website.website_name',
  6951. 'website_category.alias as category_name',
  6952. 'project.website_id',
  6953. 'project.user_id'
  6954. )
  6955. ->orderBy('project.updated_at', 'desc')
  6956. ->offset(($data['page'] - 1) * $data['pageSize'])
  6957. ->limit($data['pageSize'])
  6958. ->get();
  6959. if ($rows->isEmpty()) {
  6960. return Result::error("暂无相关项目信息", 0);
  6961. }
  6962. $result = [
  6963. 'count' => $count,
  6964. 'rows' => $rows,
  6965. ];
  6966. return Result::success($result);
  6967. }
  6968. /**
  6969. * 添加项目
  6970. * @param array $data
  6971. * @return array
  6972. */
  6973. public function addProject(array $data): array
  6974. {
  6975. $user = User::where('id', $data['user_id'])->first();
  6976. if (empty($user)) {
  6977. return Result::error("暂无相关用户信息", 0);
  6978. }
  6979. if ($user->type_id == 10000) {
  6980. $data['status'] = 1;
  6981. } else {
  6982. $data['status'] = 0;
  6983. }
  6984. if ($data['keyword'] == '') {
  6985. //提取标题+内容中的关键词
  6986. $data['keyword'] = $data['title'];
  6987. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6988. Jieba::init(); // 初始化 jieba-php
  6989. Finalseg::init();
  6990. $segList = Jieba::cut($data['keyword']);
  6991. $segList1 = array_slice($segList, 0, 8);
  6992. $data['keyword'] = implode(',', $segList1);
  6993. }
  6994. if ($data['description'] == '') {
  6995. //提取内容中的描述
  6996. // var_dump(11111);
  6997. //提取内容中的描述
  6998. $content = $data['introduce'];
  6999. // 去除 <style> 和 <script> 标签及其内容
  7000. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7001. // 去除所有 HTML 标签
  7002. $content = strip_tags($content);
  7003. // 去除 HTML 实体
  7004. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7005. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7006. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7007. // 去除多余空白
  7008. $content = preg_replace('/\s+/u', '', $content);
  7009. // 截取 100 个字符
  7010. $data['description'] = mb_substr($content, 0, 100);
  7011. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7012. }
  7013. if ($data['status'] == 0) {
  7014. $this->sendMessage([
  7015. 'talk_type' => 1000,
  7016. 'title' => $data['title'],
  7017. 'content' => '提交了审核',
  7018. 'messageType' => 9,
  7019. ]);
  7020. }
  7021. $project = Project::insertGetId($data);
  7022. if (empty($project)) {
  7023. return Result::error("暂无相关项目信息", 0);
  7024. }
  7025. return Result::success($project);
  7026. }
  7027. /**
  7028. * 更新项目
  7029. * @param array $data
  7030. * @return array
  7031. */
  7032. public function upProject(array $data): array
  7033. {
  7034. $project = Project::where('id', $data['id'])->first();
  7035. if (empty($project)) {
  7036. return Result::error("暂无相关项目信息", 0);
  7037. }
  7038. $id = $data['id'];
  7039. unset($data['id']);
  7040. $user = User::where('id', $data['user_id'])->first();
  7041. if (empty($user)) {
  7042. return Result::error("暂无相关用户信息", 0);
  7043. }
  7044. if ($user->type_id == 10000) {
  7045. $data['status'] = 1;
  7046. } else {
  7047. $data['status'] = 0;
  7048. }
  7049. unset($data['user_id']);
  7050. if ($data['keyword'] == '') {
  7051. //提取标题+内容中的关键词
  7052. $data['keyword'] = $data['title'];
  7053. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7054. Jieba::init(); // 初始化 jieba-php
  7055. Finalseg::init();
  7056. $segList = Jieba::cut($data['keyword']);
  7057. $segList1 = array_slice($segList, 0, 8);
  7058. $data['keyword'] = implode(',', $segList1);
  7059. }
  7060. if ($data['description'] == '') {
  7061. //提取内容中的描述
  7062. // var_dump(11111);
  7063. //提取内容中的描述
  7064. $content = $data['introduce'];
  7065. // 去除 <style> 和 <script> 标签及其内容
  7066. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7067. // 去除所有 HTML 标签
  7068. $content = strip_tags($content);
  7069. // 去除 HTML 实体
  7070. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7071. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7072. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7073. // 去除多余空白
  7074. $content = preg_replace('/\s+/u', '', $content);
  7075. // 截取 100 个字符
  7076. $data['description'] = mb_substr($content, 0, 100);
  7077. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7078. }
  7079. if ($data['status'] == 0) {
  7080. $this->sendMessage([
  7081. 'talk_type' => 1000,
  7082. 'title' => $data['title'],
  7083. 'content' => '提交了审核',
  7084. 'messageType' => 9,
  7085. ]);
  7086. }
  7087. $result = Project::where('id', $id)->update($data);
  7088. if (empty($result)) {
  7089. return Result::error("更新失败", 0);
  7090. }
  7091. return Result::success($result);
  7092. }
  7093. /**
  7094. * 删除项目
  7095. * @param array $data
  7096. * @return array
  7097. */
  7098. public function delProject(array $data): array
  7099. {
  7100. $user = User::where('id', $data['user_id'])->first();
  7101. if (empty($user)) {
  7102. return Result::error("暂无相关用户信息", 0);
  7103. }
  7104. $project = Project::where('id', $data['id'])->first();
  7105. if (empty($project)) {
  7106. return Result::error("暂无相关项目信息", 0);
  7107. }
  7108. $result = Project::where('id', $data['id'])->delete();
  7109. if (empty($result)) {
  7110. return Result::error("删除失败", 0);
  7111. }
  7112. return Result::success($result);
  7113. }
  7114. /**
  7115. * 审核项目
  7116. * @param array $data
  7117. * @return array
  7118. */
  7119. public function checkProject(array $data): array
  7120. {
  7121. $user = User::where('id', $data['user_id'])->first();
  7122. if (empty($user)) {
  7123. return Result::error("暂无相关用户信息", 0);
  7124. }
  7125. // 0:未审核; 1:已审核; 2:已拒绝;
  7126. if ($user->type_id != 10000) {
  7127. if ($data['status'] == 1 || $data['status'] == 2) {
  7128. return Result::error("此用户权限不足", 0);
  7129. }
  7130. }
  7131. $project = Project::where('id', $data['id'])->first();
  7132. if (empty($project)) {
  7133. return Result::error("暂无相关项目信息", 0);
  7134. }
  7135. if ($data['status'] == 2) {
  7136. $this->sendMessage([
  7137. 'talk_type' => 1001,
  7138. 'title' => $project['title'],
  7139. 'content' => '审核拒绝',
  7140. 'messageType' => 9,
  7141. 'user_id' => $project['user_id'],
  7142. ]);
  7143. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7144. } else {
  7145. if ($data['status'] == 1) {
  7146. $this->sendMessage([
  7147. 'talk_type' => 1001,
  7148. 'title' => $project['title'],
  7149. 'content' => '审核通过',
  7150. 'messageType' => 9,
  7151. 'user_id' => $project['user_id'],
  7152. ]);
  7153. } else if ($data['status'] == 0) {
  7154. $this->sendMessage([
  7155. 'talk_type' => 1000,
  7156. 'title' => $project['title'],
  7157. 'content' => '提交了审核',
  7158. 'messageType' => 9,
  7159. ]);
  7160. }
  7161. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7162. }
  7163. if (empty($result)) {
  7164. return Result::error("审核失败", 0);
  7165. }
  7166. return Result::success($result);
  7167. }
  7168. /**
  7169. * 获取项目详情
  7170. * @param array $data
  7171. * @return array
  7172. */
  7173. public function getProjectInfo(array $data): array
  7174. {
  7175. $project = Project::where('id', $data['id'])->first();
  7176. if (empty($project)) {
  7177. return Result::error("暂无相关项目信息", 0);
  7178. }
  7179. return Result::success($project);
  7180. }
  7181. public function getWebsiteCompanyInfo(array $data): array
  7182. {
  7183. $company = Company::where('id', $data['id'])
  7184. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7185. ->where('status', 1)
  7186. // ->where('website_id', $data['website_id'])
  7187. ->select('company.*', 'job_industry.hyname as hy_name')
  7188. ->first();
  7189. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7190. switch ($company->jobnature_id) {
  7191. case null:
  7192. $company->jobnature_name = '';
  7193. break;
  7194. case 0:
  7195. $company->jobnature_name = '市场监督';
  7196. break;
  7197. case 1:
  7198. $company->jobnature_name = '信访纪检';
  7199. break;
  7200. case 2:
  7201. $company->jobnature_name = '公检法司';
  7202. break;
  7203. case 3:
  7204. $company->jobnature_name = '高关注机构';
  7205. break;
  7206. default:
  7207. $company->jobnature_name = '';
  7208. break;
  7209. }
  7210. $city_arr = $company->city_arr_id;
  7211. if (!empty($city_arr)) {
  7212. $city_arr = json_decode($city_arr, true);
  7213. $cityNames = District::whereIn('id', $city_arr)
  7214. ->pluck('name')
  7215. ->implode('-');
  7216. $company->city_name = $cityNames;
  7217. } else {
  7218. $company->city_name = '';
  7219. }
  7220. if (empty($company)) {
  7221. return Result::error("暂无相关公司信息", 0);
  7222. }
  7223. return Result::success($company);
  7224. }
  7225. public function getMSG(array $data): array
  7226. {
  7227. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7228. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7229. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7230. $result = [];
  7231. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7232. //最近的5篇已审的文章
  7233. $apply_articale = Article::where('status', 1)
  7234. ->where('admin_user_id', $user_id)
  7235. ->orderBy('updated_at', 'desc')
  7236. // ->limit(5)
  7237. ->get();
  7238. //获取5条用户的已审核商品
  7239. $good = Good::where('status', 2)
  7240. ->where('user_id', $user_id)
  7241. ->orderBy('updated_at', 'desc')
  7242. // ->limit(5)
  7243. ->get();
  7244. //获取5条用户待审核的公告
  7245. $notice = Notice::where('status', 2)
  7246. ->where('user_id', $user_id)
  7247. ->orderBy('updated_at', 'desc')
  7248. ->limit(5)->get();
  7249. //获取5条用户的待审核投诉
  7250. $complaint = Complaint::where('status', 2)
  7251. ->where('user_id', $user_id)
  7252. ->orderBy('updated_at', 'desc')
  7253. // ->limit(5)
  7254. ->get();
  7255. //获取5条用户的book
  7256. $book = Book::where('status', 2)
  7257. ->where('user_id', $user_id)
  7258. ->orderBy('updated_at', 'desc')
  7259. // ->limit(5)
  7260. ->get();
  7261. //获取5条用户的求职
  7262. //获取5条用户的求职 1
  7263. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7264. ->where('job_hunting.user_id', $user_id)
  7265. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7266. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7267. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7268. ->orderBy('updated_at', 'desc')
  7269. // ->limit(5)
  7270. ->get();
  7271. //获取5条用户的求职 2
  7272. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7273. ->where('job_recruiting.user_id', $user_id)
  7274. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7275. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7276. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7277. ->orderBy('updated_at', 'desc')
  7278. // ->limit(5)
  7279. ->get();
  7280. //人才库 1
  7281. $job_apply = JobApply::where('job_apply.status', 1)
  7282. ->where('job_apply.receiver_id', $user_id)
  7283. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7284. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7285. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7286. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7287. ->select('job_recruiting', 'job_recruiting.', '', '')
  7288. ->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')
  7289. ->orderBy('updated_at', 'desc')
  7290. // ->limit(5)
  7291. ->get();
  7292. // 职场机会 2
  7293. $job_resume = JobResume::where('job_resume.status', 1)
  7294. ->where('job_resume.receiver_id', $user_id)
  7295. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7296. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7297. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7298. ->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')
  7299. ->orderBy('updated_at', 'desc')
  7300. // ->limit(5)
  7301. ->get();
  7302. //获取5条用户待处理的投诉
  7303. $complaint_deal = Complaint::where('status', 2)
  7304. ->where('deal', 1)
  7305. ->whereJsonContains('re_user_ids', $user_id)
  7306. ->orderBy('updated_at', 'desc')
  7307. // ->limit(5)
  7308. ->get();
  7309. //获取 被通知者未读信息
  7310. $notice_unread = Notice::where('status', 2)
  7311. ->whereJsonContains('re_user_ids', $user_id)
  7312. //未读消息
  7313. ->where(function ($query) use ($user_id) {
  7314. $query->whereJsonDoesntContain('read_id', $user_id)
  7315. ->orWhereNull('read_id');
  7316. })
  7317. ->orderBy('updated_at', 'desc')
  7318. ->get();
  7319. $complaint_unread = Complaint::where('status', 2)
  7320. ->whereJsonContains('re_user_ids', $user_id)
  7321. //未读消息
  7322. ->where(function ($query) use ($user_id) {
  7323. $query->whereJsonDoesntContain('read_id', $user_id)
  7324. ->orWhereNull('read_id');
  7325. })
  7326. ->orderBy('updated_at', 'desc')
  7327. ->get();
  7328. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7329. $complany = Company::where('status', 1)
  7330. ->where('user_id', $user_id)
  7331. ->orderBy('updated_at', 'desc')
  7332. // ->limit(5)
  7333. ->get();
  7334. //获取5条单聊未读聊天消息
  7335. // $chat = ChatRecords::where('is_read', 0)
  7336. // ->where('user_id', $user_id)
  7337. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7338. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7339. // ->where('action', 'recieved')
  7340. // ->where('talk_type', 1)
  7341. // ->orderBy('created_at', 'desc')
  7342. // // ->limit(5)
  7343. // ->get();
  7344. //获取5条未读群聊信息
  7345. // $chat_group = ChatRecords::where('is_read', 0)
  7346. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7347. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7348. // ->where('user_id', $user_id)
  7349. // ->where('talk_type', 2)
  7350. // ->orderBy('created_at', 'desc')
  7351. // // ->limit(5)
  7352. // ->get();
  7353. //获取5条用户的待审核项目
  7354. $project = Project::where('status', 1)
  7355. ->where('user_id', $user_id)
  7356. ->orderBy('updated_at', 'desc')
  7357. // ->limit(5)
  7358. ->get();
  7359. // count($chat) + count($chat_group) +
  7360. $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)
  7361. + count($complany)
  7362. + count($project)
  7363. + count($notice_unread)
  7364. + count($complaint_unread)
  7365. // + count($chat) + count($chat_group)
  7366. ;
  7367. $result = [
  7368. 'apply_articale' => $apply_articale,
  7369. // 'chat' => $chat,
  7370. // 'chat_group' => $chat_group,
  7371. 'good' => $good,
  7372. 'notice' => $notice,
  7373. 'complaint' => $complaint,
  7374. 'book' => $book,
  7375. 'job_hunting' => $job_hunting,
  7376. 'job_recruiting' => $job_recruiting,
  7377. 'job_apply' => $job_apply,
  7378. 'job_resume' => $job_resume,
  7379. 'complaint_deal' => $complaint_deal,
  7380. 'complany' => $complany,
  7381. 'project' => $project,
  7382. 'notice_unread' => $notice_unread,
  7383. 'complaint_unread' => $complaint_unread,
  7384. 'count' => $count,
  7385. ];
  7386. } elseif ($type_id == 12) {
  7387. //最近的5篇已审的文章
  7388. $apply_articale = Article::where('status', 1)
  7389. ->where('admin_user_id', $user_id)
  7390. ->limit(5)->get();
  7391. //获取5条单聊未读聊天消息
  7392. $chat = ChatRecords::where('is_read', 0)
  7393. ->where('user_id', $user_id)
  7394. ->where('talk_type', 1)
  7395. ->orderBy('created_at', 'desc')
  7396. ->limit(5)->get();
  7397. //获取5条未读群聊信息
  7398. $chat_group = ChatRecords::where('is_read', 0)
  7399. ->where('user_id', $user_id)
  7400. ->where('talk_type', 2)
  7401. ->orderBy('created_at', 'desc')
  7402. ->limit(5)->get();
  7403. //获取5条用户的已审核商品
  7404. $good = Good::where('status', 2)
  7405. ->where('user_id', $user_id)
  7406. ->orderBy('updated_at', 'desc')
  7407. ->limit(5)->get();
  7408. //获取5条用户的book
  7409. $book = Book::where('status', 2)
  7410. ->where('user_id', $user_id)
  7411. ->orderBy('updated_at', 'desc')
  7412. ->limit(5)->get();
  7413. //获取5条用户的求职
  7414. //获取5条用户的求职 1
  7415. //count($chat) + count($chat_group)
  7416. $count = count($apply_articale) + count($good);
  7417. $result = [
  7418. 'apply_articale' => $apply_articale,
  7419. 'chat' => $chat,
  7420. 'chat_group' => $chat_group,
  7421. 'good' => $good,
  7422. 'book' => $book,
  7423. 'count' => $count,
  7424. ];
  7425. } elseif ($type_id == 13) {
  7426. //最近的5篇已审的文章
  7427. $apply_articale = Article::where('status', 1)
  7428. ->where('admin_user_id', $user_id)
  7429. ->limit(5)->get();
  7430. //获取5条单聊未读聊天消息
  7431. $chat = ChatRecords::where('is_read', 0)
  7432. ->where('user_id', $user_id)
  7433. ->where('talk_type', 1)
  7434. ->orderBy('created_at', 'desc')
  7435. ->limit(5)->get();
  7436. //获取5条未读群聊信息
  7437. $chat_group = ChatRecords::where('is_read', 0)
  7438. ->where('user_id', $user_id)
  7439. ->where('talk_type', 2)
  7440. ->orderBy('created_at', 'desc')
  7441. ->limit(5)->get();
  7442. //获取5条用户的已审核商品
  7443. $good = Good::where('status', 2)
  7444. ->where('user_id', $user_id)
  7445. ->orderBy('updated_at', 'desc')
  7446. ->limit(5)->get();
  7447. //count($chat) + count($chat_group) +
  7448. $count = count($apply_articale) + count($good);
  7449. $result = [
  7450. 'apply_articale' => $apply_articale,
  7451. 'chat' => $chat,
  7452. 'chat_group' => $chat_group,
  7453. 'good' => $good,
  7454. 'count' => $count,
  7455. ];
  7456. } elseif ($type_id == 14) {
  7457. //最近的5篇已审的文章
  7458. $apply_articale = Article::where('status', 1)
  7459. ->where('admin_user_id', $user_id)
  7460. // ->limit(5)
  7461. ->get();
  7462. //获取5条用户的已审核商品
  7463. $good = Good::where('status', 2)
  7464. ->where('user_id', $user_id)
  7465. ->orderBy('updated_at', 'desc')
  7466. // ->limit(5)
  7467. ->get();
  7468. $count = count($apply_articale) + count($good);
  7469. $result = [
  7470. 'apply_articale' => $apply_articale,
  7471. 'chat' => '',
  7472. 'chat_group' => '',
  7473. 'good' => $good,
  7474. 'count' => $count,
  7475. ];
  7476. } elseif ($type_id == 10000) {
  7477. //获取未审核的5篇文章
  7478. $apply_articale = Article::where('status', 0)
  7479. ->orderBy('updated_at', 'desc')
  7480. // ->limit(5)
  7481. ->get();
  7482. //获取5条单聊未读聊天消息
  7483. //获取5条单聊未读聊天消息
  7484. // $chat = ChatRecords::where('is_read', 0)
  7485. // ->where('user_id', $user_id)
  7486. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7487. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7488. // ->where('action', 'recieved')
  7489. // ->where('talk_type', 1)
  7490. // ->orderBy('created_at', 'desc')
  7491. // // ->limit(5)
  7492. // ->get();
  7493. // //获取5条未读群聊信息
  7494. // $chat_group = ChatRecords::where('is_read', 0)
  7495. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7496. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7497. // ->where('user_id', $user_id)
  7498. // ->where('talk_type', 2)
  7499. // ->orderBy('created_at', 'desc')
  7500. // // ->limit(5)
  7501. // ->get();
  7502. //获取5条用户的已审核商品
  7503. $good = Good::where('status', 1)
  7504. // ->where('user_id', $user_id)
  7505. ->orderBy('updated_at', 'desc')
  7506. // ->limit(5)
  7507. ->get();
  7508. //获取5条用户待审核的公告
  7509. $notice = Notice::where('status', 1)
  7510. ->orderBy('updated_at', 'desc')
  7511. // ->limit(5)
  7512. ->get();
  7513. //获取5条用户的待审核投诉
  7514. $complaint = Complaint::where('status', 1)
  7515. ->orderBy('updated_at', 'desc')
  7516. // ->limit(5)
  7517. ->get();
  7518. //获取5条用户的book
  7519. $book = Book::where('status', 1)
  7520. ->orderBy('updated_at', 'desc')
  7521. // ->limit(5)
  7522. ->get();
  7523. //获取5条用户的求职 1
  7524. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7525. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7526. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7527. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7528. ->orderBy('updated_at', 'desc')
  7529. // ->limit(5)
  7530. ->get();
  7531. //获取5条用户的求职 2
  7532. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7533. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7534. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7535. ->select('job_recruiting.*', '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. //人才库 1
  7540. $job_apply = JobApply::where('job_apply.status', 1)
  7541. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7542. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7543. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7544. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7545. ->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')
  7546. ->orderBy('updated_at', 'desc')
  7547. // ->limit(5)
  7548. ->get();
  7549. // 职场机会 2
  7550. $job_resume = JobResume::where('job_resume.status', 1)
  7551. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7552. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7553. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7554. ->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')
  7555. ->orderBy('updated_at', 'desc')
  7556. // ->limit(5)
  7557. ->get();
  7558. //待审核数据com pro
  7559. $complany = Company::where('status', 0)
  7560. ->orderBy('updated_at', 'desc')
  7561. // ->limit(5)
  7562. ->get();
  7563. $project = Project::where('status', 0)
  7564. ->orderBy('updated_at', 'desc')
  7565. // ->limit(5)
  7566. ->get();
  7567. $count =
  7568. // count($chat) +
  7569. // count($chat_group) +
  7570. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7571. // + count($job_apply)
  7572. // + count($job_resume)
  7573. + count($complany)
  7574. + count($project);
  7575. $result = [
  7576. 'apply_articale' => $apply_articale,
  7577. // 'chat' => $chat,
  7578. // 'chat_group' => $chat_group,
  7579. 'good' => $good,
  7580. 'notice' => $notice,
  7581. 'complaint' => $complaint,
  7582. 'book' => $book,
  7583. 'job_hunting' => $job_hunting,
  7584. 'job_recruiting' => $job_recruiting,
  7585. // 'job_apply' => $job_apply,
  7586. // 'job_resume' => $job_resume,
  7587. 'complany' => $complany,
  7588. 'project' => $project,
  7589. 'count' => $count,
  7590. ];
  7591. } elseif ($type_id == 20000) {
  7592. }
  7593. var_dump($type_id, '-----------------test---------');
  7594. return Result::success($result);
  7595. }
  7596. /**
  7597. * @param array $data
  7598. * @return array
  7599. */
  7600. public function getWebsiteProject(array $data): array
  7601. {
  7602. $categorys = json_decode($data['id'], true);
  7603. if (!empty($categorys)) {
  7604. $category_arr = $this->processArticlePro($data['website_id']);
  7605. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7606. $catiall = $category_arr['catiall'];
  7607. // return Result::success($catiall);
  7608. foreach ($categorys as $key => $val) {
  7609. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7610. $level = explode(',', $val['level'])[0];
  7611. $imgnum = explode(',', $val['level'])[1] ?? null;
  7612. $textnum = explode(',', $val['level'])[2] ?? null;
  7613. if ($level == 1) {
  7614. if (!empty($textnum) && $textnum > 0) {
  7615. $text_num = Project::where('level', $level)
  7616. ->where('website_id', $data['website_id'])
  7617. ->where('status', 1)
  7618. ->select(
  7619. 'project.id',
  7620. 'project.title',
  7621. 'project.description',
  7622. 'project.updated_at',
  7623. 'project.category_id',
  7624. 'project.cat_arr_id'
  7625. )
  7626. ->orderBy('updated_at', 'desc')
  7627. ->limit($textnum)
  7628. ->get()->all();
  7629. }
  7630. if (!empty($imgnum) && $imgnum > 0) {
  7631. $img_num = Project::where('level', $level)
  7632. ->where('website_id', $data['website_id'])
  7633. ->where('status', 1)
  7634. ->where('imgurl', '!=', '')
  7635. ->whereNotNull('imgurl')
  7636. ->select(
  7637. 'project.id',
  7638. 'project.title',
  7639. 'project.description',
  7640. 'project.updated_at',
  7641. 'project.imgurl as imgs',
  7642. 'project.category_id',
  7643. 'project.cat_arr_id'
  7644. )
  7645. ->orderBy('updated_at', 'desc')
  7646. ->limit($imgnum)
  7647. ->get()->all();
  7648. }
  7649. } else {
  7650. if (!empty($textnum) && $textnum > 0) {
  7651. $text_num = Project::where('website_id', $data['website_id'])
  7652. ->where('status', 1)
  7653. ->select(
  7654. 'project.id',
  7655. 'project.title',
  7656. 'project.description',
  7657. 'project.updated_at',
  7658. 'project.category_id',
  7659. 'project.cat_arr_id',
  7660. 'project.website_id',
  7661. 'project.updated_at',
  7662. 'project.created_at'
  7663. )
  7664. ->orderBy('updated_at', 'desc')
  7665. ->limit($textnum)
  7666. ->get()->all();
  7667. }
  7668. if (!empty($imgnum) && $imgnum > 0) {
  7669. $img_num = Project::where('website_id', $data['website_id'])
  7670. ->where('status', 1)
  7671. ->where('imgurl', '!=', '')
  7672. ->whereNotNull('imgurl')
  7673. ->select(
  7674. 'project.id',
  7675. 'project.title',
  7676. 'project.description',
  7677. 'project.updated_at',
  7678. 'project.imgurl as imgs',
  7679. 'project.category_id',
  7680. 'project.cat_arr_id'
  7681. )
  7682. ->orderBy('updated_at', 'desc')
  7683. ->limit($imgnum)
  7684. ->get()->all();
  7685. }
  7686. }
  7687. }
  7688. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7689. $category_ids = explode(',', $val['id'])[0];
  7690. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7691. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7692. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7693. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7694. $text_num = Project::whereIn('category_id', $category_arr)
  7695. ->where('website_id', $data['website_id'])
  7696. ->where('status', 1)
  7697. ->select(
  7698. 'project.id',
  7699. 'project.title',
  7700. 'project.description',
  7701. 'project.updated_at',
  7702. 'project.category_id',
  7703. 'project.cat_arr_id'
  7704. )
  7705. ->orderBy('updated_at', 'desc')
  7706. ->limit($cat_textnum)
  7707. ->get()->all();
  7708. }
  7709. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7710. $img_num = Project::whereIn('category_id', $category_arr)
  7711. ->where('website_id', $data['website_id'])
  7712. ->where('status', 1)
  7713. ->where('imgurl', '!=', '')
  7714. ->whereNotNull('imgurl')
  7715. ->select(
  7716. 'project.id',
  7717. 'project.title',
  7718. 'project.description',
  7719. 'project.updated_at',
  7720. 'project.imgurl as imgs',
  7721. 'project.category_id',
  7722. 'project.cat_arr_id'
  7723. )
  7724. ->orderBy('updated_at', 'desc')
  7725. ->limit($cat_imgnum)
  7726. ->get()->all();
  7727. }
  7728. }
  7729. if (!empty($img_num)) {
  7730. foreach ($img_num as $k => $v) {
  7731. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7732. $imgurl = json_decode($v['imgs'], true);
  7733. if (!empty($imgurl)) {
  7734. $img_num[$k]->imgurl = $imgurl[0];
  7735. }
  7736. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7737. }
  7738. }
  7739. if (!empty($text_num)) {
  7740. foreach ($text_num as $k => $v) {
  7741. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7742. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7743. }
  7744. }
  7745. $project[$key]['img_num'] = $img_num ?? [];
  7746. $project[$key]['text_num'] = $text_num ?? [];
  7747. }
  7748. }
  7749. if (empty($project)) {
  7750. return Result::error("暂无相关项目信息", 0);
  7751. }
  7752. return Result::success($project);
  7753. }
  7754. /**
  7755. * @param array $data
  7756. * @return array
  7757. */
  7758. public function getWebsiteProjectInfo(array $data): array
  7759. {
  7760. $project = Project::where('id', $data['id'])
  7761. ->where('status', 1)
  7762. ->where('website_id', $data['website_id'])
  7763. ->select('project.*')
  7764. ->first();
  7765. if (empty($project)) {
  7766. return Result::error("暂无相关项目信息", 0);
  7767. }
  7768. return Result::success($project);
  7769. }
  7770. /**
  7771. * @param array $data
  7772. * @return array
  7773. */
  7774. public function getWebsiteProjectList(array $data): array
  7775. {
  7776. $where = [];
  7777. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7778. $where['category_id'] = $data['category_id'];
  7779. }
  7780. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7781. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7782. }
  7783. $query = Project::where($where)
  7784. ->where('status', 1)
  7785. ->where('website_id', $data['website_id'])
  7786. ->select(
  7787. 'project.id',
  7788. 'project.title',
  7789. 'project.description',
  7790. 'project.imgurl as imgs',
  7791. 'project.category_id',
  7792. 'project.cat_arr_id'
  7793. )
  7794. ->orderBy('updated_at', 'desc');
  7795. $count = $query->count();
  7796. $project = $query->clone()
  7797. ->offset(($data['page'] - 1) * $data['pageSize'])
  7798. ->limit($data['pageSize'])
  7799. ->get()->all();
  7800. if (empty($project)) {
  7801. return Result::error("暂无相关项目信息", 0);
  7802. }
  7803. $categorys = $this->processArticlePro($data['website_id']);
  7804. $catiall = $categorys['catiall'];
  7805. foreach ($project as $key => $val) {
  7806. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7807. if (!empty($val['imgs'])) {
  7808. $imgurl = json_decode($val['imgs'], true);
  7809. if (!empty($imgurl)) {
  7810. $project[$key]->imgurl = $imgurl[0];
  7811. }
  7812. } else {
  7813. $project[$key]->imgurl = '';
  7814. }
  7815. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7816. }
  7817. $result = [
  7818. 'rows' => $project,
  7819. 'count' => $count,
  7820. ];
  7821. return Result::success($result);
  7822. }
  7823. /**
  7824. * @param array $data
  7825. * @return array
  7826. */
  7827. public function getWebsiteCategoryJob(array $data): array
  7828. {
  7829. $categorys = json_decode($data['id'], true);
  7830. if (!empty($categorys)) {
  7831. $category_arr = $this->processArticlePro($data['website_id']);
  7832. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7833. $catiall = $category_arr['catiall'];
  7834. foreach ($categorys as $key => $val) {
  7835. if (isset($val['id']) && !empty($val['id'])) {
  7836. $catid = explode(',', $val['id'])[0] ?? null;
  7837. $type = explode(',', $val['id'])[1] ?? null;
  7838. $textnum = explode(',', $val['id'])[2] ?? null;
  7839. }
  7840. // 4:招聘;5:求职;
  7841. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7842. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7843. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7844. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7845. ->where('job_recruiting.status', 1)
  7846. ->where('job_recruiting.website_id', $data['website_id'])
  7847. ->select(
  7848. 'job_recruiting.id',
  7849. 'job_recruiting.title',
  7850. 'job_company.business_name',
  7851. 'job_recruiting.updated_at',
  7852. 'job_recruiting.cat_arr_id',
  7853. 'job_recruiting.keyword',
  7854. 'job_recruiting.description'
  7855. )
  7856. ->orderBy('job_recruiting.updated_at', 'desc')
  7857. ->limit($textnum)
  7858. ->get()->all();
  7859. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7860. // 状态 审核状态,1待审核2已审核3已拒绝
  7861. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7862. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7863. ->where('job_hunting.status', 2)
  7864. ->where('job_hunting.website_id', $data['website_id'])
  7865. ->select(
  7866. 'job_hunting.id',
  7867. 'job_hunting.name',
  7868. 'job_hunting.cat_arr_id',
  7869. 'job_position.zwname as job_name',
  7870. 'job_hunting.updated_at',
  7871. 'job_hunting.keyword',
  7872. 'job_hunting.slelf_evaluation'
  7873. )
  7874. ->orderBy('updated_at', 'desc')
  7875. ->limit($textnum)
  7876. ->get()->all();
  7877. } else {
  7878. $job = [];
  7879. }
  7880. // var_dump($catid.'222uuuuuuu'.$key);
  7881. if (!empty($job)) {
  7882. foreach ($job as $k => $value) {
  7883. if (isset($value->cat_arr_id)) {
  7884. $catArr = json_decode($value->cat_arr_id, true);
  7885. $catId = end($catArr);
  7886. } else {
  7887. continue;
  7888. }
  7889. if (isset($catiall[$catId])) {
  7890. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7891. }
  7892. }
  7893. }
  7894. // var_dump($catid.'xxxxx'.$key);
  7895. $result[$key] = $job ?? [];
  7896. }
  7897. }
  7898. if (empty($result)) {
  7899. return Result::error("暂无相关分类信息", 0);
  7900. }
  7901. return Result::success($result);
  7902. }
  7903. /**
  7904. * 发送消息
  7905. * @param array $messageData
  7906. * @return void
  7907. */
  7908. public function sendMessage($messageData)
  7909. {
  7910. $msg = [
  7911. 'talk_type' => $messageData['talk_type'],
  7912. 'title' => $messageData['title'],
  7913. 'content' => $messageData['content'],
  7914. 'messageType' => $messageData['messageType'],
  7915. 'user_id' => $messageData['user_id'] ?? '',
  7916. 'time' => microtime(),
  7917. ];
  7918. $message = new MqProducer($msg);
  7919. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7920. $producer->produce($message);
  7921. }
  7922. }