NewsService.php 260 KB

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