NewsService.php 212 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849
  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. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  57. class NewsService implements NewsServiceInterface
  58. {
  59. #[Inject]
  60. protected Redis $redis;
  61. /**
  62. * 获取导航池列表
  63. * @param array $data
  64. * @return array
  65. */
  66. public function getCategoryList(array $data): array
  67. {
  68. $search = $data['name'] ?? '';
  69. $page = (int)($data['page'] ?? 1);
  70. $perPage = (int)($data['pageSize'] ?? 10);
  71. // 1. 查出所有匹配的分类id
  72. if ($search) {
  73. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  74. if (empty($matchedIds)) {
  75. return Result::success(['rows' => [], 'total' => 0]);
  76. }
  77. // 2. 递归查所有父级,直到一级分类
  78. $idsStr = implode(',', $matchedIds);
  79. $sql = "
  80. WITH RECURSIVE parents AS (
  81. SELECT * FROM category WHERE id IN ($idsStr)
  82. UNION ALL
  83. SELECT c.* FROM category c
  84. INNER JOIN parents p ON c.id = p.pid
  85. )
  86. SELECT * FROM parents
  87. ";
  88. $parents = Db::select($sql);
  89. $parentIds = [];
  90. foreach ($parents as $row) {
  91. if ($row->pid == 0) {
  92. $parentIds[] = $row->id;
  93. }
  94. }
  95. $parentIds = array_unique($parentIds);
  96. } else {
  97. // 没有搜索,一级分类就是根
  98. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  99. }
  100. // 3. 一级分类分页
  101. $total = count($parentIds);
  102. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  103. if (empty($parentIds)) {
  104. return Result::success(['rows' => [], 'total' => $total]);
  105. }
  106. // 4. 递归查所有子孙
  107. $idsStr = implode(',', $parentIds);
  108. $sql = "
  109. WITH RECURSIVE subcategories AS (
  110. SELECT * FROM category WHERE id IN ($idsStr)
  111. UNION ALL
  112. SELECT c.* FROM category c
  113. INNER JOIN subcategories s ON c.pid = s.id
  114. )
  115. SELECT * FROM subcategories ORDER BY updated_at DESC
  116. ";
  117. $allCategories = Db::select($sql);
  118. // 5. 组装树结构
  119. $categoryMap = [];
  120. foreach ($allCategories as $cat) {
  121. $cat = (array)$cat;
  122. $cat['children'] = [];
  123. $categoryMap[$cat['id']] = $cat;
  124. }
  125. foreach ($categoryMap as $id => &$cat) {
  126. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  127. $categoryMap[$cat['pid']]['children'][] = &$cat;
  128. }
  129. }
  130. unset($cat);
  131. $categoryTree = [];
  132. foreach ($parentIds as $id) {
  133. if (isset($categoryMap[$id])) {
  134. $categoryTree[] = $categoryMap[$id];
  135. }
  136. }
  137. return Result::success([
  138. 'rows' => $categoryTree,
  139. 'total' => $total,
  140. ]);
  141. }
  142. private function findMatchedCategories($search)
  143. {
  144. if ($search) {
  145. return Category::where('name', 'like', "%{$search}%")
  146. ->orderBy('updated_at', 'desc')
  147. ->get();
  148. }
  149. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  150. ->get();
  151. }
  152. private function findAllParents($categories)
  153. {
  154. $allCategories = [];
  155. foreach ($categories as $category) {
  156. $parentId = $category->pid;
  157. while ($parentId > 0) {
  158. $parent = Category::find($parentId);
  159. if ($parent) {
  160. $allCategories[$parent->id] = $parent;
  161. $parentId = $parent->pid;
  162. } else {
  163. break;
  164. }
  165. }
  166. $allCategories[$category->id] = $category;
  167. }
  168. return array_values($allCategories);
  169. }
  170. private function buildCategoryTree($category, $allRequiredCategories)
  171. {
  172. $categoryData = $category->toArray();
  173. $children = [];
  174. foreach ($allRequiredCategories as $c) {
  175. if ($c->pid === $category->id) {
  176. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  177. }
  178. }
  179. if (!empty($children)) {
  180. $categoryData['children'] = $children;
  181. }
  182. return $categoryData;
  183. }
  184. public function myCategoryList(array $data): array
  185. {
  186. $sszq = $data['sszq'] ?? '';
  187. unset($data['sszq']);
  188. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  189. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  190. $where[] = [
  191. 'pid',
  192. '=',
  193. $data['pid'],
  194. ];
  195. if (isset($data['name'])) {
  196. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  197. }
  198. var_dump($where);
  199. //根据分类id,从category表中取出分类信息
  200. $result = Category::where($where)
  201. ->whereIn('category.id', $catorytids)
  202. ->select('category.*', 'category.id as category_id')->get();
  203. if (empty($result)) {
  204. return Result::error("没有栏目数据");
  205. }
  206. return Result::success($result);
  207. }
  208. /**
  209. * @param array $data
  210. * @return array
  211. */
  212. public function categoryList(array $data): array
  213. {
  214. $where[] = [
  215. 'pid',
  216. '=',
  217. $data['pid']
  218. ];
  219. if (isset($data['name'])) {
  220. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  221. }
  222. var_dump($where);
  223. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  224. if (empty($result)) {
  225. return Result::error("没有栏目数据");
  226. }
  227. return Result::success($result);
  228. }
  229. /**
  230. * @param array $data
  231. * @return array
  232. */
  233. public function addCategory(array $data): array
  234. {
  235. if (isset($data['id'])) {
  236. unset($data['id']);
  237. }
  238. $id = Category::insertGetId($data);
  239. if (empty($id)) {
  240. return Result::error("添加失败");
  241. }
  242. return Result::success(['id' => $id]);
  243. }
  244. /**
  245. * @param array $data
  246. * @return array
  247. */
  248. public function delCategory(array $data): array
  249. {
  250. Db::beginTransaction();
  251. try {
  252. $categoryList = Category::where(['pid' => $data['id']])->get();
  253. if ($categoryList->toArray()) {
  254. Db::rollBack();
  255. return Result::error("分类下面有子分类不能删除");
  256. }
  257. $articleList = Article::where(['catid' => $data['id']])->get();
  258. if ($articleList->toArray()) {
  259. Db::rollBack();
  260. return Result::error("分类下面有资讯不能删除");
  261. }
  262. $result = Category::where($data)->delete();
  263. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  264. if (!$result) {
  265. return Result::error("删除失败");
  266. }
  267. return Result::success($result);
  268. Db::commit();
  269. } catch (\Exception $e) {
  270. Db::rollBack();
  271. return Result::error("删除失败");
  272. }
  273. }
  274. /**
  275. * @param array $data
  276. * @return array
  277. */
  278. public function updateCategory(array $data): array
  279. {
  280. $where = [
  281. 'id' => $data['id'],
  282. ];
  283. $result = Category::where($where)->update($data);
  284. if ($result) {
  285. return Result::success($result);
  286. } else {
  287. return Result::error("更新失败");
  288. }
  289. }
  290. /**
  291. * 获取导航池信息
  292. * @param array $data
  293. * @return array
  294. */
  295. public function getCategoryInfo(array $data): array
  296. {
  297. $where = [
  298. 'id' => $data['id'],
  299. ];
  300. $result = Category::where($where)->first();
  301. if ($result) {
  302. return Result::success($result);
  303. } else {
  304. return Result::error("更新失败");
  305. }
  306. }
  307. /**
  308. * @param array $data
  309. * @return array
  310. */
  311. public function getArticleList(array $data): array
  312. {
  313. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  314. $type_id = $data['type_id'];
  315. unset($data['type_id']);
  316. $user_id = $data['user_id'];
  317. unset($data['user_id']);
  318. $where = [];
  319. $status1 = [];
  320. if (isset($data['id']) && $data['id']) {
  321. array_push($where, ['article.id', '=', $data['id']]);
  322. }
  323. if (isset($data['title']) && $data['title']) {
  324. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  325. }
  326. if (isset($data['category_name']) && $data['category_name']) {
  327. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  328. }
  329. if (isset($data['author']) && $data['author']) {
  330. array_push($where, ['article.author', '=', $data['author']]);
  331. }
  332. if (isset($data['islink']) && $data['islink'] !== "") {
  333. array_push($where, ['article.islink', '=', $data['islink']]);
  334. }
  335. if (isset($data['status']) && $data['status'] !== "") {
  336. array_push($where, ['article.status', '=', $data['status']]);
  337. }
  338. if (isset($data['status1'])) {
  339. $status1 = json_decode(($data['status1']));
  340. }
  341. //不是管理员展示个人数据;
  342. if ($type_id != 10000) {
  343. $where[] = ['article.admin_user_id', '=', $user_id];
  344. }
  345. $rep = Article::where($where)
  346. ->whereNotIn('article.status', [404])
  347. ->when($status1, function ($query) use ($status1) {
  348. if (isset($status1) && $status1) {
  349. $query->whereIn('article.status', $status1);
  350. }
  351. })
  352. ->leftJoin('category', 'article.catid', 'category.id')
  353. ->leftJoin('website_category', function ($join) {
  354. $join->on('article.web_site_id', '=', 'website_category.website_id')
  355. ->on('article.catid', '=', 'website_category.category_id');
  356. })
  357. ->select("article.*", "category.name as category_name", "website_category.alias")
  358. ->orderBy("article.updated_at", "desc")
  359. ->limit($data['pageSize'])
  360. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  361. $count = Article::where($where)->whereNotIn('article.status', [404])
  362. ->when($status1, function ($query) use ($status1) {
  363. if (isset($status1) && $status1) {
  364. $query->whereIn('article.status', $status1);
  365. }
  366. })
  367. ->leftJoin('category', 'article.catid', 'category.id')->count();
  368. $data = [
  369. 'rows' => $rep->toArray(),
  370. 'count' => $count,
  371. ];
  372. if (empty($rep)) {
  373. return Result::error("没有信息数据");
  374. }
  375. return Result::success($data);
  376. }
  377. /**
  378. * @param array $data
  379. * @return array
  380. */
  381. public function addArticle(array $data): array
  382. {
  383. var_dump($data, '----------12-----------1');
  384. unset($data['user_type']);
  385. unset($data['nav_add_pool_id']);
  386. // unset($data['commend_id']);
  387. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  388. Db::beginTransaction();
  389. try {
  390. //处理投票
  391. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  392. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  393. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  394. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  395. unset($data['is_survey']);
  396. unset($data['survey_name']);
  397. unset($data['suvey_array']);
  398. // unset($data['website_id']);
  399. // unset($data['web_site_id']);
  400. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  401. if ($data['hits'] == '') {
  402. $data['hits'] = 0;
  403. }
  404. if ($data['is_original'] == '') {
  405. $data['is_original'] = 0;
  406. }
  407. if ($data['status'] == '') {
  408. $data['status'] = 0;
  409. }
  410. $articleData = $data;
  411. unset($articleData['content']);
  412. //自动处理缩略图、关键字、描述
  413. if ($articleData['imgurl'] == '') {
  414. //如果没有图,设置level=0
  415. $levelArr = json_decode($articleData['level'], true);
  416. var_dump($levelArr, '----------levelArr-----------1');
  417. //content中提取图片第一个图,正则提取
  418. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  419. preg_match_all($reg, $data['content'], $matches);
  420. if (isset($matches[1][0])) {
  421. //截取varchar240
  422. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  423. //如果有图,设置level=3
  424. if (!in_array(3, $levelArr)) {
  425. $levelArr[] = 3;
  426. }
  427. $articleData['level'] = json_encode($levelArr);
  428. } else {
  429. if (!in_array(0, $levelArr)) {
  430. $levelArr[] = 0;
  431. }
  432. $articleData['level'] = json_encode($levelArr);
  433. }
  434. }
  435. var_dump($articleData['level'], '----------$articleData[level]----------1');
  436. if ($articleData['keyword'] == '') {
  437. //提取标题+内容中的关键词
  438. $articleData['keyword'] = $data['title'];
  439. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  440. Jieba::init(); // 初始化 jieba-php
  441. Finalseg::init();
  442. $segList = Jieba::cut($articleData['keyword']);
  443. $segList1 = array_slice($segList, 0, 8);
  444. $articleData['keyword'] = implode(',', $segList1);
  445. }
  446. if ($articleData['introduce'] == '') {
  447. //提取内容中的描述
  448. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  449. }
  450. $id = Article::insertGetId($articleData);
  451. $articleDataContent = [
  452. 'article_id' => $id,
  453. 'content' => $data['content'],
  454. ];
  455. ArticleData::insertGetId($articleDataContent);
  456. //处理投票
  457. if ($is_survey == 1) {
  458. //生成年月日时分秒+8位随机数
  459. $uuid = date('YmdHis') . rand(10000000, 99999999);
  460. var_dump($suvey_array, 'suvey_array________');
  461. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  462. var_dump($suveys_array, '---------------------1');
  463. var_dump($suvey_array, '---------------------2');
  464. $suvey_data = [];
  465. foreach ($suveys_array as $key => $value) {
  466. if ($value == '') {
  467. continue;
  468. }
  469. if (is_array($value)) {
  470. $suvey_data[] = [
  471. 'sur_id' => $uuid,
  472. 'art_id' => $id,
  473. 'website_id' => $website_id ?? 2,
  474. 'survey_name' => $survey_name,
  475. 'choice_name' => $value[1],
  476. 'is_other' => 1,
  477. 'other_id' => 0,
  478. 'results' => 0,
  479. ];
  480. } else {
  481. $suvey_data[] = [
  482. 'sur_id' => $uuid,
  483. 'art_id' => $id,
  484. 'website_id' => $website_id ?? 2,
  485. 'survey_name' => $survey_name,
  486. 'choice_name' => $value,
  487. 'is_other' => 0,
  488. 'other_id' => 0,
  489. 'results' => 0,
  490. ];
  491. }
  492. if (empty($suvey_data)) {
  493. throw new \Exception("投票数据为空");
  494. }
  495. }
  496. $result = ArticleSurvey::insert($suvey_data);
  497. if (!$result) {
  498. throw new \Exception("投票失败,ArticleSurvey插入失败");
  499. }
  500. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  501. if (!$result) {
  502. throw new \Exception("投票失败,更新主表失败");
  503. }
  504. }
  505. Db::commit();
  506. return Result::success(['id' => $id]);
  507. } catch (\Throwable $ex) {
  508. Db::rollBack();
  509. var_dump($ex->getMessage());
  510. return Result::error("创建失败", 0);
  511. }
  512. }
  513. /**
  514. * @param array $data
  515. * @return array
  516. */
  517. public function delArticle(array $data): array
  518. {
  519. $result = Article::where($data)->delete();
  520. //survey投票删除
  521. articleSurvey::where(['art_id' => $data['id']])->delete();
  522. if (!$result) {
  523. return Result::error("删除失败");
  524. }
  525. return Result::success($result);
  526. }
  527. /**
  528. * @param array $data
  529. * @return array
  530. */
  531. public function updateArticle(array $data): array
  532. {
  533. var_dump($data, '----------12-----------1');
  534. Db::beginTransaction();
  535. unset($data['user_type']);
  536. // unset($data['web_site_id']);
  537. unset($data['nav_add_pool_id']);
  538. try {
  539. //处理投票
  540. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  541. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  542. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  543. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  544. unset($data['is_survey']);
  545. unset($data['survey_name']);
  546. unset($data['suvey_array']);
  547. unset($data['website_id']);
  548. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  549. if ($data['hits'] == '') {
  550. $data['hits'] = 0;
  551. }
  552. if ($data['is_original'] == '') {
  553. $data['is_original'] = 0;
  554. }
  555. if ($data['status'] == '') {
  556. $data['status'] = 0;
  557. }
  558. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  559. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  560. $articleData = $data;
  561. unset($articleData['content']);
  562. unset($articleData['status_name']);
  563. unset($articleData['name']);
  564. unset($articleData['content']);
  565. unset($articleData['pid_arr']);
  566. unset($articleData['pid']);
  567. //自动处理缩略图、关键字、描述
  568. if ($articleData['imgurl'] == '') {
  569. //如果没有图,设置level=0
  570. $levelArr = json_decode($articleData['level'], true);
  571. var_dump($levelArr, '----------levelArr-----------1');
  572. //content中提取图片第一个图,正则提取
  573. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  574. preg_match_all($reg, $data['content'], $matches);
  575. if (isset($matches[1][0])) {
  576. //截取varchar240
  577. // 截取到第一个<
  578. $articleData['imgurl'] = $matches[1][0];
  579. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  580. $pos = strpos($articleData['imgurl'], '"');
  581. if ($pos !== false) {
  582. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  583. }
  584. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  585. //如果有图,设置level=3
  586. if (!in_array(3, $levelArr)) {
  587. $levelArr[] = 3;
  588. }
  589. $articleData['level'] = json_encode($levelArr);
  590. } else {
  591. if (!in_array(0, $levelArr)) {
  592. $levelArr[] = 0;
  593. }
  594. $articleData['level'] = json_encode($levelArr);
  595. }
  596. }
  597. var_dump($articleData['level'], '----------$articleData[level]----------1');
  598. if ($articleData['keyword'] == '') {
  599. //提取标题+内容中的关键词
  600. $articleData['keyword'] = $data['title'];
  601. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  602. Jieba::init(); // 初始化 jieba-php
  603. Finalseg::init();
  604. $segList = Jieba::cut($articleData['keyword']);
  605. $segList1 = array_slice($segList, 0, 8);
  606. $articleData['keyword'] = implode(',', $segList1);
  607. }
  608. if ($articleData['introduce'] == '') {
  609. //提取内容中的描述
  610. $articleData['introduce'] = substr(preg_replace('/\s+/', '', strip_tags($data['content'])), 0, 100);
  611. // substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  612. }
  613. $id = Article::where(['id' => $data['id']])->update($articleData);
  614. $articleDataContent = [
  615. 'content' => $data['content'],
  616. ];
  617. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  618. //处理投票
  619. $id = $data['id'];
  620. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  621. var_dump($suvey_array, 'suvey_array________delete');
  622. //处理投票
  623. if ($is_survey == 1) {
  624. //生成年月日时分秒+8位随机数
  625. $uuid = date('YmdHis') . rand(10000000, 99999999);
  626. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  627. var_dump($suveys_array, '---------------------1');
  628. $suvey_data = [];
  629. if (is_array($suveys_array)) {
  630. foreach ($suveys_array as $key => $value) {
  631. if ($value == '') {
  632. continue;
  633. }
  634. if (is_array($value)) {
  635. $suvey_data[] = [
  636. 'sur_id' => $uuid,
  637. 'art_id' => $id,
  638. 'website_id' => $website_id ?? 2,
  639. 'survey_name' => $survey_name,
  640. 'choice_name' => $value[1],
  641. 'is_other' => 1,
  642. 'other_id' => 0,
  643. 'results' => 0,
  644. ];
  645. } else {
  646. $suvey_data[] = [
  647. 'sur_id' => $uuid,
  648. 'art_id' => $id,
  649. 'website_id' => $website_id ?? 2,
  650. 'survey_name' => $survey_name,
  651. 'choice_name' => $value,
  652. 'is_other' => 0,
  653. 'other_id' => 0,
  654. 'results' => 0,
  655. ];
  656. }
  657. if (empty($suvey_data)) {
  658. throw new \Exception("投票数据为空");
  659. }
  660. }
  661. }
  662. $result = ArticleSurvey::insert($suvey_data);
  663. if (!$result) {
  664. throw new \Exception("投票失败");
  665. }
  666. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  667. if (!$result) {
  668. throw new \Exception("投票失败");
  669. }
  670. } else {
  671. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  672. }
  673. Db::commit();
  674. return Result::success([]);
  675. } catch (\Throwable $ex) {
  676. Db::rollBack();
  677. var_dump($ex->getMessage());
  678. return Result::error("更新失败" . $ex->getMessage(), 0);
  679. }
  680. }
  681. /**
  682. * 更新资讯状态
  683. * @param array $data
  684. * @return array
  685. */
  686. public function upArticleStatus(array $data): array
  687. {
  688. $result = Article::where(['id' => $data['id']])->update($data);
  689. if ($result) {
  690. return Result::success();
  691. } else {
  692. return Result::error("更新状态失败", 0);
  693. }
  694. }
  695. /**
  696. * 获取新闻详情
  697. * @param array $data
  698. * @return array
  699. */
  700. public function getArticleInfo(array $data): array
  701. {
  702. $where = [
  703. 'article.id' => $data['id'],
  704. // 'article.status' => 1,
  705. ];
  706. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  707. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  708. $info = $result;
  709. // var_dump($info, 'info');
  710. $info['survey_array'] = $articleSurvey;
  711. if ($result) {
  712. return Result::success($info);
  713. } else {
  714. return Result::error("查询失败", 0);
  715. }
  716. }
  717. /**
  718. * 获取头条新闻
  719. * @param array $data
  720. * @return array
  721. */
  722. public function getWebsiteArticlett(array $data): array
  723. {
  724. // return Result::success($data['website_id']);
  725. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  726. $category = array_values(array_unique($category->toArray()));
  727. $web['website_id'] = $data['website_id'];
  728. if ($category) {
  729. $where = [
  730. 'status' => 1,
  731. ];
  732. var_dump($data, 'data-----------------');
  733. // level=7 根据文章key来匹配文章
  734. if (isset($data['level']) && $data['level'] == 7) {
  735. // 根据文章id获取key
  736. // $data['id'] = 50142;
  737. if (isset($data['id']) && !empty($data['id'])) {
  738. $keyword = Article::where('id', $data['id'])->value('keyword');
  739. $keywordArray = explode(',', $keyword);
  740. $whereL7 = [];
  741. foreach ($keywordArray as $k => $v) {
  742. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  743. }
  744. // 原始查询
  745. $result['level7'] = Article::where($whereL7)
  746. ->when(!empty($data['imgnum']), function ($query) use ($data) {
  747. $query->where('article.imgurl', '!=', '')
  748. ->select('article.*')
  749. ->offset($data['placeid'])
  750. ->limit($data['imgnum']);
  751. })
  752. ->when(!empty($data['textnum']), function ($query) use ($data) {
  753. $query->select('article.*')
  754. ->offset($data['placeid'])
  755. ->limit($data['textnum']);
  756. })
  757. ->orderBy('updated_at', 'desc')
  758. ->get();
  759. $result['level7'] = $this->processArticle($result['level7'], $web);
  760. if (empty($result)) {
  761. return Result::success();
  762. }
  763. return Result::success($result);
  764. } else {
  765. return Result::error("参数错误level=7,id不能为空", 0);
  766. }
  767. }
  768. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  769. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  770. var_dump($where, 'where-----------------');
  771. // 初始化基础查询
  772. $query = Article::where($where)
  773. ->whereIn("catid", $category)
  774. ->where(function ($query) use ($data) {
  775. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  776. ->orWhereNull("ignore_ids");
  777. });
  778. // 处理 level 相关查询条件
  779. $query->when($data['level'] == 5, function ($query) {
  780. $query->inRandomOrder()
  781. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  782. })->when($data['level'] == 4, function ($query) {
  783. $query->orderBy("article.updated_at", "desc");
  784. })->when(!empty($data['level']), function ($query) use ($data) {
  785. if ($data['level'] != 4 && $data['level'] != 5) {
  786. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  787. ->orderBy("article.updated_at", "desc");
  788. }
  789. });
  790. // 初始化结果数组
  791. $result = [];
  792. // $input = $data['website_id'];
  793. // 处理图片新闻查询
  794. if (!empty($data['imgnum'])) {
  795. // 原错误提示表明 cleanBindings 方法需要传入数组类型的参数,而实际传入了 null。
  796. // 这里克隆查询构建器,确保绑定参数为数组,避免该错误。
  797. $imgQuery = clone $query;
  798. if ($imgQuery->getBindings() === null) {
  799. $imgQuery->setBindings([]);
  800. }
  801. $result['img'] = $imgQuery->where('article.imgurl', '!=', '')
  802. ->select(
  803. 'article.id',
  804. 'article.title',
  805. 'article.imgurl',
  806. 'article.author',
  807. 'article.updated_at',
  808. 'article.introduce',
  809. 'article.islink',
  810. 'article.linkurl',
  811. 'article.copyfrom',
  812. 'article.cat_arr_id',
  813. 'article.catid'
  814. )
  815. ->offset($data['placeid'])
  816. ->limit($data['imgnum'])
  817. ->get();
  818. $result['img'] = $this->processArticles($result['img'], $web);
  819. }
  820. // 处理文字新闻查询
  821. if (!empty($data['textnum'])) {
  822. $textQuery = clone $query;
  823. $result['text'] = $textQuery
  824. ->select(
  825. 'article.id',
  826. 'article.title',
  827. 'article.imgurl',
  828. 'article.author',
  829. 'article.updated_at',
  830. 'article.introduce',
  831. 'article.islink',
  832. 'article.linkurl',
  833. 'article.copyfrom',
  834. 'article.cat_arr_id',
  835. 'article.catid'
  836. )
  837. ->offset($data['placeid'])
  838. ->limit($data['textnum'])
  839. ->get();
  840. $result['text'] = $this->processArticles($result['text'], $web);
  841. }
  842. if (empty($result) || count($result) == 0) {
  843. return Result::error("暂无头条新闻");
  844. }
  845. return Result::success($result);
  846. } else {
  847. return Result::error("本网站下暂无相关栏目", 0);
  848. }
  849. }
  850. /**
  851. * 获取模块新闻
  852. * @param array $data
  853. * @return array
  854. */
  855. public function getWebsiteModelArticles(array $data): array
  856. {
  857. $catid = $data['catid'];
  858. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  859. $category = $category->toArray();
  860. if (!empty($category)) {
  861. $where = [
  862. 'status' => 1,
  863. 'catid' => $catid,
  864. ];
  865. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  866. // 1:文字新闻;2:轮播图;3:图文;
  867. // 级别:0:未分类
  868. // 3:推荐图片
  869. if ($data['level'] == 1) {
  870. $data['level'] = 0;
  871. }
  872. $result = Article::where($where)
  873. ->where(function ($query) use ($data) {
  874. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  875. ->orWhereNull("level")
  876. ->orWhereRaw("level = '[]'");
  877. })
  878. ->where(function ($query) use ($data) {
  879. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  880. ->orWhereNull("ignore_ids");
  881. })
  882. ->orderBy("updated_at", "desc")
  883. ->offset($placeid)
  884. ->limit($data['pagesize'])
  885. ->get();
  886. if (empty($result)) {
  887. return Result::error("此栏目暂无相关新闻", 0);
  888. }
  889. } else {
  890. return Result::error("此网站暂无此栏目", 0);
  891. }
  892. return Result::success($result);
  893. }
  894. /**
  895. *获取新闻列表
  896. * @param array $data
  897. * @return array
  898. */
  899. public function getWebsiteArticleList(array $data): array
  900. {
  901. // return Result::success($data);
  902. $where[] = ['status', '=', 1];
  903. if (isset($data['catid']) && !empty($data['catid'])) {
  904. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  905. array_push($where, ['catid', '=', $data['catid']]);
  906. if (empty($category)) {
  907. return Result::error("此网站暂无此栏目", 0);
  908. }
  909. }
  910. // return Result::success($where);
  911. $rep = Article::where($where)
  912. ->where(function ($query) use ($data) {
  913. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  914. ->orWhereNull("ignore_ids");
  915. })
  916. ->select(
  917. 'article.id',
  918. 'article.title',
  919. 'article.imgurl',
  920. 'article.author',
  921. 'article.updated_at',
  922. 'article.introduce',
  923. 'article.islink',
  924. 'article.linkurl',
  925. 'article.copyfrom',
  926. 'article.cat_arr_id',
  927. 'article.catid'
  928. )
  929. ->orderBy("updated_at", "desc")
  930. ->offset(($data['page'] - 1) * $data['pageSize'])
  931. ->limit($data['pageSize'])
  932. ->get();
  933. $web['website_id'] = $data['website_id'];
  934. $rep = $this->processArticles($rep, $web);
  935. $count = Article::where($where)
  936. ->where(function ($query) use ($data) {
  937. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  938. ->orWhereNull("ignore_ids");
  939. })->count();
  940. $data = [
  941. 'rows' => $rep->toArray(),
  942. 'count' => $count,
  943. ];
  944. if (empty($rep)) {
  945. return Result::error("没有信息数据");
  946. }
  947. return Result::success($data);
  948. }
  949. /**
  950. * 前端-获取新闻详情
  951. * @param array $data
  952. * @return array
  953. */
  954. public function selectWebsiteArticleInfo(array $data): array
  955. {
  956. $where = [
  957. 'article.id' => $data['id'],
  958. 'article.status' => 1,
  959. ];
  960. $result = Article::where($where)
  961. ->leftJoin("article_data", "article.id", "article_data.article_id")
  962. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  963. ->where(function ($query) use ($data) {
  964. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  965. ->orWhereNull("ignore_ids");
  966. })
  967. ->first();
  968. if (empty($result)) {
  969. return Result::error("暂无此新闻!", 0);
  970. }
  971. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  972. ->select('website_category.*', 'website.website_name', 'website.suffix')
  973. ->where('website_category.website_id', $data['website_id'])
  974. ->where(['website_category.category_id' => $result['catid']])
  975. ->first();
  976. if (empty($category)) {
  977. return Result::error("查询失败", 0);
  978. }
  979. //手动推荐文章
  980. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  981. $commendArticle = Article::whereIn('id', $commend_ids)
  982. ->where('status', 1)
  983. ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
  984. ->orderBy('updated_at', 'desc')
  985. ->limit(5)
  986. ->get();
  987. $result['category_id'] = $category['category_id'];
  988. $result['cat_name'] = $category['alias'];
  989. $result['website_name'] = $category['website_name'] ?? "";
  990. $result['suffix'] = $category['suffix'] ?? "";
  991. $result['commendArticle'] = $commendArticle;
  992. return Result::success($result);
  993. }
  994. /**
  995. * 前端-获取网站调查问卷
  996. * @param array $data
  997. * @return array
  998. */
  999. public function getWebsiteSurvey(array $data): array
  1000. {
  1001. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1002. $website = Website::where('id', $data['website_id'])->first();
  1003. if (empty($website)) {
  1004. return Result::error("暂无此网站", 0);
  1005. }
  1006. }
  1007. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1008. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1009. if (empty($article)) {
  1010. return Result::error("暂无此文章", 0);
  1011. }
  1012. // return Result::error($data,0);
  1013. $where['art_id'] = $data['art_id'];
  1014. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1015. } else {
  1016. $survey = Article::where(function ($query) {
  1017. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1018. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1019. })
  1020. ->where('status', 1)
  1021. ->where('is_survey', 1)
  1022. ->select('survey_id')
  1023. ->orderBy('updated_at', 'desc')
  1024. ->first();
  1025. if (empty($survey)) {
  1026. return Result::error("暂无调查问卷", 0);
  1027. }
  1028. $where['sur_id'] = $survey['survey_id'];
  1029. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1030. }
  1031. // return Result::success($where);
  1032. $result = ArticleSurvey::where($where)
  1033. ->where(function ($query) {
  1034. $query->where('is_other', 0)
  1035. ->orWhere(function ($subQuery) {
  1036. $subQuery->where('is_other', 1)
  1037. ->where('other_id', 0);
  1038. });
  1039. })
  1040. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1041. ->select('article_survey.*', 'article.survey_type')
  1042. ->get()->all();
  1043. if (empty($result)) {
  1044. return Result::error("此文章暂无调查问卷", 0);
  1045. }
  1046. return Result::success($result);
  1047. }
  1048. /**
  1049. * 前端-添加网站调查问卷选项
  1050. * @param array $data
  1051. * @return array
  1052. */
  1053. public function addWebsiteSurveyOption(array $data): array
  1054. {
  1055. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1056. $website = Website::where('id', $data['website_id'])->first();
  1057. if (empty($website)) {
  1058. return Result::error("暂无此网站", 0);
  1059. }
  1060. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1061. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1062. if (empty($survey)) {
  1063. return Result::error("此调查问卷不可添加选项", 0);
  1064. }
  1065. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1066. $choice = [
  1067. 'art_id' => $survey['art_id'],
  1068. 'website_id' => $data['website_id'],
  1069. 'survey_name' => $survey['survey_name'],
  1070. 'choice_name' => $data['choice_name'],
  1071. 'sur_id' => $survey['sur_id'],
  1072. 'is_other' => 1,
  1073. 'other_id' => $survey['id'],
  1074. ];
  1075. $result = ArticleSurvey::insertGetId($choice);
  1076. if (empty($result)) {
  1077. return Result::error("添加失败", 0);
  1078. }
  1079. return Result::success($result);
  1080. }
  1081. }
  1082. return Result::error("添加失败", 0);
  1083. }
  1084. return Result::error("添加失败", 0);
  1085. }
  1086. /**
  1087. * 前端-调查问卷投票
  1088. * @param array $data
  1089. * @return array
  1090. */
  1091. public function addWebsiteSurveyVote(array $data): array
  1092. {
  1093. // return Result::success($data);
  1094. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1095. $website = Website::where('id', $data['website_id'])->first();
  1096. if (empty($website)) {
  1097. return Result::error("暂无此网站", 0);
  1098. }
  1099. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1100. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1101. // return Result::success($survey);
  1102. if (empty($is_survey)) {
  1103. return Result::error("此调查问卷不存在", 0);
  1104. }
  1105. // return Result::success($survey);
  1106. // 调查问卷类型
  1107. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1108. //多选 若是json型则转化成数组类型
  1109. if (strpos($data['choice_id'], '[') === 0) {
  1110. $data['choice_id'] = json_decode($data['choice_id'], true);
  1111. } else {
  1112. // 单选 也转换成数组
  1113. $data['choice_id'] = [$data['choice_id']];
  1114. }
  1115. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1116. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1117. // ->where('website_id',$data['website_id'])
  1118. ->where('is_other', 1)
  1119. ->where('other_id', 0)
  1120. ->first();
  1121. if (!empty($other)) {
  1122. return Result::error("请选择已有的选项!", 0);
  1123. }
  1124. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1125. // ->where('website_id',$data['website_id'])
  1126. ->where('is_other', 1)
  1127. ->where('other_id', '!=', 0)
  1128. ->first();
  1129. // return Result::success($choice['other']);
  1130. $choice_id = $data['choice_id'];
  1131. if (!empty($choice['other'])) {
  1132. // array_push($data['choice_id'],$choice['other']['other_id']);
  1133. if (!empty($choice_id)) {
  1134. $key = array_search($choice['other']['id'], $choice_id);
  1135. if ($key !== false) {
  1136. unset($choice_id[$key]);
  1137. $choice_id = array_values($choice_id);
  1138. }
  1139. array_push($choice_id, $choice['other']['other_id']);
  1140. } else {
  1141. $choice_id[0] = $choice['other']['other_id'];
  1142. }
  1143. array_push($data['choice_id'], $choice['other']['other_id']);
  1144. }
  1145. // return Result::success($data);
  1146. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1147. // ->where('website_id',$data['website_id'])
  1148. ->increment('results', 1);
  1149. if (empty($choice)) {
  1150. return Result::error("请选择已有的选项!", 0);
  1151. }
  1152. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1153. // ->where('website_id',$data['website_id'])
  1154. ->where('other_id', 0)
  1155. ->get();
  1156. $survey['choice'] = $choice_id;
  1157. return Result::success($survey);
  1158. }
  1159. return Result::error("参数必填!");
  1160. }
  1161. return Result::error("此调查问卷不存在", 0);
  1162. }
  1163. return Result::error("参数必填!");
  1164. }
  1165. /**
  1166. * 后端-获取网站调查问卷列表
  1167. * @param array $data
  1168. * @return array
  1169. */
  1170. public function getSurveyList(array $data): array
  1171. {
  1172. $where = [];
  1173. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1174. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1175. }
  1176. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1177. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1178. }
  1179. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1180. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1181. }
  1182. // return Result::success($where);
  1183. if (!empty($where)) {
  1184. $query = Article::where($where)->where(function ($q) {
  1185. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1186. });
  1187. } else {
  1188. $query = Article::where(function ($q) {
  1189. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1190. });
  1191. }
  1192. $count = $query->count();
  1193. $survey = $query->orderByDesc('id')
  1194. ->limit($data['pageSize'])
  1195. ->offset(($data['page'] - 1) * $data['pageSize'])
  1196. ->get();
  1197. if (empty($survey->toArray())) {
  1198. return Result::error("暂无调查问卷!", 0);
  1199. }
  1200. $result = [
  1201. 'rows' => $survey,
  1202. 'count' => $count,
  1203. ];
  1204. return Result::success($result);
  1205. }
  1206. /**
  1207. * 后端-获取网站调查问卷详情
  1208. * @param array $data
  1209. * @return array
  1210. */
  1211. public function getSurveyInfo(array $data): array
  1212. {
  1213. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1214. $where = ['sur_id' => $data['sur_id']];
  1215. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1216. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1217. ->select('article_survey.*', 'article.survey_type')
  1218. ->get()->all();
  1219. if (empty($choose)) {
  1220. return Result::error("此调查问卷不存在", 0);
  1221. }
  1222. $resultsArray = array_column($choose, 'results');
  1223. $total = array_sum($resultsArray);
  1224. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1225. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1226. // $total = 0;
  1227. if (!empty($other)) {
  1228. $total = $total + $other['results'];
  1229. $other['choice_name'] = '(其他)';
  1230. if (!empty($others)) {
  1231. $other['hasChildren'] = true;
  1232. // array_push($other,['hasChildren','=',true]);
  1233. $other['children'] = $others;
  1234. $other_choices = [$other->toArray()];
  1235. $mer_choice = array_merge($choose, $other_choices);
  1236. $value_choice = array_values($mer_choice);
  1237. } else {
  1238. // return Result::error('1111');
  1239. $other_choices = [$other->toArray()];
  1240. $other_choices = array_merge($choose, $other_choices);
  1241. $value_choice = array_values($other_choices);
  1242. // return Result::success($result);
  1243. }
  1244. } else {
  1245. $value_choice = $choose;
  1246. }
  1247. $result = [
  1248. 'choose' => $value_choice,
  1249. 'total' => $total,
  1250. ];
  1251. }
  1252. return Result::success($result);
  1253. }
  1254. /**
  1255. * 前端-搜索新闻列表
  1256. * @param array $data
  1257. * @return array
  1258. */
  1259. public function selectWebsiteArticle(array $data): array
  1260. {
  1261. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1262. $query = Article::where('status', 1)
  1263. ->whereIn('catid', $category)
  1264. ->where(function ($query) use ($data) {
  1265. $query->where(function ($subQuery) use ($data) {
  1266. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1267. })->orWhereNull("ignore_ids");
  1268. });
  1269. // return Result::success($all_articles);
  1270. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1271. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1272. }
  1273. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1274. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1275. }
  1276. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1277. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1278. }
  1279. // 计算总数
  1280. $count = $query->count();
  1281. // 分页查询
  1282. $articles = $query
  1283. ->select(
  1284. 'article.id',
  1285. 'article.title',
  1286. 'article.imgurl',
  1287. 'article.author',
  1288. 'article.updated_at',
  1289. 'article.introduce',
  1290. 'article.islink',
  1291. 'article.linkurl',
  1292. 'article.copyfrom',
  1293. 'article.cat_arr_id',
  1294. 'article.catid',
  1295. 'article.department_arr_id',
  1296. 'article.city_arr_id',
  1297. )
  1298. ->orderBy("updated_at", "desc")
  1299. ->offset(($data['page'] - 1) * $data['pageSize'])
  1300. ->limit($data['pageSize'])
  1301. ->get();
  1302. $web['website_id'] = $data['website_id'];
  1303. $articles = $this->processArticles($articles, $web);
  1304. if (empty($articles)) {
  1305. return Result::error("没有符合条件的资讯数据");
  1306. }
  1307. $result = [
  1308. 'rows' => $articles,
  1309. 'count' => $count,
  1310. ];
  1311. return Result::success($result);
  1312. }
  1313. /**
  1314. * 模块新闻加强版
  1315. * @param array $data
  1316. * @return array
  1317. */
  1318. public function getWebsiteCatidArticle(array $data): array
  1319. {
  1320. $where = [
  1321. 'website_category.category_id' => $data['catid'],
  1322. 'website_category.website_id' => $data['website_id'],
  1323. ];
  1324. // $category = WebsiteCategory::where($where);
  1325. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1326. $child_catnum = $data['child_catnum'] ?? 1;
  1327. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1328. $childCategoryIds = array_column($category['child'], 'category_id');
  1329. if (empty($childCategoryIds)) {
  1330. return Result::error("暂无子栏目", 0);
  1331. }
  1332. $imgArticles = [];
  1333. $textArticles = [];
  1334. // return Result::success($childCategoryIds);
  1335. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1336. // 初始化子分类图片新闻和文字新闻数组
  1337. // 查询所有子级栏目的图文新闻
  1338. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1339. ->where(function ($query) use ($data) {
  1340. $query->where(function ($subQuery) use ($data) {
  1341. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1342. })->orWhereNull("ignore_ids");
  1343. })
  1344. ->where('status', 1)
  1345. ->where('imgurl', '!=', '')
  1346. ->select('*')
  1347. ->orderBy('updated_at', 'desc')
  1348. ->limit($data['child_imgnum'])
  1349. ->get();
  1350. }
  1351. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1352. // 查询所有子级栏目的文字新闻
  1353. $textArticles = Article::where('catid', $childCategoryIds[0])
  1354. ->where('status', 1)
  1355. ->where(function ($query) use ($data) {
  1356. $query->where(function ($subQuery) use ($data) {
  1357. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1358. })->orWhereNull("ignore_ids");
  1359. })
  1360. ->select('*')
  1361. ->orderBy('updated_at', 'desc')
  1362. ->limit($data['child_textnum'])
  1363. ->get();
  1364. }
  1365. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1366. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1367. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1368. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1369. return $child;
  1370. }, $category['child']);
  1371. }
  1372. // }
  1373. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1374. $category['img'] = WebsiteCategory::where($where)
  1375. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1376. ->where('article.status', 1)
  1377. ->where('article.imgurl', '!=', '')
  1378. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1379. ->orderBy('article.updated_at', 'desc')
  1380. ->limit($data['img_num'])
  1381. ->get();
  1382. }
  1383. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1384. $category['text'] = WebsiteCategory::where($where)
  1385. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1386. ->where('article.status', 1)
  1387. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1388. ->orderBy('article.updated_at', 'desc')
  1389. ->limit($data['text_num'])
  1390. ->get();
  1391. }
  1392. // $category = $category->get();
  1393. if (empty($category)) {
  1394. return Result::error("查询失败", 0);
  1395. }
  1396. return Result::success($category);
  1397. }
  1398. /**
  1399. * 模块新闻加强版
  1400. * @param array $data
  1401. * @return array
  1402. */
  1403. /**
  1404. * 辅助方法:获取文章列表
  1405. */
  1406. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1407. {
  1408. sleep(1);
  1409. $query = Article::where('article.status', 1)
  1410. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1411. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1412. ->where(function ($query) use ($website) {
  1413. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1414. })
  1415. ->leftJoin('website_category', function ($join) use ($website) {
  1416. $join->on('article.catid', '=', 'website_category.category_id')
  1417. ->where('website_category.website_id', '=', $website['website_id']);
  1418. })
  1419. ->select(
  1420. 'article.id',
  1421. 'article.title',
  1422. 'article.imgurl',
  1423. 'article.author',
  1424. 'article.updated_at',
  1425. 'article.introduce',
  1426. 'article.islink',
  1427. 'article.linkurl',
  1428. 'article.copyfrom',
  1429. 'article.cat_arr_id',
  1430. 'article.catid',
  1431. 'website_category.alias as category_name'
  1432. )
  1433. ->orderBy('updated_at', 'desc')
  1434. ->limit($limit);
  1435. // 如果是图片文章,添加图片URL条件
  1436. if ($isImageArticle) {
  1437. $query->where('imgurl', '!=', '');
  1438. } else {
  1439. // 文字文章不需要imgurl字段
  1440. $query->addSelect('article.introduce');
  1441. }
  1442. $articles = $query->get();
  1443. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1444. }
  1445. /**
  1446. * 乡村网-获取特殊新闻模块
  1447. * @param array $data
  1448. * @return array
  1449. */
  1450. public function getWebsiteArticles(array $data): array
  1451. {
  1452. $input['id'] = $data['id'];
  1453. $input['website_id'] = $data['website_id'];
  1454. $data = json_decode($input['id'], true);
  1455. // 使用 array_map 处理每个元素
  1456. $result = array_map(function ($item) use ($input) {
  1457. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1458. $website = [
  1459. 'website_id' => $input['website_id']
  1460. ];
  1461. // 查询栏目名称
  1462. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1463. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1464. if (empty($category)) {
  1465. $imgArticles = [];
  1466. $textArticles = [];
  1467. // return Result::error("暂无此栏目",0);
  1468. } else {
  1469. $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1470. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin . '/' : null;
  1471. // return Result::success($website);
  1472. // 查询图片新闻
  1473. // 合并查询条件
  1474. $baseQuery = Article::where(function ($query) use ($website) {
  1475. $query->where(function ($subQuery) use ($website) {
  1476. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1477. })->orWhereNull("ignore_ids");
  1478. })
  1479. ->where('article.status', 1)
  1480. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1481. ->where('website_category.website_id', $website['website_id']);
  1482. // 查询文字新闻
  1483. $textArticles = clone $baseQuery;
  1484. $textArticles = $textArticles->whereIn('catid', $child_category)
  1485. ->select(
  1486. 'article.id',
  1487. 'article.title',
  1488. // 'article.imgurl',
  1489. 'article.author',
  1490. 'article.updated_at',
  1491. 'article.introduce',
  1492. 'article.islink',
  1493. 'article.linkurl',
  1494. 'article.copyfrom',
  1495. 'website_category.category_id',
  1496. 'website_category.alias',
  1497. 'website_category.aLIas_pinyin'
  1498. )
  1499. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1500. ->orderBy('article.updated_at', 'desc')
  1501. ->limit($parentTextNum)
  1502. ->get()
  1503. ->all();
  1504. if (empty($textArticles)) {
  1505. $textArticles = clone $baseQuery;
  1506. $textArticles = $textArticles->where('catid', $parentCatId)
  1507. ->select(
  1508. 'article.id',
  1509. 'article.title',
  1510. // 'article.imgurl',
  1511. 'article.author',
  1512. 'article.updated_at',
  1513. 'article.introduce',
  1514. 'article.islink',
  1515. 'article.linkurl',
  1516. 'article.copyfrom',
  1517. 'website_category.category_id',
  1518. 'website_category.alias',
  1519. 'website_category.aLIas_pinyin'
  1520. )
  1521. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1522. ->orderBy('article.updated_at', 'desc')
  1523. ->limit($parentTextNum)
  1524. ->get()
  1525. ->all();
  1526. }
  1527. // 查询图片新闻
  1528. $imgArticles = clone $baseQuery;
  1529. $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid', $child_category)
  1530. ->select(
  1531. 'article.id',
  1532. 'article.title',
  1533. 'article.imgurl',
  1534. 'article.author',
  1535. 'article.updated_at',
  1536. 'article.introduce',
  1537. 'article.islink',
  1538. 'article.linkurl',
  1539. 'article.copyfrom',
  1540. 'website_category.category_id',
  1541. 'website_category.alias',
  1542. 'website_category.aLIas_pinyin'
  1543. )
  1544. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1545. ->orderBy('article.updated_at', 'desc')
  1546. ->limit($parentImgNum)
  1547. ->get()
  1548. ->all();
  1549. if (empty($imgArticles)) {
  1550. $imgArticles = clone $baseQuery;
  1551. $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid', $parentCatId)
  1552. ->select(
  1553. 'article.id',
  1554. 'article.title',
  1555. 'article.imgurl',
  1556. 'article.author',
  1557. 'article.updated_at',
  1558. 'article.introduce',
  1559. 'article.islink',
  1560. 'article.linkurl',
  1561. 'article.copyfrom',
  1562. 'website_category.category_id',
  1563. 'website_category.alias',
  1564. 'website_category.aLIas_pinyin'
  1565. )
  1566. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1567. ->orderBy('article.updated_at', 'desc')
  1568. ->limit($parentImgNum)
  1569. ->get()
  1570. ->all();
  1571. }
  1572. }
  1573. $resultItem = [
  1574. 'alias' => $category ? $category->alias : null,
  1575. 'category_id' => $parentCatId,
  1576. 'pinyin' => $pinyin ? $pinyin : null,
  1577. 'imgnum' => $imgArticles ?? [],
  1578. 'textnum' => $textArticles ?? [],
  1579. ];
  1580. return $resultItem;
  1581. }, $data);
  1582. return Result::success($result);
  1583. }
  1584. // 封装处理商品的路由问题
  1585. function processGoods($goods, $data)
  1586. {
  1587. return $goods->map(function ($good) use ($data) {
  1588. $catid = $good->catid ?? 0;
  1589. // $pinyin = '';
  1590. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1591. if (!empty($category->pid) && $category->pid != 0) {
  1592. $level = json_decode($category->category_arr_id);
  1593. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1594. ->whereIn('category_id', $level)
  1595. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1596. ->get(['aLIas_pinyin'])
  1597. ->pluck('aLIas_pinyin')
  1598. ->implode('/');
  1599. } else {
  1600. $pinyin = $category->aLIas_pinyin ?? '';
  1601. }
  1602. if (isset($good->city_id) && !empty($good->city_id)) {
  1603. $city = District::where('id', $good->city_id)->first(['name']);
  1604. $good->city_name = $city->name ?? '';
  1605. }
  1606. // 解析imgurl JSON并取第一条数据
  1607. $imgUrls = json_decode($good->imgurl, true);
  1608. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1609. $good->pinyin = $pinyin;
  1610. return $good;
  1611. });
  1612. }
  1613. /**
  1614. * 获取商城首页-根据栏目id
  1615. * @param array $data
  1616. * @return array
  1617. * */
  1618. function getWebsiteCatidshop(array $data): array
  1619. {
  1620. $input['catid'] = $data['catid'];
  1621. $input['website_id'] = $data['website_id'];
  1622. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1623. $result = array_map(function ($item) use ($input) {
  1624. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1625. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1626. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1627. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1628. if (empty($category) || $category->type != 2) {
  1629. return Result::error("暂无此栏目", 0);
  1630. } else {
  1631. $website['website_id'] = $input['website_id'];
  1632. $goods = Good::where('good.status', 2)
  1633. ->where('good.website_id', $website['website_id'])
  1634. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1635. ->select(
  1636. 'good.id',
  1637. 'good.name',
  1638. 'good.imgurl',
  1639. 'good.description',
  1640. 'good.updated_at',
  1641. 'good.catid',
  1642. 'good.type_id',
  1643. 'good.price',
  1644. 'good.com',
  1645. 'good.level',
  1646. 'good.unit'
  1647. )
  1648. ->orderBy('updated_at', 'desc')
  1649. ->offset($goodStart)
  1650. ->limit($goodNum);
  1651. $all_goods = $goods->get();
  1652. $all_goods = $this->processGoods($all_goods, $website);
  1653. }
  1654. return $all_goods ?? [];
  1655. }
  1656. }, $data);
  1657. return Result::success($result);
  1658. }
  1659. /**
  1660. * 获取商品模块
  1661. * @param array $data
  1662. * @return array
  1663. * */
  1664. public function getWebsiteshop(array $data): array
  1665. {
  1666. $input['id'] = $data['id'];
  1667. $input['website_id'] = $data['website_id'];
  1668. $catid = $data['catid'];
  1669. $data = json_decode($input['id'] ?? '', true) ?? [];
  1670. $result['goods'] = array_map(function ($item) use ($input) {
  1671. // 检查parent元素是否存在且不是undefined
  1672. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  1673. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  1674. $website = $input['website_id'];
  1675. $query = Good::where('good.status', 2)
  1676. ->where('good.website_id', $website);
  1677. switch ($Levelid) {
  1678. case 1:
  1679. case 2:
  1680. case 3:
  1681. $goods = $query->where(function ($q) use ($Levelid) {
  1682. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  1683. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  1684. });
  1685. break;
  1686. case 4:
  1687. $goods = $query;
  1688. break;
  1689. case 5:
  1690. $goods = $query->where('type_id', 1);
  1691. break;
  1692. case 6:
  1693. $goods = $query->where('type_id', 2);
  1694. break;
  1695. default:
  1696. return [];
  1697. }
  1698. $all_goods = $goods
  1699. ->select(
  1700. 'good.id',
  1701. 'good.name',
  1702. 'good.imgurl',
  1703. 'good.description',
  1704. 'good.updated_at',
  1705. 'good.catid',
  1706. 'good.type_id',
  1707. 'good.price',
  1708. 'good.level',
  1709. 'good.website_id'
  1710. )
  1711. ->orderBy('updated_at', 'desc')
  1712. ->offset($goodStart)
  1713. ->limit($goodNum)
  1714. ->get();
  1715. $web['website_id'] = $website;
  1716. $all_goods = $this->processGoods($all_goods, $web);
  1717. }
  1718. return $all_goods;
  1719. }, $data);
  1720. $website = $input['website_id'];
  1721. $result['article'] = Article::where(function ($query) use ($website) {
  1722. $query->where(function ($subQuery) use ($website) {
  1723. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1724. })->orWhereNull("ignore_ids");
  1725. })
  1726. ->where('catid', $catid)
  1727. ->where('article.status', 1)
  1728. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  1729. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  1730. ->orderBy('article.updated_at', 'desc')
  1731. ->first();
  1732. return Result::success($result);
  1733. }
  1734. /**
  1735. * 获取商品分类
  1736. * @param array $data
  1737. * @return array
  1738. * */
  1739. public function getWebsiteshopCat(array $data): array
  1740. {
  1741. $website = $data['website_id'];
  1742. $category = WebsiteCategory::where('website_id', $website)
  1743. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  1744. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  1745. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  1746. ->orderBy('sort')
  1747. ->get();
  1748. $cat = $category->map(function ($item) use ($website) {
  1749. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  1750. $pid = $item->pid ?? 0;
  1751. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  1752. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  1753. ->where('website_id', $website)
  1754. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  1755. ->get(['aLIas_pinyin'])
  1756. ->pluck('aLIas_pinyin')
  1757. ->implode('/');
  1758. } else {
  1759. $pinyin = $item->aLIas_pinyin ?? '';
  1760. }
  1761. $item->pinyin = $pinyin;
  1762. });
  1763. if (empty($category)) {
  1764. return Result::error("栏目查询失败", 0);
  1765. }
  1766. $cat_tree = Result::buildMenuTree($category);
  1767. $web['website_id'] = $website;
  1768. $goods = Good::where('website_id', $website)
  1769. ->where('status', 2)
  1770. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  1771. ->latest('updated_at')
  1772. ->offset(($data['page'] - 1) * $data['pageSize'])
  1773. ->limit($data['pageSize'])
  1774. ->get();
  1775. if (!empty($goods)) {
  1776. if ($goods->count() > 1 && !empty($goods)) {
  1777. $goods = $this->processGoods($goods, $web);
  1778. }
  1779. } else {
  1780. $goods = [];
  1781. }
  1782. $result = [
  1783. 'category' => $cat_tree,
  1784. 'goods' => $goods,
  1785. ];
  1786. // $resul['goods'] = $goods;
  1787. if (empty($result)) {
  1788. return Result::error("查询失败", 0);
  1789. }
  1790. return Result::success($result);
  1791. }
  1792. /*
  1793. * 获取商品列表
  1794. * @param array $data
  1795. * @return array
  1796. * */
  1797. public function getWebsiteshopList(array $data): array
  1798. {
  1799. // return Result::success($data);
  1800. $where = [
  1801. 'status' => 2,
  1802. 'website_id' => $data['website_id'],
  1803. ];
  1804. if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  1805. return Result::error("查询失败", 0);
  1806. }
  1807. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  1808. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  1809. $data['catid'] = $category->category_id ?? 0;
  1810. }
  1811. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1812. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  1813. }
  1814. if (isset($data['type_id']) && !empty($data['type_id'])) {
  1815. array_push($where, ['type_id', $data['type_id']]);
  1816. }
  1817. $query = Good::where($where)
  1818. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  1819. $query->where(function ($q) use ($data) {
  1820. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  1821. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  1822. });
  1823. })
  1824. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  1825. $query->where(function ($q) use ($data) {
  1826. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  1827. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  1828. });
  1829. })
  1830. ->select(
  1831. 'good.id',
  1832. 'good.name',
  1833. 'good.imgurl',
  1834. 'good.description',
  1835. 'good.updated_at',
  1836. 'good.com',
  1837. 'good.catid',
  1838. 'good.type_id',
  1839. 'good.website_id',
  1840. 'good.cat_arr_id',
  1841. 'good.created_at',
  1842. 'good.city_id'
  1843. )
  1844. ->latest('updated_at');
  1845. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  1846. // 获取 type_id 为 1 的数据
  1847. $result['type1'] = $this->processGoods(
  1848. $query->clone()
  1849. ->where('type_id', 1)
  1850. ->offset(($data['page'] - 1) * $data['pageSize'])
  1851. ->limit($data['pageSize'])
  1852. ->get(),
  1853. $data
  1854. );
  1855. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  1856. // 获取 type_id 为 2 的数据
  1857. $result['type2'] = $this->processGoods(
  1858. $query->clone()
  1859. ->where('type_id', 2)
  1860. ->offset(($data['page'] - 1) * $data['pageSize'])
  1861. ->limit($data['pageSize'])
  1862. ->get(),
  1863. $data
  1864. );
  1865. if (empty($result)) {
  1866. return Result::error("查询失败", 0);
  1867. }
  1868. return Result::success($result);
  1869. }
  1870. /**
  1871. * 获取商品详情
  1872. * @param array $data
  1873. * @return array
  1874. * */
  1875. public function getWebsiteshopInfo(array $data): array
  1876. {
  1877. $where = [
  1878. 'good.status' => 2,
  1879. 'good.website_id' => $data['website_id'],
  1880. 'good.id' => $data['id'],
  1881. ];
  1882. $goods = Good::where($where)
  1883. ->where('good.id', $data['id'])
  1884. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  1885. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  1886. ->first();
  1887. if (empty($goods)) {
  1888. return Result::error("查询失败", 0);
  1889. }
  1890. $goods->imgurl = json_decode($goods->imgurl, true);
  1891. return Result::success($goods);
  1892. }
  1893. /**
  1894. * 封装处理文章的路由问题
  1895. * */
  1896. function processArticles($articles, $data)
  1897. {
  1898. // 检查 $articles 是否为数组或可迭代对象
  1899. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  1900. return $articles->map(function ($article) use ($data) {
  1901. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  1902. $catid = $article->cat_arr_id ?? '';
  1903. }
  1904. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  1905. $catid = $article->category_arr_id ?? '';
  1906. }
  1907. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  1908. $level = json_decode($catid, true);
  1909. if (!is_array($level)) {
  1910. return $article;
  1911. } else {
  1912. $level = array_map('intval', $level);
  1913. }
  1914. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1915. ->where($data)
  1916. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1917. ->pluck('aLIas_pinyin')
  1918. ->implode('/');
  1919. $article->pinyin = $pinyin ?? '';
  1920. return $article;
  1921. });
  1922. } else {
  1923. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  1924. $catid = $articles->cat_arr_id ?? '';
  1925. $level = json_decode($catid, true);
  1926. if (!is_array($level)) {
  1927. return $articles;
  1928. } else {
  1929. $level = array_map('intval', $level);
  1930. }
  1931. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1932. ->where($data)
  1933. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1934. ->pluck('aLIas_pinyin')
  1935. ->implode('/');
  1936. $articles->pinyin = $pinyin ?? '';
  1937. return $articles;
  1938. }
  1939. }
  1940. // 封装处理由问题
  1941. function processJob($job, $data)
  1942. {
  1943. return $job->map(function ($job) use ($data) {
  1944. $category = $job->cat_arr_id ?? '';
  1945. $cityid = $job->city_arr_id ?? '';
  1946. $city = json_decode($cityid, true);
  1947. $pinyin = '';
  1948. $level = json_decode($category, true);
  1949. // 路由
  1950. if (!empty($level) && is_array($level)) {
  1951. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1952. ->where('website_id', $data['website_id']) // 添加网站ID条件
  1953. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1954. ->get(['aLIas_pinyin'])
  1955. ->pluck('aLIas_pinyin')
  1956. ->implode('/');
  1957. if (empty($pinyin)) {
  1958. $pinyin = $pinyin->aLIas_pinyin ?? '';
  1959. }
  1960. $job->pinyin = $pinyin;
  1961. }
  1962. // 取职位-城市 市??省
  1963. if (!empty($city) && is_array($city)) {
  1964. if (isset($city[1]) && !empty($city[1])) {
  1965. $city = District::where('id', $city[1])->first(['name']);
  1966. $job->city_name = $city->name ?? '';
  1967. } else if (isset($city[0]) && !empty($city[0])) {
  1968. $city = District::where('id', $city[0])->first(['name']);
  1969. $job->city_name = $city->name ?? '';
  1970. } else {
  1971. $job->city_name = '全国';
  1972. }
  1973. }
  1974. // 获取简历最后一级地区
  1975. if (isset($job->city_id) && !empty($job->city_id)) {
  1976. $city = District::where('id', $job->city_id)->first(['name']);
  1977. $job->hunt_cityname = $city->name ?? '';
  1978. }
  1979. // 组合详细地址
  1980. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  1981. $address_id = json_decode($job->address_arr_id, true) ?? [];
  1982. if (is_array($address_id) && !empty($address_id)) {
  1983. $address = District::whereIn('id', $address_id)
  1984. ->orderBy('level', 'asc')
  1985. ->get(['name'])
  1986. ->pluck('name')
  1987. ->implode('');
  1988. // $job->address_name = $address ?? '';
  1989. $job->address_name = ($address ?? '') . ($job->address ?? '');
  1990. }
  1991. }
  1992. // 取行业
  1993. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  1994. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  1995. if (!empty($job->industry)) {
  1996. $query->where('hyid', $job->industry);
  1997. } else if (!empty($job->hy_id)) {
  1998. $query->where('hyid', $job->hy_id);
  1999. } else if (!empty($job->company_hy_id)) {
  2000. $query->where('hyid', $job->company_hy_id);
  2001. } else {
  2002. $query->where('hyid', $job->job_industry);
  2003. }
  2004. })->first(['hyname']);
  2005. $job->hy_name = $hy_name->hyname ?? '';
  2006. }
  2007. // 取职位类别
  2008. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2009. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2010. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2011. $job->zw_name = $zw_name->zwname ?? '';
  2012. }
  2013. // 取具体职位
  2014. 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))) {
  2015. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2016. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2017. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2018. }
  2019. // 取工作经验
  2020. if (isset($job->experience) && !empty($job->experience)) {
  2021. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2022. $job->experience_name = $experience->ename ?? '';
  2023. }
  2024. // 取学历
  2025. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2026. $education = $job->educational ?? $job->school_education;
  2027. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2028. $job->education_name = $education->ename ?? '';
  2029. }
  2030. // 语言
  2031. if (isset($job->language) && !empty($job->language)) {
  2032. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2033. $job->language_name = $language->ename ?? '';
  2034. }
  2035. // 薪资
  2036. if (isset($job->salary) && !empty($job->salary)) {
  2037. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2038. $job->salary_name = $salary->ename ?? '';
  2039. }
  2040. // 职位性质
  2041. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2042. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2043. $job->job_nature_name = $job_nature->ename ?? '';
  2044. }
  2045. // 公司规模
  2046. if (isset($job->company_size) && !empty($job->company_size)) {
  2047. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2048. $job->company_size_name = $company_size->ename ?? '';
  2049. }
  2050. // 公司性质
  2051. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2052. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2053. $job->company_nature_name = $company_nature->nature_name ?? '';
  2054. }
  2055. // $job->pinyin = $pinyin;
  2056. return $job;
  2057. });
  2058. }
  2059. /**
  2060. * 获取书籍模块
  2061. * @param array $data
  2062. * @return array
  2063. * */
  2064. public function getWebsiteBook(array $data): array
  2065. {
  2066. $input['id'] = $data['id'];
  2067. $input['website_id'] = $data['website_id'];
  2068. // 将 JSON 字符串转换为 PHP 数组
  2069. $data = json_decode($input['id'], true);
  2070. // 使用 array_map 处理每个元素
  2071. $result = array_map(function ($item) use ($input) {
  2072. // 检查parent元素是否存在且不是undefined
  2073. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2074. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2075. $website = [
  2076. 'website_id' => $input['website_id'],
  2077. ];
  2078. // 查询栏目名称
  2079. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2080. if (empty($category)) {
  2081. $parent_alias = '';
  2082. $parent_pinyin = null;
  2083. $imgBooks = [];
  2084. $textBooks = [];
  2085. } else {
  2086. $parent_alias = $category->alias ?? '';
  2087. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2088. // 查找子分类ID数组
  2089. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2090. array_push($childCategoryIds, $parentCatId);
  2091. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2092. if ($parentImgNum != 0) {
  2093. // 查询图片新闻
  2094. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2095. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2096. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2097. })
  2098. ->where('book.status', 2)
  2099. ->where('book.img_url', '!=', '')
  2100. ->leftJoin('website_category', function ($join) use ($website) {
  2101. $join->on('book.cat_id', '=', 'website_category.category_id')
  2102. ->where('website_category.website_id', '=', $website['website_id']);
  2103. })
  2104. ->select(
  2105. 'book.id',
  2106. 'book.title',
  2107. 'book.img_url',
  2108. 'book.price',
  2109. 'book.market_price',
  2110. 'book.description',
  2111. 'book.cat_id',
  2112. 'book.description',
  2113. 'book.updated_at',
  2114. 'website_category.alias as category_name',
  2115. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2116. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2117. )
  2118. ->orderBy('updated_at', 'desc')
  2119. ->limit($parentImgNum)
  2120. ->get()->all();
  2121. // 查询文字新闻
  2122. }
  2123. if ($parentTextNum != 0) {
  2124. $textBooks = [];
  2125. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2126. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2127. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2128. })
  2129. ->where('book.status', 2)
  2130. ->leftJoin('website_category', function ($join) use ($website) {
  2131. $join->on('book.cat_id', '=', 'website_category.category_id')
  2132. ->where('website_category.website_id', '=', $website['website_id']);
  2133. })
  2134. ->select(
  2135. 'book.id',
  2136. 'book.title',
  2137. 'book.img_url',
  2138. 'book.price',
  2139. 'book.market_price',
  2140. 'book.description',
  2141. 'book.cat_id',
  2142. 'book.description',
  2143. 'book.updated_at',
  2144. 'website_category.alias as category_name',
  2145. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2146. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2147. )
  2148. ->orderBy('updated_at', 'desc')
  2149. ->limit($parentTextNum)
  2150. ->get()->all();
  2151. }
  2152. }
  2153. }
  2154. $resultItem = [
  2155. 'alias' => $parent_alias ?? '',
  2156. 'category_id' => $parentCatId ?? 0,
  2157. 'pinyin' => $parent_pinyin ?? null,
  2158. 'imgnum' => $imgBooks ?? [],
  2159. 'textnum' => $textBooks ?? [],
  2160. ];
  2161. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2162. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2163. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2164. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2165. ->get()->all();
  2166. if (!empty($childCategory)) {
  2167. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2168. // 查询子栏目名称
  2169. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2170. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2171. ->first();
  2172. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2173. $childImgArticles = [];
  2174. $childTextArticles = [];
  2175. $resultItem['child'] = [];
  2176. } else {
  2177. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2178. // 查询子栏目图片新闻
  2179. $childImgArticles = Book::where('cat_id', $childCatId)
  2180. ->where('status', 2)
  2181. ->where('img_url', '!=', '')
  2182. ->leftJoin('website_category', function ($join) use ($website) {
  2183. $join->on('book.cat_id', '=', 'website_category.category_id')
  2184. ->where('website_category.website_id', '=', $website['website_id']);
  2185. })
  2186. ->select(
  2187. 'book.id',
  2188. 'book.title',
  2189. 'book.img_url',
  2190. 'book.price',
  2191. 'book.market_price',
  2192. 'book.description',
  2193. 'book.cat_id',
  2194. 'book.description',
  2195. 'book.updated_at',
  2196. DB::raw("'$child_pinyin' as pinyin")
  2197. )
  2198. ->orderBy('updated_at', 'desc')
  2199. ->limit($childImgNum)
  2200. ->get()->all();
  2201. // 查询子栏目文字新闻
  2202. $childTextArticles = Book::where('cat_id', $childCatId)
  2203. ->where('status', 2)
  2204. ->leftJoin('website_category', function ($join) use ($website) {
  2205. $join->on('book.cat_id', '=', 'website_category.category_id')
  2206. ->where('website_category.website_id', '=', $website['website_id']);
  2207. })
  2208. ->select(
  2209. 'book.id',
  2210. 'book.title',
  2211. 'book.img_url',
  2212. 'book.price',
  2213. 'book.market_price',
  2214. 'book.description',
  2215. 'book.cat_id',
  2216. 'book.description',
  2217. 'book.updated_at',
  2218. DB::raw("'$child_pinyin' as pinyin")
  2219. )
  2220. ->orderBy('updated_at', 'desc')
  2221. ->limit($childTextNum)
  2222. ->get()->all();
  2223. $resultItem['child'] = [
  2224. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2225. 'category_id' => $childCatId,
  2226. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2227. 'all_childcat' => $childCategory,
  2228. 'imgnum' => $childImgArticles,
  2229. 'textnum' => $childTextArticles,
  2230. ];
  2231. }
  2232. }
  2233. } else {
  2234. $resultItem['child'] = [];
  2235. }
  2236. return $resultItem;
  2237. }, $data);
  2238. return Result::success($result);
  2239. }
  2240. /**
  2241. * 获取书刊列表
  2242. * @param array $data
  2243. * @return array
  2244. * */
  2245. public function getWebsiteBookList(array $data): array
  2246. {
  2247. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2248. if (empty($web)) {
  2249. return Result::error("查询失败", 0);
  2250. }
  2251. $catid = $data['id'];
  2252. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2253. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2254. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2255. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2256. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2257. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2258. ->where('pid', $category['pid'])
  2259. ->select(
  2260. 'category_id',
  2261. 'alias',
  2262. 'aLIas_pinyin',
  2263. 'pid',
  2264. 'sort',
  2265. 'is_url',
  2266. 'web_url',
  2267. 'seo_title',
  2268. 'seo_keywords',
  2269. 'seo_description',
  2270. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2271. )
  2272. ->orderBy('sort')
  2273. ->get()->all();
  2274. if (empty($category)) {
  2275. return Result::error("查询失败", 0);
  2276. }
  2277. $query = Book::where('book.status', 2)
  2278. ->where('book.website_id', $data['website_id'])
  2279. ->where('book.cat_id', $catid)
  2280. ->select(
  2281. 'book.id',
  2282. 'book.title',
  2283. 'book.img_url',
  2284. 'book.description',
  2285. 'book.updated_at',
  2286. 'book.cat_id',
  2287. DB::raw("'$pinyin' as pinyin")
  2288. )
  2289. ->orderBy('book.updated_at', 'desc');
  2290. $count = $query->count();
  2291. $query = clone $query;
  2292. $Book = $query
  2293. ->limit($data['pageSize'])
  2294. ->offset(($data['page'] - 1) * $data['pageSize'])
  2295. ->get()->all();
  2296. $result = [
  2297. 'category' => $categorys,
  2298. 'books' => $Book,
  2299. 'count' => $count,
  2300. ];
  2301. // if(empty($result)){
  2302. // return Result::error("查询失败", 0);
  2303. // }
  2304. return Result::success($result);
  2305. }
  2306. /**
  2307. * 获取书刊详情
  2308. * @param array $data
  2309. * @return array
  2310. * */
  2311. public function getWebsiteBookInfo(array $data): array
  2312. {
  2313. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2314. if (empty($web)) {
  2315. return Result::error("查询失败", 0);
  2316. }
  2317. $book = Book::where('status', 2)
  2318. ->where('website_id', $data['website_id'])
  2319. ->where('id', $data['id'])
  2320. ->select(
  2321. 'book.*',
  2322. )
  2323. ->orderBy('updated_at', 'desc')
  2324. ->first();
  2325. if (empty($book)) {
  2326. return Result::error("查询失败", 0);
  2327. }
  2328. // 先查询当前分类的 pid
  2329. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2330. ->where('category_id', $book['cat_id'])
  2331. ->first(['pid', 'category_id']);
  2332. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2333. if (!empty($carpid)) {
  2334. if ($carpid->pid != 0) {
  2335. $pid = $carpid['pid'];
  2336. // $parent_pinyin = '';
  2337. } else {
  2338. $pid = $carpid['category_id'];
  2339. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2340. }
  2341. }
  2342. $categorys = $query->where('pid', $pid)
  2343. ->select(
  2344. 'category_id',
  2345. 'alias',
  2346. 'aLIas_pinyin',
  2347. 'pid',
  2348. 'sort',
  2349. 'is_url',
  2350. 'web_url',
  2351. 'category_arr_id as cat_arr_id',
  2352. )
  2353. ->orderBy('sort')
  2354. ->get();
  2355. $category = $this->processArticle($categorys, $data);
  2356. $result = [
  2357. 'category' => $category,
  2358. 'books' => $book,
  2359. ];
  2360. return Result::success($result);
  2361. }
  2362. /**
  2363. * 尝试
  2364. * @param array $data
  2365. * @return array
  2366. * */
  2367. public function test(array $data): array
  2368. {
  2369. $input['id'] = $data['id'];
  2370. $input['website_id'] = $data['website_id'];
  2371. // 将 JSON 字符串转换为 PHP 数组
  2372. $data = json_decode($input['id'], true);
  2373. $result = [];
  2374. $article = $data;
  2375. $result = array_map(function ($item) use ($input) {
  2376. $website = [
  2377. 'website_id' => $input['website_id'],
  2378. ];
  2379. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2380. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2381. $parent = [
  2382. 0 => $category['category_id'] ?? [],
  2383. 1 => $parentImgNum ?? [],
  2384. 2 => $parentTextNum ?? [],
  2385. ];
  2386. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2387. $child = [];
  2388. $resultItem = [
  2389. // 'alias' => $parent_alias ?? '',
  2390. 'category_id' => $parentCatId ?? 0,
  2391. 'pinyin' => $parentImgNum ?? null,
  2392. 'imgnum' => $parentTextNum ?? [],
  2393. // 'textnum' => $textArticles ?? [],
  2394. ];
  2395. return $parent;
  2396. }, $data);
  2397. return Result::success($result);
  2398. // });
  2399. }
  2400. /**
  2401. * 封装处理文章的路由问题
  2402. * */
  2403. function processArticle($article, $data)
  2404. {
  2405. return $article->map(function ($article) use ($data) {
  2406. $catid = $article->cat_arr_id ?? '';
  2407. $level = json_decode($catid, true);
  2408. $pinyin = '';
  2409. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2410. if (!empty($level) && is_array($level)) {
  2411. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2412. ->where('website_id', $data['website_id'])
  2413. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2414. ->get(['aLIas_pinyin'])
  2415. ->pluck('aLIas_pinyin')
  2416. ->implode('/');
  2417. } else {
  2418. $pinyin = '';
  2419. }
  2420. $article->pinyin = $pinyin;
  2421. return $article;
  2422. });
  2423. }
  2424. /**
  2425. * c端-获取招工招聘下拉选框
  2426. * @param array $data
  2427. * @return array
  2428. * */
  2429. public function getWebsiteJobSelect(array $data): array
  2430. {
  2431. $web = Website::where('id', $data['website_id'])->first();
  2432. if (empty($web)) {
  2433. return Result::error("该网站不存在", 0);
  2434. }
  2435. $hy = JobIndustry::get()->all();
  2436. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2437. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2438. $result = [
  2439. 'hy' => $hy,
  2440. 'zw' => $zw,
  2441. 'jtzw' => $jtzw,
  2442. ];
  2443. if (empty($result)) {
  2444. return Result::error("查询失败", 0);
  2445. }
  2446. return Result::success($result);
  2447. }
  2448. /**
  2449. * c端-获取招工招聘
  2450. * @param array $data
  2451. * @return array
  2452. * */
  2453. public function getWebsiteJob(array $data): array
  2454. {
  2455. $web = Website::where('id', $data['website_id'])->first();
  2456. if (empty($web)) {
  2457. return Result::error("该网站不存在", 0);
  2458. }
  2459. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2460. ->where('job_hunting.website_id', $data['website_id'])
  2461. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2462. $query->where(function ($q) use ($data) {
  2463. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2464. });
  2465. })
  2466. ->select(
  2467. 'job_hunting.id',
  2468. 'job_hunting.cat_arr_id',
  2469. 'job_hunting.job_name_get',
  2470. 'job_hunting.industry',
  2471. 'job_hunting.name',
  2472. 'job_hunting.sexy',
  2473. 'job_hunting.origin',
  2474. 'job_hunting.city_arr_id',
  2475. 'job_hunting.experience',
  2476. 'job_hunting.updated_at',
  2477. 'job_hunting.salary'
  2478. )
  2479. ->orderBy('updated_at', 'desc')
  2480. ->limit($data['job1_num'])
  2481. ->get();
  2482. $web['website_id'] = $data['website_id'];
  2483. if (empty($job_hunting)) {
  2484. $job_huntings = "未查询到相关简历信息";
  2485. } else {
  2486. $job_huntings = $this->processJob($job_hunting, $web);
  2487. }
  2488. // 0:待审核 1:已通过 2:已拒绝
  2489. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2490. ->where('job_recruiting.website_id', $data['website_id'])
  2491. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2492. $query->where(function ($q) use ($data) {
  2493. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2494. });
  2495. })
  2496. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2497. ->select(
  2498. 'job_recruiting.id',
  2499. 'job_recruiting.cat_arr_id',
  2500. 'job_recruiting.title',
  2501. 'job_recruiting.jtzw_id',
  2502. 'job_recruiting.hy_id',
  2503. 'job_recruiting.city_arr_id',
  2504. 'job_recruiting.due_data',
  2505. 'job_recruiting.updated_at',
  2506. 'job_recruiting.experience',
  2507. 'job_recruiting.educational',
  2508. 'job_recruiting.salary',
  2509. 'job_recruiting.zw_id',
  2510. 'job_company.business_name'
  2511. )
  2512. ->orderBy('updated_at', 'desc')
  2513. ->limit($data['job2_num'])
  2514. ->get();
  2515. if (empty($job_recruiting->toArray())) {
  2516. $job_recruitings = "未查询到相关职位信息";
  2517. } else {
  2518. $job_recruitings = $this->processJob($job_recruiting, $web);
  2519. }
  2520. $result = [
  2521. 'job_hunting' => $job_huntings,
  2522. 'job_recuiting' => $job_recruitings,
  2523. ];
  2524. return Result::success($result);
  2525. }
  2526. /**
  2527. * c端-获取招工招聘列表
  2528. * @param array $data
  2529. * @return array
  2530. * */
  2531. public function getWebsiteJobList(array $data): array
  2532. {
  2533. $recruit_where = [];
  2534. $hunt_where = [];
  2535. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2536. if (empty($web)) {
  2537. return Result::error("此网站不存在", 0);
  2538. }
  2539. $website_id['website_id'] = $data['website_id'];
  2540. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2541. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2542. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2543. }
  2544. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2545. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2546. }
  2547. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2548. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2549. }
  2550. $query = JobRecruiting::where('job_recruiting.status', 1)
  2551. ->where('job_recruiting.website_id', $data['website_id'])
  2552. ->where($recruit_where)
  2553. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2554. $query->where(function ($q) use ($data) {
  2555. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2556. });
  2557. })
  2558. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2559. $query->where(function ($q) use ($data) {
  2560. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2561. });
  2562. })
  2563. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2564. ->select(
  2565. 'job_recruiting.id',
  2566. 'job_recruiting.hy_id',
  2567. 'job_recruiting.title',
  2568. 'job_recruiting.zw_id',
  2569. 'job_recruiting.educational',
  2570. 'job_recruiting.jtzw_id',
  2571. 'job_recruiting.city_arr_id',
  2572. 'job_recruiting.due_data',
  2573. 'job_recruiting.experience',
  2574. 'job_recruiting.cat_arr_id',
  2575. 'job_recruiting.updated_at',
  2576. 'job_company.business_name'
  2577. )
  2578. ->orderBy('updated_at', 'desc');
  2579. $recruit_count = $query->count();
  2580. $query = clone $query;
  2581. $JobRecruiting = $query
  2582. ->offset(($data['page'] - 1) * $data['pageSize'])
  2583. ->limit($data['pageSize'])
  2584. ->get();
  2585. if (empty($JobRecruiting)) {
  2586. $JobRecruiting = "暂无相关职位信息";
  2587. } else {
  2588. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2589. }
  2590. }
  2591. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2592. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2593. array_push($hunt_where, ['job', $data['zw_id']]);
  2594. }
  2595. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2596. array_push($hunt_where, ['job_name_get', $data['jtzw_id']]);
  2597. }
  2598. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2599. array_push($hunt_where, ['industry', $data['hy_id']]);
  2600. }
  2601. $query = JobHunting::where('status', 2)
  2602. ->where('job_hunting.website_id', $data['website_id'])
  2603. ->where($hunt_where)
  2604. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2605. $query->where(function ($q) use ($data) {
  2606. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2607. });
  2608. })
  2609. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  2610. $query->where(function ($q) use ($data) {
  2611. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  2612. });
  2613. })
  2614. ->select('id', 'sexy', 'experience', 'origin', 'industry', 'name', 'job', 'job_name_get', 'city_arr_id', 'cat_arr_id', 'created_at', 'updated_at')
  2615. ->orderBy('updated_at', 'desc');
  2616. $hunt_count = $query->count();
  2617. $query = clone $query;
  2618. $JobHunting = $query
  2619. ->offset(($data['page'] - 1) * $data['pageSize'])
  2620. ->limit($data['pageSize'])
  2621. ->get();
  2622. if (empty($JobHunting)) {
  2623. $JobRecruiting = "暂无相关简历信息";
  2624. } else {
  2625. $JobHunting = $this->processJob($JobHunting, $website_id);
  2626. }
  2627. }
  2628. $result = [
  2629. 'JobRecruiting' => $JobRecruiting ?? [],
  2630. 'recruit_count' => $recruit_count ?? 0,
  2631. 'JobHunting' => $JobHunting ?? [],
  2632. 'hunt_count' => $hunt_count ?? 0,
  2633. ];
  2634. return Result::success($result);
  2635. }
  2636. /**
  2637. * c端-获取招工招聘详情
  2638. * @param array $data
  2639. * @return array
  2640. * */
  2641. public function getWebsiteJobInfo(array $data): array
  2642. {
  2643. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2644. if (empty($web)) {
  2645. return Result::error("该网站不存在", 0);
  2646. }
  2647. $webid = [
  2648. 'website_id' => $data['website_id'],
  2649. ];
  2650. // 职位相关信息
  2651. if ($data['type'] == 1) {
  2652. $query = JobRecruiting::where('status', 1)
  2653. ->where('website_id', $data['website_id'])
  2654. ->select('*');
  2655. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2656. $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();
  2657. if (!empty($company)) {
  2658. $result['company'] = $this->processJob($company, $webid);
  2659. }
  2660. $other_job = JobRecruiting::where('status', 1)
  2661. ->where('website_id', $data['website_id'])
  2662. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2663. ->where('id', '!=', $data['id'])
  2664. ->where('user_id', '=', $job[0]['user_id'])
  2665. ->limit($data['pageSize'])
  2666. ->get();
  2667. if (!empty($other_job)) {
  2668. $result['other_job'] = $this->processJob($other_job, $webid);
  2669. }
  2670. } else {
  2671. // 简历相关信息
  2672. $job = JobHunting::where('job_hunting.status', 2)
  2673. ->where('job_hunting.website_id', $data['website_id'])
  2674. ->where('job_hunting.id', $data['id'])
  2675. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2676. ->select('job_hunting.*', 'user_name')
  2677. ->get();
  2678. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  2679. if (!empty($resume->toArray())) {
  2680. $result['resume'] = 1;
  2681. } else {
  2682. $result['resume'] = 0;
  2683. }
  2684. }
  2685. if (empty($job->toArray())) {
  2686. return Result::error("id参数错误", 0);
  2687. }
  2688. if (!empty($job[0]['job_experience'])) {
  2689. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  2690. if (!empty($job_experience)) {
  2691. // $hy = [];
  2692. foreach ($job_experience as $key => $value) {
  2693. // $id = $value['id'];
  2694. $hy[$key] = $value['job_industry'];
  2695. $zw_id[$key] = $value['job_typename'];
  2696. $jtzw_id[$key] = $value['job_name'];
  2697. }
  2698. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  2699. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  2700. // 先将关联表转换为索引数组,提高查找效率
  2701. $hyLookup = [];
  2702. foreach ($hy_table as $item) {
  2703. $hyLookup[$item['hyid']] = $item['hyname'];
  2704. }
  2705. $zwLookup = [];
  2706. foreach ($zw_table as $item) {
  2707. $zwLookup[$item['zwid']] = $item['zwname'];
  2708. }
  2709. foreach ($job_experience as $key => &$value) {
  2710. // 处理行业名称
  2711. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  2712. $value['hy_name'] = $hyLookup[$hy[$key]];
  2713. }
  2714. // 处理职位名称
  2715. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  2716. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  2717. }
  2718. // 处理具体职位名称
  2719. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  2720. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  2721. }
  2722. }
  2723. // 释放引用,防止意外修改后续代码
  2724. unset($value);
  2725. }
  2726. $result['job_experience'] = $job_experience ?? [];
  2727. }
  2728. if (!empty($job[0]['education_experience'])) {
  2729. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  2730. if (!empty($education_experience)) {
  2731. foreach ($education_experience as $key => $value) {
  2732. // $id = $value['id'];
  2733. $education[$key] = $value['school_education'];
  2734. }
  2735. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  2736. // // 先将关联表转换为索引数组,提高查找效率
  2737. $educationLookup = [];
  2738. foreach ($education_table as $item) {
  2739. $educationLookup[$item['evalue']] = $item['ename'];
  2740. }
  2741. foreach ($education_experience as $key => &$value) {
  2742. // 处理学历名称
  2743. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  2744. $value['education_name'] = $educationLookup[$education[$key]];
  2745. }
  2746. }
  2747. }
  2748. $result['education_experience'] = $job_experience ?? [];
  2749. }
  2750. $result['job'] = $this->processJob($job, $webid);
  2751. // // 返现对应的栏目
  2752. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  2753. $category = WebsiteCategory::where('website_id', $data['website_id'])
  2754. ->whereIn('category_id', $catid)
  2755. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  2756. ->orderBy('pid')->get()->all();
  2757. if (!empty($category)) {
  2758. $result['category'] = $category;
  2759. }
  2760. $result['job'] = $job;
  2761. $result['job_experience'] = $job_experience ?? [];
  2762. $result['education_experience'] = $education_experience ?? [];
  2763. if (empty($result)) {
  2764. return Result::error("参数错误", 0);
  2765. }
  2766. return Result::success($result);
  2767. }
  2768. /**
  2769. * c端-申请职位
  2770. * @param array $data
  2771. * @return array
  2772. * */
  2773. public function getWebsiteJobApply(array $data): array
  2774. {
  2775. // 首先验证网站是否存在
  2776. // return Result::success($data);
  2777. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2778. if (empty($web)) {
  2779. return Result::error("该网站不存在", 0);
  2780. }
  2781. // 验证用户是否存在且为个人会员/管理员
  2782. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2783. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2784. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  2785. return Result::error("用户不存在", 0);
  2786. }
  2787. // 去除重复元素和空元素,并保持原始顺序
  2788. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  2789. return !empty($value);
  2790. }));
  2791. // 验证职位是否存在 1:审核通过
  2792. $recruiting = JobRecruiting::where('status', 1)
  2793. ->where('website_id', $data['website_id'])
  2794. ->whereIn('id', $data['recruit_id'])
  2795. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  2796. if (empty($recruiting)) {
  2797. return Result::error("该职位不存在", 0);
  2798. }
  2799. // 简历是否存在
  2800. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  2801. if (empty($hunt_id)) {
  2802. return Result::error("该简历不存在", 0);
  2803. }
  2804. $data['hunt_id'] = $hunt_id['hunt_id'];
  2805. // // 验证是否已投递过该职位
  2806. $apply = JobApply::where('user_id', $data['user_id'])
  2807. ->where('hunt_id', $data['hunt_id'])
  2808. ->where('website_id', $data['website_id'])
  2809. ->whereIn('recruit_id', $data['recruit_id'])
  2810. ->get(['recruit_id']);
  2811. if (!empty($apply->toArray())) {
  2812. return Result::error("您已投递过该职位!");
  2813. }
  2814. $insertData = array_map(function ($recruiting) use ($data) {
  2815. return [
  2816. 'user_id' => $data['user_id'],
  2817. 'hunt_id' => $data['hunt_id'],
  2818. 'website_id' => $data['website_id'],
  2819. 'recruit_id' => $recruiting['recruit_id'],
  2820. 'receiver_id' => $recruiting['receiver_id'],
  2821. 'status' => 1,
  2822. ];
  2823. }, $recruiting);
  2824. // 批量插入数据
  2825. $result = JobApply::insert($insertData);
  2826. if (empty($result)) {
  2827. return Result::error("投递失败", 0);
  2828. }
  2829. return Result::success($result);
  2830. }
  2831. /**
  2832. * 招工招聘-沟通简历
  2833. * @param array $data
  2834. * @return array
  2835. * */
  2836. public function getWebsiteJobResume(array $data): array
  2837. {
  2838. // 首先验证网站是否存在
  2839. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2840. if (empty($web)) {
  2841. return Result::error("该网站不存在", 0);
  2842. }
  2843. // return Result::success($data);
  2844. // 验证用户是否存在且为企业会员/管理员
  2845. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2846. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2847. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2848. return Result::error("用户不存在", 0);
  2849. }
  2850. // 去除重复元素和空元素,并保持原始顺序
  2851. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  2852. return !empty($value);
  2853. }));
  2854. // 验证简历是否存在
  2855. $hunting = JobHunting::where('status', 2)
  2856. ->where('website_id', $data['website_id'])
  2857. ->whereIn('id', $data['hunt_id'])
  2858. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  2859. if (empty($hunting)) {
  2860. return Result::error("该简历不存在", 0);
  2861. }
  2862. // 验证是否已沟通过该简历
  2863. $remuse = JobRemuse::where('user_id', $data['user_id'])
  2864. ->where('recruit_id', $data['recruit_id'])
  2865. ->where('website_id', $data['website_id'])
  2866. ->whereIn('hunt_id', $data['hunt_id'])
  2867. ->get(['hunt_id']);
  2868. if (!empty($remuse->toArray())) {
  2869. return Result::error("您已沟通过该简历!");
  2870. }
  2871. // 准备要插入的数据数组
  2872. $insertData = array_map(function ($hunting) use ($data) {
  2873. return [
  2874. 'user_id' => $data['user_id'],
  2875. 'recruit_id' => $data['recruit_id'],
  2876. 'website_id' => $data['website_id'],
  2877. 'hunt_id' => $hunting['hunt_id'],
  2878. 'receiver_id' => $hunting['receiver_id'],
  2879. 'status' => 1,
  2880. ];
  2881. }, $hunting);
  2882. // 批量插入数据
  2883. $result = JobRemuse::insert($insertData);
  2884. if (empty($result)) {
  2885. return Result::error("沟通失败", 0);
  2886. }
  2887. return Result::success($result);
  2888. }
  2889. /**
  2890. * 招工招聘 -我的职位(企业会员)
  2891. * @param array $data
  2892. * @return array
  2893. */
  2894. public function getWebsiteJobRecruiting(array $data): array
  2895. {
  2896. $web = Website::where('id', $data['website_id'])->first('id');
  2897. if (empty($web)) {
  2898. return Result::error("该网站不存在", 0);
  2899. }
  2900. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2901. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2902. return Result::error("用户暂无权限!", 0);
  2903. }
  2904. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  2905. $result = JobRecruiting::where('website_id', $data['website_id'])
  2906. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  2907. $query->where('user_id', $user['id']);
  2908. })
  2909. ->where('status', 1)
  2910. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  2911. ->orderBy('updated_at', 'desc')
  2912. ->limit($data['pageSize'])
  2913. ->get();
  2914. if (empty($result)) {
  2915. return Result::error("暂无相关职位信息", 0);
  2916. }
  2917. return Result::success($result);
  2918. }
  2919. /**
  2920. * c端 - 验证路由
  2921. * @param array $data
  2922. * @return array
  2923. */
  2924. /**
  2925. * c端 - 验证路由
  2926. * @param array $data
  2927. * @return array
  2928. */
  2929. public function checkWebsiteRoute(array $data): array
  2930. {
  2931. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2932. if (empty($web)) {
  2933. return Result::error("该网站不存在", 0);
  2934. }
  2935. if (isset($data['other_route']) && !empty($data['other_route'])) {
  2936. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  2937. if (empty($whiteRouterInfo)) {
  2938. return Result::error("非法路径地址", 0);
  2939. } else {
  2940. return Result::success($whiteRouterInfo->toArray());
  2941. }
  2942. } else {
  2943. // 验证栏目路由
  2944. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  2945. ->where('aLIas_pinyin', $data['last_route'])
  2946. ->first();
  2947. if (empty($last_category)) {
  2948. return Result::error("该栏目不存在", 0);
  2949. }
  2950. if (isset($data['id']) && !empty($data['id'])) {
  2951. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  2952. switch ($last_category['type']) {
  2953. case 1:
  2954. // 文章
  2955. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  2956. $article = Article::where('status', 1)
  2957. ->where('id', $data['id'])
  2958. ->where(function ($query) use ($data) {
  2959. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  2960. ->orWhereNull("ignore_ids");
  2961. })
  2962. ->first(['cat_arr_id']);
  2963. if (empty($article)) {
  2964. return Result::error("该文章不存在", 0);
  2965. }
  2966. // return Result::success($article);
  2967. break;
  2968. case 2:
  2969. // 商品
  2970. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  2971. $article = Good::where('website_id', $data['website_id'])
  2972. ->where('status', 2)
  2973. ->where('id', $data['id'])
  2974. ->first(['cat_arr_id']);
  2975. if (empty($article)) {
  2976. return Result::error("该商品不存在", 0);
  2977. }
  2978. break;
  2979. case 3:
  2980. // 书刊信息
  2981. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  2982. $article = Book::where('website_id', $data['website_id'])
  2983. ->where('status', 2)
  2984. ->where('id', $data['id'])
  2985. ->first(['id', 'cat_arr_id']);
  2986. if (empty($article)) {
  2987. return Result::error("该书刊不存在", 0);
  2988. }
  2989. break;
  2990. case 4:
  2991. // 招聘
  2992. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核;(只有企业会员需要审核)',
  2993. $article = JobRecruiting::where('website_id', $data['website_id'])
  2994. ->where('status', 1)
  2995. ->where('id', $data['id'])
  2996. ->first(['cat_arr_id']);
  2997. if (empty($article)) {
  2998. return Result::error("该招聘不存在", 0);
  2999. }
  3000. break;
  3001. case 5:
  3002. // 求职
  3003. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3004. $article = JobHunting::where('website_id', $data['website_id'])
  3005. ->where('status', 2)
  3006. ->where('id', $data['id'])
  3007. ->first(['cat_arr_id']);
  3008. if (empty($article)) {
  3009. return Result::error("该求职不存在", 0);
  3010. }
  3011. break;
  3012. case 6:
  3013. // 招工招聘
  3014. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3015. $article = JobRecruiting::where('website_id', $data['website_id'])
  3016. ->where('status', 1)
  3017. ->where('id', $data['id'])
  3018. ->first(['cat_arr_id']);
  3019. if (empty($article)) {
  3020. $article = JobHunting::where('website_id', $data['website_id'])
  3021. ->where('status', 2)
  3022. ->where('id', $data['id'])
  3023. ->first(['cat_arr_id']);
  3024. }
  3025. if (empty($article)) {
  3026. return Result::error("该招工招聘不存在", 0);
  3027. }
  3028. break;
  3029. default:
  3030. return Result::error("该数据不存在", 0);
  3031. break;
  3032. }
  3033. $catid = json_decode($article['cat_arr_id'], true);
  3034. if (empty($catid)) {
  3035. return Result::error("该数据不存在", 0);
  3036. }
  3037. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3038. ->orderByRaw('FIELD(category_id, ' . implode(',', $catid) . ')')
  3039. ->whereIn('category_id', $catid)
  3040. ->pluck('aLIas_pinyin')
  3041. ->implode('/');
  3042. }
  3043. if ($last_category['pid'] != 0) {
  3044. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3045. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3046. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr) . ')')
  3047. ->whereIn('category_id', $cat_arr)
  3048. ->pluck('aLIas_pinyin')
  3049. ->implode('/');
  3050. } else {
  3051. $pinyin = $last_category['aLIas_pinyin'];
  3052. }
  3053. if (empty($pinyin) || $pinyin != $data['all_route']) {
  3054. return Result::error('非法路径!');
  3055. } else {
  3056. return Result::success($pinyin);
  3057. }
  3058. }
  3059. }
  3060. /**
  3061. * 招工招聘 - 获取推荐职位
  3062. * @param array $data
  3063. * @return array
  3064. */
  3065. public function getWebsiteLevelJob(array $data): array
  3066. {
  3067. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3068. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3069. ->where('job_recruiting.status', 1)
  3070. ->where('job_level', $data['job_level'])
  3071. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3072. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3073. ->orderBy('job_recruiting.updated_at', 'desc')
  3074. ->limit($data['pageSize'])
  3075. ->get();
  3076. $web = ['website_id' => $data['website_id']];
  3077. if (!empty($job)) {
  3078. $result = $this->processJob($job, $web);
  3079. }
  3080. if (empty($result)) {
  3081. return Result::error("暂无相关职位信息", 0);
  3082. }
  3083. return Result::success($result);
  3084. }
  3085. /**
  3086. * 验证导航名称是否重复
  3087. * @return void
  3088. */
  3089. //20250226 产品列表
  3090. public function getGoodList(array $data): array
  3091. {
  3092. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3093. unset($data['type_id']);
  3094. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3095. $where = [];
  3096. if ($type_id != '10000') {
  3097. $where = [
  3098. 'good.user_id' => $user_id,
  3099. ];
  3100. }
  3101. //类型
  3102. if (isset($data['type_id']) && $data['type_id']) {
  3103. $where = [
  3104. 'type_id' => $data['type_id'],
  3105. ];
  3106. }
  3107. //名称
  3108. if (isset($data['name']) && $data['name']) {
  3109. $where = [
  3110. 'good.name' => $data['name'],
  3111. ];
  3112. }
  3113. //status
  3114. if (isset($data['status']) && $data['status'] != '') {
  3115. $where = [
  3116. 'good.status' => $data['status'],
  3117. ];
  3118. }
  3119. //status1
  3120. // if (isset($data['status1']) && $data['status1'] == 1) {
  3121. // $status1 = 1;
  3122. // }
  3123. $where1 = [];
  3124. //website_id
  3125. // if (isset($data['website_id']) && $data['website_id']) {
  3126. // $where1 = [
  3127. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3128. // ];
  3129. // }
  3130. // website_name
  3131. if (isset($data['website_name']) && $data['website_name']) {
  3132. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3133. }
  3134. // catid
  3135. if (isset($data['category_name']) && $data['category_name']) {
  3136. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3137. }
  3138. // $result = Good::where($where)
  3139. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3140. $result = Good::where($where)
  3141. ->when(!empty($where1), function ($query) use ($where1) {
  3142. return $query->where($where1);
  3143. })
  3144. //status 1待审核2已审核3已拒绝
  3145. ->when(isset($data['status1']), function ($query) {
  3146. return $query->whereIn('good.status', [1, 3]);
  3147. })
  3148. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3149. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3150. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3151. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3152. ->orderBy("updated_at", "desc")
  3153. ->limit($data['page_size'])
  3154. ->offset(($data['page'] - 1) * $data['page_size'])
  3155. ->get();
  3156. $count = Good::where($where)
  3157. ->when(!empty($where1), function ($query) use ($where1) {
  3158. return $query->where($where1);
  3159. })
  3160. //status 1待审核2已审核3已拒绝
  3161. ->when(isset($data['status1']), function ($query) {
  3162. return $query->whereIn('good.status', [1, 3]);
  3163. })
  3164. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3165. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3166. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3167. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3168. ->orderBy("updated_at", "desc")->count();
  3169. $data = [
  3170. 'rows' => $result->toArray(),
  3171. 'count' => $count,
  3172. ];
  3173. if (empty($result)) {
  3174. return Result::error("此栏目暂无相关产品", 0);
  3175. }
  3176. return Result::success($data);
  3177. }
  3178. public function getGoodInfo(array $data): array
  3179. {
  3180. $result = Good::where('id', $data['id'])->first();
  3181. if (empty($result)) {
  3182. return Result::error("此产品不存在", 0);
  3183. }
  3184. return Result::success($result);
  3185. }
  3186. public function addGood(array $data): array
  3187. {
  3188. // unset($data['city_arr_id']);
  3189. // unset($data['cat_arr_id']);
  3190. $data['city_id'] = end($data['city_arr_id']);
  3191. $data['catid'] = end($data['cat_arr_id']);
  3192. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3193. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3194. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3195. unset($data['imgUrl']); //大小写
  3196. if (isset($data['price']) && $data['price'] == '') {
  3197. $data['price'] = 0;
  3198. }
  3199. if ($data['imgurl'] == '') {
  3200. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3201. preg_match_all($reg, $data['detail'], $matches);
  3202. if (isset($matches[1][0])) {
  3203. //截取varchar240
  3204. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3205. }
  3206. }
  3207. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3208. //提取标题+内容中的关键词
  3209. $data['keyword'] = $data['name'];
  3210. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3211. Jieba::init(); // 初始化 jieba-php
  3212. Finalseg::init();
  3213. $segList = Jieba::cut($data['keyword']);
  3214. $segList1 = array_slice($segList, 0, 8);
  3215. $data['keyword'] = implode(',', $segList1);
  3216. }
  3217. if ($data['description'] == '') {
  3218. //提取内容中的描述
  3219. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3220. }
  3221. $result = Good::insert($data);
  3222. if (empty($result)) {
  3223. return Result::error("添加失败", 0);
  3224. }
  3225. return Result::success($result);
  3226. }
  3227. public function updateGood(array $data): array
  3228. {
  3229. $data['city_id'] = end($data['city_arr_id']);
  3230. $data['catid'] = end($data['cat_arr_id']);
  3231. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3232. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3233. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3234. //设置东八区
  3235. date_default_timezone_set('Asia/Shanghai');
  3236. $data['updated_at'] = date('Y-m-d H:i:s');
  3237. if (isset($data['price']) && $data['price'] == '') {
  3238. $data['price'] = 0;
  3239. }
  3240. if ($data['imgurl'] == '') {
  3241. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3242. preg_match_all($reg, $data['detail'], $matches);
  3243. if (isset($matches[1][0])) {
  3244. //截取varchar240
  3245. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3246. }
  3247. }
  3248. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3249. //提取标题+内容中的关键词
  3250. $data['keyword'] = $data['name'];
  3251. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3252. Jieba::init(); // 初始化 jieba-php
  3253. Finalseg::init();
  3254. $segList = Jieba::cut($data['keyword']);
  3255. $segList1 = array_slice($segList, 0, 8);
  3256. $data['keyword'] = implode(',', $segList1);
  3257. }
  3258. if ($data['description'] == '') {
  3259. //提取内容中的描述
  3260. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3261. }
  3262. $result = Good::where('id', $data['id'])->update($data);
  3263. if (empty($result)) {
  3264. return Result::error("更新失败", 0);
  3265. }
  3266. return Result::success($result);
  3267. }
  3268. public function delGood(array $data): array
  3269. {
  3270. $result = Good::where('id', $data['id'])->delete();
  3271. if (empty($result)) {
  3272. return Result::error("删除失败", 0);
  3273. }
  3274. return Result::success($result);
  3275. }
  3276. //20250226 产品列表
  3277. //20250306 求职信息
  3278. public function getJobHuntingList(array $data): array
  3279. {
  3280. $where = [];
  3281. if (isset($data['username']) && !empty($data['username'])) {
  3282. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3283. }
  3284. //status 1待审核2已审核3已拒绝
  3285. if (isset($data['status']) && $data['status'] != '') {
  3286. $where = [
  3287. 'job_hunting.status' => $data['status'],
  3288. ];
  3289. }
  3290. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3291. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3292. unset($data['type_id']);
  3293. if ($type_id != '10000') {
  3294. $where[] = ['job_hunting.user_id', '=', $user_id];
  3295. }
  3296. $result = JobHunting::where($where)
  3297. ->when(!empty($data['status1']), function ($query) use ($data) {
  3298. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3299. })
  3300. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3301. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3302. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3303. ->orderBy("updated_at", "desc")
  3304. ->limit($data['page_size'])
  3305. ->offset(($data['page'] - 1) * $data['page_size'])
  3306. ->get();
  3307. if (empty($result)) {
  3308. return Result::error("查询失败", 0);
  3309. }
  3310. $count = JobHunting::where($where)
  3311. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3312. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3313. ->count();
  3314. $data = [
  3315. 'rows' => $result->toArray(),
  3316. 'count' => $count,
  3317. ];
  3318. return Result::success($data);
  3319. }
  3320. public function getJobHuntingApply(array $data): array
  3321. {
  3322. var_dump($data, '-----------------test--------1-');
  3323. $where = [];
  3324. if (isset($data['username']) && !empty($data['username'])) {
  3325. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3326. }
  3327. if (isset($data['salary']) && !empty($data['salary'])) {
  3328. $where[] = [
  3329. 'job_hunting.salary',
  3330. '=',
  3331. $data['salary'],
  3332. ];
  3333. }
  3334. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3335. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3336. unset($data['type_id']);
  3337. if ($type_id != '10000') {
  3338. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3339. }
  3340. var_dump($where, '-----------------test---------');
  3341. $result = jobApply::where($where)
  3342. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3343. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3344. // })
  3345. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3346. ->where('job_enum.egroup', '=', 'income')
  3347. ->where('job_hunting.status', 2) //已审核
  3348. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3349. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3350. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3351. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3352. //职位----是申请职位
  3353. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3354. ->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')
  3355. ->orderBy("job_hunting.updated_at", "desc")
  3356. ->limit($data['page_size'])
  3357. ->offset(($data['page'] - 1) * $data['page_size'])
  3358. ->get();
  3359. if (empty($result)) {
  3360. return Result::error("查询失败", 0);
  3361. }
  3362. $count = jobApply::where($where)
  3363. ->where('job_enum.egroup', '=', 'income')
  3364. ->where('job_hunting.status', 2) //已审核
  3365. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3366. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3367. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3368. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3369. //职位----是申请职位
  3370. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3371. ->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')
  3372. ->count();
  3373. $data = [
  3374. 'rows' => $result->toArray(),
  3375. 'count' => $count,
  3376. ];
  3377. return Result::success($data);
  3378. }
  3379. public function addJobHunting(array $data): array
  3380. {
  3381. date_default_timezone_set('Asia/Shanghai');
  3382. unset($data['company_name']);
  3383. unset($data['job_industry']);
  3384. unset($data['job_name']);
  3385. unset($data['department']);
  3386. unset($data['job_timeList']);
  3387. unset($data['job_content']);
  3388. unset($data['job_typename']); //不知道这是啥,
  3389. $data['created_at'] = date('Y-m-d H:i:s');
  3390. $data['updated_at'] = date('Y-m-d H:i:s');
  3391. //根据用户 user_id 只能添加一次
  3392. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3393. if (!empty($result)) {
  3394. return Result::error("您已添加过求职信息", 0);
  3395. }
  3396. var_dump($result, '-----------------test---------');
  3397. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3398. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3399. $cityArr = json_decode($data['city_arr_id'], true);
  3400. $data['city_id'] = end($cityArr);
  3401. } else {
  3402. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3403. $data['city_id'] = end($data['city_arr_id']);
  3404. }
  3405. $result = JobHunting::create($data);
  3406. if (empty($result)) {
  3407. return Result::error("添加失败", 0);
  3408. }
  3409. return Result::success($result);
  3410. }
  3411. public function delJobHunting(array $data): array
  3412. {
  3413. $result = JobHunting::where('id', $data['id'])->delete();
  3414. if (empty($result)) {
  3415. return Result::error("删除失败", 0);
  3416. }
  3417. return Result::success($result);
  3418. }
  3419. public function updateJobHunting(array $data): array
  3420. {
  3421. //设置东八区
  3422. date_default_timezone_set('Asia/Shanghai');
  3423. unset($data['company_name']);
  3424. unset($data['job_industry']);
  3425. unset($data['job_name']);
  3426. unset($data['department']);
  3427. unset($data['job_timeList']);
  3428. unset($data['job_content']);
  3429. unset($data['job_typename']); //不知道这是啥,
  3430. $data['created_at'] = date('Y-m-d H:i:s');
  3431. $data['updated_at'] = date('Y-m-d H:i:s');
  3432. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3433. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3434. $cityArr = json_decode($data['city_arr_id'], true);
  3435. $data['city_id'] = end($cityArr);
  3436. } else {
  3437. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3438. $data['city_id'] = end($data['city_arr_id']);
  3439. }
  3440. $result = JobHunting::where('id', $data['id'])->update($data);
  3441. if (empty($result)) {
  3442. return Result::error("更新失败", 0);
  3443. }
  3444. return Result::success($result);
  3445. }
  3446. public function getJobHuntingInfo(array $data): array
  3447. {
  3448. $result = JobHunting::where('id', $data['id'])->first();
  3449. if (empty($result)) {
  3450. return Result::error("查询失败", 0);
  3451. }
  3452. return Result::success($result);
  3453. }
  3454. public function getJobHuntingData(array $data): array
  3455. {
  3456. $jobEnum = JobEnum::get();
  3457. $jobIndustry = JobIndustry::get();
  3458. $jobNature = JobNature::get();
  3459. $jobPosition = JobPosition::get();
  3460. $data = [
  3461. 'jobEnum' => $jobEnum,
  3462. 'jobIndustry' => $jobIndustry,
  3463. 'jobNature' => $jobNature,
  3464. 'jobPosition' => $jobPosition,
  3465. ];
  3466. return Result::success($data);
  3467. }
  3468. public function delJobHuntingInfo(array $data): array
  3469. {
  3470. $result = JobHunting::where('id', $data['id'])->delete();
  3471. return Result::success();
  3472. }
  3473. //20250324 通知,公告,消息
  3474. public function delNotice(array $data): array
  3475. {
  3476. $result = Notice::where('id', $data['id'])->delete();
  3477. if ($result) {
  3478. return Result::success();
  3479. } else {
  3480. return Result::error("删除失败", 0);
  3481. }
  3482. }
  3483. public function getNoticeInfo(array $data): array
  3484. {
  3485. $result = Notice::where('id', $data['id'])->first();
  3486. if (empty($result)) {
  3487. return Result::error("查询失败", 0);
  3488. }
  3489. return Result::success($result);
  3490. }
  3491. public function addNotice(array $data): array
  3492. {
  3493. date_default_timezone_set('Asia/Shanghai');
  3494. $data['created_at'] = date('Y-m-d H:i:s');
  3495. $data['updated_at'] = date('Y-m-d H:i:s');
  3496. $user_id = UserInfo::
  3497. //city_id不是null
  3498. whereNotNull('city_id')
  3499. ->whereNotNull('department_id')
  3500. ->where(function ($query) use ($data) {
  3501. $query->where(function ($subQuery) use ($data) {
  3502. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3503. });
  3504. })
  3505. ->where(function ($query) use ($data) {
  3506. $query->where(function ($subQuery) use ($data) {
  3507. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3508. });
  3509. })
  3510. ->pluck('user_id')->toArray();
  3511. $user_id = array_unique($user_id);
  3512. $chat_ids = $user_id;
  3513. $user_id = json_encode($user_id);
  3514. $data['re_user_ids'] = $user_id;
  3515. $result = Notice::insertGetId($data);
  3516. if ($result && $data['is_group'] == 1) {
  3517. //chat_group
  3518. $group_id = PublicData::uuid();
  3519. $groupData = [
  3520. 'id' => $group_id,
  3521. 'creator_id' => $data['user_id'],
  3522. 'group_name' => $data['group_name'] ?? '',
  3523. 'profile' => $data['profile'] ?? 0,
  3524. ];
  3525. var_dump($groupData, '-----------------groupData-------');
  3526. $groupResult = ChatGroups::insertGetId($groupData);
  3527. var_dump($groupResult, '-----------------groupid-------');
  3528. $groupMemberData = [
  3529. 'id' => PublicData::uuid(),
  3530. 'user_id' => $data['user_id'],
  3531. 'group_id' => $group_id,
  3532. 'leader' => 2,
  3533. ];
  3534. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  3535. //$chat_ids 去除掉$data['user_id']
  3536. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  3537. //插入群成员表
  3538. $groupMemberDataUser = [];
  3539. $chatData = [];
  3540. foreach ($chat_ids as $key => $value) {
  3541. $groupMemberDataUser[] = [
  3542. 'id' => PublicData::uuid(),
  3543. 'user_id' => $value,
  3544. 'group_id' => $group_id,
  3545. 'leader' => 1,
  3546. ];
  3547. $chatData[] = [
  3548. 'user_id' => $value,
  3549. 'msg_type' => 1,
  3550. 'receiver_id' => $group_id,
  3551. 'content' => '通过通知创建群聊',
  3552. 'group_receiver_id' => $data['user_id'],
  3553. 'action' => 'recieved',
  3554. 'created_at' => date('Y-m-d H:i:s'),
  3555. ];
  3556. }
  3557. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  3558. ChatGroupsMember::insert($groupMemberDataUser);
  3559. //插入一条管理员聊天记录
  3560. $chatData[] = [
  3561. 'user_id' => $data['user_id'],
  3562. 'msg_type' => 1,
  3563. 'receiver_id' => $group_id,
  3564. 'content' => '通过通知创建群聊',
  3565. 'group_receiver_id' => $data['user_id'],
  3566. 'action' => 'said',
  3567. 'created_at' => date('Y-m-d H:i:s'),
  3568. ];
  3569. var_dump($chatData, '-----------------chatData-------');
  3570. $chatResult = ChatRecords::insert($chatData);
  3571. //更新result的 group_id
  3572. $data['group_id'] = $group_id;
  3573. Notice::where(['id' => $result])->update($data);
  3574. }
  3575. if (empty($result)) {
  3576. return Result::error("添加失败", 0);
  3577. }
  3578. return Result::success($result);
  3579. }
  3580. public function updateNotice(array $data): array
  3581. {
  3582. date_default_timezone_set('Asia/Shanghai');
  3583. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  3584. $user_id = UserInfo::
  3585. //city_id不是null
  3586. whereNotNull('city_id')
  3587. ->whereNotNull('department_id')
  3588. ->where(function ($query) use ($data) {
  3589. $query->where(function ($subQuery) use ($data) {
  3590. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3591. });
  3592. })
  3593. ->where(function ($query) use ($data) {
  3594. $query->where(function ($subQuery) use ($data) {
  3595. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3596. });
  3597. })
  3598. ->pluck('user_id')->toArray();
  3599. $user_id = array_unique($user_id);
  3600. $user_id = json_encode($user_id);
  3601. $data['re_user_ids'] = $user_id;
  3602. $data['updated_at'] = date('Y-m-d H:i:s');
  3603. $result = Notice::where('id', $data['id'])->update($data);
  3604. return Result::success($result);
  3605. }
  3606. public function getNoticeList(array $data): array
  3607. {
  3608. $where = [];
  3609. //title
  3610. if (isset($data['title']) && !empty($data['title'])) {
  3611. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  3612. }
  3613. //level
  3614. if (isset($data['level']) && !empty($data['level'])) {
  3615. $where[] = ['notice.level', '=', $data['level']];
  3616. }
  3617. //status
  3618. if (isset($data['status']) && !empty($data['status'])) {
  3619. $where[] = ['notice.status', '=', $data['status']];
  3620. }
  3621. var_dump($data, '------------11111-2----test---------');
  3622. if ($data['type_id'] == 10000) {
  3623. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3624. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3625. })
  3626. ->where($where)
  3627. ->orderBy('updated_at', 'desc')
  3628. ->limit($data['page_size'])
  3629. ->offset(($data['page'] - 1) * $data['page_size'])
  3630. ->get();
  3631. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3632. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3633. })
  3634. ->where($where)
  3635. ->orderBy('updated_at', 'desc')
  3636. ->count();
  3637. } else {
  3638. $result = Notice::where($where)
  3639. // ->where('user_id', $data['user_id'])
  3640. ->Where(function ($query) use ($data) {
  3641. $query->Where(function ($q) use ($data) {
  3642. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3643. ->orWhere('notice.user_id', $data['user_id']);
  3644. });
  3645. })
  3646. ->when(!empty($data['status1']), function ($query) use ($data) {
  3647. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3648. })
  3649. ->orderBy('updated_at', 'desc')
  3650. ->limit($data['page_size'])
  3651. ->offset(($data['page'] - 1) * $data['page_size'])
  3652. ->get();
  3653. $total = Notice::where($where)
  3654. ->when(!empty($data['status1']), function ($query) use ($data) {
  3655. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3656. })
  3657. // ->where('user_id', $data['user_id'])
  3658. ->Where(function ($query) use ($data) {
  3659. $query->Where(function ($q) use ($data) {
  3660. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3661. ->orWhere('notice.user_id', $data['user_id']);
  3662. });
  3663. })
  3664. ->count();
  3665. }
  3666. if (empty($result)) {
  3667. return Result::error("查询失败", 0);
  3668. }
  3669. $data = [
  3670. 'rows' => $result,
  3671. 'count' => $total,
  3672. ];
  3673. return Result::success($data);
  3674. }
  3675. public function getNoticeDetail(array $data): array
  3676. {
  3677. $result = Notice::where('id', $data['id'])->first();
  3678. if (empty($result)) {
  3679. return Result::error("查询失败", 0);
  3680. }
  3681. return Result::success($result);
  3682. }
  3683. public function deleteNotice(array $data): array
  3684. {
  3685. $notice = Notice::where('id', $data['id'])->first();
  3686. if (empty($notice)) {
  3687. return Result::error("删除失败", 0);
  3688. }
  3689. $chat_group_id = $notice->group_id;
  3690. if ($chat_group_id) {
  3691. //删除群聊
  3692. ChatGroups::where('id', $chat_group_id)->delete();
  3693. //删除群成员
  3694. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  3695. //删除群聊记录
  3696. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  3697. }
  3698. $result = Notice::where('id', $data['id'])->delete();
  3699. return Result::success($result);
  3700. }
  3701. public function getMSG(array $data): array
  3702. {
  3703. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  3704. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3705. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  3706. $result = [];
  3707. if ($type_id == 1) {
  3708. //最近的5篇已审的文章
  3709. $apply_articale = Article::where('status', 1)
  3710. ->where('admin_user_id', $user_id)
  3711. ->orderBy('updated_at', 'desc')
  3712. ->limit(5)->get();
  3713. //获取5条单聊未读聊天消息
  3714. $chat = ChatRecords::where('is_read', 0)
  3715. ->where('user_id', $user_id)
  3716. ->where('talk_type', 1)
  3717. ->orderBy('created_at', 'desc')
  3718. ->limit(5)->get();
  3719. //获取5条未读群聊信息
  3720. $chat_group = ChatRecords::where('is_read', 0)
  3721. ->where('user_id', $user_id)
  3722. ->where('talk_type', 2)
  3723. ->orderBy('created_at', 'desc')
  3724. ->limit(5)->get();
  3725. //获取5条用户的已审核商品
  3726. $good = Good::where('status', 2)
  3727. ->where('user_id', $user_id)
  3728. ->orderBy('updated_at', 'desc')
  3729. ->limit(5)->get();
  3730. //获取5条用户待审核的公告
  3731. $notice = Notice::where('status', 2)
  3732. ->where('user_id', $user_id)
  3733. ->orderBy('updated_at', 'desc')
  3734. ->limit(5)->get();
  3735. //获取5条用户的待审核投诉
  3736. $complaint = Complaint::where('status', 2)
  3737. ->where('user_id', $user_id)
  3738. ->orderBy('updated_at', 'desc')
  3739. ->limit(5)->get();
  3740. //获取5条用户的book
  3741. $book = Book::where('status', 2)
  3742. ->where('user_id', $user_id)
  3743. ->orderBy('updated_at', 'desc')
  3744. ->limit(5)->get();
  3745. //获取5条用户的求职
  3746. //获取5条用户的求职 1
  3747. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3748. ->where('job_hunting.user_id', $user_id)
  3749. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3750. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3751. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3752. ->orderBy('updated_at', 'desc')
  3753. ->limit(5)->get();
  3754. //获取5条用户的求职 2
  3755. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3756. ->where('job_recruiting.user_id', $user_id)
  3757. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3758. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3759. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3760. ->orderBy('updated_at', 'desc')
  3761. ->limit(5)->get();
  3762. //人才库 1
  3763. $job_apply = JobApply::where('job_apply.status', 1)
  3764. ->where('job_apply.receiver_id', $user_id)
  3765. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3766. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3767. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3768. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3769. ->select('job_recruiting', 'job_recruiting.', '', '')
  3770. ->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')
  3771. ->orderBy('updated_at', 'desc')
  3772. ->limit(5)->get();
  3773. // 职场机会 2
  3774. $job_resume = JobResume::where('job_resume.status', 1)
  3775. ->where('job_resume.receiver_id', $user_id)
  3776. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3777. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3778. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3779. ->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')
  3780. ->orderBy('updated_at', 'desc')
  3781. ->limit(5)->get();
  3782. // count($chat) + count($chat_group) +
  3783. $count = count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  3784. $result = [
  3785. 'apply_articale' => $apply_articale,
  3786. 'chat' => $chat,
  3787. 'chat_group' => $chat_group,
  3788. 'good' => $good,
  3789. 'notice' => $notice,
  3790. 'complaint' => $complaint,
  3791. 'book' => $book,
  3792. 'job_hunting' => $job_hunting,
  3793. 'job_recruiting' => $job_recruiting,
  3794. 'job_apply' => $job_apply,
  3795. 'job_resume' => $job_resume,
  3796. 'count' => $count,
  3797. ];
  3798. } elseif ($type_id == 2) {
  3799. //最近的5篇已审的文章
  3800. $apply_articale = Article::where('status', 1)
  3801. ->where('admin_user_id', $user_id)
  3802. ->limit(5)->get();
  3803. //获取5条单聊未读聊天消息
  3804. $chat = ChatRecords::where('is_read', 0)
  3805. ->where('user_id', $user_id)
  3806. ->where('talk_type', 1)
  3807. ->orderBy('created_at', 'desc')
  3808. ->limit(5)->get();
  3809. //获取5条未读群聊信息
  3810. $chat_group = ChatRecords::where('is_read', 0)
  3811. ->where('user_id', $user_id)
  3812. ->where('talk_type', 2)
  3813. ->orderBy('created_at', 'desc')
  3814. ->limit(5)->get();
  3815. //获取5条用户的已审核商品
  3816. $good = Good::where('status', 2)
  3817. ->where('user_id', $user_id)
  3818. ->orderBy('updated_at', 'desc')
  3819. ->limit(5)->get();
  3820. //count($chat) + count($chat_group)
  3821. $count = count($apply_articale) + count($good);
  3822. $result = [
  3823. 'apply_articale' => $apply_articale,
  3824. 'chat' => $chat,
  3825. 'chat_group' => $chat_group,
  3826. 'good' => $good,
  3827. 'count' => $count,
  3828. ];
  3829. } elseif ($type_id == 3) {
  3830. //最近的5篇已审的文章
  3831. $apply_articale = Article::where('status', 1)
  3832. ->where('admin_user_id', $user_id)
  3833. ->limit(5)->get();
  3834. //获取5条单聊未读聊天消息
  3835. $chat = ChatRecords::where('is_read', 0)
  3836. ->where('user_id', $user_id)
  3837. ->where('talk_type', 1)
  3838. ->orderBy('created_at', 'desc')
  3839. ->limit(5)->get();
  3840. //获取5条未读群聊信息
  3841. $chat_group = ChatRecords::where('is_read', 0)
  3842. ->where('user_id', $user_id)
  3843. ->where('talk_type', 2)
  3844. ->orderBy('created_at', 'desc')
  3845. ->limit(5)->get();
  3846. //获取5条用户的已审核商品
  3847. $good = Good::where('status', 2)
  3848. ->where('user_id', $user_id)
  3849. ->orderBy('updated_at', 'desc')
  3850. ->limit(5)->get();
  3851. //count($chat) + count($chat_group) +
  3852. $count = count($apply_articale) + count($good);
  3853. $result = [
  3854. 'apply_articale' => $apply_articale,
  3855. 'chat' => $chat,
  3856. 'chat_group' => $chat_group,
  3857. 'good' => $good,
  3858. 'count' => $count,
  3859. ];
  3860. } elseif ($type_id == 4) {
  3861. //最近的5篇已审的文章
  3862. $apply_articale = Article::where('status', 1)
  3863. ->where('admin_user_id', $user_id)
  3864. ->limit(5)->get();
  3865. //获取5条用户的已审核商品
  3866. $good = Good::where('status', 2)
  3867. ->where('user_id', $user_id)
  3868. ->orderBy('updated_at', 'desc')
  3869. ->limit(5)->get();
  3870. $count = count($apply_articale) + count($good);
  3871. $result = [
  3872. 'apply_articale' => $apply_articale,
  3873. 'chat' => '',
  3874. 'chat_group' => '',
  3875. 'good' => $good,
  3876. 'count' => $count,
  3877. ];
  3878. } elseif ($type_id == 10000) {
  3879. //获取未审核的5篇文章
  3880. $apply_articale = Article::where('status', 0)
  3881. ->orderBy('updated_at', 'desc')
  3882. ->limit(5)->get();
  3883. //获取5条单聊未读聊天消息
  3884. $chat = ChatRecords::where('is_read', 0)
  3885. ->where('user_id', $user_id)
  3886. ->where('talk_type', 1)
  3887. ->orderBy('created_at', 'desc')
  3888. ->limit(5)->get();
  3889. //获取5条未读群聊信息
  3890. $chat_group = ChatRecords::where('is_read', 0)
  3891. ->where('user_id', $user_id)
  3892. ->where('talk_type', 2)
  3893. ->orderBy('created_at', 'desc')
  3894. ->limit(5)->get();
  3895. //获取5条用户的已审核商品
  3896. $good = Good::where('status', 1)
  3897. // ->where('user_id', $user_id)
  3898. ->orderBy('updated_at', 'desc')
  3899. ->limit(5)->get();
  3900. //获取5条用户待审核的公告
  3901. $notice = Notice::where('status', 1)
  3902. ->orderBy('updated_at', 'desc')
  3903. ->limit(5)->get();
  3904. //获取5条用户的待审核投诉
  3905. $complaint = Complaint::where('status', 1)
  3906. ->orderBy('updated_at', 'desc')
  3907. ->limit(5)->get();
  3908. //获取5条用户的book
  3909. $book = Book::where('status', 1)
  3910. ->orderBy('updated_at', 'desc')
  3911. ->limit(5)->get();
  3912. //获取5条用户的求职 1
  3913. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3914. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3915. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3916. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3917. ->orderBy('updated_at', 'desc')
  3918. ->limit(5)->get();
  3919. //获取5条用户的求职 2
  3920. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3921. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3922. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3923. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3924. ->orderBy('updated_at', 'desc')
  3925. ->limit(5)->get();
  3926. //人才库 1
  3927. $job_apply = JobApply::where('job_apply.status', 1)
  3928. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3929. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3930. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3931. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3932. ->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')
  3933. ->orderBy('updated_at', 'desc')
  3934. ->limit(5)->get();
  3935. // 职场机会 2
  3936. $job_resume = JobResume::where('job_resume.status', 1)
  3937. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3938. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3939. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3940. ->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')
  3941. ->orderBy('updated_at', 'desc')
  3942. ->limit(5)->get();
  3943. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  3944. $result = [
  3945. 'apply_articale' => $apply_articale,
  3946. 'chat' => $chat,
  3947. 'chat_group' => $chat_group,
  3948. 'good' => $good,
  3949. 'notice' => $notice,
  3950. 'complaint' => $complaint,
  3951. 'book' => $book,
  3952. 'job_hunting' => $job_hunting,
  3953. 'job_recruiting' => $job_recruiting,
  3954. 'job_apply' => $job_apply,
  3955. 'job_resume' => $job_resume,
  3956. 'count' => $count,
  3957. ];
  3958. } elseif ($type_id == 20000) {
  3959. }
  3960. var_dump($type_id, '-----------------test---------');
  3961. return Result::success($result);
  3962. }
  3963. public function getComplaintList(array $data): array
  3964. {
  3965. var_dump($data, '00000001000000000000');
  3966. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3967. unset($data['type_id']);
  3968. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3969. $where = [];
  3970. if ($type_id != 10000 && empty($data['deal_user'])) {
  3971. $where['complaint.user_id'] = $user_id;
  3972. }
  3973. if (!empty($data['title'])) {
  3974. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  3975. }
  3976. if (!empty($data['department_id'])) {
  3977. $where['complaint.department_id'] = $data['department_id'];
  3978. }
  3979. if (!empty($data['deal'])) {
  3980. $where['complaint.deal'] = $data['deal'];
  3981. }
  3982. if (!empty($data['status'])) {
  3983. $where['complaint.status'] = $data['status'];
  3984. }
  3985. var_dump(!empty($data['deal_user']), '----------1');
  3986. var_dump($where, '----------2');
  3987. $result = Complaint::where($where)
  3988. ->when(!empty($data['status1']), function ($query) use ($data) {
  3989. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  3990. })
  3991. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  3992. //json re_user_ids data[user_id]是不是在里面
  3993. $query->Where(function ($q) use ($data) {
  3994. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  3995. ->where('complaint.status', 2);
  3996. });
  3997. })
  3998. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  3999. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4000. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4001. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4002. ->orderBy('updated_at', 'desc')
  4003. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4004. //sql输出
  4005. if (empty($result)) {
  4006. return Result::error("暂无投诉信息", 0);
  4007. }
  4008. // 取出数据
  4009. $rows = $result->items();
  4010. $count = $result->total();
  4011. $responseData = [
  4012. 'rows' => $rows,
  4013. 'count' => $count,
  4014. ];
  4015. return Result::success($responseData);
  4016. }
  4017. public function getComplaintInfo(array $data): array
  4018. {
  4019. $result = Complaint::where('id', $data['id'])->first();
  4020. if (empty($result)) {
  4021. return Result::error("查询失败", 0);
  4022. }
  4023. return Result::success($result);
  4024. }
  4025. public function addComplaint(array $data): array
  4026. {
  4027. date_default_timezone_set('Asia/Shanghai');
  4028. $data['created_at'] = date('Y-m-d H:i:s');
  4029. $data['updated_at'] = date('Y-m-d H:i:s');
  4030. $result = Complaint::create($data);
  4031. return Result::success($result);
  4032. }
  4033. public function updateComplaint(array $data): array
  4034. {
  4035. date_default_timezone_set('Asia/Shanghai');
  4036. $data['updated_at'] = date('Y-m-d H:i:s');
  4037. $user_id = $data['user_id'] ?? 0;
  4038. $type_id = $data['type_id'] ?? 0;
  4039. unset($data['user_id']);
  4040. unset($data['type_id']);
  4041. $result = Complaint::where('id', $data['id'])->update($data);
  4042. return Result::success($result);
  4043. }
  4044. public function deleteComplaint(array $data): array
  4045. {
  4046. $result = Complaint::where('id', $data['id'])->delete();
  4047. return Result::success($result);
  4048. }
  4049. public function getComplainInfo(array $data): array
  4050. {
  4051. $result = Complaint::where('id', $data['id'])->first();
  4052. if (empty($result)) {
  4053. return Result::error("查询失败", 0);
  4054. }
  4055. return Result::success($result);
  4056. }
  4057. public function updateComplaintStatus(array $data): array
  4058. {
  4059. date_default_timezone_set('Asia/Shanghai');
  4060. $data['updated_at'] = date('Y-m-d H:i:s');
  4061. $user_id = $data['user_id'] ?? 0;
  4062. $type_id = $data['type_id'] ?? 0;
  4063. unset($data['user_id']);
  4064. unset($data['type_id']);
  4065. //处理, 写入处理人
  4066. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4067. $data['real_deal_user'] = $user_id;
  4068. }
  4069. //如果是deal 23,则判断是不是处理人
  4070. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4071. $complaintInof = Complaint::where('id', $data['id'])
  4072. ->where('real_deal_user', $user_id)
  4073. ->first();
  4074. if (empty($complaintInof)) {
  4075. return Result::error("处理人错误", 0);
  4076. }
  4077. }
  4078. $result = complaint::where('id', $data['id'])->update($data);
  4079. return Result::success($result);
  4080. }
  4081. public function updateGoodStatus(array $data): array
  4082. {
  4083. $user_id = $data['user_id'] ?? 0;
  4084. $type_id = $data['type_id'] ?? 0;
  4085. unset($data['user_id']);
  4086. unset($data['type_id']);
  4087. $result = Good::where('id', $data['id'])->update($data);
  4088. return Result::success($result);
  4089. }
  4090. public function updateJobHuntingStatus(array $data): array
  4091. {
  4092. $user_id = $data['user_id'] ?? 0;
  4093. $type_id = $data['type_id'] ?? 0;
  4094. unset($data['user_id']);
  4095. unset($data['type_id']);
  4096. $result = JobHunting::where('id', $data['id'])->update($data);
  4097. return Result::success($result);
  4098. }
  4099. public function updateNoticeStatus(array $data): array
  4100. {
  4101. $user_id = $data['user_id'] ?? 0;
  4102. $type_id = $data['type_id'] ?? 0;
  4103. unset($data['user_id']);
  4104. unset($data['type_id']);
  4105. $result = Notice::where('id', $data['id'])->update($data);
  4106. return Result::success($result);
  4107. }
  4108. public function getDUser(array $data): array
  4109. {
  4110. if (!empty($data['ids'])) {
  4111. $user = User::whereIn('id', $data['ids'])->getall();
  4112. if (empty($user)) {
  4113. return Result::error('无数据', 0);
  4114. }
  4115. return Result::success($user);
  4116. }
  4117. $where = [];
  4118. if (!empty($data['department_id'])) {
  4119. $where['department_id'] = $data['department_id'];
  4120. }
  4121. if (!empty($data['city_id'])) {
  4122. $where['city_id'] = $data['city_id'];
  4123. }
  4124. $result = User::where('type_id', 2)
  4125. ->where('status', 1)
  4126. ->where($where)
  4127. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4128. ->get();
  4129. if (empty($result)) {
  4130. return Result::error("查询失败", 0);
  4131. }
  4132. return Result::success($result);
  4133. }
  4134. /**
  4135. * 验证导航名称是否重复
  4136. * @return void
  4137. */
  4138. public function checkCategoryName(array $data): array
  4139. {
  4140. $result = Category::when($data, function ($query) use ($data) {
  4141. if (isset($data['name']) && $data['name']) {
  4142. $query->where("name", $data['name']);
  4143. }
  4144. if (isset($data['id']) && $data['id']) {
  4145. $query->where("id", "!=", $data['id']);
  4146. }
  4147. })->first();
  4148. if ($result) {
  4149. return Result::error("已存在");
  4150. } else {
  4151. return Result::success();
  4152. }
  4153. }
  4154. //20250226 产品列表
  4155. // 20250306 -------招聘--------fr
  4156. /*
  4157. * 招聘列表
  4158. * */
  4159. public function getJobRecruitingList(array $data): array
  4160. {
  4161. $where = [];
  4162. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4163. if ($data['checkout'] == 0) {
  4164. $job_status = [0, 2];
  4165. } else {
  4166. $job_status = [1];
  4167. }
  4168. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4169. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4170. }
  4171. $user = User::where('id', $data['user_id'])->first();
  4172. if (empty($user)) {
  4173. return Result::error("用户不存在", 0);
  4174. }
  4175. // 3:企业会员
  4176. if ($user['type_id'] == 3) {
  4177. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4178. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4179. }
  4180. // 如果 $where 为空,则不添加 where 条件
  4181. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4182. return $query->where($where);
  4183. })
  4184. ->whereIn('job_recruiting.status', $job_status)
  4185. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4186. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4187. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4188. ->orderBy("updated_at", "desc")
  4189. ->offset(($data['page'] - 1) * $data['page_size'])
  4190. ->limit($data['page_size'])
  4191. ->get()
  4192. ->all();
  4193. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4194. return $query->where($where);
  4195. })
  4196. ->whereIn('job_recruiting.status', $job_status)
  4197. ->count();
  4198. if (empty($result)) {
  4199. return Result::error("暂无招聘信息", 0);
  4200. }
  4201. return Result::success($result);
  4202. }
  4203. /*
  4204. * 招聘信息添加
  4205. * */
  4206. public function addJobRecruiting(array $data): array
  4207. {
  4208. // return Result::success($data);
  4209. $user = User::where('user.id', $data['user_id'])
  4210. ->where('user.status', 1)
  4211. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4212. ->select(
  4213. 'user.type_id',
  4214. 'user.mobile',
  4215. 'user.email',
  4216. 'user_info.business_name',
  4217. 'user_info.company_hy_id',
  4218. 'user_info.company_nature',
  4219. 'user_info.company_size',
  4220. 'user_info.introduction',
  4221. 'user_info.real_name',
  4222. 'user_info.company_url',
  4223. 'user_info.address_arr_id',
  4224. 'user_info.address'
  4225. )
  4226. ->first();
  4227. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4228. return Result::error("用户不存在", 0);
  4229. }
  4230. $web = Website::where('id', $data['website_id'])->first();
  4231. if (empty($web)) {
  4232. return Result::error("网站不存在", 0);
  4233. }
  4234. // return Result::success($user);
  4235. $data['action_id'] = $data['user_id'];
  4236. $data['user_type'] = $user['type_id'];
  4237. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4238. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4239. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4240. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4241. // 公司地址 管理员必填
  4242. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4243. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4244. // 管理员-企业相关信息
  4245. $company = [
  4246. // 'user_id' => $data['user_id']?? null,
  4247. 'business_name' => $data['business_name'] ?? null,
  4248. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4249. 'company_size' => $data['company_size'] ?? null,
  4250. 'company_nature' => $data['company_nature'] ?? null,
  4251. 'introduction' => $data['introduction'] ?? null,
  4252. 'real_name' => $data['real_name'] ?? null,
  4253. 'mobile' => $data['mobile'] ?? null,
  4254. 'company_url' => $data['company_url'] ?? null,
  4255. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4256. 'address' => $data['address'] ?? null,
  4257. 'email' => $data['email'] ?? null,
  4258. ];
  4259. //去掉相关企业信息
  4260. $job = array_diff_key($data, array_flip(array_keys($company)));
  4261. Db::beginTransaction();
  4262. try {
  4263. // 先添加职位相关信息
  4264. if ($user['type_id'] == 10000) {
  4265. $job['status'] = 1;
  4266. }
  4267. if (empty($data['experience']) || $data['experience'] == '') {
  4268. $job['experience'] = null;
  4269. } else {
  4270. $job['experience'] = $data['experience'];
  4271. }
  4272. $jobId = JobRecruiting::insertGetId($job);
  4273. if (empty($jobId)) {
  4274. Db::rollBack();
  4275. return Result::error("添加失败");
  4276. }
  4277. // 添加公司信息
  4278. $company['user_id'] = $data['user_id'] ?? null;
  4279. $company['job_id'] = $jobId;
  4280. $company['user_type'] = $user['type_id'] ?? null;
  4281. $company['website_id'] = $data['website_id'] ?? null;
  4282. if ($user['type_id'] == 10000) {
  4283. // 管理员添加企业信息
  4284. // return Result::success($company);
  4285. $companyId = JobCompany::insertGetId($company);
  4286. if (empty($companyId)) {
  4287. Db::rollBack();
  4288. return Result::error("添加失败");
  4289. }
  4290. } else {
  4291. // 企业会员添加企业信息
  4292. $company = [
  4293. 'user_id' => $data['user_id'] ?? null,
  4294. 'business_name' => $user['business_name'] ?? null,
  4295. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4296. 'company_size' => $user['company_size'] ?? null,
  4297. 'company_nature' => $user['company_nature'] ?? null,
  4298. 'introduction' => $user['introduction'] ?? null,
  4299. 'real_name' => $user['real_name'] ?? null,
  4300. 'mobile' => $user['mobile'] ?? null,
  4301. 'company_url' => $user['company_url'] ?? null,
  4302. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4303. 'address' => $user['address'] ?? null,
  4304. 'email' => $user['email'] ?? null,
  4305. 'website_id' => $data['website_id'] ?? null,
  4306. 'user_type' => $user['type_id'] ?? null,
  4307. 'job_id' => $jobId,
  4308. ];
  4309. $companyId = JobCompany::insertGetId($company);
  4310. if (empty($companyId)) {
  4311. Db::rollBack();
  4312. return Result::error("添加失败");
  4313. }
  4314. // return Result::success($company);
  4315. }
  4316. Db::commit();
  4317. } catch (\Exception $e) {
  4318. Db::rollBack();
  4319. return Result::error($e->getMessage(), 0);
  4320. }
  4321. $result = [
  4322. 'job_id' => $jobId,
  4323. 'company_id' => $companyId,
  4324. ];
  4325. if (empty($result)) {
  4326. return Result::error("添加失败", 0);
  4327. }
  4328. return Result::success($result);
  4329. }
  4330. /*
  4331. * 获取招聘信息详情
  4332. * */
  4333. public function getJobRecruitingInfo(array $data): array
  4334. {
  4335. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4336. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4337. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4338. ->select(
  4339. 'job_recruiting.*',
  4340. 'website.website_name as website_name',
  4341. 'job_company.business_name',
  4342. 'job_company.company_hy_id',
  4343. 'job_company.company_size',
  4344. 'job_company.company_nature',
  4345. 'job_company.introduction',
  4346. 'job_company.real_name',
  4347. 'job_company.mobile',
  4348. 'job_company.company_url',
  4349. 'job_company.address_arr_id',
  4350. 'job_company.address',
  4351. 'job_company.email'
  4352. )
  4353. ->first();
  4354. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4355. if (!empty($cityId)) {
  4356. if (isset($cityId[1]) && $cityId[1] != null) {
  4357. $city = District::where('id', $cityId[1])->first(['name']);
  4358. } else {
  4359. $city = District::where('id', $cityId[0])->first(['name']);
  4360. }
  4361. $result['city'] = $city['name'] ?? '';
  4362. }
  4363. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4364. if (is_array($addressId) && !empty($addressId)) {
  4365. $address = District::whereIn('id', $addressId)
  4366. ->orderBy('level', 'asc')
  4367. ->get(['name'])
  4368. ->pluck('name')
  4369. ->implode('');
  4370. // $job->address_name = $address ?? '';
  4371. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4372. }
  4373. if (empty($result)) {
  4374. return Result::error("招聘信息不存在", 0);
  4375. }
  4376. // return Result::success($job);
  4377. return Result::success($result);
  4378. }
  4379. /*
  4380. * 修改招聘信息
  4381. * */
  4382. public function upJobRecruiting(array $data): array
  4383. {
  4384. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4385. // return Result::success($job);
  4386. if (empty($job)) {
  4387. return Result::error("招聘信息不存在", 0);
  4388. }
  4389. $user = User::where('id', $data['user_id'])->first();
  4390. // return Result::success($user);
  4391. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4392. return Result::error("用户不存在", 0);
  4393. }
  4394. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4395. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4396. }
  4397. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4398. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4399. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4400. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4401. // 公司地址 管理员必填
  4402. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4403. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4404. // 管理员-企业相关信息
  4405. $company = [
  4406. 'business_name' => $data['business_name'] ?? null,
  4407. 'company_hy_id' => $data['hy_id'] ?? null,
  4408. 'company_size' => $data['company_size'] ?? null,
  4409. 'company_nature' => $data['company_nature'] ?? null,
  4410. 'introduction' => $data['introduction'] ?? null,
  4411. 'real_name' => $data['real_name'] ?? null,
  4412. 'mobile' => $data['mobile'] ?? null,
  4413. 'company_url' => $data['company_url'] ?? null,
  4414. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4415. 'address' => $data['address'] ?? null,
  4416. 'email' => $data['email'] ?? null,
  4417. ];
  4418. //去掉相关企业信息
  4419. $data = array_diff_key($data, array_flip(array_keys($company)));
  4420. $jobId = $data['id'];
  4421. $web = $data['website_id'];
  4422. $data['action_id'] = $data['user_id'];
  4423. unset($data['user_id']);
  4424. unset($data['user_type']);
  4425. unset($data['id']);
  4426. unset($data['website_id']);
  4427. // return Result::success($data);
  4428. Db::beginTransaction();
  4429. try {
  4430. // 管理员修改招聘信息
  4431. if ($user['type_id'] == 10000) {
  4432. $data['website_id'] = $web;
  4433. $company['website_id'] = $data['website_id'];
  4434. $data['status'] = 1;
  4435. } else {
  4436. $data['status'] = 0;
  4437. }
  4438. if (empty($data['experience']) || $data['experience'] == '') {
  4439. $job['experience'] = null;
  4440. } else {
  4441. $job['experience'] = $data['experience'];
  4442. }
  4443. // Db::rollBack();
  4444. // return Result::success($company);
  4445. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4446. if (empty($result['job'])) {
  4447. Db::rollBack();
  4448. return Result::error("修改招聘信息失败");
  4449. }
  4450. // 管理员修改企业相关信息
  4451. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4452. if (empty($result['company'])) {
  4453. Db::rollBack();
  4454. return Result::error("修改企业相关信息失败");
  4455. }
  4456. Db::commit();
  4457. // return Result::success($result);
  4458. } catch (\Exception $e) {
  4459. Db::rollBack();
  4460. return Result::error($e->getMessage(), 0);
  4461. }
  4462. return Result::success($result);
  4463. }
  4464. /*
  4465. * 招聘信息删除
  4466. * */
  4467. public function delJobRecruiting(array $data): array
  4468. {
  4469. $user = User::where('id', $data['user_id'])->first();
  4470. if (empty($user)) {
  4471. return Result::error("用户不存在", 0);
  4472. }
  4473. $job = JobRecruiting::where('id', $data['id'])->first();
  4474. if (empty($job)) {
  4475. return Result::error("招聘信息不存在", 0);
  4476. }
  4477. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4478. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4479. }
  4480. Db::beginTransaction();
  4481. try {
  4482. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4483. if (empty($result['job'])) {
  4484. Db::rollBack();
  4485. return Result::error("删除招聘信息失败");
  4486. }
  4487. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4488. if (empty($result['company'])) {
  4489. Db::rollBack();
  4490. return Result::error("删除企业相关信息失败");
  4491. }
  4492. Db::commit();
  4493. } catch (\Exception $e) {
  4494. Db::rollBack();
  4495. return Result::error($e->getMessage(), 0);
  4496. }
  4497. return Result::success($result);
  4498. }
  4499. /*
  4500. * 获取公司信息
  4501. * */
  4502. public function getJobCompany(array $data): array
  4503. {
  4504. $user = User::where('user.id', $data['user_id'])
  4505. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4506. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4507. ->first();
  4508. // return Result::success($user);
  4509. if (empty($user)) {
  4510. return Result::error("用户不存在", 0);
  4511. }
  4512. if ($user['type_id'] == 3) {
  4513. $result = [
  4514. // 'id' => 0,
  4515. 'user_id' => $data['user_id'],
  4516. 'website_id' => $data['website_id'],
  4517. 'business_name' => $user['business_name'], // 企业名称
  4518. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4519. 'company_nature' => $user['company_nature'], // 公司性质
  4520. 'company_size' => $user['company_size'], // 公司规模
  4521. 'introduction' => $user['introduction'], // 公司简介
  4522. 'real_name' => $user['real_name'], // 企业联系人
  4523. 'mobile' => $user['mobile'], // 企业联系电话
  4524. 'company_url' => $user['company_url'], // 企业网址
  4525. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4526. 'address' => $user['address'], // 企业地址
  4527. 'email' => $user['email'], // 企业邮箱
  4528. ];
  4529. } else {
  4530. return Result::error("用户类型错误", 0);
  4531. }
  4532. if (empty($result)) {
  4533. return Result::error("公司信息不存在", 0);
  4534. }
  4535. return Result::success($result);
  4536. }
  4537. /*
  4538. * 修改公司信息
  4539. * */
  4540. public function upJobCompany(array $data): array
  4541. {
  4542. // return Result::success($data);
  4543. $user = User::where('user.id', $data['user_id'])
  4544. ->where('user.status', 1)
  4545. ->select('user.user_name', 'user.type_id')
  4546. ->first();
  4547. if (empty($user)) {
  4548. return Result::error("用户不存在", 0);
  4549. }
  4550. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4551. $company = [
  4552. 'business_name' => $data['business_name'], // 企业名称
  4553. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4554. 'company_nature' => $data['company_nature'], // 公司性质
  4555. 'company_size' => $data['company_size'], // 公司规模
  4556. 'introduction' => $data['introduction'], // 公司简介
  4557. // 'real_name' => $data['real_name'], // 企业联系人
  4558. 'company_url' => $data['company_url'], // 企业网址
  4559. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4560. 'address' => $data['address'], // 企业详细地址
  4561. ];
  4562. if ($user['type_id'] == 3) {
  4563. Db::beginTransaction();
  4564. try {
  4565. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  4566. 'business_name' => $data['business_name'], // 企业名称
  4567. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4568. 'company_nature' => $data['company_nature'], // 公司性质
  4569. 'company_size' => $data['company_size'], // 公司规模
  4570. 'introduction' => $data['introduction'], // 公司简介
  4571. // 'real_name' => $data['real_name'], // 企业联系人
  4572. 'company_url' => $data['company_url'], // 企业网址
  4573. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4574. 'address' => $data['address'], // 企业详细地址
  4575. ]);
  4576. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  4577. Db::commit();
  4578. } catch (\Exception $e) {
  4579. Db::rollBack();
  4580. return Result::error($e->getMessage(), 0);
  4581. }
  4582. } else {
  4583. return Result::error("用户类型错误", 0);
  4584. }
  4585. if (empty($result)) {
  4586. return Result::error("修改失败", 0);
  4587. }
  4588. return Result::success($result);
  4589. }
  4590. /*
  4591. * 获取省-市
  4592. * */
  4593. public function getJobRecruitingArea(array $data): array
  4594. {
  4595. if (isset($data['pid']) && $data['pid'] != null) {
  4596. $result = District::where('pid', $data['pid'])->get()->all();
  4597. } else {
  4598. $result = District::where('level', 1)->get()->all();
  4599. }
  4600. if (empty($result)) {
  4601. return Result::error("暂无此省市", 0);
  4602. }
  4603. return Result::success($result);
  4604. }
  4605. /*
  4606. * 获取行业分类
  4607. * */
  4608. public function getIndustry(array $data): array
  4609. {
  4610. $result = JobIndustry::get()->all();
  4611. if (empty($result)) {
  4612. return Result::error("暂无行业分类", 0);
  4613. }
  4614. return Result::success($result);
  4615. }
  4616. /*
  4617. * 获取职位
  4618. * */
  4619. public function getPositionList(array $data): array
  4620. {
  4621. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  4622. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  4623. } else {
  4624. $result = JobPosition::where('zwpid', 0)->get()->all();
  4625. }
  4626. if (empty($result)) {
  4627. return Result::error("暂无此职位", 0);
  4628. }
  4629. return Result::success($result);
  4630. }
  4631. /*
  4632. * 获取工作性质-菜单
  4633. * */
  4634. public function getJobNature(array $data): array
  4635. {
  4636. $result = JobEnum::where('egroup', 'nature')->get()->all();
  4637. if (empty($result)) {
  4638. return Result::error("暂无工作性质", 0);
  4639. }
  4640. return Result::success($result);
  4641. }
  4642. /*
  4643. * 获取工作经验-菜单
  4644. * */
  4645. public function getExperience(array $data): array
  4646. {
  4647. $result = JobEnum::where('egroup', 'years')->get()->all();
  4648. if (empty($result)) {
  4649. return Result::error("暂无工作经验", 0);
  4650. }
  4651. return Result::success($result);
  4652. }
  4653. /*
  4654. * 获取学历-菜单
  4655. * */
  4656. public function getEducation(array $data): array
  4657. {
  4658. $result = JobEnum::where('egroup', 'education')->get()->all();
  4659. if (empty($result)) {
  4660. return Result::error("暂无学历", 0);
  4661. }
  4662. return Result::success($result);
  4663. }
  4664. /*
  4665. * 获取薪资-菜单
  4666. * */
  4667. public function getSalary(array $data): array
  4668. {
  4669. $result = JobEnum::where('egroup', 'income')->get()->all();
  4670. if (empty($result)) {
  4671. return Result::error("暂无薪资", 0);
  4672. }
  4673. return Result::success($result);
  4674. }
  4675. /*
  4676. * 获取语言-菜单
  4677. * */
  4678. public function getLanguage(array $data): array
  4679. {
  4680. $result = JobEnum::where('egroup', 'language')->get()->all();
  4681. if (empty($result)) {
  4682. return Result::error("暂无语言", 0);
  4683. }
  4684. return Result::success($result);
  4685. }
  4686. /*
  4687. * 获取掌握程度-菜单
  4688. * */
  4689. public function getLevel(array $data): array
  4690. {
  4691. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  4692. if (empty($result)) {
  4693. return Result::error("暂无工作性质", 0);
  4694. }
  4695. return Result::success($result);
  4696. }
  4697. // 公司信息
  4698. /*
  4699. * 获取公司性质-菜单
  4700. * */
  4701. public function getCompanyNature(array $data): array
  4702. {
  4703. $result = JobNature::get()->all();
  4704. if (empty($result)) {
  4705. return Result::error("暂无公司性质", 0);
  4706. }
  4707. return Result::success($result);
  4708. }
  4709. /*
  4710. * 获取公司规模-菜单
  4711. * */
  4712. public function getCompanySize(array $data): array
  4713. {
  4714. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  4715. if (empty($result)) {
  4716. return Result::error("暂无公司规模", 0);
  4717. }
  4718. return Result::success($result);
  4719. }
  4720. /*
  4721. * 招聘信息审核
  4722. * */
  4723. public function checkJobRecruiting(array $data): array
  4724. {
  4725. $user = User::where('id', $data['user_id'])->first();
  4726. if (empty($user)) {
  4727. return Result::error("用户不存在", 0);
  4728. }
  4729. $job = JobRecruiting::where('id', $data['id'])->first();
  4730. if (empty($job)) {
  4731. return Result::error("招聘信息不存在", 0);
  4732. }
  4733. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  4734. if ($user['type_id'] != 10000) {
  4735. return Result::error("用户暂无权限审核此招聘信息!", 0);
  4736. }
  4737. // 驳回原因
  4738. if ($data['status'] == 2) {
  4739. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  4740. }
  4741. $data['action_id'] = $data['user_id'];
  4742. unset($data['user_id']);
  4743. $result = JobRecruiting::where('id', $data['id'])->update($data);
  4744. if (empty($result)) {
  4745. return Result::error("审核失败", 0);
  4746. }
  4747. return Result::success($result);
  4748. }
  4749. public function myApplyList(array $data): array
  4750. {
  4751. var_dump($data, '------参数');
  4752. $user = User::where('id', $data['user_id'])->first();
  4753. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4754. return Result::error("用户不存在", 0);
  4755. }
  4756. // 1:个人会员 职场机会
  4757. if ($user['type_id'] == 1) {
  4758. $where['user_id'] = $user['id'];
  4759. }
  4760. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  4761. $query->where('user_id', $user['id']);
  4762. })
  4763. ->pluck('recruit_id');
  4764. $where = [];
  4765. if (isset($data['salary']) && $data['salary'] != null) {
  4766. $where['job_recruiting.salary'] = $data['salary'];
  4767. }
  4768. if (isset($data['experience']) && $data['experience'] != null) {
  4769. $where['job_recruiting.experience'] = $data['experience'];
  4770. }
  4771. if (isset($data['business_name']) && $data['business_name'] != null) {
  4772. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4773. }
  4774. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4775. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4776. ->where($where);
  4777. // ->count();
  4778. $count = $query->count();
  4779. $query = clone $query;
  4780. $job = $query
  4781. ->leftJoin('job_enum as income_enum', function ($join) {
  4782. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4783. ->where('income_enum.egroup', 'income');
  4784. })
  4785. ->leftJoin('job_enum as years_enum', function ($join) {
  4786. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4787. ->where('years_enum.egroup', 'years');
  4788. })
  4789. // ->where($where)
  4790. ->orderBy('job_recruiting.updated_at', 'desc')
  4791. ->select(
  4792. 'job_recruiting.id',
  4793. 'job_recruiting.title',
  4794. 'job_company.business_name',
  4795. 'income_enum.evalue as salary_evalue',
  4796. 'income_enum.ename as salary_ename',
  4797. 'years_enum.evalue as experience_evalue',
  4798. 'years_enum.ename as experience_ename',
  4799. 'job_recruiting.updated_at'
  4800. )
  4801. ->offset(($data['page'] - 1) * $data['pageSize'])
  4802. ->limit($data['pageSize'])
  4803. ->get()
  4804. ->all();
  4805. if (empty($job)) {
  4806. return Result::error("暂无招聘信息", 0);
  4807. }
  4808. $result = [
  4809. 'row' => $job,
  4810. 'count' => $count,
  4811. ];
  4812. return Result::success($result);
  4813. }
  4814. /*
  4815. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  4816. * */
  4817. public function getRecruitingList(array $data): array
  4818. {
  4819. $user = User::where('id', $data['user_id'])->first();
  4820. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4821. return Result::error("用户不存在", 0);
  4822. }
  4823. // 1:个人会员 职场机会
  4824. if ($user['type_id'] == 1) {
  4825. $where['user_id'] = $user['id'];
  4826. }
  4827. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  4828. $query->where('receiver_id', $user['id']);
  4829. })
  4830. ->pluck('recruit_id');
  4831. // return Result::success($recruitingId);
  4832. $where = [];
  4833. if (isset($data['salary']) && $data['salary'] != null) {
  4834. $where['job_recruiting.salary'] = $data['salary'];
  4835. }
  4836. if (isset($data['experience']) && $data['experience'] != null) {
  4837. $where['job_recruiting.experience'] = $data['experience'];
  4838. }
  4839. if (isset($data['business_name']) && $data['business_name'] != null) {
  4840. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4841. }
  4842. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4843. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4844. ->where($where);
  4845. // ->count();
  4846. $count = $query->count();
  4847. $query = clone $query;
  4848. $job = $query
  4849. ->leftJoin('job_enum as income_enum', function ($join) {
  4850. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4851. ->where('income_enum.egroup', 'income');
  4852. })
  4853. ->leftJoin('job_enum as years_enum', function ($join) {
  4854. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4855. ->where('years_enum.egroup', 'years');
  4856. })
  4857. // ->where($where)
  4858. ->orderBy('job_recruiting.updated_at', 'desc')
  4859. ->select(
  4860. 'job_recruiting.id',
  4861. 'job_recruiting.title',
  4862. 'job_company.business_name',
  4863. 'income_enum.evalue as salary_evalue',
  4864. 'income_enum.ename as salary_ename',
  4865. 'years_enum.evalue as experience_evalue',
  4866. 'years_enum.ename as experience_ename',
  4867. 'job_recruiting.updated_at'
  4868. )
  4869. ->offset(($data['page'] - 1) * $data['pageSize'])
  4870. ->limit($data['pageSize'])
  4871. ->get()
  4872. ->all();
  4873. if (empty($job)) {
  4874. return Result::error("暂无招聘信息", 0);
  4875. }
  4876. $result = [
  4877. 'row' => $job,
  4878. 'count' => $count,
  4879. ];
  4880. return Result::success($result);
  4881. }
  4882. /*
  4883. * 获取企业会员-招聘信息列表
  4884. * */
  4885. public function getRecruitingInfo(array $data): array
  4886. {
  4887. $user = User::where('id', $data['user_id'])->first();
  4888. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4889. return Result::error("用户不存在", 0);
  4890. }
  4891. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  4892. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4893. ->select(
  4894. 'job_recruiting.*',
  4895. 'job_company.business_name',
  4896. 'job_company.company_hy_id',
  4897. 'job_company.company_size',
  4898. 'job_company.company_nature',
  4899. 'job_company.introduction',
  4900. 'job_company.real_name',
  4901. 'job_company.mobile',
  4902. 'job_company.company_url',
  4903. 'job_company.address_arr_id',
  4904. 'job_company.address',
  4905. 'job_company.email'
  4906. )
  4907. ->get();
  4908. if (empty($recruiting)) {
  4909. return Result::error("暂无招聘信息", 0);
  4910. }
  4911. return Result::success($recruiting);
  4912. }
  4913. /*
  4914. * 获取企业会员-我的沟通
  4915. * */
  4916. public function getJobResumeList(array $data): array
  4917. {
  4918. $user = User::where('id', $data['user_id'])->first();
  4919. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  4920. return Result::error("用户不存在", 0);
  4921. }
  4922. $where = [];
  4923. if (isset($data['salary']) && $data['salary'] != null) {
  4924. $where['job_hunting.salary'] = $data['salary'];
  4925. }
  4926. if (isset($data['user_name']) && $data['user_name'] != null) {
  4927. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  4928. }
  4929. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  4930. $query->where('job_resume.user_id', $user['id']);
  4931. })
  4932. ->when(!empty($where), function ($query) use ($where) {
  4933. $query->where($where);
  4934. })
  4935. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  4936. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  4937. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  4938. ->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');
  4939. $count = $job->count();
  4940. if ($count == 0) {
  4941. return Result::error("暂无沟通记录", 0);
  4942. }
  4943. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  4944. ->offset(($data['page'] - 1) * $data['pageSize'])
  4945. ->limit($data['pageSize'])
  4946. ->get();
  4947. if (empty($jobs)) {
  4948. return Result::error("暂无沟通记录", 0);
  4949. }
  4950. $result['row'] = $this->processJob($jobs, '');
  4951. $result['count'] = $count;
  4952. return Result::success($result);
  4953. }
  4954. // 20250306 招聘
  4955. //20250422 书刊音像
  4956. public function addBook(array $data): array
  4957. {
  4958. // $user_id = $data['user_id'] ?? 0;
  4959. $type_id = $data['type_id'] ?? 0;
  4960. // $website_id = $data['website_id'] ?? 0;
  4961. // unset($data['user_id']);
  4962. unset($data['type_id']);
  4963. // unset($data['website_id']);
  4964. //处理数组
  4965. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  4966. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  4967. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  4968. if ($data['img_url'] == '') {
  4969. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4970. preg_match_all($reg, $data['detail'], $matches);
  4971. if (isset($matches[1][0])) {
  4972. //截取varchar240
  4973. $data['img_url'] = substr($matches[1][0], 0, 240);
  4974. }
  4975. }
  4976. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4977. //提取标题+内容中的关键词
  4978. $data['keyword'] = $data['title'];
  4979. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4980. Jieba::init(); // 初始化 jieba-php
  4981. Finalseg::init();
  4982. $segList = Jieba::cut($data['keyword']);
  4983. $segList1 = array_slice($segList, 0, 8);
  4984. $data['keyword'] = implode(',', $segList1);
  4985. }
  4986. if ($data['description'] == '') {
  4987. //提取内容中的描述
  4988. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4989. }
  4990. var_dump($data, '--');
  4991. $result = Book::insertGetId($data);
  4992. if (empty($result)) {
  4993. return Result::error("添加失败", 0);
  4994. }
  4995. return Result::success($result);
  4996. }
  4997. public function getBookList(array $data): array
  4998. {
  4999. $where = [];
  5000. if (!empty($data["title"])) {
  5001. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5002. }
  5003. if (!empty($data['website_name'])) {
  5004. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5005. }
  5006. if (!empty($data['status'])) {
  5007. $where[] = ['book.status', '=', $data['status']];
  5008. }
  5009. $user_id = $data['user_id'];
  5010. $type_id = $data['type_id'];
  5011. // $type_id = 4;
  5012. var_dump($type_id, '------1--------');
  5013. if ($type_id != 10000) {
  5014. $where[] = ['book.user_id', '=', $user_id];
  5015. }
  5016. var_dump(!empty($data['status1']), '=-===1');
  5017. $result = Book::where($where)
  5018. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5019. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5020. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5021. ->when(isset($data['status1']), function ($query) use ($data) {
  5022. $query->whereIn('book.status', [1, 3]);
  5023. })
  5024. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5025. ->orderBy("updated_at", "desc")
  5026. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5027. if (empty($result)) {
  5028. return Result::error("暂无数据", 0);
  5029. }
  5030. // 取出数据
  5031. $rows = $result->items();
  5032. $count = $result->total();
  5033. $responseData = [
  5034. 'rows' => $rows,
  5035. 'count' => $count,
  5036. ];
  5037. return Result::success($responseData);
  5038. }
  5039. public function deleteBook(array $data): array
  5040. {
  5041. $result = Book::where('id', $data['id'])->delete();
  5042. if (empty($result)) {
  5043. return Result::error("删除失败", 0);
  5044. }
  5045. return Result::success($result);
  5046. }
  5047. public function updateBook(array $data): array
  5048. {
  5049. // $user_id = $data['user_id'] ?? 0;
  5050. $type_id = $data['type_id'] ?? 0;
  5051. // $website_id = $data['website_id'] ?? 0;
  5052. unset($data['user_id']);
  5053. unset($data['type_id']);
  5054. // unset($data['website_id']);
  5055. //处理数组
  5056. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5057. if ($data['img_url'] == '') {
  5058. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5059. preg_match_all($reg, $data['detail'], $matches);
  5060. if (isset($matches[1][0])) {
  5061. //截取varchar240
  5062. $data['img_url'] = substr($matches[1][0], 0, 240);
  5063. }
  5064. }
  5065. if ($data['keyword'] == '') {
  5066. //提取标题+内容中的关键词
  5067. $data['keyword'] = $data['title'];
  5068. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5069. Jieba::init(); // 初始化 jieba-php
  5070. Finalseg::init();
  5071. $segList = Jieba::cut($data['keyword']);
  5072. $segList1 = array_slice($segList, 0, 8);
  5073. $data['keyword'] = implode(',', $segList1);
  5074. }
  5075. if ($data['description'] == '') {
  5076. //提取内容中的描述
  5077. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  5078. }
  5079. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5080. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5081. $result = Book::where("id", $data["id"])->update($data);
  5082. if (empty($result)) {
  5083. return Result::error("更新失败", 0);
  5084. }
  5085. return Result::success($result);
  5086. }
  5087. public function getBookInfo(array $data): array
  5088. {
  5089. $result = Book::where("id", $data["id"])->first();
  5090. if (empty($result)) {
  5091. return Result::error("获取失败", 0);
  5092. }
  5093. return Result::success($result);
  5094. }
  5095. public function updateBookStatus(array $data): array
  5096. {
  5097. //审核
  5098. unset($data['user_id']);
  5099. $result = Book::where("id", $data["id"])->update($data);
  5100. if (empty($result)) {
  5101. return Result::error("更新失败", 0);
  5102. }
  5103. return Result::success($result);
  5104. }
  5105. //20250422 书刊音像
  5106. /**
  5107. * 贴身宝贝
  5108. * @param array $data
  5109. * @return array
  5110. */
  5111. public function getWebsiteTsbb(array $data): array
  5112. {
  5113. $month = $data['month'] ?? date('m');
  5114. $day = $data['day'] ?? date('d');
  5115. // 使用缓存键
  5116. $cacheKey = "tsbb_data_{$month}_{$day}";
  5117. // 尝试从缓存获取数据
  5118. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5119. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5120. if ($cachedData = $cache->get($cacheKey)) {
  5121. return Result::success(unserialize($cachedData));
  5122. }
  5123. //查询老黄历
  5124. try {
  5125. $date = date('Y-m-d');
  5126. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5127. // 使用 curl 替代 file_get_contents
  5128. $ch = curl_init();
  5129. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5130. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5131. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5132. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5133. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5134. 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');
  5135. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5136. 'Accept: application/json',
  5137. 'Content-Type: application/json',
  5138. 'Referer: https://www.36jxs.com/'
  5139. ]);
  5140. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5141. curl_setopt($ch, CURLOPT_ENCODING, '');
  5142. $almanacResponse = curl_exec($ch);
  5143. var_dump("====:", $almanacResponse);
  5144. if (curl_errno($ch)) {
  5145. var_dump('Curl error:', curl_error($ch));
  5146. throw new \Exception('Curl error: ' . curl_error($ch));
  5147. }
  5148. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5149. curl_close($ch);
  5150. if ($almanacResponse === false) {
  5151. throw new \Exception('Failed to fetch almanac data');
  5152. }
  5153. $almanacData = json_decode($almanacResponse, true);
  5154. if (json_last_error() !== JSON_ERROR_NONE) {
  5155. throw new \Exception('Failed to parse almanac data');
  5156. }
  5157. $almanacInfo = $almanacData['data'] ?? [];
  5158. } catch (\Exception $e) {
  5159. var_dump('Exception:', $e->getMessage());
  5160. $almanacInfo = [];
  5161. }
  5162. // 获取历史上的今天数据
  5163. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5164. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5165. ->orderBy('year', 'asc')
  5166. ->select("title", "id", "year", DB::raw('1 as type'))
  5167. ->limit(16)
  5168. ->get();
  5169. // 获取节日数据 - 从今天开始获取未来4条
  5170. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5171. ->orderBy('showtime', 'asc')
  5172. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5173. ->limit(16)
  5174. ->get();
  5175. //说文解字
  5176. $chartacterList = Character::orderBy('updated_at', 'desc')
  5177. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5178. ->limit(6)
  5179. ->get();
  5180. //谜语沙龙
  5181. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5182. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5183. ->limit(4)
  5184. ->get();
  5185. //成语欣赏
  5186. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5187. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5188. ->limit(32)
  5189. ->get();
  5190. //名联赏析
  5191. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5192. ->select("id", "first", "second", DB::raw('6 as type'))
  5193. ->limit(6)
  5194. ->get();
  5195. // 获取分类文章数据
  5196. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5197. ->pluck('category_id')
  5198. ->toArray();
  5199. // $categoryIds = [627, 628, 629, 630, 631, 632, 633, 634, 635, 636];
  5200. // 使用子查询优化
  5201. $articlesList = DB::table('article')
  5202. ->select([
  5203. 'article.id',
  5204. 'article.title',
  5205. 'article.imgurl',
  5206. 'article.created_at',
  5207. 'category.name as category_name',
  5208. 'category.id as category_id',
  5209. 'website_category.aLIas_pinyin as pinyin',
  5210. DB::raw('100 as type')
  5211. ])
  5212. ->join('category', 'article.catid', '=', 'category.id')
  5213. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5214. ->where('website_category.website_id', $data['website_id'])
  5215. ->where('article.status', 1)
  5216. ->whereIn('category.id', $categoryIds)
  5217. // ->whereRaw('article.created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)')
  5218. ->orderBy('article.created_at', 'desc')
  5219. ->get()
  5220. ->groupBy('category_id')
  5221. ->map(function ($group) {
  5222. // 确保第一条数据有图片
  5223. $firstWithImage = $group->first(function ($item) {
  5224. return !empty($item->imgurl);
  5225. });
  5226. if ($firstWithImage) {
  5227. // 如果有带图片的文章,将其放在第一位
  5228. $group = $group->filter(function ($item) use ($firstWithImage) {
  5229. return $item->id !== $firstWithImage->id;
  5230. })->prepend($firstWithImage);
  5231. }
  5232. return [
  5233. 'category_name' => $group->first()->category_name,
  5234. 'catid' => $group->first()->category_id,
  5235. 'pinyin' => $group->first()->pinyin,
  5236. 'type' => 100,
  5237. 'list' => $group->take(6)->map(function ($item) {
  5238. return [
  5239. 'id' => $item->id,
  5240. 'title' => $item->title,
  5241. 'imgurl' => $item->imgurl,
  5242. 'created_at' => $item->created_at
  5243. ];
  5244. })->values()
  5245. ];
  5246. })
  5247. ->values()
  5248. ->toArray();
  5249. $result = [
  5250. 'almanac' => $almanacInfo,
  5251. 'historyTodayList' => [
  5252. 'category_name' => '历史上的今天',
  5253. 'list' => $historyTodayList,
  5254. 'type' => 1
  5255. ],
  5256. 'festivalList' => [
  5257. 'category_name' => '节日预告',
  5258. 'list' => $festivalList,
  5259. 'type' => 2
  5260. ],
  5261. 'chartacterList' => [
  5262. 'category_name' => '说文解字',
  5263. 'list' => $chartacterList,
  5264. 'type' => 3
  5265. ],
  5266. 'coupletList' => [
  5267. 'category_name' => '名联赏析',
  5268. 'list' => $coupletList,
  5269. 'type' => 6
  5270. ],
  5271. 'riddletList' => [
  5272. 'category_name' => '谜语沙龙',
  5273. 'list' => $riddletList,
  5274. 'type' => 4
  5275. ],
  5276. 'idiomList' => [
  5277. 'category_name' => '成语欣赏',
  5278. 'list' => $idiomList,
  5279. 'type' => 5
  5280. ],
  5281. 'articlesList' => $articlesList
  5282. ];
  5283. // 缓存结果,设置1小时过期
  5284. $cache->set($cacheKey, serialize($result), 3600);
  5285. return Result::success($result);
  5286. }
  5287. /**
  5288. * 获取资讯列表
  5289. */
  5290. public function getWebsiteTsbbList(array $data): array
  5291. {
  5292. $page = $data['page'] ?? 1;
  5293. $pageSize = $data['pageSize'] ?? 10;
  5294. // 如果没有传入月份和日期,则使用今天的日期
  5295. $month = $data['month'] ?? date('m');
  5296. $day = $data['day'] ?? date('d');
  5297. $total = 0;
  5298. $result = [];
  5299. $data['type'] = intval($data['type']);
  5300. var_dump("接收参数:", $data);
  5301. switch ($data['type']) {
  5302. case 1:
  5303. $query = HistoryToday::where(function ($q) use ($month, $day) {
  5304. // 当前月份之后的数据
  5305. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  5306. // 或者当前月份且日期大于等于当前日期的数据
  5307. ->orWhere(function ($q) use ($month, $day) {
  5308. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5309. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  5310. });
  5311. })
  5312. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  5313. $total = $query->count();
  5314. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  5315. ->offset(($page - 1) * $pageSize)
  5316. ->limit($pageSize)
  5317. ->get();
  5318. break;
  5319. case 2:
  5320. $query = Festival::where(function ($q) use ($month, $day) {
  5321. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  5322. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  5323. ->orWhere(function ($q) use ($month, $day) {
  5324. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  5325. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  5326. });
  5327. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  5328. $total = $query->count();
  5329. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  5330. ->offset(($page - 1) * $pageSize)
  5331. ->limit($pageSize)
  5332. ->get();
  5333. break;
  5334. case 3:
  5335. $query = Character::orderBy("updated_at", "desc");
  5336. $total = $query->count();
  5337. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  5338. ->offset(($page - 1) * $pageSize)
  5339. ->limit($pageSize)
  5340. ->get();
  5341. break;
  5342. case 4:
  5343. $query = Riddle::orderBy("updated_at", "desc");
  5344. $total = $query->count();
  5345. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  5346. ->offset(($page - 1) * $pageSize)
  5347. ->limit($pageSize)
  5348. ->get();
  5349. break;
  5350. case 5:
  5351. $query = Idiom::orderBy("updated_at", "desc");
  5352. $total = $query->count();
  5353. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  5354. ->offset(($page - 1) * $pageSize)
  5355. ->limit($pageSize)
  5356. ->get();
  5357. break;
  5358. case 6:
  5359. $query = Couplet::orderBy("updated_at", "desc");
  5360. $total = $query->count();
  5361. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  5362. ->offset(($page - 1) * $pageSize)
  5363. ->limit($pageSize)
  5364. ->get();
  5365. break;
  5366. default:
  5367. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  5368. $total = $query->count();
  5369. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  5370. ->offset(($page - 1) * $pageSize)
  5371. ->limit($pageSize)
  5372. ->get();
  5373. }
  5374. return Result::success([
  5375. 'list' => $result,
  5376. 'total' => $total,
  5377. 'page' => (int)$page,
  5378. 'pageSize' => (int)$pageSize,
  5379. 'month' => $month,
  5380. 'day' => $day
  5381. ]);
  5382. }
  5383. /**
  5384. * 1:历史上的今天
  5385. * 2:节日
  5386. * 3:文章
  5387. *
  5388. * 资讯详情信息
  5389. */
  5390. public function getWebsiteTsbbDetail(array $data): array
  5391. {
  5392. $data['type'] = intval($data['type']);
  5393. switch ($data['type']) {
  5394. case 1:
  5395. $result = HistoryToday::where("id", $data['id'])->first();
  5396. break;
  5397. case 2:
  5398. $result = Festival::where("id", $data['id'])->first();
  5399. break;
  5400. case 3:
  5401. $result = Character::where("id", $data['id'])->first();
  5402. break;
  5403. case 4:
  5404. $result = Riddle::where("id", $data['id'])->first();
  5405. break;
  5406. case 5:
  5407. $result = Idiom::where("id", $data['id'])->first();
  5408. break;
  5409. case 6:
  5410. $result = Couplet::where("id", $data['id'])->first();
  5411. break;
  5412. default:
  5413. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  5414. break;
  5415. }
  5416. return Result::success($result);
  5417. }
  5418. /**
  5419. * 农网导航首页数据
  5420. */
  5421. public function getWebsiteNwHomeList(array $data): array
  5422. {
  5423. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  5424. ->pluck('category_id')
  5425. ->toArray();
  5426. // 使用子查询优化
  5427. $articlesList = DB::table('article')
  5428. ->select([
  5429. 'article.id',
  5430. 'article.title',
  5431. 'article.imgurl',
  5432. 'article.created_at',
  5433. 'category.name as category_name',
  5434. 'category.id as category_id',
  5435. 'website_category.aLIas_pinyin as pinyin',
  5436. 'parent_wc.aLIas_pinyin as parent_pinyin',
  5437. DB::raw('100 as type')
  5438. ])
  5439. ->join('category', 'article.catid', '=', 'category.id')
  5440. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5441. ->leftJoin('website_category as parent_wc', function ($join) {
  5442. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  5443. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  5444. })
  5445. ->where('website_category.website_id', $data['website_id'])
  5446. ->where('article.status', 1)
  5447. ->whereIn('category.id', $categoryIds)
  5448. ->orderBy('article.created_at', 'desc')
  5449. ->get()
  5450. ->groupBy('category_id')
  5451. ->map(function ($group) {
  5452. // 确保第一条数据有图片
  5453. $firstWithImage = $group->first(function ($item) {
  5454. return !empty($item->imgurl);
  5455. });
  5456. if ($firstWithImage) {
  5457. // 如果有带图片的文章,将其放在第一位
  5458. $group = $group->filter(function ($item) use ($firstWithImage) {
  5459. return $item->id !== $firstWithImage->id;
  5460. })->prepend($firstWithImage);
  5461. }
  5462. return [
  5463. 'category_name' => $group->first()->category_name,
  5464. 'catid' => $group->first()->category_id,
  5465. 'pinyin' => $group->first()->pinyin,
  5466. 'parent_pinyin' => $group->first()->parent_pinyin,
  5467. 'list' => $group->take(4)->map(function ($item) {
  5468. return [
  5469. 'id' => $item->id,
  5470. 'title' => $item->title,
  5471. ];
  5472. })->values()
  5473. ];
  5474. })
  5475. ->values()
  5476. ->toArray();
  5477. return Result::success($articlesList);
  5478. }
  5479. /**
  5480. * 模块新闻加强版
  5481. * @param array $data
  5482. * @return array
  5483. */
  5484. public function getWebsiteAllArticle(array $data): array
  5485. {
  5486. // 修正传入的字符串,将单引号替换为双引号
  5487. $input['id'] = $data['id'];
  5488. $input['website_id'] = $data['website_id'];
  5489. // 将 JSON 字符串转换为 PHP 数组
  5490. $data = json_decode($input['id'], true);
  5491. // 使用 array_map 处理每个元素
  5492. $result = array_map(function ($item) use ($input) {
  5493. // 检查parent元素是否存在且不是undefined
  5494. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  5495. $count = explode(',', $item['parent']);
  5496. if (count($count) != 3) {
  5497. return Result::error("参数错误", 0);
  5498. }
  5499. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  5500. $website = [
  5501. 'website_id' => $input['website_id'],
  5502. ];
  5503. // 查询栏目名称
  5504. $categroy = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin', 'type']);
  5505. // 查询图片新闻
  5506. if (isset($parentImgNum) && $parentImgNum != 0 && !empty($categroy)) {
  5507. $imgArticles = Article::where('article.status', 1)
  5508. ->where(function ($query) use ($parentCatId) {
  5509. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  5510. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  5511. })
  5512. ->where(function ($query) use ($website) {
  5513. $query->where(function ($subQuery) use ($website) {
  5514. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 1")
  5515. ->orWhereNull("ignore_ids");
  5516. });
  5517. })
  5518. ->where('imgurl', '!=', '')
  5519. ->leftJoin('website_category', function ($join) use ($website) {
  5520. $join->on('article.catid', '=', 'website_category.category_id')
  5521. ->where('website_category.website_id', '=', $website['website_id']);
  5522. })
  5523. ->select(
  5524. 'article.id',
  5525. 'article.title',
  5526. 'article.imgurl',
  5527. 'article.author',
  5528. 'article.updated_at',
  5529. 'article.introduce',
  5530. 'article.islink',
  5531. 'article.linkurl',
  5532. 'article.copyfrom',
  5533. 'article.cat_arr_id',
  5534. 'article.catid',
  5535. 'website_category.alias as category_name',
  5536. )
  5537. ->orderBy('updated_at', 'desc')
  5538. ->limit($parentImgNum)
  5539. ->get();
  5540. //调取封装路由的方法,处理新闻路由
  5541. if (!empty($imgArticles)) {
  5542. $imgArticles = $this->processArticles($imgArticles, $website);
  5543. }
  5544. }
  5545. // 查询文字新闻
  5546. if (isset($parentTextNum) && $parentTextNum != 0 && !empty($categroy)) {
  5547. $textArticles = [];
  5548. $textArticles = Article::where('article.status', 1)
  5549. ->where(function ($query) use ($parentCatId) {
  5550. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  5551. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  5552. })
  5553. ->where(function ($query) use ($website) {
  5554. $query->where(function ($subQuery) use ($website) {
  5555. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 1")
  5556. ->orWhereNull("ignore_ids");
  5557. });
  5558. })
  5559. ->leftJoin('website_category', function ($join) use ($website) {
  5560. $join->on('article.catid', '=', 'website_category.category_id')
  5561. ->where('website_category.website_id', '=', $website['website_id']);
  5562. })
  5563. ->select(
  5564. 'article.id',
  5565. 'article.title',
  5566. 'article.author',
  5567. 'article.updated_at',
  5568. 'article.cat_arr_id',
  5569. 'article.introduce',
  5570. 'article.islink',
  5571. 'article.linkurl',
  5572. 'article.copyfrom',
  5573. 'article.catid',
  5574. 'website_category.alias as category_name',
  5575. )
  5576. ->orderBy('updated_at', 'desc')
  5577. ->limit($parentTextNum)
  5578. ->get();
  5579. if (!empty($textArticles)) {
  5580. $textArticles = $this->processArticles($textArticles, $website);
  5581. }
  5582. }
  5583. }
  5584. $resultItem = [
  5585. 'alias' => $categroy ? $categroy->alias : null,
  5586. 'category_id' => $categroy ? $categroy->category_id : null,
  5587. 'pinyin' => $categroy ? $categroy->aLIas_pinyin : null,
  5588. 'imgnum' => $imgArticles ?? [],
  5589. 'textnum' => $textArticles ?? [],
  5590. ];
  5591. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  5592. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  5593. $childCategory = WebsiteCategory::where($website)
  5594. ->where("category_id", $childCatId)
  5595. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "') = 1")
  5596. ->first(['alias', 'category_id', 'aLIas_pinyin', 'pid', 'type', 'category_arr_id as cat_arr_id']);
  5597. if (!empty($childCategory)) {
  5598. $childCategory = $this->processArticles($childCategory, $website);
  5599. // 查询此层级的所有子栏目
  5600. $all_childcat = WebsiteCategory::where($website)
  5601. ->where("pid", $childCategory['pid'])
  5602. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "') = 1")
  5603. ->get(['alias', 'category_id', 'aLIas_pinyin', 'pid', 'type', 'category_arr_id as cat_arr_id']);
  5604. $all_childcat = $this->processArticles($all_childcat, $website);
  5605. // 查询子栏目图片新闻
  5606. if (isset($childImgNum) && $childImgNum != 0) {
  5607. $childImgArticles = Article::where('catid', $childCatId)
  5608. ->where('status', 1)
  5609. ->where(function ($query) use ($website) {
  5610. $query->where(function ($subQuery) use ($website) {
  5611. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 1");
  5612. })->orWhereNull("ignore_ids");
  5613. })
  5614. ->select(
  5615. 'article.id',
  5616. 'article.title',
  5617. 'article.imgurl',
  5618. 'article.author',
  5619. 'article.updated_at',
  5620. 'article.introduce',
  5621. 'article.islink',
  5622. 'article.linkurl',
  5623. 'article.catid',
  5624. 'article.cat_arr_id',
  5625. 'article.copyfrom',
  5626. )
  5627. ->where('imgurl', '!=', '')
  5628. ->orderBy('updated_at', 'desc')
  5629. ->limit($childImgNum)
  5630. ->get();
  5631. $childImgArticles = $this->processArticles($childImgArticles, $website);
  5632. }
  5633. // 查询子栏目文字新闻
  5634. if (isset($childTextNum) && $childTextNum != 0) {
  5635. $childTextArticles = Article::where('catid', $childCatId)
  5636. ->where('status', 1)
  5637. ->where(function ($query) use ($website) {
  5638. $query->where(function ($subQuery) use ($website) {
  5639. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 1");
  5640. })->orWhereNull("ignore_ids");
  5641. })
  5642. ->select(
  5643. 'article.id',
  5644. 'article.title',
  5645. 'article.author',
  5646. 'article.updated_at',
  5647. 'article.introduce',
  5648. 'article.islink',
  5649. 'article.linkurl',
  5650. 'article.catid',
  5651. 'article.cat_arr_id',
  5652. 'article.copyfrom',
  5653. )
  5654. ->orderBy('updated_at', 'desc')
  5655. ->limit($childTextNum)
  5656. ->get();
  5657. $childTextArticles = $this->processArticles($childTextArticles, $website);
  5658. }
  5659. }
  5660. $resultItem['child'] = [
  5661. 'alias' => $childCategory ? $childCategory->alias : null,
  5662. 'category_id' => $childCategory ? $childCategory->category_id : null,
  5663. 'type' => $childCategory ? $childCategory->type : null,
  5664. 'pinyin' => $childCategory ? $childCategory->pinyin : null,
  5665. 'all_childcat' => $all_childcat ?? [],
  5666. 'imgnum' => $childImgArticles ?? [],
  5667. 'textnum' => $childTextArticles ?? [],
  5668. ];
  5669. } else {
  5670. $resultItem['child'] = [];
  5671. }
  5672. return $resultItem;
  5673. }, $data);
  5674. return Result::success($result);
  5675. }
  5676. }