NewsService.php 260 KB

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