NewsService.php 270 KB

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