NewsService.php 270 KB

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