NewsService.php 268 KB

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