NewsService.php 220 KB

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