NewsService.php 272 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641
  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. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  65. class NewsService implements NewsServiceInterface
  66. {
  67. #[Inject]
  68. protected Redis $redis;
  69. /**
  70. * 获取导航池列表
  71. * @param array $data
  72. * @return array
  73. */
  74. public function getCategoryList(array $data): array
  75. {
  76. $search = $data['name'] ?? '';
  77. $page = (int)($data['page'] ?? 1);
  78. $perPage = (int)($data['pageSize'] ?? 10);
  79. // 1. 查出所有匹配的分类id
  80. if ($search) {
  81. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  82. if (empty($matchedIds)) {
  83. return Result::success(['rows' => [], 'total' => 0]);
  84. }
  85. // 2. 递归查所有父级,直到一级分类
  86. $idsStr = implode(',', $matchedIds);
  87. $sql = "
  88. WITH RECURSIVE parents AS (
  89. SELECT * FROM category WHERE id IN ($idsStr)
  90. UNION ALL
  91. SELECT c.* FROM category c
  92. INNER JOIN parents p ON c.id = p.pid
  93. )
  94. SELECT * FROM parents
  95. ";
  96. $parents = Db::select($sql);
  97. $parentIds = [];
  98. foreach ($parents as $row) {
  99. if ($row->pid == 0) {
  100. $parentIds[] = $row->id;
  101. }
  102. }
  103. $parentIds = array_unique($parentIds);
  104. } else {
  105. // 没有搜索,一级分类就是根
  106. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  107. }
  108. // 3. 一级分类分页
  109. $total = count($parentIds);
  110. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  111. if (empty($parentIds)) {
  112. return Result::success(['rows' => [], 'total' => $total]);
  113. }
  114. // 4. 递归查所有子孙
  115. $idsStr = implode(',', $parentIds);
  116. $sql = "
  117. WITH RECURSIVE subcategories AS (
  118. SELECT * FROM category WHERE id IN ($idsStr)
  119. UNION ALL
  120. SELECT c.* FROM category c
  121. INNER JOIN subcategories s ON c.pid = s.id
  122. )
  123. SELECT * FROM subcategories ORDER BY updated_at DESC
  124. ";
  125. $allCategories = Db::select($sql);
  126. // 5. 组装树结构
  127. $categoryMap = [];
  128. foreach ($allCategories as $cat) {
  129. $cat = (array)$cat;
  130. $cat['children'] = [];
  131. $categoryMap[$cat['id']] = $cat;
  132. }
  133. foreach ($categoryMap as $id => &$cat) {
  134. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  135. $categoryMap[$cat['pid']]['children'][] = &$cat;
  136. }
  137. }
  138. unset($cat);
  139. $categoryTree = [];
  140. foreach ($parentIds as $id) {
  141. if (isset($categoryMap[$id])) {
  142. $categoryTree[] = $categoryMap[$id];
  143. }
  144. }
  145. return Result::success([
  146. 'rows' => $categoryTree,
  147. 'total' => $total,
  148. ]);
  149. }
  150. private function findMatchedCategories($search)
  151. {
  152. if ($search) {
  153. return Category::where('name', 'like', "%{$search}%")
  154. ->orderBy('updated_at', 'desc')
  155. ->get();
  156. }
  157. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  158. ->get();
  159. }
  160. private function findAllParents($categories)
  161. {
  162. $allCategories = [];
  163. foreach ($categories as $category) {
  164. $parentId = $category->pid;
  165. while ($parentId > 0) {
  166. $parent = Category::find($parentId);
  167. if ($parent) {
  168. $allCategories[$parent->id] = $parent;
  169. $parentId = $parent->pid;
  170. } else {
  171. break;
  172. }
  173. }
  174. $allCategories[$category->id] = $category;
  175. }
  176. return array_values($allCategories);
  177. }
  178. private function buildCategoryTree($category, $allRequiredCategories)
  179. {
  180. $categoryData = $category->toArray();
  181. $children = [];
  182. foreach ($allRequiredCategories as $c) {
  183. if ($c->pid === $category->id) {
  184. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  185. }
  186. }
  187. if (!empty($children)) {
  188. $categoryData['children'] = $children;
  189. }
  190. return $categoryData;
  191. }
  192. public function myCategoryList(array $data): array
  193. {
  194. $sszq = $data['sszq'] ?? '';
  195. unset($data['sszq']);
  196. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  197. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  198. $where[] = [
  199. 'pid',
  200. '=',
  201. $data['pid'],
  202. ];
  203. if (isset($data['name'])) {
  204. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  205. }
  206. var_dump($where);
  207. //根据分类id,从category表中取出分类信息
  208. $result = Category::where($where)
  209. ->whereIn('category.id', $catorytids)
  210. ->select('category.*', 'category.id as category_id')->get();
  211. if (empty($result)) {
  212. return Result::error("没有栏目数据");
  213. }
  214. return Result::success($result);
  215. }
  216. /**
  217. * @param array $data
  218. * @return array
  219. */
  220. public function categoryList(array $data): array
  221. {
  222. $where[] = [
  223. 'pid',
  224. '=',
  225. $data['pid']
  226. ];
  227. if (isset($data['name'])) {
  228. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  229. }
  230. var_dump($where);
  231. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  232. if (empty($result)) {
  233. return Result::error("没有栏目数据");
  234. }
  235. return Result::success($result);
  236. }
  237. /**
  238. * @param array $data
  239. * @return array
  240. */
  241. public function addCategory(array $data): array
  242. {
  243. if (isset($data['id'])) {
  244. unset($data['id']);
  245. }
  246. $id = Category::insertGetId($data);
  247. if (empty($id)) {
  248. return Result::error("添加失败");
  249. }
  250. return Result::success(['id' => $id]);
  251. }
  252. /**
  253. * @param array $data
  254. * @return array
  255. */
  256. public function delCategory(array $data): array
  257. {
  258. Db::beginTransaction();
  259. try {
  260. $categoryList = Category::where(['pid' => $data['id']])->get();
  261. if ($categoryList->toArray()) {
  262. Db::rollBack();
  263. return Result::error("分类下面有子分类不能删除");
  264. }
  265. $articleList = Article::where(['catid' => $data['id']])->get();
  266. if ($articleList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有资讯不能删除");
  269. }
  270. $result = Category::where($data)->delete();
  271. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  272. if (!$result) {
  273. Db::rollBack();
  274. return Result::error("删除失败");
  275. }
  276. Db::commit();
  277. return Result::success($result);
  278. } catch (\Exception $e) {
  279. Db::rollBack();
  280. return Result::error("删除失败" . $e->getMessage());
  281. }
  282. }
  283. /**
  284. * @param array $data
  285. * @return array
  286. */
  287. public function updateCategory(array $data): array
  288. {
  289. $where = [
  290. 'id' => $data['id'],
  291. ];
  292. $result = Category::where($where)->update($data);
  293. if ($result) {
  294. return Result::success($result);
  295. } else {
  296. return Result::error("更新失败");
  297. }
  298. }
  299. /**
  300. * 获取导航池信息
  301. * @param array $data
  302. * @return array
  303. */
  304. public function getCategoryInfo(array $data): array
  305. {
  306. $where = [
  307. 'id' => $data['id'],
  308. ];
  309. $result = Category::where($where)->first();
  310. if ($result) {
  311. return Result::success($result);
  312. } else {
  313. return Result::error("更新失败");
  314. }
  315. }
  316. public function getArticleCommend(array $data): array
  317. {
  318. $where = [
  319. 'website_id' => $data['website_id'],
  320. ];
  321. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  322. var_dump($ids);
  323. if (empty($ids)) {
  324. return Result::error("没有推荐数据");
  325. }
  326. //id
  327. $whereArticle = [];
  328. if (isset($data['id'])) {
  329. $whereArticle['id'] = $data['id'];
  330. }
  331. //title like
  332. if (isset($data['title'])) {
  333. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  334. }
  335. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  336. ->where($whereArticle)
  337. ->orderBy('id', 'desc')
  338. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  339. if ($article) {
  340. $data = [
  341. 'rows' => $article->items(),
  342. 'count' => $article->total(),
  343. ];
  344. return Result::success($data);
  345. } else {
  346. return Result::error("获取失败失败");
  347. }
  348. }
  349. /**
  350. * @param array $data
  351. * @return array
  352. */
  353. public function getArticleList(array $data): array
  354. {
  355. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  356. $type_id = $data['type_id'];
  357. unset($data['type_id']);
  358. $user_id = $data['user_id'];
  359. unset($data['user_id']);
  360. $where = [];
  361. $status1 = [];
  362. if (isset($data['id']) && $data['id']) {
  363. array_push($where, ['article.id', '=', $data['id']]);
  364. }
  365. if (isset($data['title']) && $data['title']) {
  366. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  367. }
  368. if (isset($data['category_name']) && $data['category_name']) {
  369. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  370. }
  371. if (isset($data['catid']) && $data['catid']) {
  372. array_push($where, ['article.catid', '=', $data['catid']]);
  373. }
  374. if (isset($data['author']) && $data['author']) {
  375. array_push($where, ['article.author', '=', $data['author']]);
  376. }
  377. if (isset($data['islink']) && $data['islink'] !== "") {
  378. array_push($where, ['article.islink', '=', $data['islink']]);
  379. }
  380. if (isset($data['status']) && $data['status'] !== "") {
  381. array_push($where, ['article.status', '=', $data['status']]);
  382. }
  383. if (isset($data['status1'])) {
  384. $status1 = json_decode(($data['status1']));
  385. }
  386. //不是管理员展示个人数据;
  387. if ($type_id != 10000) {
  388. $where[] = ['article.admin_user_id', '=', $user_id];
  389. }
  390. $rep = Article::where($where)
  391. ->whereNotIn('article.status', [404])
  392. ->when($status1, function ($query) use ($status1) {
  393. if (isset($status1) && $status1) {
  394. $query->whereIn('article.status', $status1);
  395. }
  396. })
  397. ->leftJoin('category', 'article.catid', 'category.id')
  398. ->leftJoin('website_category', function ($join) {
  399. $join->on('article.web_site_id', '=', 'website_category.website_id')
  400. ->on('article.catid', '=', 'website_category.category_id');
  401. })
  402. ->select("article.*", "category.name as category_name", "website_category.alias")
  403. ->orderBy("article.updated_at", "desc")
  404. ->limit($data['pageSize'])
  405. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  406. $count = Article::where($where)->whereNotIn('article.status', [404])
  407. ->when($status1, function ($query) use ($status1) {
  408. if (isset($status1) && $status1) {
  409. $query->whereIn('article.status', $status1);
  410. }
  411. })
  412. ->leftJoin('category', 'article.catid', 'category.id')->count();
  413. $data = [
  414. 'rows' => $rep->toArray(),
  415. 'count' => $count,
  416. ];
  417. if (empty($rep)) {
  418. return Result::error("没有信息数据");
  419. }
  420. return Result::success($data);
  421. }
  422. /**
  423. * @param array $data
  424. * @return array
  425. */
  426. public function addArticle(array $data): array
  427. {
  428. var_dump($data, '----------12-----------1');
  429. unset($data['user_type']);
  430. unset($data['nav_add_pool_id']);
  431. // unset($data['commend_id']);
  432. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  433. Db::beginTransaction();
  434. try {
  435. //处理投票
  436. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  437. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  438. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  439. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  440. unset($data['is_survey']);
  441. unset($data['survey_name']);
  442. unset($data['suvey_array']);
  443. // unset($data['website_id']);
  444. // unset($data['web_site_id']);
  445. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  446. if ($data['hits'] == '') {
  447. $data['hits'] = 0;
  448. }
  449. if ($data['is_original'] == '') {
  450. $data['is_original'] = 0;
  451. }
  452. if ($data['status'] == '') {
  453. $data['status'] = 0;
  454. }
  455. $articleData = $data;
  456. unset($articleData['content']);
  457. //自动处理缩略图、关键字、描述
  458. if ($articleData['imgurl'] == '') {
  459. //如果没有图,设置level=0
  460. $levelArr = json_decode($articleData['level'], true);
  461. var_dump($levelArr, '----------levelArr-----------1');
  462. //content中提取图片第一个图,正则提取
  463. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  464. preg_match_all($reg, $data['content'], $matches);
  465. if (isset($matches[1][0])) {
  466. //截取varchar240
  467. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  468. //如果有图,设置level=3
  469. if (!in_array(3, $levelArr)) {
  470. $levelArr[] = 3;
  471. }
  472. $articleData['level'] = json_encode($levelArr);
  473. } else {
  474. if (!in_array(0, $levelArr)) {
  475. $levelArr[] = 0;
  476. }
  477. $articleData['level'] = json_encode($levelArr);
  478. }
  479. }
  480. var_dump($articleData['level'], '----------$articleData[level]----------1');
  481. if ($articleData['keyword'] == '') {
  482. //提取标题+内容中的关键词
  483. $articleData['keyword'] = $data['title'];
  484. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  485. Jieba::init(); // 初始化 jieba-php
  486. Finalseg::init();
  487. $segList = Jieba::cut($articleData['keyword']);
  488. $segList1 = array_slice($segList, 0, 8);
  489. $articleData['keyword'] = implode(',', $segList1);
  490. }
  491. if ($articleData['introduce'] == '') {
  492. //提取内容中的描述
  493. $content = $data['content'];
  494. // 去除 <style> 和 <script> 标签及其内容
  495. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  496. // 去除所有 HTML 标签
  497. $content = strip_tags($content);
  498. // 去除 HTML 实体
  499. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  500. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  501. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  502. // 去除多余空白
  503. $content = preg_replace('/\s+/u', '', $content);
  504. // 截取 100 个字符
  505. $articleData['introduce'] = mb_substr($content, 0, 100);
  506. }
  507. if ($articleData['status'] == 0) {
  508. $this->sendMessage([
  509. 'talk_type' => 100,
  510. 'title' => $articleData['title'],
  511. 'content' => '提交了审核',
  512. 'messageType' => 2,
  513. ]);
  514. }
  515. $id = Article::insertGetId($articleData);
  516. $articleDataContent = [
  517. 'article_id' => $id,
  518. 'content' => $data['content'],
  519. ];
  520. ArticleData::insertGetId($articleDataContent);
  521. //处理投票
  522. if ($is_survey == 1) {
  523. //生成年月日时分秒+8位随机数
  524. $uuid = date('YmdHis') . rand(10000000, 99999999);
  525. var_dump($suvey_array, 'suvey_array________');
  526. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  527. var_dump($suveys_array, '---------------------1');
  528. var_dump($suvey_array, '---------------------2');
  529. $suvey_data = [];
  530. foreach ($suveys_array as $key => $value) {
  531. if ($value == '') {
  532. continue;
  533. }
  534. if (is_array($value)) {
  535. $suvey_data[] = [
  536. 'sur_id' => $uuid,
  537. 'art_id' => $id,
  538. 'website_id' => $website_id ?? 2,
  539. 'survey_name' => $survey_name,
  540. 'choice_name' => $value[1],
  541. 'is_other' => 1,
  542. 'other_id' => 0,
  543. 'results' => 0,
  544. ];
  545. } else {
  546. $suvey_data[] = [
  547. 'sur_id' => $uuid,
  548. 'art_id' => $id,
  549. 'website_id' => $website_id ?? 2,
  550. 'survey_name' => $survey_name,
  551. 'choice_name' => $value,
  552. 'is_other' => 0,
  553. 'other_id' => 0,
  554. 'results' => 0,
  555. ];
  556. }
  557. if (empty($suvey_data)) {
  558. throw new \Exception("投票数据为空");
  559. }
  560. }
  561. $result = ArticleSurvey::insert($suvey_data);
  562. if (!$result) {
  563. throw new \Exception("投票失败,ArticleSurvey插入失败");
  564. }
  565. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  566. if (!$result) {
  567. throw new \Exception("投票失败,更新主表失败");
  568. }
  569. }
  570. Db::commit();
  571. return Result::success(['id' => $id]);
  572. } catch (\Throwable $ex) {
  573. Db::rollBack();
  574. var_dump($ex->getMessage());
  575. return Result::error("创建失败", 0);
  576. }
  577. }
  578. /**
  579. * @param array $data
  580. * @return array
  581. */
  582. public function delArticle(array $data): array
  583. {
  584. $result = Article::where($data)->delete();
  585. //survey投票删除
  586. articleSurvey::where(['art_id' => $data['id']])->delete();
  587. if (!$result) {
  588. return Result::error("删除失败");
  589. }
  590. return Result::success($result);
  591. }
  592. /**
  593. * @param array $data
  594. * @return array
  595. */
  596. public function updateArticle(array $data): array
  597. {
  598. var_dump($data, '----------12-----------1');
  599. Db::beginTransaction();
  600. unset($data['user_type']);
  601. // unset($data['web_site_id']);
  602. unset($data['nav_add_pool_id']);
  603. try {
  604. //处理投票
  605. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  606. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  607. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  608. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  609. unset($data['is_survey']);
  610. unset($data['survey_name']);
  611. unset($data['suvey_array']);
  612. unset($data['website_id']);
  613. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  614. if ($data['hits'] == '') {
  615. $data['hits'] = 0;
  616. }
  617. if ($data['is_original'] == '') {
  618. $data['is_original'] = 0;
  619. }
  620. if ($data['status'] == '') {
  621. $data['status'] = 0;
  622. }
  623. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  624. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  625. $articleData = $data;
  626. unset($articleData['content']);
  627. unset($articleData['status_name']);
  628. unset($articleData['name']);
  629. unset($articleData['content']);
  630. unset($articleData['pid_arr']);
  631. unset($articleData['pid']);
  632. //自动处理缩略图、关键字、描述
  633. if ($articleData['imgurl'] == '') {
  634. //如果没有图,设置level=0
  635. $levelArr = json_decode($articleData['level'], true);
  636. var_dump($levelArr, '----------levelArr-----------1');
  637. //content中提取图片第一个图,正则提取
  638. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  639. preg_match_all($reg, $data['content'], $matches);
  640. if (isset($matches[1][0])) {
  641. //截取varchar240
  642. // 截取到第一个<
  643. $articleData['imgurl'] = $matches[1][0];
  644. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  645. $pos = strpos($articleData['imgurl'], '"');
  646. if ($pos !== false) {
  647. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  648. }
  649. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  650. //如果有图,设置level=3
  651. if (!in_array(3, $levelArr)) {
  652. $levelArr[] = 3;
  653. }
  654. $articleData['level'] = json_encode($levelArr);
  655. } else {
  656. if (!in_array(0, $levelArr)) {
  657. $levelArr[] = 0;
  658. }
  659. $articleData['level'] = json_encode($levelArr);
  660. }
  661. }
  662. var_dump($articleData['level'], '----------$articleData[level]----------1');
  663. if ($articleData['keyword'] == '') {
  664. //提取标题+内容中的关键词
  665. $articleData['keyword'] = $data['title'];
  666. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  667. Jieba::init(); // 初始化 jieba-php
  668. Finalseg::init();
  669. $segList = Jieba::cut($articleData['keyword']);
  670. $segList1 = array_slice($segList, 0, 8);
  671. $articleData['keyword'] = implode(',', $segList1);
  672. }
  673. if ($articleData['introduce'] == '') {
  674. //提取内容中的描述
  675. $content = $data['content'];
  676. // 去除 <style> 和 <script> 标签及其内容
  677. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  678. // 去除所有 HTML 标签
  679. $content = strip_tags($content);
  680. // 去除 HTML 实体
  681. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  682. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  683. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  684. // 去除多余空白
  685. $content = preg_replace('/\s+/u', '', $content);
  686. // 截取 100 个字符
  687. $articleData['introduce'] = mb_substr($content, 0, 100);
  688. }
  689. if ($articleData['status'] == 0) {
  690. $this->sendMessage([
  691. 'talk_type' => 100,
  692. 'title' => $articleData['title'],
  693. 'content' => '提交了审核',
  694. 'messageType' => 2,
  695. ]);
  696. }
  697. $id = Article::where(['id' => $data['id']])->update($articleData);
  698. $articleDataContent = [
  699. 'content' => $data['content'],
  700. ];
  701. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  702. //处理投票
  703. $id = $data['id'];
  704. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  705. var_dump($suvey_array, 'suvey_array________delete');
  706. //处理投票
  707. if ($is_survey == 1) {
  708. //生成年月日时分秒+8位随机数
  709. $uuid = date('YmdHis') . rand(10000000, 99999999);
  710. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  711. var_dump($suveys_array, '---------------------1');
  712. $suvey_data = [];
  713. if (is_array($suveys_array)) {
  714. foreach ($suveys_array as $key => $value) {
  715. if ($value == '') {
  716. continue;
  717. }
  718. if (is_array($value)) {
  719. $suvey_data[] = [
  720. 'sur_id' => $uuid,
  721. 'art_id' => $id,
  722. 'website_id' => $website_id ?? 2,
  723. 'survey_name' => $survey_name,
  724. 'choice_name' => $value[1],
  725. 'is_other' => 1,
  726. 'other_id' => 0,
  727. 'results' => 0,
  728. ];
  729. } else {
  730. $suvey_data[] = [
  731. 'sur_id' => $uuid,
  732. 'art_id' => $id,
  733. 'website_id' => $website_id ?? 2,
  734. 'survey_name' => $survey_name,
  735. 'choice_name' => $value,
  736. 'is_other' => 0,
  737. 'other_id' => 0,
  738. 'results' => 0,
  739. ];
  740. }
  741. if (empty($suvey_data)) {
  742. throw new \Exception("投票数据为空");
  743. }
  744. }
  745. }
  746. $result = ArticleSurvey::insert($suvey_data);
  747. if (!$result) {
  748. throw new \Exception("投票失败");
  749. }
  750. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  751. if (!$result) {
  752. throw new \Exception("投票失败");
  753. }
  754. } else {
  755. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  756. }
  757. Db::commit();
  758. return Result::success([]);
  759. } catch (\Throwable $ex) {
  760. Db::rollBack();
  761. var_dump($ex->getMessage());
  762. return Result::error("更新失败" . $ex->getMessage(), 0);
  763. }
  764. }
  765. /**
  766. * 更新资讯状态
  767. * @param array $data
  768. * @return array
  769. */
  770. public function upArticleStatus(array $data): array
  771. {
  772. $articleData = Article::where(['id' => $data['id']])->first();
  773. if ($data['status'] == 1) {
  774. $this->sendMessage([
  775. 'talk_type' => 101,
  776. 'title' => $articleData['title'],
  777. 'content' => '审核通过',
  778. 'messageType' => 2,
  779. 'user_id' => $articleData['admin_user_id'],
  780. ]);
  781. }
  782. if ($data['status'] == 2) {
  783. $this->sendMessage([
  784. 'talk_type' => 101,
  785. 'title' => $articleData['title'],
  786. 'content' => '审核拒绝',
  787. 'messageType' => 2,
  788. 'user_id' => $articleData['admin_user_id'],
  789. ]);
  790. }
  791. if ($data['status'] == 0) {
  792. $this->sendMessage([
  793. 'talk_type' => 100,
  794. 'title' => $articleData['title'],
  795. 'content' => '提交了审核',
  796. 'messageType' => 2,
  797. ]);
  798. }
  799. $result = Article::where(['id' => $data['id']])->update($data);
  800. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  801. //article_ignore 表插入数据 db操作
  802. //转成数组
  803. //删掉数据重新写入
  804. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  805. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  806. $insert_data = [];
  807. foreach ($website_ids as $key => $value) {
  808. $insert_data[] = [
  809. 'article_id' => $data['id'],
  810. 'website_id' => $value,
  811. ];
  812. }
  813. DB::table('article_ignore')->insert($insert_data);
  814. }
  815. if ($result) {
  816. return Result::success();
  817. } else {
  818. return Result::error("更新状态失败", 0);
  819. }
  820. }
  821. /**
  822. * 获取新闻详情
  823. * @param array $data
  824. * @return array
  825. */
  826. public function getArticleInfo(array $data): array
  827. {
  828. $where = [
  829. 'article.id' => $data['id'],
  830. // 'article.status' => 1,
  831. ];
  832. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  833. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  834. $info = $result;
  835. // var_dump($info, 'info');
  836. $info['survey_array'] = $articleSurvey;
  837. if ($result) {
  838. return Result::success($info);
  839. } else {
  840. return Result::error("查询失败", 0);
  841. }
  842. }
  843. /**
  844. * 获取头条新闻
  845. * @param array $data
  846. * @return array
  847. */
  848. public function getWebsiteArticlett(array $data): array
  849. {
  850. $website_id = $data['website_id'];
  851. $categorys = $this->processArticlePro($website_id);
  852. $catiall = $categorys['catiall'];
  853. $categoryIds = $categorys['categoryIds'];
  854. $where = [
  855. 'status' => 1
  856. ];
  857. $website_id = $data['website_id'];
  858. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  859. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  860. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  861. switch ($data['level']) {
  862. case 1:
  863. case 2:
  864. case 3:
  865. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  866. $query = Article::where($where)
  867. ->where('level', 'like', '%' . $data['level'] . '%')
  868. ->orderBy('updated_at', 'desc');
  869. break;
  870. case 4: //最新资讯
  871. $query = Article::where($where)->orderBy('updated_at', 'desc');
  872. break;
  873. case 5: //资讯推荐
  874. $query = Article::where($where)
  875. ->where('updated_at', '>', $month);
  876. break;
  877. case 7: //资讯分类
  878. if (isset($data['id']) && !empty($data['id'])) {
  879. $keyword = Article::where('id', $data['id'])->value('keyword');
  880. $keywordArray = explode(',', $keyword);
  881. $whereL7 = [];
  882. foreach ($keywordArray as $k => $v) {
  883. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  884. }
  885. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  886. break;
  887. } else {
  888. return Result::error("请输入资讯ID", 0);
  889. break;
  890. }
  891. default:
  892. break;
  893. }
  894. // $whereL7 = [];
  895. // if(isset($data['id']) && !empty($data['id'])){
  896. // $keyword = Article::where('id', $data['id'])->value('keyword');
  897. // $keywordArray = explode(',', $keyword);
  898. // foreach ($keywordArray as $k => $v) {
  899. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  900. // }
  901. // }
  902. // $query = Article::where($where)
  903. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  904. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  905. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  906. // }
  907. // if($data['level'] == 7){
  908. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  909. // }
  910. // if($data['level'] == 4){
  911. // $query = $query->inRandomOrder()
  912. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  913. // }
  914. // if($data['level'] == 5){
  915. // $query = $query->orderBy('updated_at','desc');
  916. // }
  917. // });
  918. if ($data['textnum'] > 0) {
  919. $query = clone $query;
  920. $result['text'] = $query
  921. ->whereIn('catid', $categoryIds)
  922. ->leftJoinSub(function ($query) use ($website_id) {
  923. $query->from('article_ignore')
  924. ->where('website_id', $website_id);
  925. }, 'article_ignore', function ($join) {
  926. $join->on('article_ignore.article_id', '=', 'article.id');
  927. })
  928. ->where(function ($query) use ($website_id) {
  929. $query->whereNull('article_ignore.article_id')
  930. ->orWhere('article_ignore.website_id', '!=', $website_id);
  931. })
  932. ->select(
  933. 'article.id',
  934. 'article.title',
  935. 'article.author',
  936. 'article.updated_at',
  937. 'article.introduce',
  938. 'article.islink',
  939. 'article.linkurl',
  940. 'article.copyfrom',
  941. 'article.cat_arr_id',
  942. 'article.catid',
  943. 'article.level'
  944. )
  945. ->offset($data['placeid'])
  946. ->limit($data['textnum'])
  947. ->get()->all();
  948. foreach ($result['text'] as $k => $v) {
  949. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  950. }
  951. }
  952. if ($data['imgnum'] > 0) {
  953. $query = clone $query;
  954. $result['img'] = $query
  955. ->whereIn('catid', $categoryIds)
  956. ->where('article.imgurl', '!=', '')
  957. ->select(
  958. 'article.id',
  959. 'article.title',
  960. 'article.imgurl',
  961. 'article.author',
  962. 'article.updated_at',
  963. 'article.introduce',
  964. 'article.islink',
  965. 'article.linkurl',
  966. 'article.copyfrom',
  967. 'article.cat_arr_id',
  968. 'article.catid',
  969. 'article.level'
  970. )
  971. ->offset($data['placeid'])
  972. ->limit($data['imgnum'])
  973. ->get()->all();
  974. foreach ($result['img'] as $k => $v) {
  975. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  976. }
  977. }
  978. if (empty($result)) {
  979. return Result::error("暂无相关资讯", 0);
  980. }
  981. return Result::success($result);
  982. }
  983. /**
  984. * 获取模块新闻
  985. * @param array $data
  986. * @return array
  987. */
  988. public function getWebsiteModelArticles(array $data): array
  989. {
  990. $catid = $data['catid'];
  991. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  992. $category = $category->toArray();
  993. if (!empty($category)) {
  994. $where = [
  995. 'status' => 1,
  996. 'catid' => $catid,
  997. ];
  998. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  999. // 1:文字新闻;2:轮播图;3:图文;
  1000. // 级别:0:未分类
  1001. // 3:推荐图片
  1002. if ($data['level'] == 1) {
  1003. $data['level'] = 0;
  1004. }
  1005. $result = Article::where($where)
  1006. ->where(function ($query) use ($data) {
  1007. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1008. ->orWhereNull("level")
  1009. ->orWhereRaw("level = '[]'");
  1010. })
  1011. ->where(function ($query) use ($data) {
  1012. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1013. ->orWhereNull("ignore_ids");
  1014. })
  1015. ->orderBy("updated_at", "desc")
  1016. ->offset($placeid)
  1017. ->limit($data['pagesize'])
  1018. ->get();
  1019. if (empty($result)) {
  1020. return Result::error("此栏目暂无相关新闻", 0);
  1021. }
  1022. } else {
  1023. return Result::error("此网站暂无此栏目", 0);
  1024. }
  1025. return Result::success($result);
  1026. }
  1027. /**
  1028. *获取新闻列表
  1029. * @param array $data
  1030. * @return array
  1031. */
  1032. public function getWebsiteArticleList(array $data): array
  1033. {
  1034. // return Result::success($data);
  1035. $where[] = ['status', '=', 1];
  1036. $website_id = $data['website_id'];
  1037. if (isset($data['catid']) && !empty($data['catid'])) {
  1038. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1039. if (empty($category)) {
  1040. return Result::error("此网站暂无此栏目", 0);
  1041. }
  1042. array_push($where, ['catid', '=', $data['catid']]);
  1043. }
  1044. // return Result::success($where);
  1045. $query = Article::where($where)
  1046. ->leftJoinSub(function ($query) use ($website_id) {
  1047. $query->from('article_ignore')
  1048. ->where('website_id', $website_id);
  1049. }, 'article_ignore', function ($join) {
  1050. $join->on('article_ignore.article_id', '=', 'article.id');
  1051. })
  1052. ->where(function ($query) use ($website_id) {
  1053. $query->whereNull('article_ignore.article_id')
  1054. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1055. })
  1056. ->select(
  1057. 'article.id',
  1058. 'article.title',
  1059. 'article.imgurl',
  1060. 'article.author',
  1061. 'article.updated_at',
  1062. 'article.introduce',
  1063. 'article.islink',
  1064. 'article.linkurl',
  1065. 'article.copyfrom',
  1066. 'article.cat_arr_id',
  1067. 'article.catid'
  1068. );
  1069. $count = $query->count();
  1070. $rep = $query->orderBy("updated_at", "desc")
  1071. ->offset(($data['page'] - 1) * $data['pageSize'])
  1072. ->limit($data['pageSize'])
  1073. ->get()->all();
  1074. $categorys = $this->processArticlePro($website_id);
  1075. $cat_1st_arr = $categorys['cat_1st_arr'];
  1076. $catiall = $categorys['catiall'];
  1077. // $web['website_id'] = $data['website_id'];
  1078. foreach ($rep as $k => $v) {
  1079. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1080. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1081. }
  1082. // $rep = $this->processArticles($rep,$web);
  1083. $data = [
  1084. 'rows' => $rep,
  1085. 'count' => $count,
  1086. ];
  1087. if (empty($rep)) {
  1088. return Result::error("没有信息数据");
  1089. }
  1090. return Result::success($data);
  1091. }
  1092. /**
  1093. * 前端-获取新闻详情
  1094. * @param array $data
  1095. * @return array
  1096. */
  1097. public function selectWebsiteArticleInfo(array $data): array
  1098. {
  1099. $where = [
  1100. 'article.id' => $data['id'],
  1101. 'article.status' => 1,
  1102. ];
  1103. $result = Article::where($where)
  1104. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1105. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1106. ->where(function ($query) use ($data) {
  1107. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1108. ->orWhereNull("ignore_ids");
  1109. })
  1110. ->select(
  1111. 'article.*',
  1112. 'article_data.content',
  1113. 'article_data.article_id',
  1114. 'article_extend.website_url',
  1115. 'article_extend.email',
  1116. 'article_extend.contacts',
  1117. 'article_extend.contacts_mobile',
  1118. 'article_extend.contacts_address',
  1119. 'article_extend.zip_code',
  1120. 'article_extend.enterprise_name'
  1121. )
  1122. ->first();
  1123. if (empty($result)) {
  1124. return Result::error("暂无此新闻!", 0);
  1125. }
  1126. if(!empty($result['publiced_at']))
  1127. {
  1128. $result['updated_at'] = $result['publiced_at'];
  1129. }
  1130. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1131. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1132. ->where('website_category.website_id', $data['website_id'])
  1133. ->where(['website_category.category_id' => $result['catid']])
  1134. ->first();
  1135. if (empty($category)) {
  1136. return Result::error("查询失败", 0);
  1137. }
  1138. //手动推荐文章
  1139. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1140. if (empty($commend_ids)) {
  1141. $commendArticle = [];
  1142. } else {
  1143. //去除不存在的文章ID
  1144. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1145. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1146. ->where('article.status', 1)
  1147. ->where('website_category.website_id', $data['website_id'])
  1148. ->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')
  1149. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1150. // ->orderBy('article.updated_at', 'desc')
  1151. ->limit(5)
  1152. ->get();
  1153. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1154. foreach ($commendArticle as $k => $v) {
  1155. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1156. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1157. $cat_arr_id = array_unique($cat_arr_id);
  1158. // 从website_category取出alias_pinyin
  1159. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1160. ->whereIn('category_id', $cat_arr_id)
  1161. ->pluck('alias_pinyin', 'category_id')
  1162. ->toArray();
  1163. // 将cat_arr_id的json转成路径/隔开
  1164. $path_parts = [];
  1165. foreach ($cat_arr_id as $cat_id) {
  1166. if (isset($cat_arr[$cat_id])) {
  1167. $path_parts[] = $cat_arr[$cat_id];
  1168. }
  1169. }
  1170. $v->alias_pinyin = implode('/', $path_parts);
  1171. } else {
  1172. $v->alias_pinyin = '';
  1173. }
  1174. }
  1175. }
  1176. $result['category_id'] = $category['category_id'];
  1177. $result['cat_name'] = $category['alias'];
  1178. $result['website_name'] = $category['website_name'] ?? "";
  1179. $result['suffix'] = $category['suffix'] ?? "";
  1180. $result['commendArticle'] = $commendArticle;
  1181. $result['commend_ids'] = $commend_ids;
  1182. return Result::success($result);
  1183. }
  1184. /**
  1185. * 前端-获取网站调查问卷
  1186. * @param array $data
  1187. * @return array
  1188. */
  1189. public function getWebsiteSurvey(array $data): array
  1190. {
  1191. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1192. $website = Website::where('id', $data['website_id'])->first();
  1193. if (empty($website)) {
  1194. return Result::error("暂无此网站", 0);
  1195. }
  1196. }
  1197. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1198. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1199. if (empty($article)) {
  1200. return Result::error("暂无此文章", 0);
  1201. }
  1202. // return Result::error($data,0);
  1203. $where['art_id'] = $data['art_id'];
  1204. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1205. } else {
  1206. $survey = Article::where(function ($query) {
  1207. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1208. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1209. })
  1210. ->where('status', 1)
  1211. ->where('is_survey', 1)
  1212. ->select('survey_id')
  1213. ->orderBy('updated_at', 'desc')
  1214. ->first();
  1215. if (empty($survey)) {
  1216. return Result::error("暂无调查问卷", 0);
  1217. }
  1218. $where['sur_id'] = $survey['survey_id'];
  1219. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1220. }
  1221. // return Result::success($where);
  1222. $result = ArticleSurvey::where($where)
  1223. ->where(function ($query) {
  1224. $query->where('is_other', 0)
  1225. ->orWhere(function ($subQuery) {
  1226. $subQuery->where('is_other', 1)
  1227. ->where('other_id', 0);
  1228. });
  1229. })
  1230. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1231. ->select('article_survey.*', 'article.survey_type')
  1232. ->get()->all();
  1233. if (empty($result)) {
  1234. return Result::error("此文章暂无调查问卷", 0);
  1235. }
  1236. return Result::success($result);
  1237. }
  1238. /**
  1239. * 前端-添加网站调查问卷选项
  1240. * @param array $data
  1241. * @return array
  1242. */
  1243. public function addWebsiteSurveyOption(array $data): array
  1244. {
  1245. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1246. $website = Website::where('id', $data['website_id'])->first();
  1247. if (empty($website)) {
  1248. return Result::error("暂无此网站", 0);
  1249. }
  1250. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1251. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1252. if (empty($survey)) {
  1253. return Result::error("此调查问卷不可添加选项", 0);
  1254. }
  1255. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1256. $choice = [
  1257. 'art_id' => $survey['art_id'],
  1258. 'website_id' => $data['website_id'],
  1259. 'survey_name' => $survey['survey_name'],
  1260. 'choice_name' => $data['choice_name'],
  1261. 'sur_id' => $survey['sur_id'],
  1262. 'is_other' => 1,
  1263. 'other_id' => $survey['id'],
  1264. ];
  1265. $result = ArticleSurvey::insertGetId($choice);
  1266. if (empty($result)) {
  1267. return Result::error("添加失败", 0);
  1268. }
  1269. return Result::success($result);
  1270. }
  1271. }
  1272. return Result::error("添加失败", 0);
  1273. }
  1274. return Result::error("添加失败", 0);
  1275. }
  1276. /**
  1277. * 前端-调查问卷投票
  1278. * @param array $data
  1279. * @return array
  1280. */
  1281. public function addWebsiteSurveyVote(array $data): array
  1282. {
  1283. // return Result::success($data);
  1284. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1285. $website = Website::where('id', $data['website_id'])->first();
  1286. if (empty($website)) {
  1287. return Result::error("暂无此网站", 0);
  1288. }
  1289. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1290. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1291. // return Result::success($survey);
  1292. if (empty($is_survey)) {
  1293. return Result::error("此调查问卷不存在", 0);
  1294. }
  1295. // return Result::success($survey);
  1296. // 调查问卷类型
  1297. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1298. //多选 若是json型则转化成数组类型
  1299. if (strpos($data['choice_id'], '[') === 0) {
  1300. $data['choice_id'] = json_decode($data['choice_id'], true);
  1301. } else {
  1302. // 单选 也转换成数组
  1303. $data['choice_id'] = [$data['choice_id']];
  1304. }
  1305. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1306. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1307. // ->where('website_id',$data['website_id'])
  1308. ->where('is_other', 1)
  1309. ->where('other_id', 0)
  1310. ->first();
  1311. if (!empty($other)) {
  1312. return Result::error("请选择已有的选项!", 0);
  1313. }
  1314. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1315. // ->where('website_id',$data['website_id'])
  1316. ->where('is_other', 1)
  1317. ->where('other_id', '!=', 0)
  1318. ->first();
  1319. // return Result::success($choice['other']);
  1320. $choice_id = $data['choice_id'];
  1321. if (!empty($choice['other'])) {
  1322. // array_push($data['choice_id'],$choice['other']['other_id']);
  1323. if (!empty($choice_id)) {
  1324. $key = array_search($choice['other']['id'], $choice_id);
  1325. if ($key !== false) {
  1326. unset($choice_id[$key]);
  1327. $choice_id = array_values($choice_id);
  1328. }
  1329. array_push($choice_id, $choice['other']['other_id']);
  1330. } else {
  1331. $choice_id[0] = $choice['other']['other_id'];
  1332. }
  1333. array_push($data['choice_id'], $choice['other']['other_id']);
  1334. }
  1335. // return Result::success($data);
  1336. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1337. // ->where('website_id',$data['website_id'])
  1338. ->increment('results', 1);
  1339. if (empty($choice)) {
  1340. return Result::error("请选择已有的选项!", 0);
  1341. }
  1342. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1343. // ->where('website_id',$data['website_id'])
  1344. ->where('other_id', 0)
  1345. ->get();
  1346. $survey['choice'] = $choice_id;
  1347. return Result::success($survey);
  1348. }
  1349. return Result::error("参数必填!");
  1350. }
  1351. return Result::error("此调查问卷不存在", 0);
  1352. }
  1353. return Result::error("参数必填!");
  1354. }
  1355. /**
  1356. * 后端-获取网站调查问卷列表
  1357. * @param array $data
  1358. * @return array
  1359. */
  1360. public function getSurveyList(array $data): array
  1361. {
  1362. $where = [];
  1363. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1364. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1365. }
  1366. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1367. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1368. }
  1369. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1370. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1371. }
  1372. // return Result::success($where);
  1373. if (!empty($where)) {
  1374. $query = Article::where($where)->where(function ($q) {
  1375. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1376. });
  1377. } else {
  1378. $query = Article::where(function ($q) {
  1379. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1380. });
  1381. }
  1382. $count = $query->count();
  1383. $survey = $query->orderByDesc('id')
  1384. ->limit($data['pageSize'])
  1385. ->offset(($data['page'] - 1) * $data['pageSize'])
  1386. ->get();
  1387. if (empty($survey->toArray())) {
  1388. return Result::error("暂无调查问卷!", 0);
  1389. }
  1390. $result = [
  1391. 'rows' => $survey,
  1392. 'count' => $count,
  1393. ];
  1394. return Result::success($result);
  1395. }
  1396. /**
  1397. * 后端-获取网站调查问卷详情
  1398. * @param array $data
  1399. * @return array
  1400. */
  1401. public function getSurveyInfo(array $data): array
  1402. {
  1403. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1404. $where = ['sur_id' => $data['sur_id']];
  1405. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1406. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1407. ->select('article_survey.*', 'article.survey_type')
  1408. ->get()->all();
  1409. if (empty($choose)) {
  1410. return Result::error("此调查问卷不存在", 0);
  1411. }
  1412. $resultsArray = array_column($choose, 'results');
  1413. $total = array_sum($resultsArray);
  1414. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1415. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1416. // $total = 0;
  1417. if (!empty($other)) {
  1418. $total = $total + $other['results'];
  1419. $other['choice_name'] = '(其他)';
  1420. if (!empty($others)) {
  1421. $other['hasChildren'] = true;
  1422. // array_push($other,['hasChildren','=',true]);
  1423. $other['children'] = $others;
  1424. $other_choices = [$other->toArray()];
  1425. $mer_choice = array_merge($choose, $other_choices);
  1426. $value_choice = array_values($mer_choice);
  1427. } else {
  1428. // return Result::error('1111');
  1429. $other_choices = [$other->toArray()];
  1430. $other_choices = array_merge($choose, $other_choices);
  1431. $value_choice = array_values($other_choices);
  1432. // return Result::success($result);
  1433. }
  1434. } else {
  1435. $value_choice = $choose;
  1436. }
  1437. $result = [
  1438. 'choose' => $value_choice,
  1439. 'total' => $total,
  1440. ];
  1441. }
  1442. return Result::success($result);
  1443. }
  1444. /**
  1445. * 前端-搜索新闻列表
  1446. * @param array $data
  1447. * @return array
  1448. */
  1449. public function selectWebsiteArticle(array $data): array
  1450. {
  1451. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1452. $website_id = $data['website_id'];
  1453. $categorys = $this->processArticlePro($website_id);
  1454. $catiall = $categorys['catiall'];
  1455. $query = Article::where('status', 1)
  1456. ->whereIn('catid', $category)
  1457. ->leftJoinSub(function ($query) use ($website_id) {
  1458. $query->from('article_ignore')
  1459. ->where('website_id', $website_id);
  1460. }, 'article_ignore', function ($join) {
  1461. $join->on('article_ignore.article_id', '=', 'article.id');
  1462. })
  1463. ->where(function ($query) use ($website_id) {
  1464. $query->whereNull('article_ignore.article_id')
  1465. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1466. });
  1467. // return Result::success($all_articles);
  1468. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1469. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1470. }
  1471. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1472. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1473. }
  1474. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1475. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1476. }
  1477. // 计算总数
  1478. $count = $query->count();
  1479. // 分页查询
  1480. $articles = $query
  1481. ->select(
  1482. 'article.id',
  1483. 'article.title',
  1484. 'article.imgurl',
  1485. 'article.author',
  1486. 'article.updated_at',
  1487. 'article.introduce',
  1488. 'article.islink',
  1489. 'article.linkurl',
  1490. 'article.copyfrom',
  1491. 'article.cat_arr_id',
  1492. 'article.catid',
  1493. 'article.department_arr_id',
  1494. 'article.city_arr_id',
  1495. )
  1496. ->orderBy("updated_at", "desc")
  1497. ->offset(($data['page'] - 1) * $data['pageSize'])
  1498. ->limit($data['pageSize'])
  1499. ->get();
  1500. foreach ($articles as $k => $v) {
  1501. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1502. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1503. }
  1504. if (empty($articles)) {
  1505. return Result::error("没有符合条件的资讯数据");
  1506. }
  1507. $result = [
  1508. 'rows' => $articles,
  1509. 'count' => $count,
  1510. ];
  1511. return Result::success($result);
  1512. }
  1513. /**
  1514. * 模块新闻加强版
  1515. * @param array $data
  1516. * @return array
  1517. */
  1518. public function getWebsiteCatidArticle(array $data): array
  1519. {
  1520. $where = [
  1521. 'website_category.category_id' => $data['catid'],
  1522. 'website_category.website_id' => $data['website_id'],
  1523. ];
  1524. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1525. $child_catnum = $data['child_catnum'] ?? 1;
  1526. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1527. $childCategoryIds = array_column($category['child'], 'category_id');
  1528. if (empty($childCategoryIds)) {
  1529. return Result::error("暂无子栏目", 0);
  1530. }
  1531. $imgArticles = [];
  1532. $textArticles = [];
  1533. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1534. // 初始化子分类图片新闻和文字新闻数组
  1535. // 查询所有子级栏目的图文新闻
  1536. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1537. ->where(function ($query) use ($data) {
  1538. $query->where(function ($subQuery) use ($data) {
  1539. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1540. })->orWhereNull("ignore_ids");
  1541. })
  1542. ->where('status', 1)
  1543. ->where('imgurl', '!=', '')
  1544. ->select('*')
  1545. ->orderBy('updated_at', 'desc')
  1546. ->limit($data['child_imgnum'])
  1547. ->get();
  1548. }
  1549. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1550. // 查询所有子级栏目的文字新闻
  1551. $textArticles = Article::where('catid', $childCategoryIds[0])
  1552. ->where('status', 1)
  1553. ->where(function ($query) use ($data) {
  1554. $query->where(function ($subQuery) use ($data) {
  1555. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1556. })->orWhereNull("ignore_ids");
  1557. })
  1558. ->select('*')
  1559. ->orderBy('updated_at', 'desc')
  1560. ->limit($data['child_textnum'])
  1561. ->get();
  1562. }
  1563. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1564. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1565. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1566. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1567. return $child;
  1568. }, $category['child']);
  1569. }
  1570. // }
  1571. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1572. $category['img'] = WebsiteCategory::where($where)
  1573. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1574. ->where('article.status', 1)
  1575. ->where('article.imgurl', '!=', '')
  1576. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1577. ->orderBy('article.updated_at', 'desc')
  1578. ->limit($data['img_num'])
  1579. ->get();
  1580. }
  1581. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1582. $category['text'] = WebsiteCategory::where($where)
  1583. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1584. ->where('article.status', 1)
  1585. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1586. ->orderBy('article.updated_at', 'desc')
  1587. ->limit($data['text_num'])
  1588. ->get();
  1589. }
  1590. // $category = $category->get();
  1591. if (empty($category)) {
  1592. return Result::error("查询失败", 0);
  1593. }
  1594. return Result::success($category);
  1595. }
  1596. /**
  1597. * 模块新闻加强plus版
  1598. * @param array $data
  1599. * @return array
  1600. */
  1601. public function getWebsiteAllArticle(array $data): array
  1602. {
  1603. $time1 = microtime(true);
  1604. $wetbsite_id = $data['website_id'] ?? 2;
  1605. $data = json_decode($data['id'], true);
  1606. $categorys = $this->processArticlePro($wetbsite_id);
  1607. $cat_1st_arr = $categorys['cat_1st_arr'];
  1608. $catiall = $categorys['catiall'];
  1609. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1610. $parent_category = array_column($data, 'parent');
  1611. $parent_cat = [];
  1612. $child_category = array_column($data, 'child');
  1613. if (!empty($parent_category)) {
  1614. foreach ($parent_category as $key => $value) {
  1615. $arr = array_map('intval', explode(',', $value));
  1616. $parent_cat[$key] = $arr[0] ?? 0;
  1617. $parent_category = $arr[0] ?? 0;
  1618. $article_imgnum = $arr[1] ?? 0;
  1619. $article_textnum = $arr[2] ?? 0;
  1620. if ($parent_category != 0) {
  1621. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1622. // return Result::success($category_arr);
  1623. if ($article_imgnum != 0) {
  1624. $img_article = Article::whereIn('catid', $category_arr)
  1625. ->where('status', 1)
  1626. ->where('imgurl', '!=', '')
  1627. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1628. $query->from('article_ignore')
  1629. ->where('website_id', $wetbsite_id);
  1630. }, 'article_ignore', function ($join) {
  1631. $join->on('article_ignore.article_id', '=', 'article.id');
  1632. })
  1633. ->where(function ($query) use ($wetbsite_id) {
  1634. $query->whereNull('article_ignore.article_id')
  1635. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1636. })
  1637. ->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')
  1638. ->orderBy('updated_at', 'desc')
  1639. ->limit($article_imgnum)
  1640. ->get()->all();
  1641. foreach ($img_article as $k => $v) {
  1642. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1643. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1644. }
  1645. } else {
  1646. $img_article = [];
  1647. }
  1648. if ($article_textnum != 0) {
  1649. $text_article = Article::whereIn('catid', $category_arr)
  1650. ->where('status', 1)
  1651. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1652. $query->from('article_ignore')
  1653. ->where('website_id', $wetbsite_id);
  1654. }, 'article_ignore', function ($join) {
  1655. $join->on('article_ignore.article_id', '=', 'article.id');
  1656. })
  1657. ->where(function ($query) use ($wetbsite_id) {
  1658. $query->whereNull('article_ignore.article_id')
  1659. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1660. })
  1661. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1662. ->orderBy('updated_at', 'desc')
  1663. ->limit($article_textnum)
  1664. ->get()->all();
  1665. foreach ($text_article as $k => $v) {
  1666. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1667. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1668. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1669. }
  1670. } else {
  1671. $text_article = [];
  1672. }
  1673. $catiall[$parent_category]['imgnum'] = $img_article;
  1674. $catiall[$parent_category]['textnum'] = $text_article;
  1675. $parent[$key] = $catiall[$parent_category];
  1676. } else {
  1677. $parent[$key] = '';
  1678. }
  1679. }
  1680. }
  1681. if (!empty($child_category)) {
  1682. foreach ($child_category as $key => $value) {
  1683. $arr = array_map('intval', explode(',', $value));
  1684. $parent_category = $parent_cat[$key];
  1685. $child_category = $arr[0] ?? 0;
  1686. $article_imgnum = $arr[1] ?? 0;
  1687. $article_textnum = $arr[2] ?? 0;
  1688. if ($child_category != 0) {
  1689. $all_childcat = $cat_1st_arr[$parent_category];
  1690. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1691. // 从 $websiteInfoIndexed 中获取对应的数据
  1692. $info = $websiteInfoIndexed[$v];
  1693. // 返回一个包含所需信息的数组
  1694. return [
  1695. 'alias' => $info->alias,
  1696. 'category_id' => $info->category_id,
  1697. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1698. 'pid' => $info->pid,
  1699. 'type' => $info->type,
  1700. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1701. 'pinyin' => $info->pinyin,
  1702. ];
  1703. }, $all_childcat);
  1704. if ($article_imgnum != 0) {
  1705. $img_article = Article::where('catid', $child_category)
  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('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1719. ->orderBy('updated_at', 'desc')
  1720. ->limit($article_imgnum)
  1721. ->get()->all();
  1722. foreach ($img_article as $k => $v) {
  1723. // var_dump($v);
  1724. // var_dump($k);
  1725. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1726. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1727. }
  1728. } else {
  1729. $img_article = [];
  1730. }
  1731. if ($article_textnum != 0) {
  1732. $text_article = Article::where('catid', $child_category)
  1733. ->where('status', 1)
  1734. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1735. $query->from('article_ignore')
  1736. ->where('website_id', $wetbsite_id);
  1737. }, 'article_ignore', function ($join) {
  1738. $join->on('article_ignore.article_id', '=', 'article.id');
  1739. })
  1740. ->where(function ($query) use ($wetbsite_id) {
  1741. $query->whereNull('article_ignore.article_id')
  1742. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1743. })
  1744. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1745. ->orderBy('updated_at', 'desc')
  1746. ->limit($article_textnum)
  1747. ->get()->all();
  1748. foreach ($text_article as $k => $v) {
  1749. // var_dump($v);
  1750. // var_dump($k);
  1751. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1752. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1753. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1754. }
  1755. } else {
  1756. $text_article = [];
  1757. }
  1758. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1759. $catiall[$child_category]['imgnum'] = $img_article;
  1760. $catiall[$child_category]['textnum'] = $text_article;
  1761. $child[$key] = $catiall[$child_category];
  1762. // var_dump($pids);
  1763. } else {
  1764. $child[$key] = '';
  1765. }
  1766. }
  1767. }
  1768. foreach ($parent as $key => $value) {
  1769. $result[$key] = $value;
  1770. if (!empty($child[$key])) {
  1771. // var_dump($child[$key]);
  1772. $result[$key]['child'] = $child[$key];
  1773. // $value[$key]['child'] = $child[$key];
  1774. } else {
  1775. $result[$key]['child'] = [
  1776. "alias" => null,
  1777. "category_id" => null,
  1778. "type" => null,
  1779. "pinyin" => null,
  1780. "all_childcat" => [],
  1781. "imgnum" => [],
  1782. "textnum" => []
  1783. ];
  1784. }
  1785. }
  1786. return Result::success($result);
  1787. }
  1788. /**
  1789. * 辅助方法:获取文章列表
  1790. */
  1791. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1792. {
  1793. sleep(1);
  1794. $query = Article::where('article.status', 1)
  1795. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1796. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1797. ->where(function ($query) use ($website) {
  1798. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1799. })
  1800. ->leftJoin('website_category', function ($join) use ($website) {
  1801. $join->on('article.catid', '=', 'website_category.category_id')
  1802. ->where('website_category.website_id', '=', $website['website_id']);
  1803. })
  1804. ->select(
  1805. 'article.id',
  1806. 'article.title',
  1807. 'article.imgurl',
  1808. 'article.author',
  1809. 'article.updated_at',
  1810. 'article.introduce',
  1811. 'article.islink',
  1812. 'article.linkurl',
  1813. 'article.copyfrom',
  1814. 'article.cat_arr_id',
  1815. 'article.catid',
  1816. 'website_category.alias as category_name'
  1817. )
  1818. ->orderBy('updated_at', 'desc')
  1819. ->limit($limit);
  1820. // 如果是图片文章,添加图片URL条件
  1821. if ($isImageArticle) {
  1822. $query->where('imgurl', '!=', '');
  1823. } else {
  1824. // 文字文章不需要imgurl字段
  1825. $query->addSelect('article.introduce');
  1826. }
  1827. $articles = $query->get();
  1828. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1829. }
  1830. /**
  1831. * 乡村网-获取特殊新闻模块
  1832. * @param array $data
  1833. * @return array
  1834. */
  1835. public function getWebsiteArticles(array $data): array
  1836. {
  1837. $website_id = $data['website_id'];
  1838. $catids = json_decode($data['id'], true);
  1839. $parent_category = array_column($catids, 'parent');
  1840. if (!empty($parent_category) && is_array($parent_category)) {
  1841. $categorys = $this->processArticlePro($website_id);
  1842. $catiall = $categorys['catiall'];
  1843. $cat_1st_arr = $categorys['cat_1st_arr'];
  1844. // return Result::success($categorys);
  1845. foreach ($parent_category as $key => $value) {
  1846. $arr = array_map('intval', explode(',', $value));
  1847. $parent_category = $arr[0] ?? 0;
  1848. $article_imgnum = $arr[1] ?? 0;
  1849. $article_textnum = $arr[2] ?? 0;
  1850. if ($parent_category != 0) {
  1851. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1852. // return Result::success($category_arr);
  1853. if ($article_imgnum != 0) {
  1854. $img_article = Article::whereIn('catid', $category_arr)
  1855. ->where('status', 1)
  1856. ->where('imgurl', '!=', '')
  1857. ->leftJoinSub(function ($query) use ($website_id) {
  1858. $query->from('article_ignore')
  1859. ->where('website_id', $website_id);
  1860. }, 'article_ignore', function ($join) {
  1861. $join->on('article_ignore.article_id', '=', 'article.id');
  1862. })
  1863. ->where(function ($query) use ($website_id) {
  1864. $query->whereNull('article_ignore.article_id')
  1865. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1866. })
  1867. ->select(
  1868. 'id',
  1869. 'title',
  1870. 'imgurl',
  1871. 'author',
  1872. 'updated_at',
  1873. 'introduce',
  1874. 'islink',
  1875. 'linkurl',
  1876. 'copyfrom',
  1877. 'cat_arr_id',
  1878. 'catid as category_id'
  1879. )
  1880. ->orderBy('updated_at', 'desc')
  1881. ->limit($article_imgnum)
  1882. ->get()->all();
  1883. foreach ($img_article as $k => $v) {
  1884. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1885. // return Result::success($v);
  1886. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1887. }
  1888. } else {
  1889. $img_article = [];
  1890. }
  1891. if ($article_textnum != 0) {
  1892. $text_article = Article::whereIn('catid', $category_arr)
  1893. ->where('status', 1)
  1894. ->leftJoinSub(function ($query) use ($website_id) {
  1895. $query->from('article_ignore')
  1896. ->where('website_id', $website_id);
  1897. }, 'article_ignore', function ($join) {
  1898. $join->on('article_ignore.article_id', '=', 'article.id');
  1899. })
  1900. ->where(function ($query) use ($website_id) {
  1901. $query->whereNull('article_ignore.article_id')
  1902. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1903. })
  1904. ->select(
  1905. 'id',
  1906. 'title',
  1907. 'author',
  1908. 'updated_at',
  1909. 'introduce',
  1910. 'islink',
  1911. 'linkurl',
  1912. 'copyfrom',
  1913. 'cat_arr_id',
  1914. 'catid as category_id'
  1915. )
  1916. ->orderBy('updated_at', 'desc')
  1917. ->limit($article_textnum)
  1918. ->get()->all();
  1919. foreach ($text_article as $k => $v) {
  1920. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1921. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1922. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1923. }
  1924. } else {
  1925. $text_article = [];
  1926. }
  1927. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  1928. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  1929. $parent[$key] = $catiall[$parent_category];
  1930. } else {
  1931. $parent[$key] = [];
  1932. }
  1933. }
  1934. }
  1935. return Result::success($parent);
  1936. }
  1937. // 封装处理商品的路由问题
  1938. function processGoods($goods, $data)
  1939. {
  1940. return $goods->map(function ($good) use ($data) {
  1941. $catid = $good->catid ?? 0;
  1942. // $pinyin = '';
  1943. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1944. if (!empty($category->pid) && $category->pid != 0) {
  1945. $level = json_decode($category->category_arr_id, true);
  1946. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1947. ->whereIn('category_id', $level)
  1948. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1949. ->get(['aLIas_pinyin'])
  1950. ->pluck('aLIas_pinyin')
  1951. ->implode('/');
  1952. } else {
  1953. $pinyin = $category->aLIas_pinyin ?? '';
  1954. }
  1955. if (isset($good->city_id) && !empty($good->city_id)) {
  1956. $city = District::where('id', $good->city_id)->first(['name']);
  1957. $good->city_name = $city->name ?? '';
  1958. }
  1959. // 解析imgurl JSON并取第一条数据
  1960. $imgUrls = json_decode($good->imgurl, true);
  1961. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1962. $good->pinyin = $pinyin;
  1963. return $good;
  1964. });
  1965. }
  1966. /**
  1967. * 获取商城首页-根据栏目id
  1968. * @param array $data
  1969. * @return array
  1970. * */
  1971. function getWebsiteCatidshop(array $data): array
  1972. {
  1973. $input['catid'] = $data['catid'];
  1974. $input['website_id'] = $data['website_id'];
  1975. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1976. $result = array_map(function ($item) use ($input) {
  1977. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1978. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1979. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1980. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1981. if (empty($category) || $category->type != 2) {
  1982. return Result::error("暂无此栏目", 0);
  1983. } else {
  1984. $website['website_id'] = $input['website_id'];
  1985. $goods = Good::where('good.status', 2)
  1986. ->where('good.website_id', $website['website_id'])
  1987. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1988. ->select(
  1989. 'good.id',
  1990. 'good.name',
  1991. 'good.imgurl',
  1992. 'good.description',
  1993. 'good.updated_at',
  1994. 'good.catid',
  1995. 'good.type_id',
  1996. 'good.price',
  1997. 'good.com',
  1998. 'good.level',
  1999. 'good.unit'
  2000. )
  2001. ->orderBy('updated_at', 'desc')
  2002. ->offset($goodStart)
  2003. ->limit($goodNum);
  2004. $all_goods = $goods->get();
  2005. $all_goods = $this->processGoods($all_goods, $website);
  2006. }
  2007. return $all_goods ?? [];
  2008. }
  2009. }, $data);
  2010. return Result::success($result);
  2011. }
  2012. /**
  2013. * 获取商品模块
  2014. * @param array $data
  2015. * @return array
  2016. * */
  2017. public function getWebsiteshop(array $data): array
  2018. {
  2019. $input['id'] = $data['id'];
  2020. $input['website_id'] = $data['website_id'];
  2021. $catid = $data['catid'];
  2022. $data = json_decode($input['id'] ?? '', true) ?? [];
  2023. $result['goods'] = array_map(function ($item) use ($input) {
  2024. // 检查parent元素是否存在且不是undefined
  2025. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2026. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2027. $website = $input['website_id'];
  2028. $query = Good::where('good.status', 2)
  2029. ->where('good.website_id', $website);
  2030. switch ($Levelid) {
  2031. case 1:
  2032. case 2:
  2033. case 3:
  2034. $goods = $query->where(function ($q) use ($Levelid) {
  2035. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2036. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2037. });
  2038. break;
  2039. case 4:
  2040. $goods = $query;
  2041. break;
  2042. case 5:
  2043. $goods = $query->where('type_id', 1);
  2044. break;
  2045. case 6:
  2046. $goods = $query->where('type_id', 2);
  2047. break;
  2048. default:
  2049. return [];
  2050. }
  2051. $all_goods = $goods
  2052. ->select(
  2053. 'good.id',
  2054. 'good.name',
  2055. 'good.imgurl',
  2056. 'good.description',
  2057. 'good.updated_at',
  2058. 'good.catid',
  2059. 'good.type_id',
  2060. 'good.price',
  2061. 'good.level',
  2062. 'good.website_id'
  2063. )
  2064. ->orderBy('updated_at', 'desc')
  2065. ->offset($goodStart)
  2066. ->limit($goodNum)
  2067. ->get();
  2068. $web['website_id'] = $website;
  2069. $all_goods = $this->processGoods($all_goods, $web);
  2070. }
  2071. return $all_goods;
  2072. }, $data);
  2073. $website = $input['website_id'];
  2074. $result['article'] = Article::where(function ($query) use ($website) {
  2075. $query->where(function ($subQuery) use ($website) {
  2076. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2077. })->orWhereNull("ignore_ids");
  2078. })
  2079. ->where('catid', $catid)
  2080. ->where('article.status', 1)
  2081. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2082. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2083. ->orderBy('article.updated_at', 'desc')
  2084. ->first();
  2085. return Result::success($result);
  2086. }
  2087. /**
  2088. * 获取商品分类
  2089. * @param array $data
  2090. * @return array
  2091. * */
  2092. public function getWebsiteshopCat(array $data): array
  2093. {
  2094. $website = $data['website_id'];
  2095. $category = WebsiteCategory::where('website_id', $website)
  2096. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2097. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2098. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2099. ->orderBy('sort')
  2100. ->get();
  2101. $cat = $category->map(function ($item) use ($website) {
  2102. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2103. $pid = $item->pid ?? 0;
  2104. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2105. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2106. ->where('website_id', $website)
  2107. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2108. ->get(['aLIas_pinyin'])
  2109. ->pluck('aLIas_pinyin')
  2110. ->implode('/');
  2111. } else {
  2112. $pinyin = $item->aLIas_pinyin ?? '';
  2113. }
  2114. $item->pinyin = $pinyin;
  2115. });
  2116. if (empty($category)) {
  2117. return Result::error("栏目查询失败", 0);
  2118. }
  2119. $cat_tree = Result::buildMenuTree($category);
  2120. $web['website_id'] = $website;
  2121. $goods = Good::where('website_id', $website)
  2122. ->where('status', 2)
  2123. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2124. ->latest('updated_at')
  2125. ->offset(($data['page'] - 1) * $data['pageSize'])
  2126. ->limit($data['pageSize'])
  2127. ->get();
  2128. if (!empty($goods)) {
  2129. if ($goods->count() > 1 && !empty($goods)) {
  2130. $goods = $this->processGoods($goods, $web);
  2131. }
  2132. } else {
  2133. $goods = [];
  2134. }
  2135. $result = [
  2136. 'category' => $cat_tree,
  2137. 'goods' => $goods,
  2138. ];
  2139. // $resul['goods'] = $goods;
  2140. if (empty($result)) {
  2141. return Result::error("查询失败", 0);
  2142. }
  2143. return Result::success($result);
  2144. }
  2145. /*
  2146. * 获取商品列表
  2147. * @param array $data
  2148. * @return array
  2149. * */
  2150. public function getWebsiteshopList(array $data): array
  2151. {
  2152. // return Result::success($data);
  2153. $where = [
  2154. 'status' => 2,
  2155. 'website_id' => $data['website_id'],
  2156. ];
  2157. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2158. // return Result::error("查询失败", 0);
  2159. // }
  2160. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2161. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2162. $data['catid'] = $category->category_id ?? 0;
  2163. }
  2164. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2165. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2166. }
  2167. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2168. array_push($where, ['type_id', $data['type_id']]);
  2169. }
  2170. $query = Good::where($where)
  2171. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2172. $query->where(function ($q) use ($data) {
  2173. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2174. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2175. });
  2176. })
  2177. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2178. $query->where(function ($q) use ($data) {
  2179. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2180. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2181. });
  2182. })
  2183. ->select(
  2184. 'good.id',
  2185. 'good.name',
  2186. 'good.imgurl',
  2187. 'good.description',
  2188. 'good.updated_at',
  2189. 'good.com',
  2190. 'good.catid',
  2191. 'good.type_id',
  2192. 'good.website_id',
  2193. 'good.cat_arr_id',
  2194. 'good.created_at',
  2195. 'good.city_id'
  2196. )
  2197. ->latest('updated_at');
  2198. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2199. $result['count'] = $query->clone()->count();
  2200. $result['goods'] = $this->processGoods(
  2201. $query->clone()
  2202. ->offset(($data['page'] - 1) * $data['pageSize'])
  2203. ->limit($data['pageSize'])
  2204. ->get(),
  2205. $data
  2206. );
  2207. } else {
  2208. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2209. // 获取 type_id 为 1 的数据
  2210. $result['type1'] = $this->processGoods(
  2211. $query->clone()
  2212. ->where('type_id', 1)
  2213. ->offset(($data['page'] - 1) * $data['pageSize'])
  2214. ->limit($data['pageSize'])
  2215. ->get(),
  2216. $data
  2217. );
  2218. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2219. // 获取 type_id 为 2 的数据
  2220. $result['type2'] = $this->processGoods(
  2221. $query->clone()
  2222. ->where('type_id', 2)
  2223. ->offset(($data['page'] - 1) * $data['pageSize'])
  2224. ->limit($data['pageSize'])
  2225. ->get(),
  2226. $data
  2227. );
  2228. }
  2229. if (empty($result)) {
  2230. return Result::error("查询失败", 0);
  2231. }
  2232. return Result::success($result);
  2233. }
  2234. /**
  2235. * 获取商品详情
  2236. * @param array $data
  2237. * @return array
  2238. * */
  2239. public function getWebsiteshopInfo(array $data): array
  2240. {
  2241. $where = [
  2242. 'good.status' => 2,
  2243. 'good.website_id' => $data['website_id'],
  2244. 'good.id' => $data['id'],
  2245. ];
  2246. $goods = Good::where($where)
  2247. ->where('good.id', $data['id'])
  2248. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2249. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2250. ->first();
  2251. if (empty($goods)) {
  2252. return Result::error("查询失败", 0);
  2253. }
  2254. $goods->imgurl = json_decode($goods->imgurl, true);
  2255. return Result::success($goods);
  2256. }
  2257. /**
  2258. * plus pro 处理文章路由问题
  2259. */
  2260. function processArticlePro($website_id)
  2261. {
  2262. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2263. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2264. // 取出category_id 对应的aLIas_pinyin
  2265. $categoryIds = array_column($categorys, 'category_id');
  2266. $categoryPIds = array_column($categorys, 'pid');
  2267. $aliasPinyins = array_column($categorys, 'aLIas_pinyin');
  2268. $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2269. // return Result::success($categorys);
  2270. $catiall = [];
  2271. //一级所有子级的记录
  2272. $cat_1st_arr = [];
  2273. foreach ($categorys as $key => $value) {
  2274. $category_arr_id = json_decode($value->category_arr_id);
  2275. $pinyin_str = '';
  2276. // 算出一级 并且算出子级
  2277. if ($value->pid != 0) {
  2278. $cat_1st_arr[$value->pid][] = $value->category_id;
  2279. }
  2280. foreach ($category_arr_id as $k => $v) {
  2281. $pinyin_str .= $cat_arr[$v] . '/';
  2282. }
  2283. $pinyin_str = rtrim($pinyin_str, '/');
  2284. $catiall[$value->category_id]['alias'] = $value->alias;
  2285. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2286. $catiall[$value->category_id]['type'] = $value->type;
  2287. $catiall[$value->category_id]['pinyin'] = $pinyin_str;
  2288. $websiteInfoIndexed[$value->category_id]->pinyin = $pinyin_str;
  2289. }
  2290. return [
  2291. 'cat_1st_arr' => $cat_1st_arr,
  2292. 'catiall' => $catiall,
  2293. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2294. 'categoryIds' => $categoryIds,
  2295. ];
  2296. }
  2297. /**
  2298. * 封装处理文章的路由问题
  2299. * */
  2300. function processArticles($articles, $data)
  2301. {
  2302. // 检查 $articles 是否为数组或可迭代对象
  2303. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2304. return $articles->map(function ($article) use ($data) {
  2305. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2306. $catid = $article->cat_arr_id ?? '';
  2307. }
  2308. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2309. $catid = $article->category_arr_id ?? '';
  2310. }
  2311. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2312. $level = json_decode($catid, true);
  2313. if (!is_array($level)) {
  2314. return $article;
  2315. } else {
  2316. $level = array_map('intval', $level);
  2317. }
  2318. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2319. ->where($data)
  2320. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2321. ->pluck('aLIas_pinyin')
  2322. ->implode('/');
  2323. $article->pinyin = $pinyin ?? '';
  2324. return $article;
  2325. });
  2326. } else {
  2327. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2328. $catid = $articles->cat_arr_id ?? '';
  2329. $level = json_decode($catid, true);
  2330. if (!is_array($level)) {
  2331. return $articles;
  2332. } else {
  2333. $level = array_map('intval', $level);
  2334. }
  2335. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2336. ->where($data)
  2337. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2338. ->pluck('aLIas_pinyin')
  2339. ->implode('/');
  2340. $articles->pinyin = $pinyin ?? '';
  2341. return $articles;
  2342. }
  2343. }
  2344. // 封装处理由问题
  2345. function processJob($job, $data)
  2346. {
  2347. return $job->map(function ($job) use ($data) {
  2348. $category = $job->cat_arr_id ?? '';
  2349. $cityid = $job->city_arr_id ?? '';
  2350. $city = json_decode($cityid, true);
  2351. $pinyin = '';
  2352. $level = json_decode($category, true);
  2353. // 路由
  2354. if (!empty($level) && is_array($level)) {
  2355. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2356. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2357. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2358. ->get(['aLIas_pinyin'])
  2359. ->pluck('aLIas_pinyin')
  2360. ->implode('/');
  2361. if (empty($pinyin)) {
  2362. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2363. }
  2364. $job->pinyin = $pinyin;
  2365. }
  2366. // 取职位-城市 市??省
  2367. if (!empty($city) && is_array($city)) {
  2368. if (isset($city[1]) && !empty($city[1])) {
  2369. $city = District::where('id', $city[1])->first(['name']);
  2370. $job->city_name = $city->name ?? '';
  2371. } else if (isset($city[0]) && !empty($city[0])) {
  2372. $city = District::where('id', $city[0])->first(['name']);
  2373. $job->city_name = $city->name ?? '';
  2374. } else {
  2375. $job->city_name = '全国';
  2376. }
  2377. }
  2378. // 获取简历最后一级地区
  2379. if (isset($job->city_id) && !empty($job->city_id)) {
  2380. $city = District::where('id', $job->city_id)->first(['name']);
  2381. $job->hunt_cityname = $city->name ?? '';
  2382. }
  2383. // 组合详细地址
  2384. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2385. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2386. if (is_array($address_id) && !empty($address_id)) {
  2387. $address = District::whereIn('id', $address_id)
  2388. ->orderBy('level', 'asc')
  2389. ->get(['name'])
  2390. ->pluck('name')
  2391. ->implode('');
  2392. // $job->address_name = $address ?? '';
  2393. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2394. }
  2395. }
  2396. // 取行业
  2397. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2398. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2399. if (!empty($job->industry)) {
  2400. $query->where('hyid', $job->industry);
  2401. } else if (!empty($job->hy_id)) {
  2402. $query->where('hyid', $job->hy_id);
  2403. } else if (!empty($job->company_hy_id)) {
  2404. $query->where('hyid', $job->company_hy_id);
  2405. } else {
  2406. $query->where('hyid', $job->job_industry);
  2407. }
  2408. })->first(['hyname']);
  2409. $job->hy_name = $hy_name->hyname ?? '';
  2410. }
  2411. // 取职位类别
  2412. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2413. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2414. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2415. $job->zw_name = $zw_name->zwname ?? '';
  2416. }
  2417. // 取具体职位
  2418. 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))) {
  2419. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2420. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2421. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2422. }
  2423. // 取工作经验
  2424. if (isset($job->experience) && !empty($job->experience)) {
  2425. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2426. $job->experience_name = $experience->ename ?? '';
  2427. }
  2428. // 取学历
  2429. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2430. $education = $job->educational ?? $job->school_education;
  2431. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2432. $job->education_name = $education->ename ?? '';
  2433. }
  2434. // 语言
  2435. if (isset($job->language) && !empty($job->language)) {
  2436. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2437. $job->language_name = $language->ename ?? '';
  2438. }
  2439. // 薪资
  2440. if (isset($job->salary) && !empty($job->salary)) {
  2441. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2442. $job->salary_name = $salary->ename ?? '';
  2443. }
  2444. // 职位性质
  2445. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2446. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2447. $job->job_nature_name = $job_nature->ename ?? '';
  2448. }
  2449. // 公司规模
  2450. if (isset($job->company_size) && !empty($job->company_size)) {
  2451. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2452. $job->company_size_name = $company_size->ename ?? '';
  2453. }
  2454. // 公司性质
  2455. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2456. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2457. $job->company_nature_name = $company_nature->nature_name ?? '';
  2458. }
  2459. // $job->pinyin = $pinyin;
  2460. return $job;
  2461. });
  2462. }
  2463. /**
  2464. * 获取书籍模块
  2465. * @param array $data
  2466. * @return array
  2467. * */
  2468. public function getWebsiteBook(array $data): array
  2469. {
  2470. $input['id'] = $data['id'];
  2471. $input['website_id'] = $data['website_id'];
  2472. // 将 JSON 字符串转换为 PHP 数组
  2473. $data = json_decode($input['id'], true);
  2474. // 使用 array_map 处理每个元素
  2475. $result = array_map(function ($item) use ($input) {
  2476. // 检查parent元素是否存在且不是undefined
  2477. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2478. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2479. $website = [
  2480. 'website_id' => $input['website_id'],
  2481. ];
  2482. // 查询栏目名称
  2483. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2484. if (empty($category)) {
  2485. $parent_alias = '';
  2486. $parent_pinyin = null;
  2487. $imgBooks = [];
  2488. $textBooks = [];
  2489. } else {
  2490. $parent_alias = $category->alias ?? '';
  2491. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2492. // 查找子分类ID数组
  2493. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2494. array_push($childCategoryIds, $parentCatId);
  2495. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2496. if ($parentImgNum != 0) {
  2497. // 查询图片新闻
  2498. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2499. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2500. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2501. })
  2502. ->where('book.status', 2)
  2503. ->where('book.img_url', '!=', '')
  2504. ->leftJoin('website_category', function ($join) use ($website) {
  2505. $join->on('book.cat_id', '=', 'website_category.category_id')
  2506. ->where('website_category.website_id', '=', $website['website_id']);
  2507. })
  2508. ->select(
  2509. 'book.id',
  2510. 'book.title',
  2511. 'book.img_url',
  2512. 'book.price',
  2513. 'book.market_price',
  2514. 'book.description',
  2515. 'book.cat_id',
  2516. 'book.description',
  2517. 'book.updated_at',
  2518. 'website_category.alias as category_name',
  2519. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2520. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2521. )
  2522. ->orderBy('updated_at', 'desc')
  2523. ->limit($parentImgNum)
  2524. ->get()->all();
  2525. // 查询文字新闻
  2526. }
  2527. if ($parentTextNum != 0) {
  2528. $textBooks = [];
  2529. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2530. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2531. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2532. })
  2533. ->where('book.status', 2)
  2534. ->leftJoin('website_category', function ($join) use ($website) {
  2535. $join->on('book.cat_id', '=', 'website_category.category_id')
  2536. ->where('website_category.website_id', '=', $website['website_id']);
  2537. })
  2538. ->select(
  2539. 'book.id',
  2540. 'book.title',
  2541. 'book.img_url',
  2542. 'book.price',
  2543. 'book.market_price',
  2544. 'book.description',
  2545. 'book.cat_id',
  2546. 'book.description',
  2547. 'book.updated_at',
  2548. 'website_category.alias as category_name',
  2549. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2550. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2551. )
  2552. ->orderBy('updated_at', 'desc')
  2553. ->limit($parentTextNum)
  2554. ->get()->all();
  2555. }
  2556. }
  2557. }
  2558. $resultItem = [
  2559. 'alias' => $parent_alias ?? '',
  2560. 'category_id' => $parentCatId ?? 0,
  2561. 'pinyin' => $parent_pinyin ?? null,
  2562. 'imgnum' => $imgBooks ?? [],
  2563. 'textnum' => $textBooks ?? [],
  2564. ];
  2565. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2566. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2567. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2568. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2569. ->get()->all();
  2570. if (!empty($childCategory)) {
  2571. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2572. // 查询子栏目名称
  2573. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2574. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2575. ->first();
  2576. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2577. $childImgArticles = [];
  2578. $childTextArticles = [];
  2579. $resultItem['child'] = [];
  2580. } else {
  2581. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2582. // 查询子栏目图片新闻
  2583. $childImgArticles = Book::where('cat_id', $childCatId)
  2584. ->where('status', 2)
  2585. ->where('img_url', '!=', '')
  2586. ->leftJoin('website_category', function ($join) use ($website) {
  2587. $join->on('book.cat_id', '=', 'website_category.category_id')
  2588. ->where('website_category.website_id', '=', $website['website_id']);
  2589. })
  2590. ->select(
  2591. 'book.id',
  2592. 'book.title',
  2593. 'book.img_url',
  2594. 'book.price',
  2595. 'book.market_price',
  2596. 'book.description',
  2597. 'book.cat_id',
  2598. 'book.description',
  2599. 'book.updated_at',
  2600. DB::raw("'$child_pinyin' as pinyin")
  2601. )
  2602. ->orderBy('updated_at', 'desc')
  2603. ->limit($childImgNum)
  2604. ->get()->all();
  2605. // 查询子栏目文字新闻
  2606. $childTextArticles = Book::where('cat_id', $childCatId)
  2607. ->where('status', 2)
  2608. ->leftJoin('website_category', function ($join) use ($website) {
  2609. $join->on('book.cat_id', '=', 'website_category.category_id')
  2610. ->where('website_category.website_id', '=', $website['website_id']);
  2611. })
  2612. ->select(
  2613. 'book.id',
  2614. 'book.title',
  2615. 'book.img_url',
  2616. 'book.price',
  2617. 'book.market_price',
  2618. 'book.description',
  2619. 'book.cat_id',
  2620. 'book.description',
  2621. 'book.updated_at',
  2622. DB::raw("'$child_pinyin' as pinyin")
  2623. )
  2624. ->orderBy('updated_at', 'desc')
  2625. ->limit($childTextNum)
  2626. ->get()->all();
  2627. $resultItem['child'] = [
  2628. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2629. 'category_id' => $childCatId,
  2630. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2631. 'all_childcat' => $childCategory,
  2632. 'imgnum' => $childImgArticles,
  2633. 'textnum' => $childTextArticles,
  2634. ];
  2635. }
  2636. }
  2637. } else {
  2638. $resultItem['child'] = [];
  2639. }
  2640. return $resultItem;
  2641. }, $data);
  2642. return Result::success($result);
  2643. }
  2644. /**
  2645. * 获取书刊列表
  2646. * @param array $data
  2647. * @return array
  2648. * */
  2649. public function getWebsiteBookList(array $data): array
  2650. {
  2651. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2652. if (empty($web)) {
  2653. return Result::error("查询失败", 0);
  2654. }
  2655. $catid = $data['id'];
  2656. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2657. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2658. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2659. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2660. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2661. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2662. ->where('pid', $category['pid'])
  2663. ->select(
  2664. 'category_id',
  2665. 'alias',
  2666. 'aLIas_pinyin',
  2667. 'pid',
  2668. 'sort',
  2669. 'is_url',
  2670. 'web_url',
  2671. 'seo_title',
  2672. 'seo_keywords',
  2673. 'seo_description',
  2674. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2675. )
  2676. ->orderBy('sort')
  2677. ->get()->all();
  2678. if (empty($category)) {
  2679. return Result::error("查询失败", 0);
  2680. }
  2681. $query = Book::where('book.status', 2)
  2682. ->where('book.website_id', $data['website_id'])
  2683. ->where('book.cat_id', $catid)
  2684. ->select(
  2685. 'book.id',
  2686. 'book.title',
  2687. 'book.img_url',
  2688. 'book.description',
  2689. 'book.updated_at',
  2690. 'book.cat_id',
  2691. DB::raw("'$pinyin' as pinyin")
  2692. )
  2693. ->orderBy('book.updated_at', 'desc');
  2694. $count = $query->count();
  2695. $query = clone $query;
  2696. $Book = $query
  2697. ->limit($data['pageSize'])
  2698. ->offset(($data['page'] - 1) * $data['pageSize'])
  2699. ->get()->all();
  2700. $result = [
  2701. 'category' => $categorys,
  2702. 'books' => $Book,
  2703. 'count' => $count,
  2704. ];
  2705. // if(empty($result)){
  2706. // return Result::error("查询失败", 0);
  2707. // }
  2708. return Result::success($result);
  2709. }
  2710. /**
  2711. * 获取书刊详情
  2712. * @param array $data
  2713. * @return array
  2714. * */
  2715. public function getWebsiteBookInfo(array $data): array
  2716. {
  2717. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2718. if (empty($web)) {
  2719. return Result::error("查询失败", 0);
  2720. }
  2721. $book = Book::where('status', 2)
  2722. ->where('website_id', $data['website_id'])
  2723. ->where('id', $data['id'])
  2724. ->select(
  2725. 'book.*',
  2726. )
  2727. ->orderBy('updated_at', 'desc')
  2728. ->first();
  2729. if (empty($book)) {
  2730. return Result::error("查询失败", 0);
  2731. }
  2732. // 先查询当前分类的 pid
  2733. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2734. ->where('category_id', $book['cat_id'])
  2735. ->first(['pid', 'category_id']);
  2736. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2737. if (!empty($carpid)) {
  2738. if ($carpid->pid != 0) {
  2739. $pid = $carpid['pid'];
  2740. // $parent_pinyin = '';
  2741. } else {
  2742. $pid = $carpid['category_id'];
  2743. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2744. }
  2745. }
  2746. $categorys = $query->where('pid', $pid)
  2747. ->select(
  2748. 'category_id',
  2749. 'alias',
  2750. 'aLIas_pinyin',
  2751. 'pid',
  2752. 'sort',
  2753. 'is_url',
  2754. 'web_url',
  2755. 'category_arr_id as cat_arr_id',
  2756. )
  2757. ->orderBy('sort')
  2758. ->get();
  2759. $category = $this->processArticle($categorys, $data);
  2760. $result = [
  2761. 'category' => $category,
  2762. 'books' => $book,
  2763. ];
  2764. return Result::success($result);
  2765. }
  2766. /**
  2767. * 尝试
  2768. * @param array $data
  2769. * @return array
  2770. * */
  2771. public function test(array $data): array
  2772. {
  2773. $input['id'] = $data['id'];
  2774. $input['website_id'] = $data['website_id'];
  2775. // 将 JSON 字符串转换为 PHP 数组
  2776. $data = json_decode($input['id'], true);
  2777. $result = [];
  2778. $article = $data;
  2779. $result = array_map(function ($item) use ($input) {
  2780. $website = [
  2781. 'website_id' => $input['website_id'],
  2782. ];
  2783. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2784. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2785. $parent = [
  2786. 0 => $category['category_id'] ?? [],
  2787. 1 => $parentImgNum ?? [],
  2788. 2 => $parentTextNum ?? [],
  2789. ];
  2790. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2791. $child = [];
  2792. $resultItem = [
  2793. // 'alias' => $parent_alias ?? '',
  2794. 'category_id' => $parentCatId ?? 0,
  2795. 'pinyin' => $parentImgNum ?? null,
  2796. 'imgnum' => $parentTextNum ?? [],
  2797. // 'textnum' => $textArticles ?? [],
  2798. ];
  2799. return $parent;
  2800. }, $data);
  2801. return Result::success($result);
  2802. // });
  2803. }
  2804. /**
  2805. * 封装处理文章的路由问题
  2806. * */
  2807. function processArticle($article, $data)
  2808. {
  2809. return $article->map(function ($article) use ($data) {
  2810. $catid = $article->cat_arr_id ?? '';
  2811. $level = json_decode($catid, true);
  2812. $pinyin = '';
  2813. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2814. if (!empty($level) && is_array($level)) {
  2815. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2816. ->where('website_id', $data['website_id'])
  2817. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2818. ->get(['aLIas_pinyin'])
  2819. ->pluck('aLIas_pinyin')
  2820. ->implode('/');
  2821. } else {
  2822. $pinyin = '';
  2823. }
  2824. $article->pinyin = $pinyin;
  2825. return $article;
  2826. });
  2827. }
  2828. /**
  2829. * c端-获取招工招聘下拉选框
  2830. * @param array $data
  2831. * @return array
  2832. * */
  2833. public function getWebsiteJobSelect(array $data): array
  2834. {
  2835. $web = Website::where('id', $data['website_id'])->first();
  2836. if (empty($web)) {
  2837. return Result::error("该网站不存在", 0);
  2838. }
  2839. $hy = JobIndustry::get()->all();
  2840. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2841. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2842. $result = [
  2843. 'hy' => $hy,
  2844. 'zw' => $zw,
  2845. 'jtzw' => $jtzw,
  2846. ];
  2847. if (empty($result)) {
  2848. return Result::error("查询失败", 0);
  2849. }
  2850. return Result::success($result);
  2851. }
  2852. /**
  2853. * c端-获取招工招聘
  2854. * @param array $data
  2855. * @return array
  2856. * */
  2857. public function getWebsiteJob(array $data): array
  2858. {
  2859. $web = Website::where('id', $data['website_id'])->first();
  2860. if (empty($web)) {
  2861. return Result::error("该网站不存在", 0);
  2862. }
  2863. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2864. ->where('job_hunting.website_id', $data['website_id'])
  2865. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2866. $query->where(function ($q) use ($data) {
  2867. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2868. });
  2869. })
  2870. ->select(
  2871. 'job_hunting.id',
  2872. 'job_hunting.cat_arr_id',
  2873. 'job_hunting.job_name_get',
  2874. 'job_hunting.industry',
  2875. 'job_hunting.name',
  2876. 'job_hunting.sexy',
  2877. 'job_hunting.origin',
  2878. 'job_hunting.city_arr_id',
  2879. 'job_hunting.experience',
  2880. 'job_hunting.updated_at',
  2881. 'job_hunting.salary'
  2882. )
  2883. ->orderBy('updated_at', 'desc')
  2884. ->limit($data['job1_num'])
  2885. ->get();
  2886. $web['website_id'] = $data['website_id'];
  2887. if (empty($job_hunting)) {
  2888. $job_huntings = "未查询到相关简历信息";
  2889. } else {
  2890. $job_huntings = $this->processJob($job_hunting, $web);
  2891. }
  2892. // 0:待审核 1:已通过 2:已拒绝
  2893. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2894. ->where('job_recruiting.website_id', $data['website_id'])
  2895. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2896. $query->where(function ($q) use ($data) {
  2897. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2898. });
  2899. })
  2900. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2901. ->select(
  2902. 'job_recruiting.id',
  2903. 'job_recruiting.cat_arr_id',
  2904. 'job_recruiting.title',
  2905. 'job_recruiting.jtzw_id',
  2906. 'job_recruiting.hy_id',
  2907. 'job_recruiting.city_arr_id',
  2908. 'job_recruiting.due_data',
  2909. 'job_recruiting.updated_at',
  2910. 'job_recruiting.experience',
  2911. 'job_recruiting.educational',
  2912. 'job_recruiting.salary',
  2913. 'job_recruiting.zw_id',
  2914. 'job_company.business_name'
  2915. )
  2916. ->orderBy('updated_at', 'desc')
  2917. ->limit($data['job2_num'])
  2918. ->get();
  2919. if (empty($job_recruiting->toArray())) {
  2920. $job_recruitings = "未查询到相关职位信息";
  2921. } else {
  2922. $job_recruitings = $this->processJob($job_recruiting, $web);
  2923. }
  2924. $result = [
  2925. 'job_hunting' => $job_huntings,
  2926. 'job_recuiting' => $job_recruitings,
  2927. ];
  2928. return Result::success($result);
  2929. }
  2930. /**
  2931. * c端-获取招工招聘列表
  2932. * @param array $data
  2933. * @return array
  2934. * */
  2935. public function getWebsiteJobList(array $data): array
  2936. {
  2937. $recruit_where = [];
  2938. $hunt_where = [];
  2939. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2940. if (empty($web)) {
  2941. return Result::error("此网站不存在", 0);
  2942. }
  2943. $website_id['website_id'] = $data['website_id'];
  2944. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2945. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2946. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2947. }
  2948. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2949. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2950. }
  2951. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2952. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2953. }
  2954. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2955. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  2956. }
  2957. $query = JobRecruiting::where('job_recruiting.status', 1)
  2958. ->where('job_recruiting.website_id', $data['website_id'])
  2959. ->where($recruit_where)
  2960. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2961. $query->where(function ($q) use ($data) {
  2962. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2963. });
  2964. })
  2965. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2966. $query->where(function ($q) use ($data) {
  2967. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2968. });
  2969. })
  2970. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2971. ->select(
  2972. 'job_recruiting.id',
  2973. 'job_recruiting.hy_id',
  2974. 'job_recruiting.title',
  2975. 'job_recruiting.zw_id',
  2976. 'job_recruiting.educational',
  2977. 'job_recruiting.jtzw_id',
  2978. 'job_recruiting.city_arr_id',
  2979. 'job_recruiting.due_data',
  2980. 'job_recruiting.experience',
  2981. 'job_recruiting.cat_arr_id',
  2982. 'job_recruiting.updated_at',
  2983. 'job_company.business_name'
  2984. )
  2985. ->orderBy('job_recruiting.updated_at', 'desc');
  2986. $recruit_count = $query->count();
  2987. $query = clone $query;
  2988. $JobRecruiting = $query
  2989. ->offset(($data['page'] - 1) * $data['pageSize'])
  2990. ->limit($data['pageSize'])
  2991. ->get();
  2992. if (empty($JobRecruiting)) {
  2993. $JobRecruiting = "暂无相关职位信息";
  2994. } else {
  2995. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2996. }
  2997. }
  2998. if((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])){
  2999. if(isset($data['zw_id']) && !empty($data['zw_id'])){
  3000. array_push($hunt_where, ['job_hunting.job',$data['zw_id']]);
  3001. }
  3002. if(isset($data['jtzw_id']) &&!empty($data['jtzw_id'])){
  3003. array_push($hunt_where, ['job_hunting.job_name_get',$data['jtzw_id']]);
  3004. }
  3005. if(isset($data['hy_id']) && !empty($data['hy_id'])){
  3006. array_push($hunt_where, ['job_hunting.industry',$data['hy_id']]);
  3007. }
  3008. if(isset($data['keyword']) && !empty($data['keyword'])){
  3009. array_push($hunt_where, ['job_position.zwname','like','%'.$data['keyword'].'%']);
  3010. }
  3011. $query = JobHunting::where('job_hunting.status', 2)
  3012. ->where('job_hunting.website_id', $data['website_id'])
  3013. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3014. ->where($hunt_where)
  3015. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3016. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3017. // })
  3018. ->when(isset($data['city_id']) &&!empty($data['city_id']), function ($query) use ($data) {
  3019. $query->where(function($q) use ($data) {
  3020. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '". intval($data['city_id']). "') = 1");
  3021. });
  3022. })
  3023. ->when(isset($data['catid_id']) &&!empty($data['catid_id']), function ($query) use ($data) {
  3024. $query->where(function($q) use ($data) {
  3025. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '". intval($data['catid_id']). "') = 1");
  3026. });
  3027. })
  3028. ->select('job_hunting.id','job_hunting.sexy','job_hunting.experience','job_hunting.origin','job_hunting.industry',
  3029. 'job_hunting.name','job_hunting.job','job_hunting.job_name_get','job_hunting.city_arr_id','job_hunting.cat_arr_id',
  3030. 'job_hunting.created_at','job_hunting.updated_at','job_position.zwname as job_name')
  3031. ->orderBy('job_hunting.updated_at', 'desc');
  3032. $hunt_count = $query->count();
  3033. $query = clone $query;
  3034. $JobHunting = $query
  3035. ->offset(($data['page'] - 1) * $data['pageSize'])
  3036. ->limit($data['pageSize'])
  3037. ->get();
  3038. if (empty($JobHunting)) {
  3039. $JobRecruiting = "暂无相关简历信息";
  3040. } else {
  3041. $JobHunting = $this->processJob($JobHunting, $website_id);
  3042. }
  3043. }
  3044. $result = [
  3045. 'JobRecruiting' => $JobRecruiting ?? [],
  3046. 'recruit_count' => $recruit_count ?? 0,
  3047. 'JobHunting' => $JobHunting ?? [],
  3048. 'hunt_count' => $hunt_count ?? 0,
  3049. ];
  3050. return Result::success($result);
  3051. }
  3052. /**
  3053. * c端-获取招工招聘详情
  3054. * @param array $data
  3055. * @return array
  3056. * */
  3057. public function getWebsiteJobInfo(array $data): array
  3058. {
  3059. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3060. if (empty($web)) {
  3061. return Result::error("该网站不存在", 0);
  3062. }
  3063. $webid = [
  3064. 'website_id' => $data['website_id'],
  3065. ];
  3066. // 职位相关信息
  3067. if ($data['type'] == 1) {
  3068. $query = JobRecruiting::where('status', 1)
  3069. ->where('website_id', $data['website_id'])
  3070. ->select('*');
  3071. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3072. $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();
  3073. if (!empty($company)) {
  3074. $result['company'] = $this->processJob($company, $webid);
  3075. }
  3076. $other_job = JobRecruiting::where('status', 1)
  3077. ->where('website_id', $data['website_id'])
  3078. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3079. ->where('id', '!=', $data['id'])
  3080. ->where('user_id', '=', $job[0]['user_id'])
  3081. ->limit($data['pageSize'])
  3082. ->get();
  3083. if (!empty($other_job)) {
  3084. $result['other_job'] = $this->processJob($other_job, $webid);
  3085. }
  3086. } else {
  3087. // 简历相关信息
  3088. $job = JobHunting::where('job_hunting.status', 2)
  3089. ->where('job_hunting.website_id', $data['website_id'])
  3090. ->where('job_hunting.id', $data['id'])
  3091. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3092. ->select('job_hunting.*', 'user_name')
  3093. ->get();
  3094. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3095. if (!empty($resume->toArray())) {
  3096. $result['resume'] = 1;
  3097. } else {
  3098. $result['resume'] = 0;
  3099. }
  3100. }
  3101. if (empty($job->toArray())) {
  3102. return Result::error("id参数错误", 0);
  3103. }
  3104. if (!empty($job[0]['job_experience'])) {
  3105. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3106. if (!empty($job_experience)) {
  3107. // $hy = [];
  3108. foreach ($job_experience as $key => $value) {
  3109. // $id = $value['id'];
  3110. $hy[$key] = $value['job_industry'];
  3111. $zw_id[$key] = $value['job_typename'];
  3112. $jtzw_id[$key] = $value['job_name'];
  3113. }
  3114. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3115. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3116. // 先将关联表转换为索引数组,提高查找效率
  3117. $hyLookup = [];
  3118. foreach ($hy_table as $item) {
  3119. $hyLookup[$item['hyid']] = $item['hyname'];
  3120. }
  3121. $zwLookup = [];
  3122. foreach ($zw_table as $item) {
  3123. $zwLookup[$item['zwid']] = $item['zwname'];
  3124. }
  3125. foreach ($job_experience as $key => &$value) {
  3126. // 处理行业名称
  3127. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3128. $value['hy_name'] = $hyLookup[$hy[$key]];
  3129. }
  3130. // 处理职位名称
  3131. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3132. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3133. }
  3134. // 处理具体职位名称
  3135. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3136. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3137. }
  3138. }
  3139. // 释放引用,防止意外修改后续代码
  3140. unset($value);
  3141. }
  3142. $result['job_experience'] = $job_experience ?? [];
  3143. }
  3144. if (!empty($job[0]['education_experience'])) {
  3145. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3146. if (!empty($education_experience)) {
  3147. foreach ($education_experience as $key => $value) {
  3148. // $id = $value['id'];
  3149. $education[$key] = $value['school_education'];
  3150. }
  3151. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3152. // // 先将关联表转换为索引数组,提高查找效率
  3153. $educationLookup = [];
  3154. foreach ($education_table as $item) {
  3155. $educationLookup[$item['evalue']] = $item['ename'];
  3156. }
  3157. foreach ($education_experience as $key => &$value) {
  3158. // 处理学历名称
  3159. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3160. $value['education_name'] = $educationLookup[$education[$key]];
  3161. }
  3162. }
  3163. }
  3164. $result['education_experience'] = $job_experience ?? [];
  3165. }
  3166. $result['job'] = $this->processJob($job, $webid);
  3167. // // 返现对应的栏目
  3168. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3169. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3170. ->whereIn('category_id', $catid)
  3171. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3172. ->orderBy('pid')->get()->all();
  3173. if (!empty($category)) {
  3174. $result['category'] = $category;
  3175. }
  3176. $result['job'] = $job;
  3177. $result['job_experience'] = $job_experience ?? [];
  3178. $result['education_experience'] = $education_experience ?? [];
  3179. if (empty($result)) {
  3180. return Result::error("参数错误", 0);
  3181. }
  3182. return Result::success($result);
  3183. }
  3184. /**
  3185. * c端-申请职位
  3186. * @param array $data
  3187. * @return array
  3188. * */
  3189. public function getWebsiteJobApply(array $data): array
  3190. {
  3191. // 首先验证网站是否存在
  3192. // return Result::success($data);
  3193. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3194. if (empty($web)) {
  3195. return Result::error("该网站不存在", 0);
  3196. }
  3197. // 验证用户是否存在且为个人会员/管理员
  3198. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3199. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3200. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3201. return Result::error("用户不存在", 0);
  3202. }
  3203. // 去除重复元素和空元素,并保持原始顺序
  3204. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3205. return !empty($value);
  3206. }));
  3207. // 验证职位是否存在 1:审核通过
  3208. $recruiting = JobRecruiting::where('status', 1)
  3209. ->where('website_id', $data['website_id'])
  3210. ->whereIn('id', $data['recruit_id'])
  3211. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3212. if (empty($recruiting)) {
  3213. return Result::error("该职位不存在", 0);
  3214. }
  3215. // 简历是否存在
  3216. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3217. if (empty($hunt_id)) {
  3218. return Result::error("该简历不存在", 0);
  3219. }
  3220. $data['hunt_id'] = $hunt_id['hunt_id'];
  3221. // // 验证是否已投递过该职位
  3222. $apply = JobApply::where('user_id', $data['user_id'])
  3223. ->where('hunt_id', $data['hunt_id'])
  3224. ->where('website_id', $data['website_id'])
  3225. ->whereIn('recruit_id', $data['recruit_id'])
  3226. ->get(['recruit_id']);
  3227. if (!empty($apply->toArray())) {
  3228. return Result::error("您已投递过该职位!");
  3229. }
  3230. $insertData = array_map(function ($recruiting) use ($data) {
  3231. return [
  3232. 'user_id' => $data['user_id'],
  3233. 'hunt_id' => $data['hunt_id'],
  3234. 'website_id' => $data['website_id'],
  3235. 'recruit_id' => $recruiting['recruit_id'],
  3236. 'receiver_id' => $recruiting['receiver_id'],
  3237. 'status' => 1,
  3238. ];
  3239. }, $recruiting);
  3240. // 批量插入数据
  3241. $result = JobApply::insert($insertData);
  3242. if (empty($result)) {
  3243. return Result::error("投递失败", 0);
  3244. }
  3245. return Result::success($result);
  3246. }
  3247. /**
  3248. * 招工招聘-沟通简历
  3249. * @param array $data
  3250. * @return array
  3251. * */
  3252. public function getWebsiteJobResume(array $data): array
  3253. {
  3254. // 首先验证网站是否存在
  3255. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3256. if (empty($web)) {
  3257. return Result::error("该网站不存在", 0);
  3258. }
  3259. // return Result::success($data);
  3260. // 验证用户是否存在且为企业会员/管理员
  3261. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3262. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3263. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3264. return Result::error("用户不存在", 0);
  3265. }
  3266. // 去除重复元素和空元素,并保持原始顺序
  3267. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3268. return !empty($value);
  3269. }));
  3270. // 验证简历是否存在
  3271. $hunting = JobHunting::where('status', 2)
  3272. ->where('website_id', $data['website_id'])
  3273. ->whereIn('id', $data['hunt_id'])
  3274. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3275. if (empty($hunting)) {
  3276. return Result::error("该简历不存在", 0);
  3277. }
  3278. // 验证是否已沟通过该简历
  3279. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3280. ->where('recruit_id', $data['recruit_id'])
  3281. ->where('website_id', $data['website_id'])
  3282. ->whereIn('hunt_id', $data['hunt_id'])
  3283. ->get(['hunt_id']);
  3284. if (!empty($remuse->toArray())) {
  3285. return Result::error("您已沟通过该简历!");
  3286. }
  3287. // 准备要插入的数据数组
  3288. $insertData = array_map(function ($hunting) use ($data) {
  3289. return [
  3290. 'user_id' => $data['user_id'],
  3291. 'recruit_id' => $data['recruit_id'],
  3292. 'website_id' => $data['website_id'],
  3293. 'hunt_id' => $hunting['hunt_id'],
  3294. 'receiver_id' => $hunting['receiver_id'],
  3295. 'status' => 1,
  3296. ];
  3297. }, $hunting);
  3298. // 批量插入数据
  3299. $result = JobRemuse::insert($insertData);
  3300. if (empty($result)) {
  3301. return Result::error("沟通失败", 0);
  3302. }
  3303. return Result::success($result);
  3304. }
  3305. /**
  3306. * 招工招聘 -我的职位(企业会员)
  3307. * @param array $data
  3308. * @return array
  3309. */
  3310. public function getWebsiteJobRecruiting(array $data): array
  3311. {
  3312. $web = Website::where('id', $data['website_id'])->first('id');
  3313. if (empty($web)) {
  3314. return Result::error("该网站不存在", 0);
  3315. }
  3316. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3317. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3318. return Result::error("用户暂无权限!", 0);
  3319. }
  3320. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3321. $result = JobRecruiting::where('website_id', $data['website_id'])
  3322. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3323. $query->where('user_id', $user['id']);
  3324. })
  3325. ->where('status', 1)
  3326. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3327. ->orderBy('updated_at', 'desc')
  3328. ->limit($data['pageSize'])
  3329. ->get();
  3330. if (empty($result)) {
  3331. return Result::error("暂无相关职位信息", 0);
  3332. }
  3333. return Result::success($result);
  3334. }
  3335. /**
  3336. * c端 - 验证路由
  3337. * @param array $data
  3338. * @return array
  3339. */
  3340. /**
  3341. * c端 - 验证路由
  3342. * @param array $data
  3343. * @return array
  3344. */
  3345. public function checkWebsiteRoute(array $data): array
  3346. {
  3347. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3348. if (empty($web)) {
  3349. return Result::error("该网站不存在", 0);
  3350. } elseif ($web['status'] != 1) {
  3351. return Result::error("网站已经关闭", 0);
  3352. }
  3353. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3354. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3355. // 验证路由是否存在
  3356. if (empty($whiteRouterInfo)) {
  3357. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3358. }
  3359. if (!empty($whiteRouterInfo)) {
  3360. return Result::success($whiteRouterInfo->toArray());
  3361. }
  3362. }
  3363. // 验证栏目路由
  3364. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3365. ->where('aLIas_pinyin', $data['last_route'])
  3366. ->get()->all();
  3367. if (count($last_category) == 0) {
  3368. return Result::error("该栏目不存在", 0);
  3369. }
  3370. if(count($last_category) > 1){
  3371. return Result::error("该子级栏目存在多个,路由验证失败!", 0);
  3372. }
  3373. if(count($last_category) == 1){
  3374. $last_category = $last_category[0];
  3375. }
  3376. // return Result::success($last_category);
  3377. if (isset($data['id']) && !empty($data['id'])) {
  3378. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3379. switch ($last_category['type']) {
  3380. case 1:
  3381. // 文章
  3382. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3383. $article = Article::where('status', 1)
  3384. ->where('id', $data['id'])
  3385. ->where(function ($query) use ($data) {
  3386. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3387. ->orWhereNull("ignore_ids");
  3388. })
  3389. ->first(['cat_arr_id']);
  3390. if (empty($article)) {
  3391. return Result::error("该文章不存在", 0);
  3392. }
  3393. // return Result::success($article);
  3394. break;
  3395. case 2:
  3396. // 商品
  3397. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3398. $article = Good::where('website_id', $data['website_id'])
  3399. ->where('status', 2)
  3400. ->where('id', $data['id'])
  3401. ->first(['cat_arr_id']);
  3402. if (empty($article)) {
  3403. return Result::error("该商品不存在", 0);
  3404. }
  3405. break;
  3406. case 3:
  3407. // 书刊信息
  3408. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3409. $article = Book::where('website_id', $data['website_id'])
  3410. ->where('status', 2)
  3411. ->where('id', $data['id'])
  3412. ->first(['id', 'cat_arr_id']);
  3413. if (empty($article)) {
  3414. return Result::error("该书刊不存在", 0);
  3415. }
  3416. break;
  3417. case 4:
  3418. // 招聘
  3419. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3420. $article = JobRecruiting::where('website_id', $data['website_id'])
  3421. ->where('status', 1)
  3422. ->where('id', $data['id'])
  3423. ->first(['cat_arr_id']);
  3424. if (empty($article)) {
  3425. return Result::error("该招聘不存在", 0);
  3426. }
  3427. break;
  3428. case 5:
  3429. // 求职
  3430. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3431. $article = JobHunting::where('website_id', $data['website_id'])
  3432. ->where('status', 2)
  3433. ->where('id', $data['id'])
  3434. ->first(['cat_arr_id']);
  3435. if (empty($article)) {
  3436. return Result::error("该求职不存在", 0);
  3437. }
  3438. break;
  3439. case 6:
  3440. // 企业
  3441. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3442. $article = Company::where('website_id', $data['website_id'])
  3443. ->where('status', 1)
  3444. ->where('id', $data['id'])
  3445. ->first(['cat_arr_id']);
  3446. if (empty($article)) {
  3447. return Result::error("该企业不存在", 0);
  3448. }
  3449. break;
  3450. case 7:
  3451. // 项目
  3452. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3453. $article = Project::where('website_id', $data['website_id'])
  3454. ->where('status', 1)
  3455. ->where('id', $data['id'])
  3456. ->first(['cat_arr_id']);
  3457. if (empty($article)) {
  3458. return Result::error("该项目不存在", 0);
  3459. }
  3460. break;
  3461. default:
  3462. return Result::error("该数据不存在", 0);
  3463. break;
  3464. }
  3465. $catid =0 ;
  3466. $catidArray = json_decode($article['cat_arr_id'], true);
  3467. $catid = !empty($catidArray) ? end($catidArray) : null;
  3468. // return Result::success($article['cat_arr_id']);
  3469. if (empty($catid)) {
  3470. return Result::error("该数据不存在", 0);
  3471. }
  3472. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3473. ->where('category_id',$catid)
  3474. ->select('path')
  3475. ->pluck('path');
  3476. }else{
  3477. if ($last_category['pid'] != 0) {
  3478. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3479. $catid = !empty($cat_arr) ? end($cat_arr) : null;
  3480. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3481. ->where('category_id',$catid)
  3482. ->where('path',$data['all_route'])
  3483. ->pluck('path');
  3484. } else {
  3485. $pinyin[0] = $last_category['aLIas_pinyin'];
  3486. }
  3487. }
  3488. // return Result::success($pinyin[0]);
  3489. if (empty($pinyin) || count($pinyin)>1 || $pinyin[0] != $data['all_route']) {
  3490. return Result::error('非法路径!');
  3491. } else {
  3492. return Result::success($pinyin);
  3493. }
  3494. }
  3495. /**
  3496. * 招工招聘 - 获取推荐职位
  3497. * @param array $data
  3498. * @return array
  3499. */
  3500. public function getWebsiteLevelJob(array $data): array
  3501. {
  3502. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3503. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3504. ->where('job_recruiting.status', 1)
  3505. ->where('job_level', $data['job_level'])
  3506. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3507. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3508. ->orderBy('job_recruiting.updated_at', 'desc')
  3509. ->limit($data['pageSize'])
  3510. ->get();
  3511. $web = ['website_id' => $data['website_id']];
  3512. if (!empty($job)) {
  3513. $result = $this->processJob($job, $web);
  3514. }
  3515. if (empty($result)) {
  3516. return Result::error("暂无相关职位信息", 0);
  3517. }
  3518. return Result::success($result);
  3519. }
  3520. /**
  3521. * 验证导航名称是否重复
  3522. * @return void
  3523. */
  3524. //20250226 产品列表
  3525. public function getGoodList(array $data): array
  3526. {
  3527. var_dump($data, '---------1-2--');
  3528. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3529. unset($data['user_type_id']);
  3530. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3531. $where = [];
  3532. if ($type_id != '10000') {
  3533. $where = [
  3534. 'good.user_id' => $user_id,
  3535. ];
  3536. }
  3537. //类型
  3538. if (isset($data['type_id']) && $data['type_id']) {
  3539. $where['good.type_id'] = $data['type_id'];
  3540. }
  3541. //名称
  3542. if (isset($data['name']) && $data['name']) {
  3543. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3544. }
  3545. //status
  3546. if (isset($data['status']) && $data['status'] != '') {
  3547. $where['good.status'] = $data['status'];
  3548. }
  3549. //status1
  3550. // if (isset($data['status1']) && $data['status1'] == 1) {
  3551. // $status1 = 1;
  3552. // }
  3553. $where1 = [];
  3554. //website_id
  3555. // if (isset($data['website_id']) && $data['website_id']) {
  3556. // $where1 = [
  3557. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3558. // ];
  3559. // }
  3560. // website_name
  3561. if (isset($data['website_name']) && $data['website_name']) {
  3562. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3563. }
  3564. // catid
  3565. if (isset($data['category_name']) && $data['category_name']) {
  3566. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3567. }
  3568. // $result = Good::where($where)
  3569. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3570. var_dump($where, '---------1---');
  3571. $result = Good::where($where)
  3572. ->when(!empty($where1), function ($query) use ($where1) {
  3573. return $query->where($where1);
  3574. })
  3575. //status 1待审核2已审核3已拒绝
  3576. ->when(isset($data['status1']), function ($query) {
  3577. return $query->whereIn('good.status', [1, 3]);
  3578. })
  3579. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3580. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3581. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3582. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3583. ->orderBy("updated_at", "desc")
  3584. ->limit($data['page_size'])
  3585. ->offset(($data['page'] - 1) * $data['page_size'])
  3586. ->get();
  3587. $count = Good::where($where)
  3588. ->when(!empty($where1), function ($query) use ($where1) {
  3589. return $query->where($where1);
  3590. })
  3591. //status 1待审核2已审核3已拒绝
  3592. ->when(isset($data['status1']), function ($query) {
  3593. return $query->whereIn('good.status', [1, 3]);
  3594. })
  3595. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3596. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3597. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3598. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3599. ->orderBy("updated_at", "desc")->count();
  3600. $data = [
  3601. 'rows' => $result->toArray(),
  3602. 'count' => $count,
  3603. ];
  3604. if (empty($result)) {
  3605. return Result::error("此栏目暂无相关产品", 0);
  3606. }
  3607. return Result::success($data);
  3608. }
  3609. public function getGoodInfo(array $data): array
  3610. {
  3611. $result = Good::where('id', $data['id'])->first();
  3612. if (empty($result)) {
  3613. return Result::error("此产品不存在", 0);
  3614. }
  3615. return Result::success($result);
  3616. }
  3617. public function addGood(array $data): array
  3618. {
  3619. // unset($data['city_arr_id']);
  3620. // unset($data['cat_arr_id']);
  3621. $data['city_id'] = end($data['city_arr_id']);
  3622. $data['catid'] = end($data['cat_arr_id']);
  3623. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3624. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3625. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3626. unset($data['imgUrl']); //大小写
  3627. if (isset($data['price']) && $data['price'] == '') {
  3628. $data['price'] = 0;
  3629. }
  3630. if ($data['imgurl'] == '') {
  3631. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3632. preg_match_all($reg, $data['detail'], $matches);
  3633. if (isset($matches[1][0])) {
  3634. //截取varchar240
  3635. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3636. }
  3637. }
  3638. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3639. //提取标题+内容中的关键词
  3640. $data['keyword'] = $data['name'];
  3641. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3642. Jieba::init(); // 初始化 jieba-php
  3643. Finalseg::init();
  3644. $segList = Jieba::cut($data['keyword']);
  3645. $segList1 = array_slice($segList, 0, 8);
  3646. $data['keyword'] = implode(',', $segList1);
  3647. }
  3648. if ($data['description'] == '') {
  3649. //提取内容中的描述
  3650. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3651. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3652. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3653. }
  3654. if ($data['status'] == 1) {
  3655. $this->sendMessage([
  3656. 'talk_type' => 200,
  3657. 'title' => $data['name'],
  3658. 'content' => '提交了审核',
  3659. 'messageType' => 3,
  3660. ]);
  3661. }
  3662. $result = Good::insert($data);
  3663. if (empty($result)) {
  3664. return Result::error("添加失败", 0);
  3665. }
  3666. return Result::success($result);
  3667. }
  3668. public function updateGood(array $data): array
  3669. {
  3670. $data['city_id'] = end($data['city_arr_id']);
  3671. $data['catid'] = end($data['cat_arr_id']);
  3672. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3673. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3674. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3675. //设置东八区
  3676. date_default_timezone_set('Asia/Shanghai');
  3677. $data['updated_at'] = date('Y-m-d H:i:s');
  3678. if (isset($data['price']) && $data['price'] == '') {
  3679. $data['price'] = 0;
  3680. }
  3681. if ($data['imgurl'] == '') {
  3682. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3683. preg_match_all($reg, $data['detail'], $matches);
  3684. if (isset($matches[1][0])) {
  3685. //截取varchar240
  3686. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3687. }
  3688. }
  3689. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3690. //提取标题+内容中的关键词
  3691. $data['keyword'] = $data['name'];
  3692. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3693. Jieba::init(); // 初始化 jieba-php
  3694. Finalseg::init();
  3695. $segList = Jieba::cut($data['keyword']);
  3696. $segList1 = array_slice($segList, 0, 8);
  3697. $data['keyword'] = implode(',', $segList1);
  3698. }
  3699. if ($data['description'] == '') {
  3700. //提取内容中的描述
  3701. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3702. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3703. }
  3704. if ($data['status'] == 1) {
  3705. $this->sendMessage([
  3706. 'talk_type' => 200,
  3707. 'title' => $data['name'],
  3708. 'content' => '提交了审核',
  3709. 'messageType' => 3,
  3710. ]);
  3711. }
  3712. $result = Good::where('id', $data['id'])->update($data);
  3713. if (empty($result)) {
  3714. return Result::error("更新失败", 0);
  3715. }
  3716. return Result::success($result);
  3717. }
  3718. public function delGood(array $data): array
  3719. {
  3720. $result = Good::where('id', $data['id'])->delete();
  3721. if (empty($result)) {
  3722. return Result::error("删除失败", 0);
  3723. }
  3724. return Result::success($result);
  3725. }
  3726. //20250226 产品列表
  3727. //20250306 求职信息
  3728. public function getJobHuntingList(array $data): array
  3729. {
  3730. $where = [];
  3731. if (isset($data['username']) && !empty($data['username'])) {
  3732. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3733. }
  3734. //status 1待审核2已审核3已拒绝
  3735. if (isset($data['status']) && $data['status'] != '') {
  3736. $where = [
  3737. 'job_hunting.status' => $data['status'],
  3738. ];
  3739. }
  3740. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3741. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3742. unset($data['type_id']);
  3743. if ($type_id != '10000') {
  3744. $where[] = ['job_hunting.user_id', '=', $user_id];
  3745. }
  3746. $result = JobHunting::where($where)
  3747. ->when(!empty($data['status1']), function ($query) use ($data) {
  3748. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3749. })
  3750. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3751. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3752. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3753. ->orderBy("updated_at", "desc")
  3754. ->limit($data['page_size'])
  3755. ->offset(($data['page'] - 1) * $data['page_size'])
  3756. ->get();
  3757. if (empty($result)) {
  3758. return Result::error("查询失败", 0);
  3759. }
  3760. $count = JobHunting::where($where)
  3761. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3762. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3763. ->count();
  3764. $data = [
  3765. 'rows' => $result->toArray(),
  3766. 'count' => $count,
  3767. ];
  3768. return Result::success($data);
  3769. }
  3770. public function getJobHuntingApply(array $data): array
  3771. {
  3772. var_dump($data, '-----------------test--------1-');
  3773. $where = [];
  3774. if (isset($data['username']) && !empty($data['username'])) {
  3775. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3776. }
  3777. if (isset($data['salary']) && !empty($data['salary'])) {
  3778. $where[] = [
  3779. 'job_hunting.salary',
  3780. '=',
  3781. $data['salary'],
  3782. ];
  3783. }
  3784. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3785. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3786. unset($data['type_id']);
  3787. if ($type_id != '10000') {
  3788. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3789. }
  3790. var_dump($where, '-----------------test---------');
  3791. $result = jobApply::where($where)
  3792. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3793. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3794. // })
  3795. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3796. ->where('job_enum.egroup', '=', 'income')
  3797. ->where('job_hunting.status', 2) //已审核
  3798. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3799. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3800. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3801. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3802. //职位----是申请职位
  3803. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3804. ->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')
  3805. ->orderBy("job_hunting.updated_at", "desc")
  3806. ->limit($data['page_size'])
  3807. ->offset(($data['page'] - 1) * $data['page_size'])
  3808. ->get();
  3809. if (empty($result)) {
  3810. return Result::error("查询失败", 0);
  3811. }
  3812. $count = jobApply::where($where)
  3813. ->where('job_enum.egroup', '=', 'income')
  3814. ->where('job_hunting.status', 2) //已审核
  3815. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3816. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3817. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3818. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3819. //职位----是申请职位
  3820. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3821. ->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')
  3822. ->count();
  3823. $data = [
  3824. 'rows' => $result->toArray(),
  3825. 'count' => $count,
  3826. ];
  3827. return Result::success($data);
  3828. }
  3829. public function addJobHunting(array $data): array
  3830. {
  3831. date_default_timezone_set('Asia/Shanghai');
  3832. unset($data['company_name']);
  3833. unset($data['job_industry']);
  3834. unset($data['job_name']);
  3835. unset($data['department']);
  3836. unset($data['job_timeList']);
  3837. unset($data['job_content']);
  3838. unset($data['job_typename']); //不知道这是啥,
  3839. $data['created_at'] = date('Y-m-d H:i:s');
  3840. $data['updated_at'] = date('Y-m-d H:i:s');
  3841. //根据用户 user_id 只能添加一次
  3842. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3843. if (!empty($result)) {
  3844. return Result::error("您已添加过求职信息", 0);
  3845. }
  3846. var_dump($result, '-----------------test---------');
  3847. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3848. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3849. $cityArr = json_decode($data['city_arr_id'], true);
  3850. $data['city_id'] = end($cityArr);
  3851. } else {
  3852. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3853. $data['city_id'] = end($data['city_arr_id']);
  3854. }
  3855. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3856. $this->sendMessage([
  3857. 'talk_type' => 600,
  3858. 'title' => $data['name'],
  3859. 'content' => '提交了审核',
  3860. 'messageType' => 11,
  3861. ]);
  3862. }
  3863. $result = JobHunting::create($data);
  3864. if (empty($result)) {
  3865. return Result::error("添加失败", 0);
  3866. }
  3867. return Result::success($result);
  3868. }
  3869. public function delJobHunting(array $data): array
  3870. {
  3871. $result = JobHunting::where('id', $data['id'])->delete();
  3872. if (empty($result)) {
  3873. return Result::error("删除失败", 0);
  3874. }
  3875. return Result::success($result);
  3876. }
  3877. public function updateJobHunting(array $data): array
  3878. {
  3879. //设置东八区
  3880. date_default_timezone_set('Asia/Shanghai');
  3881. unset($data['company_name']);
  3882. unset($data['job_industry']);
  3883. unset($data['job_name']);
  3884. unset($data['department']);
  3885. unset($data['job_timeList']);
  3886. unset($data['job_content']);
  3887. unset($data['job_typename']); //不知道这是啥,
  3888. $data['created_at'] = date('Y-m-d H:i:s');
  3889. $data['updated_at'] = date('Y-m-d H:i:s');
  3890. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3891. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3892. $cityArr = json_decode($data['city_arr_id'], true);
  3893. $data['city_id'] = end($cityArr);
  3894. } else {
  3895. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3896. $data['city_id'] = end($data['city_arr_id']);
  3897. }
  3898. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3899. $this->sendMessage([
  3900. 'talk_type' => 600,
  3901. 'title' => $data['name'],
  3902. 'content' => '提交了审核',
  3903. 'messageType' => 11,
  3904. ]);
  3905. }
  3906. $result = JobHunting::where('id', $data['id'])->update($data);
  3907. if (empty($result)) {
  3908. return Result::error("更新失败", 0);
  3909. }
  3910. return Result::success($result);
  3911. }
  3912. public function getJobHuntingInfo(array $data): array
  3913. {
  3914. $result = JobHunting::where('id', $data['id'])->first();
  3915. if (empty($result)) {
  3916. return Result::error("查询失败", 0);
  3917. }
  3918. return Result::success($result);
  3919. }
  3920. public function getJobHuntingData(array $data): array
  3921. {
  3922. $jobEnum = JobEnum::get();
  3923. $jobIndustry = JobIndustry::get();
  3924. $jobNature = JobNature::get();
  3925. $jobPosition = JobPosition::get();
  3926. $data = [
  3927. 'jobEnum' => $jobEnum,
  3928. 'jobIndustry' => $jobIndustry,
  3929. 'jobNature' => $jobNature,
  3930. 'jobPosition' => $jobPosition,
  3931. ];
  3932. return Result::success($data);
  3933. }
  3934. public function delJobHuntingInfo(array $data): array
  3935. {
  3936. $result = JobHunting::where('id', $data['id'])->delete();
  3937. return Result::success();
  3938. }
  3939. //20250324 通知,公告,消息
  3940. public function delNotice(array $data): array
  3941. {
  3942. $result = Notice::where('id', $data['id'])->delete();
  3943. if ($result) {
  3944. return Result::success();
  3945. } else {
  3946. return Result::error("删除失败", 0);
  3947. }
  3948. }
  3949. public function getNoticeInfo(array $data): array
  3950. {
  3951. $result = Notice::where('id', $data['id'])->first();
  3952. // var_dump($result['re_user_ids'], '--------------------');
  3953. if (empty($result)) {
  3954. return Result::error("查询失败", 0);
  3955. }
  3956. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  3957. $re_user_ids = json_decode($result['re_user_ids'], true);
  3958. var_dump($re_user_ids, '--------------1---test---------');
  3959. var_dump($data, '--------------1---test---------');
  3960. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  3961. //如果已经存在,就不再添加
  3962. if (isset($result['read_id']) && !empty($result['read_id'])) {
  3963. $read_id = json_decode($result['read_id'], true);
  3964. if (!is_array($read_id)) {
  3965. $read_id = [];
  3966. }
  3967. if (!in_array($data['user_id'], $read_id)) {
  3968. $read_id[] = $data['user_id'];
  3969. $result['read_id'] = json_encode($read_id);
  3970. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  3971. }
  3972. } else {
  3973. //如果不存在,就添加
  3974. $result['read_id'] = json_encode([$data['user_id']]);
  3975. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  3976. }
  3977. }
  3978. return Result::success($result);
  3979. }
  3980. public function addNotice(array $data): array
  3981. {
  3982. date_default_timezone_set('Asia/Shanghai');
  3983. $data['created_at'] = date('Y-m-d H:i:s');
  3984. $data['updated_at'] = date('Y-m-d H:i:s');
  3985. $user_id = UserInfo::
  3986. //city_id不是null
  3987. whereNotNull('city_id')
  3988. ->whereNotNull('department_id')
  3989. ->where(function ($query) use ($data) {
  3990. $query->where(function ($subQuery) use ($data) {
  3991. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3992. });
  3993. })
  3994. ->where(function ($query) use ($data) {
  3995. $query->where(function ($subQuery) use ($data) {
  3996. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3997. });
  3998. })
  3999. ->pluck('user_id')->toArray();
  4000. $user_id = array_unique($user_id);
  4001. $chat_ids = $user_id;
  4002. $user_id = json_encode($user_id);
  4003. $data['re_user_ids'] = $user_id;
  4004. $this->sendMessage([
  4005. 'talk_type' => 700,
  4006. 'title' => $data['title'],
  4007. 'content' => '提交了审核',
  4008. 'messageType' => 5,
  4009. ]);
  4010. $result = Notice::insertGetId($data);
  4011. if (empty($result)) {
  4012. return Result::error("添加失败", 0);
  4013. }
  4014. return Result::success($result);
  4015. }
  4016. public function updateNotice(array $data): array
  4017. {
  4018. date_default_timezone_set('Asia/Shanghai');
  4019. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4020. $user_id = UserInfo::
  4021. //city_id不是null
  4022. whereNotNull('city_id')
  4023. ->whereNotNull('department_id')
  4024. ->where(function ($query) use ($data) {
  4025. $query->where(function ($subQuery) use ($data) {
  4026. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4027. });
  4028. })
  4029. ->where(function ($query) use ($data) {
  4030. $query->where(function ($subQuery) use ($data) {
  4031. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4032. });
  4033. })
  4034. ->pluck('user_id')->toArray();
  4035. $user_id = array_unique($user_id);
  4036. $user_id = json_encode($user_id);
  4037. $data['re_user_ids'] = $user_id;
  4038. $data['updated_at'] = date('Y-m-d H:i:s');
  4039. $this->sendMessage([
  4040. 'talk_type' => 700,
  4041. 'title' => $data['title'],
  4042. 'content' => '提交了审核',
  4043. 'messageType' => 5,
  4044. ]);
  4045. $result = Notice::where('id', $data['id'])->update($data);
  4046. return Result::success($result);
  4047. }
  4048. public function getNoticeList(array $data): array
  4049. {
  4050. $where = [];
  4051. //title
  4052. if (isset($data['title']) && !empty($data['title'])) {
  4053. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4054. }
  4055. //level
  4056. if (isset($data['level']) && !empty($data['level'])) {
  4057. $where[] = ['notice.level', '=', $data['level']];
  4058. }
  4059. //status
  4060. if (isset($data['status']) && !empty($data['status'])) {
  4061. $where[] = ['notice.status', '=', $data['status']];
  4062. }
  4063. //type
  4064. if (isset($data['type']) && !empty($data['type'])) {
  4065. $where[] = ['notice.type', '=', $data['type']];
  4066. }
  4067. var_dump($data, '------------11111-2----test---------');
  4068. if ($data['type_id'] == 10000) {
  4069. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4070. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4071. })
  4072. ->where($where)
  4073. ->orderBy('updated_at', 'desc')
  4074. ->limit($data['page_size'])
  4075. ->offset(($data['page'] - 1) * $data['page_size'])
  4076. ->get();
  4077. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4078. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4079. })
  4080. ->where($where)
  4081. ->orderBy('updated_at', 'desc')
  4082. ->count();
  4083. } else {
  4084. $result = Notice::where($where)
  4085. // ->where('user_id', $data['user_id'])
  4086. ->Where(function ($query) use ($data) {
  4087. $query->Where(function ($q) use ($data) {
  4088. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4089. ->orWhere('notice.user_id', $data['user_id']);
  4090. });
  4091. })
  4092. ->when(!empty($data['status1']), function ($query) use ($data) {
  4093. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4094. })
  4095. ->orderBy('updated_at', 'desc')
  4096. ->limit($data['page_size'])
  4097. ->offset(($data['page'] - 1) * $data['page_size'])
  4098. ->get();
  4099. $total = Notice::where($where)
  4100. ->when(!empty($data['status1']), function ($query) use ($data) {
  4101. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4102. })
  4103. // ->where('user_id', $data['user_id'])
  4104. ->Where(function ($query) use ($data) {
  4105. $query->Where(function ($q) use ($data) {
  4106. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4107. ->orWhere('notice.user_id', $data['user_id']);
  4108. });
  4109. })
  4110. ->count();
  4111. }
  4112. if (empty($result)) {
  4113. return Result::error("查询失败", 0);
  4114. }
  4115. $data = [
  4116. 'rows' => $result,
  4117. 'count' => $total,
  4118. ];
  4119. return Result::success($data);
  4120. }
  4121. public function getNoticeDetail(array $data): array
  4122. {
  4123. $result = Notice::where('id', $data['id'])->first();
  4124. if (empty($result)) {
  4125. return Result::error("查询失败", 0);
  4126. }
  4127. return Result::success($result);
  4128. }
  4129. public function deleteNotice(array $data): array
  4130. {
  4131. $notice = Notice::where('id', $data['id'])->first();
  4132. if (empty($notice)) {
  4133. return Result::error("删除失败", 0);
  4134. }
  4135. $chat_group_id = $notice->group_id;
  4136. if ($chat_group_id) {
  4137. //删除群聊
  4138. ChatGroups::where('id', $chat_group_id)->delete();
  4139. //删除群成员
  4140. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4141. //删除群聊记录
  4142. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4143. }
  4144. $result = Notice::where('id', $data['id'])->delete();
  4145. return Result::success($result);
  4146. }
  4147. public function getComplaintList(array $data): array
  4148. {
  4149. var_dump($data, '00000001000000000000');
  4150. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4151. unset($data['type_id']);
  4152. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4153. $where = [];
  4154. if ($type_id != 10000 && empty($data['deal_user'])) {
  4155. $where['complaint.user_id'] = $user_id;
  4156. }
  4157. if (!empty($data['title'])) {
  4158. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4159. }
  4160. if (!empty($data['department_id'])) {
  4161. $where['complaint.department_id'] = $data['department_id'];
  4162. }
  4163. if (!empty($data['deal'])) {
  4164. $where['complaint.deal'] = $data['deal'];
  4165. }
  4166. if (!empty($data['status'])) {
  4167. $where['complaint.status'] = $data['status'];
  4168. }
  4169. var_dump(!empty($data['deal_user']), '----------1');
  4170. var_dump($where, '----------2');
  4171. $result = Complaint::where($where)
  4172. ->when(!empty($data['status1']), function ($query) use ($data) {
  4173. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4174. })
  4175. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4176. //json re_user_ids data[user_id]是不是在里面
  4177. $query->Where(function ($q) use ($data) {
  4178. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4179. ->where('complaint.status', 2);
  4180. });
  4181. })
  4182. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4183. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4184. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4185. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4186. ->orderBy('updated_at', 'desc')
  4187. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4188. //sql输出
  4189. if (empty($result)) {
  4190. return Result::error("暂无投诉信息", 0);
  4191. }
  4192. // 取出数据
  4193. $rows = $result->items();
  4194. $count = $result->total();
  4195. $responseData = [
  4196. 'rows' => $rows,
  4197. 'count' => $count,
  4198. ];
  4199. return Result::success($responseData);
  4200. }
  4201. public function getComplaintInfo(array $data): array
  4202. {
  4203. $result = Complaint::where('id', $data['id'])->first();
  4204. if (empty($result)) {
  4205. return Result::error("查询失败", 0);
  4206. }
  4207. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4208. $re_user_ids = json_decode($result['re_user_ids'], true);
  4209. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4210. //如果已经存在,就不再添加
  4211. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4212. $read_id = json_decode($result['read_id'], true);
  4213. if (!is_array($read_id)) {
  4214. $read_id = [];
  4215. }
  4216. if (!in_array($data['user_id'], $read_id)) {
  4217. $read_id[] = $data['user_id'];
  4218. $result['read_id'] = json_encode($read_id);
  4219. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4220. }
  4221. } else {
  4222. //如果不存在,就添加
  4223. $result['read_id'] = json_encode([$data['user_id']]);
  4224. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4225. }
  4226. }
  4227. return Result::success($result);
  4228. }
  4229. public function addComplaint(array $data): array
  4230. {
  4231. date_default_timezone_set('Asia/Shanghai');
  4232. $data['created_at'] = date('Y-m-d H:i:s');
  4233. $data['updated_at'] = date('Y-m-d H:i:s');
  4234. $this->sendMessage([
  4235. 'talk_type' => 800,
  4236. 'title' => $data['title'],
  4237. 'content' => '提交了审核',
  4238. 'messageType' => 6,
  4239. ]);
  4240. $result = Complaint::create($data);
  4241. return Result::success($result);
  4242. }
  4243. public function updateComplaint(array $data): array
  4244. {
  4245. date_default_timezone_set('Asia/Shanghai');
  4246. $data['updated_at'] = date('Y-m-d H:i:s');
  4247. $user_id = $data['user_id'] ?? 0;
  4248. $type_id = $data['type_id'] ?? 0;
  4249. unset($data['user_id']);
  4250. unset($data['type_id']);
  4251. $this->sendMessage([
  4252. 'talk_type' => 800,
  4253. 'title' => $data['title'],
  4254. 'content' => '提交了审核',
  4255. 'messageType' => 6,
  4256. ]);
  4257. $result = Complaint::where('id', $data['id'])->update($data);
  4258. return Result::success($result);
  4259. }
  4260. public function deleteComplaint(array $data): array
  4261. {
  4262. $result = Complaint::where('id', $data['id'])->delete();
  4263. return Result::success($result);
  4264. }
  4265. public function getComplainInfo(array $data): array
  4266. {
  4267. $result = Complaint::where('id', $data['id'])->first();
  4268. if (empty($result)) {
  4269. return Result::error("查询失败", 0);
  4270. }
  4271. return Result::success($result);
  4272. }
  4273. public function updateComplaintStatus(array $data): array
  4274. {
  4275. date_default_timezone_set('Asia/Shanghai');
  4276. $data['updated_at'] = date('Y-m-d H:i:s');
  4277. $user_id = $data['user_id'] ?? 0;
  4278. $type_id = $data['type_id'] ?? 0;
  4279. unset($data['user_id']);
  4280. unset($data['type_id']);
  4281. //处理, 写入处理人
  4282. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4283. $data['real_deal_user'] = $user_id;
  4284. }
  4285. //如果是deal 23,则判断是不是处理人
  4286. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4287. $complaintInof = Complaint::where('id', $data['id'])
  4288. ->where('real_deal_user', $user_id)
  4289. ->first();
  4290. if (empty($complaintInof)) {
  4291. return Result::error("处理人错误", 0);
  4292. }
  4293. }
  4294. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4295. if ($data['status'] == 1) {
  4296. $this->sendMessage([
  4297. 'talk_type' => 800,
  4298. 'title' => $complaintInfo['title'],
  4299. 'content' => '提交了审核',
  4300. 'messageType' => 6,
  4301. ]);
  4302. }
  4303. if ($data['status'] == 2 && !isset($data['deal'])) {
  4304. $this->sendMessage([
  4305. 'talk_type' => 801,
  4306. 'title' => $complaintInfo['title'],
  4307. 'content' => '审核通过',
  4308. 'messageType' => 6,
  4309. 'user_id' => $complaintInfo['user_id'],
  4310. ]);
  4311. $this->sendMessage([
  4312. 'talk_type' => 802,
  4313. 'title' => $complaintInfo['title'],
  4314. 'content' => '待处理',
  4315. 'messageType' => 6,
  4316. 'user_id' => $complaintInfo['re_user_ids'],
  4317. ]);
  4318. }
  4319. if ($data['status'] == 3 && !isset($data['deal'])) {
  4320. $this->sendMessage([
  4321. 'talk_type' => 801,
  4322. 'title' => $complaintInfo['title'],
  4323. 'content' => '审核拒绝',
  4324. 'messageType' => 6,
  4325. 'user_id' => $complaintInfo['user_id'],
  4326. ]);
  4327. }
  4328. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4329. $this->sendMessage([
  4330. 'talk_type' => 802,
  4331. 'title' => $complaintInfo['title'],
  4332. 'content' => '处理中',
  4333. 'messageType' => 6,
  4334. 'user_id' => $complaintInfo['re_user_ids'],
  4335. ]);
  4336. }
  4337. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4338. $this->sendMessage([
  4339. 'talk_type' => 802,
  4340. 'title' => $complaintInfo['title'],
  4341. 'content' => '不予处理',
  4342. 'messageType' => 6,
  4343. 'user_id' => $complaintInfo['re_user_ids'],
  4344. ]);
  4345. }
  4346. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4347. $this->sendMessage([
  4348. 'talk_type' => 802,
  4349. 'title' => $complaintInfo['title'],
  4350. 'content' => '已完结',
  4351. 'messageType' => 6,
  4352. 'user_id' => $complaintInfo['re_user_ids'],
  4353. ]);
  4354. }
  4355. $result = complaint::where('id', $data['id'])->update($data);
  4356. return Result::success($result);
  4357. }
  4358. public function updateGoodStatus(array $data): array
  4359. {
  4360. $user_id = $data['user_id'] ?? 0;
  4361. $type_id = $data['type_id'] ?? 0;
  4362. unset($data['user_id']);
  4363. unset($data['type_id']);
  4364. $goodInfo = Good::where('id', $data['id'])->first();
  4365. if ($data['status'] == 2) {
  4366. $this->sendMessage([
  4367. 'talk_type' => 201,
  4368. 'title' => $goodInfo['name'],
  4369. 'content' => '审核通过',
  4370. 'messageType' => 3,
  4371. 'user_id' => $goodInfo['user_id'],
  4372. ]);
  4373. }
  4374. if ($data['status'] == 3) {
  4375. $this->sendMessage([
  4376. 'talk_type' => 201,
  4377. 'title' => $goodInfo['name'],
  4378. 'content' => '审核拒绝',
  4379. 'messageType' => 3,
  4380. 'user_id' => $goodInfo['user_id'],
  4381. ]);
  4382. }
  4383. if ($data['status'] == 1) {
  4384. $this->sendMessage([
  4385. 'talk_type' => 200,
  4386. 'title' => $goodInfo['name'],
  4387. 'content' => '提交了审核',
  4388. 'messageType' => 3,
  4389. ]);
  4390. }
  4391. $result = Good::where('id', $data['id'])->update($data);
  4392. return Result::success($result);
  4393. }
  4394. public function updateJobHuntingStatus(array $data): array
  4395. {
  4396. $user_id = $data['user_id'] ?? 0;
  4397. $type_id = $data['type_id'] ?? 0;
  4398. unset($data['user_id']);
  4399. unset($data['type_id']);
  4400. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4401. if ($data['status'] == 2) {
  4402. $this->sendMessage([
  4403. 'talk_type' => 601,
  4404. 'title' => $jogHuntingInfo['name'],
  4405. 'content' => '审核通过',
  4406. 'messageType' => 11,
  4407. 'user_id' => $jogHuntingInfo['user_id'],
  4408. ]);
  4409. }
  4410. if ($data['status'] == 3) {
  4411. $this->sendMessage([
  4412. 'talk_type' => 601,
  4413. 'title' => $jogHuntingInfo['name'],
  4414. 'content' => '审核拒绝',
  4415. 'messageType' => 11,
  4416. 'user_id' => $jogHuntingInfo['user_id'],
  4417. ]);
  4418. }
  4419. if ($data['status'] == 1) {
  4420. $this->sendMessage([
  4421. 'talk_type' => 600,
  4422. 'title' => $jogHuntingInfo['name'],
  4423. 'content' => '提交了审核',
  4424. 'messageType' => 11,
  4425. ]);
  4426. }
  4427. $result = JobHunting::where('id', $data['id'])->update($data);
  4428. return Result::success($result);
  4429. }
  4430. public function updateNoticeStatus(array $data): array
  4431. {
  4432. $user_id = $data['user_id'] ?? 0;
  4433. $type_id = $data['type_id'] ?? 0;
  4434. unset($data['user_id']);
  4435. unset($data['type_id']);
  4436. //查询公告
  4437. $notice = Notice::where('id', $data['id'])->first();
  4438. if (empty($notice)) {
  4439. return Result::error("公告不存在", 0);
  4440. }
  4441. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4442. if ($data['status'] == 2 && $notice['is_group'] == 1 && $notice['status'] == 1 && empty($notice['group_id'])) {
  4443. //chat_group
  4444. $group_id = PublicData::uuid();
  4445. $groupData = [
  4446. 'id' => $group_id,
  4447. 'creator_id' => $notice['user_id'],
  4448. 'group_name' => $notice['group_name'] ?? '',
  4449. 'profile' => $notice['profile'] ?? 0,
  4450. ];
  4451. var_dump($groupData, '-----------------groupData-------');
  4452. $groupResult = ChatGroups::insertGetId($groupData);
  4453. var_dump($groupResult, '-----------------groupid-------');
  4454. $groupMemberData = [
  4455. 'id' => PublicData::uuid(),
  4456. 'user_id' => $notice['user_id'],
  4457. 'group_id' => $group_id,
  4458. 'leader' => 2,
  4459. ];
  4460. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4461. //$chat_ids 去除掉$data['user_id']
  4462. $chat_ids = json_decode($notice['re_user_ids'], true);
  4463. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4464. //插入群成员表
  4465. $groupMemberDataUser = [];
  4466. $chatData = [];
  4467. foreach ($chat_ids as $key => $value) {
  4468. $groupMemberDataUser[] = [
  4469. 'id' => PublicData::uuid(),
  4470. 'user_id' => $value,
  4471. 'group_id' => $group_id,
  4472. 'leader' => 1,
  4473. ];
  4474. $chatData[] = [
  4475. 'user_id' => $value,
  4476. 'msg_type' => 1,
  4477. 'receiver_id' => $group_id,
  4478. 'content' => '通过通知创建群聊',
  4479. 'group_receiver_id' => $notice['user_id'],
  4480. 'action' => 'recieved',
  4481. 'created_at' => date('Y-m-d H:i:s'),
  4482. ];
  4483. }
  4484. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4485. ChatGroupsMember::insert($groupMemberDataUser);
  4486. //插入一条管理员聊天记录
  4487. $chatData[] = [
  4488. 'user_id' => $notice['user_id'],
  4489. 'msg_type' => 1,
  4490. 'receiver_id' => $group_id,
  4491. 'content' => '通过通知创建群聊',
  4492. 'group_receiver_id' => $notice['user_id'],
  4493. 'action' => 'said',
  4494. 'created_at' => date('Y-m-d H:i:s'),
  4495. ];
  4496. var_dump($chatData, '-----------------chatData-------');
  4497. $chatResult = ChatRecords::insert($chatData);
  4498. //更新result的 group_id
  4499. $data['group_id'] = $group_id;
  4500. Notice::where(['id' => $data['id']])->update($data);
  4501. }
  4502. $result = Notice::where('id', $data['id'])->update($data);
  4503. $noticeInfo = Notice::where('id', $data['id'])->first();
  4504. if ($data['status'] == 2) {
  4505. $this->sendMessage([
  4506. 'talk_type' => 701,
  4507. 'title' => $noticeInfo['title'],
  4508. 'content' => '审核通过',
  4509. 'messageType' => 3,
  4510. 'user_id' => $noticeInfo['user_id'],
  4511. ]);
  4512. }
  4513. if ($data['status'] == 3) {
  4514. $this->sendMessage([
  4515. 'talk_type' => 701,
  4516. 'title' => $noticeInfo['title'],
  4517. 'content' => '审核拒绝',
  4518. 'messageType' => 3,
  4519. 'user_id' => $noticeInfo['user_id'],
  4520. ]);
  4521. }
  4522. if ($data['status'] == 1) {
  4523. $this->sendMessage([
  4524. 'talk_type' => 700,
  4525. 'title' => $noticeInfo['title'],
  4526. 'content' => '提交了审核',
  4527. 'messageType' => 3,
  4528. ]);
  4529. }
  4530. return Result::success($result);
  4531. }
  4532. public function getDUser(array $data): array
  4533. {
  4534. if (!empty($data['ids'])) {
  4535. $user = User::whereIn('id', $data['ids'])->getall();
  4536. if (empty($user)) {
  4537. return Result::error('无数据', 0);
  4538. }
  4539. return Result::success($user);
  4540. }
  4541. $where = [];
  4542. if (!empty($data['department_id'])) {
  4543. $where['department_id'] = $data['department_id'];
  4544. }
  4545. if (!empty($data['city_id'])) {
  4546. $where['city_id'] = $data['city_id'];
  4547. }
  4548. $result = User::where('type_id', 2)
  4549. ->where('status', 1)
  4550. ->where($where)
  4551. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4552. ->get();
  4553. if (empty($result)) {
  4554. return Result::error("查询失败", 0);
  4555. }
  4556. return Result::success($result);
  4557. }
  4558. /**
  4559. * 验证导航名称是否重复
  4560. * @return void
  4561. */
  4562. public function checkCategoryName(array $data): array
  4563. {
  4564. $result = Category::when($data, function ($query) use ($data) {
  4565. if (isset($data['name']) && $data['name']) {
  4566. $query->where("name", $data['name']);
  4567. }
  4568. if (isset($data['id']) && $data['id']) {
  4569. $query->where("id", "!=", $data['id']);
  4570. }
  4571. })->first();
  4572. if ($result) {
  4573. return Result::error("已存在");
  4574. } else {
  4575. return Result::success();
  4576. }
  4577. }
  4578. //20250226 产品列表
  4579. // 20250306 -------招聘--------fr
  4580. /*
  4581. * 招聘列表
  4582. * */
  4583. public function getJobRecruitingList(array $data): array
  4584. {
  4585. $where = [];
  4586. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4587. if ($data['checkout'] == 0) {
  4588. $job_status = [0, 2];
  4589. } else {
  4590. $job_status = [1];
  4591. }
  4592. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4593. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4594. }
  4595. $user = User::where('id', $data['user_id'])->first();
  4596. if (empty($user)) {
  4597. return Result::error("用户不存在", 0);
  4598. }
  4599. // 3:企业会员
  4600. if ($user['type_id'] == 3) {
  4601. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4602. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4603. }
  4604. // 如果 $where 为空,则不添加 where 条件
  4605. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4606. return $query->where($where);
  4607. })
  4608. ->whereIn('job_recruiting.status', $job_status)
  4609. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4610. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4611. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4612. ->orderBy("updated_at", "desc")
  4613. ->offset(($data['page'] - 1) * $data['page_size'])
  4614. ->limit($data['page_size'])
  4615. ->get()
  4616. ->all();
  4617. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4618. return $query->where($where);
  4619. })
  4620. ->whereIn('job_recruiting.status', $job_status)
  4621. ->count();
  4622. if (empty($result)) {
  4623. return Result::error("暂无招聘信息", 0);
  4624. }
  4625. return Result::success($result);
  4626. }
  4627. /*
  4628. * 招聘信息添加
  4629. * */
  4630. public function addJobRecruiting(array $data): array
  4631. {
  4632. // return Result::success($data);
  4633. $user = User::where('user.id', $data['user_id'])
  4634. ->where('user.status', 1)
  4635. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4636. ->select(
  4637. 'user.type_id',
  4638. 'user.mobile',
  4639. 'user.email',
  4640. 'user_info.business_name',
  4641. 'user_info.company_hy_id',
  4642. 'user_info.company_nature',
  4643. 'user_info.company_size',
  4644. 'user_info.introduction',
  4645. 'user_info.real_name',
  4646. 'user_info.company_url',
  4647. 'user_info.address_arr_id',
  4648. 'user_info.address'
  4649. )
  4650. ->first();
  4651. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4652. return Result::error("用户不存在", 0);
  4653. }
  4654. $web = Website::where('id', $data['website_id'])->first();
  4655. if (empty($web)) {
  4656. return Result::error("网站不存在", 0);
  4657. }
  4658. // return Result::success($user);
  4659. $data['action_id'] = $data['user_id'];
  4660. $data['user_type'] = $user['type_id'];
  4661. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4662. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4663. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4664. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4665. // 公司地址 管理员必填
  4666. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4667. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4668. // 管理员-企业相关信息
  4669. $company = [
  4670. // 'user_id' => $data['user_id']?? null,
  4671. 'business_name' => $data['business_name'] ?? null,
  4672. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4673. 'company_size' => $data['company_size'] ?? null,
  4674. 'company_nature' => $data['company_nature'] ?? null,
  4675. 'introduction' => $data['introduction'] ?? null,
  4676. 'real_name' => $data['real_name'] ?? null,
  4677. 'mobile' => $data['mobile'] ?? null,
  4678. 'company_url' => $data['company_url'] ?? null,
  4679. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4680. 'address' => $data['address'] ?? null,
  4681. 'email' => $data['email'] ?? null,
  4682. ];
  4683. //去掉相关企业信息
  4684. $job = array_diff_key($data, array_flip(array_keys($company)));
  4685. Db::beginTransaction();
  4686. try {
  4687. // 先添加职位相关信息
  4688. if ($user['type_id'] == 10000) {
  4689. $job['status'] = 1;
  4690. }
  4691. if (empty($data['experience']) || $data['experience'] == '') {
  4692. $job['experience'] = null;
  4693. } else {
  4694. $job['experience'] = $data['experience'];
  4695. }
  4696. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  4697. $this->sendMessage([
  4698. 'talk_type' => 500,
  4699. 'title' => $data['title'],
  4700. 'content' => '提交了审核',
  4701. 'messageType' => 10,
  4702. ]);
  4703. }
  4704. $jobId = JobRecruiting::insertGetId($job);
  4705. if (empty($jobId)) {
  4706. Db::rollBack();
  4707. return Result::error("添加失败");
  4708. }
  4709. // 添加公司信息
  4710. $company['user_id'] = $data['user_id'] ?? null;
  4711. $company['job_id'] = $jobId;
  4712. $company['user_type'] = $user['type_id'] ?? null;
  4713. $company['website_id'] = $data['website_id'] ?? null;
  4714. if ($user['type_id'] == 10000) {
  4715. // 管理员添加企业信息
  4716. // return Result::success($company);
  4717. $companyId = JobCompany::insertGetId($company);
  4718. if (empty($companyId)) {
  4719. Db::rollBack();
  4720. return Result::error("添加失败");
  4721. }
  4722. } else {
  4723. // 企业会员添加企业信息
  4724. $company = [
  4725. 'user_id' => $data['user_id'] ?? null,
  4726. 'business_name' => $user['business_name'] ?? null,
  4727. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4728. 'company_size' => $user['company_size'] ?? null,
  4729. 'company_nature' => $user['company_nature'] ?? null,
  4730. 'introduction' => $user['introduction'] ?? null,
  4731. 'real_name' => $user['real_name'] ?? null,
  4732. 'mobile' => $user['mobile'] ?? null,
  4733. 'company_url' => $user['company_url'] ?? null,
  4734. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4735. 'address' => $user['address'] ?? null,
  4736. 'email' => $user['email'] ?? null,
  4737. 'website_id' => $data['website_id'] ?? null,
  4738. 'user_type' => $user['type_id'] ?? null,
  4739. 'job_id' => $jobId,
  4740. ];
  4741. $companyId = JobCompany::insertGetId($company);
  4742. if (empty($companyId)) {
  4743. Db::rollBack();
  4744. return Result::error("添加失败");
  4745. }
  4746. // return Result::success($company);
  4747. }
  4748. Db::commit();
  4749. } catch (\Exception $e) {
  4750. Db::rollBack();
  4751. return Result::error($e->getMessage(), 0);
  4752. }
  4753. $result = [
  4754. 'job_id' => $jobId,
  4755. 'company_id' => $companyId,
  4756. ];
  4757. if (empty($result)) {
  4758. return Result::error("添加失败", 0);
  4759. }
  4760. return Result::success($result);
  4761. }
  4762. /*
  4763. * 获取招聘信息详情
  4764. * */
  4765. public function getJobRecruitingInfo(array $data): array
  4766. {
  4767. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4768. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4769. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4770. ->select(
  4771. 'job_recruiting.*',
  4772. 'website.website_name as website_name',
  4773. 'job_company.business_name',
  4774. 'job_company.company_hy_id',
  4775. 'job_company.company_size',
  4776. 'job_company.company_nature',
  4777. 'job_company.introduction',
  4778. 'job_company.real_name',
  4779. 'job_company.mobile',
  4780. 'job_company.company_url',
  4781. 'job_company.address_arr_id',
  4782. 'job_company.address',
  4783. 'job_company.email'
  4784. )
  4785. ->first();
  4786. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4787. if (!empty($cityId)) {
  4788. if (isset($cityId[1]) && $cityId[1] != null) {
  4789. $city = District::where('id', $cityId[1])->first(['name']);
  4790. } else {
  4791. $city = District::where('id', $cityId[0])->first(['name']);
  4792. }
  4793. $result['city'] = $city['name'] ?? '';
  4794. }
  4795. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4796. if (is_array($addressId) && !empty($addressId)) {
  4797. $address = District::whereIn('id', $addressId)
  4798. ->orderBy('level', 'asc')
  4799. ->get(['name'])
  4800. ->pluck('name')
  4801. ->implode('');
  4802. // $job->address_name = $address ?? '';
  4803. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4804. }
  4805. if (empty($result)) {
  4806. return Result::error("招聘信息不存在", 0);
  4807. }
  4808. // return Result::success($job);
  4809. return Result::success($result);
  4810. }
  4811. /*
  4812. * 修改招聘信息
  4813. * */
  4814. public function upJobRecruiting(array $data): array
  4815. {
  4816. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4817. // return Result::success($job);
  4818. if (empty($job)) {
  4819. return Result::error("招聘信息不存在", 0);
  4820. }
  4821. $user = User::where('id', $data['user_id'])->first();
  4822. // return Result::success($user);
  4823. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4824. return Result::error("用户不存在", 0);
  4825. }
  4826. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4827. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4828. }
  4829. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4830. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4831. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4832. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4833. // 公司地址 管理员必填
  4834. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4835. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4836. // 管理员-企业相关信息
  4837. $company = [
  4838. 'business_name' => $data['business_name'] ?? null,
  4839. 'company_hy_id' => $data['hy_id'] ?? null,
  4840. 'company_size' => $data['company_size'] ?? null,
  4841. 'company_nature' => $data['company_nature'] ?? null,
  4842. 'introduction' => $data['introduction'] ?? null,
  4843. 'real_name' => $data['real_name'] ?? null,
  4844. 'mobile' => $data['mobile'] ?? null,
  4845. 'company_url' => $data['company_url'] ?? null,
  4846. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4847. 'address' => $data['address'] ?? null,
  4848. 'email' => $data['email'] ?? null,
  4849. ];
  4850. //去掉相关企业信息
  4851. $data = array_diff_key($data, array_flip(array_keys($company)));
  4852. $jobId = $data['id'];
  4853. $web = $data['website_id'];
  4854. $data['action_id'] = $data['user_id'];
  4855. unset($data['user_id']);
  4856. unset($data['user_type']);
  4857. unset($data['id']);
  4858. unset($data['website_id']);
  4859. // return Result::success($data);
  4860. Db::beginTransaction();
  4861. try {
  4862. // 管理员修改招聘信息
  4863. if ($user['type_id'] == 10000) {
  4864. $data['website_id'] = $web;
  4865. $company['website_id'] = $data['website_id'];
  4866. $data['status'] = 1;
  4867. } else {
  4868. $data['status'] = 0;
  4869. }
  4870. if (empty($data['experience']) || $data['experience'] == '') {
  4871. $job['experience'] = null;
  4872. } else {
  4873. $job['experience'] = $data['experience'];
  4874. }
  4875. // Db::rollBack();
  4876. // return Result::success($company);
  4877. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  4878. $this->sendMessage([
  4879. 'talk_type' => 500,
  4880. 'title' => $data['title'],
  4881. 'content' => '提交了审核',
  4882. 'messageType' => 10,
  4883. ]);
  4884. }
  4885. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4886. if (empty($result['job'])) {
  4887. Db::rollBack();
  4888. return Result::error("修改招聘信息失败");
  4889. }
  4890. // 管理员修改企业相关信息
  4891. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4892. if (empty($result['company'])) {
  4893. Db::rollBack();
  4894. return Result::error("修改企业相关信息失败");
  4895. }
  4896. Db::commit();
  4897. // return Result::success($result);
  4898. } catch (\Exception $e) {
  4899. Db::rollBack();
  4900. return Result::error($e->getMessage(), 0);
  4901. }
  4902. return Result::success($result);
  4903. }
  4904. /*
  4905. * 招聘信息删除
  4906. * */
  4907. public function delJobRecruiting(array $data): array
  4908. {
  4909. $user = User::where('id', $data['user_id'])->first();
  4910. if (empty($user)) {
  4911. return Result::error("用户不存在", 0);
  4912. }
  4913. $job = JobRecruiting::where('id', $data['id'])->first();
  4914. if (empty($job)) {
  4915. return Result::error("招聘信息不存在", 0);
  4916. }
  4917. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4918. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4919. }
  4920. Db::beginTransaction();
  4921. try {
  4922. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4923. if (empty($result['job'])) {
  4924. Db::rollBack();
  4925. return Result::error("删除招聘信息失败");
  4926. }
  4927. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4928. if (empty($result['company'])) {
  4929. Db::rollBack();
  4930. return Result::error("删除企业相关信息失败");
  4931. }
  4932. Db::commit();
  4933. } catch (\Exception $e) {
  4934. Db::rollBack();
  4935. return Result::error($e->getMessage(), 0);
  4936. }
  4937. return Result::success($result);
  4938. }
  4939. /*
  4940. * 获取公司信息
  4941. * */
  4942. public function getJobCompany(array $data): array
  4943. {
  4944. $user = User::where('user.id', $data['user_id'])
  4945. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4946. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4947. ->first();
  4948. // return Result::success($user);
  4949. if (empty($user)) {
  4950. return Result::error("用户不存在", 0);
  4951. }
  4952. if ($user['type_id'] == 3) {
  4953. $result = [
  4954. // 'id' => 0,
  4955. 'user_id' => $data['user_id'],
  4956. 'website_id' => $data['website_id'],
  4957. 'business_name' => $user['business_name'], // 企业名称
  4958. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4959. 'company_nature' => $user['company_nature'], // 公司性质
  4960. 'company_size' => $user['company_size'], // 公司规模
  4961. 'introduction' => $user['introduction'], // 公司简介
  4962. 'real_name' => $user['real_name'], // 企业联系人
  4963. 'mobile' => $user['mobile'], // 企业联系电话
  4964. 'company_url' => $user['company_url'], // 企业网址
  4965. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4966. 'address' => $user['address'], // 企业地址
  4967. 'email' => $user['email'], // 企业邮箱
  4968. ];
  4969. } else {
  4970. return Result::error("用户类型错误", 0);
  4971. }
  4972. if (empty($result)) {
  4973. return Result::error("公司信息不存在", 0);
  4974. }
  4975. return Result::success($result);
  4976. }
  4977. /*
  4978. * 修改公司信息
  4979. * */
  4980. public function upJobCompany(array $data): array
  4981. {
  4982. // return Result::success($data);
  4983. $user = User::where('user.id', $data['user_id'])
  4984. ->where('user.status', 1)
  4985. ->select('user.user_name', 'user.type_id')
  4986. ->first();
  4987. if (empty($user)) {
  4988. return Result::error("用户不存在", 0);
  4989. }
  4990. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4991. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  4992. $company = [
  4993. 'business_name' => $data['business_name'], // 企业名称
  4994. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4995. 'company_nature' => $data['company_nature'], // 公司性质
  4996. 'company_size' => $data['company_size'], // 公司规模
  4997. 'introduction' => $data['introduction'], // 公司简介
  4998. // 'real_name' => $data['real_name'], // 企业联系人
  4999. 'company_url' => $data['company_url'], // 企业网址
  5000. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5001. 'address' => $data['address'], // 企业详细地址
  5002. // 'email' => $data['email'], // 企业邮箱
  5003. ];
  5004. if ($user['type_id'] == 3) {
  5005. Db::beginTransaction();
  5006. try {
  5007. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5008. 'business_name' => $data['business_name'], // 企业名称
  5009. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5010. 'company_nature' => $data['company_nature'], // 公司性质
  5011. 'company_size' => $data['company_size'], // 公司规模
  5012. 'introduction' => $data['introduction'], // 公司简介
  5013. // 'real_name' => $data['real_name'], // 企业联系人
  5014. 'company_url' => $data['company_url'], // 企业网址
  5015. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5016. 'address' => $data['address'], // 企业详细地址
  5017. ]);
  5018. if (empty($result['userinfo'])) {
  5019. Db::rollBack();
  5020. return Result::error('修改企业会员信息失败!');
  5021. }
  5022. $result['user'] = User::where('id', $data['user_id'])->update([
  5023. 'email' => $data['email'], // 企业邮箱
  5024. ]);
  5025. if (empty($result['user'])) {
  5026. Db::rollBack();
  5027. return Result::error('修改个人中心信息失败!');
  5028. }
  5029. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5030. if (!empty($job_company)) {
  5031. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5032. if (empty($result['job_company'])) {
  5033. Db::rollBack();
  5034. return Result::error('修改企业会员信息失败!');
  5035. }
  5036. }
  5037. Db::commit();
  5038. return Result::success($result);
  5039. } catch (\Exception $e) {
  5040. Db::rollBack();
  5041. return Result::error($e->getMessage(), 0);
  5042. }
  5043. } else {
  5044. return Result::error("用户类型错误", 0);
  5045. }
  5046. }
  5047. /*
  5048. * 获取省-市
  5049. * */
  5050. public function getJobRecruitingArea(array $data): array
  5051. {
  5052. if (isset($data['pid']) && $data['pid'] != null) {
  5053. $result = District::where('pid', $data['pid'])->get()->all();
  5054. } else {
  5055. $result = District::where('level', 1)->get()->all();
  5056. }
  5057. if (empty($result)) {
  5058. return Result::error("暂无此省市", 0);
  5059. }
  5060. return Result::success($result);
  5061. }
  5062. /*
  5063. * 获取行业分类
  5064. * */
  5065. public function getIndustry(array $data): array
  5066. {
  5067. $result = JobIndustry::get()->all();
  5068. if (empty($result)) {
  5069. return Result::error("暂无行业分类", 0);
  5070. }
  5071. return Result::success($result);
  5072. }
  5073. /*
  5074. * 获取职位
  5075. * */
  5076. public function getPositionList(array $data): array
  5077. {
  5078. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5079. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5080. } else {
  5081. $result = JobPosition::where('zwpid', 0)->get()->all();
  5082. }
  5083. if (empty($result)) {
  5084. return Result::error("暂无此职位", 0);
  5085. }
  5086. return Result::success($result);
  5087. }
  5088. /*
  5089. * 获取工作性质-菜单
  5090. * */
  5091. public function getJobNature(array $data): array
  5092. {
  5093. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5094. if (empty($result)) {
  5095. return Result::error("暂无工作性质", 0);
  5096. }
  5097. return Result::success($result);
  5098. }
  5099. /*
  5100. * 获取工作经验-菜单
  5101. * */
  5102. public function getExperience(array $data): array
  5103. {
  5104. $result = JobEnum::where('egroup', 'years')->get()->all();
  5105. if (empty($result)) {
  5106. return Result::error("暂无工作经验", 0);
  5107. }
  5108. return Result::success($result);
  5109. }
  5110. /*
  5111. * 获取学历-菜单
  5112. * */
  5113. public function getEducation(array $data): array
  5114. {
  5115. $result = JobEnum::where('egroup', 'education')->get()->all();
  5116. if (empty($result)) {
  5117. return Result::error("暂无学历", 0);
  5118. }
  5119. return Result::success($result);
  5120. }
  5121. /*
  5122. * 获取薪资-菜单
  5123. * */
  5124. public function getSalary(array $data): array
  5125. {
  5126. $result = JobEnum::where('egroup', 'income')->get()->all();
  5127. if (empty($result)) {
  5128. return Result::error("暂无薪资", 0);
  5129. }
  5130. return Result::success($result);
  5131. }
  5132. /*
  5133. * 获取语言-菜单
  5134. * */
  5135. public function getLanguage(array $data): array
  5136. {
  5137. $result = JobEnum::where('egroup', 'language')->get()->all();
  5138. if (empty($result)) {
  5139. return Result::error("暂无语言", 0);
  5140. }
  5141. return Result::success($result);
  5142. }
  5143. /*
  5144. * 获取掌握程度-菜单
  5145. * */
  5146. public function getLevel(array $data): array
  5147. {
  5148. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5149. if (empty($result)) {
  5150. return Result::error("暂无工作性质", 0);
  5151. }
  5152. return Result::success($result);
  5153. }
  5154. // 公司信息
  5155. /*
  5156. * 获取公司性质-菜单
  5157. * */
  5158. public function getCompanyNature(array $data): array
  5159. {
  5160. $result = JobNature::get()->all();
  5161. if (empty($result)) {
  5162. return Result::error("暂无公司性质", 0);
  5163. }
  5164. return Result::success($result);
  5165. }
  5166. /*
  5167. * 获取公司规模-菜单
  5168. * */
  5169. public function getCompanySize(array $data): array
  5170. {
  5171. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5172. if (empty($result)) {
  5173. return Result::error("暂无公司规模", 0);
  5174. }
  5175. return Result::success($result);
  5176. }
  5177. /*
  5178. * 招聘信息审核
  5179. * */
  5180. public function checkJobRecruiting(array $data): array
  5181. {
  5182. $user = User::where('id', $data['user_id'])->first();
  5183. if (empty($user)) {
  5184. return Result::error("用户不存在", 0);
  5185. }
  5186. $job = JobRecruiting::where('id', $data['id'])->first();
  5187. if (empty($job)) {
  5188. return Result::error("招聘信息不存在", 0);
  5189. }
  5190. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5191. if ($user['type_id'] != 10000) {
  5192. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5193. }
  5194. // 驳回原因
  5195. if ($data['status'] == 2) {
  5196. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5197. }
  5198. $data['action_id'] = $data['user_id'];
  5199. unset($data['user_id']);
  5200. if ($data['status'] == 1) {
  5201. $this->sendMessage([
  5202. 'talk_type' => 501,
  5203. 'title' => $job['title'],
  5204. 'content' => '审核通过',
  5205. 'messageType' => 10,
  5206. 'user_id' => $job['user_id'],
  5207. ]);
  5208. }
  5209. if ($data['status'] == 2) {
  5210. $this->sendMessage([
  5211. 'talk_type' => 501,
  5212. 'title' => $job['title'],
  5213. 'content' => '审核拒绝',
  5214. 'messageType' => 10,
  5215. 'user_id' => $job['user_id'],
  5216. ]);
  5217. }
  5218. if ($data['status'] == 0) {
  5219. $this->sendMessage([
  5220. 'talk_type' => 500,
  5221. 'title' => $job['title'],
  5222. 'content' => '提交了审核',
  5223. 'messageType' => 10,
  5224. ]);
  5225. }
  5226. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5227. if (empty($result)) {
  5228. return Result::error("审核失败", 0);
  5229. }
  5230. return Result::success($result);
  5231. }
  5232. public function myApplyList(array $data): array
  5233. {
  5234. var_dump($data, '------参数');
  5235. $user = User::where('id', $data['user_id'])->first();
  5236. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5237. return Result::error("用户不存在", 0);
  5238. }
  5239. // 1:个人会员 职场机会
  5240. if ($user['type_id'] == 1) {
  5241. $where['user_id'] = $user['id'];
  5242. }
  5243. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5244. $query->where('user_id', $user['id']);
  5245. })
  5246. ->pluck('recruit_id');
  5247. $where = [];
  5248. if (isset($data['salary']) && $data['salary'] != null) {
  5249. $where['job_recruiting.salary'] = $data['salary'];
  5250. }
  5251. if (isset($data['experience']) && $data['experience'] != null) {
  5252. $where['job_recruiting.experience'] = $data['experience'];
  5253. }
  5254. if (isset($data['business_name']) && $data['business_name'] != null) {
  5255. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5256. }
  5257. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5258. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5259. ->where($where);
  5260. // ->count();
  5261. $count = $query->count();
  5262. $query = clone $query;
  5263. $job = $query
  5264. ->leftJoin('job_enum as income_enum', function ($join) {
  5265. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5266. ->where('income_enum.egroup', 'income');
  5267. })
  5268. ->leftJoin('job_enum as years_enum', function ($join) {
  5269. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5270. ->where('years_enum.egroup', 'years');
  5271. })
  5272. // ->where($where)
  5273. ->orderBy('job_recruiting.updated_at', 'desc')
  5274. ->select(
  5275. 'job_recruiting.id',
  5276. 'job_recruiting.title',
  5277. 'job_company.business_name',
  5278. 'income_enum.evalue as salary_evalue',
  5279. 'income_enum.ename as salary_ename',
  5280. 'years_enum.evalue as experience_evalue',
  5281. 'years_enum.ename as experience_ename',
  5282. 'job_recruiting.updated_at'
  5283. )
  5284. ->offset(($data['page'] - 1) * $data['pageSize'])
  5285. ->limit($data['pageSize'])
  5286. ->get()
  5287. ->all();
  5288. if (empty($job)) {
  5289. return Result::error("暂无招聘信息", 0);
  5290. }
  5291. $result = [
  5292. 'row' => $job,
  5293. 'count' => $count,
  5294. ];
  5295. return Result::success($result);
  5296. }
  5297. /*
  5298. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5299. * */
  5300. public function getRecruitingList(array $data): array
  5301. {
  5302. $user = User::where('id', $data['user_id'])->first();
  5303. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5304. return Result::error("用户不存在", 0);
  5305. }
  5306. // 1:个人会员 职场机会
  5307. if ($user['type_id'] == 1) {
  5308. $where['user_id'] = $user['id'];
  5309. }
  5310. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5311. $query->where('receiver_id', $user['id']);
  5312. })
  5313. ->pluck('recruit_id');
  5314. // return Result::success($recruitingId);
  5315. $where = [];
  5316. if (isset($data['salary']) && $data['salary'] != null) {
  5317. $where['job_recruiting.salary'] = $data['salary'];
  5318. }
  5319. if (isset($data['experience']) && $data['experience'] != null) {
  5320. $where['job_recruiting.experience'] = $data['experience'];
  5321. }
  5322. if (isset($data['business_name']) && $data['business_name'] != null) {
  5323. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5324. }
  5325. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5326. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5327. ->where($where);
  5328. // ->count();
  5329. $count = $query->count();
  5330. $query = clone $query;
  5331. $job = $query
  5332. ->leftJoin('job_enum as income_enum', function ($join) {
  5333. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5334. ->where('income_enum.egroup', 'income');
  5335. })
  5336. ->leftJoin('job_enum as years_enum', function ($join) {
  5337. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5338. ->where('years_enum.egroup', 'years');
  5339. })
  5340. // ->where($where)
  5341. ->orderBy('job_recruiting.updated_at', 'desc')
  5342. ->select(
  5343. 'job_recruiting.id',
  5344. 'job_recruiting.title',
  5345. 'job_company.business_name',
  5346. 'income_enum.evalue as salary_evalue',
  5347. 'income_enum.ename as salary_ename',
  5348. 'years_enum.evalue as experience_evalue',
  5349. 'years_enum.ename as experience_ename',
  5350. 'job_recruiting.updated_at'
  5351. )
  5352. ->offset(($data['page'] - 1) * $data['pageSize'])
  5353. ->limit($data['pageSize'])
  5354. ->get()
  5355. ->all();
  5356. if (empty($job)) {
  5357. return Result::error("暂无招聘信息", 0);
  5358. }
  5359. $result = [
  5360. 'row' => $job,
  5361. 'count' => $count,
  5362. ];
  5363. return Result::success($result);
  5364. }
  5365. /*
  5366. * 获取企业会员-招聘信息列表
  5367. * */
  5368. public function getRecruitingInfo(array $data): array
  5369. {
  5370. $user = User::where('id', $data['user_id'])->first();
  5371. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5372. return Result::error("用户不存在", 0);
  5373. }
  5374. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5375. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5376. ->select(
  5377. 'job_recruiting.*',
  5378. 'job_company.business_name',
  5379. 'job_company.company_hy_id',
  5380. 'job_company.company_size',
  5381. 'job_company.company_nature',
  5382. 'job_company.introduction',
  5383. 'job_company.real_name',
  5384. 'job_company.mobile',
  5385. 'job_company.company_url',
  5386. 'job_company.address_arr_id',
  5387. 'job_company.address',
  5388. 'job_company.email'
  5389. )
  5390. ->get();
  5391. if (empty($recruiting)) {
  5392. return Result::error("暂无招聘信息", 0);
  5393. }
  5394. return Result::success($recruiting);
  5395. }
  5396. /*
  5397. * 获取企业会员-我的沟通
  5398. * */
  5399. public function getJobResumeList(array $data): array
  5400. {
  5401. $user = User::where('id', $data['user_id'])->first();
  5402. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5403. return Result::error("用户不存在", 0);
  5404. }
  5405. $where = [];
  5406. if (isset($data['salary']) && $data['salary'] != null) {
  5407. $where['job_hunting.salary'] = $data['salary'];
  5408. }
  5409. if (isset($data['user_name']) && $data['user_name'] != null) {
  5410. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5411. }
  5412. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5413. $query->where('job_resume.user_id', $user['id']);
  5414. })
  5415. ->when(!empty($where), function ($query) use ($where) {
  5416. $query->where($where);
  5417. })
  5418. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5419. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5420. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5421. ->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');
  5422. $count = $job->count();
  5423. if ($count == 0) {
  5424. return Result::error("暂无沟通记录", 0);
  5425. }
  5426. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5427. ->offset(($data['page'] - 1) * $data['pageSize'])
  5428. ->limit($data['pageSize'])
  5429. ->get();
  5430. if (empty($jobs)) {
  5431. return Result::error("暂无沟通记录", 0);
  5432. }
  5433. $result['row'] = $this->processJob($jobs, '');
  5434. $result['count'] = $count;
  5435. return Result::success($result);
  5436. }
  5437. // 20250306 招聘
  5438. //20250422 书刊音像
  5439. public function addBook(array $data): array
  5440. {
  5441. $user_id = $data['user_id'] ?? 0;
  5442. $type_id = $data['type_id'] ?? 0;
  5443. // $website_id = $data['website_id'] ?? 0;
  5444. // unset($data['user_id']);
  5445. unset($data['type_id']);
  5446. // unset($data['website_id']);
  5447. //处理数组
  5448. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5449. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5450. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5451. if ($data['img_url'] == '') {
  5452. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5453. preg_match_all($reg, $data['detail'], $matches);
  5454. if (isset($matches[1][0])) {
  5455. //截取varchar240
  5456. $data['img_url'] = substr($matches[1][0], 0, 240);
  5457. }
  5458. }
  5459. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5460. //提取标题+内容中的关键词
  5461. $data['keyword'] = $data['title'];
  5462. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5463. Jieba::init(); // 初始化 jieba-php
  5464. Finalseg::init();
  5465. $segList = Jieba::cut($data['keyword']);
  5466. $segList1 = array_slice($segList, 0, 8);
  5467. $data['keyword'] = implode(',', $segList1);
  5468. }
  5469. if ($data['description'] == '') {
  5470. //提取内容中的描述
  5471. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5472. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5473. }
  5474. var_dump($data, '--');
  5475. if ($data['status'] == 1) {
  5476. $this->sendMessage([
  5477. 'talk_type' => 400,
  5478. 'title' => $data['title'],
  5479. 'content' => '提交了审核',
  5480. 'messageType' => 7,
  5481. ]);
  5482. }
  5483. $result = Book::insertGetId($data);
  5484. if (empty($result)) {
  5485. return Result::error("添加失败", 0);
  5486. }
  5487. return Result::success($result);
  5488. }
  5489. public function getBookList(array $data): array
  5490. {
  5491. $where = [];
  5492. if (!empty($data["title"])) {
  5493. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5494. }
  5495. if (!empty($data['website_name'])) {
  5496. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5497. }
  5498. if (!empty($data['status'])) {
  5499. $where[] = ['book.status', '=', $data['status']];
  5500. }
  5501. $user_id = $data['user_id'];
  5502. $type_id = $data['type_id'];
  5503. // $type_id = 4;
  5504. var_dump($type_id, '------1--------');
  5505. if ($type_id != 10000) {
  5506. $where[] = ['book.user_id', '=', $user_id];
  5507. }
  5508. var_dump(!empty($data['status1']), '=-===1');
  5509. $result = Book::where($where)
  5510. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5511. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5512. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5513. ->when(isset($data['status1']), function ($query) use ($data) {
  5514. $query->whereIn('book.status', [1, 3]);
  5515. })
  5516. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5517. ->orderBy("updated_at", "desc")
  5518. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5519. if (empty($result)) {
  5520. return Result::error("暂无数据", 0);
  5521. }
  5522. // 取出数据
  5523. $rows = $result->items();
  5524. $count = $result->total();
  5525. $responseData = [
  5526. 'rows' => $rows,
  5527. 'count' => $count,
  5528. ];
  5529. return Result::success($responseData);
  5530. }
  5531. public function deleteBook(array $data): array
  5532. {
  5533. $result = Book::where('id', $data['id'])->delete();
  5534. if (empty($result)) {
  5535. return Result::error("删除失败", 0);
  5536. }
  5537. return Result::success($result);
  5538. }
  5539. public function updateBook(array $data): array
  5540. {
  5541. // $user_id = $data['user_id'] ?? 0;
  5542. $type_id = $data['type_id'] ?? 0;
  5543. // $website_id = $data['website_id'] ?? 0;
  5544. unset($data['user_id']);
  5545. unset($data['type_id']);
  5546. // unset($data['website_id']);
  5547. //处理数组
  5548. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5549. if ($data['img_url'] == '') {
  5550. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5551. preg_match_all($reg, $data['detail'], $matches);
  5552. if (isset($matches[1][0])) {
  5553. //截取varchar240
  5554. $data['img_url'] = substr($matches[1][0], 0, 240);
  5555. }
  5556. }
  5557. if ($data['keyword'] == '') {
  5558. //提取标题+内容中的关键词
  5559. $data['keyword'] = $data['title'];
  5560. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5561. Jieba::init(); // 初始化 jieba-php
  5562. Finalseg::init();
  5563. $segList = Jieba::cut($data['keyword']);
  5564. $segList1 = array_slice($segList, 0, 8);
  5565. $data['keyword'] = implode(',', $segList1);
  5566. }
  5567. if ($data['description'] == '') {
  5568. //提取内容中的描述
  5569. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5570. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5571. }
  5572. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5573. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5574. if ($data['status'] == 1) {
  5575. $this->sendMessage([
  5576. 'talk_type' => 400,
  5577. 'title' => $data['title'],
  5578. 'content' => '提交了审核',
  5579. 'messageType' => 7,
  5580. ]);
  5581. }
  5582. $result = Book::where("id", $data["id"])->update($data);
  5583. if (empty($result)) {
  5584. return Result::error("更新失败", 0);
  5585. }
  5586. return Result::success($result);
  5587. }
  5588. public function getBookInfo(array $data): array
  5589. {
  5590. $result = Book::where("id", $data["id"])->first();
  5591. if (empty($result)) {
  5592. return Result::error("获取失败", 0);
  5593. }
  5594. return Result::success($result);
  5595. }
  5596. public function updateBookStatus(array $data): array
  5597. {
  5598. //审核
  5599. unset($data['user_id']);
  5600. $bookInfo = Book::where("id", $data["id"])->first();
  5601. var_dump($bookInfo, '----');
  5602. if ($data['status'] == 2) {
  5603. $this->sendMessage([
  5604. 'talk_type' => 401,
  5605. 'title' => $bookInfo['title'],
  5606. 'content' => '审核通过',
  5607. 'messageType' => 7,
  5608. 'user_id' => $bookInfo['user_id'],
  5609. ]);
  5610. }
  5611. if ($data['status'] == 3) {
  5612. $this->sendMessage([
  5613. 'talk_type' => 401,
  5614. 'title' => $bookInfo['title'],
  5615. 'content' => '审核拒绝',
  5616. 'messageType' => 7,
  5617. 'user_id' => $bookInfo['user_id'],
  5618. ]);
  5619. }
  5620. if ($data['status'] == 1) {
  5621. $this->sendMessage([
  5622. 'talk_type' => 400,
  5623. 'title' => $bookInfo['title'],
  5624. 'content' => '提交了审核',
  5625. 'messageType' => 7,
  5626. // 'user_id'=>$bookInfo['user_id'],
  5627. ]);
  5628. }
  5629. $result = Book::where("id", $data["id"])->update($data);
  5630. if (empty($result)) {
  5631. return Result::error("更新失败", 0);
  5632. }
  5633. return Result::success($result);
  5634. }
  5635. //20250422 书刊音像
  5636. /**
  5637. * 贴身宝贝
  5638. * @param array $data
  5639. * @return array
  5640. */
  5641. public function getWebsiteTsbb(array $data): array
  5642. {
  5643. $month = $data['month'] ?? date('m');
  5644. $day = $data['day'] ?? date('d');
  5645. // 使用缓存键
  5646. $cacheKey = "tsbb_data_{$month}_{$day}";
  5647. // 尝试从缓存获取数据
  5648. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5649. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5650. if ($cachedData = $cache->get($cacheKey)) {
  5651. return Result::success(unserialize($cachedData));
  5652. }
  5653. //查询老黄历
  5654. try {
  5655. $date = date('Y-m-d');
  5656. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5657. // 使用 curl 替代 file_get_contents
  5658. $ch = curl_init();
  5659. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5660. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5661. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5662. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5663. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5664. 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');
  5665. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5666. 'Accept: application/json',
  5667. 'Content-Type: application/json',
  5668. 'Referer: https://www.36jxs.com/'
  5669. ]);
  5670. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5671. curl_setopt($ch, CURLOPT_ENCODING, '');
  5672. $almanacResponse = curl_exec($ch);
  5673. var_dump("====:", $almanacResponse);
  5674. if (curl_errno($ch)) {
  5675. var_dump('Curl error:', curl_error($ch));
  5676. throw new \Exception('Curl error: ' . curl_error($ch));
  5677. }
  5678. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5679. curl_close($ch);
  5680. if ($almanacResponse === false) {
  5681. throw new \Exception('Failed to fetch almanac data');
  5682. }
  5683. $almanacData = json_decode($almanacResponse, true);
  5684. if (json_last_error() !== JSON_ERROR_NONE) {
  5685. throw new \Exception('Failed to parse almanac data');
  5686. }
  5687. $almanacInfo = $almanacData['data'] ?? [];
  5688. } catch (\Exception $e) {
  5689. var_dump('Exception:', $e->getMessage());
  5690. $almanacInfo = [];
  5691. }
  5692. // 获取历史上的今天数据
  5693. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5694. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5695. ->orderBy('year', 'asc')
  5696. ->select("title", "id", "year", DB::raw('1 as type'))
  5697. ->limit(16)
  5698. ->get();
  5699. // 获取节日数据 - 从今天开始获取未来4条
  5700. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5701. ->orderBy('showtime', 'asc')
  5702. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5703. ->limit(16)
  5704. ->get();
  5705. //说文解字
  5706. $chartacterList = Character::orderBy('updated_at', 'desc')
  5707. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5708. ->limit(6)
  5709. ->get();
  5710. //谜语沙龙
  5711. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5712. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5713. ->limit(4)
  5714. ->get();
  5715. //成语欣赏
  5716. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5717. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5718. ->limit(32)
  5719. ->get();
  5720. //名联赏析
  5721. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5722. ->select("id", "first", "second", DB::raw('6 as type'))
  5723. ->limit(6)
  5724. ->get();
  5725. // 获取分类文章数据
  5726. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5727. ->pluck('category_id')
  5728. ->toArray();
  5729. $articlesList = [];
  5730. foreach ($categoryIds as $catid) {
  5731. // 先查有图片的
  5732. $withImg = DB::table('article')
  5733. ->where('status', 1)
  5734. ->where('catid', $catid)
  5735. ->whereNotNull('imgurl')
  5736. ->where('imgurl', '!=', '')
  5737. ->orderBy('updated_at', 'desc')
  5738. ->limit(6)
  5739. ->get();
  5740. $count = $withImg->count();
  5741. if ($count < 6) {
  5742. // 不足6条再查无图片的补足
  5743. $withoutImg = DB::table('article')
  5744. ->where('status', 1)
  5745. ->where('catid', $catid)
  5746. ->where(function ($q) {
  5747. $q->whereNull('imgurl')->orWhere('imgurl', '');
  5748. })
  5749. ->orderBy('updated_at', 'desc')
  5750. ->limit(6 - $count)
  5751. ->get();
  5752. $articles = $withImg->concat($withoutImg);
  5753. } else {
  5754. $articles = $withImg;
  5755. }
  5756. // 组装
  5757. $category = \App\Model\Category::find($catid);
  5758. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  5759. $articlesList[] = [
  5760. 'category_name' => $category ? $category->name : '',
  5761. 'catid' => $catid,
  5762. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  5763. 'type' => 100,
  5764. 'list' => $articles->map(function ($item) {
  5765. return [
  5766. 'id' => $item->id,
  5767. 'title' => $item->title,
  5768. 'imgurl' => $item->imgurl,
  5769. 'created_at' => $item->created_at
  5770. ];
  5771. })->values()
  5772. ];
  5773. }
  5774. $result = [
  5775. 'almanac' => $almanacInfo,
  5776. 'historyTodayList' => [
  5777. 'category_name' => '历史上的今天',
  5778. 'list' => $historyTodayList,
  5779. 'type' => 1
  5780. ],
  5781. 'festivalList' => [
  5782. 'category_name' => '节日预告',
  5783. 'list' => $festivalList,
  5784. 'type' => 2
  5785. ],
  5786. 'chartacterList' => [
  5787. 'category_name' => '说文解字',
  5788. 'list' => $chartacterList,
  5789. 'type' => 3
  5790. ],
  5791. 'coupletList' => [
  5792. 'category_name' => '名联赏析',
  5793. 'list' => $coupletList,
  5794. 'type' => 6
  5795. ],
  5796. 'riddletList' => [
  5797. 'category_name' => '谜语沙龙',
  5798. 'list' => $riddletList,
  5799. 'type' => 4
  5800. ],
  5801. 'idiomList' => [
  5802. 'category_name' => '成语欣赏',
  5803. 'list' => $idiomList,
  5804. 'type' => 5
  5805. ],
  5806. 'articlesList' => $articlesList
  5807. ];
  5808. // 缓存结果,设置1小时过期
  5809. $cache->set($cacheKey, serialize($result), 3600);
  5810. return Result::success($result);
  5811. }
  5812. /**
  5813. * 获取资讯列表
  5814. */
  5815. public function getWebsiteTsbbList(array $data): array
  5816. {
  5817. $page = $data['page'] ?? 1;
  5818. $pageSize = $data['pageSize'] ?? 10;
  5819. // 如果没有传入月份和日期,则使用今天的日期
  5820. $month = $data['month'] ?? date('m');
  5821. $day = $data['day'] ?? date('d');
  5822. $total = 0;
  5823. $result = [];
  5824. $data['type'] = intval($data['type']);
  5825. var_dump("接收参数:", $data);
  5826. switch ($data['type']) {
  5827. case 1:
  5828. $query = HistoryToday::where(function ($q) use ($month, $day) {
  5829. // 当前月份之后的数据
  5830. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  5831. // 或者当前月份且日期大于等于当前日期的数据
  5832. ->orWhere(function ($q) use ($month, $day) {
  5833. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5834. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  5835. });
  5836. })
  5837. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  5838. $total = $query->count();
  5839. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  5840. ->offset(($page - 1) * $pageSize)
  5841. ->limit($pageSize)
  5842. ->get();
  5843. break;
  5844. case 2:
  5845. $query = Festival::where(function ($q) use ($month, $day) {
  5846. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  5847. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  5848. ->orWhere(function ($q) use ($month, $day) {
  5849. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  5850. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  5851. });
  5852. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  5853. $total = $query->count();
  5854. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  5855. ->offset(($page - 1) * $pageSize)
  5856. ->limit($pageSize)
  5857. ->get();
  5858. break;
  5859. case 3:
  5860. $query = Character::orderBy("updated_at", "desc");
  5861. $total = $query->count();
  5862. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  5863. ->offset(($page - 1) * $pageSize)
  5864. ->limit($pageSize)
  5865. ->get();
  5866. break;
  5867. case 4:
  5868. $query = Riddle::orderBy("updated_at", "desc");
  5869. $total = $query->count();
  5870. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  5871. ->offset(($page - 1) * $pageSize)
  5872. ->limit($pageSize)
  5873. ->get();
  5874. break;
  5875. case 5:
  5876. $query = Idiom::orderBy("updated_at", "desc");
  5877. $total = $query->count();
  5878. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  5879. ->offset(($page - 1) * $pageSize)
  5880. ->limit($pageSize)
  5881. ->get();
  5882. break;
  5883. case 6:
  5884. $query = Couplet::orderBy("updated_at", "desc");
  5885. $total = $query->count();
  5886. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  5887. ->offset(($page - 1) * $pageSize)
  5888. ->limit($pageSize)
  5889. ->get();
  5890. break;
  5891. default:
  5892. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  5893. $total = $query->count();
  5894. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  5895. ->offset(($page - 1) * $pageSize)
  5896. ->limit($pageSize)
  5897. ->get();
  5898. }
  5899. return Result::success([
  5900. 'list' => $result,
  5901. 'total' => $total,
  5902. 'page' => (int)$page,
  5903. 'pageSize' => (int)$pageSize,
  5904. 'month' => $month,
  5905. 'day' => $day
  5906. ]);
  5907. }
  5908. /**
  5909. * 1:历史上的今天
  5910. * 2:节日
  5911. * 3:文章
  5912. *
  5913. * 资讯详情信息
  5914. */
  5915. public function getWebsiteTsbbDetail(array $data): array
  5916. {
  5917. $data['type'] = intval($data['type']);
  5918. switch ($data['type']) {
  5919. case 1:
  5920. $result = HistoryToday::where("id", $data['id'])->first();
  5921. break;
  5922. case 2:
  5923. $result = Festival::where("id", $data['id'])->first();
  5924. break;
  5925. case 3:
  5926. $result = Character::where("id", $data['id'])->first();
  5927. break;
  5928. case 4:
  5929. $result = Riddle::where("id", $data['id'])->first();
  5930. break;
  5931. case 5:
  5932. $result = Idiom::where("id", $data['id'])->first();
  5933. break;
  5934. case 6:
  5935. $result = Couplet::where("id", $data['id'])->first();
  5936. break;
  5937. default:
  5938. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  5939. break;
  5940. }
  5941. return Result::success($result);
  5942. }
  5943. /**
  5944. * 农网导航首页数据
  5945. */
  5946. public function getWebsiteNwHomeList(array $data): array
  5947. {
  5948. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  5949. ->pluck('category_id')
  5950. ->toArray();
  5951. // 使用子查询优化
  5952. $articlesList = DB::table('article')
  5953. ->select([
  5954. 'article.id',
  5955. 'article.title',
  5956. 'article.imgurl',
  5957. 'article.created_at',
  5958. 'category.name as category_name',
  5959. 'category.id as category_id',
  5960. 'website_category.aLIas_pinyin as pinyin',
  5961. 'parent_wc.aLIas_pinyin as parent_pinyin',
  5962. DB::raw('100 as type')
  5963. ])
  5964. ->join('category', 'article.catid', '=', 'category.id')
  5965. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5966. ->leftJoin('website_category as parent_wc', function ($join) {
  5967. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  5968. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  5969. })
  5970. ->where('website_category.website_id', $data['website_id'])
  5971. ->where('article.status', 1)
  5972. ->whereIn('category.id', $categoryIds)
  5973. ->orderBy('article.created_at', 'desc')
  5974. ->get()
  5975. ->groupBy('category_id')
  5976. ->map(function ($group) {
  5977. // 确保第一条数据有图片
  5978. $firstWithImage = $group->first(function ($item) {
  5979. return !empty($item->imgurl);
  5980. });
  5981. if ($firstWithImage) {
  5982. // 如果有带图片的文章,将其放在第一位
  5983. $group = $group->filter(function ($item) use ($firstWithImage) {
  5984. return $item->id !== $firstWithImage->id;
  5985. })->prepend($firstWithImage);
  5986. }
  5987. return [
  5988. 'category_name' => $group->first()->category_name,
  5989. 'catid' => $group->first()->category_id,
  5990. 'pinyin' => $group->first()->pinyin,
  5991. 'parent_pinyin' => $group->first()->parent_pinyin,
  5992. 'list' => $group->take(4)->map(function ($item) {
  5993. return [
  5994. 'id' => $item->id,
  5995. 'title' => $item->title,
  5996. ];
  5997. })->values()
  5998. ];
  5999. })
  6000. ->values()
  6001. ->toArray();
  6002. return Result::success($articlesList);
  6003. }
  6004. /**
  6005. * 企业管理
  6006. * @param array $data
  6007. * @return array
  6008. */
  6009. public function getCompanyList(array $data): array
  6010. {
  6011. // return Result::success($data);
  6012. $where = [];
  6013. $user = User::where('id', $data['user_id'])->first();
  6014. if (empty($user)) {
  6015. return Result::error('用户不存在!');
  6016. }
  6017. if ($user['type_id'] != 10000) {
  6018. $where['user_id'] = $data['user_id'];
  6019. }
  6020. if (isset($data['title']) && !empty($data['title'])) {
  6021. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6022. }
  6023. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6024. array_push($where, ['website.id', $data['website_id']]);
  6025. }
  6026. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6027. if ($data['ischeck'] == 1) {
  6028. if (isset($data['status']) && $data['status'] != '') {
  6029. array_push($where, ['company.status', $data['status']]);
  6030. $query = Company::where($where);
  6031. } else {
  6032. $query = Company::whereIn('company.status', [0, 2]);
  6033. }
  6034. } else {
  6035. $query = Company::where('company.status', 1);
  6036. }
  6037. }
  6038. $result = $query->where($where)
  6039. ->leftJoin('website_category', function ($query) {
  6040. $query->on('website_category.category_id', '=', 'company.category_id')
  6041. ->on('website_category.website_id', '=', 'company.website_id');
  6042. })
  6043. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6044. ->select(
  6045. 'company.id',
  6046. 'company.title',
  6047. 'company.website_id',
  6048. 'company.category_id',
  6049. 'website.website_name',
  6050. 'website_category.alias as category_name',
  6051. 'company.status',
  6052. 'company.updated_at',
  6053. )
  6054. ->orderBy('company.updated_at', 'desc')
  6055. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6056. if ($result->isEmpty()) {
  6057. return Result::error("暂无企业", 0);
  6058. }
  6059. return Result::success($result);
  6060. }
  6061. /**
  6062. * 添加企业
  6063. * @param array $data
  6064. * @return array
  6065. */
  6066. public function addCompany(array $data): array
  6067. {
  6068. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6069. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6070. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6071. $data['cat_arr_id'] = json_encode($car_arr_id);
  6072. } else {
  6073. $data['cat_arr_id'] = '';
  6074. }
  6075. if ($data['imgurl'] == '') {
  6076. //content中提取图片第一个图,正则提取
  6077. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6078. preg_match_all($reg, $data['content'], $matches);
  6079. if (isset($matches[1][0])) {
  6080. //截取varchar240
  6081. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6082. }
  6083. }
  6084. if ($data['keyword'] == '') {
  6085. //提取标题+内容中的关键词
  6086. $data['keyword'] = $data['title'];
  6087. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6088. Jieba::init(); // 初始化 jieba-php
  6089. Finalseg::init();
  6090. $segList = Jieba::cut($data['keyword']);
  6091. $segList1 = array_slice($segList, 0, 8);
  6092. $data['keyword'] = implode(',', $segList1);
  6093. }
  6094. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6095. //提取内容中的描述
  6096. $content = $data['content'];
  6097. // 去除 <style> 和 <script> 标签及其内容
  6098. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6099. // 去除所有 HTML 标签
  6100. $content = strip_tags($content);
  6101. // 去除 HTML 实体
  6102. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6103. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6104. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6105. // 去除多余空白
  6106. $content = preg_replace('/\s+/u', '', $content);
  6107. // 截取 100 个字符
  6108. $data['introduce'] = mb_substr($content, 0, 100);
  6109. }
  6110. $user = User::where('id', $data['user_id'])->first();
  6111. if (empty($user)) {
  6112. return Result::error('用户不存在!');
  6113. }
  6114. if ($user['type_id'] == 10000) {
  6115. $data['status'] = 1;
  6116. }
  6117. if (isset($data['level']) && $data['level'] != null) {
  6118. $data['level'] = intval($data['level']);
  6119. } else {
  6120. $data['level'] = null;
  6121. }
  6122. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6123. $this->sendMessage([
  6124. 'talk_type' => 900,
  6125. 'title' => $data['title'],
  6126. 'content' => '提交了审核',
  6127. 'messageType' => 8,
  6128. ]);
  6129. }
  6130. $result = Company::insertGetId($data);
  6131. if ($result) {
  6132. return Result::success($result);
  6133. } else {
  6134. return Result::error('添加失败');
  6135. }
  6136. }
  6137. /**
  6138. * 更新企业
  6139. * @param array $data
  6140. * @return array
  6141. */
  6142. public function upCompany(array $data): array
  6143. {
  6144. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6145. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6146. $data['cat_arr_id'] = json_encode($car_arr_id);
  6147. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6148. } else {
  6149. $data['cat_arr_id'] = '';
  6150. }
  6151. if ($data['imgurl'] == '') {
  6152. //content中提取图片第一个图,正则提取
  6153. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6154. preg_match_all($reg, $data['content'], $matches);
  6155. if (isset($matches[1][0])) {
  6156. //截取varchar
  6157. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6158. }
  6159. }
  6160. if ($data['keyword'] == '') {
  6161. //提取标题+内容中的关键词
  6162. $data['keyword'] = $data['title'];
  6163. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6164. Jieba::init(); // 初始化 jieba-php
  6165. Finalseg::init();
  6166. $segList = Jieba::cut($data['keyword']);
  6167. $segList1 = array_slice($segList, 0, 8);
  6168. $data['keyword'] = implode(',', $segList1);
  6169. }
  6170. if ($data['introduce'] == '') {
  6171. //提取内容中的描述
  6172. $content = $data['content'];
  6173. // 去除 <style> 和 <script> 标签及其内容
  6174. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6175. // 去除所有 HTML 标签
  6176. $content = strip_tags($content);
  6177. // 去除 HTML 实体
  6178. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6179. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6180. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6181. // 去除多余空白
  6182. $content = preg_replace('/\s+/u', '', $content);
  6183. // 截取 100 个字符
  6184. $data['introduce'] = mb_substr($content, 0, 100);
  6185. }
  6186. if (isset($data['level']) && $data['level'] != null) {
  6187. $data['level'] = intval($data['level']);
  6188. } else {
  6189. $data['level'] = null;
  6190. }
  6191. $user = User::where('id', $data['user_id'])->first();
  6192. if (empty($user)) {
  6193. return Result::error('用户不存在!');
  6194. }
  6195. if ($user['type_id'] == 10000) {
  6196. $data['status'] = 1;
  6197. } else {
  6198. $data['status'] = 0;
  6199. }
  6200. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6201. $this->sendMessage([
  6202. 'talk_type' => 900,
  6203. 'title' => $data['title'],
  6204. 'content' => '提交了审核',
  6205. 'messageType' => 8,
  6206. ]);
  6207. }
  6208. $result = Company::where('id', $data['id'])->update($data);
  6209. if ($result) {
  6210. return Result::success($result);
  6211. } else {
  6212. return Result::error('修改失败');
  6213. }
  6214. }
  6215. /**
  6216. * 删除企业
  6217. * @param array $data
  6218. * @return array
  6219. */
  6220. public function delCompany(array $data): array
  6221. {
  6222. $result = Company::where('id', $data['id'])->delete();
  6223. if ($result) {
  6224. return Result::success($result);
  6225. } else {
  6226. return Result::error('删除失败');
  6227. }
  6228. }
  6229. /**
  6230. * 审核企业
  6231. * @param array $data
  6232. * @return array
  6233. */
  6234. public function checkCompany(array $data): array
  6235. {
  6236. $user = User::where('id', $data['user_id'])->first();
  6237. if (empty($user)) {
  6238. return Result::error('用户不存在!');
  6239. }
  6240. $company = Company::where('id', $data['id'])->first();
  6241. if (empty($company)) {
  6242. return Result::error('企业不存在!');
  6243. }
  6244. // 状态:0:未审核 1:已审核 2:已拒绝
  6245. if ($data['status'] == 2 || $data['status'] == '2') {
  6246. $this->sendMessage([
  6247. 'talk_type' => 901,
  6248. 'title' => $company['title'],
  6249. 'content' => '审核拒绝',
  6250. 'messageType' => 8,
  6251. 'user_id' => $company['user_id'],
  6252. ]);
  6253. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6254. } else {
  6255. if ($data['status'] == 1) {
  6256. $this->sendMessage([
  6257. 'talk_type' => 901,
  6258. 'title' => $company['title'],
  6259. 'content' => '审核通过',
  6260. 'messageType' => 8,
  6261. 'user_id' => $company['user_id'],
  6262. ]);
  6263. } else if ($data['status'] == 0) {
  6264. $this->sendMessage([
  6265. 'talk_type' => 900,
  6266. 'title' => $company['title'],
  6267. 'content' => '提交了审核',
  6268. 'messageType' => 8,
  6269. ]);
  6270. }
  6271. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6272. }
  6273. if (empty($result)) {
  6274. return Result::error('审核失败!');
  6275. } else {
  6276. return Result::success($result);
  6277. }
  6278. }
  6279. /**
  6280. * 获取企业信息
  6281. * @param array $data
  6282. * @return array
  6283. */
  6284. public function getCompanyInfo(array $data): array
  6285. {
  6286. $result = Company::where('id', $data['id'])->first();
  6287. $city_arr = json_decode($result['city_arr_id']);
  6288. $result['city_name'] = District::whereIn('id', $city_arr)
  6289. ->pluck('name')
  6290. ->implode('-');
  6291. if (empty($result)) {
  6292. return Result::error('企业不存在!');
  6293. } else {
  6294. return Result::success($result);
  6295. }
  6296. }
  6297. /**
  6298. * @param array $data
  6299. * @return array
  6300. */
  6301. public function getWebsiteCompany(array $data): array
  6302. {
  6303. $categorys = json_decode($data['id'], true);
  6304. $category_arr = $this->processArticlePro($data['website_id']);
  6305. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6306. $catiall = $category_arr['catiall'];
  6307. foreach ($categorys as $key => $value) {
  6308. if (array_key_exists('level', $value)) {
  6309. $parts = explode(',', $value['level']);
  6310. $level = $parts[0] ?? null;
  6311. $imgnum = $parts[1] ?? null;
  6312. $textnum = $parts[2] ?? null;
  6313. if (!empty($textnum) && $textnum > 0) {
  6314. $text_num = Company::where('level', $level)
  6315. ->where('website_id', $data['website_id'])
  6316. ->where('status', 1)
  6317. ->select(
  6318. 'company.id',
  6319. 'company.title',
  6320. 'company.description',
  6321. 'company.updated_at',
  6322. 'company.category_id',
  6323. 'company.cat_arr_id'
  6324. )
  6325. ->orderBy('updated_at', 'desc')
  6326. ->limit($textnum)
  6327. ->get()->all();
  6328. }
  6329. if (!empty($imgnum) && $imgnum > 0) {
  6330. $img_num = Company::where('level', $level)
  6331. ->where('website_id', $data['website_id'])
  6332. ->where('status', 1)
  6333. ->where('imgurl', '!=', '')
  6334. ->whereNotNull('imgurl')
  6335. ->select(
  6336. 'company.id',
  6337. 'company.title',
  6338. 'company.description',
  6339. 'company.updated_at',
  6340. 'company.imgurl as imgs',
  6341. 'company.category_id',
  6342. 'company.cat_arr_id'
  6343. )
  6344. ->orderBy('updated_at', 'desc')
  6345. ->limit($imgnum)
  6346. ->get()->all();
  6347. }
  6348. }
  6349. if (array_key_exists('id', $value)) {
  6350. $parts = explode(',', $value['id']);
  6351. $category_id = $parts[0] ?? null;
  6352. $imgnum = $parts[1] ?? null;
  6353. $textnum = $parts[2] ?? null;
  6354. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6355. if (!empty($textnum) && $textnum > 0) {
  6356. $text_num = Company::whereIn('category_id', $category_arr)
  6357. ->where('website_id', $data['website_id'])
  6358. ->where('status', 1)
  6359. ->select(
  6360. 'company.id',
  6361. 'company.title',
  6362. 'company.description',
  6363. 'company.updated_at',
  6364. 'company.category_id',
  6365. 'company.cat_arr_id'
  6366. )
  6367. ->orderBy('updated_at', 'desc')
  6368. ->limit($textnum)
  6369. ->get()->all();
  6370. }
  6371. if (!empty($imgnum) && $imgnum > 0) {
  6372. $img_num = Company::whereIn('category_id', $category_arr)
  6373. ->where('website_id', $data['website_id'])
  6374. ->where('status', 1)
  6375. ->where('imgurl', '!=', '')
  6376. ->whereNotNull('imgurl')
  6377. ->select(
  6378. 'company.id',
  6379. 'company.title',
  6380. 'company.description',
  6381. 'company.updated_at',
  6382. 'company.imgurl as imgs',
  6383. 'company.category_id',
  6384. 'company.cat_arr_id'
  6385. )
  6386. ->orderBy('updated_at', 'desc')
  6387. ->limit($imgnum)
  6388. ->get()->all();
  6389. }
  6390. }
  6391. if (!empty($text_num)) {
  6392. foreach ($text_num as $k => $v) {
  6393. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6394. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6395. }
  6396. }
  6397. if (!empty($img_num)) {
  6398. foreach ($img_num as $k => $v) {
  6399. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6400. $imgurl = json_decode($v['imgs'], true);
  6401. if (!empty($imgurl)) {
  6402. $img_num[$k]->imgurl = $imgurl[0];
  6403. }
  6404. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6405. }
  6406. }
  6407. $company[$key]['img_num'] = $img_num ?? [];
  6408. $company[$key]['text_num'] = $text_num ?? [];
  6409. }
  6410. if (empty($company)) {
  6411. return Result::error("暂无相关企业信息", 0);
  6412. }
  6413. return Result::success($company);
  6414. }
  6415. /**
  6416. * @param array $data
  6417. * @return array
  6418. */
  6419. public function getWebsiteCompanyList(array $data): array
  6420. {
  6421. $where['website_id'] = $data['website_id'];
  6422. $where['status'] = 1;
  6423. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6424. $where['category_id'] = $data['category_id'];
  6425. }
  6426. if (isset($data['keyword']) && !empty($data['keyword'])) {
  6427. array_push($where, ['title', 'like', '%' . $data['keyword'] . '%']);
  6428. }
  6429. $query = Company::where($where);
  6430. $company = $this->processArticle(
  6431. $query->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6432. ->orderBy('updated_at', 'desc')
  6433. ->offset(($data['page'] - 1) * $data['pageSize'])
  6434. ->limit($data['pageSize'])
  6435. ->get(),
  6436. $data
  6437. );
  6438. if (empty($company)) {
  6439. return Result::error("暂无相关公司信息", 0);
  6440. }
  6441. $result = [
  6442. 'count' => $query->clone()->count(),
  6443. 'data' => $company,
  6444. ];
  6445. return Result::success($result);
  6446. }
  6447. /**
  6448. * 获取项目列表
  6449. * @param array $data
  6450. * @return array
  6451. */
  6452. public function getProjectList(array $data): array
  6453. {
  6454. $where = [];
  6455. $user = User::where('id', $data['user_id'])->first();
  6456. if (empty($user)) {
  6457. return Result::error('用户不存在!');
  6458. }
  6459. if ($user->type_id != 10000) {
  6460. array_push($where, ['project.user_id', $data['user_id']]);
  6461. }
  6462. $query = Project::query();
  6463. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6464. array_push($where, ['project.website_id', $data['website_id']]);
  6465. }
  6466. if (isset($data['title']) && !empty($data['title'])) {
  6467. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6468. }
  6469. if ($data['status'] != 3) {
  6470. array_push($where, ['project.status', $data['status']]);
  6471. }
  6472. $query = Project::where($where)
  6473. ->when($data['status'] == 3, function ($query) {
  6474. $query->whereIn('project.status', [0, 2]);
  6475. });
  6476. $count = $query->clone()
  6477. ->count();
  6478. $rows = $query->clone()
  6479. ->leftJoin('website', 'project.website_id', 'website.id')
  6480. ->leftJoin('website_category', function ($join) {
  6481. $join->on('project.website_id', '=', 'website_category.website_id')
  6482. ->on('project.category_id', '=', 'website_category.category_id');
  6483. })
  6484. ->select(
  6485. 'project.id',
  6486. 'project.title',
  6487. 'project.updated_at',
  6488. 'project.status',
  6489. 'website.website_name',
  6490. 'website_category.alias as category_name'
  6491. )
  6492. ->orderBy('project.updated_at', 'desc')
  6493. ->offset(($data['page'] - 1) * $data['pageSize'])
  6494. ->limit($data['pageSize'])
  6495. ->get();
  6496. if ($rows->isEmpty()) {
  6497. return Result::error("暂无相关项目信息", 0);
  6498. }
  6499. $result = [
  6500. 'count' => $count,
  6501. 'rows' => $rows,
  6502. ];
  6503. return Result::success($result);
  6504. }
  6505. /**
  6506. * 添加项目
  6507. * @param array $data
  6508. * @return array
  6509. */
  6510. public function addProject(array $data): array
  6511. {
  6512. $user = User::where('id', $data['user_id'])->first();
  6513. if (empty($user)) {
  6514. return Result::error("暂无相关用户信息", 0);
  6515. }
  6516. if ($user->type_id == 10000) {
  6517. $data['status'] = 1;
  6518. } else {
  6519. $data['status'] = 0;
  6520. }
  6521. if ($data['keyword'] == '') {
  6522. //提取标题+内容中的关键词
  6523. $data['keyword'] = $data['title'];
  6524. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6525. Jieba::init(); // 初始化 jieba-php
  6526. Finalseg::init();
  6527. $segList = Jieba::cut($data['keyword']);
  6528. $segList1 = array_slice($segList, 0, 8);
  6529. $data['keyword'] = implode(',', $segList1);
  6530. }
  6531. if ($data['description'] == '') {
  6532. //提取内容中的描述
  6533. // var_dump(11111);
  6534. //提取内容中的描述
  6535. $content = $data['introduce'];
  6536. // 去除 <style> 和 <script> 标签及其内容
  6537. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6538. // 去除所有 HTML 标签
  6539. $content = strip_tags($content);
  6540. // 去除 HTML 实体
  6541. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6542. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6543. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6544. // 去除多余空白
  6545. $content = preg_replace('/\s+/u', '', $content);
  6546. // 截取 100 个字符
  6547. $data['description'] = mb_substr($content, 0, 100);
  6548. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6549. }
  6550. if ($data['status'] == 0) {
  6551. $this->sendMessage([
  6552. 'talk_type' => 1000,
  6553. 'title' => $data['title'],
  6554. 'content' => '提交了审核',
  6555. 'messageType' => 9,
  6556. ]);
  6557. }
  6558. $project = Project::insertGetId($data);
  6559. if (empty($project)) {
  6560. return Result::error("暂无相关项目信息", 0);
  6561. }
  6562. return Result::success($project);
  6563. }
  6564. /**
  6565. * 更新项目
  6566. * @param array $data
  6567. * @return array
  6568. */
  6569. public function upProject(array $data): array
  6570. {
  6571. $project = Project::where('id', $data['id'])->first();
  6572. if (empty($project)) {
  6573. return Result::error("暂无相关项目信息", 0);
  6574. }
  6575. $id = $data['id'];
  6576. unset($data['id']);
  6577. $user = User::where('id', $data['user_id'])->first();
  6578. if (empty($user)) {
  6579. return Result::error("暂无相关用户信息", 0);
  6580. }
  6581. if ($user->type_id == 10000) {
  6582. $data['status'] = 1;
  6583. } else {
  6584. $data['status'] = 0;
  6585. }
  6586. unset($data['user_id']);
  6587. if ($data['keyword'] == '') {
  6588. //提取标题+内容中的关键词
  6589. $data['keyword'] = $data['title'];
  6590. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6591. Jieba::init(); // 初始化 jieba-php
  6592. Finalseg::init();
  6593. $segList = Jieba::cut($data['keyword']);
  6594. $segList1 = array_slice($segList, 0, 8);
  6595. $data['keyword'] = implode(',', $segList1);
  6596. }
  6597. if ($data['description'] == '') {
  6598. //提取内容中的描述
  6599. // var_dump(11111);
  6600. //提取内容中的描述
  6601. $content = $data['introduce'];
  6602. // 去除 <style> 和 <script> 标签及其内容
  6603. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6604. // 去除所有 HTML 标签
  6605. $content = strip_tags($content);
  6606. // 去除 HTML 实体
  6607. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6608. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6609. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6610. // 去除多余空白
  6611. $content = preg_replace('/\s+/u', '', $content);
  6612. // 截取 100 个字符
  6613. $data['description'] = mb_substr($content, 0, 100);
  6614. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6615. }
  6616. if ($data['status'] == 0) {
  6617. $this->sendMessage([
  6618. 'talk_type' => 1000,
  6619. 'title' => $data['title'],
  6620. 'content' => '提交了审核',
  6621. 'messageType' => 9,
  6622. ]);
  6623. }
  6624. $result = Project::where('id', $id)->update($data);
  6625. if (empty($result)) {
  6626. return Result::error("更新失败", 0);
  6627. }
  6628. return Result::success($result);
  6629. }
  6630. /**
  6631. * 删除项目
  6632. * @param array $data
  6633. * @return array
  6634. */
  6635. public function delProject(array $data): array
  6636. {
  6637. $user = User::where('id', $data['user_id'])->first();
  6638. if (empty($user)) {
  6639. return Result::error("暂无相关用户信息", 0);
  6640. }
  6641. $project = Project::where('id', $data['id'])->first();
  6642. if (empty($project)) {
  6643. return Result::error("暂无相关项目信息", 0);
  6644. }
  6645. $result = Project::where('id', $data['id'])->delete();
  6646. if (empty($result)) {
  6647. return Result::error("删除失败", 0);
  6648. }
  6649. return Result::success($result);
  6650. }
  6651. /**
  6652. * 审核项目
  6653. * @param array $data
  6654. * @return array
  6655. */
  6656. public function checkProject(array $data): array
  6657. {
  6658. $user = User::where('id', $data['user_id'])->first();
  6659. if (empty($user)) {
  6660. return Result::error("暂无相关用户信息", 0);
  6661. }
  6662. // 0:未审核; 1:已审核; 2:已拒绝;
  6663. if ($user->type_id != 10000) {
  6664. if ($data['status'] == 1 || $data['status'] == 2) {
  6665. return Result::error("此用户权限不足", 0);
  6666. }
  6667. }
  6668. $project = Project::where('id', $data['id'])->first();
  6669. if (empty($project)) {
  6670. return Result::error("暂无相关项目信息", 0);
  6671. }
  6672. if ($data['status'] == 2) {
  6673. $this->sendMessage([
  6674. 'talk_type' => 1001,
  6675. 'title' => $project['title'],
  6676. 'content' => '审核拒绝',
  6677. 'messageType' => 9,
  6678. 'user_id' => $project['user_id'],
  6679. ]);
  6680. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  6681. } else {
  6682. if ($data['status'] == 1) {
  6683. $this->sendMessage([
  6684. 'talk_type' => 1001,
  6685. 'title' => $project['title'],
  6686. 'content' => '审核通过',
  6687. 'messageType' => 9,
  6688. 'user_id' => $project['user_id'],
  6689. ]);
  6690. } else if ($data['status'] == 0) {
  6691. $this->sendMessage([
  6692. 'talk_type' => 1000,
  6693. 'title' => $project['title'],
  6694. 'content' => '提交了审核',
  6695. 'messageType' => 9,
  6696. ]);
  6697. }
  6698. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  6699. }
  6700. if (empty($result)) {
  6701. return Result::error("审核失败", 0);
  6702. }
  6703. return Result::success($result);
  6704. }
  6705. /**
  6706. * 获取项目详情
  6707. * @param array $data
  6708. * @return array
  6709. */
  6710. public function getProjectInfo(array $data): array
  6711. {
  6712. $project = Project::where('id', $data['id'])->first();
  6713. if (empty($project)) {
  6714. return Result::error("暂无相关项目信息", 0);
  6715. }
  6716. return Result::success($project);
  6717. }
  6718. public function getWebsiteCompanyInfo(array $data): array
  6719. {
  6720. $company = Company::where('id', $data['id'])
  6721. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  6722. ->where('status', 1)
  6723. ->where('website_id', $data['website_id'])
  6724. ->select('company.*', 'job_industry.hyname as hy_name')
  6725. ->first();
  6726. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  6727. switch ($company->jobnature_id) {
  6728. case null:
  6729. $company->jobnature_name = '';
  6730. break;
  6731. case 0:
  6732. $company->jobnature_name = '市场监督';
  6733. break;
  6734. case 1:
  6735. $company->jobnature_name = '信访纪检';
  6736. break;
  6737. case 2:
  6738. $company->jobnature_name = '公检法司';
  6739. break;
  6740. case 3:
  6741. $company->jobnature_name = '高关注机构';
  6742. break;
  6743. default:
  6744. $company->jobnature_name = '';
  6745. break;
  6746. }
  6747. $city_arr = $company->city_arr_id;
  6748. if (!empty($city_arr)) {
  6749. $city_arr = json_decode($city_arr, true);
  6750. $cityNames = District::whereIn('id', $city_arr)
  6751. ->pluck('name')
  6752. ->implode('-');
  6753. $company->city_name = $cityNames;
  6754. } else {
  6755. $company->city_name = '';
  6756. }
  6757. if (empty($company)) {
  6758. return Result::error("暂无相关公司信息", 0);
  6759. }
  6760. return Result::success($company);
  6761. }
  6762. public function getMSG(array $data): array
  6763. {
  6764. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  6765. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  6766. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  6767. $result = [];
  6768. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  6769. //最近的5篇已审的文章
  6770. $apply_articale = Article::where('status', 1)
  6771. ->where('admin_user_id', $user_id)
  6772. ->orderBy('updated_at', 'desc')
  6773. // ->limit(5)
  6774. ->get();
  6775. //获取5条用户的已审核商品
  6776. $good = Good::where('status', 2)
  6777. ->where('user_id', $user_id)
  6778. ->orderBy('updated_at', 'desc')
  6779. // ->limit(5)
  6780. ->get();
  6781. //获取5条用户待审核的公告
  6782. $notice = Notice::where('status', 2)
  6783. ->where('user_id', $user_id)
  6784. ->orderBy('updated_at', 'desc')
  6785. ->limit(5)->get();
  6786. //获取5条用户的待审核投诉
  6787. $complaint = Complaint::where('status', 2)
  6788. ->where('user_id', $user_id)
  6789. ->orderBy('updated_at', 'desc')
  6790. // ->limit(5)
  6791. ->get();
  6792. //获取5条用户的book
  6793. $book = Book::where('status', 2)
  6794. ->where('user_id', $user_id)
  6795. ->orderBy('updated_at', 'desc')
  6796. // ->limit(5)
  6797. ->get();
  6798. //获取5条用户的求职
  6799. //获取5条用户的求职 1
  6800. $job_hunting = JobHunting::where('job_hunting.status', 2)
  6801. ->where('job_hunting.user_id', $user_id)
  6802. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  6803. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  6804. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6805. ->orderBy('updated_at', 'desc')
  6806. // ->limit(5)
  6807. ->get();
  6808. //获取5条用户的求职 2
  6809. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  6810. ->where('job_recruiting.user_id', $user_id)
  6811. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  6812. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  6813. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6814. ->orderBy('updated_at', 'desc')
  6815. // ->limit(5)
  6816. ->get();
  6817. //人才库 1
  6818. $job_apply = JobApply::where('job_apply.status', 1)
  6819. ->where('job_apply.receiver_id', $user_id)
  6820. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  6821. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  6822. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  6823. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  6824. ->select('job_recruiting', 'job_recruiting.', '', '')
  6825. ->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')
  6826. ->orderBy('updated_at', 'desc')
  6827. // ->limit(5)
  6828. ->get();
  6829. // 职场机会 2
  6830. $job_resume = JobResume::where('job_resume.status', 1)
  6831. ->where('job_resume.receiver_id', $user_id)
  6832. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  6833. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  6834. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  6835. ->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')
  6836. ->orderBy('updated_at', 'desc')
  6837. // ->limit(5)
  6838. ->get();
  6839. //获取5条用户待处理的投诉
  6840. $complaint_deal = Complaint::where('status', 2)
  6841. ->where('deal', 1)
  6842. ->whereJsonContains('re_user_ids', $user_id)
  6843. ->orderBy('updated_at', 'desc')
  6844. // ->limit(5)
  6845. ->get();
  6846. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  6847. $complany = Company::where('status', 1)
  6848. ->where('user_id', $user_id)
  6849. ->orderBy('updated_at', 'desc')
  6850. // ->limit(5)
  6851. ->get();
  6852. //获取5条单聊未读聊天消息
  6853. // $chat = ChatRecords::where('is_read', 0)
  6854. // ->where('user_id', $user_id)
  6855. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  6856. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  6857. // ->where('action', 'recieved')
  6858. // ->where('talk_type', 1)
  6859. // ->orderBy('created_at', 'desc')
  6860. // // ->limit(5)
  6861. // ->get();
  6862. //获取5条未读群聊信息
  6863. // $chat_group = ChatRecords::where('is_read', 0)
  6864. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  6865. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  6866. // ->where('user_id', $user_id)
  6867. // ->where('talk_type', 2)
  6868. // ->orderBy('created_at', 'desc')
  6869. // // ->limit(5)
  6870. // ->get();
  6871. //获取5条用户的待审核项目
  6872. $project = Project::where('status', 1)
  6873. ->where('user_id', $user_id)
  6874. ->orderBy('updated_at', 'desc')
  6875. // ->limit(5)
  6876. ->get();
  6877. // count($chat) + count($chat_group) +
  6878. $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)
  6879. + count($complany)
  6880. + count($project)
  6881. // + count($chat) + count($chat_group)
  6882. ;
  6883. $result = [
  6884. 'apply_articale' => $apply_articale,
  6885. // 'chat' => $chat,
  6886. // 'chat_group' => $chat_group,
  6887. 'good' => $good,
  6888. 'notice' => $notice,
  6889. 'complaint' => $complaint,
  6890. 'book' => $book,
  6891. 'job_hunting' => $job_hunting,
  6892. 'job_recruiting' => $job_recruiting,
  6893. 'job_apply' => $job_apply,
  6894. 'job_resume' => $job_resume,
  6895. 'complaint_deal' => $complaint_deal,
  6896. 'complany' => $complany,
  6897. 'project' => $project,
  6898. 'count' => $count,
  6899. ];
  6900. } elseif ($type_id == 12) {
  6901. //最近的5篇已审的文章
  6902. $apply_articale = Article::where('status', 1)
  6903. ->where('admin_user_id', $user_id)
  6904. ->limit(5)->get();
  6905. //获取5条单聊未读聊天消息
  6906. $chat = ChatRecords::where('is_read', 0)
  6907. ->where('user_id', $user_id)
  6908. ->where('talk_type', 1)
  6909. ->orderBy('created_at', 'desc')
  6910. ->limit(5)->get();
  6911. //获取5条未读群聊信息
  6912. $chat_group = ChatRecords::where('is_read', 0)
  6913. ->where('user_id', $user_id)
  6914. ->where('talk_type', 2)
  6915. ->orderBy('created_at', 'desc')
  6916. ->limit(5)->get();
  6917. //获取5条用户的已审核商品
  6918. $good = Good::where('status', 2)
  6919. ->where('user_id', $user_id)
  6920. ->orderBy('updated_at', 'desc')
  6921. ->limit(5)->get();
  6922. //获取5条用户的book
  6923. $book = Book::where('status', 2)
  6924. ->where('user_id', $user_id)
  6925. ->orderBy('updated_at', 'desc')
  6926. ->limit(5)->get();
  6927. //获取5条用户的求职
  6928. //获取5条用户的求职 1
  6929. //count($chat) + count($chat_group)
  6930. $count = count($apply_articale) + count($good);
  6931. $result = [
  6932. 'apply_articale' => $apply_articale,
  6933. 'chat' => $chat,
  6934. 'chat_group' => $chat_group,
  6935. 'good' => $good,
  6936. 'book' => $book,
  6937. 'count' => $count,
  6938. ];
  6939. } elseif ($type_id == 13) {
  6940. //最近的5篇已审的文章
  6941. $apply_articale = Article::where('status', 1)
  6942. ->where('admin_user_id', $user_id)
  6943. ->limit(5)->get();
  6944. //获取5条单聊未读聊天消息
  6945. $chat = ChatRecords::where('is_read', 0)
  6946. ->where('user_id', $user_id)
  6947. ->where('talk_type', 1)
  6948. ->orderBy('created_at', 'desc')
  6949. ->limit(5)->get();
  6950. //获取5条未读群聊信息
  6951. $chat_group = ChatRecords::where('is_read', 0)
  6952. ->where('user_id', $user_id)
  6953. ->where('talk_type', 2)
  6954. ->orderBy('created_at', 'desc')
  6955. ->limit(5)->get();
  6956. //获取5条用户的已审核商品
  6957. $good = Good::where('status', 2)
  6958. ->where('user_id', $user_id)
  6959. ->orderBy('updated_at', 'desc')
  6960. ->limit(5)->get();
  6961. //count($chat) + count($chat_group) +
  6962. $count = count($apply_articale) + count($good);
  6963. $result = [
  6964. 'apply_articale' => $apply_articale,
  6965. 'chat' => $chat,
  6966. 'chat_group' => $chat_group,
  6967. 'good' => $good,
  6968. 'count' => $count,
  6969. ];
  6970. } elseif ($type_id == 14) {
  6971. //最近的5篇已审的文章
  6972. $apply_articale = Article::where('status', 1)
  6973. ->where('admin_user_id', $user_id)
  6974. // ->limit(5)
  6975. ->get();
  6976. //获取5条用户的已审核商品
  6977. $good = Good::where('status', 2)
  6978. ->where('user_id', $user_id)
  6979. ->orderBy('updated_at', 'desc')
  6980. // ->limit(5)
  6981. ->get();
  6982. $count = count($apply_articale) + count($good);
  6983. $result = [
  6984. 'apply_articale' => $apply_articale,
  6985. 'chat' => '',
  6986. 'chat_group' => '',
  6987. 'good' => $good,
  6988. 'count' => $count,
  6989. ];
  6990. } elseif ($type_id == 10000) {
  6991. //获取未审核的5篇文章
  6992. $apply_articale = Article::where('status', 0)
  6993. ->orderBy('updated_at', 'desc')
  6994. // ->limit(5)
  6995. ->get();
  6996. //获取5条单聊未读聊天消息
  6997. //获取5条单聊未读聊天消息
  6998. // $chat = ChatRecords::where('is_read', 0)
  6999. // ->where('user_id', $user_id)
  7000. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7001. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7002. // ->where('action', 'recieved')
  7003. // ->where('talk_type', 1)
  7004. // ->orderBy('created_at', 'desc')
  7005. // // ->limit(5)
  7006. // ->get();
  7007. // //获取5条未读群聊信息
  7008. // $chat_group = ChatRecords::where('is_read', 0)
  7009. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7010. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7011. // ->where('user_id', $user_id)
  7012. // ->where('talk_type', 2)
  7013. // ->orderBy('created_at', 'desc')
  7014. // // ->limit(5)
  7015. // ->get();
  7016. //获取5条用户的已审核商品
  7017. $good = Good::where('status', 1)
  7018. // ->where('user_id', $user_id)
  7019. ->orderBy('updated_at', 'desc')
  7020. // ->limit(5)
  7021. ->get();
  7022. //获取5条用户待审核的公告
  7023. $notice = Notice::where('status', 1)
  7024. ->orderBy('updated_at', 'desc')
  7025. // ->limit(5)
  7026. ->get();
  7027. //获取5条用户的待审核投诉
  7028. $complaint = Complaint::where('status', 1)
  7029. ->orderBy('updated_at', 'desc')
  7030. // ->limit(5)
  7031. ->get();
  7032. //获取5条用户的book
  7033. $book = Book::where('status', 1)
  7034. ->orderBy('updated_at', 'desc')
  7035. // ->limit(5)
  7036. ->get();
  7037. //获取5条用户的求职 1
  7038. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7039. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7040. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7041. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7042. ->orderBy('updated_at', 'desc')
  7043. // ->limit(5)
  7044. ->get();
  7045. //获取5条用户的求职 2
  7046. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7047. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7048. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7049. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7050. ->orderBy('updated_at', 'desc')
  7051. // ->limit(5)
  7052. ->get();
  7053. //人才库 1
  7054. $job_apply = JobApply::where('job_apply.status', 1)
  7055. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7056. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7057. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7058. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7059. ->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')
  7060. ->orderBy('updated_at', 'desc')
  7061. // ->limit(5)
  7062. ->get();
  7063. // 职场机会 2
  7064. $job_resume = JobResume::where('job_resume.status', 1)
  7065. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7066. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7067. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7068. ->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')
  7069. ->orderBy('updated_at', 'desc')
  7070. // ->limit(5)
  7071. ->get();
  7072. //待审核数据com pro
  7073. $complany = Company::where('status', 0)
  7074. ->orderBy('updated_at', 'desc')
  7075. // ->limit(5)
  7076. ->get();
  7077. $project = Project::where('status', 0)
  7078. ->orderBy('updated_at', 'desc')
  7079. // ->limit(5)
  7080. ->get();
  7081. $count =
  7082. // count($chat) +
  7083. // count($chat_group) +
  7084. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7085. + count($job_apply)
  7086. + count($job_resume)
  7087. + count($complany)
  7088. + count($project);
  7089. $result = [
  7090. 'apply_articale' => $apply_articale,
  7091. // 'chat' => $chat,
  7092. // 'chat_group' => $chat_group,
  7093. 'good' => $good,
  7094. 'notice' => $notice,
  7095. 'complaint' => $complaint,
  7096. 'book' => $book,
  7097. 'job_hunting' => $job_hunting,
  7098. 'job_recruiting' => $job_recruiting,
  7099. 'job_apply' => $job_apply,
  7100. 'job_resume' => $job_resume,
  7101. 'complany' => $complany,
  7102. 'project' => $project,
  7103. 'count' => $count,
  7104. ];
  7105. } elseif ($type_id == 20000) {
  7106. }
  7107. var_dump($type_id, '-----------------test---------');
  7108. return Result::success($result);
  7109. }
  7110. /**
  7111. * @param array $data
  7112. * @return array
  7113. */
  7114. public function getWebsiteProject(array $data): array
  7115. {
  7116. $categorys = json_decode($data['id'], true);
  7117. if (!empty($categorys)) {
  7118. $category_arr = $this->processArticlePro($data['website_id']);
  7119. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7120. $catiall = $category_arr['catiall'];
  7121. // return Result::success($catiall);
  7122. foreach ($categorys as $key => $val) {
  7123. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7124. $level = explode(',', $val['level'])[0];
  7125. $imgnum = explode(',', $val['level'])[1] ?? null;
  7126. $textnum = explode(',', $val['level'])[2] ?? null;
  7127. if ($level == 1) {
  7128. if (!empty($textnum) && $textnum > 0) {
  7129. $text_num = Project::where('level', $level)
  7130. ->where('website_id', $data['website_id'])
  7131. ->where('status', 1)
  7132. ->select(
  7133. 'project.id',
  7134. 'project.title',
  7135. 'project.description',
  7136. 'project.updated_at',
  7137. 'project.category_id',
  7138. 'project.cat_arr_id'
  7139. )
  7140. ->orderBy('updated_at', 'desc')
  7141. ->limit($textnum)
  7142. ->get()->all();
  7143. }
  7144. if (!empty($imgnum) && $imgnum > 0) {
  7145. $img_num = Project::where('level', $level)
  7146. ->where('website_id', $data['website_id'])
  7147. ->where('status', 1)
  7148. ->where('imgurl', '!=', '')
  7149. ->whereNotNull('imgurl')
  7150. ->select(
  7151. 'project.id',
  7152. 'project.title',
  7153. 'project.description',
  7154. 'project.updated_at',
  7155. 'project.imgurl as imgs',
  7156. 'project.category_id',
  7157. 'project.cat_arr_id'
  7158. )
  7159. ->orderBy('updated_at', 'desc')
  7160. ->limit($imgnum)
  7161. ->get()->all();
  7162. }
  7163. } else {
  7164. if (!empty($textnum) && $textnum > 0) {
  7165. $text_num = Project::where('website_id', $data['website_id'])
  7166. ->where('status', 1)
  7167. ->select(
  7168. 'project.id',
  7169. 'project.title',
  7170. 'project.description',
  7171. 'project.updated_at',
  7172. 'project.category_id',
  7173. 'project.cat_arr_id',
  7174. 'project.website_id',
  7175. 'project.updated_at',
  7176. 'project.created_at'
  7177. )
  7178. ->orderBy('updated_at', 'desc')
  7179. ->limit($textnum)
  7180. ->get()->all();
  7181. }
  7182. if (!empty($imgnum) && $imgnum > 0) {
  7183. $img_num = Project::where('website_id', $data['website_id'])
  7184. ->where('status', 1)
  7185. ->where('imgurl', '!=', '')
  7186. ->whereNotNull('imgurl')
  7187. ->select(
  7188. 'project.id',
  7189. 'project.title',
  7190. 'project.description',
  7191. 'project.updated_at',
  7192. 'project.imgurl as imgs',
  7193. 'project.category_id',
  7194. 'project.cat_arr_id'
  7195. )
  7196. ->orderBy('updated_at', 'desc')
  7197. ->limit($imgnum)
  7198. ->get()->all();
  7199. }
  7200. }
  7201. }
  7202. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7203. $category_ids = explode(',', $val['id'])[0];
  7204. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7205. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7206. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7207. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7208. $text_num = Project::whereIn('category_id', $category_arr)
  7209. ->where('website_id', $data['website_id'])
  7210. ->where('status', 1)
  7211. ->select(
  7212. 'project.id',
  7213. 'project.title',
  7214. 'project.description',
  7215. 'project.updated_at',
  7216. 'project.category_id',
  7217. 'project.cat_arr_id'
  7218. )
  7219. ->orderBy('updated_at', 'desc')
  7220. ->limit($cat_textnum)
  7221. ->get()->all();
  7222. }
  7223. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7224. $img_num = Project::whereIn('category_id', $category_arr)
  7225. ->where('website_id', $data['website_id'])
  7226. ->where('status', 1)
  7227. ->where('imgurl', '!=', '')
  7228. ->whereNotNull('imgurl')
  7229. ->select(
  7230. 'project.id',
  7231. 'project.title',
  7232. 'project.description',
  7233. 'project.updated_at',
  7234. 'project.imgurl as imgs',
  7235. 'project.category_id',
  7236. 'project.cat_arr_id'
  7237. )
  7238. ->orderBy('updated_at', 'desc')
  7239. ->limit($cat_imgnum)
  7240. ->get()->all();
  7241. }
  7242. }
  7243. if (!empty($img_num)) {
  7244. foreach ($img_num as $k => $v) {
  7245. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7246. $imgurl = json_decode($v['imgs'], true);
  7247. if (!empty($imgurl)) {
  7248. $img_num[$k]->imgurl = $imgurl[0];
  7249. }
  7250. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7251. }
  7252. }
  7253. if (!empty($text_num)) {
  7254. foreach ($text_num as $k => $v) {
  7255. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7256. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7257. }
  7258. }
  7259. $project[$key]['img_num'] = $img_num ?? [];
  7260. $project[$key]['text_num'] = $text_num ?? [];
  7261. }
  7262. }
  7263. if (empty($project)) {
  7264. return Result::error("暂无相关项目信息", 0);
  7265. }
  7266. return Result::success($project);
  7267. }
  7268. /**
  7269. * @param array $data
  7270. * @return array
  7271. */
  7272. public function getWebsiteProjectInfo(array $data): array
  7273. {
  7274. $project = Project::where('id', $data['id'])
  7275. ->where('status', 1)
  7276. ->where('website_id', $data['website_id'])
  7277. ->select('project.*')
  7278. ->first();
  7279. if (empty($project)) {
  7280. return Result::error("暂无相关项目信息", 0);
  7281. }
  7282. return Result::success($project);
  7283. }
  7284. /**
  7285. * @param array $data
  7286. * @return array
  7287. */
  7288. public function getWebsiteProjectList(array $data): array
  7289. {
  7290. $where = [];
  7291. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7292. $where['category_id'] = $data['category_id'];
  7293. }
  7294. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7295. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7296. }
  7297. $query = Project::where($where)
  7298. ->where('status', 1)
  7299. ->where('website_id', $data['website_id'])
  7300. ->select(
  7301. 'project.id',
  7302. 'project.title',
  7303. 'project.description',
  7304. 'project.imgurl as imgs',
  7305. 'project.category_id',
  7306. 'project.cat_arr_id'
  7307. )
  7308. ->orderBy('updated_at', 'desc');
  7309. $count = $query->count();
  7310. $project = $query->clone()
  7311. ->offset(($data['page'] - 1) * $data['pageSize'])
  7312. ->limit($data['pageSize'])
  7313. ->get()->all();
  7314. if (empty($project)) {
  7315. return Result::error("暂无相关项目信息", 0);
  7316. }
  7317. $categorys = $this->processArticlePro($data['website_id']);
  7318. $catiall = $categorys['catiall'];
  7319. foreach ($project as $key => $val) {
  7320. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7321. if (!empty($val['imgs'])) {
  7322. $imgurl = json_decode($val['imgs'], true);
  7323. if (!empty($imgurl)) {
  7324. $project[$key]->imgurl = $imgurl[0];
  7325. }
  7326. } else {
  7327. $project[$key]->imgurl = '';
  7328. }
  7329. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7330. }
  7331. $result = [
  7332. 'rows' => $project,
  7333. 'count' => $count,
  7334. ];
  7335. return Result::success($result);
  7336. }
  7337. /**
  7338. * @param array $data
  7339. * @return array
  7340. */
  7341. public function getWebsiteCategoryJob(array $data): array
  7342. {
  7343. $categorys = json_decode($data['id'], true);
  7344. if (!empty($categorys)) {
  7345. $category_arr = $this->processArticlePro($data['website_id']);
  7346. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7347. $catiall = $category_arr['catiall'];
  7348. foreach ($categorys as $key => $val) {
  7349. if (isset($val['id']) && !empty($val['id'])) {
  7350. $catid = explode(',', $val['id'])[0] ?? null;
  7351. $type = explode(',', $val['id'])[1] ?? null;
  7352. $textnum = explode(',', $val['id'])[2] ?? null;
  7353. }
  7354. // 4:招聘;5:求职;
  7355. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7356. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7357. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7358. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7359. ->where('job_recruiting.status', 1)
  7360. ->where('job_recruiting.website_id', $data['website_id'])
  7361. ->select(
  7362. 'job_recruiting.id',
  7363. 'job_recruiting.title',
  7364. 'job_company.business_name',
  7365. 'job_recruiting.updated_at',
  7366. 'job_recruiting.cat_arr_id'
  7367. )
  7368. ->orderBy('job_recruiting.updated_at', 'desc')
  7369. ->limit($textnum)
  7370. ->get()->all();
  7371. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7372. // 状态 审核状态,1待审核2已审核3已拒绝
  7373. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7374. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7375. ->where('job_hunting.status', 2)
  7376. ->where('job_hunting.website_id', $data['website_id'])
  7377. ->select(
  7378. 'job_hunting.id',
  7379. 'job_hunting.name',
  7380. 'job_hunting.cat_arr_id',
  7381. 'job_position.zwname as job_name',
  7382. 'job_hunting.updated_at'
  7383. )
  7384. ->orderBy('updated_at', 'desc')
  7385. ->limit($textnum)
  7386. ->get()->all();
  7387. } else {
  7388. $job = [];
  7389. }
  7390. // var_dump($catid.'222uuuuuuu'.$key);
  7391. if (!empty($job)) {
  7392. foreach ($job as $k => $value) {
  7393. if (isset($value->cat_arr_id)) {
  7394. $catArr = json_decode($value->cat_arr_id, true);
  7395. $catId = end($catArr);
  7396. } else {
  7397. continue;
  7398. }
  7399. if (isset($catiall[$catId])) {
  7400. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7401. }
  7402. }
  7403. }
  7404. // var_dump($catid.'xxxxx'.$key);
  7405. $result[$key] = $job ?? [];
  7406. }
  7407. }
  7408. if (empty($result)) {
  7409. return Result::error("暂无相关分类信息", 0);
  7410. }
  7411. return Result::success($result);
  7412. }
  7413. /**
  7414. * 发送消息
  7415. * @param array $messageData
  7416. * @return void
  7417. */
  7418. public function sendMessage($messageData)
  7419. {
  7420. $msg = [
  7421. 'talk_type' => $messageData['talk_type'],
  7422. 'title' => $messageData['title'],
  7423. 'content' => $messageData['content'],
  7424. 'messageType' => $messageData['messageType'],
  7425. 'user_id' => $messageData['user_id'] ?? '',
  7426. 'time' => microtime(),
  7427. ];
  7428. $message = new MqProducer($msg);
  7429. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7430. $producer->produce($message);
  7431. }
  7432. }