NewsService.php 269 KB

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