NewsService.php 271 KB

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