NewsService.php 229 KB

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