NewsService.php 271 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607
  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. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  3932. $re_user_ids = json_decode($result['re_user_ids'], true);
  3933. var_dump($re_user_ids, '--------------1---test---------');
  3934. var_dump($data, '--------------1---test---------');
  3935. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  3936. //如果已经存在,就不再添加
  3937. if (isset($result['read_id']) && !empty($result['read_id'])) {
  3938. $read_id = json_decode($result['read_id'], true);
  3939. if (!is_array($read_id)) {
  3940. $read_id = [];
  3941. }
  3942. if (!in_array($data['user_id'], $read_id)) {
  3943. $read_id[] = $data['user_id'];
  3944. $result['read_id'] = json_encode($read_id);
  3945. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  3946. }
  3947. } else {
  3948. //如果不存在,就添加
  3949. $result['read_id'] = json_encode([$data['user_id']]);
  3950. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  3951. }
  3952. }
  3953. return Result::success($result);
  3954. }
  3955. public function addNotice(array $data): array
  3956. {
  3957. date_default_timezone_set('Asia/Shanghai');
  3958. $data['created_at'] = date('Y-m-d H:i:s');
  3959. $data['updated_at'] = date('Y-m-d H:i:s');
  3960. $user_id = UserInfo::
  3961. //city_id不是null
  3962. whereNotNull('city_id')
  3963. ->whereNotNull('department_id')
  3964. ->where(function ($query) use ($data) {
  3965. $query->where(function ($subQuery) use ($data) {
  3966. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3967. });
  3968. })
  3969. ->where(function ($query) use ($data) {
  3970. $query->where(function ($subQuery) use ($data) {
  3971. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3972. });
  3973. })
  3974. ->pluck('user_id')->toArray();
  3975. $user_id = array_unique($user_id);
  3976. $chat_ids = $user_id;
  3977. $user_id = json_encode($user_id);
  3978. $data['re_user_ids'] = $user_id;
  3979. $this->sendMessage([
  3980. 'talk_type' => 700,
  3981. 'title' => $data['title'],
  3982. 'content' => '提交了审核',
  3983. 'messageType' => 5,
  3984. ]);
  3985. $result = Notice::insertGetId($data);
  3986. if (empty($result)) {
  3987. return Result::error("添加失败", 0);
  3988. }
  3989. return Result::success($result);
  3990. }
  3991. public function updateNotice(array $data): array
  3992. {
  3993. date_default_timezone_set('Asia/Shanghai');
  3994. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  3995. $user_id = UserInfo::
  3996. //city_id不是null
  3997. whereNotNull('city_id')
  3998. ->whereNotNull('department_id')
  3999. ->where(function ($query) use ($data) {
  4000. $query->where(function ($subQuery) use ($data) {
  4001. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4002. });
  4003. })
  4004. ->where(function ($query) use ($data) {
  4005. $query->where(function ($subQuery) use ($data) {
  4006. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4007. });
  4008. })
  4009. ->pluck('user_id')->toArray();
  4010. $user_id = array_unique($user_id);
  4011. $user_id = json_encode($user_id);
  4012. $data['re_user_ids'] = $user_id;
  4013. $data['updated_at'] = date('Y-m-d H:i:s');
  4014. $this->sendMessage([
  4015. 'talk_type' => 700,
  4016. 'title' => $data['title'],
  4017. 'content' => '提交了审核',
  4018. 'messageType' => 5,
  4019. ]);
  4020. $result = Notice::where('id', $data['id'])->update($data);
  4021. return Result::success($result);
  4022. }
  4023. public function getNoticeList(array $data): array
  4024. {
  4025. $where = [];
  4026. //title
  4027. if (isset($data['title']) && !empty($data['title'])) {
  4028. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4029. }
  4030. //level
  4031. if (isset($data['level']) && !empty($data['level'])) {
  4032. $where[] = ['notice.level', '=', $data['level']];
  4033. }
  4034. //status
  4035. if (isset($data['status']) && !empty($data['status'])) {
  4036. $where[] = ['notice.status', '=', $data['status']];
  4037. }
  4038. //type
  4039. if (isset($data['type']) && !empty($data['type'])) {
  4040. $where[] = ['notice.type', '=', $data['type']];
  4041. }
  4042. var_dump($data, '------------11111-2----test---------');
  4043. if ($data['type_id'] == 10000) {
  4044. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4045. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4046. })
  4047. ->where($where)
  4048. ->orderBy('updated_at', 'desc')
  4049. ->limit($data['page_size'])
  4050. ->offset(($data['page'] - 1) * $data['page_size'])
  4051. ->get();
  4052. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4053. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4054. })
  4055. ->where($where)
  4056. ->orderBy('updated_at', 'desc')
  4057. ->count();
  4058. } else {
  4059. $result = Notice::where($where)
  4060. // ->where('user_id', $data['user_id'])
  4061. ->Where(function ($query) use ($data) {
  4062. $query->Where(function ($q) use ($data) {
  4063. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4064. ->orWhere('notice.user_id', $data['user_id']);
  4065. });
  4066. })
  4067. ->when(!empty($data['status1']), function ($query) use ($data) {
  4068. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4069. })
  4070. ->orderBy('updated_at', 'desc')
  4071. ->limit($data['page_size'])
  4072. ->offset(($data['page'] - 1) * $data['page_size'])
  4073. ->get();
  4074. $total = Notice::where($where)
  4075. ->when(!empty($data['status1']), function ($query) use ($data) {
  4076. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4077. })
  4078. // ->where('user_id', $data['user_id'])
  4079. ->Where(function ($query) use ($data) {
  4080. $query->Where(function ($q) use ($data) {
  4081. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4082. ->orWhere('notice.user_id', $data['user_id']);
  4083. });
  4084. })
  4085. ->count();
  4086. }
  4087. if (empty($result)) {
  4088. return Result::error("查询失败", 0);
  4089. }
  4090. $data = [
  4091. 'rows' => $result,
  4092. 'count' => $total,
  4093. ];
  4094. return Result::success($data);
  4095. }
  4096. public function getNoticeDetail(array $data): array
  4097. {
  4098. $result = Notice::where('id', $data['id'])->first();
  4099. if (empty($result)) {
  4100. return Result::error("查询失败", 0);
  4101. }
  4102. return Result::success($result);
  4103. }
  4104. public function deleteNotice(array $data): array
  4105. {
  4106. $notice = Notice::where('id', $data['id'])->first();
  4107. if (empty($notice)) {
  4108. return Result::error("删除失败", 0);
  4109. }
  4110. $chat_group_id = $notice->group_id;
  4111. if ($chat_group_id) {
  4112. //删除群聊
  4113. ChatGroups::where('id', $chat_group_id)->delete();
  4114. //删除群成员
  4115. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4116. //删除群聊记录
  4117. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4118. }
  4119. $result = Notice::where('id', $data['id'])->delete();
  4120. return Result::success($result);
  4121. }
  4122. public function getComplaintList(array $data): array
  4123. {
  4124. var_dump($data, '00000001000000000000');
  4125. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4126. unset($data['type_id']);
  4127. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4128. $where = [];
  4129. if ($type_id != 10000 && empty($data['deal_user'])) {
  4130. $where['complaint.user_id'] = $user_id;
  4131. }
  4132. if (!empty($data['title'])) {
  4133. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4134. }
  4135. if (!empty($data['department_id'])) {
  4136. $where['complaint.department_id'] = $data['department_id'];
  4137. }
  4138. if (!empty($data['deal'])) {
  4139. $where['complaint.deal'] = $data['deal'];
  4140. }
  4141. if (!empty($data['status'])) {
  4142. $where['complaint.status'] = $data['status'];
  4143. }
  4144. var_dump(!empty($data['deal_user']), '----------1');
  4145. var_dump($where, '----------2');
  4146. $result = Complaint::where($where)
  4147. ->when(!empty($data['status1']), function ($query) use ($data) {
  4148. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4149. })
  4150. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4151. //json re_user_ids data[user_id]是不是在里面
  4152. $query->Where(function ($q) use ($data) {
  4153. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4154. ->where('complaint.status', 2);
  4155. });
  4156. })
  4157. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4158. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4159. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4160. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4161. ->orderBy('updated_at', 'desc')
  4162. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4163. //sql输出
  4164. if (empty($result)) {
  4165. return Result::error("暂无投诉信息", 0);
  4166. }
  4167. // 取出数据
  4168. $rows = $result->items();
  4169. $count = $result->total();
  4170. $responseData = [
  4171. 'rows' => $rows,
  4172. 'count' => $count,
  4173. ];
  4174. return Result::success($responseData);
  4175. }
  4176. public function getComplaintInfo(array $data): array
  4177. {
  4178. $result = Complaint::where('id', $data['id'])->first();
  4179. if (empty($result)) {
  4180. return Result::error("查询失败", 0);
  4181. }
  4182. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4183. $re_user_ids = json_decode($result['re_user_ids'], true);
  4184. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4185. //如果已经存在,就不再添加
  4186. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4187. $read_id = json_decode($result['read_id'], true);
  4188. if (!is_array($read_id)) {
  4189. $read_id = [];
  4190. }
  4191. if (!in_array($data['user_id'], $read_id)) {
  4192. $read_id[] = $data['user_id'];
  4193. $result['read_id'] = json_encode($read_id);
  4194. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4195. }
  4196. } else {
  4197. //如果不存在,就添加
  4198. $result['read_id'] = json_encode([$data['user_id']]);
  4199. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4200. }
  4201. }
  4202. return Result::success($result);
  4203. }
  4204. public function addComplaint(array $data): array
  4205. {
  4206. date_default_timezone_set('Asia/Shanghai');
  4207. $data['created_at'] = date('Y-m-d H:i:s');
  4208. $data['updated_at'] = date('Y-m-d H:i:s');
  4209. $this->sendMessage([
  4210. 'talk_type' => 800,
  4211. 'title' => $data['title'],
  4212. 'content' => '提交了审核',
  4213. 'messageType' => 6,
  4214. ]);
  4215. $result = Complaint::create($data);
  4216. return Result::success($result);
  4217. }
  4218. public function updateComplaint(array $data): array
  4219. {
  4220. date_default_timezone_set('Asia/Shanghai');
  4221. $data['updated_at'] = date('Y-m-d H:i:s');
  4222. $user_id = $data['user_id'] ?? 0;
  4223. $type_id = $data['type_id'] ?? 0;
  4224. unset($data['user_id']);
  4225. unset($data['type_id']);
  4226. $this->sendMessage([
  4227. 'talk_type' => 800,
  4228. 'title' => $data['title'],
  4229. 'content' => '提交了审核',
  4230. 'messageType' => 6,
  4231. ]);
  4232. $result = Complaint::where('id', $data['id'])->update($data);
  4233. return Result::success($result);
  4234. }
  4235. public function deleteComplaint(array $data): array
  4236. {
  4237. $result = Complaint::where('id', $data['id'])->delete();
  4238. return Result::success($result);
  4239. }
  4240. public function getComplainInfo(array $data): array
  4241. {
  4242. $result = Complaint::where('id', $data['id'])->first();
  4243. if (empty($result)) {
  4244. return Result::error("查询失败", 0);
  4245. }
  4246. return Result::success($result);
  4247. }
  4248. public function updateComplaintStatus(array $data): array
  4249. {
  4250. date_default_timezone_set('Asia/Shanghai');
  4251. $data['updated_at'] = date('Y-m-d H:i:s');
  4252. $user_id = $data['user_id'] ?? 0;
  4253. $type_id = $data['type_id'] ?? 0;
  4254. unset($data['user_id']);
  4255. unset($data['type_id']);
  4256. //处理, 写入处理人
  4257. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4258. $data['real_deal_user'] = $user_id;
  4259. }
  4260. //如果是deal 23,则判断是不是处理人
  4261. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4262. $complaintInof = Complaint::where('id', $data['id'])
  4263. ->where('real_deal_user', $user_id)
  4264. ->first();
  4265. if (empty($complaintInof)) {
  4266. return Result::error("处理人错误", 0);
  4267. }
  4268. }
  4269. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4270. if ($data['status'] == 1) {
  4271. $this->sendMessage([
  4272. 'talk_type' => 800,
  4273. 'title' => $complaintInfo['title'],
  4274. 'content' => '提交了审核',
  4275. 'messageType' => 6,
  4276. ]);
  4277. }
  4278. if ($data['status'] == 2 && !isset($data['deal'])) {
  4279. $this->sendMessage([
  4280. 'talk_type' => 801,
  4281. 'title' => $complaintInfo['title'],
  4282. 'content' => '审核通过',
  4283. 'messageType' => 6,
  4284. 'user_id' => $complaintInfo['user_id'],
  4285. ]);
  4286. $this->sendMessage([
  4287. 'talk_type' => 802,
  4288. 'title' => $complaintInfo['title'],
  4289. 'content' => '待处理',
  4290. 'messageType' => 6,
  4291. 'user_id' => $complaintInfo['re_user_ids'],
  4292. ]);
  4293. }
  4294. if ($data['status'] == 3 && !isset($data['deal'])) {
  4295. $this->sendMessage([
  4296. 'talk_type' => 801,
  4297. 'title' => $complaintInfo['title'],
  4298. 'content' => '审核拒绝',
  4299. 'messageType' => 6,
  4300. 'user_id' => $complaintInfo['user_id'],
  4301. ]);
  4302. }
  4303. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4304. $this->sendMessage([
  4305. 'talk_type' => 802,
  4306. 'title' => $complaintInfo['title'],
  4307. 'content' => '处理中',
  4308. 'messageType' => 6,
  4309. 'user_id' => $complaintInfo['re_user_ids'],
  4310. ]);
  4311. }
  4312. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4313. $this->sendMessage([
  4314. 'talk_type' => 802,
  4315. 'title' => $complaintInfo['title'],
  4316. 'content' => '不予处理',
  4317. 'messageType' => 6,
  4318. 'user_id' => $complaintInfo['re_user_ids'],
  4319. ]);
  4320. }
  4321. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4322. $this->sendMessage([
  4323. 'talk_type' => 802,
  4324. 'title' => $complaintInfo['title'],
  4325. 'content' => '已完结',
  4326. 'messageType' => 6,
  4327. 'user_id' => $complaintInfo['re_user_ids'],
  4328. ]);
  4329. }
  4330. $result = complaint::where('id', $data['id'])->update($data);
  4331. return Result::success($result);
  4332. }
  4333. public function updateGoodStatus(array $data): array
  4334. {
  4335. $user_id = $data['user_id'] ?? 0;
  4336. $type_id = $data['type_id'] ?? 0;
  4337. unset($data['user_id']);
  4338. unset($data['type_id']);
  4339. $goodInfo = Good::where('id', $data['id'])->first();
  4340. if ($data['status'] == 2) {
  4341. $this->sendMessage([
  4342. 'talk_type' => 201,
  4343. 'title' => $goodInfo['name'],
  4344. 'content' => '审核通过',
  4345. 'messageType' => 3,
  4346. 'user_id' => $goodInfo['user_id'],
  4347. ]);
  4348. }
  4349. if ($data['status'] == 3) {
  4350. $this->sendMessage([
  4351. 'talk_type' => 201,
  4352. 'title' => $goodInfo['name'],
  4353. 'content' => '审核拒绝',
  4354. 'messageType' => 3,
  4355. 'user_id' => $goodInfo['user_id'],
  4356. ]);
  4357. }
  4358. if ($data['status'] == 1) {
  4359. $this->sendMessage([
  4360. 'talk_type' => 200,
  4361. 'title' => $goodInfo['name'],
  4362. 'content' => '提交了审核',
  4363. 'messageType' => 3,
  4364. ]);
  4365. }
  4366. $result = Good::where('id', $data['id'])->update($data);
  4367. return Result::success($result);
  4368. }
  4369. public function updateJobHuntingStatus(array $data): array
  4370. {
  4371. $user_id = $data['user_id'] ?? 0;
  4372. $type_id = $data['type_id'] ?? 0;
  4373. unset($data['user_id']);
  4374. unset($data['type_id']);
  4375. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4376. if ($data['status'] == 2) {
  4377. $this->sendMessage([
  4378. 'talk_type' => 601,
  4379. 'title' => $jogHuntingInfo['name'],
  4380. 'content' => '审核通过',
  4381. 'messageType' => 11,
  4382. 'user_id' => $jogHuntingInfo['user_id'],
  4383. ]);
  4384. }
  4385. if ($data['status'] == 3) {
  4386. $this->sendMessage([
  4387. 'talk_type' => 601,
  4388. 'title' => $jogHuntingInfo['name'],
  4389. 'content' => '审核拒绝',
  4390. 'messageType' => 11,
  4391. 'user_id' => $jogHuntingInfo['user_id'],
  4392. ]);
  4393. }
  4394. if ($data['status'] == 1) {
  4395. $this->sendMessage([
  4396. 'talk_type' => 600,
  4397. 'title' => $jogHuntingInfo['name'],
  4398. 'content' => '提交了审核',
  4399. 'messageType' => 11,
  4400. ]);
  4401. }
  4402. $result = JobHunting::where('id', $data['id'])->update($data);
  4403. return Result::success($result);
  4404. }
  4405. public function updateNoticeStatus(array $data): array
  4406. {
  4407. $user_id = $data['user_id'] ?? 0;
  4408. $type_id = $data['type_id'] ?? 0;
  4409. unset($data['user_id']);
  4410. unset($data['type_id']);
  4411. //查询公告
  4412. $notice = Notice::where('id', $data['id'])->first();
  4413. if (empty($notice)) {
  4414. return Result::error("公告不存在", 0);
  4415. }
  4416. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4417. if ($data['status'] == 2 && $notice['is_group'] == 1 && $notice['status'] == 1 && empty($notice['group_id'])) {
  4418. //chat_group
  4419. $group_id = PublicData::uuid();
  4420. $groupData = [
  4421. 'id' => $group_id,
  4422. 'creator_id' => $notice['user_id'],
  4423. 'group_name' => $notice['group_name'] ?? '',
  4424. 'profile' => $notice['profile'] ?? 0,
  4425. ];
  4426. var_dump($groupData, '-----------------groupData-------');
  4427. $groupResult = ChatGroups::insertGetId($groupData);
  4428. var_dump($groupResult, '-----------------groupid-------');
  4429. $groupMemberData = [
  4430. 'id' => PublicData::uuid(),
  4431. 'user_id' => $notice['user_id'],
  4432. 'group_id' => $group_id,
  4433. 'leader' => 2,
  4434. ];
  4435. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4436. //$chat_ids 去除掉$data['user_id']
  4437. $chat_ids = json_decode($notice['re_user_ids'], true);
  4438. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4439. //插入群成员表
  4440. $groupMemberDataUser = [];
  4441. $chatData = [];
  4442. foreach ($chat_ids as $key => $value) {
  4443. $groupMemberDataUser[] = [
  4444. 'id' => PublicData::uuid(),
  4445. 'user_id' => $value,
  4446. 'group_id' => $group_id,
  4447. 'leader' => 1,
  4448. ];
  4449. $chatData[] = [
  4450. 'user_id' => $value,
  4451. 'msg_type' => 1,
  4452. 'receiver_id' => $group_id,
  4453. 'content' => '通过通知创建群聊',
  4454. 'group_receiver_id' => $notice['user_id'],
  4455. 'action' => 'recieved',
  4456. 'created_at' => date('Y-m-d H:i:s'),
  4457. ];
  4458. }
  4459. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4460. ChatGroupsMember::insert($groupMemberDataUser);
  4461. //插入一条管理员聊天记录
  4462. $chatData[] = [
  4463. 'user_id' => $notice['user_id'],
  4464. 'msg_type' => 1,
  4465. 'receiver_id' => $group_id,
  4466. 'content' => '通过通知创建群聊',
  4467. 'group_receiver_id' => $notice['user_id'],
  4468. 'action' => 'said',
  4469. 'created_at' => date('Y-m-d H:i:s'),
  4470. ];
  4471. var_dump($chatData, '-----------------chatData-------');
  4472. $chatResult = ChatRecords::insert($chatData);
  4473. //更新result的 group_id
  4474. $data['group_id'] = $group_id;
  4475. Notice::where(['id' => $data['id']])->update($data);
  4476. }
  4477. $result = Notice::where('id', $data['id'])->update($data);
  4478. $noticeInfo = Notice::where('id', $data['id'])->first();
  4479. if ($data['status'] == 2) {
  4480. $this->sendMessage([
  4481. 'talk_type' => 701,
  4482. 'title' => $noticeInfo['title'],
  4483. 'content' => '审核通过',
  4484. 'messageType' => 3,
  4485. 'user_id' => $noticeInfo['user_id'],
  4486. ]);
  4487. }
  4488. if ($data['status'] == 3) {
  4489. $this->sendMessage([
  4490. 'talk_type' => 701,
  4491. 'title' => $noticeInfo['title'],
  4492. 'content' => '审核拒绝',
  4493. 'messageType' => 3,
  4494. 'user_id' => $noticeInfo['user_id'],
  4495. ]);
  4496. }
  4497. if ($data['status'] == 1) {
  4498. $this->sendMessage([
  4499. 'talk_type' => 700,
  4500. 'title' => $noticeInfo['title'],
  4501. 'content' => '提交了审核',
  4502. 'messageType' => 3,
  4503. ]);
  4504. }
  4505. return Result::success($result);
  4506. }
  4507. public function getDUser(array $data): array
  4508. {
  4509. if (!empty($data['ids'])) {
  4510. $user = User::whereIn('id', $data['ids'])->getall();
  4511. if (empty($user)) {
  4512. return Result::error('无数据', 0);
  4513. }
  4514. return Result::success($user);
  4515. }
  4516. $where = [];
  4517. if (!empty($data['department_id'])) {
  4518. $where['department_id'] = $data['department_id'];
  4519. }
  4520. if (!empty($data['city_id'])) {
  4521. $where['city_id'] = $data['city_id'];
  4522. }
  4523. $result = User::where('type_id', 2)
  4524. ->where('status', 1)
  4525. ->where($where)
  4526. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4527. ->get();
  4528. if (empty($result)) {
  4529. return Result::error("查询失败", 0);
  4530. }
  4531. return Result::success($result);
  4532. }
  4533. /**
  4534. * 验证导航名称是否重复
  4535. * @return void
  4536. */
  4537. public function checkCategoryName(array $data): array
  4538. {
  4539. $result = Category::when($data, function ($query) use ($data) {
  4540. if (isset($data['name']) && $data['name']) {
  4541. $query->where("name", $data['name']);
  4542. }
  4543. if (isset($data['id']) && $data['id']) {
  4544. $query->where("id", "!=", $data['id']);
  4545. }
  4546. })->first();
  4547. if ($result) {
  4548. return Result::error("已存在");
  4549. } else {
  4550. return Result::success();
  4551. }
  4552. }
  4553. //20250226 产品列表
  4554. // 20250306 -------招聘--------fr
  4555. /*
  4556. * 招聘列表
  4557. * */
  4558. public function getJobRecruitingList(array $data): array
  4559. {
  4560. $where = [];
  4561. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4562. if ($data['checkout'] == 0) {
  4563. $job_status = [0, 2];
  4564. } else {
  4565. $job_status = [1];
  4566. }
  4567. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4568. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4569. }
  4570. $user = User::where('id', $data['user_id'])->first();
  4571. if (empty($user)) {
  4572. return Result::error("用户不存在", 0);
  4573. }
  4574. // 3:企业会员
  4575. if ($user['type_id'] == 3) {
  4576. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4577. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4578. }
  4579. // 如果 $where 为空,则不添加 where 条件
  4580. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4581. return $query->where($where);
  4582. })
  4583. ->whereIn('job_recruiting.status', $job_status)
  4584. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4585. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4586. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4587. ->orderBy("updated_at", "desc")
  4588. ->offset(($data['page'] - 1) * $data['page_size'])
  4589. ->limit($data['page_size'])
  4590. ->get()
  4591. ->all();
  4592. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4593. return $query->where($where);
  4594. })
  4595. ->whereIn('job_recruiting.status', $job_status)
  4596. ->count();
  4597. if (empty($result)) {
  4598. return Result::error("暂无招聘信息", 0);
  4599. }
  4600. return Result::success($result);
  4601. }
  4602. /*
  4603. * 招聘信息添加
  4604. * */
  4605. public function addJobRecruiting(array $data): array
  4606. {
  4607. // return Result::success($data);
  4608. $user = User::where('user.id', $data['user_id'])
  4609. ->where('user.status', 1)
  4610. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4611. ->select(
  4612. 'user.type_id',
  4613. 'user.mobile',
  4614. 'user.email',
  4615. 'user_info.business_name',
  4616. 'user_info.company_hy_id',
  4617. 'user_info.company_nature',
  4618. 'user_info.company_size',
  4619. 'user_info.introduction',
  4620. 'user_info.real_name',
  4621. 'user_info.company_url',
  4622. 'user_info.address_arr_id',
  4623. 'user_info.address'
  4624. )
  4625. ->first();
  4626. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4627. return Result::error("用户不存在", 0);
  4628. }
  4629. $web = Website::where('id', $data['website_id'])->first();
  4630. if (empty($web)) {
  4631. return Result::error("网站不存在", 0);
  4632. }
  4633. // return Result::success($user);
  4634. $data['action_id'] = $data['user_id'];
  4635. $data['user_type'] = $user['type_id'];
  4636. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4637. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4638. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4639. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4640. // 公司地址 管理员必填
  4641. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4642. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4643. // 管理员-企业相关信息
  4644. $company = [
  4645. // 'user_id' => $data['user_id']?? null,
  4646. 'business_name' => $data['business_name'] ?? null,
  4647. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4648. 'company_size' => $data['company_size'] ?? null,
  4649. 'company_nature' => $data['company_nature'] ?? null,
  4650. 'introduction' => $data['introduction'] ?? null,
  4651. 'real_name' => $data['real_name'] ?? null,
  4652. 'mobile' => $data['mobile'] ?? null,
  4653. 'company_url' => $data['company_url'] ?? null,
  4654. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4655. 'address' => $data['address'] ?? null,
  4656. 'email' => $data['email'] ?? null,
  4657. ];
  4658. //去掉相关企业信息
  4659. $job = array_diff_key($data, array_flip(array_keys($company)));
  4660. Db::beginTransaction();
  4661. try {
  4662. // 先添加职位相关信息
  4663. if ($user['type_id'] == 10000) {
  4664. $job['status'] = 1;
  4665. }
  4666. if (empty($data['experience']) || $data['experience'] == '') {
  4667. $job['experience'] = null;
  4668. } else {
  4669. $job['experience'] = $data['experience'];
  4670. }
  4671. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  4672. $this->sendMessage([
  4673. 'talk_type' => 500,
  4674. 'title' => $data['title'],
  4675. 'content' => '提交了审核',
  4676. 'messageType' => 10,
  4677. ]);
  4678. }
  4679. $jobId = JobRecruiting::insertGetId($job);
  4680. if (empty($jobId)) {
  4681. Db::rollBack();
  4682. return Result::error("添加失败");
  4683. }
  4684. // 添加公司信息
  4685. $company['user_id'] = $data['user_id'] ?? null;
  4686. $company['job_id'] = $jobId;
  4687. $company['user_type'] = $user['type_id'] ?? null;
  4688. $company['website_id'] = $data['website_id'] ?? null;
  4689. if ($user['type_id'] == 10000) {
  4690. // 管理员添加企业信息
  4691. // return Result::success($company);
  4692. $companyId = JobCompany::insertGetId($company);
  4693. if (empty($companyId)) {
  4694. Db::rollBack();
  4695. return Result::error("添加失败");
  4696. }
  4697. } else {
  4698. // 企业会员添加企业信息
  4699. $company = [
  4700. 'user_id' => $data['user_id'] ?? null,
  4701. 'business_name' => $user['business_name'] ?? null,
  4702. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4703. 'company_size' => $user['company_size'] ?? null,
  4704. 'company_nature' => $user['company_nature'] ?? null,
  4705. 'introduction' => $user['introduction'] ?? null,
  4706. 'real_name' => $user['real_name'] ?? null,
  4707. 'mobile' => $user['mobile'] ?? null,
  4708. 'company_url' => $user['company_url'] ?? null,
  4709. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4710. 'address' => $user['address'] ?? null,
  4711. 'email' => $user['email'] ?? null,
  4712. 'website_id' => $data['website_id'] ?? null,
  4713. 'user_type' => $user['type_id'] ?? null,
  4714. 'job_id' => $jobId,
  4715. ];
  4716. $companyId = JobCompany::insertGetId($company);
  4717. if (empty($companyId)) {
  4718. Db::rollBack();
  4719. return Result::error("添加失败");
  4720. }
  4721. // return Result::success($company);
  4722. }
  4723. Db::commit();
  4724. } catch (\Exception $e) {
  4725. Db::rollBack();
  4726. return Result::error($e->getMessage(), 0);
  4727. }
  4728. $result = [
  4729. 'job_id' => $jobId,
  4730. 'company_id' => $companyId,
  4731. ];
  4732. if (empty($result)) {
  4733. return Result::error("添加失败", 0);
  4734. }
  4735. return Result::success($result);
  4736. }
  4737. /*
  4738. * 获取招聘信息详情
  4739. * */
  4740. public function getJobRecruitingInfo(array $data): array
  4741. {
  4742. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4743. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4744. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4745. ->select(
  4746. 'job_recruiting.*',
  4747. 'website.website_name as website_name',
  4748. 'job_company.business_name',
  4749. 'job_company.company_hy_id',
  4750. 'job_company.company_size',
  4751. 'job_company.company_nature',
  4752. 'job_company.introduction',
  4753. 'job_company.real_name',
  4754. 'job_company.mobile',
  4755. 'job_company.company_url',
  4756. 'job_company.address_arr_id',
  4757. 'job_company.address',
  4758. 'job_company.email'
  4759. )
  4760. ->first();
  4761. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4762. if (!empty($cityId)) {
  4763. if (isset($cityId[1]) && $cityId[1] != null) {
  4764. $city = District::where('id', $cityId[1])->first(['name']);
  4765. } else {
  4766. $city = District::where('id', $cityId[0])->first(['name']);
  4767. }
  4768. $result['city'] = $city['name'] ?? '';
  4769. }
  4770. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4771. if (is_array($addressId) && !empty($addressId)) {
  4772. $address = District::whereIn('id', $addressId)
  4773. ->orderBy('level', 'asc')
  4774. ->get(['name'])
  4775. ->pluck('name')
  4776. ->implode('');
  4777. // $job->address_name = $address ?? '';
  4778. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4779. }
  4780. if (empty($result)) {
  4781. return Result::error("招聘信息不存在", 0);
  4782. }
  4783. // return Result::success($job);
  4784. return Result::success($result);
  4785. }
  4786. /*
  4787. * 修改招聘信息
  4788. * */
  4789. public function upJobRecruiting(array $data): array
  4790. {
  4791. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4792. // return Result::success($job);
  4793. if (empty($job)) {
  4794. return Result::error("招聘信息不存在", 0);
  4795. }
  4796. $user = User::where('id', $data['user_id'])->first();
  4797. // return Result::success($user);
  4798. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4799. return Result::error("用户不存在", 0);
  4800. }
  4801. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4802. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4803. }
  4804. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4805. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4806. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4807. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4808. // 公司地址 管理员必填
  4809. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4810. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4811. // 管理员-企业相关信息
  4812. $company = [
  4813. 'business_name' => $data['business_name'] ?? null,
  4814. 'company_hy_id' => $data['hy_id'] ?? null,
  4815. 'company_size' => $data['company_size'] ?? null,
  4816. 'company_nature' => $data['company_nature'] ?? null,
  4817. 'introduction' => $data['introduction'] ?? null,
  4818. 'real_name' => $data['real_name'] ?? null,
  4819. 'mobile' => $data['mobile'] ?? null,
  4820. 'company_url' => $data['company_url'] ?? null,
  4821. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4822. 'address' => $data['address'] ?? null,
  4823. 'email' => $data['email'] ?? null,
  4824. ];
  4825. //去掉相关企业信息
  4826. $data = array_diff_key($data, array_flip(array_keys($company)));
  4827. $jobId = $data['id'];
  4828. $web = $data['website_id'];
  4829. $data['action_id'] = $data['user_id'];
  4830. unset($data['user_id']);
  4831. unset($data['user_type']);
  4832. unset($data['id']);
  4833. unset($data['website_id']);
  4834. // return Result::success($data);
  4835. Db::beginTransaction();
  4836. try {
  4837. // 管理员修改招聘信息
  4838. if ($user['type_id'] == 10000) {
  4839. $data['website_id'] = $web;
  4840. $company['website_id'] = $data['website_id'];
  4841. $data['status'] = 1;
  4842. } else {
  4843. $data['status'] = 0;
  4844. }
  4845. if (empty($data['experience']) || $data['experience'] == '') {
  4846. $job['experience'] = null;
  4847. } else {
  4848. $job['experience'] = $data['experience'];
  4849. }
  4850. // Db::rollBack();
  4851. // return Result::success($company);
  4852. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  4853. $this->sendMessage([
  4854. 'talk_type' => 500,
  4855. 'title' => $data['title'],
  4856. 'content' => '提交了审核',
  4857. 'messageType' => 10,
  4858. ]);
  4859. }
  4860. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4861. if (empty($result['job'])) {
  4862. Db::rollBack();
  4863. return Result::error("修改招聘信息失败");
  4864. }
  4865. // 管理员修改企业相关信息
  4866. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4867. if (empty($result['company'])) {
  4868. Db::rollBack();
  4869. return Result::error("修改企业相关信息失败");
  4870. }
  4871. Db::commit();
  4872. // return Result::success($result);
  4873. } catch (\Exception $e) {
  4874. Db::rollBack();
  4875. return Result::error($e->getMessage(), 0);
  4876. }
  4877. return Result::success($result);
  4878. }
  4879. /*
  4880. * 招聘信息删除
  4881. * */
  4882. public function delJobRecruiting(array $data): array
  4883. {
  4884. $user = User::where('id', $data['user_id'])->first();
  4885. if (empty($user)) {
  4886. return Result::error("用户不存在", 0);
  4887. }
  4888. $job = JobRecruiting::where('id', $data['id'])->first();
  4889. if (empty($job)) {
  4890. return Result::error("招聘信息不存在", 0);
  4891. }
  4892. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4893. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4894. }
  4895. Db::beginTransaction();
  4896. try {
  4897. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4898. if (empty($result['job'])) {
  4899. Db::rollBack();
  4900. return Result::error("删除招聘信息失败");
  4901. }
  4902. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4903. if (empty($result['company'])) {
  4904. Db::rollBack();
  4905. return Result::error("删除企业相关信息失败");
  4906. }
  4907. Db::commit();
  4908. } catch (\Exception $e) {
  4909. Db::rollBack();
  4910. return Result::error($e->getMessage(), 0);
  4911. }
  4912. return Result::success($result);
  4913. }
  4914. /*
  4915. * 获取公司信息
  4916. * */
  4917. public function getJobCompany(array $data): array
  4918. {
  4919. $user = User::where('user.id', $data['user_id'])
  4920. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4921. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4922. ->first();
  4923. // return Result::success($user);
  4924. if (empty($user)) {
  4925. return Result::error("用户不存在", 0);
  4926. }
  4927. if ($user['type_id'] == 3) {
  4928. $result = [
  4929. // 'id' => 0,
  4930. 'user_id' => $data['user_id'],
  4931. 'website_id' => $data['website_id'],
  4932. 'business_name' => $user['business_name'], // 企业名称
  4933. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4934. 'company_nature' => $user['company_nature'], // 公司性质
  4935. 'company_size' => $user['company_size'], // 公司规模
  4936. 'introduction' => $user['introduction'], // 公司简介
  4937. 'real_name' => $user['real_name'], // 企业联系人
  4938. 'mobile' => $user['mobile'], // 企业联系电话
  4939. 'company_url' => $user['company_url'], // 企业网址
  4940. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4941. 'address' => $user['address'], // 企业地址
  4942. 'email' => $user['email'], // 企业邮箱
  4943. ];
  4944. } else {
  4945. return Result::error("用户类型错误", 0);
  4946. }
  4947. if (empty($result)) {
  4948. return Result::error("公司信息不存在", 0);
  4949. }
  4950. return Result::success($result);
  4951. }
  4952. /*
  4953. * 修改公司信息
  4954. * */
  4955. public function upJobCompany(array $data): array
  4956. {
  4957. // return Result::success($data);
  4958. $user = User::where('user.id', $data['user_id'])
  4959. ->where('user.status', 1)
  4960. ->select('user.user_name', 'user.type_id')
  4961. ->first();
  4962. if (empty($user)) {
  4963. return Result::error("用户不存在", 0);
  4964. }
  4965. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4966. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  4967. $company = [
  4968. 'business_name' => $data['business_name'], // 企业名称
  4969. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4970. 'company_nature' => $data['company_nature'], // 公司性质
  4971. 'company_size' => $data['company_size'], // 公司规模
  4972. 'introduction' => $data['introduction'], // 公司简介
  4973. // 'real_name' => $data['real_name'], // 企业联系人
  4974. 'company_url' => $data['company_url'], // 企业网址
  4975. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4976. 'address' => $data['address'], // 企业详细地址
  4977. // 'email' => $data['email'], // 企业邮箱
  4978. ];
  4979. if ($user['type_id'] == 3) {
  4980. Db::beginTransaction();
  4981. try {
  4982. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  4983. 'business_name' => $data['business_name'], // 企业名称
  4984. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4985. 'company_nature' => $data['company_nature'], // 公司性质
  4986. 'company_size' => $data['company_size'], // 公司规模
  4987. 'introduction' => $data['introduction'], // 公司简介
  4988. // 'real_name' => $data['real_name'], // 企业联系人
  4989. 'company_url' => $data['company_url'], // 企业网址
  4990. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4991. 'address' => $data['address'], // 企业详细地址
  4992. ]);
  4993. if (empty($result['userinfo'])) {
  4994. Db::rollBack();
  4995. return Result::error('修改企业会员信息失败!');
  4996. }
  4997. $result['user'] = User::where('id', $data['user_id'])->update([
  4998. 'email' => $data['email'], // 企业邮箱
  4999. ]);
  5000. if (empty($result['user'])) {
  5001. Db::rollBack();
  5002. return Result::error('修改个人中心信息失败!');
  5003. }
  5004. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5005. if (!empty($job_company)) {
  5006. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5007. if (empty($result['job_company'])) {
  5008. Db::rollBack();
  5009. return Result::error('修改企业会员信息失败!');
  5010. }
  5011. }
  5012. Db::commit();
  5013. return Result::success($result);
  5014. } catch (\Exception $e) {
  5015. Db::rollBack();
  5016. return Result::error($e->getMessage(), 0);
  5017. }
  5018. } else {
  5019. return Result::error("用户类型错误", 0);
  5020. }
  5021. }
  5022. /*
  5023. * 获取省-市
  5024. * */
  5025. public function getJobRecruitingArea(array $data): array
  5026. {
  5027. if (isset($data['pid']) && $data['pid'] != null) {
  5028. $result = District::where('pid', $data['pid'])->get()->all();
  5029. } else {
  5030. $result = District::where('level', 1)->get()->all();
  5031. }
  5032. if (empty($result)) {
  5033. return Result::error("暂无此省市", 0);
  5034. }
  5035. return Result::success($result);
  5036. }
  5037. /*
  5038. * 获取行业分类
  5039. * */
  5040. public function getIndustry(array $data): array
  5041. {
  5042. $result = JobIndustry::get()->all();
  5043. if (empty($result)) {
  5044. return Result::error("暂无行业分类", 0);
  5045. }
  5046. return Result::success($result);
  5047. }
  5048. /*
  5049. * 获取职位
  5050. * */
  5051. public function getPositionList(array $data): array
  5052. {
  5053. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5054. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5055. } else {
  5056. $result = JobPosition::where('zwpid', 0)->get()->all();
  5057. }
  5058. if (empty($result)) {
  5059. return Result::error("暂无此职位", 0);
  5060. }
  5061. return Result::success($result);
  5062. }
  5063. /*
  5064. * 获取工作性质-菜单
  5065. * */
  5066. public function getJobNature(array $data): array
  5067. {
  5068. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5069. if (empty($result)) {
  5070. return Result::error("暂无工作性质", 0);
  5071. }
  5072. return Result::success($result);
  5073. }
  5074. /*
  5075. * 获取工作经验-菜单
  5076. * */
  5077. public function getExperience(array $data): array
  5078. {
  5079. $result = JobEnum::where('egroup', 'years')->get()->all();
  5080. if (empty($result)) {
  5081. return Result::error("暂无工作经验", 0);
  5082. }
  5083. return Result::success($result);
  5084. }
  5085. /*
  5086. * 获取学历-菜单
  5087. * */
  5088. public function getEducation(array $data): array
  5089. {
  5090. $result = JobEnum::where('egroup', 'education')->get()->all();
  5091. if (empty($result)) {
  5092. return Result::error("暂无学历", 0);
  5093. }
  5094. return Result::success($result);
  5095. }
  5096. /*
  5097. * 获取薪资-菜单
  5098. * */
  5099. public function getSalary(array $data): array
  5100. {
  5101. $result = JobEnum::where('egroup', 'income')->get()->all();
  5102. if (empty($result)) {
  5103. return Result::error("暂无薪资", 0);
  5104. }
  5105. return Result::success($result);
  5106. }
  5107. /*
  5108. * 获取语言-菜单
  5109. * */
  5110. public function getLanguage(array $data): array
  5111. {
  5112. $result = JobEnum::where('egroup', 'language')->get()->all();
  5113. if (empty($result)) {
  5114. return Result::error("暂无语言", 0);
  5115. }
  5116. return Result::success($result);
  5117. }
  5118. /*
  5119. * 获取掌握程度-菜单
  5120. * */
  5121. public function getLevel(array $data): array
  5122. {
  5123. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5124. if (empty($result)) {
  5125. return Result::error("暂无工作性质", 0);
  5126. }
  5127. return Result::success($result);
  5128. }
  5129. // 公司信息
  5130. /*
  5131. * 获取公司性质-菜单
  5132. * */
  5133. public function getCompanyNature(array $data): array
  5134. {
  5135. $result = JobNature::get()->all();
  5136. if (empty($result)) {
  5137. return Result::error("暂无公司性质", 0);
  5138. }
  5139. return Result::success($result);
  5140. }
  5141. /*
  5142. * 获取公司规模-菜单
  5143. * */
  5144. public function getCompanySize(array $data): array
  5145. {
  5146. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5147. if (empty($result)) {
  5148. return Result::error("暂无公司规模", 0);
  5149. }
  5150. return Result::success($result);
  5151. }
  5152. /*
  5153. * 招聘信息审核
  5154. * */
  5155. public function checkJobRecruiting(array $data): array
  5156. {
  5157. $user = User::where('id', $data['user_id'])->first();
  5158. if (empty($user)) {
  5159. return Result::error("用户不存在", 0);
  5160. }
  5161. $job = JobRecruiting::where('id', $data['id'])->first();
  5162. if (empty($job)) {
  5163. return Result::error("招聘信息不存在", 0);
  5164. }
  5165. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5166. if ($user['type_id'] != 10000) {
  5167. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5168. }
  5169. // 驳回原因
  5170. if ($data['status'] == 2) {
  5171. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5172. }
  5173. $data['action_id'] = $data['user_id'];
  5174. unset($data['user_id']);
  5175. if ($data['status'] == 1) {
  5176. $this->sendMessage([
  5177. 'talk_type' => 501,
  5178. 'title' => $job['title'],
  5179. 'content' => '审核通过',
  5180. 'messageType' => 10,
  5181. 'user_id' => $job['user_id'],
  5182. ]);
  5183. }
  5184. if ($data['status'] == 2) {
  5185. $this->sendMessage([
  5186. 'talk_type' => 501,
  5187. 'title' => $job['title'],
  5188. 'content' => '审核拒绝',
  5189. 'messageType' => 10,
  5190. 'user_id' => $job['user_id'],
  5191. ]);
  5192. }
  5193. if ($data['status'] == 0) {
  5194. $this->sendMessage([
  5195. 'talk_type' => 500,
  5196. 'title' => $job['title'],
  5197. 'content' => '提交了审核',
  5198. 'messageType' => 10,
  5199. ]);
  5200. }
  5201. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5202. if (empty($result)) {
  5203. return Result::error("审核失败", 0);
  5204. }
  5205. return Result::success($result);
  5206. }
  5207. public function myApplyList(array $data): array
  5208. {
  5209. var_dump($data, '------参数');
  5210. $user = User::where('id', $data['user_id'])->first();
  5211. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5212. return Result::error("用户不存在", 0);
  5213. }
  5214. // 1:个人会员 职场机会
  5215. if ($user['type_id'] == 1) {
  5216. $where['user_id'] = $user['id'];
  5217. }
  5218. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5219. $query->where('user_id', $user['id']);
  5220. })
  5221. ->pluck('recruit_id');
  5222. $where = [];
  5223. if (isset($data['salary']) && $data['salary'] != null) {
  5224. $where['job_recruiting.salary'] = $data['salary'];
  5225. }
  5226. if (isset($data['experience']) && $data['experience'] != null) {
  5227. $where['job_recruiting.experience'] = $data['experience'];
  5228. }
  5229. if (isset($data['business_name']) && $data['business_name'] != null) {
  5230. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5231. }
  5232. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5233. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5234. ->where($where);
  5235. // ->count();
  5236. $count = $query->count();
  5237. $query = clone $query;
  5238. $job = $query
  5239. ->leftJoin('job_enum as income_enum', function ($join) {
  5240. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5241. ->where('income_enum.egroup', 'income');
  5242. })
  5243. ->leftJoin('job_enum as years_enum', function ($join) {
  5244. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5245. ->where('years_enum.egroup', 'years');
  5246. })
  5247. // ->where($where)
  5248. ->orderBy('job_recruiting.updated_at', 'desc')
  5249. ->select(
  5250. 'job_recruiting.id',
  5251. 'job_recruiting.title',
  5252. 'job_company.business_name',
  5253. 'income_enum.evalue as salary_evalue',
  5254. 'income_enum.ename as salary_ename',
  5255. 'years_enum.evalue as experience_evalue',
  5256. 'years_enum.ename as experience_ename',
  5257. 'job_recruiting.updated_at'
  5258. )
  5259. ->offset(($data['page'] - 1) * $data['pageSize'])
  5260. ->limit($data['pageSize'])
  5261. ->get()
  5262. ->all();
  5263. if (empty($job)) {
  5264. return Result::error("暂无招聘信息", 0);
  5265. }
  5266. $result = [
  5267. 'row' => $job,
  5268. 'count' => $count,
  5269. ];
  5270. return Result::success($result);
  5271. }
  5272. /*
  5273. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5274. * */
  5275. public function getRecruitingList(array $data): array
  5276. {
  5277. $user = User::where('id', $data['user_id'])->first();
  5278. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5279. return Result::error("用户不存在", 0);
  5280. }
  5281. // 1:个人会员 职场机会
  5282. if ($user['type_id'] == 1) {
  5283. $where['user_id'] = $user['id'];
  5284. }
  5285. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5286. $query->where('receiver_id', $user['id']);
  5287. })
  5288. ->pluck('recruit_id');
  5289. // return Result::success($recruitingId);
  5290. $where = [];
  5291. if (isset($data['salary']) && $data['salary'] != null) {
  5292. $where['job_recruiting.salary'] = $data['salary'];
  5293. }
  5294. if (isset($data['experience']) && $data['experience'] != null) {
  5295. $where['job_recruiting.experience'] = $data['experience'];
  5296. }
  5297. if (isset($data['business_name']) && $data['business_name'] != null) {
  5298. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5299. }
  5300. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5301. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5302. ->where($where);
  5303. // ->count();
  5304. $count = $query->count();
  5305. $query = clone $query;
  5306. $job = $query
  5307. ->leftJoin('job_enum as income_enum', function ($join) {
  5308. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5309. ->where('income_enum.egroup', 'income');
  5310. })
  5311. ->leftJoin('job_enum as years_enum', function ($join) {
  5312. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5313. ->where('years_enum.egroup', 'years');
  5314. })
  5315. // ->where($where)
  5316. ->orderBy('job_recruiting.updated_at', 'desc')
  5317. ->select(
  5318. 'job_recruiting.id',
  5319. 'job_recruiting.title',
  5320. 'job_company.business_name',
  5321. 'income_enum.evalue as salary_evalue',
  5322. 'income_enum.ename as salary_ename',
  5323. 'years_enum.evalue as experience_evalue',
  5324. 'years_enum.ename as experience_ename',
  5325. 'job_recruiting.updated_at'
  5326. )
  5327. ->offset(($data['page'] - 1) * $data['pageSize'])
  5328. ->limit($data['pageSize'])
  5329. ->get()
  5330. ->all();
  5331. if (empty($job)) {
  5332. return Result::error("暂无招聘信息", 0);
  5333. }
  5334. $result = [
  5335. 'row' => $job,
  5336. 'count' => $count,
  5337. ];
  5338. return Result::success($result);
  5339. }
  5340. /*
  5341. * 获取企业会员-招聘信息列表
  5342. * */
  5343. public function getRecruitingInfo(array $data): array
  5344. {
  5345. $user = User::where('id', $data['user_id'])->first();
  5346. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5347. return Result::error("用户不存在", 0);
  5348. }
  5349. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5350. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5351. ->select(
  5352. 'job_recruiting.*',
  5353. 'job_company.business_name',
  5354. 'job_company.company_hy_id',
  5355. 'job_company.company_size',
  5356. 'job_company.company_nature',
  5357. 'job_company.introduction',
  5358. 'job_company.real_name',
  5359. 'job_company.mobile',
  5360. 'job_company.company_url',
  5361. 'job_company.address_arr_id',
  5362. 'job_company.address',
  5363. 'job_company.email'
  5364. )
  5365. ->get();
  5366. if (empty($recruiting)) {
  5367. return Result::error("暂无招聘信息", 0);
  5368. }
  5369. return Result::success($recruiting);
  5370. }
  5371. /*
  5372. * 获取企业会员-我的沟通
  5373. * */
  5374. public function getJobResumeList(array $data): array
  5375. {
  5376. $user = User::where('id', $data['user_id'])->first();
  5377. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5378. return Result::error("用户不存在", 0);
  5379. }
  5380. $where = [];
  5381. if (isset($data['salary']) && $data['salary'] != null) {
  5382. $where['job_hunting.salary'] = $data['salary'];
  5383. }
  5384. if (isset($data['user_name']) && $data['user_name'] != null) {
  5385. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5386. }
  5387. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5388. $query->where('job_resume.user_id', $user['id']);
  5389. })
  5390. ->when(!empty($where), function ($query) use ($where) {
  5391. $query->where($where);
  5392. })
  5393. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5394. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5395. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5396. ->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');
  5397. $count = $job->count();
  5398. if ($count == 0) {
  5399. return Result::error("暂无沟通记录", 0);
  5400. }
  5401. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5402. ->offset(($data['page'] - 1) * $data['pageSize'])
  5403. ->limit($data['pageSize'])
  5404. ->get();
  5405. if (empty($jobs)) {
  5406. return Result::error("暂无沟通记录", 0);
  5407. }
  5408. $result['row'] = $this->processJob($jobs, '');
  5409. $result['count'] = $count;
  5410. return Result::success($result);
  5411. }
  5412. // 20250306 招聘
  5413. //20250422 书刊音像
  5414. public function addBook(array $data): array
  5415. {
  5416. $user_id = $data['user_id'] ?? 0;
  5417. $type_id = $data['type_id'] ?? 0;
  5418. // $website_id = $data['website_id'] ?? 0;
  5419. // unset($data['user_id']);
  5420. unset($data['type_id']);
  5421. // unset($data['website_id']);
  5422. //处理数组
  5423. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5424. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5425. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5426. if ($data['img_url'] == '') {
  5427. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5428. preg_match_all($reg, $data['detail'], $matches);
  5429. if (isset($matches[1][0])) {
  5430. //截取varchar240
  5431. $data['img_url'] = substr($matches[1][0], 0, 240);
  5432. }
  5433. }
  5434. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5435. //提取标题+内容中的关键词
  5436. $data['keyword'] = $data['title'];
  5437. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5438. Jieba::init(); // 初始化 jieba-php
  5439. Finalseg::init();
  5440. $segList = Jieba::cut($data['keyword']);
  5441. $segList1 = array_slice($segList, 0, 8);
  5442. $data['keyword'] = implode(',', $segList1);
  5443. }
  5444. if ($data['description'] == '') {
  5445. //提取内容中的描述
  5446. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5447. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5448. }
  5449. var_dump($data, '--');
  5450. if ($data['status'] == 1) {
  5451. $this->sendMessage([
  5452. 'talk_type' => 400,
  5453. 'title' => $data['title'],
  5454. 'content' => '提交了审核',
  5455. 'messageType' => 7,
  5456. ]);
  5457. }
  5458. $result = Book::insertGetId($data);
  5459. if (empty($result)) {
  5460. return Result::error("添加失败", 0);
  5461. }
  5462. return Result::success($result);
  5463. }
  5464. public function getBookList(array $data): array
  5465. {
  5466. $where = [];
  5467. if (!empty($data["title"])) {
  5468. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5469. }
  5470. if (!empty($data['website_name'])) {
  5471. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5472. }
  5473. if (!empty($data['status'])) {
  5474. $where[] = ['book.status', '=', $data['status']];
  5475. }
  5476. $user_id = $data['user_id'];
  5477. $type_id = $data['type_id'];
  5478. // $type_id = 4;
  5479. var_dump($type_id, '------1--------');
  5480. if ($type_id != 10000) {
  5481. $where[] = ['book.user_id', '=', $user_id];
  5482. }
  5483. var_dump(!empty($data['status1']), '=-===1');
  5484. $result = Book::where($where)
  5485. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5486. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5487. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5488. ->when(isset($data['status1']), function ($query) use ($data) {
  5489. $query->whereIn('book.status', [1, 3]);
  5490. })
  5491. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5492. ->orderBy("updated_at", "desc")
  5493. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5494. if (empty($result)) {
  5495. return Result::error("暂无数据", 0);
  5496. }
  5497. // 取出数据
  5498. $rows = $result->items();
  5499. $count = $result->total();
  5500. $responseData = [
  5501. 'rows' => $rows,
  5502. 'count' => $count,
  5503. ];
  5504. return Result::success($responseData);
  5505. }
  5506. public function deleteBook(array $data): array
  5507. {
  5508. $result = Book::where('id', $data['id'])->delete();
  5509. if (empty($result)) {
  5510. return Result::error("删除失败", 0);
  5511. }
  5512. return Result::success($result);
  5513. }
  5514. public function updateBook(array $data): array
  5515. {
  5516. // $user_id = $data['user_id'] ?? 0;
  5517. $type_id = $data['type_id'] ?? 0;
  5518. // $website_id = $data['website_id'] ?? 0;
  5519. unset($data['user_id']);
  5520. unset($data['type_id']);
  5521. // unset($data['website_id']);
  5522. //处理数组
  5523. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5524. if ($data['img_url'] == '') {
  5525. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5526. preg_match_all($reg, $data['detail'], $matches);
  5527. if (isset($matches[1][0])) {
  5528. //截取varchar240
  5529. $data['img_url'] = substr($matches[1][0], 0, 240);
  5530. }
  5531. }
  5532. if ($data['keyword'] == '') {
  5533. //提取标题+内容中的关键词
  5534. $data['keyword'] = $data['title'];
  5535. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5536. Jieba::init(); // 初始化 jieba-php
  5537. Finalseg::init();
  5538. $segList = Jieba::cut($data['keyword']);
  5539. $segList1 = array_slice($segList, 0, 8);
  5540. $data['keyword'] = implode(',', $segList1);
  5541. }
  5542. if ($data['description'] == '') {
  5543. //提取内容中的描述
  5544. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5545. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5546. }
  5547. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5548. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5549. if ($data['status'] == 1) {
  5550. $this->sendMessage([
  5551. 'talk_type' => 400,
  5552. 'title' => $data['title'],
  5553. 'content' => '提交了审核',
  5554. 'messageType' => 7,
  5555. ]);
  5556. }
  5557. $result = Book::where("id", $data["id"])->update($data);
  5558. if (empty($result)) {
  5559. return Result::error("更新失败", 0);
  5560. }
  5561. return Result::success($result);
  5562. }
  5563. public function getBookInfo(array $data): array
  5564. {
  5565. $result = Book::where("id", $data["id"])->first();
  5566. if (empty($result)) {
  5567. return Result::error("获取失败", 0);
  5568. }
  5569. return Result::success($result);
  5570. }
  5571. public function updateBookStatus(array $data): array
  5572. {
  5573. //审核
  5574. unset($data['user_id']);
  5575. $bookInfo = Book::where("id", $data["id"])->first();
  5576. var_dump($bookInfo, '----');
  5577. if ($data['status'] == 2) {
  5578. $this->sendMessage([
  5579. 'talk_type' => 401,
  5580. 'title' => $bookInfo['title'],
  5581. 'content' => '审核通过',
  5582. 'messageType' => 7,
  5583. 'user_id' => $bookInfo['user_id'],
  5584. ]);
  5585. }
  5586. if ($data['status'] == 3) {
  5587. $this->sendMessage([
  5588. 'talk_type' => 401,
  5589. 'title' => $bookInfo['title'],
  5590. 'content' => '审核拒绝',
  5591. 'messageType' => 7,
  5592. 'user_id' => $bookInfo['user_id'],
  5593. ]);
  5594. }
  5595. if ($data['status'] == 1) {
  5596. $this->sendMessage([
  5597. 'talk_type' => 400,
  5598. 'title' => $bookInfo['title'],
  5599. 'content' => '提交了审核',
  5600. 'messageType' => 7,
  5601. // 'user_id'=>$bookInfo['user_id'],
  5602. ]);
  5603. }
  5604. $result = Book::where("id", $data["id"])->update($data);
  5605. if (empty($result)) {
  5606. return Result::error("更新失败", 0);
  5607. }
  5608. return Result::success($result);
  5609. }
  5610. //20250422 书刊音像
  5611. /**
  5612. * 贴身宝贝
  5613. * @param array $data
  5614. * @return array
  5615. */
  5616. public function getWebsiteTsbb(array $data): array
  5617. {
  5618. $month = $data['month'] ?? date('m');
  5619. $day = $data['day'] ?? date('d');
  5620. // 使用缓存键
  5621. $cacheKey = "tsbb_data_{$month}_{$day}";
  5622. // 尝试从缓存获取数据
  5623. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5624. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5625. if ($cachedData = $cache->get($cacheKey)) {
  5626. return Result::success(unserialize($cachedData));
  5627. }
  5628. //查询老黄历
  5629. try {
  5630. $date = date('Y-m-d');
  5631. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5632. // 使用 curl 替代 file_get_contents
  5633. $ch = curl_init();
  5634. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5635. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5636. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5637. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5638. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5639. 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');
  5640. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5641. 'Accept: application/json',
  5642. 'Content-Type: application/json',
  5643. 'Referer: https://www.36jxs.com/'
  5644. ]);
  5645. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5646. curl_setopt($ch, CURLOPT_ENCODING, '');
  5647. $almanacResponse = curl_exec($ch);
  5648. var_dump("====:", $almanacResponse);
  5649. if (curl_errno($ch)) {
  5650. var_dump('Curl error:', curl_error($ch));
  5651. throw new \Exception('Curl error: ' . curl_error($ch));
  5652. }
  5653. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5654. curl_close($ch);
  5655. if ($almanacResponse === false) {
  5656. throw new \Exception('Failed to fetch almanac data');
  5657. }
  5658. $almanacData = json_decode($almanacResponse, true);
  5659. if (json_last_error() !== JSON_ERROR_NONE) {
  5660. throw new \Exception('Failed to parse almanac data');
  5661. }
  5662. $almanacInfo = $almanacData['data'] ?? [];
  5663. } catch (\Exception $e) {
  5664. var_dump('Exception:', $e->getMessage());
  5665. $almanacInfo = [];
  5666. }
  5667. // 获取历史上的今天数据
  5668. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5669. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5670. ->orderBy('year', 'asc')
  5671. ->select("title", "id", "year", DB::raw('1 as type'))
  5672. ->limit(16)
  5673. ->get();
  5674. // 获取节日数据 - 从今天开始获取未来4条
  5675. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5676. ->orderBy('showtime', 'asc')
  5677. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5678. ->limit(16)
  5679. ->get();
  5680. //说文解字
  5681. $chartacterList = Character::orderBy('updated_at', 'desc')
  5682. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5683. ->limit(6)
  5684. ->get();
  5685. //谜语沙龙
  5686. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5687. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5688. ->limit(4)
  5689. ->get();
  5690. //成语欣赏
  5691. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5692. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5693. ->limit(32)
  5694. ->get();
  5695. //名联赏析
  5696. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5697. ->select("id", "first", "second", DB::raw('6 as type'))
  5698. ->limit(6)
  5699. ->get();
  5700. // 获取分类文章数据
  5701. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5702. ->pluck('category_id')
  5703. ->toArray();
  5704. $articlesList = [];
  5705. foreach ($categoryIds as $catid) {
  5706. // 先查有图片的
  5707. $withImg = DB::table('article')
  5708. ->where('status', 1)
  5709. ->where('catid', $catid)
  5710. ->whereNotNull('imgurl')
  5711. ->where('imgurl', '!=', '')
  5712. ->orderBy('updated_at', 'desc')
  5713. ->limit(6)
  5714. ->get();
  5715. $count = $withImg->count();
  5716. if ($count < 6) {
  5717. // 不足6条再查无图片的补足
  5718. $withoutImg = DB::table('article')
  5719. ->where('status', 1)
  5720. ->where('catid', $catid)
  5721. ->where(function ($q) {
  5722. $q->whereNull('imgurl')->orWhere('imgurl', '');
  5723. })
  5724. ->orderBy('updated_at', 'desc')
  5725. ->limit(6 - $count)
  5726. ->get();
  5727. $articles = $withImg->concat($withoutImg);
  5728. } else {
  5729. $articles = $withImg;
  5730. }
  5731. // 组装
  5732. $category = \App\Model\Category::find($catid);
  5733. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  5734. $articlesList[] = [
  5735. 'category_name' => $category ? $category->name : '',
  5736. 'catid' => $catid,
  5737. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  5738. 'type' => 100,
  5739. 'list' => $articles->map(function ($item) {
  5740. return [
  5741. 'id' => $item->id,
  5742. 'title' => $item->title,
  5743. 'imgurl' => $item->imgurl,
  5744. 'created_at' => $item->created_at
  5745. ];
  5746. })->values()
  5747. ];
  5748. }
  5749. $result = [
  5750. 'almanac' => $almanacInfo,
  5751. 'historyTodayList' => [
  5752. 'category_name' => '历史上的今天',
  5753. 'list' => $historyTodayList,
  5754. 'type' => 1
  5755. ],
  5756. 'festivalList' => [
  5757. 'category_name' => '节日预告',
  5758. 'list' => $festivalList,
  5759. 'type' => 2
  5760. ],
  5761. 'chartacterList' => [
  5762. 'category_name' => '说文解字',
  5763. 'list' => $chartacterList,
  5764. 'type' => 3
  5765. ],
  5766. 'coupletList' => [
  5767. 'category_name' => '名联赏析',
  5768. 'list' => $coupletList,
  5769. 'type' => 6
  5770. ],
  5771. 'riddletList' => [
  5772. 'category_name' => '谜语沙龙',
  5773. 'list' => $riddletList,
  5774. 'type' => 4
  5775. ],
  5776. 'idiomList' => [
  5777. 'category_name' => '成语欣赏',
  5778. 'list' => $idiomList,
  5779. 'type' => 5
  5780. ],
  5781. 'articlesList' => $articlesList
  5782. ];
  5783. // 缓存结果,设置1小时过期
  5784. $cache->set($cacheKey, serialize($result), 3600);
  5785. return Result::success($result);
  5786. }
  5787. /**
  5788. * 获取资讯列表
  5789. */
  5790. public function getWebsiteTsbbList(array $data): array
  5791. {
  5792. $page = $data['page'] ?? 1;
  5793. $pageSize = $data['pageSize'] ?? 10;
  5794. // 如果没有传入月份和日期,则使用今天的日期
  5795. $month = $data['month'] ?? date('m');
  5796. $day = $data['day'] ?? date('d');
  5797. $total = 0;
  5798. $result = [];
  5799. $data['type'] = intval($data['type']);
  5800. var_dump("接收参数:", $data);
  5801. switch ($data['type']) {
  5802. case 1:
  5803. $query = HistoryToday::where(function ($q) use ($month, $day) {
  5804. // 当前月份之后的数据
  5805. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  5806. // 或者当前月份且日期大于等于当前日期的数据
  5807. ->orWhere(function ($q) use ($month, $day) {
  5808. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5809. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  5810. });
  5811. })
  5812. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  5813. $total = $query->count();
  5814. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  5815. ->offset(($page - 1) * $pageSize)
  5816. ->limit($pageSize)
  5817. ->get();
  5818. break;
  5819. case 2:
  5820. $query = Festival::where(function ($q) use ($month, $day) {
  5821. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  5822. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  5823. ->orWhere(function ($q) use ($month, $day) {
  5824. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  5825. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  5826. });
  5827. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  5828. $total = $query->count();
  5829. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  5830. ->offset(($page - 1) * $pageSize)
  5831. ->limit($pageSize)
  5832. ->get();
  5833. break;
  5834. case 3:
  5835. $query = Character::orderBy("updated_at", "desc");
  5836. $total = $query->count();
  5837. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  5838. ->offset(($page - 1) * $pageSize)
  5839. ->limit($pageSize)
  5840. ->get();
  5841. break;
  5842. case 4:
  5843. $query = Riddle::orderBy("updated_at", "desc");
  5844. $total = $query->count();
  5845. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  5846. ->offset(($page - 1) * $pageSize)
  5847. ->limit($pageSize)
  5848. ->get();
  5849. break;
  5850. case 5:
  5851. $query = Idiom::orderBy("updated_at", "desc");
  5852. $total = $query->count();
  5853. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  5854. ->offset(($page - 1) * $pageSize)
  5855. ->limit($pageSize)
  5856. ->get();
  5857. break;
  5858. case 6:
  5859. $query = Couplet::orderBy("updated_at", "desc");
  5860. $total = $query->count();
  5861. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  5862. ->offset(($page - 1) * $pageSize)
  5863. ->limit($pageSize)
  5864. ->get();
  5865. break;
  5866. default:
  5867. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  5868. $total = $query->count();
  5869. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  5870. ->offset(($page - 1) * $pageSize)
  5871. ->limit($pageSize)
  5872. ->get();
  5873. }
  5874. return Result::success([
  5875. 'list' => $result,
  5876. 'total' => $total,
  5877. 'page' => (int)$page,
  5878. 'pageSize' => (int)$pageSize,
  5879. 'month' => $month,
  5880. 'day' => $day
  5881. ]);
  5882. }
  5883. /**
  5884. * 1:历史上的今天
  5885. * 2:节日
  5886. * 3:文章
  5887. *
  5888. * 资讯详情信息
  5889. */
  5890. public function getWebsiteTsbbDetail(array $data): array
  5891. {
  5892. $data['type'] = intval($data['type']);
  5893. switch ($data['type']) {
  5894. case 1:
  5895. $result = HistoryToday::where("id", $data['id'])->first();
  5896. break;
  5897. case 2:
  5898. $result = Festival::where("id", $data['id'])->first();
  5899. break;
  5900. case 3:
  5901. $result = Character::where("id", $data['id'])->first();
  5902. break;
  5903. case 4:
  5904. $result = Riddle::where("id", $data['id'])->first();
  5905. break;
  5906. case 5:
  5907. $result = Idiom::where("id", $data['id'])->first();
  5908. break;
  5909. case 6:
  5910. $result = Couplet::where("id", $data['id'])->first();
  5911. break;
  5912. default:
  5913. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  5914. break;
  5915. }
  5916. return Result::success($result);
  5917. }
  5918. /**
  5919. * 农网导航首页数据
  5920. */
  5921. public function getWebsiteNwHomeList(array $data): array
  5922. {
  5923. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  5924. ->pluck('category_id')
  5925. ->toArray();
  5926. // 使用子查询优化
  5927. $articlesList = DB::table('article')
  5928. ->select([
  5929. 'article.id',
  5930. 'article.title',
  5931. 'article.imgurl',
  5932. 'article.created_at',
  5933. 'category.name as category_name',
  5934. 'category.id as category_id',
  5935. 'website_category.aLIas_pinyin as pinyin',
  5936. 'parent_wc.aLIas_pinyin as parent_pinyin',
  5937. DB::raw('100 as type')
  5938. ])
  5939. ->join('category', 'article.catid', '=', 'category.id')
  5940. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5941. ->leftJoin('website_category as parent_wc', function ($join) {
  5942. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  5943. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  5944. })
  5945. ->where('website_category.website_id', $data['website_id'])
  5946. ->where('article.status', 1)
  5947. ->whereIn('category.id', $categoryIds)
  5948. ->orderBy('article.created_at', 'desc')
  5949. ->get()
  5950. ->groupBy('category_id')
  5951. ->map(function ($group) {
  5952. // 确保第一条数据有图片
  5953. $firstWithImage = $group->first(function ($item) {
  5954. return !empty($item->imgurl);
  5955. });
  5956. if ($firstWithImage) {
  5957. // 如果有带图片的文章,将其放在第一位
  5958. $group = $group->filter(function ($item) use ($firstWithImage) {
  5959. return $item->id !== $firstWithImage->id;
  5960. })->prepend($firstWithImage);
  5961. }
  5962. return [
  5963. 'category_name' => $group->first()->category_name,
  5964. 'catid' => $group->first()->category_id,
  5965. 'pinyin' => $group->first()->pinyin,
  5966. 'parent_pinyin' => $group->first()->parent_pinyin,
  5967. 'list' => $group->take(4)->map(function ($item) {
  5968. return [
  5969. 'id' => $item->id,
  5970. 'title' => $item->title,
  5971. ];
  5972. })->values()
  5973. ];
  5974. })
  5975. ->values()
  5976. ->toArray();
  5977. return Result::success($articlesList);
  5978. }
  5979. /**
  5980. * 企业管理
  5981. * @param array $data
  5982. * @return array
  5983. */
  5984. public function getCompanyList(array $data): array
  5985. {
  5986. // return Result::success($data);
  5987. $where = [];
  5988. $user = User::where('id', $data['user_id'])->first();
  5989. if (empty($user)) {
  5990. return Result::error('用户不存在!');
  5991. }
  5992. if ($user['type_id'] != 10000) {
  5993. $where['user_id'] = $data['user_id'];
  5994. }
  5995. if (isset($data['title']) && !empty($data['title'])) {
  5996. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  5997. }
  5998. if (isset($data['website_id']) && !empty($data['website_id'])) {
  5999. array_push($where, ['website.id', $data['website_id']]);
  6000. }
  6001. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6002. if ($data['ischeck'] == 1) {
  6003. if (isset($data['status']) && $data['status'] != '') {
  6004. array_push($where, ['company.status', $data['status']]);
  6005. $query = Company::where($where);
  6006. } else {
  6007. $query = Company::whereIn('company.status', [0, 2]);
  6008. }
  6009. } else {
  6010. $query = Company::where('company.status', 1);
  6011. }
  6012. }
  6013. $result = $query->where($where)
  6014. ->leftJoin('website_category', function ($query) {
  6015. $query->on('website_category.category_id', '=', 'company.category_id')
  6016. ->on('website_category.website_id', '=', 'company.website_id');
  6017. })
  6018. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6019. ->select(
  6020. 'company.id',
  6021. 'company.title',
  6022. 'company.website_id',
  6023. 'company.category_id',
  6024. 'website.website_name',
  6025. 'website_category.alias as category_name',
  6026. 'company.status',
  6027. 'company.updated_at',
  6028. )
  6029. ->orderBy('company.updated_at', 'desc')
  6030. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6031. if ($result->isEmpty()) {
  6032. return Result::error("暂无企业", 0);
  6033. }
  6034. return Result::success($result);
  6035. }
  6036. /**
  6037. * 添加企业
  6038. * @param array $data
  6039. * @return array
  6040. */
  6041. public function addCompany(array $data): array
  6042. {
  6043. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6044. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6045. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6046. $data['cat_arr_id'] = json_encode($car_arr_id);
  6047. } else {
  6048. $data['cat_arr_id'] = '';
  6049. }
  6050. if ($data['imgurl'] == '') {
  6051. //content中提取图片第一个图,正则提取
  6052. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6053. preg_match_all($reg, $data['content'], $matches);
  6054. if (isset($matches[1][0])) {
  6055. //截取varchar240
  6056. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6057. }
  6058. }
  6059. if ($data['keyword'] == '') {
  6060. //提取标题+内容中的关键词
  6061. $data['keyword'] = $data['title'];
  6062. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6063. Jieba::init(); // 初始化 jieba-php
  6064. Finalseg::init();
  6065. $segList = Jieba::cut($data['keyword']);
  6066. $segList1 = array_slice($segList, 0, 8);
  6067. $data['keyword'] = implode(',', $segList1);
  6068. }
  6069. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6070. //提取内容中的描述
  6071. $content = $data['content'];
  6072. // 去除 <style> 和 <script> 标签及其内容
  6073. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6074. // 去除所有 HTML 标签
  6075. $content = strip_tags($content);
  6076. // 去除 HTML 实体
  6077. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6078. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6079. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6080. // 去除多余空白
  6081. $content = preg_replace('/\s+/u', '', $content);
  6082. // 截取 100 个字符
  6083. $data['introduce'] = mb_substr($content, 0, 100);
  6084. }
  6085. $user = User::where('id', $data['user_id'])->first();
  6086. if (empty($user)) {
  6087. return Result::error('用户不存在!');
  6088. }
  6089. if ($user['type_id'] == 10000) {
  6090. $data['status'] = 1;
  6091. }
  6092. if (isset($data['level']) && $data['level'] != null) {
  6093. $data['level'] = intval($data['level']);
  6094. } else {
  6095. $data['level'] = null;
  6096. }
  6097. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6098. $this->sendMessage([
  6099. 'talk_type' => 900,
  6100. 'title' => $data['title'],
  6101. 'content' => '提交了审核',
  6102. 'messageType' => 8,
  6103. ]);
  6104. }
  6105. $result = Company::insertGetId($data);
  6106. if ($result) {
  6107. return Result::success($result);
  6108. } else {
  6109. return Result::error('添加失败');
  6110. }
  6111. }
  6112. /**
  6113. * 更新企业
  6114. * @param array $data
  6115. * @return array
  6116. */
  6117. public function upCompany(array $data): array
  6118. {
  6119. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6120. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6121. $data['cat_arr_id'] = json_encode($car_arr_id);
  6122. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6123. } else {
  6124. $data['cat_arr_id'] = '';
  6125. }
  6126. if ($data['imgurl'] == '') {
  6127. //content中提取图片第一个图,正则提取
  6128. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6129. preg_match_all($reg, $data['content'], $matches);
  6130. if (isset($matches[1][0])) {
  6131. //截取varchar
  6132. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6133. }
  6134. }
  6135. if ($data['keyword'] == '') {
  6136. //提取标题+内容中的关键词
  6137. $data['keyword'] = $data['title'];
  6138. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6139. Jieba::init(); // 初始化 jieba-php
  6140. Finalseg::init();
  6141. $segList = Jieba::cut($data['keyword']);
  6142. $segList1 = array_slice($segList, 0, 8);
  6143. $data['keyword'] = implode(',', $segList1);
  6144. }
  6145. if ($data['introduce'] == '') {
  6146. //提取内容中的描述
  6147. $content = $data['content'];
  6148. // 去除 <style> 和 <script> 标签及其内容
  6149. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6150. // 去除所有 HTML 标签
  6151. $content = strip_tags($content);
  6152. // 去除 HTML 实体
  6153. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6154. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6155. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6156. // 去除多余空白
  6157. $content = preg_replace('/\s+/u', '', $content);
  6158. // 截取 100 个字符
  6159. $data['introduce'] = mb_substr($content, 0, 100);
  6160. }
  6161. if (isset($data['level']) && $data['level'] != null) {
  6162. $data['level'] = intval($data['level']);
  6163. } else {
  6164. $data['level'] = null;
  6165. }
  6166. $user = User::where('id', $data['user_id'])->first();
  6167. if (empty($user)) {
  6168. return Result::error('用户不存在!');
  6169. }
  6170. if ($user['type_id'] == 10000) {
  6171. $data['status'] = 1;
  6172. } else {
  6173. $data['status'] = 0;
  6174. }
  6175. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6176. $this->sendMessage([
  6177. 'talk_type' => 900,
  6178. 'title' => $data['title'],
  6179. 'content' => '提交了审核',
  6180. 'messageType' => 8,
  6181. ]);
  6182. }
  6183. $result = Company::where('id', $data['id'])->update($data);
  6184. if ($result) {
  6185. return Result::success($result);
  6186. } else {
  6187. return Result::error('修改失败');
  6188. }
  6189. }
  6190. /**
  6191. * 删除企业
  6192. * @param array $data
  6193. * @return array
  6194. */
  6195. public function delCompany(array $data): array
  6196. {
  6197. $result = Company::where('id', $data['id'])->delete();
  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 checkCompany(array $data): array
  6210. {
  6211. $user = User::where('id', $data['user_id'])->first();
  6212. if (empty($user)) {
  6213. return Result::error('用户不存在!');
  6214. }
  6215. $company = Company::where('id', $data['id'])->first();
  6216. if (empty($company)) {
  6217. return Result::error('企业不存在!');
  6218. }
  6219. // 状态:0:未审核 1:已审核 2:已拒绝
  6220. if ($data['status'] == 2 || $data['status'] == '2') {
  6221. $this->sendMessage([
  6222. 'talk_type' => 901,
  6223. 'title' => $company['title'],
  6224. 'content' => '审核拒绝',
  6225. 'messageType' => 8,
  6226. 'user_id' => $company['user_id'],
  6227. ]);
  6228. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6229. } else {
  6230. if ($data['status'] == 1) {
  6231. $this->sendMessage([
  6232. 'talk_type' => 901,
  6233. 'title' => $company['title'],
  6234. 'content' => '审核通过',
  6235. 'messageType' => 8,
  6236. 'user_id' => $company['user_id'],
  6237. ]);
  6238. } else if ($data['status'] == 0) {
  6239. $this->sendMessage([
  6240. 'talk_type' => 900,
  6241. 'title' => $company['title'],
  6242. 'content' => '提交了审核',
  6243. 'messageType' => 8,
  6244. ]);
  6245. }
  6246. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6247. }
  6248. if (empty($result)) {
  6249. return Result::error('审核失败!');
  6250. } else {
  6251. return Result::success($result);
  6252. }
  6253. }
  6254. /**
  6255. * 获取企业信息
  6256. * @param array $data
  6257. * @return array
  6258. */
  6259. public function getCompanyInfo(array $data): array
  6260. {
  6261. $result = Company::where('id', $data['id'])->first();
  6262. if (empty($result)) {
  6263. return Result::error('企业不存在!');
  6264. } else {
  6265. return Result::success($result);
  6266. }
  6267. }
  6268. /**
  6269. * @param array $data
  6270. * @return array
  6271. */
  6272. public function getWebsiteCompany(array $data): array
  6273. {
  6274. $categorys = json_decode($data['id'], true);
  6275. $category_arr = $this->processArticlePro($data['website_id']);
  6276. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6277. $catiall = $category_arr['catiall'];
  6278. foreach ($categorys as $key => $value) {
  6279. if (array_key_exists('level', $value)) {
  6280. $parts = explode(',', $value['level']);
  6281. $level = $parts[0] ?? null;
  6282. $imgnum = $parts[1] ?? null;
  6283. $textnum = $parts[2] ?? null;
  6284. if (!empty($textnum) && $textnum > 0) {
  6285. $text_num = Company::where('level', $level)
  6286. ->where('website_id', $data['website_id'])
  6287. ->where('status', 1)
  6288. ->select(
  6289. 'company.id',
  6290. 'company.title',
  6291. 'company.description',
  6292. 'company.updated_at',
  6293. 'company.category_id',
  6294. 'company.cat_arr_id'
  6295. )
  6296. ->orderBy('updated_at', 'desc')
  6297. ->limit($textnum)
  6298. ->get()->all();
  6299. }
  6300. if (!empty($imgnum) && $imgnum > 0) {
  6301. $img_num = Company::where('level', $level)
  6302. ->where('website_id', $data['website_id'])
  6303. ->where('status', 1)
  6304. ->where('imgurl', '!=', '')
  6305. ->whereNotNull('imgurl')
  6306. ->select(
  6307. 'company.id',
  6308. 'company.title',
  6309. 'company.description',
  6310. 'company.updated_at',
  6311. 'company.imgurl as imgs',
  6312. 'company.category_id',
  6313. 'company.cat_arr_id'
  6314. )
  6315. ->orderBy('updated_at', 'desc')
  6316. ->limit($imgnum)
  6317. ->get()->all();
  6318. }
  6319. }
  6320. if (array_key_exists('id', $value)) {
  6321. $parts = explode(',', $value['id']);
  6322. $category_id = $parts[0] ?? null;
  6323. $imgnum = $parts[1] ?? null;
  6324. $textnum = $parts[2] ?? null;
  6325. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6326. if (!empty($textnum) && $textnum > 0) {
  6327. $text_num = Company::whereIn('category_id', $category_arr)
  6328. ->where('website_id', $data['website_id'])
  6329. ->where('status', 1)
  6330. ->select(
  6331. 'company.id',
  6332. 'company.title',
  6333. 'company.description',
  6334. 'company.updated_at',
  6335. 'company.category_id',
  6336. 'company.cat_arr_id'
  6337. )
  6338. ->orderBy('updated_at', 'desc')
  6339. ->limit($textnum)
  6340. ->get()->all();
  6341. }
  6342. if (!empty($imgnum) && $imgnum > 0) {
  6343. $img_num = Company::whereIn('category_id', $category_arr)
  6344. ->where('website_id', $data['website_id'])
  6345. ->where('status', 1)
  6346. ->where('imgurl', '!=', '')
  6347. ->whereNotNull('imgurl')
  6348. ->select(
  6349. 'company.id',
  6350. 'company.title',
  6351. 'company.description',
  6352. 'company.updated_at',
  6353. 'company.imgurl as imgs',
  6354. 'company.category_id',
  6355. 'company.cat_arr_id'
  6356. )
  6357. ->orderBy('updated_at', 'desc')
  6358. ->limit($imgnum)
  6359. ->get()->all();
  6360. }
  6361. }
  6362. if (!empty($text_num)) {
  6363. foreach ($text_num as $k => $v) {
  6364. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6365. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6366. }
  6367. }
  6368. if (!empty($img_num)) {
  6369. foreach ($img_num as $k => $v) {
  6370. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6371. $imgurl = json_decode($v['imgs'], true);
  6372. if (!empty($imgurl)) {
  6373. $img_num[$k]->imgurl = $imgurl[0];
  6374. }
  6375. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6376. }
  6377. }
  6378. $company[$key]['img_num'] = $img_num ?? [];
  6379. $company[$key]['text_num'] = $text_num ?? [];
  6380. }
  6381. if (empty($company)) {
  6382. return Result::error("暂无相关企业信息", 0);
  6383. }
  6384. return Result::success($company);
  6385. }
  6386. /**
  6387. * @param array $data
  6388. * @return array
  6389. */
  6390. public function getWebsiteCompanyList(array $data): array
  6391. {
  6392. $where['website_id'] = $data['website_id'];
  6393. $where['status'] = 1;
  6394. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6395. $where['category_id'] = $data['category_id'];
  6396. }
  6397. if (isset($data['keyword']) && !empty($data['keyword'])) {
  6398. array_push($where, ['title', 'like', '%' . $data['keyword'] . '%']);
  6399. }
  6400. $query = Company::where($where);
  6401. $company = $this->processArticle(
  6402. $query->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6403. ->orderBy('updated_at', 'desc')
  6404. ->offset(($data['page'] - 1) * $data['pageSize'])
  6405. ->limit($data['pageSize'])
  6406. ->get(),
  6407. $data
  6408. );
  6409. if (empty($company)) {
  6410. return Result::error("暂无相关公司信息", 0);
  6411. }
  6412. $result = [
  6413. 'count' => $query->clone()->count(),
  6414. 'data' => $company,
  6415. ];
  6416. return Result::success($result);
  6417. }
  6418. /**
  6419. * 获取项目列表
  6420. * @param array $data
  6421. * @return array
  6422. */
  6423. public function getProjectList(array $data): array
  6424. {
  6425. $where = [];
  6426. $user = User::where('id', $data['user_id'])->first();
  6427. if (empty($user)) {
  6428. return Result::error('用户不存在!');
  6429. }
  6430. if ($user->type_id != 10000) {
  6431. array_push($where, ['project.user_id', $data['user_id']]);
  6432. }
  6433. $query = Project::query();
  6434. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6435. array_push($where, ['project.website_id', $data['website_id']]);
  6436. }
  6437. if (isset($data['title']) && !empty($data['title'])) {
  6438. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6439. }
  6440. if ($data['status'] != 3) {
  6441. array_push($where, ['project.status', $data['status']]);
  6442. }
  6443. $query = Project::where($where)
  6444. ->when($data['status'] == 3, function ($query) {
  6445. $query->whereIn('project.status', [0, 2]);
  6446. });
  6447. $count = $query->clone()
  6448. ->count();
  6449. $rows = $query->clone()
  6450. ->leftJoin('website', 'project.website_id', 'website.id')
  6451. ->leftJoin('website_category', function ($join) {
  6452. $join->on('project.website_id', '=', 'website_category.website_id')
  6453. ->on('project.category_id', '=', 'website_category.category_id');
  6454. })
  6455. ->select(
  6456. 'project.id',
  6457. 'project.title',
  6458. 'project.updated_at',
  6459. 'project.status',
  6460. 'website.website_name',
  6461. 'website_category.alias as category_name'
  6462. )
  6463. ->orderBy('project.updated_at', 'desc')
  6464. ->offset(($data['page'] - 1) * $data['pageSize'])
  6465. ->limit($data['pageSize'])
  6466. ->get();
  6467. if ($rows->isEmpty()) {
  6468. return Result::error("暂无相关项目信息", 0);
  6469. }
  6470. $result = [
  6471. 'count' => $count,
  6472. 'rows' => $rows,
  6473. ];
  6474. return Result::success($result);
  6475. }
  6476. /**
  6477. * 添加项目
  6478. * @param array $data
  6479. * @return array
  6480. */
  6481. public function addProject(array $data): array
  6482. {
  6483. $user = User::where('id', $data['user_id'])->first();
  6484. if (empty($user)) {
  6485. return Result::error("暂无相关用户信息", 0);
  6486. }
  6487. if ($user->type_id == 10000) {
  6488. $data['status'] = 1;
  6489. } else {
  6490. $data['status'] = 0;
  6491. }
  6492. if ($data['keyword'] == '') {
  6493. //提取标题+内容中的关键词
  6494. $data['keyword'] = $data['title'];
  6495. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6496. Jieba::init(); // 初始化 jieba-php
  6497. Finalseg::init();
  6498. $segList = Jieba::cut($data['keyword']);
  6499. $segList1 = array_slice($segList, 0, 8);
  6500. $data['keyword'] = implode(',', $segList1);
  6501. }
  6502. if ($data['description'] == '') {
  6503. //提取内容中的描述
  6504. // var_dump(11111);
  6505. //提取内容中的描述
  6506. $content = $data['introduce'];
  6507. // 去除 <style> 和 <script> 标签及其内容
  6508. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6509. // 去除所有 HTML 标签
  6510. $content = strip_tags($content);
  6511. // 去除 HTML 实体
  6512. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6513. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6514. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6515. // 去除多余空白
  6516. $content = preg_replace('/\s+/u', '', $content);
  6517. // 截取 100 个字符
  6518. $data['description'] = mb_substr($content, 0, 100);
  6519. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6520. }
  6521. if ($data['status'] == 0) {
  6522. $this->sendMessage([
  6523. 'talk_type' => 1000,
  6524. 'title' => $data['title'],
  6525. 'content' => '提交了审核',
  6526. 'messageType' => 9,
  6527. ]);
  6528. }
  6529. $project = Project::insertGetId($data);
  6530. if (empty($project)) {
  6531. return Result::error("暂无相关项目信息", 0);
  6532. }
  6533. return Result::success($project);
  6534. }
  6535. /**
  6536. * 更新项目
  6537. * @param array $data
  6538. * @return array
  6539. */
  6540. public function upProject(array $data): array
  6541. {
  6542. $project = Project::where('id', $data['id'])->first();
  6543. if (empty($project)) {
  6544. return Result::error("暂无相关项目信息", 0);
  6545. }
  6546. $id = $data['id'];
  6547. unset($data['id']);
  6548. $user = User::where('id', $data['user_id'])->first();
  6549. if (empty($user)) {
  6550. return Result::error("暂无相关用户信息", 0);
  6551. }
  6552. if ($user->type_id == 10000) {
  6553. $data['status'] = 1;
  6554. } else {
  6555. $data['status'] = 0;
  6556. }
  6557. unset($data['user_id']);
  6558. if ($data['keyword'] == '') {
  6559. //提取标题+内容中的关键词
  6560. $data['keyword'] = $data['title'];
  6561. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6562. Jieba::init(); // 初始化 jieba-php
  6563. Finalseg::init();
  6564. $segList = Jieba::cut($data['keyword']);
  6565. $segList1 = array_slice($segList, 0, 8);
  6566. $data['keyword'] = implode(',', $segList1);
  6567. }
  6568. if ($data['description'] == '') {
  6569. //提取内容中的描述
  6570. // var_dump(11111);
  6571. //提取内容中的描述
  6572. $content = $data['introduce'];
  6573. // 去除 <style> 和 <script> 标签及其内容
  6574. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6575. // 去除所有 HTML 标签
  6576. $content = strip_tags($content);
  6577. // 去除 HTML 实体
  6578. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6579. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6580. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6581. // 去除多余空白
  6582. $content = preg_replace('/\s+/u', '', $content);
  6583. // 截取 100 个字符
  6584. $data['description'] = mb_substr($content, 0, 100);
  6585. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6586. }
  6587. if ($data['status'] == 0) {
  6588. $this->sendMessage([
  6589. 'talk_type' => 1000,
  6590. 'title' => $data['title'],
  6591. 'content' => '提交了审核',
  6592. 'messageType' => 9,
  6593. ]);
  6594. }
  6595. $result = Project::where('id', $id)->update($data);
  6596. if (empty($result)) {
  6597. return Result::error("更新失败", 0);
  6598. }
  6599. return Result::success($result);
  6600. }
  6601. /**
  6602. * 删除项目
  6603. * @param array $data
  6604. * @return array
  6605. */
  6606. public function delProject(array $data): array
  6607. {
  6608. $user = User::where('id', $data['user_id'])->first();
  6609. if (empty($user)) {
  6610. return Result::error("暂无相关用户信息", 0);
  6611. }
  6612. $project = Project::where('id', $data['id'])->first();
  6613. if (empty($project)) {
  6614. return Result::error("暂无相关项目信息", 0);
  6615. }
  6616. $result = Project::where('id', $data['id'])->delete();
  6617. if (empty($result)) {
  6618. return Result::error("删除失败", 0);
  6619. }
  6620. return Result::success($result);
  6621. }
  6622. /**
  6623. * 审核项目
  6624. * @param array $data
  6625. * @return array
  6626. */
  6627. public function checkProject(array $data): array
  6628. {
  6629. $user = User::where('id', $data['user_id'])->first();
  6630. if (empty($user)) {
  6631. return Result::error("暂无相关用户信息", 0);
  6632. }
  6633. // 0:未审核; 1:已审核; 2:已拒绝;
  6634. if ($user->type_id != 10000) {
  6635. if ($data['status'] == 1 || $data['status'] == 2) {
  6636. return Result::error("此用户权限不足", 0);
  6637. }
  6638. }
  6639. $project = Project::where('id', $data['id'])->first();
  6640. if (empty($project)) {
  6641. return Result::error("暂无相关项目信息", 0);
  6642. }
  6643. if ($data['status'] == 2) {
  6644. $this->sendMessage([
  6645. 'talk_type' => 1001,
  6646. 'title' => $project['title'],
  6647. 'content' => '审核拒绝',
  6648. 'messageType' => 9,
  6649. 'user_id' => $project['user_id'],
  6650. ]);
  6651. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  6652. } else {
  6653. if ($data['status'] == 1) {
  6654. $this->sendMessage([
  6655. 'talk_type' => 1001,
  6656. 'title' => $project['title'],
  6657. 'content' => '审核通过',
  6658. 'messageType' => 9,
  6659. 'user_id' => $project['user_id'],
  6660. ]);
  6661. } else if ($data['status'] == 0) {
  6662. $this->sendMessage([
  6663. 'talk_type' => 1000,
  6664. 'title' => $project['title'],
  6665. 'content' => '提交了审核',
  6666. 'messageType' => 9,
  6667. ]);
  6668. }
  6669. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  6670. }
  6671. if (empty($result)) {
  6672. return Result::error("审核失败", 0);
  6673. }
  6674. return Result::success($result);
  6675. }
  6676. /**
  6677. * 获取项目详情
  6678. * @param array $data
  6679. * @return array
  6680. */
  6681. public function getProjectInfo(array $data): array
  6682. {
  6683. $project = Project::where('id', $data['id'])->first();
  6684. if (empty($project)) {
  6685. return Result::error("暂无相关项目信息", 0);
  6686. }
  6687. return Result::success($project);
  6688. }
  6689. public function getWebsiteCompanyInfo(array $data): array
  6690. {
  6691. $company = Company::where('id', $data['id'])
  6692. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  6693. ->where('status', 1)
  6694. ->where('website_id', $data['website_id'])
  6695. ->select('company.*', 'job_industry.hyname as hy_name')
  6696. ->first();
  6697. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  6698. switch ($company->jobnature_id) {
  6699. case null:
  6700. $company->jobnature_name = '';
  6701. break;
  6702. case 0:
  6703. $company->jobnature_name = '市场监督';
  6704. break;
  6705. case 1:
  6706. $company->jobnature_name = '信访纪检';
  6707. break;
  6708. case 2:
  6709. $company->jobnature_name = '公检法司';
  6710. break;
  6711. case 3:
  6712. $company->jobnature_name = '高关注机构';
  6713. break;
  6714. default:
  6715. $company->jobnature_name = '';
  6716. break;
  6717. }
  6718. $city_arr = $company->city_arr_id;
  6719. if (!empty($city_arr)) {
  6720. $city_arr = json_decode($city_arr, true);
  6721. $cityNames = District::whereIn('id', $city_arr)
  6722. ->pluck('name')
  6723. ->implode('-');
  6724. $company->city_name = $cityNames;
  6725. } else {
  6726. $company->city_name = '';
  6727. }
  6728. if (empty($company)) {
  6729. return Result::error("暂无相关公司信息", 0);
  6730. }
  6731. return Result::success($company);
  6732. }
  6733. public function getMSG(array $data): array
  6734. {
  6735. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  6736. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  6737. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  6738. $result = [];
  6739. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  6740. //最近的5篇已审的文章
  6741. $apply_articale = Article::where('status', 1)
  6742. ->where('admin_user_id', $user_id)
  6743. ->orderBy('updated_at', 'desc')
  6744. // ->limit(5)
  6745. ->get();
  6746. //获取5条用户的已审核商品
  6747. $good = Good::where('status', 2)
  6748. ->where('user_id', $user_id)
  6749. ->orderBy('updated_at', 'desc')
  6750. // ->limit(5)
  6751. ->get();
  6752. //获取5条用户待审核的公告
  6753. $notice = Notice::where('status', 2)
  6754. ->where('user_id', $user_id)
  6755. ->orderBy('updated_at', 'desc')
  6756. ->limit(5)->get();
  6757. //获取5条用户的待审核投诉
  6758. $complaint = Complaint::where('status', 2)
  6759. ->where('user_id', $user_id)
  6760. ->orderBy('updated_at', 'desc')
  6761. // ->limit(5)
  6762. ->get();
  6763. //获取5条用户的book
  6764. $book = Book::where('status', 2)
  6765. ->where('user_id', $user_id)
  6766. ->orderBy('updated_at', 'desc')
  6767. // ->limit(5)
  6768. ->get();
  6769. //获取5条用户的求职
  6770. //获取5条用户的求职 1
  6771. $job_hunting = JobHunting::where('job_hunting.status', 2)
  6772. ->where('job_hunting.user_id', $user_id)
  6773. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  6774. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  6775. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6776. ->orderBy('updated_at', 'desc')
  6777. // ->limit(5)
  6778. ->get();
  6779. //获取5条用户的求职 2
  6780. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  6781. ->where('job_recruiting.user_id', $user_id)
  6782. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  6783. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  6784. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6785. ->orderBy('updated_at', 'desc')
  6786. // ->limit(5)
  6787. ->get();
  6788. //人才库 1
  6789. $job_apply = JobApply::where('job_apply.status', 1)
  6790. ->where('job_apply.receiver_id', $user_id)
  6791. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  6792. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  6793. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  6794. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  6795. ->select('job_recruiting', 'job_recruiting.', '', '')
  6796. ->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')
  6797. ->orderBy('updated_at', 'desc')
  6798. // ->limit(5)
  6799. ->get();
  6800. // 职场机会 2
  6801. $job_resume = JobResume::where('job_resume.status', 1)
  6802. ->where('job_resume.receiver_id', $user_id)
  6803. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  6804. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  6805. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  6806. ->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')
  6807. ->orderBy('updated_at', 'desc')
  6808. // ->limit(5)
  6809. ->get();
  6810. //获取5条用户待处理的投诉
  6811. $complaint_deal = Complaint::where('status', 2)
  6812. ->where('deal', 1)
  6813. ->whereJsonContains('re_user_ids', $user_id)
  6814. ->orderBy('updated_at', 'desc')
  6815. // ->limit(5)
  6816. ->get();
  6817. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  6818. $complany = Company::where('status', 1)
  6819. ->where('user_id', $user_id)
  6820. ->orderBy('updated_at', 'desc')
  6821. // ->limit(5)
  6822. ->get();
  6823. //获取5条单聊未读聊天消息
  6824. // $chat = ChatRecords::where('is_read', 0)
  6825. // ->where('user_id', $user_id)
  6826. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  6827. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  6828. // ->where('action', 'recieved')
  6829. // ->where('talk_type', 1)
  6830. // ->orderBy('created_at', 'desc')
  6831. // // ->limit(5)
  6832. // ->get();
  6833. //获取5条未读群聊信息
  6834. // $chat_group = ChatRecords::where('is_read', 0)
  6835. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  6836. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  6837. // ->where('user_id', $user_id)
  6838. // ->where('talk_type', 2)
  6839. // ->orderBy('created_at', 'desc')
  6840. // // ->limit(5)
  6841. // ->get();
  6842. //获取5条用户的待审核项目
  6843. $project = Project::where('status', 1)
  6844. ->where('user_id', $user_id)
  6845. ->orderBy('updated_at', 'desc')
  6846. // ->limit(5)
  6847. ->get();
  6848. // count($chat) + count($chat_group) +
  6849. $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)
  6850. + count($complany)
  6851. + count($project)
  6852. // + count($chat) + count($chat_group)
  6853. ;
  6854. $result = [
  6855. 'apply_articale' => $apply_articale,
  6856. // 'chat' => $chat,
  6857. // 'chat_group' => $chat_group,
  6858. 'good' => $good,
  6859. 'notice' => $notice,
  6860. 'complaint' => $complaint,
  6861. 'book' => $book,
  6862. 'job_hunting' => $job_hunting,
  6863. 'job_recruiting' => $job_recruiting,
  6864. 'job_apply' => $job_apply,
  6865. 'job_resume' => $job_resume,
  6866. 'complaint_deal' => $complaint_deal,
  6867. 'complany' => $complany,
  6868. 'project' => $project,
  6869. 'count' => $count,
  6870. ];
  6871. } elseif ($type_id == 12) {
  6872. //最近的5篇已审的文章
  6873. $apply_articale = Article::where('status', 1)
  6874. ->where('admin_user_id', $user_id)
  6875. ->limit(5)->get();
  6876. //获取5条单聊未读聊天消息
  6877. $chat = ChatRecords::where('is_read', 0)
  6878. ->where('user_id', $user_id)
  6879. ->where('talk_type', 1)
  6880. ->orderBy('created_at', 'desc')
  6881. ->limit(5)->get();
  6882. //获取5条未读群聊信息
  6883. $chat_group = ChatRecords::where('is_read', 0)
  6884. ->where('user_id', $user_id)
  6885. ->where('talk_type', 2)
  6886. ->orderBy('created_at', 'desc')
  6887. ->limit(5)->get();
  6888. //获取5条用户的已审核商品
  6889. $good = Good::where('status', 2)
  6890. ->where('user_id', $user_id)
  6891. ->orderBy('updated_at', 'desc')
  6892. ->limit(5)->get();
  6893. //获取5条用户的book
  6894. $book = Book::where('status', 2)
  6895. ->where('user_id', $user_id)
  6896. ->orderBy('updated_at', 'desc')
  6897. ->limit(5)->get();
  6898. //获取5条用户的求职
  6899. //获取5条用户的求职 1
  6900. //count($chat) + count($chat_group)
  6901. $count = count($apply_articale) + count($good);
  6902. $result = [
  6903. 'apply_articale' => $apply_articale,
  6904. 'chat' => $chat,
  6905. 'chat_group' => $chat_group,
  6906. 'good' => $good,
  6907. 'book' => $book,
  6908. 'count' => $count,
  6909. ];
  6910. } elseif ($type_id == 13) {
  6911. //最近的5篇已审的文章
  6912. $apply_articale = Article::where('status', 1)
  6913. ->where('admin_user_id', $user_id)
  6914. ->limit(5)->get();
  6915. //获取5条单聊未读聊天消息
  6916. $chat = ChatRecords::where('is_read', 0)
  6917. ->where('user_id', $user_id)
  6918. ->where('talk_type', 1)
  6919. ->orderBy('created_at', 'desc')
  6920. ->limit(5)->get();
  6921. //获取5条未读群聊信息
  6922. $chat_group = ChatRecords::where('is_read', 0)
  6923. ->where('user_id', $user_id)
  6924. ->where('talk_type', 2)
  6925. ->orderBy('created_at', 'desc')
  6926. ->limit(5)->get();
  6927. //获取5条用户的已审核商品
  6928. $good = Good::where('status', 2)
  6929. ->where('user_id', $user_id)
  6930. ->orderBy('updated_at', 'desc')
  6931. ->limit(5)->get();
  6932. //count($chat) + count($chat_group) +
  6933. $count = count($apply_articale) + count($good);
  6934. $result = [
  6935. 'apply_articale' => $apply_articale,
  6936. 'chat' => $chat,
  6937. 'chat_group' => $chat_group,
  6938. 'good' => $good,
  6939. 'count' => $count,
  6940. ];
  6941. } elseif ($type_id == 14) {
  6942. //最近的5篇已审的文章
  6943. $apply_articale = Article::where('status', 1)
  6944. ->where('admin_user_id', $user_id)
  6945. // ->limit(5)
  6946. ->get();
  6947. //获取5条用户的已审核商品
  6948. $good = Good::where('status', 2)
  6949. ->where('user_id', $user_id)
  6950. ->orderBy('updated_at', 'desc')
  6951. // ->limit(5)
  6952. ->get();
  6953. $count = count($apply_articale) + count($good);
  6954. $result = [
  6955. 'apply_articale' => $apply_articale,
  6956. 'chat' => '',
  6957. 'chat_group' => '',
  6958. 'good' => $good,
  6959. 'count' => $count,
  6960. ];
  6961. } elseif ($type_id == 10000) {
  6962. //获取未审核的5篇文章
  6963. $apply_articale = Article::where('status', 0)
  6964. ->orderBy('updated_at', 'desc')
  6965. // ->limit(5)
  6966. ->get();
  6967. //获取5条单聊未读聊天消息
  6968. //获取5条单聊未读聊天消息
  6969. // $chat = ChatRecords::where('is_read', 0)
  6970. // ->where('user_id', $user_id)
  6971. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  6972. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  6973. // ->where('action', 'recieved')
  6974. // ->where('talk_type', 1)
  6975. // ->orderBy('created_at', 'desc')
  6976. // // ->limit(5)
  6977. // ->get();
  6978. // //获取5条未读群聊信息
  6979. // $chat_group = ChatRecords::where('is_read', 0)
  6980. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  6981. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  6982. // ->where('user_id', $user_id)
  6983. // ->where('talk_type', 2)
  6984. // ->orderBy('created_at', 'desc')
  6985. // // ->limit(5)
  6986. // ->get();
  6987. //获取5条用户的已审核商品
  6988. $good = Good::where('status', 1)
  6989. // ->where('user_id', $user_id)
  6990. ->orderBy('updated_at', 'desc')
  6991. // ->limit(5)
  6992. ->get();
  6993. //获取5条用户待审核的公告
  6994. $notice = Notice::where('status', 1)
  6995. ->orderBy('updated_at', 'desc')
  6996. // ->limit(5)
  6997. ->get();
  6998. //获取5条用户的待审核投诉
  6999. $complaint = Complaint::where('status', 1)
  7000. ->orderBy('updated_at', 'desc')
  7001. // ->limit(5)
  7002. ->get();
  7003. //获取5条用户的book
  7004. $book = Book::where('status', 1)
  7005. ->orderBy('updated_at', 'desc')
  7006. // ->limit(5)
  7007. ->get();
  7008. //获取5条用户的求职 1
  7009. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7010. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7011. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7012. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7013. ->orderBy('updated_at', 'desc')
  7014. // ->limit(5)
  7015. ->get();
  7016. //获取5条用户的求职 2
  7017. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7018. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7019. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7020. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7021. ->orderBy('updated_at', 'desc')
  7022. // ->limit(5)
  7023. ->get();
  7024. //人才库 1
  7025. $job_apply = JobApply::where('job_apply.status', 1)
  7026. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7027. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7028. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7029. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7030. ->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')
  7031. ->orderBy('updated_at', 'desc')
  7032. // ->limit(5)
  7033. ->get();
  7034. // 职场机会 2
  7035. $job_resume = JobResume::where('job_resume.status', 1)
  7036. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7037. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7038. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7039. ->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')
  7040. ->orderBy('updated_at', 'desc')
  7041. // ->limit(5)
  7042. ->get();
  7043. //待审核数据com pro
  7044. $complany = Company::where('status', 0)
  7045. ->orderBy('updated_at', 'desc')
  7046. // ->limit(5)
  7047. ->get();
  7048. $project = Project::where('status', 0)
  7049. ->orderBy('updated_at', 'desc')
  7050. // ->limit(5)
  7051. ->get();
  7052. $count =
  7053. // count($chat) +
  7054. // count($chat_group) +
  7055. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7056. + count($job_apply)
  7057. + count($job_resume)
  7058. + count($complany)
  7059. + count($project);
  7060. $result = [
  7061. 'apply_articale' => $apply_articale,
  7062. // 'chat' => $chat,
  7063. // 'chat_group' => $chat_group,
  7064. 'good' => $good,
  7065. 'notice' => $notice,
  7066. 'complaint' => $complaint,
  7067. 'book' => $book,
  7068. 'job_hunting' => $job_hunting,
  7069. 'job_recruiting' => $job_recruiting,
  7070. 'job_apply' => $job_apply,
  7071. 'job_resume' => $job_resume,
  7072. 'complany' => $complany,
  7073. 'project' => $project,
  7074. 'count' => $count,
  7075. ];
  7076. } elseif ($type_id == 20000) {
  7077. }
  7078. var_dump($type_id, '-----------------test---------');
  7079. return Result::success($result);
  7080. }
  7081. /**
  7082. * @param array $data
  7083. * @return array
  7084. */
  7085. public function getWebsiteProject(array $data): array
  7086. {
  7087. $categorys = json_decode($data['id'], true);
  7088. if (!empty($categorys)) {
  7089. $category_arr = $this->processArticlePro($data['website_id']);
  7090. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7091. $catiall = $category_arr['catiall'];
  7092. // return Result::success($catiall);
  7093. foreach ($categorys as $key => $val) {
  7094. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7095. $level = explode(',', $val['level'])[0];
  7096. $imgnum = explode(',', $val['level'])[1] ?? null;
  7097. $textnum = explode(',', $val['level'])[2] ?? null;
  7098. if ($level == 1) {
  7099. if (!empty($textnum) && $textnum > 0) {
  7100. $text_num = Project::where('level', $level)
  7101. ->where('website_id', $data['website_id'])
  7102. ->where('status', 1)
  7103. ->select(
  7104. 'project.id',
  7105. 'project.title',
  7106. 'project.description',
  7107. 'project.updated_at',
  7108. 'project.category_id',
  7109. 'project.cat_arr_id'
  7110. )
  7111. ->orderBy('updated_at', 'desc')
  7112. ->limit($textnum)
  7113. ->get()->all();
  7114. }
  7115. if (!empty($imgnum) && $imgnum > 0) {
  7116. $img_num = Project::where('level', $level)
  7117. ->where('website_id', $data['website_id'])
  7118. ->where('status', 1)
  7119. ->where('imgurl', '!=', '')
  7120. ->whereNotNull('imgurl')
  7121. ->select(
  7122. 'project.id',
  7123. 'project.title',
  7124. 'project.description',
  7125. 'project.updated_at',
  7126. 'project.imgurl as imgs',
  7127. 'project.category_id',
  7128. 'project.cat_arr_id'
  7129. )
  7130. ->orderBy('updated_at', 'desc')
  7131. ->limit($imgnum)
  7132. ->get()->all();
  7133. }
  7134. } else {
  7135. if (!empty($textnum) && $textnum > 0) {
  7136. $text_num = Project::where('website_id', $data['website_id'])
  7137. ->where('status', 1)
  7138. ->select(
  7139. 'project.id',
  7140. 'project.title',
  7141. 'project.description',
  7142. 'project.updated_at',
  7143. 'project.category_id',
  7144. 'project.cat_arr_id',
  7145. 'project.website_id',
  7146. 'project.updated_at',
  7147. 'project.created_at'
  7148. )
  7149. ->orderBy('updated_at', 'desc')
  7150. ->limit($textnum)
  7151. ->get()->all();
  7152. }
  7153. if (!empty($imgnum) && $imgnum > 0) {
  7154. $img_num = Project::where('website_id', $data['website_id'])
  7155. ->where('status', 1)
  7156. ->where('imgurl', '!=', '')
  7157. ->whereNotNull('imgurl')
  7158. ->select(
  7159. 'project.id',
  7160. 'project.title',
  7161. 'project.description',
  7162. 'project.updated_at',
  7163. 'project.imgurl as imgs',
  7164. 'project.category_id',
  7165. 'project.cat_arr_id'
  7166. )
  7167. ->orderBy('updated_at', 'desc')
  7168. ->limit($imgnum)
  7169. ->get()->all();
  7170. }
  7171. }
  7172. }
  7173. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7174. $category_ids = explode(',', $val['id'])[0];
  7175. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7176. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7177. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7178. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7179. $text_num = Project::whereIn('category_id', $category_arr)
  7180. ->where('website_id', $data['website_id'])
  7181. ->where('status', 1)
  7182. ->select(
  7183. 'project.id',
  7184. 'project.title',
  7185. 'project.description',
  7186. 'project.updated_at',
  7187. 'project.category_id',
  7188. 'project.cat_arr_id'
  7189. )
  7190. ->orderBy('updated_at', 'desc')
  7191. ->limit($cat_textnum)
  7192. ->get()->all();
  7193. }
  7194. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7195. $img_num = Project::whereIn('category_id', $category_arr)
  7196. ->where('website_id', $data['website_id'])
  7197. ->where('status', 1)
  7198. ->where('imgurl', '!=', '')
  7199. ->whereNotNull('imgurl')
  7200. ->select(
  7201. 'project.id',
  7202. 'project.title',
  7203. 'project.description',
  7204. 'project.updated_at',
  7205. 'project.imgurl as imgs',
  7206. 'project.category_id',
  7207. 'project.cat_arr_id'
  7208. )
  7209. ->orderBy('updated_at', 'desc')
  7210. ->limit($cat_imgnum)
  7211. ->get()->all();
  7212. }
  7213. }
  7214. if (!empty($img_num)) {
  7215. foreach ($img_num as $k => $v) {
  7216. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7217. $imgurl = json_decode($v['imgs'], true);
  7218. if (!empty($imgurl)) {
  7219. $img_num[$k]->imgurl = $imgurl[0];
  7220. }
  7221. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7222. }
  7223. }
  7224. if (!empty($text_num)) {
  7225. foreach ($text_num as $k => $v) {
  7226. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7227. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7228. }
  7229. }
  7230. $project[$key]['img_num'] = $img_num ?? [];
  7231. $project[$key]['text_num'] = $text_num ?? [];
  7232. }
  7233. }
  7234. if (empty($project)) {
  7235. return Result::error("暂无相关项目信息", 0);
  7236. }
  7237. return Result::success($project);
  7238. }
  7239. /**
  7240. * @param array $data
  7241. * @return array
  7242. */
  7243. public function getWebsiteProjectInfo(array $data): array
  7244. {
  7245. $project = Project::where('id', $data['id'])
  7246. ->where('status', 1)
  7247. ->where('website_id', $data['website_id'])
  7248. ->select('project.*')
  7249. ->first();
  7250. if (empty($project)) {
  7251. return Result::error("暂无相关项目信息", 0);
  7252. }
  7253. return Result::success($project);
  7254. }
  7255. /**
  7256. * @param array $data
  7257. * @return array
  7258. */
  7259. public function getWebsiteProjectList(array $data): array
  7260. {
  7261. $where = [];
  7262. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7263. $where['category_id'] = $data['category_id'];
  7264. }
  7265. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7266. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7267. }
  7268. $query = Project::where($where)
  7269. ->where('status', 1)
  7270. ->where('website_id', $data['website_id'])
  7271. ->select(
  7272. 'project.id',
  7273. 'project.title',
  7274. 'project.description',
  7275. 'project.imgurl as imgs',
  7276. 'project.category_id',
  7277. 'project.cat_arr_id'
  7278. )
  7279. ->orderBy('updated_at', 'desc');
  7280. $count = $query->count();
  7281. $project = $query->clone()
  7282. ->offset(($data['page'] - 1) * $data['pageSize'])
  7283. ->limit($data['pageSize'])
  7284. ->get()->all();
  7285. if (empty($project)) {
  7286. return Result::error("暂无相关项目信息", 0);
  7287. }
  7288. $categorys = $this->processArticlePro($data['website_id']);
  7289. $catiall = $categorys['catiall'];
  7290. foreach ($project as $key => $val) {
  7291. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7292. if (!empty($val['imgs'])) {
  7293. $imgurl = json_decode($val['imgs'], true);
  7294. if (!empty($imgurl)) {
  7295. $project[$key]->imgurl = $imgurl[0];
  7296. }
  7297. } else {
  7298. $project[$key]->imgurl = '';
  7299. }
  7300. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7301. }
  7302. $result = [
  7303. 'rows' => $project,
  7304. 'count' => $count,
  7305. ];
  7306. return Result::success($result);
  7307. }
  7308. /**
  7309. * @param array $data
  7310. * @return array
  7311. */
  7312. public function getWebsiteCategoryJob(array $data): array
  7313. {
  7314. $categorys = json_decode($data['id'], true);
  7315. if (!empty($categorys)) {
  7316. $category_arr = $this->processArticlePro($data['website_id']);
  7317. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7318. $catiall = $category_arr['catiall'];
  7319. foreach ($categorys as $key => $val) {
  7320. if (isset($val['id']) && !empty($val['id'])) {
  7321. $catid = explode(',', $val['id'])[0] ?? null;
  7322. $type = explode(',', $val['id'])[1] ?? null;
  7323. $textnum = explode(',', $val['id'])[2] ?? null;
  7324. }
  7325. // 4:招聘;5:求职;
  7326. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7327. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7328. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7329. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7330. ->where('job_recruiting.status', 1)
  7331. ->where('job_recruiting.website_id', $data['website_id'])
  7332. ->select(
  7333. 'job_recruiting.id',
  7334. 'job_recruiting.title',
  7335. 'job_company.business_name',
  7336. 'job_recruiting.updated_at',
  7337. 'job_recruiting.cat_arr_id'
  7338. )
  7339. ->orderBy('job_recruiting.updated_at', 'desc')
  7340. ->limit($textnum)
  7341. ->get()->all();
  7342. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7343. // 状态 审核状态,1待审核2已审核3已拒绝
  7344. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7345. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7346. ->where('job_hunting.status', 2)
  7347. ->where('job_hunting.website_id', $data['website_id'])
  7348. ->select(
  7349. 'job_hunting.id',
  7350. 'job_hunting.name',
  7351. 'job_hunting.cat_arr_id',
  7352. 'job_position.zwname as job_name',
  7353. 'job_hunting.updated_at'
  7354. )
  7355. ->orderBy('updated_at', 'desc')
  7356. ->limit($textnum)
  7357. ->get()->all();
  7358. } else {
  7359. $job = [];
  7360. }
  7361. // var_dump($catid.'222uuuuuuu'.$key);
  7362. if (!empty($job)) {
  7363. foreach ($job as $k => $value) {
  7364. if (isset($value->cat_arr_id)) {
  7365. $catArr = json_decode($value->cat_arr_id, true);
  7366. $catId = end($catArr);
  7367. } else {
  7368. continue;
  7369. }
  7370. if (isset($catiall[$catId])) {
  7371. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7372. }
  7373. }
  7374. }
  7375. // var_dump($catid.'xxxxx'.$key);
  7376. $result[$key] = $job ?? [];
  7377. }
  7378. }
  7379. if (empty($result)) {
  7380. return Result::error("暂无相关分类信息", 0);
  7381. }
  7382. return Result::success($result);
  7383. }
  7384. /**
  7385. * 发送消息
  7386. * @param array $messageData
  7387. * @return void
  7388. */
  7389. public function sendMessage($messageData)
  7390. {
  7391. $msg = [
  7392. 'talk_type' => $messageData['talk_type'],
  7393. 'title' => $messageData['title'],
  7394. 'content' => $messageData['content'],
  7395. 'messageType' => $messageData['messageType'],
  7396. 'user_id' => $messageData['user_id'] ?? '',
  7397. 'time' => microtime(),
  7398. ];
  7399. $message = new MqProducer($msg);
  7400. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7401. $producer->produce($message);
  7402. }
  7403. }