NewsService.php 221 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086
  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(
  1832. 'good.id',
  1833. 'good.name',
  1834. 'good.imgurl',
  1835. 'good.description',
  1836. 'good.updated_at',
  1837. 'good.com',
  1838. 'good.catid',
  1839. 'good.type_id',
  1840. 'good.website_id',
  1841. 'good.cat_arr_id',
  1842. 'good.created_at',
  1843. 'good.city_id'
  1844. )
  1845. ->latest('updated_at');
  1846. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  1847. // 获取 type_id 为 1 的数据
  1848. $result['type1'] = $this->processGoods(
  1849. $query->clone()
  1850. ->where('type_id', 1)
  1851. ->offset(($data['page'] - 1) * $data['pageSize'])
  1852. ->limit($data['pageSize'])
  1853. ->get(),
  1854. $data
  1855. );
  1856. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  1857. // 获取 type_id 为 2 的数据
  1858. $result['type2'] = $this->processGoods(
  1859. $query->clone()
  1860. ->where('type_id', 2)
  1861. ->offset(($data['page'] - 1) * $data['pageSize'])
  1862. ->limit($data['pageSize'])
  1863. ->get(),
  1864. $data
  1865. );
  1866. if (empty($result)) {
  1867. return Result::error("查询失败", 0);
  1868. }
  1869. return Result::success($result);
  1870. }
  1871. /**
  1872. * 获取商品详情
  1873. * @param array $data
  1874. * @return array
  1875. * */
  1876. public function getWebsiteshopInfo(array $data): array
  1877. {
  1878. $where = [
  1879. 'good.status' => 2,
  1880. 'good.website_id' => $data['website_id'],
  1881. 'good.id' => $data['id'],
  1882. ];
  1883. $goods = Good::where($where)
  1884. ->where('good.id', $data['id'])
  1885. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  1886. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  1887. ->first();
  1888. if (empty($goods)) {
  1889. return Result::error("查询失败", 0);
  1890. }
  1891. $goods->imgurl = json_decode($goods->imgurl, true);
  1892. return Result::success($goods);
  1893. }
  1894. /**
  1895. * 封装处理文章的路由问题
  1896. * */
  1897. function processArticles($articles, $data)
  1898. {
  1899. // 检查 $articles 是否为数组或可迭代对象
  1900. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  1901. return $articles->map(function ($article) use ($data) {
  1902. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  1903. $catid = $article->cat_arr_id ?? '';
  1904. }
  1905. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  1906. $catid = $article->category_arr_id ?? '';
  1907. }
  1908. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  1909. $level = json_decode($catid, true);
  1910. if (!is_array($level)) {
  1911. return $article;
  1912. } else {
  1913. $level = array_map('intval', $level);
  1914. }
  1915. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1916. ->where($data)
  1917. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1918. ->pluck('aLIas_pinyin')
  1919. ->implode('/');
  1920. $article->pinyin = $pinyin ?? '';
  1921. return $article;
  1922. });
  1923. } else {
  1924. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  1925. $catid = $articles->cat_arr_id ?? '';
  1926. $level = json_decode($catid, true);
  1927. if (!is_array($level)) {
  1928. return $articles;
  1929. } else {
  1930. $level = array_map('intval', $level);
  1931. }
  1932. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1933. ->where($data)
  1934. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1935. ->pluck('aLIas_pinyin')
  1936. ->implode('/');
  1937. $articles->pinyin = $pinyin ?? '';
  1938. return $articles;
  1939. }
  1940. }
  1941. // 封装处理由问题
  1942. function processJob($job, $data)
  1943. {
  1944. return $job->map(function ($job) use ($data) {
  1945. $category = $job->cat_arr_id ?? '';
  1946. $cityid = $job->city_arr_id ?? '';
  1947. $city = json_decode($cityid, true);
  1948. $pinyin = '';
  1949. $level = json_decode($category, true);
  1950. // 路由
  1951. if (!empty($level) && is_array($level)) {
  1952. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1953. ->where('website_id', $data['website_id']) // 添加网站ID条件
  1954. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1955. ->get(['aLIas_pinyin'])
  1956. ->pluck('aLIas_pinyin')
  1957. ->implode('/');
  1958. if (empty($pinyin)) {
  1959. $pinyin = $pinyin->aLIas_pinyin ?? '';
  1960. }
  1961. $job->pinyin = $pinyin;
  1962. }
  1963. // 取职位-城市 市??省
  1964. if (!empty($city) && is_array($city)) {
  1965. if (isset($city[1]) && !empty($city[1])) {
  1966. $city = District::where('id', $city[1])->first(['name']);
  1967. $job->city_name = $city->name ?? '';
  1968. } else if (isset($city[0]) && !empty($city[0])) {
  1969. $city = District::where('id', $city[0])->first(['name']);
  1970. $job->city_name = $city->name ?? '';
  1971. } else {
  1972. $job->city_name = '全国';
  1973. }
  1974. }
  1975. // 获取简历最后一级地区
  1976. if (isset($job->city_id) && !empty($job->city_id)) {
  1977. $city = District::where('id', $job->city_id)->first(['name']);
  1978. $job->hunt_cityname = $city->name ?? '';
  1979. }
  1980. // 组合详细地址
  1981. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  1982. $address_id = json_decode($job->address_arr_id, true) ?? [];
  1983. if (is_array($address_id) && !empty($address_id)) {
  1984. $address = District::whereIn('id', $address_id)
  1985. ->orderBy('level', 'asc')
  1986. ->get(['name'])
  1987. ->pluck('name')
  1988. ->implode('');
  1989. // $job->address_name = $address ?? '';
  1990. $job->address_name = ($address ?? '') . ($job->address ?? '');
  1991. }
  1992. }
  1993. // 取行业
  1994. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  1995. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  1996. if (!empty($job->industry)) {
  1997. $query->where('hyid', $job->industry);
  1998. } else if (!empty($job->hy_id)) {
  1999. $query->where('hyid', $job->hy_id);
  2000. } else if (!empty($job->company_hy_id)) {
  2001. $query->where('hyid', $job->company_hy_id);
  2002. } else {
  2003. $query->where('hyid', $job->job_industry);
  2004. }
  2005. })->first(['hyname']);
  2006. $job->hy_name = $hy_name->hyname ?? '';
  2007. }
  2008. // 取职位类别
  2009. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2010. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2011. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2012. $job->zw_name = $zw_name->zwname ?? '';
  2013. }
  2014. // 取具体职位
  2015. 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))) {
  2016. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2017. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2018. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2019. }
  2020. // 取工作经验
  2021. if (isset($job->experience) && !empty($job->experience)) {
  2022. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2023. $job->experience_name = $experience->ename ?? '';
  2024. }
  2025. // 取学历
  2026. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2027. $education = $job->educational ?? $job->school_education;
  2028. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2029. $job->education_name = $education->ename ?? '';
  2030. }
  2031. // 语言
  2032. if (isset($job->language) && !empty($job->language)) {
  2033. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2034. $job->language_name = $language->ename ?? '';
  2035. }
  2036. // 薪资
  2037. if (isset($job->salary) && !empty($job->salary)) {
  2038. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2039. $job->salary_name = $salary->ename ?? '';
  2040. }
  2041. // 职位性质
  2042. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2043. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2044. $job->job_nature_name = $job_nature->ename ?? '';
  2045. }
  2046. // 公司规模
  2047. if (isset($job->company_size) && !empty($job->company_size)) {
  2048. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2049. $job->company_size_name = $company_size->ename ?? '';
  2050. }
  2051. // 公司性质
  2052. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2053. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2054. $job->company_nature_name = $company_nature->nature_name ?? '';
  2055. }
  2056. // $job->pinyin = $pinyin;
  2057. return $job;
  2058. });
  2059. }
  2060. /**
  2061. * 获取书籍模块
  2062. * @param array $data
  2063. * @return array
  2064. * */
  2065. public function getWebsiteBook(array $data): array
  2066. {
  2067. $input['id'] = $data['id'];
  2068. $input['website_id'] = $data['website_id'];
  2069. // 将 JSON 字符串转换为 PHP 数组
  2070. $data = json_decode($input['id'], true);
  2071. // 使用 array_map 处理每个元素
  2072. $result = array_map(function ($item) use ($input) {
  2073. // 检查parent元素是否存在且不是undefined
  2074. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2075. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2076. $website = [
  2077. 'website_id' => $input['website_id'],
  2078. ];
  2079. // 查询栏目名称
  2080. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2081. if (empty($category)) {
  2082. $parent_alias = '';
  2083. $parent_pinyin = null;
  2084. $imgBooks = [];
  2085. $textBooks = [];
  2086. } else {
  2087. $parent_alias = $category->alias ?? '';
  2088. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2089. // 查找子分类ID数组
  2090. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2091. array_push($childCategoryIds, $parentCatId);
  2092. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2093. if ($parentImgNum != 0) {
  2094. // 查询图片新闻
  2095. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2096. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2097. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2098. })
  2099. ->where('book.status', 2)
  2100. ->where('book.img_url', '!=', '')
  2101. ->leftJoin('website_category', function ($join) use ($website) {
  2102. $join->on('book.cat_id', '=', 'website_category.category_id')
  2103. ->where('website_category.website_id', '=', $website['website_id']);
  2104. })
  2105. ->select(
  2106. 'book.id',
  2107. 'book.title',
  2108. 'book.img_url',
  2109. 'book.price',
  2110. 'book.market_price',
  2111. 'book.description',
  2112. 'book.cat_id',
  2113. 'book.description',
  2114. 'book.updated_at',
  2115. 'website_category.alias as category_name',
  2116. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2117. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2118. )
  2119. ->orderBy('updated_at', 'desc')
  2120. ->limit($parentImgNum)
  2121. ->get()->all();
  2122. // 查询文字新闻
  2123. }
  2124. if ($parentTextNum != 0) {
  2125. $textBooks = [];
  2126. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2127. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2128. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2129. })
  2130. ->where('book.status', 2)
  2131. ->leftJoin('website_category', function ($join) use ($website) {
  2132. $join->on('book.cat_id', '=', 'website_category.category_id')
  2133. ->where('website_category.website_id', '=', $website['website_id']);
  2134. })
  2135. ->select(
  2136. 'book.id',
  2137. 'book.title',
  2138. 'book.img_url',
  2139. 'book.price',
  2140. 'book.market_price',
  2141. 'book.description',
  2142. 'book.cat_id',
  2143. 'book.description',
  2144. 'book.updated_at',
  2145. 'website_category.alias as category_name',
  2146. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2147. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2148. )
  2149. ->orderBy('updated_at', 'desc')
  2150. ->limit($parentTextNum)
  2151. ->get()->all();
  2152. }
  2153. }
  2154. }
  2155. $resultItem = [
  2156. 'alias' => $parent_alias ?? '',
  2157. 'category_id' => $parentCatId ?? 0,
  2158. 'pinyin' => $parent_pinyin ?? null,
  2159. 'imgnum' => $imgBooks ?? [],
  2160. 'textnum' => $textBooks ?? [],
  2161. ];
  2162. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2163. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2164. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2165. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2166. ->get()->all();
  2167. if (!empty($childCategory)) {
  2168. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2169. // 查询子栏目名称
  2170. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2171. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2172. ->first();
  2173. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2174. $childImgArticles = [];
  2175. $childTextArticles = [];
  2176. $resultItem['child'] = [];
  2177. } else {
  2178. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2179. // 查询子栏目图片新闻
  2180. $childImgArticles = Book::where('cat_id', $childCatId)
  2181. ->where('status', 2)
  2182. ->where('img_url', '!=', '')
  2183. ->leftJoin('website_category', function ($join) use ($website) {
  2184. $join->on('book.cat_id', '=', 'website_category.category_id')
  2185. ->where('website_category.website_id', '=', $website['website_id']);
  2186. })
  2187. ->select(
  2188. 'book.id',
  2189. 'book.title',
  2190. 'book.img_url',
  2191. 'book.price',
  2192. 'book.market_price',
  2193. 'book.description',
  2194. 'book.cat_id',
  2195. 'book.description',
  2196. 'book.updated_at',
  2197. DB::raw("'$child_pinyin' as pinyin")
  2198. )
  2199. ->orderBy('updated_at', 'desc')
  2200. ->limit($childImgNum)
  2201. ->get()->all();
  2202. // 查询子栏目文字新闻
  2203. $childTextArticles = Book::where('cat_id', $childCatId)
  2204. ->where('status', 2)
  2205. ->leftJoin('website_category', function ($join) use ($website) {
  2206. $join->on('book.cat_id', '=', 'website_category.category_id')
  2207. ->where('website_category.website_id', '=', $website['website_id']);
  2208. })
  2209. ->select(
  2210. 'book.id',
  2211. 'book.title',
  2212. 'book.img_url',
  2213. 'book.price',
  2214. 'book.market_price',
  2215. 'book.description',
  2216. 'book.cat_id',
  2217. 'book.description',
  2218. 'book.updated_at',
  2219. DB::raw("'$child_pinyin' as pinyin")
  2220. )
  2221. ->orderBy('updated_at', 'desc')
  2222. ->limit($childTextNum)
  2223. ->get()->all();
  2224. $resultItem['child'] = [
  2225. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2226. 'category_id' => $childCatId,
  2227. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2228. 'all_childcat' => $childCategory,
  2229. 'imgnum' => $childImgArticles,
  2230. 'textnum' => $childTextArticles,
  2231. ];
  2232. }
  2233. }
  2234. } else {
  2235. $resultItem['child'] = [];
  2236. }
  2237. return $resultItem;
  2238. }, $data);
  2239. return Result::success($result);
  2240. }
  2241. /**
  2242. * 获取书刊列表
  2243. * @param array $data
  2244. * @return array
  2245. * */
  2246. public function getWebsiteBookList(array $data): array
  2247. {
  2248. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2249. if (empty($web)) {
  2250. return Result::error("查询失败", 0);
  2251. }
  2252. $catid = $data['id'];
  2253. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2254. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2255. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2256. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2257. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2258. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2259. ->where('pid', $category['pid'])
  2260. ->select(
  2261. 'category_id',
  2262. 'alias',
  2263. 'aLIas_pinyin',
  2264. 'pid',
  2265. 'sort',
  2266. 'is_url',
  2267. 'web_url',
  2268. 'seo_title',
  2269. 'seo_keywords',
  2270. 'seo_description',
  2271. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2272. )
  2273. ->orderBy('sort')
  2274. ->get()->all();
  2275. if (empty($category)) {
  2276. return Result::error("查询失败", 0);
  2277. }
  2278. $query = Book::where('book.status', 2)
  2279. ->where('book.website_id', $data['website_id'])
  2280. ->where('book.cat_id', $catid)
  2281. ->select(
  2282. 'book.id',
  2283. 'book.title',
  2284. 'book.img_url',
  2285. 'book.description',
  2286. 'book.updated_at',
  2287. 'book.cat_id',
  2288. DB::raw("'$pinyin' as pinyin")
  2289. )
  2290. ->orderBy('book.updated_at', 'desc');
  2291. $count = $query->count();
  2292. $query = clone $query;
  2293. $Book = $query
  2294. ->limit($data['pageSize'])
  2295. ->offset(($data['page'] - 1) * $data['pageSize'])
  2296. ->get()->all();
  2297. $result = [
  2298. 'category' => $categorys,
  2299. 'books' => $Book,
  2300. 'count' => $count,
  2301. ];
  2302. // if(empty($result)){
  2303. // return Result::error("查询失败", 0);
  2304. // }
  2305. return Result::success($result);
  2306. }
  2307. /**
  2308. * 获取书刊详情
  2309. * @param array $data
  2310. * @return array
  2311. * */
  2312. public function getWebsiteBookInfo(array $data): array
  2313. {
  2314. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2315. if (empty($web)) {
  2316. return Result::error("查询失败", 0);
  2317. }
  2318. $book = Book::where('status', 2)
  2319. ->where('website_id', $data['website_id'])
  2320. ->where('id', $data['id'])
  2321. ->select(
  2322. 'book.*',
  2323. )
  2324. ->orderBy('updated_at', 'desc')
  2325. ->first();
  2326. if (empty($book)) {
  2327. return Result::error("查询失败", 0);
  2328. }
  2329. // 先查询当前分类的 pid
  2330. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2331. ->where('category_id', $book['cat_id'])
  2332. ->first(['pid', 'category_id']);
  2333. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2334. if (!empty($carpid)) {
  2335. if ($carpid->pid != 0) {
  2336. $pid = $carpid['pid'];
  2337. // $parent_pinyin = '';
  2338. } else {
  2339. $pid = $carpid['category_id'];
  2340. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2341. }
  2342. }
  2343. $categorys = $query->where('pid', $pid)
  2344. ->select(
  2345. 'category_id',
  2346. 'alias',
  2347. 'aLIas_pinyin',
  2348. 'pid',
  2349. 'sort',
  2350. 'is_url',
  2351. 'web_url',
  2352. 'category_arr_id as cat_arr_id',
  2353. )
  2354. ->orderBy('sort')
  2355. ->get();
  2356. $category = $this->processArticle($categorys, $data);
  2357. $result = [
  2358. 'category' => $category,
  2359. 'books' => $book,
  2360. ];
  2361. return Result::success($result);
  2362. }
  2363. /**
  2364. * 尝试
  2365. * @param array $data
  2366. * @return array
  2367. * */
  2368. public function test(array $data): array
  2369. {
  2370. $input['id'] = $data['id'];
  2371. $input['website_id'] = $data['website_id'];
  2372. // 将 JSON 字符串转换为 PHP 数组
  2373. $data = json_decode($input['id'], true);
  2374. $result = [];
  2375. $article = $data;
  2376. $result = array_map(function ($item) use ($input) {
  2377. $website = [
  2378. 'website_id' => $input['website_id'],
  2379. ];
  2380. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2381. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2382. $parent = [
  2383. 0 => $category['category_id'] ?? [],
  2384. 1 => $parentImgNum ?? [],
  2385. 2 => $parentTextNum ?? [],
  2386. ];
  2387. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2388. $child = [];
  2389. $resultItem = [
  2390. // 'alias' => $parent_alias ?? '',
  2391. 'category_id' => $parentCatId ?? 0,
  2392. 'pinyin' => $parentImgNum ?? null,
  2393. 'imgnum' => $parentTextNum ?? [],
  2394. // 'textnum' => $textArticles ?? [],
  2395. ];
  2396. return $parent;
  2397. }, $data);
  2398. return Result::success($result);
  2399. // });
  2400. }
  2401. /**
  2402. * 封装处理文章的路由问题
  2403. * */
  2404. function processArticle($article, $data)
  2405. {
  2406. return $article->map(function ($article) use ($data) {
  2407. $catid = $article->cat_arr_id ?? '';
  2408. $level = json_decode($catid, true);
  2409. $pinyin = '';
  2410. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2411. if (!empty($level) && is_array($level)) {
  2412. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2413. ->where('website_id', $data['website_id'])
  2414. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2415. ->get(['aLIas_pinyin'])
  2416. ->pluck('aLIas_pinyin')
  2417. ->implode('/');
  2418. } else {
  2419. $pinyin = '';
  2420. }
  2421. $article->pinyin = $pinyin;
  2422. return $article;
  2423. });
  2424. }
  2425. /**
  2426. * c端-获取招工招聘下拉选框
  2427. * @param array $data
  2428. * @return array
  2429. * */
  2430. public function getWebsiteJobSelect(array $data): array
  2431. {
  2432. $web = Website::where('id', $data['website_id'])->first();
  2433. if (empty($web)) {
  2434. return Result::error("该网站不存在", 0);
  2435. }
  2436. $hy = JobIndustry::get()->all();
  2437. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2438. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2439. $result = [
  2440. 'hy' => $hy,
  2441. 'zw' => $zw,
  2442. 'jtzw' => $jtzw,
  2443. ];
  2444. if (empty($result)) {
  2445. return Result::error("查询失败", 0);
  2446. }
  2447. return Result::success($result);
  2448. }
  2449. /**
  2450. * c端-获取招工招聘
  2451. * @param array $data
  2452. * @return array
  2453. * */
  2454. public function getWebsiteJob(array $data): array
  2455. {
  2456. $web = Website::where('id', $data['website_id'])->first();
  2457. if (empty($web)) {
  2458. return Result::error("该网站不存在", 0);
  2459. }
  2460. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2461. ->where('job_hunting.website_id', $data['website_id'])
  2462. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2463. $query->where(function ($q) use ($data) {
  2464. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2465. });
  2466. })
  2467. ->select(
  2468. 'job_hunting.id',
  2469. 'job_hunting.cat_arr_id',
  2470. 'job_hunting.job_name_get',
  2471. 'job_hunting.industry',
  2472. 'job_hunting.name',
  2473. 'job_hunting.sexy',
  2474. 'job_hunting.origin',
  2475. 'job_hunting.city_arr_id',
  2476. 'job_hunting.experience',
  2477. 'job_hunting.updated_at',
  2478. 'job_hunting.salary'
  2479. )
  2480. ->orderBy('updated_at', 'desc')
  2481. ->limit($data['job1_num'])
  2482. ->get();
  2483. $web['website_id'] = $data['website_id'];
  2484. if (empty($job_hunting)) {
  2485. $job_huntings = "未查询到相关简历信息";
  2486. } else {
  2487. $job_huntings = $this->processJob($job_hunting, $web);
  2488. }
  2489. // 0:待审核 1:已通过 2:已拒绝
  2490. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2491. ->where('job_recruiting.website_id', $data['website_id'])
  2492. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2493. $query->where(function ($q) use ($data) {
  2494. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2495. });
  2496. })
  2497. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2498. ->select(
  2499. 'job_recruiting.id',
  2500. 'job_recruiting.cat_arr_id',
  2501. 'job_recruiting.title',
  2502. 'job_recruiting.jtzw_id',
  2503. 'job_recruiting.hy_id',
  2504. 'job_recruiting.city_arr_id',
  2505. 'job_recruiting.due_data',
  2506. 'job_recruiting.updated_at',
  2507. 'job_recruiting.experience',
  2508. 'job_recruiting.educational',
  2509. 'job_recruiting.salary',
  2510. 'job_recruiting.zw_id',
  2511. 'job_company.business_name'
  2512. )
  2513. ->orderBy('updated_at', 'desc')
  2514. ->limit($data['job2_num'])
  2515. ->get();
  2516. if (empty($job_recruiting->toArray())) {
  2517. $job_recruitings = "未查询到相关职位信息";
  2518. } else {
  2519. $job_recruitings = $this->processJob($job_recruiting, $web);
  2520. }
  2521. $result = [
  2522. 'job_hunting' => $job_huntings,
  2523. 'job_recuiting' => $job_recruitings,
  2524. ];
  2525. return Result::success($result);
  2526. }
  2527. /**
  2528. * c端-获取招工招聘列表
  2529. * @param array $data
  2530. * @return array
  2531. * */
  2532. public function getWebsiteJobList(array $data): array
  2533. {
  2534. $recruit_where = [];
  2535. $hunt_where = [];
  2536. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2537. if (empty($web)) {
  2538. return Result::error("此网站不存在", 0);
  2539. }
  2540. $website_id['website_id'] = $data['website_id'];
  2541. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2542. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2543. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2544. }
  2545. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2546. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2547. }
  2548. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2549. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2550. }
  2551. if(isset($data['keyword']) && !empty($data['keyword'])){
  2552. array_push($recruit_where, ['title','like','%'.$data['keyword'].'%']);
  2553. }
  2554. $query = JobRecruiting::where('job_recruiting.status', 1)
  2555. ->where('job_recruiting.website_id', $data['website_id'])
  2556. ->where($recruit_where)
  2557. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2558. $query->where(function ($q) use ($data) {
  2559. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2560. });
  2561. })
  2562. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2563. $query->where(function ($q) use ($data) {
  2564. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2565. });
  2566. })
  2567. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2568. ->select(
  2569. 'job_recruiting.id',
  2570. 'job_recruiting.hy_id',
  2571. 'job_recruiting.title',
  2572. 'job_recruiting.zw_id',
  2573. 'job_recruiting.educational',
  2574. 'job_recruiting.jtzw_id',
  2575. 'job_recruiting.city_arr_id',
  2576. 'job_recruiting.due_data',
  2577. 'job_recruiting.experience',
  2578. 'job_recruiting.cat_arr_id',
  2579. 'job_recruiting.updated_at',
  2580. 'job_company.business_name'
  2581. )
  2582. ->orderBy('updated_at', 'desc');
  2583. $recruit_count = $query->count();
  2584. $query = clone $query;
  2585. $JobRecruiting = $query
  2586. ->offset(($data['page'] - 1) * $data['pageSize'])
  2587. ->limit($data['pageSize'])
  2588. ->get();
  2589. if (empty($JobRecruiting)) {
  2590. $JobRecruiting = "暂无相关职位信息";
  2591. } else {
  2592. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2593. }
  2594. }
  2595. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2596. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2597. array_push($hunt_where, ['job', $data['zw_id']]);
  2598. }
  2599. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2600. array_push($hunt_where, ['job_name_get', $data['jtzw_id']]);
  2601. }
  2602. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2603. array_push($hunt_where, ['industry', $data['hy_id']]);
  2604. }
  2605. $query = JobHunting::where('status', 2)
  2606. ->where('job_hunting.website_id', $data['website_id'])
  2607. ->where($hunt_where)
  2608. ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  2609. $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  2610. })
  2611. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2612. $query->where(function ($q) use ($data) {
  2613. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2614. });
  2615. })
  2616. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  2617. $query->where(function ($q) use ($data) {
  2618. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  2619. });
  2620. })
  2621. ->select('id', 'sexy', 'experience', 'origin', 'industry', 'name', 'job', 'job_name_get', 'city_arr_id', 'cat_arr_id', 'created_at', 'updated_at')
  2622. ->orderBy('updated_at', 'desc');
  2623. $hunt_count = $query->count();
  2624. $query = clone $query;
  2625. $JobHunting = $query
  2626. ->offset(($data['page'] - 1) * $data['pageSize'])
  2627. ->limit($data['pageSize'])
  2628. ->get();
  2629. if (empty($JobHunting)) {
  2630. $JobRecruiting = "暂无相关简历信息";
  2631. } else {
  2632. $JobHunting = $this->processJob($JobHunting, $website_id);
  2633. }
  2634. }
  2635. $result = [
  2636. 'JobRecruiting' => $JobRecruiting ?? [],
  2637. 'recruit_count' => $recruit_count ?? 0,
  2638. 'JobHunting' => $JobHunting ?? [],
  2639. 'hunt_count' => $hunt_count ?? 0,
  2640. ];
  2641. return Result::success($result);
  2642. }
  2643. /**
  2644. * c端-获取招工招聘详情
  2645. * @param array $data
  2646. * @return array
  2647. * */
  2648. public function getWebsiteJobInfo(array $data): array
  2649. {
  2650. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2651. if (empty($web)) {
  2652. return Result::error("该网站不存在", 0);
  2653. }
  2654. $webid = [
  2655. 'website_id' => $data['website_id'],
  2656. ];
  2657. // 职位相关信息
  2658. if ($data['type'] == 1) {
  2659. $query = JobRecruiting::where('status', 1)
  2660. ->where('website_id', $data['website_id'])
  2661. ->select('*');
  2662. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2663. $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();
  2664. if (!empty($company)) {
  2665. $result['company'] = $this->processJob($company, $webid);
  2666. }
  2667. $other_job = JobRecruiting::where('status', 1)
  2668. ->where('website_id', $data['website_id'])
  2669. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2670. ->where('id', '!=', $data['id'])
  2671. ->where('user_id', '=', $job[0]['user_id'])
  2672. ->limit($data['pageSize'])
  2673. ->get();
  2674. if (!empty($other_job)) {
  2675. $result['other_job'] = $this->processJob($other_job, $webid);
  2676. }
  2677. } else {
  2678. // 简历相关信息
  2679. $job = JobHunting::where('job_hunting.status', 2)
  2680. ->where('job_hunting.website_id', $data['website_id'])
  2681. ->where('job_hunting.id', $data['id'])
  2682. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2683. ->select('job_hunting.*', 'user_name')
  2684. ->get();
  2685. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  2686. if (!empty($resume->toArray())) {
  2687. $result['resume'] = 1;
  2688. } else {
  2689. $result['resume'] = 0;
  2690. }
  2691. }
  2692. if (empty($job->toArray())) {
  2693. return Result::error("id参数错误", 0);
  2694. }
  2695. if (!empty($job[0]['job_experience'])) {
  2696. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  2697. if (!empty($job_experience)) {
  2698. // $hy = [];
  2699. foreach ($job_experience as $key => $value) {
  2700. // $id = $value['id'];
  2701. $hy[$key] = $value['job_industry'];
  2702. $zw_id[$key] = $value['job_typename'];
  2703. $jtzw_id[$key] = $value['job_name'];
  2704. }
  2705. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  2706. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  2707. // 先将关联表转换为索引数组,提高查找效率
  2708. $hyLookup = [];
  2709. foreach ($hy_table as $item) {
  2710. $hyLookup[$item['hyid']] = $item['hyname'];
  2711. }
  2712. $zwLookup = [];
  2713. foreach ($zw_table as $item) {
  2714. $zwLookup[$item['zwid']] = $item['zwname'];
  2715. }
  2716. foreach ($job_experience as $key => &$value) {
  2717. // 处理行业名称
  2718. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  2719. $value['hy_name'] = $hyLookup[$hy[$key]];
  2720. }
  2721. // 处理职位名称
  2722. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  2723. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  2724. }
  2725. // 处理具体职位名称
  2726. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  2727. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  2728. }
  2729. }
  2730. // 释放引用,防止意外修改后续代码
  2731. unset($value);
  2732. }
  2733. $result['job_experience'] = $job_experience ?? [];
  2734. }
  2735. if (!empty($job[0]['education_experience'])) {
  2736. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  2737. if (!empty($education_experience)) {
  2738. foreach ($education_experience as $key => $value) {
  2739. // $id = $value['id'];
  2740. $education[$key] = $value['school_education'];
  2741. }
  2742. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  2743. // // 先将关联表转换为索引数组,提高查找效率
  2744. $educationLookup = [];
  2745. foreach ($education_table as $item) {
  2746. $educationLookup[$item['evalue']] = $item['ename'];
  2747. }
  2748. foreach ($education_experience as $key => &$value) {
  2749. // 处理学历名称
  2750. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  2751. $value['education_name'] = $educationLookup[$education[$key]];
  2752. }
  2753. }
  2754. }
  2755. $result['education_experience'] = $job_experience ?? [];
  2756. }
  2757. $result['job'] = $this->processJob($job, $webid);
  2758. // // 返现对应的栏目
  2759. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  2760. $category = WebsiteCategory::where('website_id', $data['website_id'])
  2761. ->whereIn('category_id', $catid)
  2762. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  2763. ->orderBy('pid')->get()->all();
  2764. if (!empty($category)) {
  2765. $result['category'] = $category;
  2766. }
  2767. $result['job'] = $job;
  2768. $result['job_experience'] = $job_experience ?? [];
  2769. $result['education_experience'] = $education_experience ?? [];
  2770. if (empty($result)) {
  2771. return Result::error("参数错误", 0);
  2772. }
  2773. return Result::success($result);
  2774. }
  2775. /**
  2776. * c端-申请职位
  2777. * @param array $data
  2778. * @return array
  2779. * */
  2780. public function getWebsiteJobApply(array $data): array
  2781. {
  2782. // 首先验证网站是否存在
  2783. // return Result::success($data);
  2784. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2785. if (empty($web)) {
  2786. return Result::error("该网站不存在", 0);
  2787. }
  2788. // 验证用户是否存在且为个人会员/管理员
  2789. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2790. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2791. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  2792. return Result::error("用户不存在", 0);
  2793. }
  2794. // 去除重复元素和空元素,并保持原始顺序
  2795. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  2796. return !empty($value);
  2797. }));
  2798. // 验证职位是否存在 1:审核通过
  2799. $recruiting = JobRecruiting::where('status', 1)
  2800. ->where('website_id', $data['website_id'])
  2801. ->whereIn('id', $data['recruit_id'])
  2802. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  2803. if (empty($recruiting)) {
  2804. return Result::error("该职位不存在", 0);
  2805. }
  2806. // 简历是否存在
  2807. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  2808. if (empty($hunt_id)) {
  2809. return Result::error("该简历不存在", 0);
  2810. }
  2811. $data['hunt_id'] = $hunt_id['hunt_id'];
  2812. // // 验证是否已投递过该职位
  2813. $apply = JobApply::where('user_id', $data['user_id'])
  2814. ->where('hunt_id', $data['hunt_id'])
  2815. ->where('website_id', $data['website_id'])
  2816. ->whereIn('recruit_id', $data['recruit_id'])
  2817. ->get(['recruit_id']);
  2818. if (!empty($apply->toArray())) {
  2819. return Result::error("您已投递过该职位!");
  2820. }
  2821. $insertData = array_map(function ($recruiting) use ($data) {
  2822. return [
  2823. 'user_id' => $data['user_id'],
  2824. 'hunt_id' => $data['hunt_id'],
  2825. 'website_id' => $data['website_id'],
  2826. 'recruit_id' => $recruiting['recruit_id'],
  2827. 'receiver_id' => $recruiting['receiver_id'],
  2828. 'status' => 1,
  2829. ];
  2830. }, $recruiting);
  2831. // 批量插入数据
  2832. $result = JobApply::insert($insertData);
  2833. if (empty($result)) {
  2834. return Result::error("投递失败", 0);
  2835. }
  2836. return Result::success($result);
  2837. }
  2838. /**
  2839. * 招工招聘-沟通简历
  2840. * @param array $data
  2841. * @return array
  2842. * */
  2843. public function getWebsiteJobResume(array $data): array
  2844. {
  2845. // 首先验证网站是否存在
  2846. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2847. if (empty($web)) {
  2848. return Result::error("该网站不存在", 0);
  2849. }
  2850. // return Result::success($data);
  2851. // 验证用户是否存在且为企业会员/管理员
  2852. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2853. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2854. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2855. return Result::error("用户不存在", 0);
  2856. }
  2857. // 去除重复元素和空元素,并保持原始顺序
  2858. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  2859. return !empty($value);
  2860. }));
  2861. // 验证简历是否存在
  2862. $hunting = JobHunting::where('status', 2)
  2863. ->where('website_id', $data['website_id'])
  2864. ->whereIn('id', $data['hunt_id'])
  2865. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  2866. if (empty($hunting)) {
  2867. return Result::error("该简历不存在", 0);
  2868. }
  2869. // 验证是否已沟通过该简历
  2870. $remuse = JobRemuse::where('user_id', $data['user_id'])
  2871. ->where('recruit_id', $data['recruit_id'])
  2872. ->where('website_id', $data['website_id'])
  2873. ->whereIn('hunt_id', $data['hunt_id'])
  2874. ->get(['hunt_id']);
  2875. if (!empty($remuse->toArray())) {
  2876. return Result::error("您已沟通过该简历!");
  2877. }
  2878. // 准备要插入的数据数组
  2879. $insertData = array_map(function ($hunting) use ($data) {
  2880. return [
  2881. 'user_id' => $data['user_id'],
  2882. 'recruit_id' => $data['recruit_id'],
  2883. 'website_id' => $data['website_id'],
  2884. 'hunt_id' => $hunting['hunt_id'],
  2885. 'receiver_id' => $hunting['receiver_id'],
  2886. 'status' => 1,
  2887. ];
  2888. }, $hunting);
  2889. // 批量插入数据
  2890. $result = JobRemuse::insert($insertData);
  2891. if (empty($result)) {
  2892. return Result::error("沟通失败", 0);
  2893. }
  2894. return Result::success($result);
  2895. }
  2896. /**
  2897. * 招工招聘 -我的职位(企业会员)
  2898. * @param array $data
  2899. * @return array
  2900. */
  2901. public function getWebsiteJobRecruiting(array $data): array
  2902. {
  2903. $web = Website::where('id', $data['website_id'])->first('id');
  2904. if (empty($web)) {
  2905. return Result::error("该网站不存在", 0);
  2906. }
  2907. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2908. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2909. return Result::error("用户暂无权限!", 0);
  2910. }
  2911. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  2912. $result = JobRecruiting::where('website_id', $data['website_id'])
  2913. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  2914. $query->where('user_id', $user['id']);
  2915. })
  2916. ->where('status', 1)
  2917. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  2918. ->orderBy('updated_at', 'desc')
  2919. ->limit($data['pageSize'])
  2920. ->get();
  2921. if (empty($result)) {
  2922. return Result::error("暂无相关职位信息", 0);
  2923. }
  2924. return Result::success($result);
  2925. }
  2926. /**
  2927. * c端 - 验证路由
  2928. * @param array $data
  2929. * @return array
  2930. */
  2931. /**
  2932. * c端 - 验证路由
  2933. * @param array $data
  2934. * @return array
  2935. */
  2936. public function checkWebsiteRoute(array $data): array
  2937. {
  2938. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2939. if (empty($web)) {
  2940. return Result::error("该网站不存在", 0);
  2941. }
  2942. if (isset($data['other_route']) && !empty($data['other_route'])) {
  2943. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  2944. if (empty($whiteRouterInfo)) {
  2945. return Result::error("非法路径地址", 0);
  2946. } else {
  2947. return Result::success($whiteRouterInfo->toArray());
  2948. }
  2949. } else {
  2950. // 验证栏目路由
  2951. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  2952. ->where('aLIas_pinyin', $data['last_route'])
  2953. ->first();
  2954. if (empty($last_category)) {
  2955. return Result::error("该栏目不存在", 0);
  2956. }
  2957. if (isset($data['id']) && !empty($data['id'])) {
  2958. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  2959. switch ($last_category['type']) {
  2960. case 1:
  2961. // 文章
  2962. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  2963. $article = Article::where('status', 1)
  2964. ->where('id', $data['id'])
  2965. ->where(function ($query) use ($data) {
  2966. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  2967. ->orWhereNull("ignore_ids");
  2968. })
  2969. ->first(['cat_arr_id']);
  2970. if (empty($article)) {
  2971. return Result::error("该文章不存在", 0);
  2972. }
  2973. // return Result::success($article);
  2974. break;
  2975. case 2:
  2976. // 商品
  2977. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  2978. $article = Good::where('website_id', $data['website_id'])
  2979. ->where('status', 2)
  2980. ->where('id', $data['id'])
  2981. ->first(['cat_arr_id']);
  2982. if (empty($article)) {
  2983. return Result::error("该商品不存在", 0);
  2984. }
  2985. break;
  2986. case 3:
  2987. // 书刊信息
  2988. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  2989. $article = Book::where('website_id', $data['website_id'])
  2990. ->where('status', 2)
  2991. ->where('id', $data['id'])
  2992. ->first(['id', 'cat_arr_id']);
  2993. if (empty($article)) {
  2994. return Result::error("该书刊不存在", 0);
  2995. }
  2996. break;
  2997. case 4:
  2998. // 招聘
  2999. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核;(只有企业会员需要审核)',
  3000. $article = JobRecruiting::where('website_id', $data['website_id'])
  3001. ->where('status', 1)
  3002. ->where('id', $data['id'])
  3003. ->first(['cat_arr_id']);
  3004. if (empty($article)) {
  3005. return Result::error("该招聘不存在", 0);
  3006. }
  3007. break;
  3008. case 5:
  3009. // 求职
  3010. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3011. $article = JobHunting::where('website_id', $data['website_id'])
  3012. ->where('status', 2)
  3013. ->where('id', $data['id'])
  3014. ->first(['cat_arr_id']);
  3015. if (empty($article)) {
  3016. return Result::error("该求职不存在", 0);
  3017. }
  3018. break;
  3019. case 6:
  3020. // 招工招聘
  3021. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3022. $article = JobRecruiting::where('website_id', $data['website_id'])
  3023. ->where('status', 1)
  3024. ->where('id', $data['id'])
  3025. ->first(['cat_arr_id']);
  3026. if (empty($article)) {
  3027. $article = JobHunting::where('website_id', $data['website_id'])
  3028. ->where('status', 2)
  3029. ->where('id', $data['id'])
  3030. ->first(['cat_arr_id']);
  3031. }
  3032. if (empty($article)) {
  3033. return Result::error("该招工招聘不存在", 0);
  3034. }
  3035. break;
  3036. default:
  3037. return Result::error("该数据不存在", 0);
  3038. break;
  3039. }
  3040. $catid = json_decode($article['cat_arr_id'], true);
  3041. if (empty($catid)) {
  3042. return Result::error("该数据不存在", 0);
  3043. }
  3044. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3045. ->orderByRaw('FIELD(category_id, ' . implode(',', $catid) . ')')
  3046. ->whereIn('category_id', $catid)
  3047. ->pluck('aLIas_pinyin')
  3048. ->implode('/');
  3049. }
  3050. if ($last_category['pid'] != 0) {
  3051. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3052. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3053. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr) . ')')
  3054. ->whereIn('category_id', $cat_arr)
  3055. ->pluck('aLIas_pinyin')
  3056. ->implode('/');
  3057. } else {
  3058. $pinyin = $last_category['aLIas_pinyin'];
  3059. }
  3060. if (empty($pinyin) || $pinyin != $data['all_route']) {
  3061. return Result::error('非法路径!');
  3062. } else {
  3063. return Result::success($pinyin);
  3064. }
  3065. }
  3066. }
  3067. /**
  3068. * 招工招聘 - 获取推荐职位
  3069. * @param array $data
  3070. * @return array
  3071. */
  3072. public function getWebsiteLevelJob(array $data): array
  3073. {
  3074. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3075. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3076. ->where('job_recruiting.status', 1)
  3077. ->where('job_level', $data['job_level'])
  3078. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3079. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3080. ->orderBy('job_recruiting.updated_at', 'desc')
  3081. ->limit($data['pageSize'])
  3082. ->get();
  3083. $web = ['website_id' => $data['website_id']];
  3084. if (!empty($job)) {
  3085. $result = $this->processJob($job, $web);
  3086. }
  3087. if (empty($result)) {
  3088. return Result::error("暂无相关职位信息", 0);
  3089. }
  3090. return Result::success($result);
  3091. }
  3092. /**
  3093. * 验证导航名称是否重复
  3094. * @return void
  3095. */
  3096. //20250226 产品列表
  3097. public function getGoodList(array $data): array
  3098. {
  3099. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3100. unset($data['type_id']);
  3101. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3102. $where = [];
  3103. if ($type_id != '10000') {
  3104. $where = [
  3105. 'good.user_id' => $user_id,
  3106. ];
  3107. }
  3108. //类型
  3109. if (isset($data['type_id']) && $data['type_id']) {
  3110. $where = [
  3111. 'type_id' => $data['type_id'],
  3112. ];
  3113. }
  3114. //名称
  3115. if (isset($data['name']) && $data['name']) {
  3116. $where = [
  3117. 'good.name' => $data['name'],
  3118. ];
  3119. }
  3120. //status
  3121. if (isset($data['status']) && $data['status'] != '') {
  3122. $where = [
  3123. 'good.status' => $data['status'],
  3124. ];
  3125. }
  3126. //status1
  3127. // if (isset($data['status1']) && $data['status1'] == 1) {
  3128. // $status1 = 1;
  3129. // }
  3130. $where1 = [];
  3131. //website_id
  3132. // if (isset($data['website_id']) && $data['website_id']) {
  3133. // $where1 = [
  3134. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3135. // ];
  3136. // }
  3137. // website_name
  3138. if (isset($data['website_name']) && $data['website_name']) {
  3139. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3140. }
  3141. // catid
  3142. if (isset($data['category_name']) && $data['category_name']) {
  3143. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3144. }
  3145. // $result = Good::where($where)
  3146. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3147. $result = Good::where($where)
  3148. ->when(!empty($where1), function ($query) use ($where1) {
  3149. return $query->where($where1);
  3150. })
  3151. //status 1待审核2已审核3已拒绝
  3152. ->when(isset($data['status1']), function ($query) {
  3153. return $query->whereIn('good.status', [1, 3]);
  3154. })
  3155. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3156. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3157. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3158. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3159. ->orderBy("updated_at", "desc")
  3160. ->limit($data['page_size'])
  3161. ->offset(($data['page'] - 1) * $data['page_size'])
  3162. ->get();
  3163. $count = Good::where($where)
  3164. ->when(!empty($where1), function ($query) use ($where1) {
  3165. return $query->where($where1);
  3166. })
  3167. //status 1待审核2已审核3已拒绝
  3168. ->when(isset($data['status1']), function ($query) {
  3169. return $query->whereIn('good.status', [1, 3]);
  3170. })
  3171. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3172. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3173. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3174. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3175. ->orderBy("updated_at", "desc")->count();
  3176. $data = [
  3177. 'rows' => $result->toArray(),
  3178. 'count' => $count,
  3179. ];
  3180. if (empty($result)) {
  3181. return Result::error("此栏目暂无相关产品", 0);
  3182. }
  3183. return Result::success($data);
  3184. }
  3185. public function getGoodInfo(array $data): array
  3186. {
  3187. $result = Good::where('id', $data['id'])->first();
  3188. if (empty($result)) {
  3189. return Result::error("此产品不存在", 0);
  3190. }
  3191. return Result::success($result);
  3192. }
  3193. public function addGood(array $data): array
  3194. {
  3195. // unset($data['city_arr_id']);
  3196. // unset($data['cat_arr_id']);
  3197. $data['city_id'] = end($data['city_arr_id']);
  3198. $data['catid'] = end($data['cat_arr_id']);
  3199. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3200. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3201. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3202. unset($data['imgUrl']); //大小写
  3203. if (isset($data['price']) && $data['price'] == '') {
  3204. $data['price'] = 0;
  3205. }
  3206. if ($data['imgurl'] == '') {
  3207. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3208. preg_match_all($reg, $data['detail'], $matches);
  3209. if (isset($matches[1][0])) {
  3210. //截取varchar240
  3211. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3212. }
  3213. }
  3214. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3215. //提取标题+内容中的关键词
  3216. $data['keyword'] = $data['name'];
  3217. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3218. Jieba::init(); // 初始化 jieba-php
  3219. Finalseg::init();
  3220. $segList = Jieba::cut($data['keyword']);
  3221. $segList1 = array_slice($segList, 0, 8);
  3222. $data['keyword'] = implode(',', $segList1);
  3223. }
  3224. if ($data['description'] == '') {
  3225. //提取内容中的描述
  3226. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3227. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3228. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3229. }
  3230. $result = Good::insert($data);
  3231. if (empty($result)) {
  3232. return Result::error("添加失败", 0);
  3233. }
  3234. return Result::success($result);
  3235. }
  3236. public function updateGood(array $data): array
  3237. {
  3238. $data['city_id'] = end($data['city_arr_id']);
  3239. $data['catid'] = end($data['cat_arr_id']);
  3240. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3241. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3242. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3243. //设置东八区
  3244. date_default_timezone_set('Asia/Shanghai');
  3245. $data['updated_at'] = date('Y-m-d H:i:s');
  3246. if (isset($data['price']) && $data['price'] == '') {
  3247. $data['price'] = 0;
  3248. }
  3249. if ($data['imgurl'] == '') {
  3250. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3251. preg_match_all($reg, $data['detail'], $matches);
  3252. if (isset($matches[1][0])) {
  3253. //截取varchar240
  3254. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3255. }
  3256. }
  3257. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3258. //提取标题+内容中的关键词
  3259. $data['keyword'] = $data['name'];
  3260. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3261. Jieba::init(); // 初始化 jieba-php
  3262. Finalseg::init();
  3263. $segList = Jieba::cut($data['keyword']);
  3264. $segList1 = array_slice($segList, 0, 8);
  3265. $data['keyword'] = implode(',', $segList1);
  3266. }
  3267. if ($data['description'] == '') {
  3268. //提取内容中的描述
  3269. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3270. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3271. }
  3272. $result = Good::where('id', $data['id'])->update($data);
  3273. if (empty($result)) {
  3274. return Result::error("更新失败", 0);
  3275. }
  3276. return Result::success($result);
  3277. }
  3278. public function delGood(array $data): array
  3279. {
  3280. $result = Good::where('id', $data['id'])->delete();
  3281. if (empty($result)) {
  3282. return Result::error("删除失败", 0);
  3283. }
  3284. return Result::success($result);
  3285. }
  3286. //20250226 产品列表
  3287. //20250306 求职信息
  3288. public function getJobHuntingList(array $data): array
  3289. {
  3290. $where = [];
  3291. if (isset($data['username']) && !empty($data['username'])) {
  3292. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3293. }
  3294. //status 1待审核2已审核3已拒绝
  3295. if (isset($data['status']) && $data['status'] != '') {
  3296. $where = [
  3297. 'job_hunting.status' => $data['status'],
  3298. ];
  3299. }
  3300. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3301. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3302. unset($data['type_id']);
  3303. if ($type_id != '10000') {
  3304. $where[] = ['job_hunting.user_id', '=', $user_id];
  3305. }
  3306. $result = JobHunting::where($where)
  3307. ->when(!empty($data['status1']), function ($query) use ($data) {
  3308. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3309. })
  3310. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3311. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3312. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3313. ->orderBy("updated_at", "desc")
  3314. ->limit($data['page_size'])
  3315. ->offset(($data['page'] - 1) * $data['page_size'])
  3316. ->get();
  3317. if (empty($result)) {
  3318. return Result::error("查询失败", 0);
  3319. }
  3320. $count = JobHunting::where($where)
  3321. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3322. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3323. ->count();
  3324. $data = [
  3325. 'rows' => $result->toArray(),
  3326. 'count' => $count,
  3327. ];
  3328. return Result::success($data);
  3329. }
  3330. public function getJobHuntingApply(array $data): array
  3331. {
  3332. var_dump($data, '-----------------test--------1-');
  3333. $where = [];
  3334. if (isset($data['username']) && !empty($data['username'])) {
  3335. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3336. }
  3337. if (isset($data['salary']) && !empty($data['salary'])) {
  3338. $where[] = [
  3339. 'job_hunting.salary',
  3340. '=',
  3341. $data['salary'],
  3342. ];
  3343. }
  3344. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3345. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3346. unset($data['type_id']);
  3347. if ($type_id != '10000') {
  3348. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3349. }
  3350. var_dump($where, '-----------------test---------');
  3351. $result = jobApply::where($where)
  3352. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3353. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3354. // })
  3355. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3356. ->where('job_enum.egroup', '=', 'income')
  3357. ->where('job_hunting.status', 2) //已审核
  3358. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3359. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3360. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3361. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3362. //职位----是申请职位
  3363. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3364. ->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')
  3365. ->orderBy("job_hunting.updated_at", "desc")
  3366. ->limit($data['page_size'])
  3367. ->offset(($data['page'] - 1) * $data['page_size'])
  3368. ->get();
  3369. if (empty($result)) {
  3370. return Result::error("查询失败", 0);
  3371. }
  3372. $count = jobApply::where($where)
  3373. ->where('job_enum.egroup', '=', 'income')
  3374. ->where('job_hunting.status', 2) //已审核
  3375. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3376. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3377. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3378. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3379. //职位----是申请职位
  3380. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3381. ->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')
  3382. ->count();
  3383. $data = [
  3384. 'rows' => $result->toArray(),
  3385. 'count' => $count,
  3386. ];
  3387. return Result::success($data);
  3388. }
  3389. public function addJobHunting(array $data): array
  3390. {
  3391. date_default_timezone_set('Asia/Shanghai');
  3392. unset($data['company_name']);
  3393. unset($data['job_industry']);
  3394. unset($data['job_name']);
  3395. unset($data['department']);
  3396. unset($data['job_timeList']);
  3397. unset($data['job_content']);
  3398. unset($data['job_typename']); //不知道这是啥,
  3399. $data['created_at'] = date('Y-m-d H:i:s');
  3400. $data['updated_at'] = date('Y-m-d H:i:s');
  3401. //根据用户 user_id 只能添加一次
  3402. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3403. if (!empty($result)) {
  3404. return Result::error("您已添加过求职信息", 0);
  3405. }
  3406. var_dump($result, '-----------------test---------');
  3407. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3408. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3409. $cityArr = json_decode($data['city_arr_id'], true);
  3410. $data['city_id'] = end($cityArr);
  3411. } else {
  3412. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3413. $data['city_id'] = end($data['city_arr_id']);
  3414. }
  3415. $result = JobHunting::create($data);
  3416. if (empty($result)) {
  3417. return Result::error("添加失败", 0);
  3418. }
  3419. return Result::success($result);
  3420. }
  3421. public function delJobHunting(array $data): array
  3422. {
  3423. $result = JobHunting::where('id', $data['id'])->delete();
  3424. if (empty($result)) {
  3425. return Result::error("删除失败", 0);
  3426. }
  3427. return Result::success($result);
  3428. }
  3429. public function updateJobHunting(array $data): array
  3430. {
  3431. //设置东八区
  3432. date_default_timezone_set('Asia/Shanghai');
  3433. unset($data['company_name']);
  3434. unset($data['job_industry']);
  3435. unset($data['job_name']);
  3436. unset($data['department']);
  3437. unset($data['job_timeList']);
  3438. unset($data['job_content']);
  3439. unset($data['job_typename']); //不知道这是啥,
  3440. $data['created_at'] = date('Y-m-d H:i:s');
  3441. $data['updated_at'] = date('Y-m-d H:i:s');
  3442. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3443. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3444. $cityArr = json_decode($data['city_arr_id'], true);
  3445. $data['city_id'] = end($cityArr);
  3446. } else {
  3447. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3448. $data['city_id'] = end($data['city_arr_id']);
  3449. }
  3450. $result = JobHunting::where('id', $data['id'])->update($data);
  3451. if (empty($result)) {
  3452. return Result::error("更新失败", 0);
  3453. }
  3454. return Result::success($result);
  3455. }
  3456. public function getJobHuntingInfo(array $data): array
  3457. {
  3458. $result = JobHunting::where('id', $data['id'])->first();
  3459. if (empty($result)) {
  3460. return Result::error("查询失败", 0);
  3461. }
  3462. return Result::success($result);
  3463. }
  3464. public function getJobHuntingData(array $data): array
  3465. {
  3466. $jobEnum = JobEnum::get();
  3467. $jobIndustry = JobIndustry::get();
  3468. $jobNature = JobNature::get();
  3469. $jobPosition = JobPosition::get();
  3470. $data = [
  3471. 'jobEnum' => $jobEnum,
  3472. 'jobIndustry' => $jobIndustry,
  3473. 'jobNature' => $jobNature,
  3474. 'jobPosition' => $jobPosition,
  3475. ];
  3476. return Result::success($data);
  3477. }
  3478. public function delJobHuntingInfo(array $data): array
  3479. {
  3480. $result = JobHunting::where('id', $data['id'])->delete();
  3481. return Result::success();
  3482. }
  3483. //20250324 通知,公告,消息
  3484. public function delNotice(array $data): array
  3485. {
  3486. $result = Notice::where('id', $data['id'])->delete();
  3487. if ($result) {
  3488. return Result::success();
  3489. } else {
  3490. return Result::error("删除失败", 0);
  3491. }
  3492. }
  3493. public function getNoticeInfo(array $data): array
  3494. {
  3495. $result = Notice::where('id', $data['id'])->first();
  3496. if (empty($result)) {
  3497. return Result::error("查询失败", 0);
  3498. }
  3499. return Result::success($result);
  3500. }
  3501. public function addNotice(array $data): array
  3502. {
  3503. date_default_timezone_set('Asia/Shanghai');
  3504. $data['created_at'] = date('Y-m-d H:i:s');
  3505. $data['updated_at'] = date('Y-m-d H:i:s');
  3506. $user_id = UserInfo::
  3507. //city_id不是null
  3508. whereNotNull('city_id')
  3509. ->whereNotNull('department_id')
  3510. ->where(function ($query) use ($data) {
  3511. $query->where(function ($subQuery) use ($data) {
  3512. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3513. });
  3514. })
  3515. ->where(function ($query) use ($data) {
  3516. $query->where(function ($subQuery) use ($data) {
  3517. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3518. });
  3519. })
  3520. ->pluck('user_id')->toArray();
  3521. $user_id = array_unique($user_id);
  3522. $chat_ids = $user_id;
  3523. $user_id = json_encode($user_id);
  3524. $data['re_user_ids'] = $user_id;
  3525. $result = Notice::insertGetId($data);
  3526. if ($result && $data['is_group'] == 1) {
  3527. //chat_group
  3528. $group_id = PublicData::uuid();
  3529. $groupData = [
  3530. 'id' => $group_id,
  3531. 'creator_id' => $data['user_id'],
  3532. 'group_name' => $data['group_name'] ?? '',
  3533. 'profile' => $data['profile'] ?? 0,
  3534. ];
  3535. var_dump($groupData, '-----------------groupData-------');
  3536. $groupResult = ChatGroups::insertGetId($groupData);
  3537. var_dump($groupResult, '-----------------groupid-------');
  3538. $groupMemberData = [
  3539. 'id' => PublicData::uuid(),
  3540. 'user_id' => $data['user_id'],
  3541. 'group_id' => $group_id,
  3542. 'leader' => 2,
  3543. ];
  3544. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  3545. //$chat_ids 去除掉$data['user_id']
  3546. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  3547. //插入群成员表
  3548. $groupMemberDataUser = [];
  3549. $chatData = [];
  3550. foreach ($chat_ids as $key => $value) {
  3551. $groupMemberDataUser[] = [
  3552. 'id' => PublicData::uuid(),
  3553. 'user_id' => $value,
  3554. 'group_id' => $group_id,
  3555. 'leader' => 1,
  3556. ];
  3557. $chatData[] = [
  3558. 'user_id' => $value,
  3559. 'msg_type' => 1,
  3560. 'receiver_id' => $group_id,
  3561. 'content' => '通过通知创建群聊',
  3562. 'group_receiver_id' => $data['user_id'],
  3563. 'action' => 'recieved',
  3564. 'created_at' => date('Y-m-d H:i:s'),
  3565. ];
  3566. }
  3567. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  3568. ChatGroupsMember::insert($groupMemberDataUser);
  3569. //插入一条管理员聊天记录
  3570. $chatData[] = [
  3571. 'user_id' => $data['user_id'],
  3572. 'msg_type' => 1,
  3573. 'receiver_id' => $group_id,
  3574. 'content' => '通过通知创建群聊',
  3575. 'group_receiver_id' => $data['user_id'],
  3576. 'action' => 'said',
  3577. 'created_at' => date('Y-m-d H:i:s'),
  3578. ];
  3579. var_dump($chatData, '-----------------chatData-------');
  3580. $chatResult = ChatRecords::insert($chatData);
  3581. //更新result的 group_id
  3582. $data['group_id'] = $group_id;
  3583. Notice::where(['id' => $result])->update($data);
  3584. }
  3585. if (empty($result)) {
  3586. return Result::error("添加失败", 0);
  3587. }
  3588. return Result::success($result);
  3589. }
  3590. public function updateNotice(array $data): array
  3591. {
  3592. date_default_timezone_set('Asia/Shanghai');
  3593. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  3594. $user_id = UserInfo::
  3595. //city_id不是null
  3596. whereNotNull('city_id')
  3597. ->whereNotNull('department_id')
  3598. ->where(function ($query) use ($data) {
  3599. $query->where(function ($subQuery) use ($data) {
  3600. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3601. });
  3602. })
  3603. ->where(function ($query) use ($data) {
  3604. $query->where(function ($subQuery) use ($data) {
  3605. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3606. });
  3607. })
  3608. ->pluck('user_id')->toArray();
  3609. $user_id = array_unique($user_id);
  3610. $user_id = json_encode($user_id);
  3611. $data['re_user_ids'] = $user_id;
  3612. $data['updated_at'] = date('Y-m-d H:i:s');
  3613. $result = Notice::where('id', $data['id'])->update($data);
  3614. return Result::success($result);
  3615. }
  3616. public function getNoticeList(array $data): array
  3617. {
  3618. $where = [];
  3619. //title
  3620. if (isset($data['title']) && !empty($data['title'])) {
  3621. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  3622. }
  3623. //level
  3624. if (isset($data['level']) && !empty($data['level'])) {
  3625. $where[] = ['notice.level', '=', $data['level']];
  3626. }
  3627. //status
  3628. if (isset($data['status']) && !empty($data['status'])) {
  3629. $where[] = ['notice.status', '=', $data['status']];
  3630. }
  3631. var_dump($data, '------------11111-2----test---------');
  3632. if ($data['type_id'] == 10000) {
  3633. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3634. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3635. })
  3636. ->where($where)
  3637. ->orderBy('updated_at', 'desc')
  3638. ->limit($data['page_size'])
  3639. ->offset(($data['page'] - 1) * $data['page_size'])
  3640. ->get();
  3641. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3642. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3643. })
  3644. ->where($where)
  3645. ->orderBy('updated_at', 'desc')
  3646. ->count();
  3647. } else {
  3648. $result = Notice::where($where)
  3649. // ->where('user_id', $data['user_id'])
  3650. ->Where(function ($query) use ($data) {
  3651. $query->Where(function ($q) use ($data) {
  3652. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3653. ->orWhere('notice.user_id', $data['user_id']);
  3654. });
  3655. })
  3656. ->when(!empty($data['status1']), function ($query) use ($data) {
  3657. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3658. })
  3659. ->orderBy('updated_at', 'desc')
  3660. ->limit($data['page_size'])
  3661. ->offset(($data['page'] - 1) * $data['page_size'])
  3662. ->get();
  3663. $total = Notice::where($where)
  3664. ->when(!empty($data['status1']), function ($query) use ($data) {
  3665. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3666. })
  3667. // ->where('user_id', $data['user_id'])
  3668. ->Where(function ($query) use ($data) {
  3669. $query->Where(function ($q) use ($data) {
  3670. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3671. ->orWhere('notice.user_id', $data['user_id']);
  3672. });
  3673. })
  3674. ->count();
  3675. }
  3676. if (empty($result)) {
  3677. return Result::error("查询失败", 0);
  3678. }
  3679. $data = [
  3680. 'rows' => $result,
  3681. 'count' => $total,
  3682. ];
  3683. return Result::success($data);
  3684. }
  3685. public function getNoticeDetail(array $data): array
  3686. {
  3687. $result = Notice::where('id', $data['id'])->first();
  3688. if (empty($result)) {
  3689. return Result::error("查询失败", 0);
  3690. }
  3691. return Result::success($result);
  3692. }
  3693. public function deleteNotice(array $data): array
  3694. {
  3695. $notice = Notice::where('id', $data['id'])->first();
  3696. if (empty($notice)) {
  3697. return Result::error("删除失败", 0);
  3698. }
  3699. $chat_group_id = $notice->group_id;
  3700. if ($chat_group_id) {
  3701. //删除群聊
  3702. ChatGroups::where('id', $chat_group_id)->delete();
  3703. //删除群成员
  3704. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  3705. //删除群聊记录
  3706. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  3707. }
  3708. $result = Notice::where('id', $data['id'])->delete();
  3709. return Result::success($result);
  3710. }
  3711. public function getMSG(array $data): array
  3712. {
  3713. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  3714. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3715. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  3716. $result = [];
  3717. if ($type_id == 1) {
  3718. //最近的5篇已审的文章
  3719. $apply_articale = Article::where('status', 1)
  3720. ->where('admin_user_id', $user_id)
  3721. ->orderBy('updated_at', 'desc')
  3722. ->limit(5)->get();
  3723. //获取5条单聊未读聊天消息
  3724. $chat = ChatRecords::where('is_read', 0)
  3725. ->where('user_id', $user_id)
  3726. ->where('talk_type', 1)
  3727. ->orderBy('created_at', 'desc')
  3728. ->limit(5)->get();
  3729. //获取5条未读群聊信息
  3730. $chat_group = ChatRecords::where('is_read', 0)
  3731. ->where('user_id', $user_id)
  3732. ->where('talk_type', 2)
  3733. ->orderBy('created_at', 'desc')
  3734. ->limit(5)->get();
  3735. //获取5条用户的已审核商品
  3736. $good = Good::where('status', 2)
  3737. ->where('user_id', $user_id)
  3738. ->orderBy('updated_at', 'desc')
  3739. ->limit(5)->get();
  3740. //获取5条用户待审核的公告
  3741. $notice = Notice::where('status', 2)
  3742. ->where('user_id', $user_id)
  3743. ->orderBy('updated_at', 'desc')
  3744. ->limit(5)->get();
  3745. //获取5条用户的待审核投诉
  3746. $complaint = Complaint::where('status', 2)
  3747. ->where('user_id', $user_id)
  3748. ->orderBy('updated_at', 'desc')
  3749. ->limit(5)->get();
  3750. //获取5条用户的book
  3751. $book = Book::where('status', 2)
  3752. ->where('user_id', $user_id)
  3753. ->orderBy('updated_at', 'desc')
  3754. ->limit(5)->get();
  3755. //获取5条用户的求职
  3756. //获取5条用户的求职 1
  3757. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3758. ->where('job_hunting.user_id', $user_id)
  3759. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3760. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3761. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3762. ->orderBy('updated_at', 'desc')
  3763. ->limit(5)->get();
  3764. //获取5条用户的求职 2
  3765. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3766. ->where('job_recruiting.user_id', $user_id)
  3767. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3768. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3769. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3770. ->orderBy('updated_at', 'desc')
  3771. ->limit(5)->get();
  3772. //人才库 1
  3773. $job_apply = JobApply::where('job_apply.status', 1)
  3774. ->where('job_apply.receiver_id', $user_id)
  3775. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3776. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3777. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3778. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3779. ->select('job_recruiting', 'job_recruiting.', '', '')
  3780. ->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')
  3781. ->orderBy('updated_at', 'desc')
  3782. ->limit(5)->get();
  3783. // 职场机会 2
  3784. $job_resume = JobResume::where('job_resume.status', 1)
  3785. ->where('job_resume.receiver_id', $user_id)
  3786. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3787. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3788. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3789. ->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')
  3790. ->orderBy('updated_at', 'desc')
  3791. ->limit(5)->get();
  3792. // count($chat) + count($chat_group) +
  3793. $count = count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  3794. $result = [
  3795. 'apply_articale' => $apply_articale,
  3796. 'chat' => $chat,
  3797. 'chat_group' => $chat_group,
  3798. 'good' => $good,
  3799. 'notice' => $notice,
  3800. 'complaint' => $complaint,
  3801. 'book' => $book,
  3802. 'job_hunting' => $job_hunting,
  3803. 'job_recruiting' => $job_recruiting,
  3804. 'job_apply' => $job_apply,
  3805. 'job_resume' => $job_resume,
  3806. 'count' => $count,
  3807. ];
  3808. } elseif ($type_id == 2) {
  3809. //最近的5篇已审的文章
  3810. $apply_articale = Article::where('status', 1)
  3811. ->where('admin_user_id', $user_id)
  3812. ->limit(5)->get();
  3813. //获取5条单聊未读聊天消息
  3814. $chat = ChatRecords::where('is_read', 0)
  3815. ->where('user_id', $user_id)
  3816. ->where('talk_type', 1)
  3817. ->orderBy('created_at', 'desc')
  3818. ->limit(5)->get();
  3819. //获取5条未读群聊信息
  3820. $chat_group = ChatRecords::where('is_read', 0)
  3821. ->where('user_id', $user_id)
  3822. ->where('talk_type', 2)
  3823. ->orderBy('created_at', 'desc')
  3824. ->limit(5)->get();
  3825. //获取5条用户的已审核商品
  3826. $good = Good::where('status', 2)
  3827. ->where('user_id', $user_id)
  3828. ->orderBy('updated_at', 'desc')
  3829. ->limit(5)->get();
  3830. //count($chat) + count($chat_group)
  3831. $count = count($apply_articale) + count($good);
  3832. $result = [
  3833. 'apply_articale' => $apply_articale,
  3834. 'chat' => $chat,
  3835. 'chat_group' => $chat_group,
  3836. 'good' => $good,
  3837. 'count' => $count,
  3838. ];
  3839. } elseif ($type_id == 3) {
  3840. //最近的5篇已审的文章
  3841. $apply_articale = Article::where('status', 1)
  3842. ->where('admin_user_id', $user_id)
  3843. ->limit(5)->get();
  3844. //获取5条单聊未读聊天消息
  3845. $chat = ChatRecords::where('is_read', 0)
  3846. ->where('user_id', $user_id)
  3847. ->where('talk_type', 1)
  3848. ->orderBy('created_at', 'desc')
  3849. ->limit(5)->get();
  3850. //获取5条未读群聊信息
  3851. $chat_group = ChatRecords::where('is_read', 0)
  3852. ->where('user_id', $user_id)
  3853. ->where('talk_type', 2)
  3854. ->orderBy('created_at', 'desc')
  3855. ->limit(5)->get();
  3856. //获取5条用户的已审核商品
  3857. $good = Good::where('status', 2)
  3858. ->where('user_id', $user_id)
  3859. ->orderBy('updated_at', 'desc')
  3860. ->limit(5)->get();
  3861. //count($chat) + count($chat_group) +
  3862. $count = count($apply_articale) + count($good);
  3863. $result = [
  3864. 'apply_articale' => $apply_articale,
  3865. 'chat' => $chat,
  3866. 'chat_group' => $chat_group,
  3867. 'good' => $good,
  3868. 'count' => $count,
  3869. ];
  3870. } elseif ($type_id == 4) {
  3871. //最近的5篇已审的文章
  3872. $apply_articale = Article::where('status', 1)
  3873. ->where('admin_user_id', $user_id)
  3874. ->limit(5)->get();
  3875. //获取5条用户的已审核商品
  3876. $good = Good::where('status', 2)
  3877. ->where('user_id', $user_id)
  3878. ->orderBy('updated_at', 'desc')
  3879. ->limit(5)->get();
  3880. $count = count($apply_articale) + count($good);
  3881. $result = [
  3882. 'apply_articale' => $apply_articale,
  3883. 'chat' => '',
  3884. 'chat_group' => '',
  3885. 'good' => $good,
  3886. 'count' => $count,
  3887. ];
  3888. } elseif ($type_id == 10000) {
  3889. //获取未审核的5篇文章
  3890. $apply_articale = Article::where('status', 0)
  3891. ->orderBy('updated_at', 'desc')
  3892. ->limit(5)->get();
  3893. //获取5条单聊未读聊天消息
  3894. $chat = ChatRecords::where('is_read', 0)
  3895. ->where('user_id', $user_id)
  3896. ->where('talk_type', 1)
  3897. ->orderBy('created_at', 'desc')
  3898. ->limit(5)->get();
  3899. //获取5条未读群聊信息
  3900. $chat_group = ChatRecords::where('is_read', 0)
  3901. ->where('user_id', $user_id)
  3902. ->where('talk_type', 2)
  3903. ->orderBy('created_at', 'desc')
  3904. ->limit(5)->get();
  3905. //获取5条用户的已审核商品
  3906. $good = Good::where('status', 1)
  3907. // ->where('user_id', $user_id)
  3908. ->orderBy('updated_at', 'desc')
  3909. ->limit(5)->get();
  3910. //获取5条用户待审核的公告
  3911. $notice = Notice::where('status', 1)
  3912. ->orderBy('updated_at', 'desc')
  3913. ->limit(5)->get();
  3914. //获取5条用户的待审核投诉
  3915. $complaint = Complaint::where('status', 1)
  3916. ->orderBy('updated_at', 'desc')
  3917. ->limit(5)->get();
  3918. //获取5条用户的book
  3919. $book = Book::where('status', 1)
  3920. ->orderBy('updated_at', 'desc')
  3921. ->limit(5)->get();
  3922. //获取5条用户的求职 1
  3923. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3924. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3925. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3926. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3927. ->orderBy('updated_at', 'desc')
  3928. ->limit(5)->get();
  3929. //获取5条用户的求职 2
  3930. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3931. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3932. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3933. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3934. ->orderBy('updated_at', 'desc')
  3935. ->limit(5)->get();
  3936. //人才库 1
  3937. $job_apply = JobApply::where('job_apply.status', 1)
  3938. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3939. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3940. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3941. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3942. ->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')
  3943. ->orderBy('updated_at', 'desc')
  3944. ->limit(5)->get();
  3945. // 职场机会 2
  3946. $job_resume = JobResume::where('job_resume.status', 1)
  3947. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3948. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3949. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3950. ->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')
  3951. ->orderBy('updated_at', 'desc')
  3952. ->limit(5)->get();
  3953. $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);
  3954. $result = [
  3955. 'apply_articale' => $apply_articale,
  3956. 'chat' => $chat,
  3957. 'chat_group' => $chat_group,
  3958. 'good' => $good,
  3959. 'notice' => $notice,
  3960. 'complaint' => $complaint,
  3961. 'book' => $book,
  3962. 'job_hunting' => $job_hunting,
  3963. 'job_recruiting' => $job_recruiting,
  3964. 'job_apply' => $job_apply,
  3965. 'job_resume' => $job_resume,
  3966. 'count' => $count,
  3967. ];
  3968. } elseif ($type_id == 20000) {
  3969. }
  3970. var_dump($type_id, '-----------------test---------');
  3971. return Result::success($result);
  3972. }
  3973. public function getComplaintList(array $data): array
  3974. {
  3975. var_dump($data, '00000001000000000000');
  3976. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3977. unset($data['type_id']);
  3978. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3979. $where = [];
  3980. if ($type_id != 10000 && empty($data['deal_user'])) {
  3981. $where['complaint.user_id'] = $user_id;
  3982. }
  3983. if (!empty($data['title'])) {
  3984. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  3985. }
  3986. if (!empty($data['department_id'])) {
  3987. $where['complaint.department_id'] = $data['department_id'];
  3988. }
  3989. if (!empty($data['deal'])) {
  3990. $where['complaint.deal'] = $data['deal'];
  3991. }
  3992. if (!empty($data['status'])) {
  3993. $where['complaint.status'] = $data['status'];
  3994. }
  3995. var_dump(!empty($data['deal_user']), '----------1');
  3996. var_dump($where, '----------2');
  3997. $result = Complaint::where($where)
  3998. ->when(!empty($data['status1']), function ($query) use ($data) {
  3999. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4000. })
  4001. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4002. //json re_user_ids data[user_id]是不是在里面
  4003. $query->Where(function ($q) use ($data) {
  4004. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4005. ->where('complaint.status', 2);
  4006. });
  4007. })
  4008. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4009. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4010. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4011. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4012. ->orderBy('updated_at', 'desc')
  4013. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4014. //sql输出
  4015. if (empty($result)) {
  4016. return Result::error("暂无投诉信息", 0);
  4017. }
  4018. // 取出数据
  4019. $rows = $result->items();
  4020. $count = $result->total();
  4021. $responseData = [
  4022. 'rows' => $rows,
  4023. 'count' => $count,
  4024. ];
  4025. return Result::success($responseData);
  4026. }
  4027. public function getComplaintInfo(array $data): array
  4028. {
  4029. $result = Complaint::where('id', $data['id'])->first();
  4030. if (empty($result)) {
  4031. return Result::error("查询失败", 0);
  4032. }
  4033. return Result::success($result);
  4034. }
  4035. public function addComplaint(array $data): array
  4036. {
  4037. date_default_timezone_set('Asia/Shanghai');
  4038. $data['created_at'] = date('Y-m-d H:i:s');
  4039. $data['updated_at'] = date('Y-m-d H:i:s');
  4040. $result = Complaint::create($data);
  4041. return Result::success($result);
  4042. }
  4043. public function updateComplaint(array $data): array
  4044. {
  4045. date_default_timezone_set('Asia/Shanghai');
  4046. $data['updated_at'] = date('Y-m-d H:i:s');
  4047. $user_id = $data['user_id'] ?? 0;
  4048. $type_id = $data['type_id'] ?? 0;
  4049. unset($data['user_id']);
  4050. unset($data['type_id']);
  4051. $result = Complaint::where('id', $data['id'])->update($data);
  4052. return Result::success($result);
  4053. }
  4054. public function deleteComplaint(array $data): array
  4055. {
  4056. $result = Complaint::where('id', $data['id'])->delete();
  4057. return Result::success($result);
  4058. }
  4059. public function getComplainInfo(array $data): array
  4060. {
  4061. $result = Complaint::where('id', $data['id'])->first();
  4062. if (empty($result)) {
  4063. return Result::error("查询失败", 0);
  4064. }
  4065. return Result::success($result);
  4066. }
  4067. public function updateComplaintStatus(array $data): array
  4068. {
  4069. date_default_timezone_set('Asia/Shanghai');
  4070. $data['updated_at'] = date('Y-m-d H:i:s');
  4071. $user_id = $data['user_id'] ?? 0;
  4072. $type_id = $data['type_id'] ?? 0;
  4073. unset($data['user_id']);
  4074. unset($data['type_id']);
  4075. //处理, 写入处理人
  4076. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4077. $data['real_deal_user'] = $user_id;
  4078. }
  4079. //如果是deal 23,则判断是不是处理人
  4080. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4081. $complaintInof = Complaint::where('id', $data['id'])
  4082. ->where('real_deal_user', $user_id)
  4083. ->first();
  4084. if (empty($complaintInof)) {
  4085. return Result::error("处理人错误", 0);
  4086. }
  4087. }
  4088. $result = complaint::where('id', $data['id'])->update($data);
  4089. return Result::success($result);
  4090. }
  4091. public function updateGoodStatus(array $data): array
  4092. {
  4093. $user_id = $data['user_id'] ?? 0;
  4094. $type_id = $data['type_id'] ?? 0;
  4095. unset($data['user_id']);
  4096. unset($data['type_id']);
  4097. $result = Good::where('id', $data['id'])->update($data);
  4098. return Result::success($result);
  4099. }
  4100. public function updateJobHuntingStatus(array $data): array
  4101. {
  4102. $user_id = $data['user_id'] ?? 0;
  4103. $type_id = $data['type_id'] ?? 0;
  4104. unset($data['user_id']);
  4105. unset($data['type_id']);
  4106. $result = JobHunting::where('id', $data['id'])->update($data);
  4107. return Result::success($result);
  4108. }
  4109. public function updateNoticeStatus(array $data): array
  4110. {
  4111. $user_id = $data['user_id'] ?? 0;
  4112. $type_id = $data['type_id'] ?? 0;
  4113. unset($data['user_id']);
  4114. unset($data['type_id']);
  4115. $result = Notice::where('id', $data['id'])->update($data);
  4116. return Result::success($result);
  4117. }
  4118. public function getDUser(array $data): array
  4119. {
  4120. if (!empty($data['ids'])) {
  4121. $user = User::whereIn('id', $data['ids'])->getall();
  4122. if (empty($user)) {
  4123. return Result::error('无数据', 0);
  4124. }
  4125. return Result::success($user);
  4126. }
  4127. $where = [];
  4128. if (!empty($data['department_id'])) {
  4129. $where['department_id'] = $data['department_id'];
  4130. }
  4131. if (!empty($data['city_id'])) {
  4132. $where['city_id'] = $data['city_id'];
  4133. }
  4134. $result = User::where('type_id', 2)
  4135. ->where('status', 1)
  4136. ->where($where)
  4137. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4138. ->get();
  4139. if (empty($result)) {
  4140. return Result::error("查询失败", 0);
  4141. }
  4142. return Result::success($result);
  4143. }
  4144. /**
  4145. * 验证导航名称是否重复
  4146. * @return void
  4147. */
  4148. public function checkCategoryName(array $data): array
  4149. {
  4150. $result = Category::when($data, function ($query) use ($data) {
  4151. if (isset($data['name']) && $data['name']) {
  4152. $query->where("name", $data['name']);
  4153. }
  4154. if (isset($data['id']) && $data['id']) {
  4155. $query->where("id", "!=", $data['id']);
  4156. }
  4157. })->first();
  4158. if ($result) {
  4159. return Result::error("已存在");
  4160. } else {
  4161. return Result::success();
  4162. }
  4163. }
  4164. //20250226 产品列表
  4165. // 20250306 -------招聘--------fr
  4166. /*
  4167. * 招聘列表
  4168. * */
  4169. public function getJobRecruitingList(array $data): array
  4170. {
  4171. $where = [];
  4172. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4173. if ($data['checkout'] == 0) {
  4174. $job_status = [0, 2];
  4175. } else {
  4176. $job_status = [1];
  4177. }
  4178. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4179. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4180. }
  4181. $user = User::where('id', $data['user_id'])->first();
  4182. if (empty($user)) {
  4183. return Result::error("用户不存在", 0);
  4184. }
  4185. // 3:企业会员
  4186. if ($user['type_id'] == 3) {
  4187. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4188. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4189. }
  4190. // 如果 $where 为空,则不添加 where 条件
  4191. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4192. return $query->where($where);
  4193. })
  4194. ->whereIn('job_recruiting.status', $job_status)
  4195. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4196. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4197. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4198. ->orderBy("updated_at", "desc")
  4199. ->offset(($data['page'] - 1) * $data['page_size'])
  4200. ->limit($data['page_size'])
  4201. ->get()
  4202. ->all();
  4203. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4204. return $query->where($where);
  4205. })
  4206. ->whereIn('job_recruiting.status', $job_status)
  4207. ->count();
  4208. if (empty($result)) {
  4209. return Result::error("暂无招聘信息", 0);
  4210. }
  4211. return Result::success($result);
  4212. }
  4213. /*
  4214. * 招聘信息添加
  4215. * */
  4216. public function addJobRecruiting(array $data): array
  4217. {
  4218. // return Result::success($data);
  4219. $user = User::where('user.id', $data['user_id'])
  4220. ->where('user.status', 1)
  4221. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4222. ->select(
  4223. 'user.type_id',
  4224. 'user.mobile',
  4225. 'user.email',
  4226. 'user_info.business_name',
  4227. 'user_info.company_hy_id',
  4228. 'user_info.company_nature',
  4229. 'user_info.company_size',
  4230. 'user_info.introduction',
  4231. 'user_info.real_name',
  4232. 'user_info.company_url',
  4233. 'user_info.address_arr_id',
  4234. 'user_info.address'
  4235. )
  4236. ->first();
  4237. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4238. return Result::error("用户不存在", 0);
  4239. }
  4240. $web = Website::where('id', $data['website_id'])->first();
  4241. if (empty($web)) {
  4242. return Result::error("网站不存在", 0);
  4243. }
  4244. // return Result::success($user);
  4245. $data['action_id'] = $data['user_id'];
  4246. $data['user_type'] = $user['type_id'];
  4247. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4248. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4249. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4250. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4251. // 公司地址 管理员必填
  4252. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4253. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4254. // 管理员-企业相关信息
  4255. $company = [
  4256. // 'user_id' => $data['user_id']?? null,
  4257. 'business_name' => $data['business_name'] ?? null,
  4258. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4259. 'company_size' => $data['company_size'] ?? null,
  4260. 'company_nature' => $data['company_nature'] ?? null,
  4261. 'introduction' => $data['introduction'] ?? null,
  4262. 'real_name' => $data['real_name'] ?? null,
  4263. 'mobile' => $data['mobile'] ?? null,
  4264. 'company_url' => $data['company_url'] ?? null,
  4265. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4266. 'address' => $data['address'] ?? null,
  4267. 'email' => $data['email'] ?? null,
  4268. ];
  4269. //去掉相关企业信息
  4270. $job = array_diff_key($data, array_flip(array_keys($company)));
  4271. Db::beginTransaction();
  4272. try {
  4273. // 先添加职位相关信息
  4274. if ($user['type_id'] == 10000) {
  4275. $job['status'] = 1;
  4276. }
  4277. if (empty($data['experience']) || $data['experience'] == '') {
  4278. $job['experience'] = null;
  4279. } else {
  4280. $job['experience'] = $data['experience'];
  4281. }
  4282. $jobId = JobRecruiting::insertGetId($job);
  4283. if (empty($jobId)) {
  4284. Db::rollBack();
  4285. return Result::error("添加失败");
  4286. }
  4287. // 添加公司信息
  4288. $company['user_id'] = $data['user_id'] ?? null;
  4289. $company['job_id'] = $jobId;
  4290. $company['user_type'] = $user['type_id'] ?? null;
  4291. $company['website_id'] = $data['website_id'] ?? null;
  4292. if ($user['type_id'] == 10000) {
  4293. // 管理员添加企业信息
  4294. // return Result::success($company);
  4295. $companyId = JobCompany::insertGetId($company);
  4296. if (empty($companyId)) {
  4297. Db::rollBack();
  4298. return Result::error("添加失败");
  4299. }
  4300. } else {
  4301. // 企业会员添加企业信息
  4302. $company = [
  4303. 'user_id' => $data['user_id'] ?? null,
  4304. 'business_name' => $user['business_name'] ?? null,
  4305. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4306. 'company_size' => $user['company_size'] ?? null,
  4307. 'company_nature' => $user['company_nature'] ?? null,
  4308. 'introduction' => $user['introduction'] ?? null,
  4309. 'real_name' => $user['real_name'] ?? null,
  4310. 'mobile' => $user['mobile'] ?? null,
  4311. 'company_url' => $user['company_url'] ?? null,
  4312. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4313. 'address' => $user['address'] ?? null,
  4314. 'email' => $user['email'] ?? null,
  4315. 'website_id' => $data['website_id'] ?? null,
  4316. 'user_type' => $user['type_id'] ?? null,
  4317. 'job_id' => $jobId,
  4318. ];
  4319. $companyId = JobCompany::insertGetId($company);
  4320. if (empty($companyId)) {
  4321. Db::rollBack();
  4322. return Result::error("添加失败");
  4323. }
  4324. // return Result::success($company);
  4325. }
  4326. Db::commit();
  4327. } catch (\Exception $e) {
  4328. Db::rollBack();
  4329. return Result::error($e->getMessage(), 0);
  4330. }
  4331. $result = [
  4332. 'job_id' => $jobId,
  4333. 'company_id' => $companyId,
  4334. ];
  4335. if (empty($result)) {
  4336. return Result::error("添加失败", 0);
  4337. }
  4338. return Result::success($result);
  4339. }
  4340. /*
  4341. * 获取招聘信息详情
  4342. * */
  4343. public function getJobRecruitingInfo(array $data): array
  4344. {
  4345. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4346. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4347. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4348. ->select(
  4349. 'job_recruiting.*',
  4350. 'website.website_name as website_name',
  4351. 'job_company.business_name',
  4352. 'job_company.company_hy_id',
  4353. 'job_company.company_size',
  4354. 'job_company.company_nature',
  4355. 'job_company.introduction',
  4356. 'job_company.real_name',
  4357. 'job_company.mobile',
  4358. 'job_company.company_url',
  4359. 'job_company.address_arr_id',
  4360. 'job_company.address',
  4361. 'job_company.email'
  4362. )
  4363. ->first();
  4364. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4365. if (!empty($cityId)) {
  4366. if (isset($cityId[1]) && $cityId[1] != null) {
  4367. $city = District::where('id', $cityId[1])->first(['name']);
  4368. } else {
  4369. $city = District::where('id', $cityId[0])->first(['name']);
  4370. }
  4371. $result['city'] = $city['name'] ?? '';
  4372. }
  4373. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4374. if (is_array($addressId) && !empty($addressId)) {
  4375. $address = District::whereIn('id', $addressId)
  4376. ->orderBy('level', 'asc')
  4377. ->get(['name'])
  4378. ->pluck('name')
  4379. ->implode('');
  4380. // $job->address_name = $address ?? '';
  4381. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4382. }
  4383. if (empty($result)) {
  4384. return Result::error("招聘信息不存在", 0);
  4385. }
  4386. // return Result::success($job);
  4387. return Result::success($result);
  4388. }
  4389. /*
  4390. * 修改招聘信息
  4391. * */
  4392. public function upJobRecruiting(array $data): array
  4393. {
  4394. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4395. // return Result::success($job);
  4396. if (empty($job)) {
  4397. return Result::error("招聘信息不存在", 0);
  4398. }
  4399. $user = User::where('id', $data['user_id'])->first();
  4400. // return Result::success($user);
  4401. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4402. return Result::error("用户不存在", 0);
  4403. }
  4404. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4405. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4406. }
  4407. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4408. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4409. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4410. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4411. // 公司地址 管理员必填
  4412. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4413. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4414. // 管理员-企业相关信息
  4415. $company = [
  4416. 'business_name' => $data['business_name'] ?? null,
  4417. 'company_hy_id' => $data['hy_id'] ?? null,
  4418. 'company_size' => $data['company_size'] ?? null,
  4419. 'company_nature' => $data['company_nature'] ?? null,
  4420. 'introduction' => $data['introduction'] ?? null,
  4421. 'real_name' => $data['real_name'] ?? null,
  4422. 'mobile' => $data['mobile'] ?? null,
  4423. 'company_url' => $data['company_url'] ?? null,
  4424. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4425. 'address' => $data['address'] ?? null,
  4426. 'email' => $data['email'] ?? null,
  4427. ];
  4428. //去掉相关企业信息
  4429. $data = array_diff_key($data, array_flip(array_keys($company)));
  4430. $jobId = $data['id'];
  4431. $web = $data['website_id'];
  4432. $data['action_id'] = $data['user_id'];
  4433. unset($data['user_id']);
  4434. unset($data['user_type']);
  4435. unset($data['id']);
  4436. unset($data['website_id']);
  4437. // return Result::success($data);
  4438. Db::beginTransaction();
  4439. try {
  4440. // 管理员修改招聘信息
  4441. if ($user['type_id'] == 10000) {
  4442. $data['website_id'] = $web;
  4443. $company['website_id'] = $data['website_id'];
  4444. $data['status'] = 1;
  4445. } else {
  4446. $data['status'] = 0;
  4447. }
  4448. if (empty($data['experience']) || $data['experience'] == '') {
  4449. $job['experience'] = null;
  4450. } else {
  4451. $job['experience'] = $data['experience'];
  4452. }
  4453. // Db::rollBack();
  4454. // return Result::success($company);
  4455. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4456. if (empty($result['job'])) {
  4457. Db::rollBack();
  4458. return Result::error("修改招聘信息失败");
  4459. }
  4460. // 管理员修改企业相关信息
  4461. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4462. if (empty($result['company'])) {
  4463. Db::rollBack();
  4464. return Result::error("修改企业相关信息失败");
  4465. }
  4466. Db::commit();
  4467. // return Result::success($result);
  4468. } catch (\Exception $e) {
  4469. Db::rollBack();
  4470. return Result::error($e->getMessage(), 0);
  4471. }
  4472. return Result::success($result);
  4473. }
  4474. /*
  4475. * 招聘信息删除
  4476. * */
  4477. public function delJobRecruiting(array $data): array
  4478. {
  4479. $user = User::where('id', $data['user_id'])->first();
  4480. if (empty($user)) {
  4481. return Result::error("用户不存在", 0);
  4482. }
  4483. $job = JobRecruiting::where('id', $data['id'])->first();
  4484. if (empty($job)) {
  4485. return Result::error("招聘信息不存在", 0);
  4486. }
  4487. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4488. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4489. }
  4490. Db::beginTransaction();
  4491. try {
  4492. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4493. if (empty($result['job'])) {
  4494. Db::rollBack();
  4495. return Result::error("删除招聘信息失败");
  4496. }
  4497. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4498. if (empty($result['company'])) {
  4499. Db::rollBack();
  4500. return Result::error("删除企业相关信息失败");
  4501. }
  4502. Db::commit();
  4503. } catch (\Exception $e) {
  4504. Db::rollBack();
  4505. return Result::error($e->getMessage(), 0);
  4506. }
  4507. return Result::success($result);
  4508. }
  4509. /*
  4510. * 获取公司信息
  4511. * */
  4512. public function getJobCompany(array $data): array
  4513. {
  4514. $user = User::where('user.id', $data['user_id'])
  4515. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4516. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4517. ->first();
  4518. // return Result::success($user);
  4519. if (empty($user)) {
  4520. return Result::error("用户不存在", 0);
  4521. }
  4522. if ($user['type_id'] == 3) {
  4523. $result = [
  4524. // 'id' => 0,
  4525. 'user_id' => $data['user_id'],
  4526. 'website_id' => $data['website_id'],
  4527. 'business_name' => $user['business_name'], // 企业名称
  4528. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4529. 'company_nature' => $user['company_nature'], // 公司性质
  4530. 'company_size' => $user['company_size'], // 公司规模
  4531. 'introduction' => $user['introduction'], // 公司简介
  4532. 'real_name' => $user['real_name'], // 企业联系人
  4533. 'mobile' => $user['mobile'], // 企业联系电话
  4534. 'company_url' => $user['company_url'], // 企业网址
  4535. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4536. 'address' => $user['address'], // 企业地址
  4537. 'email' => $user['email'], // 企业邮箱
  4538. ];
  4539. } else {
  4540. return Result::error("用户类型错误", 0);
  4541. }
  4542. if (empty($result)) {
  4543. return Result::error("公司信息不存在", 0);
  4544. }
  4545. return Result::success($result);
  4546. }
  4547. /*
  4548. * 修改公司信息
  4549. * */
  4550. public function upJobCompany(array $data): array
  4551. {
  4552. // return Result::success($data);
  4553. $user = User::where('user.id', $data['user_id'])
  4554. ->where('user.status', 1)
  4555. ->select('user.user_name', 'user.type_id')
  4556. ->first();
  4557. if (empty($user)) {
  4558. return Result::error("用户不存在", 0);
  4559. }
  4560. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4561. $company = [
  4562. 'business_name' => $data['business_name'], // 企业名称
  4563. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4564. 'company_nature' => $data['company_nature'], // 公司性质
  4565. 'company_size' => $data['company_size'], // 公司规模
  4566. 'introduction' => $data['introduction'], // 公司简介
  4567. // 'real_name' => $data['real_name'], // 企业联系人
  4568. 'company_url' => $data['company_url'], // 企业网址
  4569. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4570. 'address' => $data['address'], // 企业详细地址
  4571. ];
  4572. if ($user['type_id'] == 3) {
  4573. Db::beginTransaction();
  4574. try {
  4575. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  4576. 'business_name' => $data['business_name'], // 企业名称
  4577. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4578. 'company_nature' => $data['company_nature'], // 公司性质
  4579. 'company_size' => $data['company_size'], // 公司规模
  4580. 'introduction' => $data['introduction'], // 公司简介
  4581. // 'real_name' => $data['real_name'], // 企业联系人
  4582. 'company_url' => $data['company_url'], // 企业网址
  4583. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4584. 'address' => $data['address'], // 企业详细地址
  4585. ]);
  4586. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  4587. Db::commit();
  4588. } catch (\Exception $e) {
  4589. Db::rollBack();
  4590. return Result::error($e->getMessage(), 0);
  4591. }
  4592. } else {
  4593. return Result::error("用户类型错误", 0);
  4594. }
  4595. if (empty($result)) {
  4596. return Result::error("修改失败", 0);
  4597. }
  4598. return Result::success($result);
  4599. }
  4600. /*
  4601. * 获取省-市
  4602. * */
  4603. public function getJobRecruitingArea(array $data): array
  4604. {
  4605. if (isset($data['pid']) && $data['pid'] != null) {
  4606. $result = District::where('pid', $data['pid'])->get()->all();
  4607. } else {
  4608. $result = District::where('level', 1)->get()->all();
  4609. }
  4610. if (empty($result)) {
  4611. return Result::error("暂无此省市", 0);
  4612. }
  4613. return Result::success($result);
  4614. }
  4615. /*
  4616. * 获取行业分类
  4617. * */
  4618. public function getIndustry(array $data): array
  4619. {
  4620. $result = JobIndustry::get()->all();
  4621. if (empty($result)) {
  4622. return Result::error("暂无行业分类", 0);
  4623. }
  4624. return Result::success($result);
  4625. }
  4626. /*
  4627. * 获取职位
  4628. * */
  4629. public function getPositionList(array $data): array
  4630. {
  4631. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  4632. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  4633. } else {
  4634. $result = JobPosition::where('zwpid', 0)->get()->all();
  4635. }
  4636. if (empty($result)) {
  4637. return Result::error("暂无此职位", 0);
  4638. }
  4639. return Result::success($result);
  4640. }
  4641. /*
  4642. * 获取工作性质-菜单
  4643. * */
  4644. public function getJobNature(array $data): array
  4645. {
  4646. $result = JobEnum::where('egroup', 'nature')->get()->all();
  4647. if (empty($result)) {
  4648. return Result::error("暂无工作性质", 0);
  4649. }
  4650. return Result::success($result);
  4651. }
  4652. /*
  4653. * 获取工作经验-菜单
  4654. * */
  4655. public function getExperience(array $data): array
  4656. {
  4657. $result = JobEnum::where('egroup', 'years')->get()->all();
  4658. if (empty($result)) {
  4659. return Result::error("暂无工作经验", 0);
  4660. }
  4661. return Result::success($result);
  4662. }
  4663. /*
  4664. * 获取学历-菜单
  4665. * */
  4666. public function getEducation(array $data): array
  4667. {
  4668. $result = JobEnum::where('egroup', 'education')->get()->all();
  4669. if (empty($result)) {
  4670. return Result::error("暂无学历", 0);
  4671. }
  4672. return Result::success($result);
  4673. }
  4674. /*
  4675. * 获取薪资-菜单
  4676. * */
  4677. public function getSalary(array $data): array
  4678. {
  4679. $result = JobEnum::where('egroup', 'income')->get()->all();
  4680. if (empty($result)) {
  4681. return Result::error("暂无薪资", 0);
  4682. }
  4683. return Result::success($result);
  4684. }
  4685. /*
  4686. * 获取语言-菜单
  4687. * */
  4688. public function getLanguage(array $data): array
  4689. {
  4690. $result = JobEnum::where('egroup', 'language')->get()->all();
  4691. if (empty($result)) {
  4692. return Result::error("暂无语言", 0);
  4693. }
  4694. return Result::success($result);
  4695. }
  4696. /*
  4697. * 获取掌握程度-菜单
  4698. * */
  4699. public function getLevel(array $data): array
  4700. {
  4701. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  4702. if (empty($result)) {
  4703. return Result::error("暂无工作性质", 0);
  4704. }
  4705. return Result::success($result);
  4706. }
  4707. // 公司信息
  4708. /*
  4709. * 获取公司性质-菜单
  4710. * */
  4711. public function getCompanyNature(array $data): array
  4712. {
  4713. $result = JobNature::get()->all();
  4714. if (empty($result)) {
  4715. return Result::error("暂无公司性质", 0);
  4716. }
  4717. return Result::success($result);
  4718. }
  4719. /*
  4720. * 获取公司规模-菜单
  4721. * */
  4722. public function getCompanySize(array $data): array
  4723. {
  4724. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  4725. if (empty($result)) {
  4726. return Result::error("暂无公司规模", 0);
  4727. }
  4728. return Result::success($result);
  4729. }
  4730. /*
  4731. * 招聘信息审核
  4732. * */
  4733. public function checkJobRecruiting(array $data): array
  4734. {
  4735. $user = User::where('id', $data['user_id'])->first();
  4736. if (empty($user)) {
  4737. return Result::error("用户不存在", 0);
  4738. }
  4739. $job = JobRecruiting::where('id', $data['id'])->first();
  4740. if (empty($job)) {
  4741. return Result::error("招聘信息不存在", 0);
  4742. }
  4743. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  4744. if ($user['type_id'] != 10000) {
  4745. return Result::error("用户暂无权限审核此招聘信息!", 0);
  4746. }
  4747. // 驳回原因
  4748. if ($data['status'] == 2) {
  4749. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  4750. }
  4751. $data['action_id'] = $data['user_id'];
  4752. unset($data['user_id']);
  4753. $result = JobRecruiting::where('id', $data['id'])->update($data);
  4754. if (empty($result)) {
  4755. return Result::error("审核失败", 0);
  4756. }
  4757. return Result::success($result);
  4758. }
  4759. public function myApplyList(array $data): array
  4760. {
  4761. var_dump($data, '------参数');
  4762. $user = User::where('id', $data['user_id'])->first();
  4763. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4764. return Result::error("用户不存在", 0);
  4765. }
  4766. // 1:个人会员 职场机会
  4767. if ($user['type_id'] == 1) {
  4768. $where['user_id'] = $user['id'];
  4769. }
  4770. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  4771. $query->where('user_id', $user['id']);
  4772. })
  4773. ->pluck('recruit_id');
  4774. $where = [];
  4775. if (isset($data['salary']) && $data['salary'] != null) {
  4776. $where['job_recruiting.salary'] = $data['salary'];
  4777. }
  4778. if (isset($data['experience']) && $data['experience'] != null) {
  4779. $where['job_recruiting.experience'] = $data['experience'];
  4780. }
  4781. if (isset($data['business_name']) && $data['business_name'] != null) {
  4782. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4783. }
  4784. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4785. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4786. ->where($where);
  4787. // ->count();
  4788. $count = $query->count();
  4789. $query = clone $query;
  4790. $job = $query
  4791. ->leftJoin('job_enum as income_enum', function ($join) {
  4792. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4793. ->where('income_enum.egroup', 'income');
  4794. })
  4795. ->leftJoin('job_enum as years_enum', function ($join) {
  4796. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4797. ->where('years_enum.egroup', 'years');
  4798. })
  4799. // ->where($where)
  4800. ->orderBy('job_recruiting.updated_at', 'desc')
  4801. ->select(
  4802. 'job_recruiting.id',
  4803. 'job_recruiting.title',
  4804. 'job_company.business_name',
  4805. 'income_enum.evalue as salary_evalue',
  4806. 'income_enum.ename as salary_ename',
  4807. 'years_enum.evalue as experience_evalue',
  4808. 'years_enum.ename as experience_ename',
  4809. 'job_recruiting.updated_at'
  4810. )
  4811. ->offset(($data['page'] - 1) * $data['pageSize'])
  4812. ->limit($data['pageSize'])
  4813. ->get()
  4814. ->all();
  4815. if (empty($job)) {
  4816. return Result::error("暂无招聘信息", 0);
  4817. }
  4818. $result = [
  4819. 'row' => $job,
  4820. 'count' => $count,
  4821. ];
  4822. return Result::success($result);
  4823. }
  4824. /*
  4825. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  4826. * */
  4827. public function getRecruitingList(array $data): array
  4828. {
  4829. $user = User::where('id', $data['user_id'])->first();
  4830. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4831. return Result::error("用户不存在", 0);
  4832. }
  4833. // 1:个人会员 职场机会
  4834. if ($user['type_id'] == 1) {
  4835. $where['user_id'] = $user['id'];
  4836. }
  4837. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  4838. $query->where('receiver_id', $user['id']);
  4839. })
  4840. ->pluck('recruit_id');
  4841. // return Result::success($recruitingId);
  4842. $where = [];
  4843. if (isset($data['salary']) && $data['salary'] != null) {
  4844. $where['job_recruiting.salary'] = $data['salary'];
  4845. }
  4846. if (isset($data['experience']) && $data['experience'] != null) {
  4847. $where['job_recruiting.experience'] = $data['experience'];
  4848. }
  4849. if (isset($data['business_name']) && $data['business_name'] != null) {
  4850. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4851. }
  4852. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4853. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4854. ->where($where);
  4855. // ->count();
  4856. $count = $query->count();
  4857. $query = clone $query;
  4858. $job = $query
  4859. ->leftJoin('job_enum as income_enum', function ($join) {
  4860. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4861. ->where('income_enum.egroup', 'income');
  4862. })
  4863. ->leftJoin('job_enum as years_enum', function ($join) {
  4864. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4865. ->where('years_enum.egroup', 'years');
  4866. })
  4867. // ->where($where)
  4868. ->orderBy('job_recruiting.updated_at', 'desc')
  4869. ->select(
  4870. 'job_recruiting.id',
  4871. 'job_recruiting.title',
  4872. 'job_company.business_name',
  4873. 'income_enum.evalue as salary_evalue',
  4874. 'income_enum.ename as salary_ename',
  4875. 'years_enum.evalue as experience_evalue',
  4876. 'years_enum.ename as experience_ename',
  4877. 'job_recruiting.updated_at'
  4878. )
  4879. ->offset(($data['page'] - 1) * $data['pageSize'])
  4880. ->limit($data['pageSize'])
  4881. ->get()
  4882. ->all();
  4883. if (empty($job)) {
  4884. return Result::error("暂无招聘信息", 0);
  4885. }
  4886. $result = [
  4887. 'row' => $job,
  4888. 'count' => $count,
  4889. ];
  4890. return Result::success($result);
  4891. }
  4892. /*
  4893. * 获取企业会员-招聘信息列表
  4894. * */
  4895. public function getRecruitingInfo(array $data): array
  4896. {
  4897. $user = User::where('id', $data['user_id'])->first();
  4898. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4899. return Result::error("用户不存在", 0);
  4900. }
  4901. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  4902. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4903. ->select(
  4904. 'job_recruiting.*',
  4905. 'job_company.business_name',
  4906. 'job_company.company_hy_id',
  4907. 'job_company.company_size',
  4908. 'job_company.company_nature',
  4909. 'job_company.introduction',
  4910. 'job_company.real_name',
  4911. 'job_company.mobile',
  4912. 'job_company.company_url',
  4913. 'job_company.address_arr_id',
  4914. 'job_company.address',
  4915. 'job_company.email'
  4916. )
  4917. ->get();
  4918. if (empty($recruiting)) {
  4919. return Result::error("暂无招聘信息", 0);
  4920. }
  4921. return Result::success($recruiting);
  4922. }
  4923. /*
  4924. * 获取企业会员-我的沟通
  4925. * */
  4926. public function getJobResumeList(array $data): array
  4927. {
  4928. $user = User::where('id', $data['user_id'])->first();
  4929. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  4930. return Result::error("用户不存在", 0);
  4931. }
  4932. $where = [];
  4933. if (isset($data['salary']) && $data['salary'] != null) {
  4934. $where['job_hunting.salary'] = $data['salary'];
  4935. }
  4936. if (isset($data['user_name']) && $data['user_name'] != null) {
  4937. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  4938. }
  4939. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  4940. $query->where('job_resume.user_id', $user['id']);
  4941. })
  4942. ->when(!empty($where), function ($query) use ($where) {
  4943. $query->where($where);
  4944. })
  4945. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  4946. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  4947. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  4948. ->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');
  4949. $count = $job->count();
  4950. if ($count == 0) {
  4951. return Result::error("暂无沟通记录", 0);
  4952. }
  4953. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  4954. ->offset(($data['page'] - 1) * $data['pageSize'])
  4955. ->limit($data['pageSize'])
  4956. ->get();
  4957. if (empty($jobs)) {
  4958. return Result::error("暂无沟通记录", 0);
  4959. }
  4960. $result['row'] = $this->processJob($jobs, '');
  4961. $result['count'] = $count;
  4962. return Result::success($result);
  4963. }
  4964. // 20250306 招聘
  4965. //20250422 书刊音像
  4966. public function addBook(array $data): array
  4967. {
  4968. // $user_id = $data['user_id'] ?? 0;
  4969. $type_id = $data['type_id'] ?? 0;
  4970. // $website_id = $data['website_id'] ?? 0;
  4971. // unset($data['user_id']);
  4972. unset($data['type_id']);
  4973. // unset($data['website_id']);
  4974. //处理数组
  4975. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  4976. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  4977. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  4978. if ($data['img_url'] == '') {
  4979. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4980. preg_match_all($reg, $data['detail'], $matches);
  4981. if (isset($matches[1][0])) {
  4982. //截取varchar240
  4983. $data['img_url'] = substr($matches[1][0], 0, 240);
  4984. }
  4985. }
  4986. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4987. //提取标题+内容中的关键词
  4988. $data['keyword'] = $data['title'];
  4989. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4990. Jieba::init(); // 初始化 jieba-php
  4991. Finalseg::init();
  4992. $segList = Jieba::cut($data['keyword']);
  4993. $segList1 = array_slice($segList, 0, 8);
  4994. $data['keyword'] = implode(',', $segList1);
  4995. }
  4996. if ($data['description'] == '') {
  4997. //提取内容中的描述
  4998. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4999. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5000. }
  5001. var_dump($data, '--');
  5002. $result = Book::insertGetId($data);
  5003. if (empty($result)) {
  5004. return Result::error("添加失败", 0);
  5005. }
  5006. return Result::success($result);
  5007. }
  5008. public function getBookList(array $data): array
  5009. {
  5010. $where = [];
  5011. if (!empty($data["title"])) {
  5012. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5013. }
  5014. if (!empty($data['website_name'])) {
  5015. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5016. }
  5017. if (!empty($data['status'])) {
  5018. $where[] = ['book.status', '=', $data['status']];
  5019. }
  5020. $user_id = $data['user_id'];
  5021. $type_id = $data['type_id'];
  5022. // $type_id = 4;
  5023. var_dump($type_id, '------1--------');
  5024. if ($type_id != 10000) {
  5025. $where[] = ['book.user_id', '=', $user_id];
  5026. }
  5027. var_dump(!empty($data['status1']), '=-===1');
  5028. $result = Book::where($where)
  5029. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5030. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5031. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5032. ->when(isset($data['status1']), function ($query) use ($data) {
  5033. $query->whereIn('book.status', [1, 3]);
  5034. })
  5035. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5036. ->orderBy("updated_at", "desc")
  5037. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5038. if (empty($result)) {
  5039. return Result::error("暂无数据", 0);
  5040. }
  5041. // 取出数据
  5042. $rows = $result->items();
  5043. $count = $result->total();
  5044. $responseData = [
  5045. 'rows' => $rows,
  5046. 'count' => $count,
  5047. ];
  5048. return Result::success($responseData);
  5049. }
  5050. public function deleteBook(array $data): array
  5051. {
  5052. $result = Book::where('id', $data['id'])->delete();
  5053. if (empty($result)) {
  5054. return Result::error("删除失败", 0);
  5055. }
  5056. return Result::success($result);
  5057. }
  5058. public function updateBook(array $data): array
  5059. {
  5060. // $user_id = $data['user_id'] ?? 0;
  5061. $type_id = $data['type_id'] ?? 0;
  5062. // $website_id = $data['website_id'] ?? 0;
  5063. unset($data['user_id']);
  5064. unset($data['type_id']);
  5065. // unset($data['website_id']);
  5066. //处理数组
  5067. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5068. if ($data['img_url'] == '') {
  5069. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5070. preg_match_all($reg, $data['detail'], $matches);
  5071. if (isset($matches[1][0])) {
  5072. //截取varchar240
  5073. $data['img_url'] = substr($matches[1][0], 0, 240);
  5074. }
  5075. }
  5076. if ($data['keyword'] == '') {
  5077. //提取标题+内容中的关键词
  5078. $data['keyword'] = $data['title'];
  5079. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5080. Jieba::init(); // 初始化 jieba-php
  5081. Finalseg::init();
  5082. $segList = Jieba::cut($data['keyword']);
  5083. $segList1 = array_slice($segList, 0, 8);
  5084. $data['keyword'] = implode(',', $segList1);
  5085. }
  5086. if ($data['description'] == '') {
  5087. //提取内容中的描述
  5088. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5089. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5090. }
  5091. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5092. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5093. $result = Book::where("id", $data["id"])->update($data);
  5094. if (empty($result)) {
  5095. return Result::error("更新失败", 0);
  5096. }
  5097. return Result::success($result);
  5098. }
  5099. public function getBookInfo(array $data): array
  5100. {
  5101. $result = Book::where("id", $data["id"])->first();
  5102. if (empty($result)) {
  5103. return Result::error("获取失败", 0);
  5104. }
  5105. return Result::success($result);
  5106. }
  5107. public function updateBookStatus(array $data): array
  5108. {
  5109. //审核
  5110. unset($data['user_id']);
  5111. $result = Book::where("id", $data["id"])->update($data);
  5112. if (empty($result)) {
  5113. return Result::error("更新失败", 0);
  5114. }
  5115. return Result::success($result);
  5116. }
  5117. //20250422 书刊音像
  5118. /**
  5119. * 贴身宝贝
  5120. * @param array $data
  5121. * @return array
  5122. */
  5123. public function getWebsiteTsbb(array $data): array
  5124. {
  5125. $month = $data['month'] ?? date('m');
  5126. $day = $data['day'] ?? date('d');
  5127. // 使用缓存键
  5128. $cacheKey = "tsbb_data_{$month}_{$day}";
  5129. // 尝试从缓存获取数据
  5130. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5131. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5132. if ($cachedData = $cache->get($cacheKey)) {
  5133. return Result::success(unserialize($cachedData));
  5134. }
  5135. //查询老黄历
  5136. try {
  5137. $date = date('Y-m-d');
  5138. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5139. // 使用 curl 替代 file_get_contents
  5140. $ch = curl_init();
  5141. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5142. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5143. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5144. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5145. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5146. 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');
  5147. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5148. 'Accept: application/json',
  5149. 'Content-Type: application/json',
  5150. 'Referer: https://www.36jxs.com/'
  5151. ]);
  5152. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5153. curl_setopt($ch, CURLOPT_ENCODING, '');
  5154. $almanacResponse = curl_exec($ch);
  5155. var_dump("====:", $almanacResponse);
  5156. if (curl_errno($ch)) {
  5157. var_dump('Curl error:', curl_error($ch));
  5158. throw new \Exception('Curl error: ' . curl_error($ch));
  5159. }
  5160. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5161. curl_close($ch);
  5162. if ($almanacResponse === false) {
  5163. throw new \Exception('Failed to fetch almanac data');
  5164. }
  5165. $almanacData = json_decode($almanacResponse, true);
  5166. if (json_last_error() !== JSON_ERROR_NONE) {
  5167. throw new \Exception('Failed to parse almanac data');
  5168. }
  5169. $almanacInfo = $almanacData['data'] ?? [];
  5170. } catch (\Exception $e) {
  5171. var_dump('Exception:', $e->getMessage());
  5172. $almanacInfo = [];
  5173. }
  5174. // 获取历史上的今天数据
  5175. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5176. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5177. ->orderBy('year', 'asc')
  5178. ->select("title", "id", "year", DB::raw('1 as type'))
  5179. ->limit(16)
  5180. ->get();
  5181. // 获取节日数据 - 从今天开始获取未来4条
  5182. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5183. ->orderBy('showtime', 'asc')
  5184. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5185. ->limit(16)
  5186. ->get();
  5187. //说文解字
  5188. $chartacterList = Character::orderBy('updated_at', 'desc')
  5189. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5190. ->limit(6)
  5191. ->get();
  5192. //谜语沙龙
  5193. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5194. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5195. ->limit(4)
  5196. ->get();
  5197. //成语欣赏
  5198. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5199. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5200. ->limit(32)
  5201. ->get();
  5202. //名联赏析
  5203. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5204. ->select("id", "first", "second", DB::raw('6 as type'))
  5205. ->limit(6)
  5206. ->get();
  5207. // 获取分类文章数据
  5208. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5209. ->pluck('category_id')
  5210. ->toArray();
  5211. // $categoryIds = [627, 628, 629, 630, 631, 632, 633, 634, 635, 636];
  5212. // 使用子查询优化
  5213. $articlesList = DB::table('article')
  5214. ->select([
  5215. 'article.id',
  5216. 'article.title',
  5217. 'article.imgurl',
  5218. 'article.created_at',
  5219. 'category.name as category_name',
  5220. 'category.id as category_id',
  5221. 'website_category.aLIas_pinyin as pinyin',
  5222. DB::raw('100 as type')
  5223. ])
  5224. ->join('category', 'article.catid', '=', 'category.id')
  5225. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5226. ->where('website_category.website_id', $data['website_id'])
  5227. ->where('article.status', 1)
  5228. ->whereIn('category.id', $categoryIds)
  5229. // ->whereRaw('article.created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)')
  5230. ->orderBy('article.created_at', 'desc')
  5231. ->get()
  5232. ->groupBy('category_id')
  5233. ->map(function ($group) {
  5234. // 确保第一条数据有图片
  5235. $firstWithImage = $group->first(function ($item) {
  5236. return !empty($item->imgurl);
  5237. });
  5238. if ($firstWithImage) {
  5239. // 如果有带图片的文章,将其放在第一位
  5240. $group = $group->filter(function ($item) use ($firstWithImage) {
  5241. return $item->id !== $firstWithImage->id;
  5242. })->prepend($firstWithImage);
  5243. }
  5244. return [
  5245. 'category_name' => $group->first()->category_name,
  5246. 'catid' => $group->first()->category_id,
  5247. 'pinyin' => $group->first()->pinyin,
  5248. 'type' => 100,
  5249. 'list' => $group->take(6)->map(function ($item) {
  5250. return [
  5251. 'id' => $item->id,
  5252. 'title' => $item->title,
  5253. 'imgurl' => $item->imgurl,
  5254. 'created_at' => $item->created_at
  5255. ];
  5256. })->values()
  5257. ];
  5258. })
  5259. ->values()
  5260. ->toArray();
  5261. $result = [
  5262. 'almanac' => $almanacInfo,
  5263. 'historyTodayList' => [
  5264. 'category_name' => '历史上的今天',
  5265. 'list' => $historyTodayList,
  5266. 'type' => 1
  5267. ],
  5268. 'festivalList' => [
  5269. 'category_name' => '节日预告',
  5270. 'list' => $festivalList,
  5271. 'type' => 2
  5272. ],
  5273. 'chartacterList' => [
  5274. 'category_name' => '说文解字',
  5275. 'list' => $chartacterList,
  5276. 'type' => 3
  5277. ],
  5278. 'coupletList' => [
  5279. 'category_name' => '名联赏析',
  5280. 'list' => $coupletList,
  5281. 'type' => 6
  5282. ],
  5283. 'riddletList' => [
  5284. 'category_name' => '谜语沙龙',
  5285. 'list' => $riddletList,
  5286. 'type' => 4
  5287. ],
  5288. 'idiomList' => [
  5289. 'category_name' => '成语欣赏',
  5290. 'list' => $idiomList,
  5291. 'type' => 5
  5292. ],
  5293. 'articlesList' => $articlesList
  5294. ];
  5295. // 缓存结果,设置1小时过期
  5296. $cache->set($cacheKey, serialize($result), 3600);
  5297. return Result::success($result);
  5298. }
  5299. /**
  5300. * 获取资讯列表
  5301. */
  5302. public function getWebsiteTsbbList(array $data): array
  5303. {
  5304. $page = $data['page'] ?? 1;
  5305. $pageSize = $data['pageSize'] ?? 10;
  5306. // 如果没有传入月份和日期,则使用今天的日期
  5307. $month = $data['month'] ?? date('m');
  5308. $day = $data['day'] ?? date('d');
  5309. $total = 0;
  5310. $result = [];
  5311. $data['type'] = intval($data['type']);
  5312. var_dump("接收参数:", $data);
  5313. switch ($data['type']) {
  5314. case 1:
  5315. $query = HistoryToday::where(function ($q) use ($month, $day) {
  5316. // 当前月份之后的数据
  5317. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  5318. // 或者当前月份且日期大于等于当前日期的数据
  5319. ->orWhere(function ($q) use ($month, $day) {
  5320. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5321. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  5322. });
  5323. })
  5324. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  5325. $total = $query->count();
  5326. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  5327. ->offset(($page - 1) * $pageSize)
  5328. ->limit($pageSize)
  5329. ->get();
  5330. break;
  5331. case 2:
  5332. $query = Festival::where(function ($q) use ($month, $day) {
  5333. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  5334. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  5335. ->orWhere(function ($q) use ($month, $day) {
  5336. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  5337. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  5338. });
  5339. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  5340. $total = $query->count();
  5341. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  5342. ->offset(($page - 1) * $pageSize)
  5343. ->limit($pageSize)
  5344. ->get();
  5345. break;
  5346. case 3:
  5347. $query = Character::orderBy("updated_at", "desc");
  5348. $total = $query->count();
  5349. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  5350. ->offset(($page - 1) * $pageSize)
  5351. ->limit($pageSize)
  5352. ->get();
  5353. break;
  5354. case 4:
  5355. $query = Riddle::orderBy("updated_at", "desc");
  5356. $total = $query->count();
  5357. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  5358. ->offset(($page - 1) * $pageSize)
  5359. ->limit($pageSize)
  5360. ->get();
  5361. break;
  5362. case 5:
  5363. $query = Idiom::orderBy("updated_at", "desc");
  5364. $total = $query->count();
  5365. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  5366. ->offset(($page - 1) * $pageSize)
  5367. ->limit($pageSize)
  5368. ->get();
  5369. break;
  5370. case 6:
  5371. $query = Couplet::orderBy("updated_at", "desc");
  5372. $total = $query->count();
  5373. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  5374. ->offset(($page - 1) * $pageSize)
  5375. ->limit($pageSize)
  5376. ->get();
  5377. break;
  5378. default:
  5379. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  5380. $total = $query->count();
  5381. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  5382. ->offset(($page - 1) * $pageSize)
  5383. ->limit($pageSize)
  5384. ->get();
  5385. }
  5386. return Result::success([
  5387. 'list' => $result,
  5388. 'total' => $total,
  5389. 'page' => (int)$page,
  5390. 'pageSize' => (int)$pageSize,
  5391. 'month' => $month,
  5392. 'day' => $day
  5393. ]);
  5394. }
  5395. /**
  5396. * 1:历史上的今天
  5397. * 2:节日
  5398. * 3:文章
  5399. *
  5400. * 资讯详情信息
  5401. */
  5402. public function getWebsiteTsbbDetail(array $data): array
  5403. {
  5404. $data['type'] = intval($data['type']);
  5405. switch ($data['type']) {
  5406. case 1:
  5407. $result = HistoryToday::where("id", $data['id'])->first();
  5408. break;
  5409. case 2:
  5410. $result = Festival::where("id", $data['id'])->first();
  5411. break;
  5412. case 3:
  5413. $result = Character::where("id", $data['id'])->first();
  5414. break;
  5415. case 4:
  5416. $result = Riddle::where("id", $data['id'])->first();
  5417. break;
  5418. case 5:
  5419. $result = Idiom::where("id", $data['id'])->first();
  5420. break;
  5421. case 6:
  5422. $result = Couplet::where("id", $data['id'])->first();
  5423. break;
  5424. default:
  5425. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  5426. break;
  5427. }
  5428. return Result::success($result);
  5429. }
  5430. /**
  5431. * 农网导航首页数据
  5432. */
  5433. public function getWebsiteNwHomeList(array $data): array
  5434. {
  5435. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  5436. ->pluck('category_id')
  5437. ->toArray();
  5438. // 使用子查询优化
  5439. $articlesList = DB::table('article')
  5440. ->select([
  5441. 'article.id',
  5442. 'article.title',
  5443. 'article.imgurl',
  5444. 'article.created_at',
  5445. 'category.name as category_name',
  5446. 'category.id as category_id',
  5447. 'website_category.aLIas_pinyin as pinyin',
  5448. 'parent_wc.aLIas_pinyin as parent_pinyin',
  5449. DB::raw('100 as type')
  5450. ])
  5451. ->join('category', 'article.catid', '=', 'category.id')
  5452. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5453. ->leftJoin('website_category as parent_wc', function ($join) {
  5454. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  5455. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  5456. })
  5457. ->where('website_category.website_id', $data['website_id'])
  5458. ->where('article.status', 1)
  5459. ->whereIn('category.id', $categoryIds)
  5460. ->orderBy('article.created_at', 'desc')
  5461. ->get()
  5462. ->groupBy('category_id')
  5463. ->map(function ($group) {
  5464. // 确保第一条数据有图片
  5465. $firstWithImage = $group->first(function ($item) {
  5466. return !empty($item->imgurl);
  5467. });
  5468. if ($firstWithImage) {
  5469. // 如果有带图片的文章,将其放在第一位
  5470. $group = $group->filter(function ($item) use ($firstWithImage) {
  5471. return $item->id !== $firstWithImage->id;
  5472. })->prepend($firstWithImage);
  5473. }
  5474. return [
  5475. 'category_name' => $group->first()->category_name,
  5476. 'catid' => $group->first()->category_id,
  5477. 'pinyin' => $group->first()->pinyin,
  5478. 'parent_pinyin' => $group->first()->parent_pinyin,
  5479. 'list' => $group->take(4)->map(function ($item) {
  5480. return [
  5481. 'id' => $item->id,
  5482. 'title' => $item->title,
  5483. ];
  5484. })->values()
  5485. ];
  5486. })
  5487. ->values()
  5488. ->toArray();
  5489. return Result::success($articlesList);
  5490. }
  5491. /**
  5492. * 模块新闻加强版
  5493. * @param array $data
  5494. * @return array
  5495. */
  5496. public function getWebsiteAllArticle(array $data): array
  5497. {
  5498. // 修正传入的字符串,将单引号替换为双引号
  5499. $input['id'] = $data['id'];
  5500. $input['website_id'] = $data['website_id'];
  5501. // 将 JSON 字符串转换为 PHP 数组
  5502. $data = json_decode($input['id'], true);
  5503. // 使用 array_map 处理每个元素
  5504. $result = array_map(function ($item) use ($input) {
  5505. // 检查parent元素是否存在且不是undefined
  5506. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  5507. $count = explode(',', $item['parent']);
  5508. if (count($count) != 3) {
  5509. return Result::error("参数错误", 0);
  5510. }
  5511. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  5512. $website = [
  5513. 'website_id' => $input['website_id'],
  5514. ];
  5515. // 查询栏目名称
  5516. $categroy = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin', 'type']);
  5517. // 查询图片新闻
  5518. if (isset($parentImgNum) && $parentImgNum != 0 && !empty($categroy)) {
  5519. $imgArticles = Article::where('article.status', 1)
  5520. ->where(function ($query) use ($parentCatId) {
  5521. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  5522. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  5523. })
  5524. ->where(function ($query) use ($website) {
  5525. $query->where(function ($subQuery) use ($website) {
  5526. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 1")
  5527. ->orWhereNull("ignore_ids");
  5528. });
  5529. })
  5530. ->where('imgurl', '!=', '')
  5531. ->leftJoin('website_category', function ($join) use ($website) {
  5532. $join->on('article.catid', '=', 'website_category.category_id')
  5533. ->where('website_category.website_id', '=', $website['website_id']);
  5534. })
  5535. ->select(
  5536. 'article.id',
  5537. 'article.title',
  5538. 'article.imgurl',
  5539. 'article.author',
  5540. 'article.updated_at',
  5541. 'article.introduce',
  5542. 'article.islink',
  5543. 'article.linkurl',
  5544. 'article.copyfrom',
  5545. 'article.cat_arr_id',
  5546. 'article.catid',
  5547. 'website_category.alias as category_name',
  5548. )
  5549. ->orderBy('updated_at', 'desc')
  5550. ->limit($parentImgNum)
  5551. ->get();
  5552. //调取封装路由的方法,处理新闻路由
  5553. if (!empty($imgArticles)) {
  5554. $imgArticles = $this->processArticles($imgArticles, $website);
  5555. }
  5556. }
  5557. // 查询文字新闻
  5558. if (isset($parentTextNum) && $parentTextNum != 0 && !empty($categroy)) {
  5559. $textArticles = [];
  5560. $textArticles = Article::where('article.status', 1)
  5561. ->where(function ($query) use ($parentCatId) {
  5562. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  5563. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  5564. })
  5565. ->where(function ($query) use ($website) {
  5566. $query->where(function ($subQuery) use ($website) {
  5567. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 1")
  5568. ->orWhereNull("ignore_ids");
  5569. });
  5570. })
  5571. ->leftJoin('website_category', function ($join) use ($website) {
  5572. $join->on('article.catid', '=', 'website_category.category_id')
  5573. ->where('website_category.website_id', '=', $website['website_id']);
  5574. })
  5575. ->select(
  5576. 'article.id',
  5577. 'article.title',
  5578. 'article.author',
  5579. 'article.updated_at',
  5580. 'article.cat_arr_id',
  5581. 'article.introduce',
  5582. 'article.islink',
  5583. 'article.linkurl',
  5584. 'article.copyfrom',
  5585. 'article.catid',
  5586. 'website_category.alias as category_name',
  5587. )
  5588. ->orderBy('updated_at', 'desc')
  5589. ->limit($parentTextNum)
  5590. ->get();
  5591. if (!empty($textArticles)) {
  5592. $textArticles = $this->processArticles($textArticles, $website);
  5593. }
  5594. }
  5595. }
  5596. $resultItem = [
  5597. 'alias' => $categroy ? $categroy->alias : null,
  5598. 'category_id' => $categroy ? $categroy->category_id : null,
  5599. 'pinyin' => $categroy ? $categroy->aLIas_pinyin : null,
  5600. 'imgnum' => $imgArticles ?? [],
  5601. 'textnum' => $textArticles ?? [],
  5602. ];
  5603. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  5604. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  5605. $childCategory = WebsiteCategory::where($website)
  5606. ->where("category_id", $childCatId)
  5607. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "') = 1")
  5608. ->first(['alias', 'category_id', 'aLIas_pinyin', 'pid', 'type', 'category_arr_id as cat_arr_id']);
  5609. if (!empty($childCategory)) {
  5610. $childCategory = $this->processArticles($childCategory, $website);
  5611. // 查询此层级的所有子栏目
  5612. $all_childcat = WebsiteCategory::where($website)
  5613. ->where("pid", $childCategory['pid'])
  5614. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "') = 1")
  5615. ->get(['alias', 'category_id', 'aLIas_pinyin', 'pid', 'type', 'category_arr_id as cat_arr_id']);
  5616. $all_childcat = $this->processArticles($all_childcat, $website);
  5617. // 查询子栏目图片新闻
  5618. if (isset($childImgNum) && $childImgNum != 0) {
  5619. $childImgArticles = Article::where('catid', $childCatId)
  5620. ->where('status', 1)
  5621. ->where(function ($query) use ($website) {
  5622. $query->where(function ($subQuery) use ($website) {
  5623. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 1");
  5624. })->orWhereNull("ignore_ids");
  5625. })
  5626. ->select(
  5627. 'article.id',
  5628. 'article.title',
  5629. 'article.imgurl',
  5630. 'article.author',
  5631. 'article.updated_at',
  5632. 'article.introduce',
  5633. 'article.islink',
  5634. 'article.linkurl',
  5635. 'article.catid',
  5636. 'article.cat_arr_id',
  5637. 'article.copyfrom',
  5638. )
  5639. ->where('imgurl', '!=', '')
  5640. ->orderBy('updated_at', 'desc')
  5641. ->limit($childImgNum)
  5642. ->get();
  5643. $childImgArticles = $this->processArticles($childImgArticles, $website);
  5644. }
  5645. // 查询子栏目文字新闻
  5646. if (isset($childTextNum) && $childTextNum != 0) {
  5647. $childTextArticles = Article::where('catid', $childCatId)
  5648. ->where('status', 1)
  5649. ->where(function ($query) use ($website) {
  5650. $query->where(function ($subQuery) use ($website) {
  5651. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 1");
  5652. })->orWhereNull("ignore_ids");
  5653. })
  5654. ->select(
  5655. 'article.id',
  5656. 'article.title',
  5657. 'article.author',
  5658. 'article.updated_at',
  5659. 'article.introduce',
  5660. 'article.islink',
  5661. 'article.linkurl',
  5662. 'article.catid',
  5663. 'article.cat_arr_id',
  5664. 'article.copyfrom',
  5665. )
  5666. ->orderBy('updated_at', 'desc')
  5667. ->limit($childTextNum)
  5668. ->get();
  5669. $childTextArticles = $this->processArticles($childTextArticles, $website);
  5670. }
  5671. }
  5672. $resultItem['child'] = [
  5673. 'alias' => $childCategory ? $childCategory->alias : null,
  5674. 'category_id' => $childCategory ? $childCategory->category_id : null,
  5675. 'type' => $childCategory ? $childCategory->type : null,
  5676. 'pinyin' => $childCategory ? $childCategory->pinyin : null,
  5677. 'all_childcat' => $all_childcat ?? [],
  5678. 'imgnum' => $childImgArticles ?? [],
  5679. 'textnum' => $childTextArticles ?? [],
  5680. ];
  5681. } else {
  5682. $resultItem['child'] = [];
  5683. }
  5684. return $resultItem;
  5685. }, $data);
  5686. return Result::success($result);
  5687. }
  5688. /**
  5689. * 企业管理
  5690. * @param array $data
  5691. * @return array
  5692. */
  5693. public function getCompanyList(array $data): array
  5694. {
  5695. // return Result::success($data);
  5696. $where = [];
  5697. $user = User::where('id', $data['user_id'])->first();
  5698. if(empty($user)){
  5699. return Result::error('用户不存在!');
  5700. }
  5701. if($user['type_id']!= 10000){
  5702. $where['user_id'] = $data['user_id'];
  5703. }
  5704. if(isset($data['title']) && !empty($data['title'])){
  5705. array_push($where, ['company.title', 'like', '%'. $data['title']. '%']);
  5706. }
  5707. if(isset($data['website_name']) && !empty($data['website_name'])){
  5708. array_push($where, ['website.website_name', 'like', '%'. $data['website_name']. '%']);
  5709. }
  5710. if(isset($data['ischeck']) && !empty($data['ischeck'])){
  5711. if($data['ischeck'] == 1){
  5712. if(isset($data['status']) && $data['status'] != ''){
  5713. array_push($where, ['company.status', $data['status']]);
  5714. $query = Company::where($where);
  5715. }else{
  5716. $query = Company::whereIn('company.status', [0,2]);
  5717. }
  5718. }else{
  5719. $query = Company::where('company.status', 1);
  5720. }
  5721. }
  5722. $result = $query->where($where)
  5723. ->leftJoin('website_category', function ($query) {
  5724. $query->on('website_category.category_id', '=', 'company.category_id')
  5725. ->on('website_category.website_id', '=', 'company.website_id');
  5726. })
  5727. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  5728. ->select(
  5729. 'company.id',
  5730. 'company.title',
  5731. 'company.website_id',
  5732. 'company.category_id',
  5733. 'website.website_name',
  5734. 'website_category.alias as category_name',
  5735. 'company.status',
  5736. 'company.updated_at',
  5737. )
  5738. ->orderBy('company.updated_at', 'desc')
  5739. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  5740. if($result->isEmpty()){
  5741. return Result::error("暂无企业", 0);
  5742. }
  5743. return Result::success($result);
  5744. }
  5745. /**
  5746. * 添加企业
  5747. * @param array $data
  5748. * @return array
  5749. */
  5750. public function addCompany(array $data): array
  5751. {
  5752. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  5753. if(isset($data['cat_arr_id']) &&!empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])){
  5754. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  5755. $data['cat_arr_id'] = json_encode($car_arr_id);
  5756. }else{
  5757. $data['cat_arr_id'] = '';
  5758. }
  5759. if ($data['imgurl'] == '') {
  5760. //content中提取图片第一个图,正则提取
  5761. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5762. preg_match_all($reg, $data['content'], $matches);
  5763. if (isset($matches[1][0])) {
  5764. //截取varchar240
  5765. $data['imgurl'] = substr($matches[1][0], 0, 240);
  5766. }
  5767. }
  5768. if ($data['keyword'] == '') {
  5769. //提取标题+内容中的关键词
  5770. $data['keyword'] = $data['title'];
  5771. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5772. Jieba::init(); // 初始化 jieba-php
  5773. Finalseg::init();
  5774. $segList = Jieba::cut($data['keyword']);
  5775. $segList1 = array_slice($segList, 0, 8);
  5776. $data['keyword'] = implode(',', $segList1);
  5777. }
  5778. if ($data['introduce'] == '' || empty($data['introduce'])) {
  5779. //提取内容中的描述
  5780. $data['introduce'] = mb_substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100) ?? '';
  5781. }
  5782. $user = User::where('id', $data['user_id'])->first();
  5783. if(empty($user)){
  5784. return Result::error('用户不存在!');
  5785. }
  5786. if($user['type_id']== 10000){
  5787. $data['status'] = 1;
  5788. }
  5789. $result = Company::insertGetId($data);
  5790. if ($result) {
  5791. return Result::success($result);
  5792. } else {
  5793. return Result::error('添加失败');
  5794. }
  5795. }
  5796. /**
  5797. * 更新企业
  5798. * @param array $data
  5799. * @return array
  5800. */
  5801. public function upCompany(array $data): array
  5802. {
  5803. if(isset($data['cat_arr_id']) &&!empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])){
  5804. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  5805. $data['cat_arr_id'] = json_encode($car_arr_id);
  5806. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  5807. }else{
  5808. $data['cat_arr_id'] = '';
  5809. }
  5810. // $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  5811. if ($data['imgurl'] == '') {
  5812. //content中提取图片第一个图,正则提取
  5813. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5814. preg_match_all($reg, $data['content'], $matches);
  5815. if (isset($matches[1][0])) {
  5816. //截取varchar240
  5817. $data['imgurl'] = substr($matches[1][0], 0, 240);
  5818. }
  5819. }
  5820. if ($data['keyword'] == '') {
  5821. //提取标题+内容中的关键词
  5822. $data['keyword'] = $data['title'];
  5823. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5824. Jieba::init(); // 初始化 jieba-php
  5825. Finalseg::init();
  5826. $segList = Jieba::cut($data['keyword']);
  5827. $segList1 = array_slice($segList, 0, 8);
  5828. $data['keyword'] = implode(',', $segList1);
  5829. }
  5830. if ($data['introduce'] == '') {
  5831. //提取内容中的描述
  5832. // var_dump(11111);
  5833. $data['introduce'] = mb_substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  5834. // var_dump($data['introduce']);
  5835. }
  5836. // return Result::success($data);
  5837. $user = User::where('id', $data['user_id'])->first();
  5838. if(empty($user)){
  5839. return Result::error('用户不存在!');
  5840. }
  5841. if($user['type_id']== 10000){
  5842. $data['status'] = 1;
  5843. }else{
  5844. $data['status'] = 0;
  5845. }
  5846. $result = Company::where('id', $data['id'])->update($data);
  5847. if ($result) {
  5848. return Result::success($result);
  5849. } else {
  5850. return Result::error('修改失败');
  5851. }
  5852. }
  5853. /**
  5854. * 删除企业
  5855. * @param array $data
  5856. * @return array
  5857. */
  5858. public function delCompany(array $data): array
  5859. {
  5860. $result = Company::where('id', $data['id'])->delete();
  5861. if ($result) {
  5862. return Result::success($result);
  5863. } else {
  5864. return Result::error('删除失败');
  5865. }
  5866. }
  5867. /**
  5868. * 审核企业
  5869. * @param array $data
  5870. * @return array
  5871. */
  5872. public function checkCompany(array $data): array
  5873. {
  5874. $user = User::where('id', $data['user_id'])->first();
  5875. if(empty($user)){
  5876. return Result::error('用户不存在!');
  5877. }
  5878. $company = Company::where('id', $data['id'])->first();
  5879. if(empty($company)){
  5880. return Result::error('企业不存在!');
  5881. }
  5882. // 状态:0:未审核 1:已审核 2:已拒绝
  5883. if($data['status'] == 2 || $data['status'] == '2'){
  5884. $result = Company::where('id', $data['id'])->update(['status' => $data['status'],'reject_reason'=> $data['reason']]);
  5885. }else{
  5886. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  5887. }
  5888. if(empty($result)){
  5889. return Result::error('审核失败!');
  5890. }else{
  5891. return Result::success($result);
  5892. }
  5893. }
  5894. /**
  5895. * 获取企业信息
  5896. * @param array $data
  5897. * @return array
  5898. */
  5899. public function getCompanyInfo(array $data): array
  5900. {
  5901. $result = Company::where('id', $data['id'])->first();
  5902. if(empty($result)){
  5903. return Result::error('企业不存在!');
  5904. }else{
  5905. return Result::success($result);
  5906. }
  5907. }
  5908. }