NewsService.php 260 KB

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