NewsService.php 222 KB

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