NewsService.php 274 KB

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