NewsService.php 269 KB

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