NewsService.php 223 KB

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