NewsService.php 278 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832
  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. use App\Model\Web;
  64. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  65. class NewsService implements NewsServiceInterface
  66. {
  67. #[Inject]
  68. protected Redis $redis;
  69. /**
  70. * 获取导航池列表
  71. * @param array $data
  72. * @return array
  73. */
  74. public function getCategoryList(array $data): array
  75. {
  76. $search = $data['name'] ?? '';
  77. $page = (int)($data['page'] ?? 1);
  78. $perPage = (int)($data['pageSize'] ?? 10);
  79. // 1. 查出所有匹配的分类id
  80. if ($search) {
  81. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  82. if (empty($matchedIds)) {
  83. return Result::success(['rows' => [], 'total' => 0]);
  84. }
  85. // 2. 递归查所有父级,直到一级分类
  86. $idsStr = implode(',', $matchedIds);
  87. $sql = "
  88. WITH RECURSIVE parents AS (
  89. SELECT * FROM category WHERE id IN ($idsStr)
  90. UNION ALL
  91. SELECT c.* FROM category c
  92. INNER JOIN parents p ON c.id = p.pid
  93. )
  94. SELECT * FROM parents
  95. ";
  96. $parents = Db::select($sql);
  97. $parentIds = [];
  98. foreach ($parents as $row) {
  99. if ($row->pid == 0) {
  100. $parentIds[] = $row->id;
  101. }
  102. }
  103. $parentIds = array_unique($parentIds);
  104. } else {
  105. // 没有搜索,一级分类就是根
  106. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  107. }
  108. // 3. 一级分类分页
  109. $total = count($parentIds);
  110. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  111. if (empty($parentIds)) {
  112. return Result::success(['rows' => [], 'total' => $total]);
  113. }
  114. // 4. 递归查所有子孙
  115. $idsStr = implode(',', $parentIds);
  116. $sql = "
  117. WITH RECURSIVE subcategories AS (
  118. SELECT * FROM category WHERE id IN ($idsStr)
  119. UNION ALL
  120. SELECT c.* FROM category c
  121. INNER JOIN subcategories s ON c.pid = s.id
  122. )
  123. SELECT * FROM subcategories ORDER BY updated_at DESC
  124. ";
  125. $allCategories = Db::select($sql);
  126. // 5. 组装树结构
  127. $categoryMap = [];
  128. foreach ($allCategories as $cat) {
  129. $cat = (array)$cat;
  130. $cat['children'] = [];
  131. $categoryMap[$cat['id']] = $cat;
  132. }
  133. foreach ($categoryMap as $id => &$cat) {
  134. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  135. $categoryMap[$cat['pid']]['children'][] = &$cat;
  136. }
  137. }
  138. unset($cat);
  139. $categoryTree = [];
  140. foreach ($parentIds as $id) {
  141. if (isset($categoryMap[$id])) {
  142. $categoryTree[] = $categoryMap[$id];
  143. }
  144. }
  145. return Result::success([
  146. 'rows' => $categoryTree,
  147. 'total' => $total,
  148. ]);
  149. }
  150. private function findMatchedCategories($search)
  151. {
  152. if ($search) {
  153. return Category::where('name', 'like', "%{$search}%")
  154. ->orderBy('updated_at', 'desc')
  155. ->get();
  156. }
  157. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  158. ->get();
  159. }
  160. private function findAllParents($categories)
  161. {
  162. $allCategories = [];
  163. foreach ($categories as $category) {
  164. $parentId = $category->pid;
  165. while ($parentId > 0) {
  166. $parent = Category::find($parentId);
  167. if ($parent) {
  168. $allCategories[$parent->id] = $parent;
  169. $parentId = $parent->pid;
  170. } else {
  171. break;
  172. }
  173. }
  174. $allCategories[$category->id] = $category;
  175. }
  176. return array_values($allCategories);
  177. }
  178. private function buildCategoryTree($category, $allRequiredCategories)
  179. {
  180. $categoryData = $category->toArray();
  181. $children = [];
  182. foreach ($allRequiredCategories as $c) {
  183. if ($c->pid === $category->id) {
  184. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  185. }
  186. }
  187. if (!empty($children)) {
  188. $categoryData['children'] = $children;
  189. }
  190. return $categoryData;
  191. }
  192. public function myCategoryList(array $data): array
  193. {
  194. $sszq = $data['sszq'] ?? '';
  195. unset($data['sszq']);
  196. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  197. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  198. $where[] = [
  199. 'pid',
  200. '=',
  201. $data['pid'],
  202. ];
  203. if (isset($data['name'])) {
  204. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  205. }
  206. var_dump($where);
  207. //根据分类id,从category表中取出分类信息
  208. $result = Category::where($where)
  209. ->whereIn('category.id', $catorytids)
  210. ->select('category.*', 'category.id as category_id')->get();
  211. if (empty($result)) {
  212. return Result::error("没有栏目数据");
  213. }
  214. return Result::success($result);
  215. }
  216. /**
  217. * @param array $data
  218. * @return array
  219. */
  220. public function categoryList(array $data): array
  221. {
  222. $where[] = [
  223. 'pid',
  224. '=',
  225. $data['pid']
  226. ];
  227. if (isset($data['name'])) {
  228. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  229. }
  230. var_dump($where);
  231. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  232. if (empty($result)) {
  233. return Result::error("没有栏目数据");
  234. }
  235. return Result::success($result);
  236. }
  237. /**
  238. * @param array $data
  239. * @return array
  240. */
  241. public function addCategory(array $data): array
  242. {
  243. if (isset($data['id'])) {
  244. unset($data['id']);
  245. }
  246. $id = Category::insertGetId($data);
  247. if (empty($id)) {
  248. return Result::error("添加失败");
  249. }
  250. return Result::success(['id' => $id]);
  251. }
  252. /**
  253. * @param array $data
  254. * @return array
  255. */
  256. public function delCategory(array $data): array
  257. {
  258. Db::beginTransaction();
  259. try {
  260. $categoryList = Category::where(['pid' => $data['id']])->get();
  261. if ($categoryList->toArray()) {
  262. Db::rollBack();
  263. return Result::error("分类下面有子分类不能删除");
  264. }
  265. $articleList = Article::where(['catid' => $data['id']])->get();
  266. if ($articleList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有资讯不能删除");
  269. }
  270. $result = Category::where($data)->delete();
  271. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  272. if (!$result) {
  273. Db::rollBack();
  274. return Result::error("删除失败");
  275. }
  276. Db::commit();
  277. return Result::success($result);
  278. } catch (\Exception $e) {
  279. Db::rollBack();
  280. return Result::error("删除失败" . $e->getMessage());
  281. }
  282. }
  283. /**
  284. * @param array $data
  285. * @return array
  286. */
  287. public function updateCategory(array $data): array
  288. {
  289. $where = [
  290. 'id' => $data['id'],
  291. ];
  292. $result = Category::where($where)->update($data);
  293. if ($result) {
  294. return Result::success($result);
  295. } else {
  296. return Result::error("更新失败");
  297. }
  298. }
  299. /**
  300. * 获取导航池信息
  301. * @param array $data
  302. * @return array
  303. */
  304. public function getCategoryInfo(array $data): array
  305. {
  306. $where = [
  307. 'id' => $data['id'],
  308. ];
  309. $result = Category::where($where)->first();
  310. if ($result) {
  311. return Result::success($result);
  312. } else {
  313. return Result::error("更新失败");
  314. }
  315. }
  316. public function getArticleCommend(array $data): array
  317. {
  318. $where = [
  319. 'website_id' => $data['website_id'],
  320. ];
  321. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  322. var_dump($ids);
  323. if (empty($ids)) {
  324. return Result::error("没有推荐数据");
  325. }
  326. //id
  327. $whereArticle = [];
  328. if (isset($data['id'])) {
  329. $whereArticle['id'] = $data['id'];
  330. }
  331. //title like
  332. if (isset($data['title'])) {
  333. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  334. }
  335. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  336. ->where($whereArticle)
  337. ->orderBy('id', 'desc')
  338. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  339. if ($article) {
  340. $data = [
  341. 'rows' => $article->items(),
  342. 'count' => $article->total(),
  343. ];
  344. return Result::success($data);
  345. } else {
  346. return Result::error("获取失败失败");
  347. }
  348. }
  349. /**
  350. * @param array $data
  351. * @return array
  352. */
  353. public function getArticleList(array $data): array
  354. {
  355. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  356. $type_id = $data['type_id'];
  357. unset($data['type_id']);
  358. $user_id = $data['user_id'];
  359. unset($data['user_id']);
  360. $where = [];
  361. $status1 = [];
  362. if (isset($data['id']) && $data['id']) {
  363. array_push($where, ['article.id', '=', $data['id']]);
  364. }
  365. if (isset($data['title']) && $data['title']) {
  366. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  367. }
  368. if (isset($data['category_name']) && $data['category_name']) {
  369. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  370. }
  371. if (isset($data['catid']) && $data['catid']) {
  372. array_push($where, ['article.catid', '=', $data['catid']]);
  373. }
  374. if (isset($data['author']) && $data['author']) {
  375. array_push($where, ['article.author', '=', $data['author']]);
  376. }
  377. if (isset($data['islink']) && $data['islink'] !== "") {
  378. array_push($where, ['article.islink', '=', $data['islink']]);
  379. }
  380. if (isset($data['status']) && $data['status'] !== "") {
  381. array_push($where, ['article.status', '=', $data['status']]);
  382. }
  383. if (isset($data['status1'])) {
  384. $status1 = json_decode(($data['status1']));
  385. }
  386. //不是管理员展示个人数据;
  387. if ($type_id != 10000) {
  388. $where[] = ['article.admin_user_id', '=', $user_id];
  389. }
  390. $rep = Article::where($where)
  391. ->whereNotIn('article.status', [404])
  392. ->when($status1, function ($query) use ($status1) {
  393. if (isset($status1) && $status1) {
  394. $query->whereIn('article.status', $status1);
  395. }
  396. })
  397. ->leftJoin('category', 'article.catid', 'category.id')
  398. ->leftJoin('website_category', function ($join) {
  399. $join->on('article.web_site_id', '=', 'website_category.website_id')
  400. ->on('article.catid', '=', 'website_category.category_id');
  401. })
  402. ->select("article.*", "category.name as category_name", "website_category.alias")
  403. ->orderBy("article.updated_at", "desc")
  404. ->limit($data['pageSize'])
  405. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  406. $count = Article::where($where)->whereNotIn('article.status', [404])
  407. ->when($status1, function ($query) use ($status1) {
  408. if (isset($status1) && $status1) {
  409. $query->whereIn('article.status', $status1);
  410. }
  411. })
  412. ->leftJoin('category', 'article.catid', 'category.id')->count();
  413. $data = [
  414. 'rows' => $rep->toArray(),
  415. 'count' => $count,
  416. ];
  417. if (empty($rep)) {
  418. return Result::error("没有信息数据");
  419. }
  420. return Result::success($data);
  421. }
  422. /**
  423. * @param array $data
  424. * @return array
  425. */
  426. public function addArticle(array $data): array
  427. {
  428. var_dump($data, '----------12-----------1');
  429. unset($data['user_type']);
  430. unset($data['nav_add_pool_id']);
  431. // unset($data['commend_id']);
  432. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  433. Db::beginTransaction();
  434. try {
  435. //处理投票
  436. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  437. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  438. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  439. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  440. unset($data['is_survey']);
  441. unset($data['survey_name']);
  442. unset($data['suvey_array']);
  443. // unset($data['website_id']);
  444. // unset($data['web_site_id']);
  445. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  446. if ($data['hits'] == '') {
  447. $data['hits'] = 0;
  448. }
  449. if ($data['is_original'] == '') {
  450. $data['is_original'] = 0;
  451. }
  452. if ($data['status'] == '') {
  453. $data['status'] = 0;
  454. }
  455. $articleData = $data;
  456. unset($articleData['content']);
  457. //自动处理缩略图、关键字、描述
  458. if ($articleData['imgurl'] == '') {
  459. //如果没有图,设置level=0
  460. $levelArr = json_decode($articleData['level'], true);
  461. var_dump($levelArr, '----------levelArr-----------1');
  462. //content中提取图片第一个图,正则提取
  463. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  464. preg_match_all($reg, $data['content'], $matches);
  465. if (isset($matches[1][0])) {
  466. //截取varchar240
  467. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  468. //如果有图,设置level=3
  469. if (!in_array(3, $levelArr)) {
  470. $levelArr[] = 3;
  471. }
  472. $articleData['level'] = json_encode($levelArr);
  473. } else {
  474. if (!in_array(0, $levelArr)) {
  475. $levelArr[] = 0;
  476. }
  477. $articleData['level'] = json_encode($levelArr);
  478. }
  479. }
  480. var_dump($articleData['level'], '----------$articleData[level]----------1');
  481. if ($articleData['keyword'] == '') {
  482. //提取标题+内容中的关键词
  483. $articleData['keyword'] = $data['title'];
  484. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  485. Jieba::init(); // 初始化 jieba-php
  486. Finalseg::init();
  487. $segList = Jieba::cut($articleData['keyword']);
  488. $segList1 = array_slice($segList, 0, 8);
  489. $articleData['keyword'] = implode(',', $segList1);
  490. }
  491. if ($articleData['introduce'] == '') {
  492. //提取内容中的描述
  493. $content = $data['content'];
  494. // 去除 <style> 和 <script> 标签及其内容
  495. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  496. // 去除所有 HTML 标签
  497. $content = strip_tags($content);
  498. // 去除 HTML 实体
  499. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  500. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  501. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  502. // 去除多余空白
  503. $content = preg_replace('/\s+/u', '', $content);
  504. // 截取 100 个字符
  505. $articleData['introduce'] = mb_substr($content, 0, 100);
  506. }
  507. if ($articleData['status'] == 0) {
  508. $this->sendMessage([
  509. 'talk_type' => 100,
  510. 'title' => $articleData['title'],
  511. 'content' => '提交了审核',
  512. 'messageType' => 2,
  513. ]);
  514. }
  515. $id = Article::insertGetId($articleData);
  516. $articleDataContent = [
  517. 'article_id' => $id,
  518. 'content' => $data['content'],
  519. ];
  520. ArticleData::insertGetId($articleDataContent);
  521. //处理投票
  522. if ($is_survey == 1) {
  523. //生成年月日时分秒+8位随机数
  524. $uuid = date('YmdHis') . rand(10000000, 99999999);
  525. var_dump($suvey_array, 'suvey_array________');
  526. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  527. var_dump($suveys_array, '---------------------1');
  528. var_dump($suvey_array, '---------------------2');
  529. $suvey_data = [];
  530. foreach ($suveys_array as $key => $value) {
  531. if ($value == '') {
  532. continue;
  533. }
  534. if (is_array($value)) {
  535. $suvey_data[] = [
  536. 'sur_id' => $uuid,
  537. 'art_id' => $id,
  538. 'website_id' => $website_id ?? 2,
  539. 'survey_name' => $survey_name,
  540. 'choice_name' => $value[1],
  541. 'is_other' => 1,
  542. 'other_id' => 0,
  543. 'results' => 0,
  544. ];
  545. } else {
  546. $suvey_data[] = [
  547. 'sur_id' => $uuid,
  548. 'art_id' => $id,
  549. 'website_id' => $website_id ?? 2,
  550. 'survey_name' => $survey_name,
  551. 'choice_name' => $value,
  552. 'is_other' => 0,
  553. 'other_id' => 0,
  554. 'results' => 0,
  555. ];
  556. }
  557. if (empty($suvey_data)) {
  558. throw new \Exception("投票数据为空");
  559. }
  560. }
  561. $result = ArticleSurvey::insert($suvey_data);
  562. if (!$result) {
  563. throw new \Exception("投票失败,ArticleSurvey插入失败");
  564. }
  565. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  566. if (!$result) {
  567. throw new \Exception("投票失败,更新主表失败");
  568. }
  569. }
  570. Db::commit();
  571. return Result::success(['id' => $id]);
  572. } catch (\Throwable $ex) {
  573. Db::rollBack();
  574. var_dump($ex->getMessage());
  575. return Result::error("创建失败", 0);
  576. }
  577. }
  578. /**
  579. * @param array $data
  580. * @return array
  581. */
  582. public function delArticle(array $data): array
  583. {
  584. $result = Article::where($data)->delete();
  585. //survey投票删除
  586. articleSurvey::where(['art_id' => $data['id']])->delete();
  587. if (!$result) {
  588. return Result::error("删除失败");
  589. }
  590. return Result::success($result);
  591. }
  592. /**
  593. * @param array $data
  594. * @return array
  595. */
  596. public function updateArticle(array $data): array
  597. {
  598. var_dump($data, '----------12-----------1');
  599. Db::beginTransaction();
  600. unset($data['user_type']);
  601. // unset($data['web_site_id']);
  602. unset($data['nav_add_pool_id']);
  603. try {
  604. //处理投票
  605. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  606. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  607. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  608. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  609. unset($data['is_survey']);
  610. unset($data['survey_name']);
  611. unset($data['suvey_array']);
  612. unset($data['website_id']);
  613. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  614. if ($data['hits'] == '') {
  615. $data['hits'] = 0;
  616. }
  617. if ($data['is_original'] == '') {
  618. $data['is_original'] = 0;
  619. }
  620. if ($data['status'] == '') {
  621. $data['status'] = 0;
  622. }
  623. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  624. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  625. $articleData = $data;
  626. unset($articleData['content']);
  627. unset($articleData['status_name']);
  628. unset($articleData['name']);
  629. unset($articleData['content']);
  630. unset($articleData['pid_arr']);
  631. unset($articleData['pid']);
  632. //自动处理缩略图、关键字、描述
  633. if ($articleData['imgurl'] == '') {
  634. //如果没有图,设置level=0
  635. $levelArr = json_decode($articleData['level'], true);
  636. var_dump($levelArr, '----------levelArr-----------1');
  637. //content中提取图片第一个图,正则提取
  638. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  639. preg_match_all($reg, $data['content'], $matches);
  640. if (isset($matches[1][0])) {
  641. //截取varchar240
  642. // 截取到第一个<
  643. $articleData['imgurl'] = $matches[1][0];
  644. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  645. $pos = strpos($articleData['imgurl'], '"');
  646. if ($pos !== false) {
  647. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  648. }
  649. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  650. //如果有图,设置level=3
  651. if (!in_array(3, $levelArr)) {
  652. $levelArr[] = 3;
  653. }
  654. $articleData['level'] = json_encode($levelArr);
  655. } else {
  656. if (!in_array(0, $levelArr)) {
  657. $levelArr[] = 0;
  658. }
  659. $articleData['level'] = json_encode($levelArr);
  660. }
  661. }
  662. var_dump($articleData['level'], '----------$articleData[level]----------1');
  663. if ($articleData['keyword'] == '') {
  664. //提取标题+内容中的关键词
  665. $articleData['keyword'] = $data['title'];
  666. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  667. Jieba::init(); // 初始化 jieba-php
  668. Finalseg::init();
  669. $segList = Jieba::cut($articleData['keyword']);
  670. $segList1 = array_slice($segList, 0, 8);
  671. $articleData['keyword'] = implode(',', $segList1);
  672. }
  673. if ($articleData['introduce'] == '') {
  674. //提取内容中的描述
  675. $content = $data['content'];
  676. // 去除 <style> 和 <script> 标签及其内容
  677. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  678. // 去除所有 HTML 标签
  679. $content = strip_tags($content);
  680. // 去除 HTML 实体
  681. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  682. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  683. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  684. // 去除多余空白
  685. $content = preg_replace('/\s+/u', '', $content);
  686. // 截取 100 个字符
  687. $articleData['introduce'] = mb_substr($content, 0, 100);
  688. }
  689. if ($articleData['status'] == 0) {
  690. $this->sendMessage([
  691. 'talk_type' => 100,
  692. 'title' => $articleData['title'],
  693. 'content' => '提交了审核',
  694. 'messageType' => 2,
  695. ]);
  696. }
  697. $id = Article::where(['id' => $data['id']])->update($articleData);
  698. $articleDataContent = [
  699. 'content' => $data['content'],
  700. ];
  701. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  702. //处理投票
  703. $id = $data['id'];
  704. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  705. var_dump($suvey_array, 'suvey_array________delete');
  706. //处理投票
  707. if ($is_survey == 1) {
  708. //生成年月日时分秒+8位随机数
  709. $uuid = date('YmdHis') . rand(10000000, 99999999);
  710. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  711. var_dump($suveys_array, '---------------------1');
  712. $suvey_data = [];
  713. if (is_array($suveys_array)) {
  714. foreach ($suveys_array as $key => $value) {
  715. if ($value == '') {
  716. continue;
  717. }
  718. if (is_array($value)) {
  719. $suvey_data[] = [
  720. 'sur_id' => $uuid,
  721. 'art_id' => $id,
  722. 'website_id' => $website_id ?? 2,
  723. 'survey_name' => $survey_name,
  724. 'choice_name' => $value[1],
  725. 'is_other' => 1,
  726. 'other_id' => 0,
  727. 'results' => 0,
  728. ];
  729. } else {
  730. $suvey_data[] = [
  731. 'sur_id' => $uuid,
  732. 'art_id' => $id,
  733. 'website_id' => $website_id ?? 2,
  734. 'survey_name' => $survey_name,
  735. 'choice_name' => $value,
  736. 'is_other' => 0,
  737. 'other_id' => 0,
  738. 'results' => 0,
  739. ];
  740. }
  741. if (empty($suvey_data)) {
  742. throw new \Exception("投票数据为空");
  743. }
  744. }
  745. }
  746. $result = ArticleSurvey::insert($suvey_data);
  747. if (!$result) {
  748. throw new \Exception("投票失败");
  749. }
  750. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  751. if (!$result) {
  752. throw new \Exception("投票失败");
  753. }
  754. } else {
  755. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  756. }
  757. Db::commit();
  758. return Result::success([]);
  759. } catch (\Throwable $ex) {
  760. Db::rollBack();
  761. var_dump($ex->getMessage());
  762. return Result::error("更新失败" . $ex->getMessage(), 0);
  763. }
  764. }
  765. /**
  766. * 更新资讯状态
  767. * @param array $data
  768. * @return array
  769. */
  770. public function upArticleStatus(array $data): array
  771. {
  772. $articleData = Article::where(['id' => $data['id']])->first();
  773. if ($data['status'] == 1) {
  774. $this->sendMessage([
  775. 'talk_type' => 101,
  776. 'title' => $articleData['title'],
  777. 'content' => '审核通过',
  778. 'messageType' => 2,
  779. 'user_id' => $articleData['admin_user_id'],
  780. ]);
  781. }
  782. if ($data['status'] == 2) {
  783. $this->sendMessage([
  784. 'talk_type' => 101,
  785. 'title' => $articleData['title'],
  786. 'content' => '审核拒绝',
  787. 'messageType' => 2,
  788. 'user_id' => $articleData['admin_user_id'],
  789. ]);
  790. }
  791. if ($data['status'] == 0) {
  792. $this->sendMessage([
  793. 'talk_type' => 100,
  794. 'title' => $articleData['title'],
  795. 'content' => '提交了审核',
  796. 'messageType' => 2,
  797. ]);
  798. }
  799. $result = Article::where(['id' => $data['id']])->update($data);
  800. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  801. //article_ignore 表插入数据 db操作
  802. //转成数组
  803. //删掉数据重新写入
  804. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  805. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  806. $insert_data = [];
  807. foreach ($website_ids as $key => $value) {
  808. $insert_data[] = [
  809. 'article_id' => $data['id'],
  810. 'website_id' => $value,
  811. ];
  812. }
  813. DB::table('article_ignore')->insert($insert_data);
  814. }
  815. if ($result) {
  816. return Result::success();
  817. } else {
  818. return Result::error("更新状态失败", 0);
  819. }
  820. }
  821. /**
  822. * 获取新闻详情
  823. * @param array $data
  824. * @return array
  825. */
  826. public function getArticleInfo(array $data): array
  827. {
  828. $where = [
  829. 'article.id' => $data['id'],
  830. // 'article.status' => 1,
  831. ];
  832. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  833. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  834. $info = $result;
  835. // var_dump($info, 'info');
  836. $info['survey_array'] = $articleSurvey;
  837. if ($result) {
  838. return Result::success($info);
  839. } else {
  840. return Result::error("查询失败", 0);
  841. }
  842. }
  843. /**
  844. * 获取头条新闻
  845. * @param array $data
  846. * @return array
  847. */
  848. public function getWebsiteArticlett(array $data): array
  849. {
  850. $website_id = $data['website_id'];
  851. $categorys = $this->processArticlePro($website_id);
  852. $catiall = $categorys['catiall'];
  853. $categoryIds = $categorys['categoryIds'];
  854. $where = [
  855. 'status' => 1
  856. ];
  857. $website_id = $data['website_id'];
  858. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  859. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  860. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  861. switch ($data['level']) {
  862. case 1:
  863. case 2:
  864. case 3:
  865. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  866. $query = Article::where($where)
  867. ->where('level', 'like', '%' . $data['level'] . '%')
  868. ->orderBy('updated_at', 'desc');
  869. break;
  870. case 4: //最新资讯
  871. $query = Article::where($where)->orderBy('updated_at', 'desc');
  872. break;
  873. case 5: //资讯推荐
  874. $query = Article::where($where)
  875. ->where('updated_at', '>', $month);
  876. break;
  877. case 7: //资讯分类
  878. if (isset($data['id']) && !empty($data['id'])) {
  879. $keyword = Article::where('id', $data['id'])->value('keyword');
  880. $keywordArray = explode(',', $keyword);
  881. $whereL7 = [];
  882. foreach ($keywordArray as $k => $v) {
  883. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  884. }
  885. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  886. break;
  887. } else {
  888. return Result::error("请输入资讯ID", 0);
  889. break;
  890. }
  891. default:
  892. break;
  893. }
  894. // $whereL7 = [];
  895. // if(isset($data['id']) && !empty($data['id'])){
  896. // $keyword = Article::where('id', $data['id'])->value('keyword');
  897. // $keywordArray = explode(',', $keyword);
  898. // foreach ($keywordArray as $k => $v) {
  899. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  900. // }
  901. // }
  902. // $query = Article::where($where)
  903. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  904. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  905. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  906. // }
  907. // if($data['level'] == 7){
  908. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  909. // }
  910. // if($data['level'] == 4){
  911. // $query = $query->inRandomOrder()
  912. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  913. // }
  914. // if($data['level'] == 5){
  915. // $query = $query->orderBy('updated_at','desc');
  916. // }
  917. // });
  918. if ($data['textnum'] > 0) {
  919. $query = clone $query;
  920. $result['text'] = $query
  921. ->whereIn('catid', $categoryIds)
  922. ->leftJoinSub(function ($query) use ($website_id) {
  923. $query->from('article_ignore')
  924. ->where('website_id', $website_id);
  925. }, 'article_ignore', function ($join) {
  926. $join->on('article_ignore.article_id', '=', 'article.id');
  927. })
  928. ->where(function ($query) use ($website_id) {
  929. $query->whereNull('article_ignore.article_id')
  930. ->orWhere('article_ignore.website_id', '!=', $website_id);
  931. })
  932. ->select(
  933. 'article.id',
  934. 'article.title',
  935. 'article.author',
  936. 'article.updated_at',
  937. 'article.introduce',
  938. 'article.islink',
  939. 'article.linkurl',
  940. 'article.copyfrom',
  941. 'article.cat_arr_id',
  942. 'article.catid',
  943. 'article.level'
  944. )
  945. ->offset($data['placeid'])
  946. ->limit($data['textnum'])
  947. ->get()->all();
  948. foreach ($result['text'] as $k => $v) {
  949. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  950. }
  951. }
  952. if ($data['imgnum'] > 0) {
  953. $query = clone $query;
  954. $result['img'] = $query
  955. ->whereIn('catid', $categoryIds)
  956. ->where('article.imgurl', '!=', '')
  957. ->select(
  958. 'article.id',
  959. 'article.title',
  960. 'article.imgurl',
  961. 'article.author',
  962. 'article.updated_at',
  963. 'article.introduce',
  964. 'article.islink',
  965. 'article.linkurl',
  966. 'article.copyfrom',
  967. 'article.cat_arr_id',
  968. 'article.catid',
  969. 'article.level'
  970. )
  971. ->offset($data['placeid'])
  972. ->limit($data['imgnum'])
  973. ->get()->all();
  974. foreach ($result['img'] as $k => $v) {
  975. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  976. }
  977. }
  978. if (empty($result)) {
  979. return Result::error("暂无相关资讯", 0);
  980. }
  981. return Result::success($result);
  982. }
  983. /**
  984. * 获取模块新闻
  985. * @param array $data
  986. * @return array
  987. */
  988. public function getWebsiteModelArticles(array $data): array
  989. {
  990. $catid = $data['catid'];
  991. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  992. $category = $category->toArray();
  993. if (!empty($category)) {
  994. $where = [
  995. 'status' => 1,
  996. 'catid' => $catid,
  997. ];
  998. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  999. // 1:文字新闻;2:轮播图;3:图文;
  1000. // 级别:0:未分类
  1001. // 3:推荐图片
  1002. if ($data['level'] == 1) {
  1003. $data['level'] = 0;
  1004. }
  1005. $result = Article::where($where)
  1006. ->where(function ($query) use ($data) {
  1007. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1008. ->orWhereNull("level")
  1009. ->orWhereRaw("level = '[]'");
  1010. })
  1011. ->where(function ($query) use ($data) {
  1012. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1013. ->orWhereNull("ignore_ids");
  1014. })
  1015. ->orderBy("updated_at", "desc")
  1016. ->offset($placeid)
  1017. ->limit($data['pagesize'])
  1018. ->get();
  1019. if (empty($result)) {
  1020. return Result::error("此栏目暂无相关新闻", 0);
  1021. }
  1022. } else {
  1023. return Result::error("此网站暂无此栏目", 0);
  1024. }
  1025. return Result::success($result);
  1026. }
  1027. /**
  1028. *获取新闻列表
  1029. * @param array $data
  1030. * @return array
  1031. */
  1032. public function getWebsiteArticleList(array $data): array
  1033. {
  1034. // return Result::success($data);
  1035. $where[] = ['status', '=', 1];
  1036. $website_id = $data['website_id'];
  1037. if (isset($data['catid']) && !empty($data['catid'])) {
  1038. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1039. if (empty($category)) {
  1040. return Result::error("此网站暂无此栏目", 0);
  1041. }
  1042. array_push($where, ['catid', '=', $data['catid']]);
  1043. }
  1044. // return Result::success($where);
  1045. $query = Article::where($where)
  1046. ->leftJoinSub(function ($query) use ($website_id) {
  1047. $query->from('article_ignore')
  1048. ->where('website_id', $website_id);
  1049. }, 'article_ignore', function ($join) {
  1050. $join->on('article_ignore.article_id', '=', 'article.id');
  1051. })
  1052. ->where(function ($query) use ($website_id) {
  1053. $query->whereNull('article_ignore.article_id')
  1054. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1055. })
  1056. ->select(
  1057. 'article.id',
  1058. 'article.title',
  1059. 'article.imgurl',
  1060. 'article.author',
  1061. 'article.updated_at',
  1062. 'article.introduce',
  1063. 'article.islink',
  1064. 'article.linkurl',
  1065. 'article.copyfrom',
  1066. 'article.cat_arr_id',
  1067. 'article.catid'
  1068. );
  1069. $count = $query->count();
  1070. $rep = $query->orderBy("updated_at", "desc")
  1071. ->offset(($data['page'] - 1) * $data['pageSize'])
  1072. ->limit($data['pageSize'])
  1073. ->get()->all();
  1074. $categorys = $this->processArticlePro($website_id);
  1075. $cat_1st_arr = $categorys['cat_1st_arr'];
  1076. $catiall = $categorys['catiall'];
  1077. // $web['website_id'] = $data['website_id'];
  1078. foreach ($rep as $k => $v) {
  1079. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1080. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1081. }
  1082. // $rep = $this->processArticles($rep,$web);
  1083. $data = [
  1084. 'rows' => $rep,
  1085. 'count' => $count,
  1086. ];
  1087. if (empty($rep)) {
  1088. return Result::error("没有信息数据");
  1089. }
  1090. return Result::success($data);
  1091. }
  1092. /**
  1093. * 前端-获取新闻详情
  1094. * @param array $data
  1095. * @return array
  1096. */
  1097. public function selectWebsiteArticleInfo(array $data): array
  1098. {
  1099. $where = [
  1100. 'article.id' => $data['id'],
  1101. 'article.status' => 1,
  1102. ];
  1103. $result = Article::where($where)
  1104. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1105. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1106. ->where(function ($query) use ($data) {
  1107. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1108. ->orWhereNull("ignore_ids");
  1109. })
  1110. ->select(
  1111. 'article.*',
  1112. 'article_data.content',
  1113. 'article_data.article_id',
  1114. 'article_extend.website_url',
  1115. 'article_extend.email',
  1116. 'article_extend.contacts',
  1117. 'article_extend.contacts_mobile',
  1118. 'article_extend.contacts_address',
  1119. 'article_extend.zip_code',
  1120. 'article_extend.enterprise_name'
  1121. )
  1122. ->first();
  1123. if (empty($result)) {
  1124. return Result::error("暂无此新闻!", 0);
  1125. }
  1126. if (!empty($result['publiced_at'])) {
  1127. $result['updated_at'] = $result['publiced_at'];
  1128. }
  1129. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1130. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1131. ->where('website_category.website_id', $data['website_id'])
  1132. ->where(['website_category.category_id' => $result['catid']])
  1133. ->first();
  1134. if (empty($category)) {
  1135. return Result::error("查询失败", 0);
  1136. }
  1137. //手动推荐文章
  1138. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1139. if (empty($commend_ids)) {
  1140. $commendArticle = [];
  1141. } else {
  1142. //去除不存在的文章ID
  1143. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1144. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1145. ->where('article.status', 1)
  1146. ->where('website_category.website_id', $data['website_id'])
  1147. ->select('article.id', 'article.cat_arr_id', 'article.title', 'article.catid', 'article.imgurl', 'article.hits', 'article.created_at', 'website_category.alias', 'website_category.alias_pinyin', 'website_category.website_id')
  1148. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1149. // ->orderBy('article.updated_at', 'desc')
  1150. ->limit(5)
  1151. ->get();
  1152. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1153. foreach ($commendArticle as $k => $v) {
  1154. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1155. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1156. $cat_arr_id = array_unique($cat_arr_id);
  1157. // 从website_category取出alias_pinyin
  1158. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1159. ->whereIn('category_id', $cat_arr_id)
  1160. ->pluck('alias_pinyin', 'category_id')
  1161. ->toArray();
  1162. // 将cat_arr_id的json转成路径/隔开
  1163. $path_parts = [];
  1164. foreach ($cat_arr_id as $cat_id) {
  1165. if (isset($cat_arr[$cat_id])) {
  1166. $path_parts[] = $cat_arr[$cat_id];
  1167. }
  1168. }
  1169. $v->alias_pinyin = implode('/', $path_parts);
  1170. } else {
  1171. $v->alias_pinyin = '';
  1172. }
  1173. }
  1174. }
  1175. $result['category_id'] = $category['category_id'];
  1176. $result['cat_name'] = $category['alias'];
  1177. $result['website_name'] = $category['website_name'] ?? "";
  1178. $result['suffix'] = $category['suffix'] ?? "";
  1179. $result['commendArticle'] = $commendArticle;
  1180. $result['commend_ids'] = $commend_ids;
  1181. return Result::success($result);
  1182. }
  1183. /**
  1184. * 前端-获取网站调查问卷
  1185. * @param array $data
  1186. * @return array
  1187. */
  1188. public function getWebsiteSurvey(array $data): array
  1189. {
  1190. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1191. $website = Website::where('id', $data['website_id'])->first();
  1192. if (empty($website)) {
  1193. return Result::error("暂无此网站", 0);
  1194. }
  1195. }
  1196. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1197. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1198. if (empty($article)) {
  1199. return Result::error("暂无此文章", 0);
  1200. }
  1201. // return Result::error($data,0);
  1202. $where['art_id'] = $data['art_id'];
  1203. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1204. } else {
  1205. $survey = Article::where(function ($query) {
  1206. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1207. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1208. })
  1209. ->where('status', 1)
  1210. ->where('is_survey', 1)
  1211. ->select('survey_id')
  1212. ->orderBy('updated_at', 'desc')
  1213. ->first();
  1214. if (empty($survey)) {
  1215. return Result::error("暂无调查问卷", 0);
  1216. }
  1217. $where['sur_id'] = $survey['survey_id'];
  1218. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1219. }
  1220. // return Result::success($where);
  1221. $result = ArticleSurvey::where($where)
  1222. ->where(function ($query) {
  1223. $query->where('is_other', 0)
  1224. ->orWhere(function ($subQuery) {
  1225. $subQuery->where('is_other', 1)
  1226. ->where('other_id', 0);
  1227. });
  1228. })
  1229. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1230. ->select('article_survey.*', 'article.survey_type')
  1231. ->get()->all();
  1232. if (empty($result)) {
  1233. return Result::error("此文章暂无调查问卷", 0);
  1234. }
  1235. return Result::success($result);
  1236. }
  1237. /**
  1238. * 前端-添加网站调查问卷选项
  1239. * @param array $data
  1240. * @return array
  1241. */
  1242. public function addWebsiteSurveyOption(array $data): array
  1243. {
  1244. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1245. $website = Website::where('id', $data['website_id'])->first();
  1246. if (empty($website)) {
  1247. return Result::error("暂无此网站", 0);
  1248. }
  1249. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1250. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1251. if (empty($survey)) {
  1252. return Result::error("此调查问卷不可添加选项", 0);
  1253. }
  1254. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1255. $choice = [
  1256. 'art_id' => $survey['art_id'],
  1257. 'website_id' => $data['website_id'],
  1258. 'survey_name' => $survey['survey_name'],
  1259. 'choice_name' => $data['choice_name'],
  1260. 'sur_id' => $survey['sur_id'],
  1261. 'is_other' => 1,
  1262. 'other_id' => $survey['id'],
  1263. ];
  1264. $result = ArticleSurvey::insertGetId($choice);
  1265. if (empty($result)) {
  1266. return Result::error("添加失败", 0);
  1267. }
  1268. return Result::success($result);
  1269. }
  1270. }
  1271. return Result::error("添加失败", 0);
  1272. }
  1273. return Result::error("添加失败", 0);
  1274. }
  1275. /**
  1276. * 前端-调查问卷投票
  1277. * @param array $data
  1278. * @return array
  1279. */
  1280. public function addWebsiteSurveyVote(array $data): array
  1281. {
  1282. // return Result::success($data);
  1283. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1284. $website = Website::where('id', $data['website_id'])->first();
  1285. if (empty($website)) {
  1286. return Result::error("暂无此网站", 0);
  1287. }
  1288. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1289. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1290. // return Result::success($survey);
  1291. if (empty($is_survey)) {
  1292. return Result::error("此调查问卷不存在", 0);
  1293. }
  1294. // return Result::success($survey);
  1295. // 调查问卷类型
  1296. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1297. //多选 若是json型则转化成数组类型
  1298. if (strpos($data['choice_id'], '[') === 0) {
  1299. $data['choice_id'] = json_decode($data['choice_id'], true);
  1300. } else {
  1301. // 单选 也转换成数组
  1302. $data['choice_id'] = [$data['choice_id']];
  1303. }
  1304. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1305. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1306. // ->where('website_id',$data['website_id'])
  1307. ->where('is_other', 1)
  1308. ->where('other_id', 0)
  1309. ->first();
  1310. if (!empty($other)) {
  1311. return Result::error("请选择已有的选项!", 0);
  1312. }
  1313. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1314. // ->where('website_id',$data['website_id'])
  1315. ->where('is_other', 1)
  1316. ->where('other_id', '!=', 0)
  1317. ->first();
  1318. // return Result::success($choice['other']);
  1319. $choice_id = $data['choice_id'];
  1320. if (!empty($choice['other'])) {
  1321. // array_push($data['choice_id'],$choice['other']['other_id']);
  1322. if (!empty($choice_id)) {
  1323. $key = array_search($choice['other']['id'], $choice_id);
  1324. if ($key !== false) {
  1325. unset($choice_id[$key]);
  1326. $choice_id = array_values($choice_id);
  1327. }
  1328. array_push($choice_id, $choice['other']['other_id']);
  1329. } else {
  1330. $choice_id[0] = $choice['other']['other_id'];
  1331. }
  1332. array_push($data['choice_id'], $choice['other']['other_id']);
  1333. }
  1334. // return Result::success($data);
  1335. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1336. // ->where('website_id',$data['website_id'])
  1337. ->increment('results', 1);
  1338. if (empty($choice)) {
  1339. return Result::error("请选择已有的选项!", 0);
  1340. }
  1341. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1342. // ->where('website_id',$data['website_id'])
  1343. ->where('other_id', 0)
  1344. ->get();
  1345. $survey['choice'] = $choice_id;
  1346. return Result::success($survey);
  1347. }
  1348. return Result::error("参数必填!");
  1349. }
  1350. return Result::error("此调查问卷不存在", 0);
  1351. }
  1352. return Result::error("参数必填!");
  1353. }
  1354. /**
  1355. * 后端-获取网站调查问卷列表
  1356. * @param array $data
  1357. * @return array
  1358. */
  1359. public function getSurveyList(array $data): array
  1360. {
  1361. $where = [];
  1362. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1363. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1364. }
  1365. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1366. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1367. }
  1368. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1369. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1370. }
  1371. // return Result::success($where);
  1372. if (!empty($where)) {
  1373. $query = Article::where($where)->where(function ($q) {
  1374. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1375. });
  1376. } else {
  1377. $query = Article::where(function ($q) {
  1378. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1379. });
  1380. }
  1381. $count = $query->count();
  1382. $survey = $query->orderByDesc('id')
  1383. ->limit($data['pageSize'])
  1384. ->offset(($data['page'] - 1) * $data['pageSize'])
  1385. ->get();
  1386. if (empty($survey->toArray())) {
  1387. return Result::error("暂无调查问卷!", 0);
  1388. }
  1389. $result = [
  1390. 'rows' => $survey,
  1391. 'count' => $count,
  1392. ];
  1393. return Result::success($result);
  1394. }
  1395. /**
  1396. * 后端-获取网站调查问卷详情
  1397. * @param array $data
  1398. * @return array
  1399. */
  1400. public function getSurveyInfo(array $data): array
  1401. {
  1402. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1403. $where = ['sur_id' => $data['sur_id']];
  1404. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1405. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1406. ->select('article_survey.*', 'article.survey_type')
  1407. ->get()->all();
  1408. if (empty($choose)) {
  1409. return Result::error("此调查问卷不存在", 0);
  1410. }
  1411. $resultsArray = array_column($choose, 'results');
  1412. $total = array_sum($resultsArray);
  1413. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1414. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1415. // $total = 0;
  1416. if (!empty($other)) {
  1417. $total = $total + $other['results'];
  1418. $other['choice_name'] = '(其他)';
  1419. if (!empty($others)) {
  1420. $other['hasChildren'] = true;
  1421. // array_push($other,['hasChildren','=',true]);
  1422. $other['children'] = $others;
  1423. $other_choices = [$other->toArray()];
  1424. $mer_choice = array_merge($choose, $other_choices);
  1425. $value_choice = array_values($mer_choice);
  1426. } else {
  1427. // return Result::error('1111');
  1428. $other_choices = [$other->toArray()];
  1429. $other_choices = array_merge($choose, $other_choices);
  1430. $value_choice = array_values($other_choices);
  1431. // return Result::success($result);
  1432. }
  1433. } else {
  1434. $value_choice = $choose;
  1435. }
  1436. $result = [
  1437. 'choose' => $value_choice,
  1438. 'total' => $total,
  1439. ];
  1440. }
  1441. return Result::success($result);
  1442. }
  1443. /**
  1444. * 前端-搜索新闻列表
  1445. * @param array $data
  1446. * @return array
  1447. */
  1448. public function selectWebsiteArticle(array $data): array
  1449. {
  1450. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1451. $website_id = $data['website_id'];
  1452. $categorys = $this->processArticlePro($website_id);
  1453. $catiall = $categorys['catiall'];
  1454. $query = Article::where('status', 1)
  1455. ->whereIn('catid', $category)
  1456. ->leftJoinSub(function ($query) use ($website_id) {
  1457. $query->from('article_ignore')
  1458. ->where('website_id', $website_id);
  1459. }, 'article_ignore', function ($join) {
  1460. $join->on('article_ignore.article_id', '=', 'article.id');
  1461. })
  1462. ->where(function ($query) use ($website_id) {
  1463. $query->whereNull('article_ignore.article_id')
  1464. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1465. });
  1466. // return Result::success($all_articles);
  1467. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1468. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1469. }
  1470. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1471. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1472. }
  1473. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1474. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1475. }
  1476. // 计算总数
  1477. $count = $query->count();
  1478. // 分页查询
  1479. $articles = $query
  1480. ->select(
  1481. 'article.id',
  1482. 'article.title',
  1483. 'article.imgurl',
  1484. 'article.author',
  1485. 'article.updated_at',
  1486. 'article.introduce',
  1487. 'article.islink',
  1488. 'article.linkurl',
  1489. 'article.copyfrom',
  1490. 'article.cat_arr_id',
  1491. 'article.catid',
  1492. 'article.department_arr_id',
  1493. 'article.city_arr_id',
  1494. )
  1495. ->orderBy("updated_at", "desc")
  1496. ->offset(($data['page'] - 1) * $data['pageSize'])
  1497. ->limit($data['pageSize'])
  1498. ->get();
  1499. foreach ($articles as $k => $v) {
  1500. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1501. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1502. }
  1503. if (empty($articles)) {
  1504. return Result::error("没有符合条件的资讯数据");
  1505. }
  1506. $result = [
  1507. 'rows' => $articles,
  1508. 'count' => $count,
  1509. ];
  1510. return Result::success($result);
  1511. }
  1512. /**
  1513. * 模块新闻加强版
  1514. * @param array $data
  1515. * @return array
  1516. */
  1517. public function getWebsiteCatidArticle(array $data): array
  1518. {
  1519. $where = [
  1520. 'website_category.category_id' => $data['catid'],
  1521. 'website_category.website_id' => $data['website_id'],
  1522. ];
  1523. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1524. $child_catnum = $data['child_catnum'] ?? 1;
  1525. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1526. $childCategoryIds = array_column($category['child'], 'category_id');
  1527. if (empty($childCategoryIds)) {
  1528. return Result::error("暂无子栏目", 0);
  1529. }
  1530. $imgArticles = [];
  1531. $textArticles = [];
  1532. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1533. // 初始化子分类图片新闻和文字新闻数组
  1534. // 查询所有子级栏目的图文新闻
  1535. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1536. ->where(function ($query) use ($data) {
  1537. $query->where(function ($subQuery) use ($data) {
  1538. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1539. })->orWhereNull("ignore_ids");
  1540. })
  1541. ->where('status', 1)
  1542. ->where('imgurl', '!=', '')
  1543. ->select('*')
  1544. ->orderBy('updated_at', 'desc')
  1545. ->limit($data['child_imgnum'])
  1546. ->get();
  1547. }
  1548. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1549. // 查询所有子级栏目的文字新闻
  1550. $textArticles = Article::where('catid', $childCategoryIds[0])
  1551. ->where('status', 1)
  1552. ->where(function ($query) use ($data) {
  1553. $query->where(function ($subQuery) use ($data) {
  1554. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1555. })->orWhereNull("ignore_ids");
  1556. })
  1557. ->select('*')
  1558. ->orderBy('updated_at', 'desc')
  1559. ->limit($data['child_textnum'])
  1560. ->get();
  1561. }
  1562. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1563. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1564. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1565. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1566. return $child;
  1567. }, $category['child']);
  1568. }
  1569. // }
  1570. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1571. $category['img'] = WebsiteCategory::where($where)
  1572. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1573. ->where('article.status', 1)
  1574. ->where('article.imgurl', '!=', '')
  1575. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1576. ->orderBy('article.updated_at', 'desc')
  1577. ->limit($data['img_num'])
  1578. ->get();
  1579. }
  1580. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1581. $category['text'] = WebsiteCategory::where($where)
  1582. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1583. ->where('article.status', 1)
  1584. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1585. ->orderBy('article.updated_at', 'desc')
  1586. ->limit($data['text_num'])
  1587. ->get();
  1588. }
  1589. // $category = $category->get();
  1590. if (empty($category)) {
  1591. return Result::error("查询失败", 0);
  1592. }
  1593. return Result::success($category);
  1594. }
  1595. /**
  1596. * 模块新闻加强plus版
  1597. * @param array $data
  1598. * @return array
  1599. */
  1600. public function getWebsiteAllArticle(array $data): array
  1601. {
  1602. $time1 = microtime(true);
  1603. $wetbsite_id = $data['website_id'] ?? 2;
  1604. $data = json_decode($data['id'], true);
  1605. $categorys = $this->processArticlePro($wetbsite_id);
  1606. $cat_1st_arr = $categorys['cat_1st_arr'];
  1607. $catiall = $categorys['catiall'];
  1608. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1609. $parent_category = array_column($data, 'parent');
  1610. $parent_cat = [];
  1611. $child_category = array_column($data, 'child');
  1612. if (!empty($parent_category)) {
  1613. foreach ($parent_category as $key => $value) {
  1614. $arr = array_map('intval', explode(',', $value));
  1615. $parent_cat[$key] = $arr[0] ?? 0;
  1616. $parent_category = $arr[0] ?? 0;
  1617. $article_imgnum = $arr[1] ?? 0;
  1618. $article_textnum = $arr[2] ?? 0;
  1619. if ($parent_category != 0) {
  1620. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1621. // return Result::success($category_arr);
  1622. if ($article_imgnum != 0) {
  1623. $img_article = Article::whereIn('catid', $category_arr)
  1624. ->where('status', 1)
  1625. ->where('imgurl', '!=', '')
  1626. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1627. $query->from('article_ignore')
  1628. ->where('website_id', $wetbsite_id);
  1629. }, 'article_ignore', function ($join) {
  1630. $join->on('article_ignore.article_id', '=', 'article.id');
  1631. })
  1632. ->where(function ($query) use ($wetbsite_id) {
  1633. $query->whereNull('article_ignore.article_id')
  1634. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1635. })
  1636. ->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')
  1637. ->orderBy('updated_at', 'desc')
  1638. ->limit($article_imgnum)
  1639. ->get()->all();
  1640. foreach ($img_article as $k => $v) {
  1641. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1642. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1643. }
  1644. } else {
  1645. $img_article = [];
  1646. }
  1647. if ($article_textnum != 0) {
  1648. $text_article = Article::whereIn('catid', $category_arr)
  1649. ->where('status', 1)
  1650. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1651. $query->from('article_ignore')
  1652. ->where('website_id', $wetbsite_id);
  1653. }, 'article_ignore', function ($join) {
  1654. $join->on('article_ignore.article_id', '=', 'article.id');
  1655. })
  1656. ->where(function ($query) use ($wetbsite_id) {
  1657. $query->whereNull('article_ignore.article_id')
  1658. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1659. })
  1660. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1661. ->orderBy('updated_at', 'desc')
  1662. ->limit($article_textnum)
  1663. ->get()->all();
  1664. foreach ($text_article as $k => $v) {
  1665. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1666. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1667. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1668. }
  1669. } else {
  1670. $text_article = [];
  1671. }
  1672. $catiall[$parent_category]['imgnum'] = $img_article;
  1673. $catiall[$parent_category]['textnum'] = $text_article;
  1674. $parent[$key] = $catiall[$parent_category];
  1675. } else {
  1676. $parent[$key] = '';
  1677. }
  1678. }
  1679. }
  1680. if (!empty($child_category)) {
  1681. foreach ($child_category as $key => $value) {
  1682. $arr = array_map('intval', explode(',', $value));
  1683. $parent_category = $parent_cat[$key];
  1684. $child_category = $arr[0] ?? 0;
  1685. $article_imgnum = $arr[1] ?? 0;
  1686. $article_textnum = $arr[2] ?? 0;
  1687. if ($child_category != 0) {
  1688. $all_childcat = $cat_1st_arr[$parent_category];
  1689. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1690. // 从 $websiteInfoIndexed 中获取对应的数据
  1691. $info = $websiteInfoIndexed[$v];
  1692. // 返回一个包含所需信息的数组
  1693. return [
  1694. 'alias' => $info->alias,
  1695. 'category_id' => $info->category_id,
  1696. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1697. 'pid' => $info->pid,
  1698. 'type' => $info->type,
  1699. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1700. 'pinyin' => $info->pinyin,
  1701. ];
  1702. }, $all_childcat);
  1703. if ($article_imgnum != 0) {
  1704. $img_article = Article::where('catid', $child_category)
  1705. ->where('status', 1)
  1706. ->where('imgurl', '!=', '')
  1707. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1708. $query->from('article_ignore')
  1709. ->where('website_id', $wetbsite_id);
  1710. }, 'article_ignore', function ($join) {
  1711. $join->on('article_ignore.article_id', '=', 'article.id');
  1712. })
  1713. ->where(function ($query) use ($wetbsite_id) {
  1714. $query->whereNull('article_ignore.article_id')
  1715. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1716. })
  1717. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1718. ->orderBy('updated_at', 'desc')
  1719. ->limit($article_imgnum)
  1720. ->get()->all();
  1721. foreach ($img_article as $k => $v) {
  1722. // var_dump($v);
  1723. // var_dump($k);
  1724. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1725. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1726. }
  1727. } else {
  1728. $img_article = [];
  1729. }
  1730. if ($article_textnum != 0) {
  1731. $text_article = Article::where('catid', $child_category)
  1732. ->where('status', 1)
  1733. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1734. $query->from('article_ignore')
  1735. ->where('website_id', $wetbsite_id);
  1736. }, 'article_ignore', function ($join) {
  1737. $join->on('article_ignore.article_id', '=', 'article.id');
  1738. })
  1739. ->where(function ($query) use ($wetbsite_id) {
  1740. $query->whereNull('article_ignore.article_id')
  1741. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1742. })
  1743. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1744. ->orderBy('updated_at', 'desc')
  1745. ->limit($article_textnum)
  1746. ->get()->all();
  1747. foreach ($text_article as $k => $v) {
  1748. // var_dump($v);
  1749. // var_dump($k);
  1750. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1751. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1752. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1753. }
  1754. } else {
  1755. $text_article = [];
  1756. }
  1757. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1758. $catiall[$child_category]['imgnum'] = $img_article;
  1759. $catiall[$child_category]['textnum'] = $text_article;
  1760. $child[$key] = $catiall[$child_category];
  1761. // var_dump($pids);
  1762. } else {
  1763. $child[$key] = '';
  1764. }
  1765. }
  1766. }
  1767. foreach ($parent as $key => $value) {
  1768. $result[$key] = $value;
  1769. if (!empty($child[$key])) {
  1770. // var_dump($child[$key]);
  1771. $result[$key]['child'] = $child[$key];
  1772. // $value[$key]['child'] = $child[$key];
  1773. } else {
  1774. $result[$key]['child'] = [
  1775. "alias" => null,
  1776. "category_id" => null,
  1777. "type" => null,
  1778. "pinyin" => null,
  1779. "all_childcat" => [],
  1780. "imgnum" => [],
  1781. "textnum" => []
  1782. ];
  1783. }
  1784. }
  1785. return Result::success($result);
  1786. }
  1787. /**
  1788. * 辅助方法:获取文章列表
  1789. */
  1790. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1791. {
  1792. sleep(1);
  1793. $query = Article::where('article.status', 1)
  1794. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1795. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1796. ->where(function ($query) use ($website) {
  1797. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1798. })
  1799. ->leftJoin('website_category', function ($join) use ($website) {
  1800. $join->on('article.catid', '=', 'website_category.category_id')
  1801. ->where('website_category.website_id', '=', $website['website_id']);
  1802. })
  1803. ->select(
  1804. 'article.id',
  1805. 'article.title',
  1806. 'article.imgurl',
  1807. 'article.author',
  1808. 'article.updated_at',
  1809. 'article.introduce',
  1810. 'article.islink',
  1811. 'article.linkurl',
  1812. 'article.copyfrom',
  1813. 'article.cat_arr_id',
  1814. 'article.catid',
  1815. 'website_category.alias as category_name'
  1816. )
  1817. ->orderBy('updated_at', 'desc')
  1818. ->limit($limit);
  1819. // 如果是图片文章,添加图片URL条件
  1820. if ($isImageArticle) {
  1821. $query->where('imgurl', '!=', '');
  1822. } else {
  1823. // 文字文章不需要imgurl字段
  1824. $query->addSelect('article.introduce');
  1825. }
  1826. $articles = $query->get();
  1827. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1828. }
  1829. /**
  1830. * 乡村网-获取特殊新闻模块
  1831. * @param array $data
  1832. * @return array
  1833. */
  1834. public function getWebsiteArticles(array $data): array
  1835. {
  1836. $website_id = $data['website_id'];
  1837. $catids = json_decode($data['id'], true);
  1838. $parent_category = array_column($catids, 'parent');
  1839. if (!empty($parent_category) && is_array($parent_category)) {
  1840. $categorys = $this->processArticlePro($website_id);
  1841. $catiall = $categorys['catiall'];
  1842. $cat_1st_arr = $categorys['cat_1st_arr'];
  1843. // return Result::success($categorys);
  1844. foreach ($parent_category as $key => $value) {
  1845. $arr = array_map('intval', explode(',', $value));
  1846. $parent_category = $arr[0] ?? 0;
  1847. $article_imgnum = $arr[1] ?? 0;
  1848. $article_textnum = $arr[2] ?? 0;
  1849. if ($parent_category != 0) {
  1850. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1851. // return Result::success($category_arr);
  1852. if ($article_imgnum != 0) {
  1853. $img_article = Article::whereIn('catid', $category_arr)
  1854. ->where('status', 1)
  1855. ->where('imgurl', '!=', '')
  1856. ->leftJoinSub(function ($query) use ($website_id) {
  1857. $query->from('article_ignore')
  1858. ->where('website_id', $website_id);
  1859. }, 'article_ignore', function ($join) {
  1860. $join->on('article_ignore.article_id', '=', 'article.id');
  1861. })
  1862. ->where(function ($query) use ($website_id) {
  1863. $query->whereNull('article_ignore.article_id')
  1864. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1865. })
  1866. ->select(
  1867. 'id',
  1868. 'title',
  1869. 'imgurl',
  1870. 'author',
  1871. 'updated_at',
  1872. 'introduce',
  1873. 'islink',
  1874. 'linkurl',
  1875. 'copyfrom',
  1876. 'cat_arr_id',
  1877. 'catid as category_id'
  1878. )
  1879. ->orderBy('updated_at', 'desc')
  1880. ->limit($article_imgnum)
  1881. ->get()->all();
  1882. foreach ($img_article as $k => $v) {
  1883. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1884. // return Result::success($v);
  1885. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1886. }
  1887. } else {
  1888. $img_article = [];
  1889. }
  1890. if ($article_textnum != 0) {
  1891. $text_article = Article::whereIn('catid', $category_arr)
  1892. ->where('status', 1)
  1893. ->leftJoinSub(function ($query) use ($website_id) {
  1894. $query->from('article_ignore')
  1895. ->where('website_id', $website_id);
  1896. }, 'article_ignore', function ($join) {
  1897. $join->on('article_ignore.article_id', '=', 'article.id');
  1898. })
  1899. ->where(function ($query) use ($website_id) {
  1900. $query->whereNull('article_ignore.article_id')
  1901. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1902. })
  1903. ->select(
  1904. 'id',
  1905. 'title',
  1906. 'author',
  1907. 'updated_at',
  1908. 'introduce',
  1909. 'islink',
  1910. 'linkurl',
  1911. 'copyfrom',
  1912. 'cat_arr_id',
  1913. 'catid as category_id'
  1914. )
  1915. ->orderBy('updated_at', 'desc')
  1916. ->limit($article_textnum)
  1917. ->get()->all();
  1918. foreach ($text_article as $k => $v) {
  1919. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1920. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1921. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1922. }
  1923. } else {
  1924. $text_article = [];
  1925. }
  1926. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  1927. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  1928. $parent[$key] = $catiall[$parent_category];
  1929. } else {
  1930. $parent[$key] = [];
  1931. }
  1932. }
  1933. }
  1934. return Result::success($parent);
  1935. }
  1936. // 封装处理商品的路由问题
  1937. function processGoods($goods, $data)
  1938. {
  1939. return $goods->map(function ($good) use ($data) {
  1940. $catid = $good->catid ?? 0;
  1941. // $pinyin = '';
  1942. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1943. if (!empty($category->pid) && $category->pid != 0) {
  1944. $level = json_decode($category->category_arr_id, true);
  1945. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1946. ->whereIn('category_id', $level)
  1947. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1948. ->get(['aLIas_pinyin'])
  1949. ->pluck('aLIas_pinyin')
  1950. ->implode('/');
  1951. } else {
  1952. $pinyin = $category->aLIas_pinyin ?? '';
  1953. }
  1954. if (isset($good->city_id) && !empty($good->city_id)) {
  1955. $city = District::where('id', $good->city_id)->first(['name']);
  1956. $good->city_name = $city->name ?? '';
  1957. }
  1958. // 解析imgurl JSON并取第一条数据
  1959. $imgUrls = json_decode($good->imgurl, true);
  1960. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1961. $good->pinyin = $pinyin;
  1962. return $good;
  1963. });
  1964. }
  1965. /**
  1966. * 获取商城首页-根据栏目id
  1967. * @param array $data
  1968. * @return array
  1969. * */
  1970. function getWebsiteCatidshop(array $data): array
  1971. {
  1972. $input['catid'] = $data['catid'];
  1973. $input['website_id'] = $data['website_id'];
  1974. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1975. $result = array_map(function ($item) use ($input) {
  1976. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1977. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1978. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1979. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1980. if (empty($category) || $category->type != 2) {
  1981. return Result::error("暂无此栏目", 0);
  1982. } else {
  1983. $website['website_id'] = $input['website_id'];
  1984. $goods = Good::where('good.status', 2)
  1985. ->where('good.website_id', $website['website_id'])
  1986. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1987. ->select(
  1988. 'good.id',
  1989. 'good.name',
  1990. 'good.imgurl',
  1991. 'good.description',
  1992. 'good.updated_at',
  1993. 'good.catid',
  1994. 'good.type_id',
  1995. 'good.price',
  1996. 'good.com',
  1997. 'good.level',
  1998. 'good.unit'
  1999. )
  2000. ->orderBy('updated_at', 'desc')
  2001. ->offset($goodStart)
  2002. ->limit($goodNum);
  2003. $all_goods = $goods->get();
  2004. $all_goods = $this->processGoods($all_goods, $website);
  2005. }
  2006. return $all_goods ?? [];
  2007. }
  2008. }, $data);
  2009. return Result::success($result);
  2010. }
  2011. /**
  2012. * 获取商品模块
  2013. * @param array $data
  2014. * @return array
  2015. * */
  2016. public function getWebsiteshop(array $data): array
  2017. {
  2018. $input['id'] = $data['id'];
  2019. $input['website_id'] = $data['website_id'];
  2020. $catid = $data['catid'];
  2021. $data = json_decode($input['id'] ?? '', true) ?? [];
  2022. $result['goods'] = array_map(function ($item) use ($input) {
  2023. // 检查parent元素是否存在且不是undefined
  2024. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2025. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2026. $website = $input['website_id'];
  2027. $query = Good::where('good.status', 2)
  2028. ->where('good.website_id', $website);
  2029. switch ($Levelid) {
  2030. case 1:
  2031. case 2:
  2032. case 3:
  2033. $goods = $query->where(function ($q) use ($Levelid) {
  2034. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2035. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2036. });
  2037. break;
  2038. case 4:
  2039. $goods = $query;
  2040. break;
  2041. case 5:
  2042. $goods = $query->where('type_id', 1);
  2043. break;
  2044. case 6:
  2045. $goods = $query->where('type_id', 2);
  2046. break;
  2047. default:
  2048. return [];
  2049. }
  2050. $all_goods = $goods
  2051. ->select(
  2052. 'good.id',
  2053. 'good.name',
  2054. 'good.imgurl',
  2055. 'good.description',
  2056. 'good.updated_at',
  2057. 'good.catid',
  2058. 'good.type_id',
  2059. 'good.price',
  2060. 'good.level',
  2061. 'good.website_id'
  2062. )
  2063. ->orderBy('updated_at', 'desc')
  2064. ->offset($goodStart)
  2065. ->limit($goodNum)
  2066. ->get();
  2067. $web['website_id'] = $website;
  2068. $all_goods = $this->processGoods($all_goods, $web);
  2069. }
  2070. return $all_goods;
  2071. }, $data);
  2072. $website = $input['website_id'];
  2073. $result['article'] = Article::where(function ($query) use ($website) {
  2074. $query->where(function ($subQuery) use ($website) {
  2075. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2076. })->orWhereNull("ignore_ids");
  2077. })
  2078. ->where('catid', $catid)
  2079. ->where('article.status', 1)
  2080. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2081. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2082. ->orderBy('article.updated_at', 'desc')
  2083. ->first();
  2084. return Result::success($result);
  2085. }
  2086. /**
  2087. * 获取商品分类
  2088. * @param array $data
  2089. * @return array
  2090. * */
  2091. public function getWebsiteshopCat(array $data): array
  2092. {
  2093. $website = $data['website_id'];
  2094. $category = WebsiteCategory::where('website_id', $website)
  2095. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2096. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2097. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2098. ->orderBy('sort')
  2099. ->get();
  2100. $cat = $category->map(function ($item) use ($website) {
  2101. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2102. $pid = $item->pid ?? 0;
  2103. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2104. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2105. ->where('website_id', $website)
  2106. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2107. ->get(['aLIas_pinyin'])
  2108. ->pluck('aLIas_pinyin')
  2109. ->implode('/');
  2110. } else {
  2111. $pinyin = $item->aLIas_pinyin ?? '';
  2112. }
  2113. $item->pinyin = $pinyin;
  2114. });
  2115. if (empty($category)) {
  2116. return Result::error("栏目查询失败", 0);
  2117. }
  2118. $cat_tree = Result::buildMenuTree($category);
  2119. $web['website_id'] = $website;
  2120. $goods = Good::where('website_id', $website)
  2121. ->where('status', 2)
  2122. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2123. ->latest('updated_at')
  2124. ->offset(($data['page'] - 1) * $data['pageSize'])
  2125. ->limit($data['pageSize'])
  2126. ->get();
  2127. if (!empty($goods)) {
  2128. if ($goods->count() > 1 && !empty($goods)) {
  2129. $goods = $this->processGoods($goods, $web);
  2130. }
  2131. } else {
  2132. $goods = [];
  2133. }
  2134. $result = [
  2135. 'category' => $cat_tree,
  2136. 'goods' => $goods,
  2137. ];
  2138. // $resul['goods'] = $goods;
  2139. if (empty($result)) {
  2140. return Result::error("查询失败", 0);
  2141. }
  2142. return Result::success($result);
  2143. }
  2144. /*
  2145. * 获取商品列表
  2146. * @param array $data
  2147. * @return array
  2148. * */
  2149. public function getWebsiteshopList(array $data): array
  2150. {
  2151. // return Result::success($data);
  2152. $where = [
  2153. 'status' => 2,
  2154. 'website_id' => $data['website_id'],
  2155. ];
  2156. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2157. // return Result::error("查询失败", 0);
  2158. // }
  2159. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2160. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2161. $data['catid'] = $category->category_id ?? 0;
  2162. }
  2163. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2164. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2165. }
  2166. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2167. array_push($where, ['type_id', $data['type_id']]);
  2168. }
  2169. $query = Good::where($where)
  2170. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2171. $query->where(function ($q) use ($data) {
  2172. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2173. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2174. });
  2175. })
  2176. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2177. $query->where(function ($q) use ($data) {
  2178. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2179. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2180. });
  2181. })
  2182. ->select(
  2183. 'good.id',
  2184. 'good.name',
  2185. 'good.imgurl',
  2186. 'good.description',
  2187. 'good.updated_at',
  2188. 'good.com',
  2189. 'good.catid',
  2190. 'good.type_id',
  2191. 'good.website_id',
  2192. 'good.cat_arr_id',
  2193. 'good.created_at',
  2194. 'good.city_id'
  2195. )
  2196. ->latest('updated_at');
  2197. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2198. $result['count'] = $query->clone()->count();
  2199. $result['goods'] = $this->processGoods(
  2200. $query->clone()
  2201. ->offset(($data['page'] - 1) * $data['pageSize'])
  2202. ->limit($data['pageSize'])
  2203. ->get(),
  2204. $data
  2205. );
  2206. } else {
  2207. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2208. // 获取 type_id 为 1 的数据
  2209. $result['type1'] = $this->processGoods(
  2210. $query->clone()
  2211. ->where('type_id', 1)
  2212. ->offset(($data['page'] - 1) * $data['pageSize'])
  2213. ->limit($data['pageSize'])
  2214. ->get(),
  2215. $data
  2216. );
  2217. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2218. // 获取 type_id 为 2 的数据
  2219. $result['type2'] = $this->processGoods(
  2220. $query->clone()
  2221. ->where('type_id', 2)
  2222. ->offset(($data['page'] - 1) * $data['pageSize'])
  2223. ->limit($data['pageSize'])
  2224. ->get(),
  2225. $data
  2226. );
  2227. }
  2228. if (empty($result)) {
  2229. return Result::error("查询失败", 0);
  2230. }
  2231. return Result::success($result);
  2232. }
  2233. /**
  2234. * 获取商品详情
  2235. * @param array $data
  2236. * @return array
  2237. * */
  2238. public function getWebsiteshopInfo(array $data): array
  2239. {
  2240. $where = [
  2241. 'good.status' => 2,
  2242. 'good.website_id' => $data['website_id'],
  2243. 'good.id' => $data['id'],
  2244. ];
  2245. $goods = Good::where($where)
  2246. ->where('good.id', $data['id'])
  2247. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2248. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2249. ->first();
  2250. if (empty($goods)) {
  2251. return Result::error("查询失败", 0);
  2252. }
  2253. $goods->imgurl = json_decode($goods->imgurl, true);
  2254. return Result::success($goods);
  2255. }
  2256. /**
  2257. * plus pro 处理文章路由问题
  2258. */
  2259. function processArticlePro($website_id)
  2260. {
  2261. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2262. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2263. // 取出category_id 对应的aLIas_pinyin
  2264. $categoryIds = array_column($categorys, 'category_id');
  2265. $categoryPIds = array_column($categorys, 'pid');
  2266. $aliasPinyins = array_column($categorys, 'aLIas_pinyin');
  2267. $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2268. // return Result::success($categorys);
  2269. $catiall = [];
  2270. //一级所有子级的记录
  2271. $cat_1st_arr = [];
  2272. foreach ($categorys as $key => $value) {
  2273. $category_arr_id = json_decode($value->category_arr_id);
  2274. $pinyin_str = '';
  2275. // 算出一级 并且算出子级
  2276. if ($value->pid != 0) {
  2277. $cat_1st_arr[$value->pid][] = $value->category_id;
  2278. }
  2279. foreach ($category_arr_id as $k => $v) {
  2280. $pinyin_str .= $cat_arr[$v] . '/';
  2281. }
  2282. $pinyin_str = rtrim($pinyin_str, '/');
  2283. $catiall[$value->category_id]['alias'] = $value->alias;
  2284. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2285. $catiall[$value->category_id]['type'] = $value->type;
  2286. $catiall[$value->category_id]['pinyin'] = $pinyin_str;
  2287. $websiteInfoIndexed[$value->category_id]->pinyin = $pinyin_str;
  2288. }
  2289. return [
  2290. 'cat_1st_arr' => $cat_1st_arr,
  2291. 'catiall' => $catiall,
  2292. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2293. 'categoryIds' => $categoryIds,
  2294. ];
  2295. }
  2296. /**
  2297. * 封装处理文章的路由问题
  2298. * */
  2299. function processArticles($articles, $data)
  2300. {
  2301. // 检查 $articles 是否为数组或可迭代对象
  2302. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2303. return $articles->map(function ($article) use ($data) {
  2304. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2305. $catid = $article->cat_arr_id ?? '';
  2306. }
  2307. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2308. $catid = $article->category_arr_id ?? '';
  2309. }
  2310. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2311. $level = json_decode($catid, true);
  2312. if (!is_array($level)) {
  2313. return $article;
  2314. } else {
  2315. $level = array_map('intval', $level);
  2316. }
  2317. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2318. ->where($data)
  2319. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2320. ->pluck('aLIas_pinyin')
  2321. ->implode('/');
  2322. $article->pinyin = $pinyin ?? '';
  2323. return $article;
  2324. });
  2325. } else {
  2326. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2327. $catid = $articles->cat_arr_id ?? '';
  2328. $level = json_decode($catid, true);
  2329. if (!is_array($level)) {
  2330. return $articles;
  2331. } else {
  2332. $level = array_map('intval', $level);
  2333. }
  2334. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2335. ->where($data)
  2336. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2337. ->pluck('aLIas_pinyin')
  2338. ->implode('/');
  2339. $articles->pinyin = $pinyin ?? '';
  2340. return $articles;
  2341. }
  2342. }
  2343. // 封装处理由问题
  2344. function processJob($job, $data)
  2345. {
  2346. return $job->map(function ($job) use ($data) {
  2347. $category = $job->cat_arr_id ?? '';
  2348. $cityid = $job->city_arr_id ?? '';
  2349. $city = json_decode($cityid, true);
  2350. $pinyin = '';
  2351. $level = json_decode($category, true);
  2352. // 路由
  2353. if (!empty($level) && is_array($level)) {
  2354. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2355. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2356. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2357. ->get(['aLIas_pinyin'])
  2358. ->pluck('aLIas_pinyin')
  2359. ->implode('/');
  2360. if (empty($pinyin)) {
  2361. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2362. }
  2363. $job->pinyin = $pinyin;
  2364. }
  2365. // 取职位-城市 市??省
  2366. if (!empty($city) && is_array($city)) {
  2367. if (isset($city[1]) && !empty($city[1])) {
  2368. $city = District::where('id', $city[1])->first(['name']);
  2369. $job->city_name = $city->name ?? '';
  2370. } else if (isset($city[0]) && !empty($city[0])) {
  2371. $city = District::where('id', $city[0])->first(['name']);
  2372. $job->city_name = $city->name ?? '';
  2373. } else {
  2374. $job->city_name = '全国';
  2375. }
  2376. }
  2377. // 获取简历最后一级地区
  2378. if (isset($job->city_id) && !empty($job->city_id)) {
  2379. $city = District::where('id', $job->city_id)->first(['name']);
  2380. $job->hunt_cityname = $city->name ?? '';
  2381. }
  2382. // 组合详细地址
  2383. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2384. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2385. if (is_array($address_id) && !empty($address_id)) {
  2386. $address = District::whereIn('id', $address_id)
  2387. ->orderBy('level', 'asc')
  2388. ->get(['name'])
  2389. ->pluck('name')
  2390. ->implode('');
  2391. // $job->address_name = $address ?? '';
  2392. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2393. }
  2394. }
  2395. // 取行业
  2396. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2397. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2398. if (!empty($job->industry)) {
  2399. $query->where('hyid', $job->industry);
  2400. } else if (!empty($job->hy_id)) {
  2401. $query->where('hyid', $job->hy_id);
  2402. } else if (!empty($job->company_hy_id)) {
  2403. $query->where('hyid', $job->company_hy_id);
  2404. } else {
  2405. $query->where('hyid', $job->job_industry);
  2406. }
  2407. })->first(['hyname']);
  2408. $job->hy_name = $hy_name->hyname ?? '';
  2409. }
  2410. // 取职位类别
  2411. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2412. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2413. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2414. $job->zw_name = $zw_name->zwname ?? '';
  2415. }
  2416. // 取具体职位
  2417. 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))) {
  2418. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2419. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2420. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2421. }
  2422. // 取工作经验
  2423. if (isset($job->experience) && !empty($job->experience)) {
  2424. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2425. $job->experience_name = $experience->ename ?? '';
  2426. }
  2427. // 取学历
  2428. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2429. $education = $job->educational ?? $job->school_education;
  2430. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2431. $job->education_name = $education->ename ?? '';
  2432. }
  2433. // 语言
  2434. if (isset($job->language) && !empty($job->language)) {
  2435. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2436. $job->language_name = $language->ename ?? '';
  2437. }
  2438. // 薪资
  2439. if (isset($job->salary) && !empty($job->salary)) {
  2440. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2441. $job->salary_name = $salary->ename ?? '';
  2442. }
  2443. // 职位性质
  2444. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2445. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2446. $job->job_nature_name = $job_nature->ename ?? '';
  2447. }
  2448. // 公司规模
  2449. if (isset($job->company_size) && !empty($job->company_size)) {
  2450. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2451. $job->company_size_name = $company_size->ename ?? '';
  2452. }
  2453. // 公司性质
  2454. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2455. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2456. $job->company_nature_name = $company_nature->nature_name ?? '';
  2457. }
  2458. // $job->pinyin = $pinyin;
  2459. return $job;
  2460. });
  2461. }
  2462. /**
  2463. * 获取书籍模块
  2464. * @param array $data
  2465. * @return array
  2466. * */
  2467. public function getWebsiteBook(array $data): array
  2468. {
  2469. $input['id'] = $data['id'];
  2470. $input['website_id'] = $data['website_id'];
  2471. // 将 JSON 字符串转换为 PHP 数组
  2472. $data = json_decode($input['id'], true);
  2473. // 使用 array_map 处理每个元素
  2474. $result = array_map(function ($item) use ($input) {
  2475. // 检查parent元素是否存在且不是undefined
  2476. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2477. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2478. $website = [
  2479. 'website_id' => $input['website_id'],
  2480. ];
  2481. // 查询栏目名称
  2482. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2483. if (empty($category)) {
  2484. $parent_alias = '';
  2485. $parent_pinyin = null;
  2486. $imgBooks = [];
  2487. $textBooks = [];
  2488. } else {
  2489. $parent_alias = $category->alias ?? '';
  2490. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2491. // 查找子分类ID数组
  2492. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2493. array_push($childCategoryIds, $parentCatId);
  2494. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2495. if ($parentImgNum != 0) {
  2496. // 查询图片新闻
  2497. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2498. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2499. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2500. })
  2501. ->where('book.status', 2)
  2502. ->where('book.img_url', '!=', '')
  2503. ->leftJoin('website_category', function ($join) use ($website) {
  2504. $join->on('book.cat_id', '=', 'website_category.category_id')
  2505. ->where('website_category.website_id', '=', $website['website_id']);
  2506. })
  2507. ->select(
  2508. 'book.id',
  2509. 'book.title',
  2510. 'book.img_url',
  2511. 'book.price',
  2512. 'book.market_price',
  2513. 'book.description',
  2514. 'book.cat_id',
  2515. 'book.description',
  2516. 'book.updated_at',
  2517. 'website_category.alias as category_name',
  2518. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2519. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2520. )
  2521. ->orderBy('updated_at', 'desc')
  2522. ->limit($parentImgNum)
  2523. ->get()->all();
  2524. // 查询文字新闻
  2525. }
  2526. if ($parentTextNum != 0) {
  2527. $textBooks = [];
  2528. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2529. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2530. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2531. })
  2532. ->where('book.status', 2)
  2533. ->leftJoin('website_category', function ($join) use ($website) {
  2534. $join->on('book.cat_id', '=', 'website_category.category_id')
  2535. ->where('website_category.website_id', '=', $website['website_id']);
  2536. })
  2537. ->select(
  2538. 'book.id',
  2539. 'book.title',
  2540. 'book.img_url',
  2541. 'book.price',
  2542. 'book.market_price',
  2543. 'book.description',
  2544. 'book.cat_id',
  2545. 'book.description',
  2546. 'book.updated_at',
  2547. 'website_category.alias as category_name',
  2548. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2549. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2550. )
  2551. ->orderBy('updated_at', 'desc')
  2552. ->limit($parentTextNum)
  2553. ->get()->all();
  2554. }
  2555. }
  2556. }
  2557. $resultItem = [
  2558. 'alias' => $parent_alias ?? '',
  2559. 'category_id' => $parentCatId ?? 0,
  2560. 'pinyin' => $parent_pinyin ?? null,
  2561. 'imgnum' => $imgBooks ?? [],
  2562. 'textnum' => $textBooks ?? [],
  2563. ];
  2564. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2565. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2566. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2567. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2568. ->get()->all();
  2569. if (!empty($childCategory)) {
  2570. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2571. // 查询子栏目名称
  2572. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2573. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2574. ->first();
  2575. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2576. $childImgArticles = [];
  2577. $childTextArticles = [];
  2578. $resultItem['child'] = [];
  2579. } else {
  2580. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2581. // 查询子栏目图片新闻
  2582. $childImgArticles = Book::where('cat_id', $childCatId)
  2583. ->where('status', 2)
  2584. ->where('img_url', '!=', '')
  2585. ->leftJoin('website_category', function ($join) use ($website) {
  2586. $join->on('book.cat_id', '=', 'website_category.category_id')
  2587. ->where('website_category.website_id', '=', $website['website_id']);
  2588. })
  2589. ->select(
  2590. 'book.id',
  2591. 'book.title',
  2592. 'book.img_url',
  2593. 'book.price',
  2594. 'book.market_price',
  2595. 'book.description',
  2596. 'book.cat_id',
  2597. 'book.description',
  2598. 'book.updated_at',
  2599. DB::raw("'$child_pinyin' as pinyin")
  2600. )
  2601. ->orderBy('updated_at', 'desc')
  2602. ->limit($childImgNum)
  2603. ->get()->all();
  2604. // 查询子栏目文字新闻
  2605. $childTextArticles = Book::where('cat_id', $childCatId)
  2606. ->where('status', 2)
  2607. ->leftJoin('website_category', function ($join) use ($website) {
  2608. $join->on('book.cat_id', '=', 'website_category.category_id')
  2609. ->where('website_category.website_id', '=', $website['website_id']);
  2610. })
  2611. ->select(
  2612. 'book.id',
  2613. 'book.title',
  2614. 'book.img_url',
  2615. 'book.price',
  2616. 'book.market_price',
  2617. 'book.description',
  2618. 'book.cat_id',
  2619. 'book.description',
  2620. 'book.updated_at',
  2621. DB::raw("'$child_pinyin' as pinyin")
  2622. )
  2623. ->orderBy('updated_at', 'desc')
  2624. ->limit($childTextNum)
  2625. ->get()->all();
  2626. $resultItem['child'] = [
  2627. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2628. 'category_id' => $childCatId,
  2629. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2630. 'all_childcat' => $childCategory,
  2631. 'imgnum' => $childImgArticles,
  2632. 'textnum' => $childTextArticles,
  2633. ];
  2634. }
  2635. }
  2636. } else {
  2637. $resultItem['child'] = [];
  2638. }
  2639. return $resultItem;
  2640. }, $data);
  2641. return Result::success($result);
  2642. }
  2643. /**
  2644. * 获取书刊列表
  2645. * @param array $data
  2646. * @return array
  2647. * */
  2648. public function getWebsiteBookList(array $data): array
  2649. {
  2650. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2651. if (empty($web)) {
  2652. return Result::error("查询失败", 0);
  2653. }
  2654. $catid = $data['id'];
  2655. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2656. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2657. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2658. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2659. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2660. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2661. ->where('pid', $category['pid'])
  2662. ->select(
  2663. 'category_id',
  2664. 'alias',
  2665. 'aLIas_pinyin',
  2666. 'pid',
  2667. 'sort',
  2668. 'is_url',
  2669. 'web_url',
  2670. 'seo_title',
  2671. 'seo_keywords',
  2672. 'seo_description',
  2673. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2674. )
  2675. ->orderBy('sort')
  2676. ->get()->all();
  2677. if (empty($category)) {
  2678. return Result::error("查询失败", 0);
  2679. }
  2680. $query = Book::where('book.status', 2)
  2681. ->where('book.website_id', $data['website_id'])
  2682. ->where('book.cat_id', $catid)
  2683. ->select(
  2684. 'book.id',
  2685. 'book.title',
  2686. 'book.img_url',
  2687. 'book.description',
  2688. 'book.updated_at',
  2689. 'book.cat_id',
  2690. DB::raw("'$pinyin' as pinyin")
  2691. )
  2692. ->orderBy('book.updated_at', 'desc');
  2693. $count = $query->count();
  2694. $query = clone $query;
  2695. $Book = $query
  2696. ->limit($data['pageSize'])
  2697. ->offset(($data['page'] - 1) * $data['pageSize'])
  2698. ->get()->all();
  2699. $result = [
  2700. 'category' => $categorys,
  2701. 'books' => $Book,
  2702. 'count' => $count,
  2703. ];
  2704. // if(empty($result)){
  2705. // return Result::error("查询失败", 0);
  2706. // }
  2707. return Result::success($result);
  2708. }
  2709. /**
  2710. * 获取书刊详情
  2711. * @param array $data
  2712. * @return array
  2713. * */
  2714. public function getWebsiteBookInfo(array $data): array
  2715. {
  2716. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2717. if (empty($web)) {
  2718. return Result::error("查询失败", 0);
  2719. }
  2720. $book = Book::where('status', 2)
  2721. ->where('website_id', $data['website_id'])
  2722. ->where('id', $data['id'])
  2723. ->select(
  2724. 'book.*',
  2725. )
  2726. ->orderBy('updated_at', 'desc')
  2727. ->first();
  2728. if (empty($book)) {
  2729. return Result::error("查询失败", 0);
  2730. }
  2731. // 先查询当前分类的 pid
  2732. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2733. ->where('category_id', $book['cat_id'])
  2734. ->first(['pid', 'category_id']);
  2735. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2736. if (!empty($carpid)) {
  2737. if ($carpid->pid != 0) {
  2738. $pid = $carpid['pid'];
  2739. // $parent_pinyin = '';
  2740. } else {
  2741. $pid = $carpid['category_id'];
  2742. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2743. }
  2744. }
  2745. $categorys = $query->where('pid', $pid)
  2746. ->select(
  2747. 'category_id',
  2748. 'alias',
  2749. 'aLIas_pinyin',
  2750. 'pid',
  2751. 'sort',
  2752. 'is_url',
  2753. 'web_url',
  2754. 'category_arr_id as cat_arr_id',
  2755. )
  2756. ->orderBy('sort')
  2757. ->get();
  2758. $category = $this->processArticle($categorys, $data);
  2759. $result = [
  2760. 'category' => $category,
  2761. 'books' => $book,
  2762. ];
  2763. return Result::success($result);
  2764. }
  2765. /**
  2766. * 尝试
  2767. * @param array $data
  2768. * @return array
  2769. * */
  2770. public function test(array $data): array
  2771. {
  2772. $input['id'] = $data['id'];
  2773. $input['website_id'] = $data['website_id'];
  2774. // 将 JSON 字符串转换为 PHP 数组
  2775. $data = json_decode($input['id'], true);
  2776. $result = [];
  2777. $article = $data;
  2778. $result = array_map(function ($item) use ($input) {
  2779. $website = [
  2780. 'website_id' => $input['website_id'],
  2781. ];
  2782. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2783. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2784. $parent = [
  2785. 0 => $category['category_id'] ?? [],
  2786. 1 => $parentImgNum ?? [],
  2787. 2 => $parentTextNum ?? [],
  2788. ];
  2789. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2790. $child = [];
  2791. $resultItem = [
  2792. // 'alias' => $parent_alias ?? '',
  2793. 'category_id' => $parentCatId ?? 0,
  2794. 'pinyin' => $parentImgNum ?? null,
  2795. 'imgnum' => $parentTextNum ?? [],
  2796. // 'textnum' => $textArticles ?? [],
  2797. ];
  2798. return $parent;
  2799. }, $data);
  2800. return Result::success($result);
  2801. // });
  2802. }
  2803. /**
  2804. * 封装处理文章的路由问题
  2805. * */
  2806. function processArticle($article, $data)
  2807. {
  2808. return $article->map(function ($article) use ($data) {
  2809. $catid = $article->cat_arr_id ?? '';
  2810. $level = json_decode($catid, true);
  2811. $pinyin = '';
  2812. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2813. if (!empty($level) && is_array($level)) {
  2814. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2815. ->where('website_id', $data['website_id'])
  2816. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2817. ->get(['aLIas_pinyin'])
  2818. ->pluck('aLIas_pinyin')
  2819. ->implode('/');
  2820. } else {
  2821. $pinyin = '';
  2822. }
  2823. $article->pinyin = $pinyin;
  2824. return $article;
  2825. });
  2826. }
  2827. /**
  2828. * c端-获取招工招聘下拉选框
  2829. * @param array $data
  2830. * @return array
  2831. * */
  2832. public function getWebsiteJobSelect(array $data): array
  2833. {
  2834. $web = Website::where('id', $data['website_id'])->first();
  2835. if (empty($web)) {
  2836. return Result::error("该网站不存在", 0);
  2837. }
  2838. $hy = JobIndustry::get()->all();
  2839. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2840. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2841. $result = [
  2842. 'hy' => $hy,
  2843. 'zw' => $zw,
  2844. 'jtzw' => $jtzw,
  2845. ];
  2846. if (empty($result)) {
  2847. return Result::error("查询失败", 0);
  2848. }
  2849. return Result::success($result);
  2850. }
  2851. /**
  2852. * c端-获取招工招聘
  2853. * @param array $data
  2854. * @return array
  2855. * */
  2856. public function getWebsiteJob(array $data): array
  2857. {
  2858. $web = Website::where('id', $data['website_id'])->first();
  2859. if (empty($web)) {
  2860. return Result::error("该网站不存在", 0);
  2861. }
  2862. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2863. ->where('job_hunting.website_id', $data['website_id'])
  2864. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2865. $query->where(function ($q) use ($data) {
  2866. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2867. });
  2868. })
  2869. ->select(
  2870. 'job_hunting.id',
  2871. 'job_hunting.cat_arr_id',
  2872. 'job_hunting.job_name_get',
  2873. 'job_hunting.industry',
  2874. 'job_hunting.name',
  2875. 'job_hunting.sexy',
  2876. 'job_hunting.origin',
  2877. 'job_hunting.city_arr_id',
  2878. 'job_hunting.experience',
  2879. 'job_hunting.updated_at',
  2880. 'job_hunting.salary'
  2881. )
  2882. ->orderBy('updated_at', 'desc')
  2883. ->limit($data['job1_num'])
  2884. ->get();
  2885. $web['website_id'] = $data['website_id'];
  2886. if (empty($job_hunting)) {
  2887. $job_huntings = "未查询到相关简历信息";
  2888. } else {
  2889. $job_huntings = $this->processJob($job_hunting, $web);
  2890. }
  2891. // 0:待审核 1:已通过 2:已拒绝
  2892. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2893. ->where('job_recruiting.website_id', $data['website_id'])
  2894. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2895. $query->where(function ($q) use ($data) {
  2896. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2897. });
  2898. })
  2899. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2900. ->select(
  2901. 'job_recruiting.id',
  2902. 'job_recruiting.cat_arr_id',
  2903. 'job_recruiting.title',
  2904. 'job_recruiting.jtzw_id',
  2905. 'job_recruiting.hy_id',
  2906. 'job_recruiting.city_arr_id',
  2907. 'job_recruiting.due_data',
  2908. 'job_recruiting.updated_at',
  2909. 'job_recruiting.experience',
  2910. 'job_recruiting.educational',
  2911. 'job_recruiting.salary',
  2912. 'job_recruiting.zw_id',
  2913. 'job_company.business_name'
  2914. )
  2915. ->orderBy('updated_at', 'desc')
  2916. ->limit($data['job2_num'])
  2917. ->get();
  2918. if (empty($job_recruiting->toArray())) {
  2919. $job_recruitings = "未查询到相关职位信息";
  2920. } else {
  2921. $job_recruitings = $this->processJob($job_recruiting, $web);
  2922. }
  2923. $result = [
  2924. 'job_hunting' => $job_huntings,
  2925. 'job_recuiting' => $job_recruitings,
  2926. ];
  2927. return Result::success($result);
  2928. }
  2929. /**
  2930. * c端-获取招工招聘列表
  2931. * @param array $data
  2932. * @return array
  2933. * */
  2934. public function getWebsiteJobList(array $data): array
  2935. {
  2936. $recruit_where = [];
  2937. $hunt_where = [];
  2938. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2939. if (empty($web)) {
  2940. return Result::error("此网站不存在", 0);
  2941. }
  2942. $website_id['website_id'] = $data['website_id'];
  2943. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2944. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2945. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2946. }
  2947. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2948. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2949. }
  2950. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2951. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2952. }
  2953. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2954. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  2955. }
  2956. $query = JobRecruiting::where('job_recruiting.status', 1)
  2957. ->where('job_recruiting.website_id', $data['website_id'])
  2958. ->where($recruit_where)
  2959. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2960. $query->where(function ($q) use ($data) {
  2961. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2962. });
  2963. })
  2964. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2965. $query->where(function ($q) use ($data) {
  2966. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2967. });
  2968. })
  2969. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2970. ->select(
  2971. 'job_recruiting.id',
  2972. 'job_recruiting.hy_id',
  2973. 'job_recruiting.title',
  2974. 'job_recruiting.zw_id',
  2975. 'job_recruiting.educational',
  2976. 'job_recruiting.jtzw_id',
  2977. 'job_recruiting.city_arr_id',
  2978. 'job_recruiting.due_data',
  2979. 'job_recruiting.experience',
  2980. 'job_recruiting.cat_arr_id',
  2981. 'job_recruiting.updated_at',
  2982. 'job_company.business_name'
  2983. )
  2984. ->orderBy('job_recruiting.updated_at', 'desc');
  2985. $recruit_count = $query->count();
  2986. $query = clone $query;
  2987. $JobRecruiting = $query
  2988. ->offset(($data['page'] - 1) * $data['pageSize'])
  2989. ->limit($data['pageSize'])
  2990. ->get();
  2991. if (empty($JobRecruiting)) {
  2992. $JobRecruiting = "暂无相关职位信息";
  2993. } else {
  2994. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2995. }
  2996. }
  2997. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2998. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2999. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3000. }
  3001. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3002. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3003. }
  3004. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3005. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3006. }
  3007. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3008. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3009. }
  3010. $query = JobHunting::where('job_hunting.status', 2)
  3011. ->where('job_hunting.website_id', $data['website_id'])
  3012. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3013. ->where($hunt_where)
  3014. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3015. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3016. // })
  3017. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3018. $query->where(function ($q) use ($data) {
  3019. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3020. });
  3021. })
  3022. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3023. $query->where(function ($q) use ($data) {
  3024. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3025. });
  3026. })
  3027. ->select(
  3028. 'job_hunting.id',
  3029. 'job_hunting.sexy',
  3030. 'job_hunting.experience',
  3031. 'job_hunting.origin',
  3032. 'job_hunting.industry',
  3033. 'job_hunting.name',
  3034. 'job_hunting.job',
  3035. 'job_hunting.job_name_get',
  3036. 'job_hunting.city_arr_id',
  3037. 'job_hunting.cat_arr_id',
  3038. 'job_hunting.created_at',
  3039. 'job_hunting.updated_at',
  3040. 'job_position.zwname as job_name'
  3041. )
  3042. ->orderBy('job_hunting.updated_at', 'desc');
  3043. $hunt_count = $query->count();
  3044. $query = clone $query;
  3045. $JobHunting = $query
  3046. ->offset(($data['page'] - 1) * $data['pageSize'])
  3047. ->limit($data['pageSize'])
  3048. ->get();
  3049. if (empty($JobHunting)) {
  3050. $JobRecruiting = "暂无相关简历信息";
  3051. } else {
  3052. $JobHunting = $this->processJob($JobHunting, $website_id);
  3053. }
  3054. }
  3055. $result = [
  3056. 'JobRecruiting' => $JobRecruiting ?? [],
  3057. 'recruit_count' => $recruit_count ?? 0,
  3058. 'JobHunting' => $JobHunting ?? [],
  3059. 'hunt_count' => $hunt_count ?? 0,
  3060. ];
  3061. return Result::success($result);
  3062. }
  3063. /**
  3064. * c端-获取招工招聘详情
  3065. * @param array $data
  3066. * @return array
  3067. * */
  3068. public function getWebsiteJobInfo(array $data): array
  3069. {
  3070. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3071. if (empty($web)) {
  3072. return Result::error("该网站不存在", 0);
  3073. }
  3074. $webid = [
  3075. 'website_id' => $data['website_id'],
  3076. ];
  3077. // 职位相关信息
  3078. if ($data['type'] == 1) {
  3079. $query = JobRecruiting::where('status', 1)
  3080. ->where('website_id', $data['website_id'])
  3081. ->select('*');
  3082. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3083. $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();
  3084. if (!empty($company)) {
  3085. $result['company'] = $this->processJob($company, $webid);
  3086. }
  3087. $other_job = JobRecruiting::where('status', 1)
  3088. ->where('website_id', $data['website_id'])
  3089. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3090. ->where('id', '!=', $data['id'])
  3091. ->where('user_id', '=', $job[0]['user_id'])
  3092. ->limit($data['pageSize'])
  3093. ->get();
  3094. if (!empty($other_job)) {
  3095. $result['other_job'] = $this->processJob($other_job, $webid);
  3096. }
  3097. } else {
  3098. // 简历相关信息
  3099. $job = JobHunting::where('job_hunting.status', 2)
  3100. ->where('job_hunting.website_id', $data['website_id'])
  3101. ->where('job_hunting.id', $data['id'])
  3102. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3103. ->select('job_hunting.*', 'user_name')
  3104. ->get();
  3105. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3106. if (!empty($resume->toArray())) {
  3107. $result['resume'] = 1;
  3108. } else {
  3109. $result['resume'] = 0;
  3110. }
  3111. }
  3112. if (empty($job->toArray())) {
  3113. return Result::error("id参数错误", 0);
  3114. }
  3115. if (!empty($job[0]['job_experience'])) {
  3116. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3117. if (!empty($job_experience)) {
  3118. // $hy = [];
  3119. foreach ($job_experience as $key => $value) {
  3120. // $id = $value['id'];
  3121. $hy[$key] = $value['job_industry'];
  3122. $zw_id[$key] = $value['job_typename'];
  3123. $jtzw_id[$key] = $value['job_name'];
  3124. }
  3125. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3126. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3127. // 先将关联表转换为索引数组,提高查找效率
  3128. $hyLookup = [];
  3129. foreach ($hy_table as $item) {
  3130. $hyLookup[$item['hyid']] = $item['hyname'];
  3131. }
  3132. $zwLookup = [];
  3133. foreach ($zw_table as $item) {
  3134. $zwLookup[$item['zwid']] = $item['zwname'];
  3135. }
  3136. foreach ($job_experience as $key => &$value) {
  3137. // 处理行业名称
  3138. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3139. $value['hy_name'] = $hyLookup[$hy[$key]];
  3140. }
  3141. // 处理职位名称
  3142. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3143. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3144. }
  3145. // 处理具体职位名称
  3146. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3147. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3148. }
  3149. }
  3150. // 释放引用,防止意外修改后续代码
  3151. unset($value);
  3152. }
  3153. $result['job_experience'] = $job_experience ?? [];
  3154. }
  3155. if (!empty($job[0]['education_experience'])) {
  3156. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3157. if (!empty($education_experience)) {
  3158. foreach ($education_experience as $key => $value) {
  3159. // $id = $value['id'];
  3160. $education[$key] = $value['school_education'];
  3161. }
  3162. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3163. // // 先将关联表转换为索引数组,提高查找效率
  3164. $educationLookup = [];
  3165. foreach ($education_table as $item) {
  3166. $educationLookup[$item['evalue']] = $item['ename'];
  3167. }
  3168. foreach ($education_experience as $key => &$value) {
  3169. // 处理学历名称
  3170. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3171. $value['education_name'] = $educationLookup[$education[$key]];
  3172. }
  3173. }
  3174. }
  3175. $result['education_experience'] = $job_experience ?? [];
  3176. }
  3177. $result['job'] = $this->processJob($job, $webid);
  3178. // // 返现对应的栏目
  3179. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3180. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3181. ->whereIn('category_id', $catid)
  3182. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3183. ->orderBy('pid')->get()->all();
  3184. if (!empty($category)) {
  3185. $result['category'] = $category;
  3186. }
  3187. $result['job'] = $job;
  3188. $result['job_experience'] = $job_experience ?? [];
  3189. $result['education_experience'] = $education_experience ?? [];
  3190. if (empty($result)) {
  3191. return Result::error("参数错误", 0);
  3192. }
  3193. return Result::success($result);
  3194. }
  3195. /**
  3196. * c端-申请职位
  3197. * @param array $data
  3198. * @return array
  3199. * */
  3200. public function getWebsiteJobApply(array $data): array
  3201. {
  3202. // 首先验证网站是否存在
  3203. // return Result::success($data);
  3204. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3205. if (empty($web)) {
  3206. return Result::error("该网站不存在", 0);
  3207. }
  3208. // 验证用户是否存在且为个人会员/管理员
  3209. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3210. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3211. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3212. return Result::error("用户不存在", 0);
  3213. }
  3214. // 去除重复元素和空元素,并保持原始顺序
  3215. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3216. return !empty($value);
  3217. }));
  3218. // 验证职位是否存在 1:审核通过
  3219. $recruiting = JobRecruiting::where('status', 1)
  3220. ->where('website_id', $data['website_id'])
  3221. ->whereIn('id', $data['recruit_id'])
  3222. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3223. if (empty($recruiting)) {
  3224. return Result::error("该职位不存在", 0);
  3225. }
  3226. // 简历是否存在
  3227. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3228. if (empty($hunt_id)) {
  3229. return Result::error("该简历不存在", 0);
  3230. }
  3231. $data['hunt_id'] = $hunt_id['hunt_id'];
  3232. // // 验证是否已投递过该职位
  3233. $apply = JobApply::where('user_id', $data['user_id'])
  3234. ->where('hunt_id', $data['hunt_id'])
  3235. ->where('website_id', $data['website_id'])
  3236. ->whereIn('recruit_id', $data['recruit_id'])
  3237. ->get(['recruit_id']);
  3238. if (!empty($apply->toArray())) {
  3239. return Result::error("您已投递过该职位!");
  3240. }
  3241. $insertData = array_map(function ($recruiting) use ($data) {
  3242. return [
  3243. 'user_id' => $data['user_id'],
  3244. 'hunt_id' => $data['hunt_id'],
  3245. 'website_id' => $data['website_id'],
  3246. 'recruit_id' => $recruiting['recruit_id'],
  3247. 'receiver_id' => $recruiting['receiver_id'],
  3248. 'status' => 1,
  3249. ];
  3250. }, $recruiting);
  3251. // 批量插入数据
  3252. $result = JobApply::insert($insertData);
  3253. if (empty($result)) {
  3254. return Result::error("投递失败", 0);
  3255. }
  3256. return Result::success($result);
  3257. }
  3258. /**
  3259. * 招工招聘-沟通简历
  3260. * @param array $data
  3261. * @return array
  3262. * */
  3263. public function getWebsiteJobResume(array $data): array
  3264. {
  3265. // 首先验证网站是否存在
  3266. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3267. if (empty($web)) {
  3268. return Result::error("该网站不存在", 0);
  3269. }
  3270. // return Result::success($data);
  3271. // 验证用户是否存在且为企业会员/管理员
  3272. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3273. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3274. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3275. return Result::error("用户不存在", 0);
  3276. }
  3277. // 去除重复元素和空元素,并保持原始顺序
  3278. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3279. return !empty($value);
  3280. }));
  3281. // 验证简历是否存在
  3282. $hunting = JobHunting::where('status', 2)
  3283. ->where('website_id', $data['website_id'])
  3284. ->whereIn('id', $data['hunt_id'])
  3285. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3286. if (empty($hunting)) {
  3287. return Result::error("该简历不存在", 0);
  3288. }
  3289. // 验证是否已沟通过该简历
  3290. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3291. ->where('recruit_id', $data['recruit_id'])
  3292. ->where('website_id', $data['website_id'])
  3293. ->whereIn('hunt_id', $data['hunt_id'])
  3294. ->get(['hunt_id']);
  3295. if (!empty($remuse->toArray())) {
  3296. return Result::error("您已沟通过该简历!");
  3297. }
  3298. // 准备要插入的数据数组
  3299. $insertData = array_map(function ($hunting) use ($data) {
  3300. return [
  3301. 'user_id' => $data['user_id'],
  3302. 'recruit_id' => $data['recruit_id'],
  3303. 'website_id' => $data['website_id'],
  3304. 'hunt_id' => $hunting['hunt_id'],
  3305. 'receiver_id' => $hunting['receiver_id'],
  3306. 'status' => 1,
  3307. ];
  3308. }, $hunting);
  3309. // 批量插入数据
  3310. $result = JobRemuse::insert($insertData);
  3311. if (empty($result)) {
  3312. return Result::error("沟通失败", 0);
  3313. }
  3314. return Result::success($result);
  3315. }
  3316. /**
  3317. * 招工招聘 -我的职位(企业会员)
  3318. * @param array $data
  3319. * @return array
  3320. */
  3321. public function getWebsiteJobRecruiting(array $data): array
  3322. {
  3323. $web = Website::where('id', $data['website_id'])->first('id');
  3324. if (empty($web)) {
  3325. return Result::error("该网站不存在", 0);
  3326. }
  3327. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3328. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3329. return Result::error("用户暂无权限!", 0);
  3330. }
  3331. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3332. $result = JobRecruiting::where('website_id', $data['website_id'])
  3333. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3334. $query->where('user_id', $user['id']);
  3335. })
  3336. ->where('status', 1)
  3337. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3338. ->orderBy('updated_at', 'desc')
  3339. ->limit($data['pageSize'])
  3340. ->get();
  3341. if (empty($result)) {
  3342. return Result::error("暂无相关职位信息", 0);
  3343. }
  3344. return Result::success($result);
  3345. }
  3346. /**
  3347. * c端 - 验证路由
  3348. * @param array $data
  3349. * @return array
  3350. */
  3351. /**
  3352. * c端 - 验证路由
  3353. * @param array $data
  3354. * @return array
  3355. */
  3356. public function checkWebsiteRoute(array $data): array
  3357. {
  3358. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3359. if (empty($web)) {
  3360. return Result::error("该网站不存在", 0);
  3361. } elseif ($web['status'] != 1) {
  3362. return Result::error("网站已经关闭", 0);
  3363. }
  3364. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3365. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3366. // 验证路由是否存在
  3367. if (empty($whiteRouterInfo)) {
  3368. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3369. }
  3370. if (!empty($whiteRouterInfo)) {
  3371. return Result::success($whiteRouterInfo->toArray());
  3372. }
  3373. }
  3374. // 验证栏目路由
  3375. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3376. ->where('aLIas_pinyin', $data['last_route'])
  3377. ->get()->all();
  3378. if (count($last_category) == 0) {
  3379. return Result::error("该栏目不存在", 0);
  3380. }
  3381. if (count($last_category) > 1) {
  3382. return Result::error("该子级栏目存在多个,路由验证失败!", 0);
  3383. }
  3384. if (count($last_category) == 1) {
  3385. $last_category = $last_category[0];
  3386. }
  3387. // return Result::success($last_category);
  3388. if (isset($data['id']) && !empty($data['id'])) {
  3389. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3390. switch ($last_category['type']) {
  3391. case 1:
  3392. // 文章
  3393. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3394. $article = Article::where('status', 1)
  3395. ->where('id', $data['id'])
  3396. ->where(function ($query) use ($data) {
  3397. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3398. ->orWhereNull("ignore_ids");
  3399. })
  3400. ->first(['cat_arr_id']);
  3401. if (empty($article)) {
  3402. return Result::error("该文章不存在", 0);
  3403. }
  3404. // return Result::success($article);
  3405. break;
  3406. case 2:
  3407. // 商品
  3408. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3409. $article = Good::where('website_id', $data['website_id'])
  3410. ->where('status', 2)
  3411. ->where('id', $data['id'])
  3412. ->first(['cat_arr_id']);
  3413. if (empty($article)) {
  3414. return Result::error("该商品不存在", 0);
  3415. }
  3416. break;
  3417. case 3:
  3418. // 书刊信息
  3419. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3420. $article = Book::where('website_id', $data['website_id'])
  3421. ->where('status', 2)
  3422. ->where('id', $data['id'])
  3423. ->first(['id', 'cat_arr_id']);
  3424. if (empty($article)) {
  3425. return Result::error("该书刊不存在", 0);
  3426. }
  3427. break;
  3428. case 4:
  3429. // 招聘
  3430. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3431. $article = JobRecruiting::where('website_id', $data['website_id'])
  3432. ->where('status', 1)
  3433. ->where('id', $data['id'])
  3434. ->first(['cat_arr_id']);
  3435. if (empty($article)) {
  3436. return Result::error("该招聘不存在", 0);
  3437. }
  3438. break;
  3439. case 5:
  3440. // 求职
  3441. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3442. $article = JobHunting::where('website_id', $data['website_id'])
  3443. ->where('status', 2)
  3444. ->where('id', $data['id'])
  3445. ->first(['cat_arr_id']);
  3446. if (empty($article)) {
  3447. return Result::error("该求职不存在", 0);
  3448. }
  3449. break;
  3450. case 6:
  3451. // 企业
  3452. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3453. $article = Company::where('website_id', $data['website_id'])
  3454. ->where('status', 1)
  3455. ->where('id', $data['id'])
  3456. ->first(['cat_arr_id']);
  3457. if (empty($article)) {
  3458. return Result::error("该企业不存在", 0);
  3459. }
  3460. break;
  3461. case 7:
  3462. // 项目
  3463. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3464. $article = Project::where('website_id', $data['website_id'])
  3465. ->where('status', 1)
  3466. ->where('id', $data['id'])
  3467. ->first(['cat_arr_id']);
  3468. if (empty($article)) {
  3469. return Result::error("该项目不存在", 0);
  3470. }
  3471. break;
  3472. default:
  3473. return Result::error("该数据不存在", 0);
  3474. break;
  3475. }
  3476. $catid = 0;
  3477. $catidArray = json_decode($article['cat_arr_id'], true);
  3478. $catid = !empty($catidArray) ? end($catidArray) : null;
  3479. // return Result::success($article['cat_arr_id']);
  3480. if (empty($catid)) {
  3481. return Result::error("该数据不存在", 0);
  3482. }
  3483. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3484. ->where('category_id', $catid)
  3485. ->select('path')
  3486. ->pluck('path');
  3487. } else {
  3488. if ($last_category['pid'] != 0) {
  3489. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3490. $catid = !empty($cat_arr) ? end($cat_arr) : null;
  3491. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3492. ->where('category_id', $catid)
  3493. ->where('path', $data['all_route'])
  3494. ->pluck('path');
  3495. } else {
  3496. $pinyin[0] = $last_category['aLIas_pinyin'];
  3497. }
  3498. }
  3499. // return Result::success($pinyin[0]);
  3500. if (empty($pinyin) || count($pinyin) > 1 || $pinyin[0] != $data['all_route']) {
  3501. return Result::error('非法路径!');
  3502. } else {
  3503. return Result::success($pinyin);
  3504. }
  3505. }
  3506. /**
  3507. * 招工招聘 - 获取推荐职位
  3508. * @param array $data
  3509. * @return array
  3510. */
  3511. public function getWebsiteLevelJob(array $data): array
  3512. {
  3513. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3514. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3515. ->where('job_recruiting.status', 1)
  3516. ->where('job_level', $data['job_level'])
  3517. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3518. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3519. ->orderBy('job_recruiting.updated_at', 'desc')
  3520. ->limit($data['pageSize'])
  3521. ->get();
  3522. $web = ['website_id' => $data['website_id']];
  3523. if (!empty($job)) {
  3524. $result = $this->processJob($job, $web);
  3525. }
  3526. if (empty($result)) {
  3527. return Result::error("暂无相关职位信息", 0);
  3528. }
  3529. return Result::success($result);
  3530. }
  3531. /**
  3532. * 验证导航名称是否重复
  3533. * @return void
  3534. */
  3535. //20250226 产品列表
  3536. public function getGoodList(array $data): array
  3537. {
  3538. var_dump($data, '---------1-2--');
  3539. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3540. unset($data['user_type_id']);
  3541. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3542. $where = [];
  3543. if ($type_id != '10000') {
  3544. $where = [
  3545. 'good.user_id' => $user_id,
  3546. ];
  3547. }
  3548. //类型
  3549. if (isset($data['type_id']) && $data['type_id']) {
  3550. $where['good.type_id'] = $data['type_id'];
  3551. }
  3552. //名称
  3553. if (isset($data['name']) && $data['name']) {
  3554. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3555. }
  3556. //status
  3557. if (isset($data['status']) && $data['status'] != '') {
  3558. $where['good.status'] = $data['status'];
  3559. }
  3560. //status1
  3561. // if (isset($data['status1']) && $data['status1'] == 1) {
  3562. // $status1 = 1;
  3563. // }
  3564. $where1 = [];
  3565. //website_id
  3566. // if (isset($data['website_id']) && $data['website_id']) {
  3567. // $where1 = [
  3568. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3569. // ];
  3570. // }
  3571. // website_name
  3572. if (isset($data['website_name']) && $data['website_name']) {
  3573. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3574. }
  3575. // catid
  3576. if (isset($data['category_name']) && $data['category_name']) {
  3577. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3578. }
  3579. // $result = Good::where($where)
  3580. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3581. var_dump($where, '---------1---');
  3582. $result = Good::where($where)
  3583. ->when(!empty($where1), function ($query) use ($where1) {
  3584. return $query->where($where1);
  3585. })
  3586. //status 1待审核2已审核3已拒绝
  3587. ->when(isset($data['status1']), function ($query) {
  3588. return $query->whereIn('good.status', [1, 3]);
  3589. })
  3590. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3591. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3592. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3593. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3594. ->orderBy("updated_at", "desc")
  3595. ->limit($data['page_size'])
  3596. ->offset(($data['page'] - 1) * $data['page_size'])
  3597. ->get();
  3598. $count = Good::where($where)
  3599. ->when(!empty($where1), function ($query) use ($where1) {
  3600. return $query->where($where1);
  3601. })
  3602. //status 1待审核2已审核3已拒绝
  3603. ->when(isset($data['status1']), function ($query) {
  3604. return $query->whereIn('good.status', [1, 3]);
  3605. })
  3606. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3607. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3608. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3609. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3610. ->orderBy("updated_at", "desc")->count();
  3611. $data = [
  3612. 'rows' => $result->toArray(),
  3613. 'count' => $count,
  3614. ];
  3615. if (empty($result)) {
  3616. return Result::error("此栏目暂无相关产品", 0);
  3617. }
  3618. return Result::success($data);
  3619. }
  3620. public function getGoodInfo(array $data): array
  3621. {
  3622. $result = Good::where('id', $data['id'])->first();
  3623. if (empty($result)) {
  3624. return Result::error("此产品不存在", 0);
  3625. }
  3626. return Result::success($result);
  3627. }
  3628. public function addGood(array $data): array
  3629. {
  3630. // unset($data['city_arr_id']);
  3631. // unset($data['cat_arr_id']);
  3632. $data['city_id'] = end($data['city_arr_id']);
  3633. $data['catid'] = end($data['cat_arr_id']);
  3634. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3635. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3636. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3637. unset($data['imgUrl']); //大小写
  3638. if (isset($data['price']) && $data['price'] == '') {
  3639. $data['price'] = 0;
  3640. }
  3641. if ($data['imgurl'] == '') {
  3642. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3643. preg_match_all($reg, $data['detail'], $matches);
  3644. if (isset($matches[1][0])) {
  3645. //截取varchar240
  3646. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3647. }
  3648. }
  3649. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3650. //提取标题+内容中的关键词
  3651. $data['keyword'] = $data['name'];
  3652. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3653. Jieba::init(); // 初始化 jieba-php
  3654. Finalseg::init();
  3655. $segList = Jieba::cut($data['keyword']);
  3656. $segList1 = array_slice($segList, 0, 8);
  3657. $data['keyword'] = implode(',', $segList1);
  3658. }
  3659. if ($data['description'] == '') {
  3660. //提取内容中的描述
  3661. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3662. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3663. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3664. }
  3665. if ($data['status'] == 1) {
  3666. $this->sendMessage([
  3667. 'talk_type' => 200,
  3668. 'title' => $data['name'],
  3669. 'content' => '提交了审核',
  3670. 'messageType' => 3,
  3671. ]);
  3672. }
  3673. $result = Good::insert($data);
  3674. if (empty($result)) {
  3675. return Result::error("添加失败", 0);
  3676. }
  3677. return Result::success($result);
  3678. }
  3679. public function updateGood(array $data): array
  3680. {
  3681. $data['city_id'] = end($data['city_arr_id']);
  3682. $data['catid'] = end($data['cat_arr_id']);
  3683. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3684. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3685. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3686. //设置东八区
  3687. date_default_timezone_set('Asia/Shanghai');
  3688. $data['updated_at'] = date('Y-m-d H:i:s');
  3689. if (isset($data['price']) && $data['price'] == '') {
  3690. $data['price'] = 0;
  3691. }
  3692. if ($data['imgurl'] == '') {
  3693. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3694. preg_match_all($reg, $data['detail'], $matches);
  3695. if (isset($matches[1][0])) {
  3696. //截取varchar240
  3697. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3698. }
  3699. }
  3700. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3701. //提取标题+内容中的关键词
  3702. $data['keyword'] = $data['name'];
  3703. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3704. Jieba::init(); // 初始化 jieba-php
  3705. Finalseg::init();
  3706. $segList = Jieba::cut($data['keyword']);
  3707. $segList1 = array_slice($segList, 0, 8);
  3708. $data['keyword'] = implode(',', $segList1);
  3709. }
  3710. if ($data['description'] == '') {
  3711. //提取内容中的描述
  3712. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3713. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3714. }
  3715. if ($data['status'] == 1) {
  3716. $this->sendMessage([
  3717. 'talk_type' => 200,
  3718. 'title' => $data['name'],
  3719. 'content' => '提交了审核',
  3720. 'messageType' => 3,
  3721. ]);
  3722. }
  3723. $result = Good::where('id', $data['id'])->update($data);
  3724. if (empty($result)) {
  3725. return Result::error("更新失败", 0);
  3726. }
  3727. return Result::success($result);
  3728. }
  3729. public function delGood(array $data): array
  3730. {
  3731. $result = Good::where('id', $data['id'])->delete();
  3732. if (empty($result)) {
  3733. return Result::error("删除失败", 0);
  3734. }
  3735. return Result::success($result);
  3736. }
  3737. //20250226 产品列表
  3738. //20250306 求职信息
  3739. public function getJobHuntingList(array $data): array
  3740. {
  3741. $where = [];
  3742. if (isset($data['username']) && !empty($data['username'])) {
  3743. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3744. }
  3745. //status 1待审核2已审核3已拒绝
  3746. if (isset($data['status']) && $data['status'] != '') {
  3747. $where = [
  3748. 'job_hunting.status' => $data['status'],
  3749. ];
  3750. }
  3751. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3752. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3753. unset($data['type_id']);
  3754. if ($type_id != '10000') {
  3755. $where[] = ['job_hunting.user_id', '=', $user_id];
  3756. }
  3757. $result = JobHunting::where($where)
  3758. ->when(!empty($data['status1']), function ($query) use ($data) {
  3759. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3760. })
  3761. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3762. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3763. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3764. ->orderBy("updated_at", "desc")
  3765. ->limit($data['page_size'])
  3766. ->offset(($data['page'] - 1) * $data['page_size'])
  3767. ->get();
  3768. if (empty($result)) {
  3769. return Result::error("查询失败", 0);
  3770. }
  3771. $count = JobHunting::where($where)
  3772. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3773. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3774. ->count();
  3775. $data = [
  3776. 'rows' => $result->toArray(),
  3777. 'count' => $count,
  3778. ];
  3779. return Result::success($data);
  3780. }
  3781. public function getJobHuntingApply(array $data): array
  3782. {
  3783. var_dump($data, '-----------------test--------1-');
  3784. $where = [];
  3785. if (isset($data['username']) && !empty($data['username'])) {
  3786. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3787. }
  3788. if (isset($data['salary']) && !empty($data['salary'])) {
  3789. $where[] = [
  3790. 'job_hunting.salary',
  3791. '=',
  3792. $data['salary'],
  3793. ];
  3794. }
  3795. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3796. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3797. unset($data['type_id']);
  3798. if ($type_id != '10000') {
  3799. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3800. }
  3801. var_dump($where, '-----------------test---------');
  3802. $result = jobApply::where($where)
  3803. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3804. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3805. // })
  3806. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3807. ->where('job_enum.egroup', '=', 'income')
  3808. ->where('job_hunting.status', 2) //已审核
  3809. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3810. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3811. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3812. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3813. //职位----是申请职位
  3814. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3815. ->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')
  3816. ->orderBy("job_hunting.updated_at", "desc")
  3817. ->limit($data['page_size'])
  3818. ->offset(($data['page'] - 1) * $data['page_size'])
  3819. ->get();
  3820. if (empty($result)) {
  3821. return Result::error("查询失败", 0);
  3822. }
  3823. $count = jobApply::where($where)
  3824. ->where('job_enum.egroup', '=', 'income')
  3825. ->where('job_hunting.status', 2) //已审核
  3826. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3827. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3828. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3829. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3830. //职位----是申请职位
  3831. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3832. ->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')
  3833. ->count();
  3834. $data = [
  3835. 'rows' => $result->toArray(),
  3836. 'count' => $count,
  3837. ];
  3838. return Result::success($data);
  3839. }
  3840. public function addJobHunting(array $data): array
  3841. {
  3842. date_default_timezone_set('Asia/Shanghai');
  3843. unset($data['company_name']);
  3844. unset($data['job_industry']);
  3845. unset($data['job_name']);
  3846. unset($data['department']);
  3847. unset($data['job_timeList']);
  3848. unset($data['job_content']);
  3849. unset($data['job_typename']); //不知道这是啥,
  3850. $data['created_at'] = date('Y-m-d H:i:s');
  3851. $data['updated_at'] = date('Y-m-d H:i:s');
  3852. //根据用户 user_id 只能添加一次
  3853. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3854. if (!empty($result)) {
  3855. return Result::error("您已添加过求职信息", 0);
  3856. }
  3857. var_dump($result, '-----------------test---------');
  3858. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3859. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3860. $cityArr = json_decode($data['city_arr_id'], true);
  3861. $data['city_id'] = end($cityArr);
  3862. } else {
  3863. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3864. $data['city_id'] = end($data['city_arr_id']);
  3865. }
  3866. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3867. $this->sendMessage([
  3868. 'talk_type' => 600,
  3869. 'title' => $data['name'],
  3870. 'content' => '提交了审核',
  3871. 'messageType' => 11,
  3872. ]);
  3873. }
  3874. $result = JobHunting::create($data);
  3875. if (empty($result)) {
  3876. return Result::error("添加失败", 0);
  3877. }
  3878. return Result::success($result);
  3879. }
  3880. public function delJobHunting(array $data): array
  3881. {
  3882. $result = JobHunting::where('id', $data['id'])->delete();
  3883. if (empty($result)) {
  3884. return Result::error("删除失败", 0);
  3885. }
  3886. return Result::success($result);
  3887. }
  3888. public function updateJobHunting(array $data): array
  3889. {
  3890. //设置东八区
  3891. date_default_timezone_set('Asia/Shanghai');
  3892. unset($data['company_name']);
  3893. unset($data['job_industry']);
  3894. unset($data['job_name']);
  3895. unset($data['department']);
  3896. unset($data['job_timeList']);
  3897. unset($data['job_content']);
  3898. unset($data['job_typename']); //不知道这是啥,
  3899. $data['created_at'] = date('Y-m-d H:i:s');
  3900. $data['updated_at'] = date('Y-m-d H:i:s');
  3901. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3902. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3903. $cityArr = json_decode($data['city_arr_id'], true);
  3904. $data['city_id'] = end($cityArr);
  3905. } else {
  3906. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3907. $data['city_id'] = end($data['city_arr_id']);
  3908. }
  3909. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3910. $this->sendMessage([
  3911. 'talk_type' => 600,
  3912. 'title' => $data['name'],
  3913. 'content' => '提交了审核',
  3914. 'messageType' => 11,
  3915. ]);
  3916. }
  3917. $result = JobHunting::where('id', $data['id'])->update($data);
  3918. if (empty($result)) {
  3919. return Result::error("更新失败", 0);
  3920. }
  3921. return Result::success($result);
  3922. }
  3923. public function getJobHuntingInfo(array $data): array
  3924. {
  3925. $result = JobHunting::where('id', $data['id'])->first();
  3926. if (empty($result)) {
  3927. return Result::error("查询失败", 0);
  3928. }
  3929. return Result::success($result);
  3930. }
  3931. public function getJobHuntingData(array $data): array
  3932. {
  3933. $jobEnum = JobEnum::get();
  3934. $jobIndustry = JobIndustry::get();
  3935. $jobNature = JobNature::get();
  3936. $jobPosition = JobPosition::get();
  3937. $data = [
  3938. 'jobEnum' => $jobEnum,
  3939. 'jobIndustry' => $jobIndustry,
  3940. 'jobNature' => $jobNature,
  3941. 'jobPosition' => $jobPosition,
  3942. ];
  3943. return Result::success($data);
  3944. }
  3945. public function delJobHuntingInfo(array $data): array
  3946. {
  3947. $result = JobHunting::where('id', $data['id'])->delete();
  3948. return Result::success();
  3949. }
  3950. //20250324 通知,公告,消息
  3951. public function delNotice(array $data): array
  3952. {
  3953. $result = Notice::where('id', $data['id'])->delete();
  3954. if ($result) {
  3955. return Result::success();
  3956. } else {
  3957. return Result::error("删除失败", 0);
  3958. }
  3959. }
  3960. public function getNoticeInfo(array $data): array
  3961. {
  3962. $result = Notice::where('id', $data['id'])->first();
  3963. // var_dump($result['re_user_ids'], '--------------------');
  3964. if (empty($result)) {
  3965. return Result::error("查询失败", 0);
  3966. }
  3967. return Result::success($result);
  3968. }
  3969. public function readNotice(array $data): array
  3970. {
  3971. $result = Notice::where('id', $data['id'])->first();
  3972. // var_dump($result['re_user_ids'], '--------------------');
  3973. if (empty($result)) {
  3974. return Result::error("查询失败", 0);
  3975. }
  3976. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  3977. $re_user_ids = json_decode($result['re_user_ids'], true);
  3978. var_dump($re_user_ids, '--------------1---test---------');
  3979. var_dump($data, '--------------1---test---------');
  3980. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  3981. //如果已经存在,就不再添加
  3982. if (isset($result['read_id']) && !empty($result['read_id'])) {
  3983. $read_id = json_decode($result['read_id'], true);
  3984. if (!is_array($read_id)) {
  3985. $read_id = [];
  3986. }
  3987. if (!in_array($data['user_id'], $read_id)) {
  3988. $read_id[] = $data['user_id'];
  3989. $result['read_id'] = json_encode($read_id);
  3990. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  3991. }
  3992. } else {
  3993. //如果不存在,就添加
  3994. $result['read_id'] = json_encode([$data['user_id']]);
  3995. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  3996. }
  3997. }
  3998. return Result::success($result);
  3999. }
  4000. public function addNotice(array $data): array
  4001. {
  4002. date_default_timezone_set('Asia/Shanghai');
  4003. $data['created_at'] = date('Y-m-d H:i:s');
  4004. $data['updated_at'] = date('Y-m-d H:i:s');
  4005. $user_id = UserInfo::
  4006. //city_id不是null
  4007. whereNotNull('city_id')
  4008. ->whereNotNull('department_id')
  4009. ->where(function ($query) use ($data) {
  4010. $query->where(function ($subQuery) use ($data) {
  4011. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4012. });
  4013. })
  4014. ->where(function ($query) use ($data) {
  4015. $query->where(function ($subQuery) use ($data) {
  4016. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4017. });
  4018. })
  4019. ->pluck('user_id')->toArray();
  4020. $user_id = array_unique($user_id);
  4021. $chat_ids = $user_id;
  4022. $user_id = json_encode($user_id);
  4023. $data['re_user_ids'] = $user_id;
  4024. $this->sendMessage([
  4025. 'talk_type' => 700,
  4026. 'title' => $data['title'],
  4027. 'content' => '提交了审核',
  4028. 'messageType' => 5,
  4029. ]);
  4030. $result = Notice::insertGetId($data);
  4031. if (empty($result)) {
  4032. return Result::error("添加失败", 0);
  4033. }
  4034. return Result::success($result);
  4035. }
  4036. public function updateNotice(array $data): array
  4037. {
  4038. date_default_timezone_set('Asia/Shanghai');
  4039. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4040. $user_id = UserInfo::
  4041. //city_id不是null
  4042. whereNotNull('city_id')
  4043. ->whereNotNull('department_id')
  4044. ->where(function ($query) use ($data) {
  4045. $query->where(function ($subQuery) use ($data) {
  4046. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4047. });
  4048. })
  4049. ->where(function ($query) use ($data) {
  4050. $query->where(function ($subQuery) use ($data) {
  4051. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4052. });
  4053. })
  4054. ->pluck('user_id')->toArray();
  4055. $user_id = array_unique($user_id);
  4056. $user_id = json_encode($user_id);
  4057. $data['re_user_ids'] = $user_id;
  4058. $data['updated_at'] = date('Y-m-d H:i:s');
  4059. $this->sendMessage([
  4060. 'talk_type' => 700,
  4061. 'title' => $data['title'],
  4062. 'content' => '提交了审核',
  4063. 'messageType' => 5,
  4064. ]);
  4065. $result = Notice::where('id', $data['id'])->update($data);
  4066. return Result::success($result);
  4067. }
  4068. public function getNoticeList(array $data): array
  4069. {
  4070. $where = [];
  4071. //title
  4072. if (isset($data['title']) && !empty($data['title'])) {
  4073. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4074. }
  4075. //level
  4076. if (isset($data['level']) && !empty($data['level'])) {
  4077. $where[] = ['notice.level', '=', $data['level']];
  4078. }
  4079. //status
  4080. if (isset($data['status']) && !empty($data['status'])) {
  4081. $where[] = ['notice.status', '=', $data['status']];
  4082. }
  4083. //type
  4084. if (isset($data['type']) && !empty($data['type'])) {
  4085. $where[] = ['notice.type', '=', $data['type']];
  4086. }
  4087. var_dump($data, '------------11111-2----test---------');
  4088. if ($data['type_id'] == 10000) {
  4089. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4090. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4091. })
  4092. ->where($where)
  4093. ->orderBy('updated_at', 'desc')
  4094. ->limit($data['page_size'])
  4095. ->offset(($data['page'] - 1) * $data['page_size'])
  4096. ->get();
  4097. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4098. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4099. })
  4100. ->where($where)
  4101. ->orderBy('updated_at', 'desc')
  4102. ->count();
  4103. } else {
  4104. $result = Notice::where($where)
  4105. // ->where('user_id', $data['user_id'])
  4106. ->Where(function ($query) use ($data) {
  4107. $query->Where(function ($q) use ($data) {
  4108. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4109. ->orWhere('notice.user_id', $data['user_id']);
  4110. });
  4111. })
  4112. ->when(!empty($data['status1']), function ($query) use ($data) {
  4113. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4114. })
  4115. ->orderBy('updated_at', 'desc')
  4116. ->limit($data['page_size'])
  4117. ->offset(($data['page'] - 1) * $data['page_size'])
  4118. ->get();
  4119. $total = Notice::where($where)
  4120. ->when(!empty($data['status1']), function ($query) use ($data) {
  4121. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4122. })
  4123. // ->where('user_id', $data['user_id'])
  4124. ->Where(function ($query) use ($data) {
  4125. $query->Where(function ($q) use ($data) {
  4126. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4127. ->orWhere('notice.user_id', $data['user_id']);
  4128. });
  4129. })
  4130. ->count();
  4131. }
  4132. if (empty($result)) {
  4133. return Result::error("查询失败", 0);
  4134. }
  4135. $data = [
  4136. 'rows' => $result,
  4137. 'count' => $total,
  4138. ];
  4139. return Result::success($data);
  4140. }
  4141. public function noticeList(array $data): array
  4142. {
  4143. $where = [];
  4144. //title
  4145. if (isset($data['title']) && !empty($data['title'])) {
  4146. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4147. }
  4148. //level
  4149. if (isset($data['level']) && !empty($data['level'])) {
  4150. $where[] = ['notice.level', '=', $data['level']];
  4151. }
  4152. //status
  4153. if (isset($data['status']) && !empty($data['status'])) {
  4154. $where[] = ['notice.status', '=', $data['status']];
  4155. }
  4156. //type
  4157. if (isset($data['type']) && !empty($data['type'])) {
  4158. $where[] = ['notice.type', '=', $data['type']];
  4159. }
  4160. var_dump($data, '------------11111-2----test---------');
  4161. if ($data['type_id'] == 10000) {
  4162. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4163. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4164. })
  4165. ->where($where)
  4166. ->orderBy('updated_at', 'desc')
  4167. ->limit($data['page_size'])
  4168. ->offset(($data['page'] - 1) * $data['page_size'])
  4169. ->get();
  4170. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4171. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4172. })
  4173. ->where($where)
  4174. ->orderBy('updated_at', 'desc')
  4175. ->count();
  4176. } else {
  4177. $result = Notice::where($where)
  4178. // ->where('user_id', $data['user_id'])
  4179. ->Where(function ($query) use ($data) {
  4180. $query->Where(function ($q) use ($data) {
  4181. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4182. ->orWhere('notice.user_id', $data['user_id']);
  4183. });
  4184. })
  4185. ->when(!empty($data['status1']), function ($query) use ($data) {
  4186. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4187. })
  4188. ->orderBy('updated_at', 'desc')
  4189. ->limit($data['page_size'])
  4190. ->offset(($data['page'] - 1) * $data['page_size'])
  4191. ->get();
  4192. $total = Notice::where($where)
  4193. ->when(!empty($data['status1']), function ($query) use ($data) {
  4194. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4195. })
  4196. // ->where('user_id', $data['user_id'])
  4197. ->Where(function ($query) use ($data) {
  4198. $query->Where(function ($q) use ($data) {
  4199. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4200. ->orWhere('notice.user_id', $data['user_id']);
  4201. });
  4202. })
  4203. ->count();
  4204. }
  4205. if (empty($result)) {
  4206. return Result::error("查询失败", 0);
  4207. }
  4208. $data = [
  4209. 'rows' => $result,
  4210. 'count' => $total,
  4211. ];
  4212. return Result::success($data);
  4213. }
  4214. public function getNoticeDetail(array $data): array
  4215. {
  4216. $result = Notice::where('id', $data['id'])->first();
  4217. if (empty($result)) {
  4218. return Result::error("查询失败", 0);
  4219. }
  4220. return Result::success($result);
  4221. }
  4222. public function deleteNotice(array $data): array
  4223. {
  4224. $notice = Notice::where('id', $data['id'])->first();
  4225. if (empty($notice)) {
  4226. return Result::error("删除失败", 0);
  4227. }
  4228. $chat_group_id = $notice->group_id;
  4229. if ($chat_group_id) {
  4230. //删除群聊
  4231. ChatGroups::where('id', $chat_group_id)->delete();
  4232. //删除群成员
  4233. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4234. //删除群聊记录
  4235. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4236. }
  4237. $result = Notice::where('id', $data['id'])->delete();
  4238. return Result::success($result);
  4239. }
  4240. public function complaintlist(array $data): array
  4241. {
  4242. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4243. unset($data['type_id']);
  4244. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4245. $where = [];
  4246. if ($type_id != 10000 && empty($data['deal_user'])) {
  4247. $where['complaint.user_id'] = $user_id;
  4248. }
  4249. if (!empty($data['title'])) {
  4250. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4251. }
  4252. if (!empty($data['department_id'])) {
  4253. $where['complaint.department_id'] = $data['department_id'];
  4254. }
  4255. if (!empty($data['deal'])) {
  4256. $where['complaint.deal'] = $data['deal'];
  4257. }
  4258. if (!empty($data['status'])) {
  4259. $where['complaint.status'] = $data['status'];
  4260. }
  4261. var_dump(!empty($data['deal_user']), '----------1');
  4262. var_dump($where, '----------2');
  4263. $result = Complaint::where($where)
  4264. ->when(!empty($data['status1']), function ($query) use ($data) {
  4265. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4266. })
  4267. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4268. //json re_user_ids data[user_id]是不是在里面
  4269. $query->Where(function ($q) use ($data) {
  4270. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4271. ->where('complaint.status', 2);
  4272. });
  4273. })
  4274. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4275. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4276. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4277. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4278. ->orderBy('updated_at', 'desc')
  4279. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4280. //sql输出
  4281. if (empty($result)) {
  4282. return Result::error("暂无投诉信息", 0);
  4283. }
  4284. // 取出数据
  4285. $rows = $result->items();
  4286. $count = $result->total();
  4287. $responseData = [
  4288. 'rows' => $rows,
  4289. 'count' => $count,
  4290. ];
  4291. return Result::success($responseData);
  4292. }
  4293. public function getComplaintList(array $data): array
  4294. {
  4295. var_dump($data, '00000001000000000000');
  4296. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4297. unset($data['type_id']);
  4298. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4299. $where = [];
  4300. if ($type_id != 10000 && empty($data['deal_user'])) {
  4301. $where['complaint.user_id'] = $user_id;
  4302. }
  4303. if (!empty($data['title'])) {
  4304. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4305. }
  4306. if (!empty($data['department_id'])) {
  4307. $where['complaint.department_id'] = $data['department_id'];
  4308. }
  4309. if (!empty($data['deal'])) {
  4310. $where['complaint.deal'] = $data['deal'];
  4311. }
  4312. if (!empty($data['status'])) {
  4313. $where['complaint.status'] = $data['status'];
  4314. }
  4315. var_dump(!empty($data['deal_user']), '----------1');
  4316. var_dump($where, '----------2');
  4317. $result = Complaint::where($where)
  4318. ->when(!empty($data['status1']), function ($query) use ($data) {
  4319. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4320. })
  4321. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4322. //json re_user_ids data[user_id]是不是在里面
  4323. $query->Where(function ($q) use ($data) {
  4324. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4325. ->where('complaint.status', 2);
  4326. });
  4327. })
  4328. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4329. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4330. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4331. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4332. ->orderBy('updated_at', 'desc')
  4333. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4334. //sql输出
  4335. if (empty($result)) {
  4336. return Result::error("暂无投诉信息", 0);
  4337. }
  4338. // 取出数据
  4339. $rows = $result->items();
  4340. $count = $result->total();
  4341. $responseData = [
  4342. 'rows' => $rows,
  4343. 'count' => $count,
  4344. ];
  4345. return Result::success($responseData);
  4346. }
  4347. public function getComplaintInfo(array $data): array
  4348. {
  4349. $result = Complaint::where('id', $data['id'])->first();
  4350. if (empty($result)) {
  4351. return Result::error("查询失败", 0);
  4352. }
  4353. return Result::success($result);
  4354. }
  4355. public function readComplaint(array $data): array
  4356. {
  4357. $result = Complaint::where('id', $data['id'])->first();
  4358. if (empty($result)) {
  4359. return Result::error("查询失败", 0);
  4360. }
  4361. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4362. $re_user_ids = json_decode($result['re_user_ids'], true);
  4363. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4364. //如果已经存在,就不再添加
  4365. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4366. $read_id = json_decode($result['read_id'], true);
  4367. if (!is_array($read_id)) {
  4368. $read_id = [];
  4369. }
  4370. if (!in_array($data['user_id'], $read_id)) {
  4371. $read_id[] = $data['user_id'];
  4372. $result['read_id'] = json_encode($read_id);
  4373. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4374. }
  4375. } else {
  4376. //如果不存在,就添加
  4377. $result['read_id'] = json_encode([$data['user_id']]);
  4378. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4379. }
  4380. }
  4381. return Result::success($result);
  4382. }
  4383. public function addComplaint(array $data): array
  4384. {
  4385. date_default_timezone_set('Asia/Shanghai');
  4386. $data['created_at'] = date('Y-m-d H:i:s');
  4387. $data['updated_at'] = date('Y-m-d H:i:s');
  4388. $this->sendMessage([
  4389. 'talk_type' => 800,
  4390. 'title' => $data['title'],
  4391. 'content' => '提交了审核',
  4392. 'messageType' => 6,
  4393. ]);
  4394. $result = Complaint::create($data);
  4395. return Result::success($result);
  4396. }
  4397. public function updateComplaint(array $data): array
  4398. {
  4399. date_default_timezone_set('Asia/Shanghai');
  4400. $data['updated_at'] = date('Y-m-d H:i:s');
  4401. $user_id = $data['user_id'] ?? 0;
  4402. $type_id = $data['type_id'] ?? 0;
  4403. unset($data['user_id']);
  4404. unset($data['type_id']);
  4405. $this->sendMessage([
  4406. 'talk_type' => 800,
  4407. 'title' => $data['title'],
  4408. 'content' => '提交了审核',
  4409. 'messageType' => 6,
  4410. ]);
  4411. $result = Complaint::where('id', $data['id'])->update($data);
  4412. return Result::success($result);
  4413. }
  4414. public function deleteComplaint(array $data): array
  4415. {
  4416. $result = Complaint::where('id', $data['id'])->delete();
  4417. return Result::success($result);
  4418. }
  4419. public function getComplainInfo(array $data): array
  4420. {
  4421. $result = Complaint::where('id', $data['id'])->first();
  4422. if (empty($result)) {
  4423. return Result::error("查询失败", 0);
  4424. }
  4425. return Result::success($result);
  4426. }
  4427. public function updateComplaintStatus(array $data): array
  4428. {
  4429. date_default_timezone_set('Asia/Shanghai');
  4430. $data['updated_at'] = date('Y-m-d H:i:s');
  4431. $user_id = $data['user_id'] ?? 0;
  4432. $type_id = $data['type_id'] ?? 0;
  4433. unset($data['user_id']);
  4434. unset($data['type_id']);
  4435. //处理, 写入处理人
  4436. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4437. $data['real_deal_user'] = $user_id;
  4438. }
  4439. //如果是deal 23,则判断是不是处理人
  4440. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4441. $complaintInof = Complaint::where('id', $data['id'])
  4442. ->where('real_deal_user', $user_id)
  4443. ->first();
  4444. if (empty($complaintInof)) {
  4445. return Result::error("处理人错误", 0);
  4446. }
  4447. }
  4448. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4449. if ($data['status'] == 1) {
  4450. $this->sendMessage([
  4451. 'talk_type' => 800,
  4452. 'title' => $complaintInfo['title'],
  4453. 'content' => '提交了审核',
  4454. 'messageType' => 6,
  4455. ]);
  4456. }
  4457. if ($data['status'] == 2 && !isset($data['deal'])) {
  4458. $this->sendMessage([
  4459. 'talk_type' => 801,
  4460. 'title' => $complaintInfo['title'],
  4461. 'content' => '审核通过',
  4462. 'messageType' => 6,
  4463. 'user_id' => $complaintInfo['user_id'],
  4464. ]);
  4465. $this->sendMessage([
  4466. 'talk_type' => 802,
  4467. 'title' => $complaintInfo['title'],
  4468. 'content' => '待处理',
  4469. 'messageType' => 6,
  4470. 'user_id' => $complaintInfo['re_user_ids'],
  4471. ]);
  4472. }
  4473. if ($data['status'] == 3 && !isset($data['deal'])) {
  4474. $this->sendMessage([
  4475. 'talk_type' => 801,
  4476. 'title' => $complaintInfo['title'],
  4477. 'content' => '审核拒绝',
  4478. 'messageType' => 6,
  4479. 'user_id' => $complaintInfo['user_id'],
  4480. ]);
  4481. }
  4482. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4483. $this->sendMessage([
  4484. 'talk_type' => 802,
  4485. 'title' => $complaintInfo['title'],
  4486. 'content' => '处理中',
  4487. 'messageType' => 6,
  4488. 'user_id' => $complaintInfo['re_user_ids'],
  4489. ]);
  4490. }
  4491. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4492. $this->sendMessage([
  4493. 'talk_type' => 802,
  4494. 'title' => $complaintInfo['title'],
  4495. 'content' => '不予处理',
  4496. 'messageType' => 6,
  4497. 'user_id' => $complaintInfo['re_user_ids'],
  4498. ]);
  4499. }
  4500. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4501. $this->sendMessage([
  4502. 'talk_type' => 802,
  4503. 'title' => $complaintInfo['title'],
  4504. 'content' => '已完结',
  4505. 'messageType' => 6,
  4506. 'user_id' => $complaintInfo['re_user_ids'],
  4507. ]);
  4508. }
  4509. $result = complaint::where('id', $data['id'])->update($data);
  4510. return Result::success($result);
  4511. }
  4512. public function updateGoodStatus(array $data): array
  4513. {
  4514. $user_id = $data['user_id'] ?? 0;
  4515. $type_id = $data['type_id'] ?? 0;
  4516. unset($data['user_id']);
  4517. unset($data['type_id']);
  4518. $goodInfo = Good::where('id', $data['id'])->first();
  4519. if ($data['status'] == 2) {
  4520. $this->sendMessage([
  4521. 'talk_type' => 201,
  4522. 'title' => $goodInfo['name'],
  4523. 'content' => '审核通过',
  4524. 'messageType' => 3,
  4525. 'user_id' => $goodInfo['user_id'],
  4526. ]);
  4527. }
  4528. if ($data['status'] == 3) {
  4529. $this->sendMessage([
  4530. 'talk_type' => 201,
  4531. 'title' => $goodInfo['name'],
  4532. 'content' => '审核拒绝',
  4533. 'messageType' => 3,
  4534. 'user_id' => $goodInfo['user_id'],
  4535. ]);
  4536. }
  4537. if ($data['status'] == 1) {
  4538. $this->sendMessage([
  4539. 'talk_type' => 200,
  4540. 'title' => $goodInfo['name'],
  4541. 'content' => '提交了审核',
  4542. 'messageType' => 3,
  4543. ]);
  4544. }
  4545. $result = Good::where('id', $data['id'])->update($data);
  4546. return Result::success($result);
  4547. }
  4548. public function updateJobHuntingStatus(array $data): array
  4549. {
  4550. $user_id = $data['user_id'] ?? 0;
  4551. $type_id = $data['type_id'] ?? 0;
  4552. unset($data['user_id']);
  4553. unset($data['type_id']);
  4554. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4555. if ($data['status'] == 2) {
  4556. $this->sendMessage([
  4557. 'talk_type' => 601,
  4558. 'title' => $jogHuntingInfo['name'],
  4559. 'content' => '审核通过',
  4560. 'messageType' => 11,
  4561. 'user_id' => $jogHuntingInfo['user_id'],
  4562. ]);
  4563. }
  4564. if ($data['status'] == 3) {
  4565. $this->sendMessage([
  4566. 'talk_type' => 601,
  4567. 'title' => $jogHuntingInfo['name'],
  4568. 'content' => '审核拒绝',
  4569. 'messageType' => 11,
  4570. 'user_id' => $jogHuntingInfo['user_id'],
  4571. ]);
  4572. }
  4573. if ($data['status'] == 1) {
  4574. $this->sendMessage([
  4575. 'talk_type' => 600,
  4576. 'title' => $jogHuntingInfo['name'],
  4577. 'content' => '提交了审核',
  4578. 'messageType' => 11,
  4579. ]);
  4580. }
  4581. $result = JobHunting::where('id', $data['id'])->update($data);
  4582. return Result::success($result);
  4583. }
  4584. public function updateNoticeStatus(array $data): array
  4585. {
  4586. $user_id = $data['user_id'] ?? 0;
  4587. $type_id = $data['type_id'] ?? 0;
  4588. unset($data['user_id']);
  4589. unset($data['type_id']);
  4590. //查询公告
  4591. $notice = Notice::where('id', $data['id'])->first();
  4592. if (empty($notice)) {
  4593. return Result::error("公告不存在", 0);
  4594. }
  4595. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4596. if ($data['status'] == 2 && $notice['is_group'] == 1 && $notice['status'] == 1 && empty($notice['group_id'])) {
  4597. //chat_group
  4598. $group_id = PublicData::uuid();
  4599. $groupData = [
  4600. 'id' => $group_id,
  4601. 'creator_id' => $notice['user_id'],
  4602. 'group_name' => $notice['group_name'] ?? '',
  4603. 'profile' => $notice['profile'] ?? 0,
  4604. ];
  4605. var_dump($groupData, '-----------------groupData-------');
  4606. $groupResult = ChatGroups::insertGetId($groupData);
  4607. var_dump($groupResult, '-----------------groupid-------');
  4608. $groupMemberData = [
  4609. 'id' => PublicData::uuid(),
  4610. 'user_id' => $notice['user_id'],
  4611. 'group_id' => $group_id,
  4612. 'leader' => 2,
  4613. ];
  4614. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4615. //$chat_ids 去除掉$data['user_id']
  4616. $chat_ids = json_decode($notice['re_user_ids'], true);
  4617. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4618. //插入群成员表
  4619. $groupMemberDataUser = [];
  4620. $chatData = [];
  4621. foreach ($chat_ids as $key => $value) {
  4622. $groupMemberDataUser[] = [
  4623. 'id' => PublicData::uuid(),
  4624. 'user_id' => $value,
  4625. 'group_id' => $group_id,
  4626. 'leader' => 1,
  4627. ];
  4628. $chatData[] = [
  4629. 'user_id' => $value,
  4630. 'msg_type' => 1,
  4631. 'receiver_id' => $group_id,
  4632. 'content' => '通过通知创建群聊',
  4633. 'group_receiver_id' => $notice['user_id'],
  4634. 'action' => 'recieved',
  4635. 'created_at' => date('Y-m-d H:i:s'),
  4636. ];
  4637. }
  4638. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4639. ChatGroupsMember::insert($groupMemberDataUser);
  4640. //插入一条管理员聊天记录
  4641. $chatData[] = [
  4642. 'user_id' => $notice['user_id'],
  4643. 'msg_type' => 1,
  4644. 'receiver_id' => $group_id,
  4645. 'content' => '通过通知创建群聊',
  4646. 'group_receiver_id' => $notice['user_id'],
  4647. 'action' => 'said',
  4648. 'created_at' => date('Y-m-d H:i:s'),
  4649. ];
  4650. var_dump($chatData, '-----------------chatData-------');
  4651. $chatResult = ChatRecords::insert($chatData);
  4652. //更新result的 group_id
  4653. $data['group_id'] = $group_id;
  4654. Notice::where(['id' => $data['id']])->update($data);
  4655. }
  4656. $result = Notice::where('id', $data['id'])->update($data);
  4657. $noticeInfo = Notice::where('id', $data['id'])->first();
  4658. if ($data['status'] == 2) {
  4659. $this->sendMessage([
  4660. 'talk_type' => 701,
  4661. 'title' => $noticeInfo['title'],
  4662. 'content' => '审核通过',
  4663. 'messageType' => 3,
  4664. 'user_id' => $noticeInfo['user_id'],
  4665. ]);
  4666. }
  4667. if ($data['status'] == 3) {
  4668. $this->sendMessage([
  4669. 'talk_type' => 701,
  4670. 'title' => $noticeInfo['title'],
  4671. 'content' => '审核拒绝',
  4672. 'messageType' => 3,
  4673. 'user_id' => $noticeInfo['user_id'],
  4674. ]);
  4675. }
  4676. if ($data['status'] == 1) {
  4677. $this->sendMessage([
  4678. 'talk_type' => 700,
  4679. 'title' => $noticeInfo['title'],
  4680. 'content' => '提交了审核',
  4681. 'messageType' => 3,
  4682. ]);
  4683. }
  4684. return Result::success($result);
  4685. }
  4686. public function getDUser(array $data): array
  4687. {
  4688. if (!empty($data['ids'])) {
  4689. $user = User::whereIn('id', $data['ids'])->getall();
  4690. if (empty($user)) {
  4691. return Result::error('无数据', 0);
  4692. }
  4693. return Result::success($user);
  4694. }
  4695. $where = [];
  4696. if (!empty($data['department_id'])) {
  4697. $where['department_id'] = $data['department_id'];
  4698. }
  4699. if (!empty($data['city_id'])) {
  4700. $where['city_id'] = $data['city_id'];
  4701. }
  4702. $result = User::where('type_id', 2)
  4703. ->where('status', 1)
  4704. ->where($where)
  4705. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4706. ->get();
  4707. if (empty($result)) {
  4708. return Result::error("查询失败", 0);
  4709. }
  4710. return Result::success($result);
  4711. }
  4712. /**
  4713. * 验证导航名称是否重复
  4714. * @return void
  4715. */
  4716. public function checkCategoryName(array $data): array
  4717. {
  4718. $result = Category::when($data, function ($query) use ($data) {
  4719. if (isset($data['name']) && $data['name']) {
  4720. $query->where("name", $data['name']);
  4721. }
  4722. if (isset($data['id']) && $data['id']) {
  4723. $query->where("id", "!=", $data['id']);
  4724. }
  4725. })->first();
  4726. if ($result) {
  4727. return Result::error("已存在");
  4728. } else {
  4729. return Result::success();
  4730. }
  4731. }
  4732. //20250226 产品列表
  4733. // 20250306 -------招聘--------fr
  4734. /*
  4735. * 招聘列表
  4736. * */
  4737. public function getJobRecruitingList(array $data): array
  4738. {
  4739. $where = [];
  4740. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4741. if ($data['checkout'] == 0) {
  4742. $job_status = [0, 2];
  4743. } else {
  4744. $job_status = [1];
  4745. }
  4746. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4747. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4748. }
  4749. $user = User::where('id', $data['user_id'])->first();
  4750. if (empty($user)) {
  4751. return Result::error("用户不存在", 0);
  4752. }
  4753. // 3:企业会员
  4754. if ($user['type_id'] == 3) {
  4755. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4756. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4757. }
  4758. // 如果 $where 为空,则不添加 where 条件
  4759. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4760. return $query->where($where);
  4761. })
  4762. ->whereIn('job_recruiting.status', $job_status)
  4763. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4764. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4765. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4766. ->orderBy("updated_at", "desc")
  4767. ->offset(($data['page'] - 1) * $data['page_size'])
  4768. ->limit($data['page_size'])
  4769. ->get()
  4770. ->all();
  4771. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4772. return $query->where($where);
  4773. })
  4774. ->whereIn('job_recruiting.status', $job_status)
  4775. ->count();
  4776. if (empty($result)) {
  4777. return Result::error("暂无招聘信息", 0);
  4778. }
  4779. return Result::success($result);
  4780. }
  4781. /*
  4782. * 招聘信息添加
  4783. * */
  4784. public function addJobRecruiting(array $data): array
  4785. {
  4786. // return Result::success($data);
  4787. $user = User::where('user.id', $data['user_id'])
  4788. ->where('user.status', 1)
  4789. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4790. ->select(
  4791. 'user.type_id',
  4792. 'user.mobile',
  4793. 'user.email',
  4794. 'user_info.business_name',
  4795. 'user_info.company_hy_id',
  4796. 'user_info.company_nature',
  4797. 'user_info.company_size',
  4798. 'user_info.introduction',
  4799. 'user_info.real_name',
  4800. 'user_info.company_url',
  4801. 'user_info.address_arr_id',
  4802. 'user_info.address'
  4803. )
  4804. ->first();
  4805. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4806. return Result::error("用户不存在", 0);
  4807. }
  4808. $web = Website::where('id', $data['website_id'])->first();
  4809. if (empty($web)) {
  4810. return Result::error("网站不存在", 0);
  4811. }
  4812. // return Result::success($user);
  4813. $data['action_id'] = $data['user_id'];
  4814. $data['user_type'] = $user['type_id'];
  4815. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4816. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4817. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4818. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4819. // 公司地址 管理员必填
  4820. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4821. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4822. // 管理员-企业相关信息
  4823. $company = [
  4824. // 'user_id' => $data['user_id']?? null,
  4825. 'business_name' => $data['business_name'] ?? null,
  4826. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4827. 'company_size' => $data['company_size'] ?? null,
  4828. 'company_nature' => $data['company_nature'] ?? null,
  4829. 'introduction' => $data['introduction'] ?? null,
  4830. 'real_name' => $data['real_name'] ?? null,
  4831. 'mobile' => $data['mobile'] ?? null,
  4832. 'company_url' => $data['company_url'] ?? null,
  4833. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4834. 'address' => $data['address'] ?? null,
  4835. 'email' => $data['email'] ?? null,
  4836. ];
  4837. //去掉相关企业信息
  4838. $job = array_diff_key($data, array_flip(array_keys($company)));
  4839. Db::beginTransaction();
  4840. try {
  4841. // 先添加职位相关信息
  4842. if ($user['type_id'] == 10000) {
  4843. $job['status'] = 1;
  4844. }
  4845. if (empty($data['experience']) || $data['experience'] == '') {
  4846. $job['experience'] = null;
  4847. } else {
  4848. $job['experience'] = $data['experience'];
  4849. }
  4850. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  4851. $this->sendMessage([
  4852. 'talk_type' => 500,
  4853. 'title' => $data['title'],
  4854. 'content' => '提交了审核',
  4855. 'messageType' => 10,
  4856. ]);
  4857. }
  4858. $jobId = JobRecruiting::insertGetId($job);
  4859. if (empty($jobId)) {
  4860. Db::rollBack();
  4861. return Result::error("添加失败");
  4862. }
  4863. // 添加公司信息
  4864. $company['user_id'] = $data['user_id'] ?? null;
  4865. $company['job_id'] = $jobId;
  4866. $company['user_type'] = $user['type_id'] ?? null;
  4867. $company['website_id'] = $data['website_id'] ?? null;
  4868. if ($user['type_id'] == 10000) {
  4869. // 管理员添加企业信息
  4870. // return Result::success($company);
  4871. $companyId = JobCompany::insertGetId($company);
  4872. if (empty($companyId)) {
  4873. Db::rollBack();
  4874. return Result::error("添加失败");
  4875. }
  4876. } else {
  4877. // 企业会员添加企业信息
  4878. $company = [
  4879. 'user_id' => $data['user_id'] ?? null,
  4880. 'business_name' => $user['business_name'] ?? null,
  4881. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4882. 'company_size' => $user['company_size'] ?? null,
  4883. 'company_nature' => $user['company_nature'] ?? null,
  4884. 'introduction' => $user['introduction'] ?? null,
  4885. 'real_name' => $user['real_name'] ?? null,
  4886. 'mobile' => $user['mobile'] ?? null,
  4887. 'company_url' => $user['company_url'] ?? null,
  4888. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4889. 'address' => $user['address'] ?? null,
  4890. 'email' => $user['email'] ?? null,
  4891. 'website_id' => $data['website_id'] ?? null,
  4892. 'user_type' => $user['type_id'] ?? null,
  4893. 'job_id' => $jobId,
  4894. ];
  4895. $companyId = JobCompany::insertGetId($company);
  4896. if (empty($companyId)) {
  4897. Db::rollBack();
  4898. return Result::error("添加失败");
  4899. }
  4900. // return Result::success($company);
  4901. }
  4902. Db::commit();
  4903. } catch (\Exception $e) {
  4904. Db::rollBack();
  4905. return Result::error($e->getMessage(), 0);
  4906. }
  4907. $result = [
  4908. 'job_id' => $jobId,
  4909. 'company_id' => $companyId,
  4910. ];
  4911. if (empty($result)) {
  4912. return Result::error("添加失败", 0);
  4913. }
  4914. return Result::success($result);
  4915. }
  4916. /*
  4917. * 获取招聘信息详情
  4918. * */
  4919. public function getJobRecruitingInfo(array $data): array
  4920. {
  4921. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4922. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4923. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4924. ->select(
  4925. 'job_recruiting.*',
  4926. 'website.website_name as website_name',
  4927. 'job_company.business_name',
  4928. 'job_company.company_hy_id',
  4929. 'job_company.company_size',
  4930. 'job_company.company_nature',
  4931. 'job_company.introduction',
  4932. 'job_company.real_name',
  4933. 'job_company.mobile',
  4934. 'job_company.company_url',
  4935. 'job_company.address_arr_id',
  4936. 'job_company.address',
  4937. 'job_company.email'
  4938. )
  4939. ->first();
  4940. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4941. if (!empty($cityId)) {
  4942. if (isset($cityId[1]) && $cityId[1] != null) {
  4943. $city = District::where('id', $cityId[1])->first(['name']);
  4944. } else {
  4945. $city = District::where('id', $cityId[0])->first(['name']);
  4946. }
  4947. $result['city'] = $city['name'] ?? '';
  4948. }
  4949. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4950. if (is_array($addressId) && !empty($addressId)) {
  4951. $address = District::whereIn('id', $addressId)
  4952. ->orderBy('level', 'asc')
  4953. ->get(['name'])
  4954. ->pluck('name')
  4955. ->implode('');
  4956. // $job->address_name = $address ?? '';
  4957. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4958. }
  4959. if (empty($result)) {
  4960. return Result::error("招聘信息不存在", 0);
  4961. }
  4962. // return Result::success($job);
  4963. return Result::success($result);
  4964. }
  4965. /*
  4966. * 修改招聘信息
  4967. * */
  4968. public function upJobRecruiting(array $data): array
  4969. {
  4970. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4971. // return Result::success($job);
  4972. if (empty($job)) {
  4973. return Result::error("招聘信息不存在", 0);
  4974. }
  4975. $user = User::where('id', $data['user_id'])->first();
  4976. // return Result::success($user);
  4977. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4978. return Result::error("用户不存在", 0);
  4979. }
  4980. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4981. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4982. }
  4983. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4984. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4985. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4986. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4987. // 公司地址 管理员必填
  4988. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4989. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4990. // 管理员-企业相关信息
  4991. $company = [
  4992. 'business_name' => $data['business_name'] ?? null,
  4993. 'company_hy_id' => $data['hy_id'] ?? null,
  4994. 'company_size' => $data['company_size'] ?? null,
  4995. 'company_nature' => $data['company_nature'] ?? null,
  4996. 'introduction' => $data['introduction'] ?? null,
  4997. 'real_name' => $data['real_name'] ?? null,
  4998. 'mobile' => $data['mobile'] ?? null,
  4999. 'company_url' => $data['company_url'] ?? null,
  5000. 'address_arr_id' => $data['address_arr_id'] ?? null,
  5001. 'address' => $data['address'] ?? null,
  5002. 'email' => $data['email'] ?? null,
  5003. ];
  5004. //去掉相关企业信息
  5005. $data = array_diff_key($data, array_flip(array_keys($company)));
  5006. $jobId = $data['id'];
  5007. $web = $data['website_id'];
  5008. $data['action_id'] = $data['user_id'];
  5009. unset($data['user_id']);
  5010. unset($data['user_type']);
  5011. unset($data['id']);
  5012. unset($data['website_id']);
  5013. // return Result::success($data);
  5014. Db::beginTransaction();
  5015. try {
  5016. // 管理员修改招聘信息
  5017. if ($user['type_id'] == 10000) {
  5018. $data['website_id'] = $web;
  5019. $company['website_id'] = $data['website_id'];
  5020. $data['status'] = 1;
  5021. } else {
  5022. $data['status'] = 0;
  5023. }
  5024. if (empty($data['experience']) || $data['experience'] == '') {
  5025. $job['experience'] = null;
  5026. } else {
  5027. $job['experience'] = $data['experience'];
  5028. }
  5029. // Db::rollBack();
  5030. // return Result::success($company);
  5031. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5032. $this->sendMessage([
  5033. 'talk_type' => 500,
  5034. 'title' => $data['title'],
  5035. 'content' => '提交了审核',
  5036. 'messageType' => 10,
  5037. ]);
  5038. }
  5039. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5040. if (empty($result['job'])) {
  5041. Db::rollBack();
  5042. return Result::error("修改招聘信息失败");
  5043. }
  5044. // 管理员修改企业相关信息
  5045. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5046. if (empty($result['company'])) {
  5047. Db::rollBack();
  5048. return Result::error("修改企业相关信息失败");
  5049. }
  5050. Db::commit();
  5051. // return Result::success($result);
  5052. } catch (\Exception $e) {
  5053. Db::rollBack();
  5054. return Result::error($e->getMessage(), 0);
  5055. }
  5056. return Result::success($result);
  5057. }
  5058. /*
  5059. * 招聘信息删除
  5060. * */
  5061. public function delJobRecruiting(array $data): array
  5062. {
  5063. $user = User::where('id', $data['user_id'])->first();
  5064. if (empty($user)) {
  5065. return Result::error("用户不存在", 0);
  5066. }
  5067. $job = JobRecruiting::where('id', $data['id'])->first();
  5068. if (empty($job)) {
  5069. return Result::error("招聘信息不存在", 0);
  5070. }
  5071. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5072. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5073. }
  5074. Db::beginTransaction();
  5075. try {
  5076. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5077. if (empty($result['job'])) {
  5078. Db::rollBack();
  5079. return Result::error("删除招聘信息失败");
  5080. }
  5081. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5082. if (empty($result['company'])) {
  5083. Db::rollBack();
  5084. return Result::error("删除企业相关信息失败");
  5085. }
  5086. Db::commit();
  5087. } catch (\Exception $e) {
  5088. Db::rollBack();
  5089. return Result::error($e->getMessage(), 0);
  5090. }
  5091. return Result::success($result);
  5092. }
  5093. /*
  5094. * 获取公司信息
  5095. * */
  5096. public function getJobCompany(array $data): array
  5097. {
  5098. $user = User::where('user.id', $data['user_id'])
  5099. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5100. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5101. ->first();
  5102. // return Result::success($user);
  5103. if (empty($user)) {
  5104. return Result::error("用户不存在", 0);
  5105. }
  5106. if ($user['type_id'] == 3) {
  5107. $result = [
  5108. // 'id' => 0,
  5109. 'user_id' => $data['user_id'],
  5110. 'website_id' => $data['website_id'],
  5111. 'business_name' => $user['business_name'], // 企业名称
  5112. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5113. 'company_nature' => $user['company_nature'], // 公司性质
  5114. 'company_size' => $user['company_size'], // 公司规模
  5115. 'introduction' => $user['introduction'], // 公司简介
  5116. 'real_name' => $user['real_name'], // 企业联系人
  5117. 'mobile' => $user['mobile'], // 企业联系电话
  5118. 'company_url' => $user['company_url'], // 企业网址
  5119. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5120. 'address' => $user['address'], // 企业地址
  5121. 'email' => $user['email'], // 企业邮箱
  5122. ];
  5123. } else {
  5124. return Result::error("用户类型错误", 0);
  5125. }
  5126. if (empty($result)) {
  5127. return Result::error("公司信息不存在", 0);
  5128. }
  5129. return Result::success($result);
  5130. }
  5131. /*
  5132. * 修改公司信息
  5133. * */
  5134. public function upJobCompany(array $data): array
  5135. {
  5136. // return Result::success($data);
  5137. $user = User::where('user.id', $data['user_id'])
  5138. ->where('user.status', 1)
  5139. ->select('user.user_name', 'user.type_id')
  5140. ->first();
  5141. if (empty($user)) {
  5142. return Result::error("用户不存在", 0);
  5143. }
  5144. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5145. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5146. $company = [
  5147. 'business_name' => $data['business_name'], // 企业名称
  5148. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5149. 'company_nature' => $data['company_nature'], // 公司性质
  5150. 'company_size' => $data['company_size'], // 公司规模
  5151. 'introduction' => $data['introduction'], // 公司简介
  5152. // 'real_name' => $data['real_name'], // 企业联系人
  5153. 'company_url' => $data['company_url'], // 企业网址
  5154. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5155. 'address' => $data['address'], // 企业详细地址
  5156. // 'email' => $data['email'], // 企业邮箱
  5157. ];
  5158. if ($user['type_id'] == 3) {
  5159. Db::beginTransaction();
  5160. try {
  5161. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5162. 'business_name' => $data['business_name'], // 企业名称
  5163. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5164. 'company_nature' => $data['company_nature'], // 公司性质
  5165. 'company_size' => $data['company_size'], // 公司规模
  5166. 'introduction' => $data['introduction'], // 公司简介
  5167. // 'real_name' => $data['real_name'], // 企业联系人
  5168. 'company_url' => $data['company_url'], // 企业网址
  5169. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5170. 'address' => $data['address'], // 企业详细地址
  5171. ]);
  5172. if (empty($result['userinfo'])) {
  5173. Db::rollBack();
  5174. return Result::error('修改企业会员信息失败!');
  5175. }
  5176. $result['user'] = User::where('id', $data['user_id'])->update([
  5177. 'email' => $data['email'], // 企业邮箱
  5178. ]);
  5179. if (empty($result['user'])) {
  5180. Db::rollBack();
  5181. return Result::error('修改个人中心信息失败!');
  5182. }
  5183. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5184. if (!empty($job_company)) {
  5185. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5186. if (empty($result['job_company'])) {
  5187. Db::rollBack();
  5188. return Result::error('修改企业会员信息失败!');
  5189. }
  5190. }
  5191. Db::commit();
  5192. return Result::success($result);
  5193. } catch (\Exception $e) {
  5194. Db::rollBack();
  5195. return Result::error($e->getMessage(), 0);
  5196. }
  5197. } else {
  5198. return Result::error("用户类型错误", 0);
  5199. }
  5200. }
  5201. /*
  5202. * 获取省-市
  5203. * */
  5204. public function getJobRecruitingArea(array $data): array
  5205. {
  5206. if (isset($data['pid']) && $data['pid'] != null) {
  5207. $result = District::where('pid', $data['pid'])->get()->all();
  5208. } else {
  5209. $result = District::where('level', 1)->get()->all();
  5210. }
  5211. if (empty($result)) {
  5212. return Result::error("暂无此省市", 0);
  5213. }
  5214. return Result::success($result);
  5215. }
  5216. /*
  5217. * 获取行业分类
  5218. * */
  5219. public function getIndustry(array $data): array
  5220. {
  5221. $result = JobIndustry::get()->all();
  5222. if (empty($result)) {
  5223. return Result::error("暂无行业分类", 0);
  5224. }
  5225. return Result::success($result);
  5226. }
  5227. /*
  5228. * 获取职位
  5229. * */
  5230. public function getPositionList(array $data): array
  5231. {
  5232. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5233. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5234. } else {
  5235. $result = JobPosition::where('zwpid', 0)->get()->all();
  5236. }
  5237. if (empty($result)) {
  5238. return Result::error("暂无此职位", 0);
  5239. }
  5240. return Result::success($result);
  5241. }
  5242. /*
  5243. * 获取工作性质-菜单
  5244. * */
  5245. public function getJobNature(array $data): array
  5246. {
  5247. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5248. if (empty($result)) {
  5249. return Result::error("暂无工作性质", 0);
  5250. }
  5251. return Result::success($result);
  5252. }
  5253. /*
  5254. * 获取工作经验-菜单
  5255. * */
  5256. public function getExperience(array $data): array
  5257. {
  5258. $result = JobEnum::where('egroup', 'years')->get()->all();
  5259. if (empty($result)) {
  5260. return Result::error("暂无工作经验", 0);
  5261. }
  5262. return Result::success($result);
  5263. }
  5264. /*
  5265. * 获取学历-菜单
  5266. * */
  5267. public function getEducation(array $data): array
  5268. {
  5269. $result = JobEnum::where('egroup', 'education')->get()->all();
  5270. if (empty($result)) {
  5271. return Result::error("暂无学历", 0);
  5272. }
  5273. return Result::success($result);
  5274. }
  5275. /*
  5276. * 获取薪资-菜单
  5277. * */
  5278. public function getSalary(array $data): array
  5279. {
  5280. $result = JobEnum::where('egroup', 'income')->get()->all();
  5281. if (empty($result)) {
  5282. return Result::error("暂无薪资", 0);
  5283. }
  5284. return Result::success($result);
  5285. }
  5286. /*
  5287. * 获取语言-菜单
  5288. * */
  5289. public function getLanguage(array $data): array
  5290. {
  5291. $result = JobEnum::where('egroup', 'language')->get()->all();
  5292. if (empty($result)) {
  5293. return Result::error("暂无语言", 0);
  5294. }
  5295. return Result::success($result);
  5296. }
  5297. /*
  5298. * 获取掌握程度-菜单
  5299. * */
  5300. public function getLevel(array $data): array
  5301. {
  5302. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5303. if (empty($result)) {
  5304. return Result::error("暂无工作性质", 0);
  5305. }
  5306. return Result::success($result);
  5307. }
  5308. // 公司信息
  5309. /*
  5310. * 获取公司性质-菜单
  5311. * */
  5312. public function getCompanyNature(array $data): array
  5313. {
  5314. $result = JobNature::get()->all();
  5315. if (empty($result)) {
  5316. return Result::error("暂无公司性质", 0);
  5317. }
  5318. return Result::success($result);
  5319. }
  5320. /*
  5321. * 获取公司规模-菜单
  5322. * */
  5323. public function getCompanySize(array $data): array
  5324. {
  5325. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5326. if (empty($result)) {
  5327. return Result::error("暂无公司规模", 0);
  5328. }
  5329. return Result::success($result);
  5330. }
  5331. /*
  5332. * 招聘信息审核
  5333. * */
  5334. public function checkJobRecruiting(array $data): array
  5335. {
  5336. $user = User::where('id', $data['user_id'])->first();
  5337. if (empty($user)) {
  5338. return Result::error("用户不存在", 0);
  5339. }
  5340. $job = JobRecruiting::where('id', $data['id'])->first();
  5341. if (empty($job)) {
  5342. return Result::error("招聘信息不存在", 0);
  5343. }
  5344. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5345. if ($user['type_id'] != 10000) {
  5346. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5347. }
  5348. // 驳回原因
  5349. if ($data['status'] == 2) {
  5350. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5351. }
  5352. $data['action_id'] = $data['user_id'];
  5353. unset($data['user_id']);
  5354. if ($data['status'] == 1) {
  5355. $this->sendMessage([
  5356. 'talk_type' => 501,
  5357. 'title' => $job['title'],
  5358. 'content' => '审核通过',
  5359. 'messageType' => 10,
  5360. 'user_id' => $job['user_id'],
  5361. ]);
  5362. }
  5363. if ($data['status'] == 2) {
  5364. $this->sendMessage([
  5365. 'talk_type' => 501,
  5366. 'title' => $job['title'],
  5367. 'content' => '审核拒绝',
  5368. 'messageType' => 10,
  5369. 'user_id' => $job['user_id'],
  5370. ]);
  5371. }
  5372. if ($data['status'] == 0) {
  5373. $this->sendMessage([
  5374. 'talk_type' => 500,
  5375. 'title' => $job['title'],
  5376. 'content' => '提交了审核',
  5377. 'messageType' => 10,
  5378. ]);
  5379. }
  5380. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5381. if (empty($result)) {
  5382. return Result::error("审核失败", 0);
  5383. }
  5384. return Result::success($result);
  5385. }
  5386. public function myApplyList(array $data): array
  5387. {
  5388. var_dump($data, '------参数');
  5389. $user = User::where('id', $data['user_id'])->first();
  5390. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5391. return Result::error("用户不存在", 0);
  5392. }
  5393. // 1:个人会员 职场机会
  5394. if ($user['type_id'] == 1) {
  5395. $where['user_id'] = $user['id'];
  5396. }
  5397. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5398. $query->where('user_id', $user['id']);
  5399. })
  5400. ->pluck('recruit_id');
  5401. $where = [];
  5402. if (isset($data['salary']) && $data['salary'] != null) {
  5403. $where['job_recruiting.salary'] = $data['salary'];
  5404. }
  5405. if (isset($data['experience']) && $data['experience'] != null) {
  5406. $where['job_recruiting.experience'] = $data['experience'];
  5407. }
  5408. if (isset($data['business_name']) && $data['business_name'] != null) {
  5409. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5410. }
  5411. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5412. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5413. ->where($where);
  5414. // ->count();
  5415. $count = $query->count();
  5416. $query = clone $query;
  5417. $job = $query
  5418. ->leftJoin('job_enum as income_enum', function ($join) {
  5419. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5420. ->where('income_enum.egroup', 'income');
  5421. })
  5422. ->leftJoin('job_enum as years_enum', function ($join) {
  5423. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5424. ->where('years_enum.egroup', 'years');
  5425. })
  5426. // ->where($where)
  5427. ->orderBy('job_recruiting.updated_at', 'desc')
  5428. ->select(
  5429. 'job_recruiting.id',
  5430. 'job_recruiting.title',
  5431. 'job_company.business_name',
  5432. 'income_enum.evalue as salary_evalue',
  5433. 'income_enum.ename as salary_ename',
  5434. 'years_enum.evalue as experience_evalue',
  5435. 'years_enum.ename as experience_ename',
  5436. 'job_recruiting.updated_at'
  5437. )
  5438. ->offset(($data['page'] - 1) * $data['pageSize'])
  5439. ->limit($data['pageSize'])
  5440. ->get()
  5441. ->all();
  5442. if (empty($job)) {
  5443. return Result::error("暂无招聘信息", 0);
  5444. }
  5445. $result = [
  5446. 'row' => $job,
  5447. 'count' => $count,
  5448. ];
  5449. return Result::success($result);
  5450. }
  5451. public function readJobApply(array $data): array
  5452. {
  5453. $result = JobApply::where('id', $data['id'])->first();
  5454. if (empty($result)) {
  5455. return Result::error("查询失败", 0);
  5456. }
  5457. $result = JobApply::where('id', $data['id'])->update([
  5458. 'status' => 2,
  5459. ]);
  5460. return Result::success($result);
  5461. }
  5462. /*
  5463. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5464. * */
  5465. public function getRecruitingList(array $data): array
  5466. {
  5467. $user = User::where('id', $data['user_id'])->first();
  5468. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5469. return Result::error("用户不存在", 0);
  5470. }
  5471. // 1:个人会员 职场机会
  5472. if ($user['type_id'] == 1) {
  5473. $where['user_id'] = $user['id'];
  5474. }
  5475. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5476. $query->where('receiver_id', $user['id']);
  5477. })
  5478. ->pluck('recruit_id');
  5479. // return Result::success($recruitingId);
  5480. $where = [];
  5481. if (isset($data['salary']) && $data['salary'] != null) {
  5482. $where['job_recruiting.salary'] = $data['salary'];
  5483. }
  5484. if (isset($data['experience']) && $data['experience'] != null) {
  5485. $where['job_recruiting.experience'] = $data['experience'];
  5486. }
  5487. if (isset($data['business_name']) && $data['business_name'] != null) {
  5488. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5489. }
  5490. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5491. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5492. ->where($where);
  5493. // ->count();
  5494. $count = $query->count();
  5495. $query = clone $query;
  5496. $job = $query
  5497. ->leftJoin('job_enum as income_enum', function ($join) {
  5498. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5499. ->where('income_enum.egroup', 'income');
  5500. })
  5501. ->leftJoin('job_enum as years_enum', function ($join) {
  5502. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5503. ->where('years_enum.egroup', 'years');
  5504. })
  5505. // ->where($where)
  5506. ->orderBy('job_recruiting.updated_at', 'desc')
  5507. ->select(
  5508. 'job_recruiting.id',
  5509. 'job_recruiting.title',
  5510. 'job_company.business_name',
  5511. 'income_enum.evalue as salary_evalue',
  5512. 'income_enum.ename as salary_ename',
  5513. 'years_enum.evalue as experience_evalue',
  5514. 'years_enum.ename as experience_ename',
  5515. 'job_recruiting.updated_at'
  5516. )
  5517. ->offset(($data['page'] - 1) * $data['pageSize'])
  5518. ->limit($data['pageSize'])
  5519. ->get()
  5520. ->all();
  5521. if (empty($job)) {
  5522. return Result::error("暂无招聘信息", 0);
  5523. }
  5524. $result = [
  5525. 'row' => $job,
  5526. 'count' => $count,
  5527. ];
  5528. return Result::success($result);
  5529. }
  5530. /*
  5531. * 获取企业会员-招聘信息列表
  5532. * */
  5533. public function getRecruitingInfo(array $data): array
  5534. {
  5535. $user = User::where('id', $data['user_id'])->first();
  5536. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5537. return Result::error("用户不存在", 0);
  5538. }
  5539. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5540. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5541. ->select(
  5542. 'job_recruiting.*',
  5543. 'job_company.business_name',
  5544. 'job_company.company_hy_id',
  5545. 'job_company.company_size',
  5546. 'job_company.company_nature',
  5547. 'job_company.introduction',
  5548. 'job_company.real_name',
  5549. 'job_company.mobile',
  5550. 'job_company.company_url',
  5551. 'job_company.address_arr_id',
  5552. 'job_company.address',
  5553. 'job_company.email'
  5554. )
  5555. ->get();
  5556. if (empty($recruiting)) {
  5557. return Result::error("暂无招聘信息", 0);
  5558. }
  5559. return Result::success($recruiting);
  5560. }
  5561. /*
  5562. * 获取企业会员-我的沟通
  5563. * */
  5564. public function getJobResumeList(array $data): array
  5565. {
  5566. $user = User::where('id', $data['user_id'])->first();
  5567. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5568. return Result::error("用户不存在", 0);
  5569. }
  5570. $where = [];
  5571. if (isset($data['salary']) && $data['salary'] != null) {
  5572. $where['job_hunting.salary'] = $data['salary'];
  5573. }
  5574. if (isset($data['user_name']) && $data['user_name'] != null) {
  5575. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5576. }
  5577. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5578. $query->where('job_resume.user_id', $user['id']);
  5579. })
  5580. ->when(!empty($where), function ($query) use ($where) {
  5581. $query->where($where);
  5582. })
  5583. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5584. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5585. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5586. ->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');
  5587. $count = $job->count();
  5588. if ($count == 0) {
  5589. return Result::error("暂无沟通记录", 0);
  5590. }
  5591. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5592. ->offset(($data['page'] - 1) * $data['pageSize'])
  5593. ->limit($data['pageSize'])
  5594. ->get();
  5595. if (empty($jobs)) {
  5596. return Result::error("暂无沟通记录", 0);
  5597. }
  5598. $result['row'] = $this->processJob($jobs, '');
  5599. $result['count'] = $count;
  5600. return Result::success($result);
  5601. }
  5602. public function readJobResume(array $data): array
  5603. {
  5604. $result = JobResume::where('id', $data['id'])->first();
  5605. if (empty($result)) {
  5606. return Result::error("查询失败", 0);
  5607. }
  5608. $result = JobResume::where('id', $data['id'])->update([
  5609. 'status' => 2,
  5610. ]);
  5611. return Result::success($result);
  5612. }
  5613. // 20250306 招聘
  5614. //20250422 书刊音像
  5615. public function addBook(array $data): array
  5616. {
  5617. $user_id = $data['user_id'] ?? 0;
  5618. $type_id = $data['type_id'] ?? 0;
  5619. // $website_id = $data['website_id'] ?? 0;
  5620. // unset($data['user_id']);
  5621. unset($data['type_id']);
  5622. // unset($data['website_id']);
  5623. //处理数组
  5624. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5625. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5626. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5627. if ($data['img_url'] == '') {
  5628. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5629. preg_match_all($reg, $data['detail'], $matches);
  5630. if (isset($matches[1][0])) {
  5631. //截取varchar240
  5632. $data['img_url'] = substr($matches[1][0], 0, 240);
  5633. }
  5634. }
  5635. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5636. //提取标题+内容中的关键词
  5637. $data['keyword'] = $data['title'];
  5638. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5639. Jieba::init(); // 初始化 jieba-php
  5640. Finalseg::init();
  5641. $segList = Jieba::cut($data['keyword']);
  5642. $segList1 = array_slice($segList, 0, 8);
  5643. $data['keyword'] = implode(',', $segList1);
  5644. }
  5645. if ($data['description'] == '') {
  5646. //提取内容中的描述
  5647. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5648. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5649. }
  5650. var_dump($data, '--');
  5651. if ($data['status'] == 1) {
  5652. $this->sendMessage([
  5653. 'talk_type' => 400,
  5654. 'title' => $data['title'],
  5655. 'content' => '提交了审核',
  5656. 'messageType' => 7,
  5657. ]);
  5658. }
  5659. $result = Book::insertGetId($data);
  5660. if (empty($result)) {
  5661. return Result::error("添加失败", 0);
  5662. }
  5663. return Result::success($result);
  5664. }
  5665. public function getBookList(array $data): array
  5666. {
  5667. $where = [];
  5668. if (!empty($data["title"])) {
  5669. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5670. }
  5671. if (!empty($data['website_name'])) {
  5672. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5673. }
  5674. if (!empty($data['status'])) {
  5675. $where[] = ['book.status', '=', $data['status']];
  5676. }
  5677. $user_id = $data['user_id'];
  5678. $type_id = $data['type_id'];
  5679. // $type_id = 4;
  5680. var_dump($type_id, '------1--------');
  5681. if ($type_id != 10000) {
  5682. $where[] = ['book.user_id', '=', $user_id];
  5683. }
  5684. var_dump(!empty($data['status1']), '=-===1');
  5685. $result = Book::where($where)
  5686. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5687. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5688. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5689. ->when(isset($data['status1']), function ($query) use ($data) {
  5690. $query->whereIn('book.status', [1, 3]);
  5691. })
  5692. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5693. ->orderBy("updated_at", "desc")
  5694. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5695. if (empty($result)) {
  5696. return Result::error("暂无数据", 0);
  5697. }
  5698. // 取出数据
  5699. $rows = $result->items();
  5700. $count = $result->total();
  5701. $responseData = [
  5702. 'rows' => $rows,
  5703. 'count' => $count,
  5704. ];
  5705. return Result::success($responseData);
  5706. }
  5707. public function deleteBook(array $data): array
  5708. {
  5709. $result = Book::where('id', $data['id'])->delete();
  5710. if (empty($result)) {
  5711. return Result::error("删除失败", 0);
  5712. }
  5713. return Result::success($result);
  5714. }
  5715. public function updateBook(array $data): array
  5716. {
  5717. // $user_id = $data['user_id'] ?? 0;
  5718. $type_id = $data['type_id'] ?? 0;
  5719. // $website_id = $data['website_id'] ?? 0;
  5720. unset($data['user_id']);
  5721. unset($data['type_id']);
  5722. // unset($data['website_id']);
  5723. //处理数组
  5724. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5725. if ($data['img_url'] == '') {
  5726. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5727. preg_match_all($reg, $data['detail'], $matches);
  5728. if (isset($matches[1][0])) {
  5729. //截取varchar240
  5730. $data['img_url'] = substr($matches[1][0], 0, 240);
  5731. }
  5732. }
  5733. if ($data['keyword'] == '') {
  5734. //提取标题+内容中的关键词
  5735. $data['keyword'] = $data['title'];
  5736. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5737. Jieba::init(); // 初始化 jieba-php
  5738. Finalseg::init();
  5739. $segList = Jieba::cut($data['keyword']);
  5740. $segList1 = array_slice($segList, 0, 8);
  5741. $data['keyword'] = implode(',', $segList1);
  5742. }
  5743. if ($data['description'] == '') {
  5744. //提取内容中的描述
  5745. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5746. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5747. }
  5748. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5749. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5750. if ($data['status'] == 1) {
  5751. $this->sendMessage([
  5752. 'talk_type' => 400,
  5753. 'title' => $data['title'],
  5754. 'content' => '提交了审核',
  5755. 'messageType' => 7,
  5756. ]);
  5757. }
  5758. $result = Book::where("id", $data["id"])->update($data);
  5759. if (empty($result)) {
  5760. return Result::error("更新失败", 0);
  5761. }
  5762. return Result::success($result);
  5763. }
  5764. public function getBookInfo(array $data): array
  5765. {
  5766. $result = Book::where("id", $data["id"])->first();
  5767. if (empty($result)) {
  5768. return Result::error("获取失败", 0);
  5769. }
  5770. return Result::success($result);
  5771. }
  5772. public function updateBookStatus(array $data): array
  5773. {
  5774. //审核
  5775. unset($data['user_id']);
  5776. $bookInfo = Book::where("id", $data["id"])->first();
  5777. var_dump($bookInfo, '----');
  5778. if ($data['status'] == 2) {
  5779. $this->sendMessage([
  5780. 'talk_type' => 401,
  5781. 'title' => $bookInfo['title'],
  5782. 'content' => '审核通过',
  5783. 'messageType' => 7,
  5784. 'user_id' => $bookInfo['user_id'],
  5785. ]);
  5786. }
  5787. if ($data['status'] == 3) {
  5788. $this->sendMessage([
  5789. 'talk_type' => 401,
  5790. 'title' => $bookInfo['title'],
  5791. 'content' => '审核拒绝',
  5792. 'messageType' => 7,
  5793. 'user_id' => $bookInfo['user_id'],
  5794. ]);
  5795. }
  5796. if ($data['status'] == 1) {
  5797. $this->sendMessage([
  5798. 'talk_type' => 400,
  5799. 'title' => $bookInfo['title'],
  5800. 'content' => '提交了审核',
  5801. 'messageType' => 7,
  5802. // 'user_id'=>$bookInfo['user_id'],
  5803. ]);
  5804. }
  5805. $result = Book::where("id", $data["id"])->update($data);
  5806. if (empty($result)) {
  5807. return Result::error("更新失败", 0);
  5808. }
  5809. return Result::success($result);
  5810. }
  5811. //20250422 书刊音像
  5812. /**
  5813. * 贴身宝贝
  5814. * @param array $data
  5815. * @return array
  5816. */
  5817. public function getWebsiteTsbb(array $data): array
  5818. {
  5819. $month = $data['month'] ?? date('m');
  5820. $day = $data['day'] ?? date('d');
  5821. // 使用缓存键
  5822. $cacheKey = "tsbb_data_{$month}_{$day}";
  5823. // 尝试从缓存获取数据
  5824. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5825. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5826. if ($cachedData = $cache->get($cacheKey)) {
  5827. return Result::success(unserialize($cachedData));
  5828. }
  5829. //查询老黄历
  5830. try {
  5831. $date = date('Y-m-d');
  5832. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5833. // 使用 curl 替代 file_get_contents
  5834. $ch = curl_init();
  5835. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5836. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5837. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5838. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5839. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5840. 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');
  5841. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5842. 'Accept: application/json',
  5843. 'Content-Type: application/json',
  5844. 'Referer: https://www.36jxs.com/'
  5845. ]);
  5846. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5847. curl_setopt($ch, CURLOPT_ENCODING, '');
  5848. $almanacResponse = curl_exec($ch);
  5849. var_dump("====:", $almanacResponse);
  5850. if (curl_errno($ch)) {
  5851. var_dump('Curl error:', curl_error($ch));
  5852. throw new \Exception('Curl error: ' . curl_error($ch));
  5853. }
  5854. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5855. curl_close($ch);
  5856. if ($almanacResponse === false) {
  5857. throw new \Exception('Failed to fetch almanac data');
  5858. }
  5859. $almanacData = json_decode($almanacResponse, true);
  5860. if (json_last_error() !== JSON_ERROR_NONE) {
  5861. throw new \Exception('Failed to parse almanac data');
  5862. }
  5863. $almanacInfo = $almanacData['data'] ?? [];
  5864. } catch (\Exception $e) {
  5865. var_dump('Exception:', $e->getMessage());
  5866. $almanacInfo = [];
  5867. }
  5868. // 获取历史上的今天数据
  5869. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5870. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5871. ->orderBy('year', 'asc')
  5872. ->select("title", "id", "year", DB::raw('1 as type'))
  5873. ->limit(16)
  5874. ->get();
  5875. // 获取节日数据 - 从今天开始获取未来4条
  5876. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5877. ->orderBy('showtime', 'asc')
  5878. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5879. ->limit(16)
  5880. ->get();
  5881. //说文解字
  5882. $chartacterList = Character::orderBy('updated_at', 'desc')
  5883. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5884. ->limit(6)
  5885. ->get();
  5886. //谜语沙龙
  5887. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5888. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5889. ->limit(4)
  5890. ->get();
  5891. //成语欣赏
  5892. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5893. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5894. ->limit(32)
  5895. ->get();
  5896. //名联赏析
  5897. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5898. ->select("id", "first", "second", DB::raw('6 as type'))
  5899. ->limit(6)
  5900. ->get();
  5901. // 获取分类文章数据
  5902. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5903. ->pluck('category_id')
  5904. ->toArray();
  5905. $articlesList = [];
  5906. foreach ($categoryIds as $catid) {
  5907. // 先查有图片的
  5908. $withImg = DB::table('article')
  5909. ->where('status', 1)
  5910. ->where('catid', $catid)
  5911. ->whereNotNull('imgurl')
  5912. ->where('imgurl', '!=', '')
  5913. ->orderBy('updated_at', 'desc')
  5914. ->limit(6)
  5915. ->get();
  5916. $count = $withImg->count();
  5917. if ($count < 6) {
  5918. // 不足6条再查无图片的补足
  5919. $withoutImg = DB::table('article')
  5920. ->where('status', 1)
  5921. ->where('catid', $catid)
  5922. ->where(function ($q) {
  5923. $q->whereNull('imgurl')->orWhere('imgurl', '');
  5924. })
  5925. ->orderBy('updated_at', 'desc')
  5926. ->limit(6 - $count)
  5927. ->get();
  5928. $articles = $withImg->concat($withoutImg);
  5929. } else {
  5930. $articles = $withImg;
  5931. }
  5932. // 组装
  5933. $category = \App\Model\Category::find($catid);
  5934. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  5935. $articlesList[] = [
  5936. 'category_name' => $category ? $category->name : '',
  5937. 'catid' => $catid,
  5938. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  5939. 'type' => 100,
  5940. 'list' => $articles->map(function ($item) {
  5941. return [
  5942. 'id' => $item->id,
  5943. 'title' => $item->title,
  5944. 'imgurl' => $item->imgurl,
  5945. 'created_at' => $item->created_at
  5946. ];
  5947. })->values()
  5948. ];
  5949. }
  5950. $result = [
  5951. 'almanac' => $almanacInfo,
  5952. 'historyTodayList' => [
  5953. 'category_name' => '历史上的今天',
  5954. 'list' => $historyTodayList,
  5955. 'type' => 1
  5956. ],
  5957. 'festivalList' => [
  5958. 'category_name' => '节日预告',
  5959. 'list' => $festivalList,
  5960. 'type' => 2
  5961. ],
  5962. 'chartacterList' => [
  5963. 'category_name' => '说文解字',
  5964. 'list' => $chartacterList,
  5965. 'type' => 3
  5966. ],
  5967. 'coupletList' => [
  5968. 'category_name' => '名联赏析',
  5969. 'list' => $coupletList,
  5970. 'type' => 6
  5971. ],
  5972. 'riddletList' => [
  5973. 'category_name' => '谜语沙龙',
  5974. 'list' => $riddletList,
  5975. 'type' => 4
  5976. ],
  5977. 'idiomList' => [
  5978. 'category_name' => '成语欣赏',
  5979. 'list' => $idiomList,
  5980. 'type' => 5
  5981. ],
  5982. 'articlesList' => $articlesList
  5983. ];
  5984. // 缓存结果,设置1小时过期
  5985. $cache->set($cacheKey, serialize($result), 3600);
  5986. return Result::success($result);
  5987. }
  5988. /**
  5989. * 获取资讯列表
  5990. */
  5991. public function getWebsiteTsbbList(array $data): array
  5992. {
  5993. $page = $data['page'] ?? 1;
  5994. $pageSize = $data['pageSize'] ?? 10;
  5995. // 如果没有传入月份和日期,则使用今天的日期
  5996. $month = $data['month'] ?? date('m');
  5997. $day = $data['day'] ?? date('d');
  5998. $total = 0;
  5999. $result = [];
  6000. $data['type'] = intval($data['type']);
  6001. var_dump("接收参数:", $data);
  6002. switch ($data['type']) {
  6003. case 1:
  6004. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6005. // 当前月份之后的数据
  6006. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6007. // 或者当前月份且日期大于等于当前日期的数据
  6008. ->orWhere(function ($q) use ($month, $day) {
  6009. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6010. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6011. });
  6012. })
  6013. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6014. $total = $query->count();
  6015. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6016. ->offset(($page - 1) * $pageSize)
  6017. ->limit($pageSize)
  6018. ->get();
  6019. break;
  6020. case 2:
  6021. $query = Festival::where(function ($q) use ($month, $day) {
  6022. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6023. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6024. ->orWhere(function ($q) use ($month, $day) {
  6025. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6026. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6027. });
  6028. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6029. $total = $query->count();
  6030. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6031. ->offset(($page - 1) * $pageSize)
  6032. ->limit($pageSize)
  6033. ->get();
  6034. break;
  6035. case 3:
  6036. $query = Character::orderBy("updated_at", "desc");
  6037. $total = $query->count();
  6038. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6039. ->offset(($page - 1) * $pageSize)
  6040. ->limit($pageSize)
  6041. ->get();
  6042. break;
  6043. case 4:
  6044. $query = Riddle::orderBy("updated_at", "desc");
  6045. $total = $query->count();
  6046. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6047. ->offset(($page - 1) * $pageSize)
  6048. ->limit($pageSize)
  6049. ->get();
  6050. break;
  6051. case 5:
  6052. $query = Idiom::orderBy("updated_at", "desc");
  6053. $total = $query->count();
  6054. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6055. ->offset(($page - 1) * $pageSize)
  6056. ->limit($pageSize)
  6057. ->get();
  6058. break;
  6059. case 6:
  6060. $query = Couplet::orderBy("updated_at", "desc");
  6061. $total = $query->count();
  6062. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6063. ->offset(($page - 1) * $pageSize)
  6064. ->limit($pageSize)
  6065. ->get();
  6066. break;
  6067. default:
  6068. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6069. $total = $query->count();
  6070. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6071. ->offset(($page - 1) * $pageSize)
  6072. ->limit($pageSize)
  6073. ->get();
  6074. }
  6075. return Result::success([
  6076. 'list' => $result,
  6077. 'total' => $total,
  6078. 'page' => (int)$page,
  6079. 'pageSize' => (int)$pageSize,
  6080. 'month' => $month,
  6081. 'day' => $day
  6082. ]);
  6083. }
  6084. /**
  6085. * 1:历史上的今天
  6086. * 2:节日
  6087. * 3:文章
  6088. *
  6089. * 资讯详情信息
  6090. */
  6091. public function getWebsiteTsbbDetail(array $data): array
  6092. {
  6093. $data['type'] = intval($data['type']);
  6094. switch ($data['type']) {
  6095. case 1:
  6096. $result = HistoryToday::where("id", $data['id'])->first();
  6097. break;
  6098. case 2:
  6099. $result = Festival::where("id", $data['id'])->first();
  6100. break;
  6101. case 3:
  6102. $result = Character::where("id", $data['id'])->first();
  6103. break;
  6104. case 4:
  6105. $result = Riddle::where("id", $data['id'])->first();
  6106. break;
  6107. case 5:
  6108. $result = Idiom::where("id", $data['id'])->first();
  6109. break;
  6110. case 6:
  6111. $result = Couplet::where("id", $data['id'])->first();
  6112. break;
  6113. default:
  6114. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6115. break;
  6116. }
  6117. return Result::success($result);
  6118. }
  6119. /**
  6120. * 农网导航首页数据
  6121. */
  6122. public function getWebsiteNwHomeList(array $data): array
  6123. {
  6124. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6125. ->pluck('category_id')
  6126. ->toArray();
  6127. // 使用子查询优化
  6128. $articlesList = DB::table('article')
  6129. ->select([
  6130. 'article.id',
  6131. 'article.title',
  6132. 'article.imgurl',
  6133. 'article.created_at',
  6134. 'category.name as category_name',
  6135. 'category.id as category_id',
  6136. 'website_category.aLIas_pinyin as pinyin',
  6137. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6138. DB::raw('100 as type')
  6139. ])
  6140. ->join('category', 'article.catid', '=', 'category.id')
  6141. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6142. ->leftJoin('website_category as parent_wc', function ($join) {
  6143. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6144. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6145. })
  6146. ->where('website_category.website_id', $data['website_id'])
  6147. ->where('article.status', 1)
  6148. ->whereIn('category.id', $categoryIds)
  6149. ->orderBy('article.created_at', 'desc')
  6150. ->get()
  6151. ->groupBy('category_id')
  6152. ->map(function ($group) {
  6153. // 确保第一条数据有图片
  6154. $firstWithImage = $group->first(function ($item) {
  6155. return !empty($item->imgurl);
  6156. });
  6157. if ($firstWithImage) {
  6158. // 如果有带图片的文章,将其放在第一位
  6159. $group = $group->filter(function ($item) use ($firstWithImage) {
  6160. return $item->id !== $firstWithImage->id;
  6161. })->prepend($firstWithImage);
  6162. }
  6163. return [
  6164. 'category_name' => $group->first()->category_name,
  6165. 'catid' => $group->first()->category_id,
  6166. 'pinyin' => $group->first()->pinyin,
  6167. 'parent_pinyin' => $group->first()->parent_pinyin,
  6168. 'list' => $group->take(4)->map(function ($item) {
  6169. return [
  6170. 'id' => $item->id,
  6171. 'title' => $item->title,
  6172. ];
  6173. })->values()
  6174. ];
  6175. })
  6176. ->values()
  6177. ->toArray();
  6178. return Result::success($articlesList);
  6179. }
  6180. /**
  6181. * 企业管理
  6182. * @param array $data
  6183. * @return array
  6184. */
  6185. public function getCompanyList(array $data): array
  6186. {
  6187. // return Result::success($data);
  6188. $where = [];
  6189. $user = User::where('id', $data['user_id'])->first();
  6190. if (empty($user)) {
  6191. return Result::error('用户不存在!');
  6192. }
  6193. if ($user['type_id'] != 10000) {
  6194. $where['user_id'] = $data['user_id'];
  6195. }
  6196. if (isset($data['title']) && !empty($data['title'])) {
  6197. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6198. }
  6199. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6200. array_push($where, ['website.id', $data['website_id']]);
  6201. }
  6202. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6203. if ($data['ischeck'] == 1) {
  6204. if (isset($data['status']) && $data['status'] != '') {
  6205. array_push($where, ['company.status', $data['status']]);
  6206. $query = Company::where($where);
  6207. } else {
  6208. $query = Company::whereIn('company.status', [0, 2]);
  6209. }
  6210. } else {
  6211. $query = Company::where('company.status', 1);
  6212. }
  6213. }
  6214. $result = $query->where($where)
  6215. ->leftJoin('website_category', function ($query) {
  6216. $query->on('website_category.category_id', '=', 'company.category_id')
  6217. ->on('website_category.website_id', '=', 'company.website_id');
  6218. })
  6219. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6220. ->select(
  6221. 'company.id',
  6222. 'company.title',
  6223. 'company.website_id',
  6224. 'company.category_id',
  6225. 'website.website_name',
  6226. 'website_category.alias as category_name',
  6227. 'company.status',
  6228. 'company.updated_at',
  6229. 'company.user_id'
  6230. )
  6231. ->orderBy('company.updated_at', 'desc')
  6232. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6233. if ($result->isEmpty()) {
  6234. return Result::error("暂无企业", 0);
  6235. }
  6236. return Result::success($result);
  6237. }
  6238. /**
  6239. * 添加企业
  6240. * @param array $data
  6241. * @return array
  6242. */
  6243. public function addCompany(array $data): array
  6244. {
  6245. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6246. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6247. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6248. $data['cat_arr_id'] = json_encode($car_arr_id);
  6249. } else {
  6250. $data['cat_arr_id'] = '';
  6251. }
  6252. if ($data['imgurl'] == '') {
  6253. //content中提取图片第一个图,正则提取
  6254. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6255. preg_match_all($reg, $data['content'], $matches);
  6256. if (isset($matches[1][0])) {
  6257. //截取varchar240
  6258. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6259. }
  6260. }
  6261. if ($data['keyword'] == '') {
  6262. //提取标题+内容中的关键词
  6263. $data['keyword'] = $data['title'];
  6264. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6265. Jieba::init(); // 初始化 jieba-php
  6266. Finalseg::init();
  6267. $segList = Jieba::cut($data['keyword']);
  6268. $segList1 = array_slice($segList, 0, 8);
  6269. $data['keyword'] = implode(',', $segList1);
  6270. }
  6271. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6272. //提取内容中的描述
  6273. $content = $data['content'];
  6274. // 去除 <style> 和 <script> 标签及其内容
  6275. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6276. // 去除所有 HTML 标签
  6277. $content = strip_tags($content);
  6278. // 去除 HTML 实体
  6279. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6280. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6281. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6282. // 去除多余空白
  6283. $content = preg_replace('/\s+/u', '', $content);
  6284. // 截取 100 个字符
  6285. $data['introduce'] = mb_substr($content, 0, 100);
  6286. }
  6287. $user = User::where('id', $data['user_id'])->first();
  6288. if (empty($user)) {
  6289. return Result::error('用户不存在!');
  6290. }
  6291. if ($user['type_id'] == 10000) {
  6292. $data['status'] = 1;
  6293. }
  6294. if (isset($data['level']) && $data['level'] != null) {
  6295. $data['level'] = intval($data['level']);
  6296. } else {
  6297. $data['level'] = null;
  6298. }
  6299. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6300. $this->sendMessage([
  6301. 'talk_type' => 900,
  6302. 'title' => $data['title'],
  6303. 'content' => '提交了审核',
  6304. 'messageType' => 8,
  6305. ]);
  6306. }
  6307. $result = Company::insertGetId($data);
  6308. if ($result) {
  6309. return Result::success($result);
  6310. } else {
  6311. return Result::error('添加失败');
  6312. }
  6313. }
  6314. /**
  6315. * 更新企业
  6316. * @param array $data
  6317. * @return array
  6318. */
  6319. public function upCompany(array $data): array
  6320. {
  6321. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6322. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6323. $data['cat_arr_id'] = json_encode($car_arr_id);
  6324. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6325. } else {
  6326. $data['cat_arr_id'] = '';
  6327. }
  6328. if ($data['imgurl'] == '') {
  6329. //content中提取图片第一个图,正则提取
  6330. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6331. preg_match_all($reg, $data['content'], $matches);
  6332. if (isset($matches[1][0])) {
  6333. //截取varchar
  6334. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6335. }
  6336. }
  6337. if ($data['keyword'] == '') {
  6338. //提取标题+内容中的关键词
  6339. $data['keyword'] = $data['title'];
  6340. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6341. Jieba::init(); // 初始化 jieba-php
  6342. Finalseg::init();
  6343. $segList = Jieba::cut($data['keyword']);
  6344. $segList1 = array_slice($segList, 0, 8);
  6345. $data['keyword'] = implode(',', $segList1);
  6346. }
  6347. if ($data['introduce'] == '') {
  6348. //提取内容中的描述
  6349. $content = $data['content'];
  6350. // 去除 <style> 和 <script> 标签及其内容
  6351. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6352. // 去除所有 HTML 标签
  6353. $content = strip_tags($content);
  6354. // 去除 HTML 实体
  6355. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6356. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6357. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6358. // 去除多余空白
  6359. $content = preg_replace('/\s+/u', '', $content);
  6360. // 截取 100 个字符
  6361. $data['introduce'] = mb_substr($content, 0, 100);
  6362. }
  6363. if (isset($data['level']) && $data['level'] != null) {
  6364. $data['level'] = intval($data['level']);
  6365. } else {
  6366. $data['level'] = null;
  6367. }
  6368. $user = User::where('id', $data['user_id'])->first();
  6369. if (empty($user)) {
  6370. return Result::error('用户不存在!');
  6371. }
  6372. if ($user['type_id'] == 10000) {
  6373. $data['status'] = 1;
  6374. } else {
  6375. $data['status'] = 0;
  6376. }
  6377. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6378. $this->sendMessage([
  6379. 'talk_type' => 900,
  6380. 'title' => $data['title'],
  6381. 'content' => '提交了审核',
  6382. 'messageType' => 8,
  6383. ]);
  6384. }
  6385. $result = Company::where('id', $data['id'])->update($data);
  6386. if ($result) {
  6387. return Result::success($result);
  6388. } else {
  6389. return Result::error('修改失败');
  6390. }
  6391. }
  6392. /**
  6393. * 删除企业
  6394. * @param array $data
  6395. * @return array
  6396. */
  6397. public function delCompany(array $data): array
  6398. {
  6399. $result = Company::where('id', $data['id'])->delete();
  6400. if ($result) {
  6401. return Result::success($result);
  6402. } else {
  6403. return Result::error('删除失败');
  6404. }
  6405. }
  6406. /**
  6407. * 审核企业
  6408. * @param array $data
  6409. * @return array
  6410. */
  6411. public function checkCompany(array $data): array
  6412. {
  6413. $user = User::where('id', $data['user_id'])->first();
  6414. if (empty($user)) {
  6415. return Result::error('用户不存在!');
  6416. }
  6417. $company = Company::where('id', $data['id'])->first();
  6418. if (empty($company)) {
  6419. return Result::error('企业不存在!');
  6420. }
  6421. // 状态:0:未审核 1:已审核 2:已拒绝
  6422. if ($data['status'] == 2 || $data['status'] == '2') {
  6423. $this->sendMessage([
  6424. 'talk_type' => 901,
  6425. 'title' => $company['title'],
  6426. 'content' => '审核拒绝',
  6427. 'messageType' => 8,
  6428. 'user_id' => $company['user_id'],
  6429. ]);
  6430. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6431. } else {
  6432. if ($data['status'] == 1) {
  6433. $this->sendMessage([
  6434. 'talk_type' => 901,
  6435. 'title' => $company['title'],
  6436. 'content' => '审核通过',
  6437. 'messageType' => 8,
  6438. 'user_id' => $company['user_id'],
  6439. ]);
  6440. } else if ($data['status'] == 0) {
  6441. $this->sendMessage([
  6442. 'talk_type' => 900,
  6443. 'title' => $company['title'],
  6444. 'content' => '提交了审核',
  6445. 'messageType' => 8,
  6446. ]);
  6447. }
  6448. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6449. }
  6450. if (empty($result)) {
  6451. return Result::error('审核失败!');
  6452. } else {
  6453. return Result::success($result);
  6454. }
  6455. }
  6456. /**
  6457. * 获取企业信息
  6458. * @param array $data
  6459. * @return array
  6460. */
  6461. public function getCompanyInfo(array $data): array
  6462. {
  6463. $result = Company::where('id', $data['id'])->first();
  6464. $city_arr = json_decode($result['city_arr_id']);
  6465. $result['city_name'] = District::whereIn('id', $city_arr)
  6466. ->pluck('name')
  6467. ->implode('-');
  6468. if (empty($result)) {
  6469. return Result::error('企业不存在!');
  6470. } else {
  6471. return Result::success($result);
  6472. }
  6473. }
  6474. /**
  6475. * @param array $data
  6476. * @return array
  6477. */
  6478. public function getWebsiteCompany(array $data): array
  6479. {
  6480. $categorys = json_decode($data['id'], true);
  6481. $category_arr = $this->processArticlePro($data['website_id']);
  6482. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6483. $catiall = $category_arr['catiall'];
  6484. foreach ($categorys as $key => $value) {
  6485. if (array_key_exists('level', $value)) {
  6486. $parts = explode(',', $value['level']);
  6487. $level = $parts[0] ?? null;
  6488. $imgnum = $parts[1] ?? null;
  6489. $textnum = $parts[2] ?? null;
  6490. if (!empty($textnum) && $textnum > 0) {
  6491. $text_num = Company::where('level', $level)
  6492. ->where('website_id', $data['website_id'])
  6493. ->where('status', 1)
  6494. ->select(
  6495. 'company.id',
  6496. 'company.title',
  6497. 'company.description',
  6498. 'company.updated_at',
  6499. 'company.category_id',
  6500. 'company.cat_arr_id'
  6501. )
  6502. ->orderBy('updated_at', 'desc')
  6503. ->limit($textnum)
  6504. ->get()->all();
  6505. }
  6506. if (!empty($imgnum) && $imgnum > 0) {
  6507. $img_num = Company::where('level', $level)
  6508. ->where('website_id', $data['website_id'])
  6509. ->where('status', 1)
  6510. ->where('imgurl', '!=', '')
  6511. ->whereNotNull('imgurl')
  6512. ->select(
  6513. 'company.id',
  6514. 'company.title',
  6515. 'company.description',
  6516. 'company.updated_at',
  6517. 'company.imgurl as imgs',
  6518. 'company.category_id',
  6519. 'company.cat_arr_id'
  6520. )
  6521. ->orderBy('updated_at', 'desc')
  6522. ->limit($imgnum)
  6523. ->get()->all();
  6524. }
  6525. }
  6526. if (array_key_exists('id', $value)) {
  6527. $parts = explode(',', $value['id']);
  6528. $category_id = $parts[0] ?? null;
  6529. $imgnum = $parts[1] ?? null;
  6530. $textnum = $parts[2] ?? null;
  6531. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6532. if (!empty($textnum) && $textnum > 0) {
  6533. $text_num = Company::whereIn('category_id', $category_arr)
  6534. ->where('website_id', $data['website_id'])
  6535. ->where('status', 1)
  6536. ->select(
  6537. 'company.id',
  6538. 'company.title',
  6539. 'company.description',
  6540. 'company.updated_at',
  6541. 'company.category_id',
  6542. 'company.cat_arr_id'
  6543. )
  6544. ->orderBy('updated_at', 'desc')
  6545. ->limit($textnum)
  6546. ->get()->all();
  6547. }
  6548. if (!empty($imgnum) && $imgnum > 0) {
  6549. $img_num = Company::whereIn('category_id', $category_arr)
  6550. ->where('website_id', $data['website_id'])
  6551. ->where('status', 1)
  6552. ->where('imgurl', '!=', '')
  6553. ->whereNotNull('imgurl')
  6554. ->select(
  6555. 'company.id',
  6556. 'company.title',
  6557. 'company.description',
  6558. 'company.updated_at',
  6559. 'company.imgurl as imgs',
  6560. 'company.category_id',
  6561. 'company.cat_arr_id'
  6562. )
  6563. ->orderBy('updated_at', 'desc')
  6564. ->limit($imgnum)
  6565. ->get()->all();
  6566. }
  6567. }
  6568. if (!empty($text_num)) {
  6569. foreach ($text_num as $k => $v) {
  6570. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6571. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6572. }
  6573. }
  6574. if (!empty($img_num)) {
  6575. foreach ($img_num as $k => $v) {
  6576. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6577. $imgurl = json_decode($v['imgs'], true);
  6578. if (!empty($imgurl)) {
  6579. $img_num[$k]->imgurl = $imgurl[0];
  6580. }
  6581. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6582. }
  6583. }
  6584. $company[$key]['img_num'] = $img_num ?? [];
  6585. $company[$key]['text_num'] = $text_num ?? [];
  6586. }
  6587. if (empty($company)) {
  6588. return Result::error("暂无相关企业信息", 0);
  6589. }
  6590. return Result::success($company);
  6591. }
  6592. /**
  6593. * @param array $data
  6594. * @return array
  6595. */
  6596. public function getWebsiteCompanyList(array $data): array
  6597. {
  6598. $where['website_id'] = $data['website_id'];
  6599. $where['status'] = 1;
  6600. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6601. $where['category_id'] = $data['category_id'];
  6602. }
  6603. if (isset($data['keyword']) && !empty($data['keyword'])) {
  6604. array_push($where, ['title', 'like', '%' . $data['keyword'] . '%']);
  6605. }
  6606. $query = Company::where($where);
  6607. $company = $this->processArticle(
  6608. $query->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6609. ->orderBy('updated_at', 'desc')
  6610. ->offset(($data['page'] - 1) * $data['pageSize'])
  6611. ->limit($data['pageSize'])
  6612. ->get(),
  6613. $data
  6614. );
  6615. if (empty($company)) {
  6616. return Result::error("暂无相关公司信息", 0);
  6617. }
  6618. $result = [
  6619. 'count' => $query->clone()->count(),
  6620. 'data' => $company,
  6621. ];
  6622. return Result::success($result);
  6623. }
  6624. /**
  6625. * 获取项目列表
  6626. * @param array $data
  6627. * @return array
  6628. */
  6629. public function getProjectList(array $data): array
  6630. {
  6631. $where = [];
  6632. $user = User::where('id', $data['user_id'])->first();
  6633. if (empty($user)) {
  6634. return Result::error('用户不存在!');
  6635. }
  6636. if ($user->type_id != 10000) {
  6637. array_push($where, ['project.user_id', $data['user_id']]);
  6638. }
  6639. $query = Project::query();
  6640. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6641. array_push($where, ['project.website_id', $data['website_id']]);
  6642. }
  6643. if (isset($data['title']) && !empty($data['title'])) {
  6644. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6645. }
  6646. if ($data['status'] != 3) {
  6647. array_push($where, ['project.status', $data['status']]);
  6648. }
  6649. $query = Project::where($where)
  6650. ->when($data['status'] == 3, function ($query) {
  6651. $query->whereIn('project.status', [0, 2]);
  6652. });
  6653. $count = $query->clone()
  6654. ->count();
  6655. $rows = $query->clone()
  6656. ->leftJoin('website', 'project.website_id', 'website.id')
  6657. ->leftJoin('website_category', function ($join) {
  6658. $join->on('project.website_id', '=', 'website_category.website_id')
  6659. ->on('project.category_id', '=', 'website_category.category_id');
  6660. })
  6661. ->select(
  6662. 'project.id',
  6663. 'project.title',
  6664. 'project.updated_at',
  6665. 'project.status',
  6666. 'website.website_name',
  6667. 'website_category.alias as category_name',
  6668. 'project.website_id',
  6669. 'project.user_id'
  6670. )
  6671. ->orderBy('project.updated_at', 'desc')
  6672. ->offset(($data['page'] - 1) * $data['pageSize'])
  6673. ->limit($data['pageSize'])
  6674. ->get();
  6675. if ($rows->isEmpty()) {
  6676. return Result::error("暂无相关项目信息", 0);
  6677. }
  6678. $result = [
  6679. 'count' => $count,
  6680. 'rows' => $rows,
  6681. ];
  6682. return Result::success($result);
  6683. }
  6684. /**
  6685. * 添加项目
  6686. * @param array $data
  6687. * @return array
  6688. */
  6689. public function addProject(array $data): array
  6690. {
  6691. $user = User::where('id', $data['user_id'])->first();
  6692. if (empty($user)) {
  6693. return Result::error("暂无相关用户信息", 0);
  6694. }
  6695. if ($user->type_id == 10000) {
  6696. $data['status'] = 1;
  6697. } else {
  6698. $data['status'] = 0;
  6699. }
  6700. if ($data['keyword'] == '') {
  6701. //提取标题+内容中的关键词
  6702. $data['keyword'] = $data['title'];
  6703. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6704. Jieba::init(); // 初始化 jieba-php
  6705. Finalseg::init();
  6706. $segList = Jieba::cut($data['keyword']);
  6707. $segList1 = array_slice($segList, 0, 8);
  6708. $data['keyword'] = implode(',', $segList1);
  6709. }
  6710. if ($data['description'] == '') {
  6711. //提取内容中的描述
  6712. // var_dump(11111);
  6713. //提取内容中的描述
  6714. $content = $data['introduce'];
  6715. // 去除 <style> 和 <script> 标签及其内容
  6716. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6717. // 去除所有 HTML 标签
  6718. $content = strip_tags($content);
  6719. // 去除 HTML 实体
  6720. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6721. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6722. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6723. // 去除多余空白
  6724. $content = preg_replace('/\s+/u', '', $content);
  6725. // 截取 100 个字符
  6726. $data['description'] = mb_substr($content, 0, 100);
  6727. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6728. }
  6729. if ($data['status'] == 0) {
  6730. $this->sendMessage([
  6731. 'talk_type' => 1000,
  6732. 'title' => $data['title'],
  6733. 'content' => '提交了审核',
  6734. 'messageType' => 9,
  6735. ]);
  6736. }
  6737. $project = Project::insertGetId($data);
  6738. if (empty($project)) {
  6739. return Result::error("暂无相关项目信息", 0);
  6740. }
  6741. return Result::success($project);
  6742. }
  6743. /**
  6744. * 更新项目
  6745. * @param array $data
  6746. * @return array
  6747. */
  6748. public function upProject(array $data): array
  6749. {
  6750. $project = Project::where('id', $data['id'])->first();
  6751. if (empty($project)) {
  6752. return Result::error("暂无相关项目信息", 0);
  6753. }
  6754. $id = $data['id'];
  6755. unset($data['id']);
  6756. $user = User::where('id', $data['user_id'])->first();
  6757. if (empty($user)) {
  6758. return Result::error("暂无相关用户信息", 0);
  6759. }
  6760. if ($user->type_id == 10000) {
  6761. $data['status'] = 1;
  6762. } else {
  6763. $data['status'] = 0;
  6764. }
  6765. unset($data['user_id']);
  6766. if ($data['keyword'] == '') {
  6767. //提取标题+内容中的关键词
  6768. $data['keyword'] = $data['title'];
  6769. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6770. Jieba::init(); // 初始化 jieba-php
  6771. Finalseg::init();
  6772. $segList = Jieba::cut($data['keyword']);
  6773. $segList1 = array_slice($segList, 0, 8);
  6774. $data['keyword'] = implode(',', $segList1);
  6775. }
  6776. if ($data['description'] == '') {
  6777. //提取内容中的描述
  6778. // var_dump(11111);
  6779. //提取内容中的描述
  6780. $content = $data['introduce'];
  6781. // 去除 <style> 和 <script> 标签及其内容
  6782. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6783. // 去除所有 HTML 标签
  6784. $content = strip_tags($content);
  6785. // 去除 HTML 实体
  6786. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6787. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6788. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6789. // 去除多余空白
  6790. $content = preg_replace('/\s+/u', '', $content);
  6791. // 截取 100 个字符
  6792. $data['description'] = mb_substr($content, 0, 100);
  6793. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6794. }
  6795. if ($data['status'] == 0) {
  6796. $this->sendMessage([
  6797. 'talk_type' => 1000,
  6798. 'title' => $data['title'],
  6799. 'content' => '提交了审核',
  6800. 'messageType' => 9,
  6801. ]);
  6802. }
  6803. $result = Project::where('id', $id)->update($data);
  6804. if (empty($result)) {
  6805. return Result::error("更新失败", 0);
  6806. }
  6807. return Result::success($result);
  6808. }
  6809. /**
  6810. * 删除项目
  6811. * @param array $data
  6812. * @return array
  6813. */
  6814. public function delProject(array $data): array
  6815. {
  6816. $user = User::where('id', $data['user_id'])->first();
  6817. if (empty($user)) {
  6818. return Result::error("暂无相关用户信息", 0);
  6819. }
  6820. $project = Project::where('id', $data['id'])->first();
  6821. if (empty($project)) {
  6822. return Result::error("暂无相关项目信息", 0);
  6823. }
  6824. $result = Project::where('id', $data['id'])->delete();
  6825. if (empty($result)) {
  6826. return Result::error("删除失败", 0);
  6827. }
  6828. return Result::success($result);
  6829. }
  6830. /**
  6831. * 审核项目
  6832. * @param array $data
  6833. * @return array
  6834. */
  6835. public function checkProject(array $data): array
  6836. {
  6837. $user = User::where('id', $data['user_id'])->first();
  6838. if (empty($user)) {
  6839. return Result::error("暂无相关用户信息", 0);
  6840. }
  6841. // 0:未审核; 1:已审核; 2:已拒绝;
  6842. if ($user->type_id != 10000) {
  6843. if ($data['status'] == 1 || $data['status'] == 2) {
  6844. return Result::error("此用户权限不足", 0);
  6845. }
  6846. }
  6847. $project = Project::where('id', $data['id'])->first();
  6848. if (empty($project)) {
  6849. return Result::error("暂无相关项目信息", 0);
  6850. }
  6851. if ($data['status'] == 2) {
  6852. $this->sendMessage([
  6853. 'talk_type' => 1001,
  6854. 'title' => $project['title'],
  6855. 'content' => '审核拒绝',
  6856. 'messageType' => 9,
  6857. 'user_id' => $project['user_id'],
  6858. ]);
  6859. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  6860. } else {
  6861. if ($data['status'] == 1) {
  6862. $this->sendMessage([
  6863. 'talk_type' => 1001,
  6864. 'title' => $project['title'],
  6865. 'content' => '审核通过',
  6866. 'messageType' => 9,
  6867. 'user_id' => $project['user_id'],
  6868. ]);
  6869. } else if ($data['status'] == 0) {
  6870. $this->sendMessage([
  6871. 'talk_type' => 1000,
  6872. 'title' => $project['title'],
  6873. 'content' => '提交了审核',
  6874. 'messageType' => 9,
  6875. ]);
  6876. }
  6877. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  6878. }
  6879. if (empty($result)) {
  6880. return Result::error("审核失败", 0);
  6881. }
  6882. return Result::success($result);
  6883. }
  6884. /**
  6885. * 获取项目详情
  6886. * @param array $data
  6887. * @return array
  6888. */
  6889. public function getProjectInfo(array $data): array
  6890. {
  6891. $project = Project::where('id', $data['id'])->first();
  6892. if (empty($project)) {
  6893. return Result::error("暂无相关项目信息", 0);
  6894. }
  6895. return Result::success($project);
  6896. }
  6897. public function getWebsiteCompanyInfo(array $data): array
  6898. {
  6899. $company = Company::where('id', $data['id'])
  6900. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  6901. ->where('status', 1)
  6902. ->where('website_id', $data['website_id'])
  6903. ->select('company.*', 'job_industry.hyname as hy_name')
  6904. ->first();
  6905. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  6906. switch ($company->jobnature_id) {
  6907. case null:
  6908. $company->jobnature_name = '';
  6909. break;
  6910. case 0:
  6911. $company->jobnature_name = '市场监督';
  6912. break;
  6913. case 1:
  6914. $company->jobnature_name = '信访纪检';
  6915. break;
  6916. case 2:
  6917. $company->jobnature_name = '公检法司';
  6918. break;
  6919. case 3:
  6920. $company->jobnature_name = '高关注机构';
  6921. break;
  6922. default:
  6923. $company->jobnature_name = '';
  6924. break;
  6925. }
  6926. $city_arr = $company->city_arr_id;
  6927. if (!empty($city_arr)) {
  6928. $city_arr = json_decode($city_arr, true);
  6929. $cityNames = District::whereIn('id', $city_arr)
  6930. ->pluck('name')
  6931. ->implode('-');
  6932. $company->city_name = $cityNames;
  6933. } else {
  6934. $company->city_name = '';
  6935. }
  6936. if (empty($company)) {
  6937. return Result::error("暂无相关公司信息", 0);
  6938. }
  6939. return Result::success($company);
  6940. }
  6941. public function getMSG(array $data): array
  6942. {
  6943. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  6944. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  6945. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  6946. $result = [];
  6947. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  6948. //最近的5篇已审的文章
  6949. $apply_articale = Article::where('status', 1)
  6950. ->where('admin_user_id', $user_id)
  6951. ->orderBy('updated_at', 'desc')
  6952. // ->limit(5)
  6953. ->get();
  6954. //获取5条用户的已审核商品
  6955. $good = Good::where('status', 2)
  6956. ->where('user_id', $user_id)
  6957. ->orderBy('updated_at', 'desc')
  6958. // ->limit(5)
  6959. ->get();
  6960. //获取5条用户待审核的公告
  6961. $notice = Notice::where('status', 2)
  6962. ->where('user_id', $user_id)
  6963. ->orderBy('updated_at', 'desc')
  6964. ->limit(5)->get();
  6965. //获取5条用户的待审核投诉
  6966. $complaint = Complaint::where('status', 2)
  6967. ->where('user_id', $user_id)
  6968. ->orderBy('updated_at', 'desc')
  6969. // ->limit(5)
  6970. ->get();
  6971. //获取5条用户的book
  6972. $book = Book::where('status', 2)
  6973. ->where('user_id', $user_id)
  6974. ->orderBy('updated_at', 'desc')
  6975. // ->limit(5)
  6976. ->get();
  6977. //获取5条用户的求职
  6978. //获取5条用户的求职 1
  6979. $job_hunting = JobHunting::where('job_hunting.status', 2)
  6980. ->where('job_hunting.user_id', $user_id)
  6981. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  6982. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  6983. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6984. ->orderBy('updated_at', 'desc')
  6985. // ->limit(5)
  6986. ->get();
  6987. //获取5条用户的求职 2
  6988. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  6989. ->where('job_recruiting.user_id', $user_id)
  6990. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  6991. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  6992. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6993. ->orderBy('updated_at', 'desc')
  6994. // ->limit(5)
  6995. ->get();
  6996. //人才库 1
  6997. $job_apply = JobApply::where('job_apply.status', 1)
  6998. ->where('job_apply.receiver_id', $user_id)
  6999. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7000. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7001. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7002. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7003. ->select('job_recruiting', 'job_recruiting.', '', '')
  7004. ->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')
  7005. ->orderBy('updated_at', 'desc')
  7006. // ->limit(5)
  7007. ->get();
  7008. // 职场机会 2
  7009. $job_resume = JobResume::where('job_resume.status', 1)
  7010. ->where('job_resume.receiver_id', $user_id)
  7011. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7012. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7013. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7014. ->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')
  7015. ->orderBy('updated_at', 'desc')
  7016. // ->limit(5)
  7017. ->get();
  7018. //获取5条用户待处理的投诉
  7019. $complaint_deal = Complaint::where('status', 2)
  7020. ->where('deal', 1)
  7021. ->whereJsonContains('re_user_ids', $user_id)
  7022. ->orderBy('updated_at', 'desc')
  7023. // ->limit(5)
  7024. ->get();
  7025. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7026. $complany = Company::where('status', 1)
  7027. ->where('user_id', $user_id)
  7028. ->orderBy('updated_at', 'desc')
  7029. // ->limit(5)
  7030. ->get();
  7031. //获取5条单聊未读聊天消息
  7032. // $chat = ChatRecords::where('is_read', 0)
  7033. // ->where('user_id', $user_id)
  7034. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7035. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7036. // ->where('action', 'recieved')
  7037. // ->where('talk_type', 1)
  7038. // ->orderBy('created_at', 'desc')
  7039. // // ->limit(5)
  7040. // ->get();
  7041. //获取5条未读群聊信息
  7042. // $chat_group = ChatRecords::where('is_read', 0)
  7043. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7044. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7045. // ->where('user_id', $user_id)
  7046. // ->where('talk_type', 2)
  7047. // ->orderBy('created_at', 'desc')
  7048. // // ->limit(5)
  7049. // ->get();
  7050. //获取5条用户的待审核项目
  7051. $project = Project::where('status', 1)
  7052. ->where('user_id', $user_id)
  7053. ->orderBy('updated_at', 'desc')
  7054. // ->limit(5)
  7055. ->get();
  7056. // count($chat) + count($chat_group) +
  7057. $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)
  7058. + count($complany)
  7059. + count($project)
  7060. // + count($chat) + count($chat_group)
  7061. ;
  7062. $result = [
  7063. 'apply_articale' => $apply_articale,
  7064. // 'chat' => $chat,
  7065. // 'chat_group' => $chat_group,
  7066. 'good' => $good,
  7067. 'notice' => $notice,
  7068. 'complaint' => $complaint,
  7069. 'book' => $book,
  7070. 'job_hunting' => $job_hunting,
  7071. 'job_recruiting' => $job_recruiting,
  7072. 'job_apply' => $job_apply,
  7073. 'job_resume' => $job_resume,
  7074. 'complaint_deal' => $complaint_deal,
  7075. 'complany' => $complany,
  7076. 'project' => $project,
  7077. 'count' => $count,
  7078. ];
  7079. } elseif ($type_id == 12) {
  7080. //最近的5篇已审的文章
  7081. $apply_articale = Article::where('status', 1)
  7082. ->where('admin_user_id', $user_id)
  7083. ->limit(5)->get();
  7084. //获取5条单聊未读聊天消息
  7085. $chat = ChatRecords::where('is_read', 0)
  7086. ->where('user_id', $user_id)
  7087. ->where('talk_type', 1)
  7088. ->orderBy('created_at', 'desc')
  7089. ->limit(5)->get();
  7090. //获取5条未读群聊信息
  7091. $chat_group = ChatRecords::where('is_read', 0)
  7092. ->where('user_id', $user_id)
  7093. ->where('talk_type', 2)
  7094. ->orderBy('created_at', 'desc')
  7095. ->limit(5)->get();
  7096. //获取5条用户的已审核商品
  7097. $good = Good::where('status', 2)
  7098. ->where('user_id', $user_id)
  7099. ->orderBy('updated_at', 'desc')
  7100. ->limit(5)->get();
  7101. //获取5条用户的book
  7102. $book = Book::where('status', 2)
  7103. ->where('user_id', $user_id)
  7104. ->orderBy('updated_at', 'desc')
  7105. ->limit(5)->get();
  7106. //获取5条用户的求职
  7107. //获取5条用户的求职 1
  7108. //count($chat) + count($chat_group)
  7109. $count = count($apply_articale) + count($good);
  7110. $result = [
  7111. 'apply_articale' => $apply_articale,
  7112. 'chat' => $chat,
  7113. 'chat_group' => $chat_group,
  7114. 'good' => $good,
  7115. 'book' => $book,
  7116. 'count' => $count,
  7117. ];
  7118. } elseif ($type_id == 13) {
  7119. //最近的5篇已审的文章
  7120. $apply_articale = Article::where('status', 1)
  7121. ->where('admin_user_id', $user_id)
  7122. ->limit(5)->get();
  7123. //获取5条单聊未读聊天消息
  7124. $chat = ChatRecords::where('is_read', 0)
  7125. ->where('user_id', $user_id)
  7126. ->where('talk_type', 1)
  7127. ->orderBy('created_at', 'desc')
  7128. ->limit(5)->get();
  7129. //获取5条未读群聊信息
  7130. $chat_group = ChatRecords::where('is_read', 0)
  7131. ->where('user_id', $user_id)
  7132. ->where('talk_type', 2)
  7133. ->orderBy('created_at', 'desc')
  7134. ->limit(5)->get();
  7135. //获取5条用户的已审核商品
  7136. $good = Good::where('status', 2)
  7137. ->where('user_id', $user_id)
  7138. ->orderBy('updated_at', 'desc')
  7139. ->limit(5)->get();
  7140. //count($chat) + count($chat_group) +
  7141. $count = count($apply_articale) + count($good);
  7142. $result = [
  7143. 'apply_articale' => $apply_articale,
  7144. 'chat' => $chat,
  7145. 'chat_group' => $chat_group,
  7146. 'good' => $good,
  7147. 'count' => $count,
  7148. ];
  7149. } elseif ($type_id == 14) {
  7150. //最近的5篇已审的文章
  7151. $apply_articale = Article::where('status', 1)
  7152. ->where('admin_user_id', $user_id)
  7153. // ->limit(5)
  7154. ->get();
  7155. //获取5条用户的已审核商品
  7156. $good = Good::where('status', 2)
  7157. ->where('user_id', $user_id)
  7158. ->orderBy('updated_at', 'desc')
  7159. // ->limit(5)
  7160. ->get();
  7161. $count = count($apply_articale) + count($good);
  7162. $result = [
  7163. 'apply_articale' => $apply_articale,
  7164. 'chat' => '',
  7165. 'chat_group' => '',
  7166. 'good' => $good,
  7167. 'count' => $count,
  7168. ];
  7169. } elseif ($type_id == 10000) {
  7170. //获取未审核的5篇文章
  7171. $apply_articale = Article::where('status', 0)
  7172. ->orderBy('updated_at', 'desc')
  7173. // ->limit(5)
  7174. ->get();
  7175. //获取5条单聊未读聊天消息
  7176. //获取5条单聊未读聊天消息
  7177. // $chat = ChatRecords::where('is_read', 0)
  7178. // ->where('user_id', $user_id)
  7179. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7180. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7181. // ->where('action', 'recieved')
  7182. // ->where('talk_type', 1)
  7183. // ->orderBy('created_at', 'desc')
  7184. // // ->limit(5)
  7185. // ->get();
  7186. // //获取5条未读群聊信息
  7187. // $chat_group = ChatRecords::where('is_read', 0)
  7188. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7189. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7190. // ->where('user_id', $user_id)
  7191. // ->where('talk_type', 2)
  7192. // ->orderBy('created_at', 'desc')
  7193. // // ->limit(5)
  7194. // ->get();
  7195. //获取5条用户的已审核商品
  7196. $good = Good::where('status', 1)
  7197. // ->where('user_id', $user_id)
  7198. ->orderBy('updated_at', 'desc')
  7199. // ->limit(5)
  7200. ->get();
  7201. //获取5条用户待审核的公告
  7202. $notice = Notice::where('status', 1)
  7203. ->orderBy('updated_at', 'desc')
  7204. // ->limit(5)
  7205. ->get();
  7206. //获取5条用户的待审核投诉
  7207. $complaint = Complaint::where('status', 1)
  7208. ->orderBy('updated_at', 'desc')
  7209. // ->limit(5)
  7210. ->get();
  7211. //获取5条用户的book
  7212. $book = Book::where('status', 1)
  7213. ->orderBy('updated_at', 'desc')
  7214. // ->limit(5)
  7215. ->get();
  7216. //获取5条用户的求职 1
  7217. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7218. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7219. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7220. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7221. ->orderBy('updated_at', 'desc')
  7222. // ->limit(5)
  7223. ->get();
  7224. //获取5条用户的求职 2
  7225. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7226. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7227. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7228. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7229. ->orderBy('updated_at', 'desc')
  7230. // ->limit(5)
  7231. ->get();
  7232. //人才库 1
  7233. $job_apply = JobApply::where('job_apply.status', 1)
  7234. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7235. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7236. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7237. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7238. ->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')
  7239. ->orderBy('updated_at', 'desc')
  7240. // ->limit(5)
  7241. ->get();
  7242. // 职场机会 2
  7243. $job_resume = JobResume::where('job_resume.status', 1)
  7244. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7245. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7246. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7247. ->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')
  7248. ->orderBy('updated_at', 'desc')
  7249. // ->limit(5)
  7250. ->get();
  7251. //待审核数据com pro
  7252. $complany = Company::where('status', 0)
  7253. ->orderBy('updated_at', 'desc')
  7254. // ->limit(5)
  7255. ->get();
  7256. $project = Project::where('status', 0)
  7257. ->orderBy('updated_at', 'desc')
  7258. // ->limit(5)
  7259. ->get();
  7260. $count =
  7261. // count($chat) +
  7262. // count($chat_group) +
  7263. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7264. + count($job_apply)
  7265. + count($job_resume)
  7266. + count($complany)
  7267. + count($project);
  7268. $result = [
  7269. 'apply_articale' => $apply_articale,
  7270. // 'chat' => $chat,
  7271. // 'chat_group' => $chat_group,
  7272. 'good' => $good,
  7273. 'notice' => $notice,
  7274. 'complaint' => $complaint,
  7275. 'book' => $book,
  7276. 'job_hunting' => $job_hunting,
  7277. 'job_recruiting' => $job_recruiting,
  7278. 'job_apply' => $job_apply,
  7279. 'job_resume' => $job_resume,
  7280. 'complany' => $complany,
  7281. 'project' => $project,
  7282. 'count' => $count,
  7283. ];
  7284. } elseif ($type_id == 20000) {
  7285. }
  7286. var_dump($type_id, '-----------------test---------');
  7287. return Result::success($result);
  7288. }
  7289. /**
  7290. * @param array $data
  7291. * @return array
  7292. */
  7293. public function getWebsiteProject(array $data): array
  7294. {
  7295. $categorys = json_decode($data['id'], true);
  7296. if (!empty($categorys)) {
  7297. $category_arr = $this->processArticlePro($data['website_id']);
  7298. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7299. $catiall = $category_arr['catiall'];
  7300. // return Result::success($catiall);
  7301. foreach ($categorys as $key => $val) {
  7302. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7303. $level = explode(',', $val['level'])[0];
  7304. $imgnum = explode(',', $val['level'])[1] ?? null;
  7305. $textnum = explode(',', $val['level'])[2] ?? null;
  7306. if ($level == 1) {
  7307. if (!empty($textnum) && $textnum > 0) {
  7308. $text_num = Project::where('level', $level)
  7309. ->where('website_id', $data['website_id'])
  7310. ->where('status', 1)
  7311. ->select(
  7312. 'project.id',
  7313. 'project.title',
  7314. 'project.description',
  7315. 'project.updated_at',
  7316. 'project.category_id',
  7317. 'project.cat_arr_id'
  7318. )
  7319. ->orderBy('updated_at', 'desc')
  7320. ->limit($textnum)
  7321. ->get()->all();
  7322. }
  7323. if (!empty($imgnum) && $imgnum > 0) {
  7324. $img_num = Project::where('level', $level)
  7325. ->where('website_id', $data['website_id'])
  7326. ->where('status', 1)
  7327. ->where('imgurl', '!=', '')
  7328. ->whereNotNull('imgurl')
  7329. ->select(
  7330. 'project.id',
  7331. 'project.title',
  7332. 'project.description',
  7333. 'project.updated_at',
  7334. 'project.imgurl as imgs',
  7335. 'project.category_id',
  7336. 'project.cat_arr_id'
  7337. )
  7338. ->orderBy('updated_at', 'desc')
  7339. ->limit($imgnum)
  7340. ->get()->all();
  7341. }
  7342. } else {
  7343. if (!empty($textnum) && $textnum > 0) {
  7344. $text_num = Project::where('website_id', $data['website_id'])
  7345. ->where('status', 1)
  7346. ->select(
  7347. 'project.id',
  7348. 'project.title',
  7349. 'project.description',
  7350. 'project.updated_at',
  7351. 'project.category_id',
  7352. 'project.cat_arr_id',
  7353. 'project.website_id',
  7354. 'project.updated_at',
  7355. 'project.created_at'
  7356. )
  7357. ->orderBy('updated_at', 'desc')
  7358. ->limit($textnum)
  7359. ->get()->all();
  7360. }
  7361. if (!empty($imgnum) && $imgnum > 0) {
  7362. $img_num = Project::where('website_id', $data['website_id'])
  7363. ->where('status', 1)
  7364. ->where('imgurl', '!=', '')
  7365. ->whereNotNull('imgurl')
  7366. ->select(
  7367. 'project.id',
  7368. 'project.title',
  7369. 'project.description',
  7370. 'project.updated_at',
  7371. 'project.imgurl as imgs',
  7372. 'project.category_id',
  7373. 'project.cat_arr_id'
  7374. )
  7375. ->orderBy('updated_at', 'desc')
  7376. ->limit($imgnum)
  7377. ->get()->all();
  7378. }
  7379. }
  7380. }
  7381. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7382. $category_ids = explode(',', $val['id'])[0];
  7383. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7384. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7385. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7386. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7387. $text_num = Project::whereIn('category_id', $category_arr)
  7388. ->where('website_id', $data['website_id'])
  7389. ->where('status', 1)
  7390. ->select(
  7391. 'project.id',
  7392. 'project.title',
  7393. 'project.description',
  7394. 'project.updated_at',
  7395. 'project.category_id',
  7396. 'project.cat_arr_id'
  7397. )
  7398. ->orderBy('updated_at', 'desc')
  7399. ->limit($cat_textnum)
  7400. ->get()->all();
  7401. }
  7402. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7403. $img_num = Project::whereIn('category_id', $category_arr)
  7404. ->where('website_id', $data['website_id'])
  7405. ->where('status', 1)
  7406. ->where('imgurl', '!=', '')
  7407. ->whereNotNull('imgurl')
  7408. ->select(
  7409. 'project.id',
  7410. 'project.title',
  7411. 'project.description',
  7412. 'project.updated_at',
  7413. 'project.imgurl as imgs',
  7414. 'project.category_id',
  7415. 'project.cat_arr_id'
  7416. )
  7417. ->orderBy('updated_at', 'desc')
  7418. ->limit($cat_imgnum)
  7419. ->get()->all();
  7420. }
  7421. }
  7422. if (!empty($img_num)) {
  7423. foreach ($img_num as $k => $v) {
  7424. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7425. $imgurl = json_decode($v['imgs'], true);
  7426. if (!empty($imgurl)) {
  7427. $img_num[$k]->imgurl = $imgurl[0];
  7428. }
  7429. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7430. }
  7431. }
  7432. if (!empty($text_num)) {
  7433. foreach ($text_num as $k => $v) {
  7434. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7435. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7436. }
  7437. }
  7438. $project[$key]['img_num'] = $img_num ?? [];
  7439. $project[$key]['text_num'] = $text_num ?? [];
  7440. }
  7441. }
  7442. if (empty($project)) {
  7443. return Result::error("暂无相关项目信息", 0);
  7444. }
  7445. return Result::success($project);
  7446. }
  7447. /**
  7448. * @param array $data
  7449. * @return array
  7450. */
  7451. public function getWebsiteProjectInfo(array $data): array
  7452. {
  7453. $project = Project::where('id', $data['id'])
  7454. ->where('status', 1)
  7455. ->where('website_id', $data['website_id'])
  7456. ->select('project.*')
  7457. ->first();
  7458. if (empty($project)) {
  7459. return Result::error("暂无相关项目信息", 0);
  7460. }
  7461. return Result::success($project);
  7462. }
  7463. /**
  7464. * @param array $data
  7465. * @return array
  7466. */
  7467. public function getWebsiteProjectList(array $data): array
  7468. {
  7469. $where = [];
  7470. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7471. $where['category_id'] = $data['category_id'];
  7472. }
  7473. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7474. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7475. }
  7476. $query = Project::where($where)
  7477. ->where('status', 1)
  7478. ->where('website_id', $data['website_id'])
  7479. ->select(
  7480. 'project.id',
  7481. 'project.title',
  7482. 'project.description',
  7483. 'project.imgurl as imgs',
  7484. 'project.category_id',
  7485. 'project.cat_arr_id'
  7486. )
  7487. ->orderBy('updated_at', 'desc');
  7488. $count = $query->count();
  7489. $project = $query->clone()
  7490. ->offset(($data['page'] - 1) * $data['pageSize'])
  7491. ->limit($data['pageSize'])
  7492. ->get()->all();
  7493. if (empty($project)) {
  7494. return Result::error("暂无相关项目信息", 0);
  7495. }
  7496. $categorys = $this->processArticlePro($data['website_id']);
  7497. $catiall = $categorys['catiall'];
  7498. foreach ($project as $key => $val) {
  7499. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7500. if (!empty($val['imgs'])) {
  7501. $imgurl = json_decode($val['imgs'], true);
  7502. if (!empty($imgurl)) {
  7503. $project[$key]->imgurl = $imgurl[0];
  7504. }
  7505. } else {
  7506. $project[$key]->imgurl = '';
  7507. }
  7508. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7509. }
  7510. $result = [
  7511. 'rows' => $project,
  7512. 'count' => $count,
  7513. ];
  7514. return Result::success($result);
  7515. }
  7516. /**
  7517. * @param array $data
  7518. * @return array
  7519. */
  7520. public function getWebsiteCategoryJob(array $data): array
  7521. {
  7522. $categorys = json_decode($data['id'], true);
  7523. if (!empty($categorys)) {
  7524. $category_arr = $this->processArticlePro($data['website_id']);
  7525. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7526. $catiall = $category_arr['catiall'];
  7527. foreach ($categorys as $key => $val) {
  7528. if (isset($val['id']) && !empty($val['id'])) {
  7529. $catid = explode(',', $val['id'])[0] ?? null;
  7530. $type = explode(',', $val['id'])[1] ?? null;
  7531. $textnum = explode(',', $val['id'])[2] ?? null;
  7532. }
  7533. // 4:招聘;5:求职;
  7534. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7535. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7536. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7537. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7538. ->where('job_recruiting.status', 1)
  7539. ->where('job_recruiting.website_id', $data['website_id'])
  7540. ->select(
  7541. 'job_recruiting.id',
  7542. 'job_recruiting.title',
  7543. 'job_company.business_name',
  7544. 'job_recruiting.updated_at',
  7545. 'job_recruiting.cat_arr_id'
  7546. )
  7547. ->orderBy('job_recruiting.updated_at', 'desc')
  7548. ->limit($textnum)
  7549. ->get()->all();
  7550. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7551. // 状态 审核状态,1待审核2已审核3已拒绝
  7552. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7553. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7554. ->where('job_hunting.status', 2)
  7555. ->where('job_hunting.website_id', $data['website_id'])
  7556. ->select(
  7557. 'job_hunting.id',
  7558. 'job_hunting.name',
  7559. 'job_hunting.cat_arr_id',
  7560. 'job_position.zwname as job_name',
  7561. 'job_hunting.updated_at'
  7562. )
  7563. ->orderBy('updated_at', 'desc')
  7564. ->limit($textnum)
  7565. ->get()->all();
  7566. } else {
  7567. $job = [];
  7568. }
  7569. // var_dump($catid.'222uuuuuuu'.$key);
  7570. if (!empty($job)) {
  7571. foreach ($job as $k => $value) {
  7572. if (isset($value->cat_arr_id)) {
  7573. $catArr = json_decode($value->cat_arr_id, true);
  7574. $catId = end($catArr);
  7575. } else {
  7576. continue;
  7577. }
  7578. if (isset($catiall[$catId])) {
  7579. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7580. }
  7581. }
  7582. }
  7583. // var_dump($catid.'xxxxx'.$key);
  7584. $result[$key] = $job ?? [];
  7585. }
  7586. }
  7587. if (empty($result)) {
  7588. return Result::error("暂无相关分类信息", 0);
  7589. }
  7590. return Result::success($result);
  7591. }
  7592. /**
  7593. * 发送消息
  7594. * @param array $messageData
  7595. * @return void
  7596. */
  7597. public function sendMessage($messageData)
  7598. {
  7599. $msg = [
  7600. 'talk_type' => $messageData['talk_type'],
  7601. 'title' => $messageData['title'],
  7602. 'content' => $messageData['content'],
  7603. 'messageType' => $messageData['messageType'],
  7604. 'user_id' => $messageData['user_id'] ?? '',
  7605. 'time' => microtime(),
  7606. ];
  7607. $message = new MqProducer($msg);
  7608. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7609. $producer->produce($message);
  7610. }
  7611. }