NewsService.php 225 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181
  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. * 模块新闻加强版
  1402. * @param array $data
  1403. * @return array
  1404. */
  1405. /**
  1406. * 辅助方法:获取文章列表
  1407. */
  1408. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1409. {
  1410. sleep(1);
  1411. $query = Article::where('article.status', 1)
  1412. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1413. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1414. ->where(function ($query) use ($website) {
  1415. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1416. })
  1417. ->leftJoin('website_category', function ($join) use ($website) {
  1418. $join->on('article.catid', '=', 'website_category.category_id')
  1419. ->where('website_category.website_id', '=', $website['website_id']);
  1420. })
  1421. ->select(
  1422. 'article.id',
  1423. 'article.title',
  1424. 'article.imgurl',
  1425. 'article.author',
  1426. 'article.updated_at',
  1427. 'article.introduce',
  1428. 'article.islink',
  1429. 'article.linkurl',
  1430. 'article.copyfrom',
  1431. 'article.cat_arr_id',
  1432. 'article.catid',
  1433. 'website_category.alias as category_name'
  1434. )
  1435. ->orderBy('updated_at', 'desc')
  1436. ->limit($limit);
  1437. // 如果是图片文章,添加图片URL条件
  1438. if ($isImageArticle) {
  1439. $query->where('imgurl', '!=', '');
  1440. } else {
  1441. // 文字文章不需要imgurl字段
  1442. $query->addSelect('article.introduce');
  1443. }
  1444. $articles = $query->get();
  1445. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1446. }
  1447. /**
  1448. * 乡村网-获取特殊新闻模块
  1449. * @param array $data
  1450. * @return array
  1451. */
  1452. public function getWebsiteArticles(array $data): array
  1453. {
  1454. $input['id'] = $data['id'];
  1455. $input['website_id'] = $data['website_id'];
  1456. $data = json_decode($input['id'], true);
  1457. // 使用 array_map 处理每个元素
  1458. $result = array_map(function ($item) use ($input) {
  1459. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1460. $website = [
  1461. 'website_id' => $input['website_id']
  1462. ];
  1463. // 查询栏目名称
  1464. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1465. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1466. if (empty($category)) {
  1467. $imgArticles = [];
  1468. $textArticles = [];
  1469. // return Result::error("暂无此栏目",0);
  1470. } else {
  1471. $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1472. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin . '/' : null;
  1473. // return Result::success($website);
  1474. // 查询图片新闻
  1475. // 合并查询条件
  1476. $baseQuery = Article::where(function ($query) use ($website) {
  1477. $query->where(function ($subQuery) use ($website) {
  1478. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1479. })->orWhereNull("ignore_ids");
  1480. })
  1481. ->where('article.status', 1)
  1482. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1483. ->where('website_category.website_id', $website['website_id']);
  1484. // 查询文字新闻
  1485. $textArticles = clone $baseQuery;
  1486. $textArticles = $textArticles->whereIn('catid', $child_category)
  1487. ->select(
  1488. 'article.id',
  1489. 'article.title',
  1490. // 'article.imgurl',
  1491. 'article.author',
  1492. 'article.updated_at',
  1493. 'article.introduce',
  1494. 'article.islink',
  1495. 'article.linkurl',
  1496. 'article.copyfrom',
  1497. 'website_category.category_id',
  1498. 'website_category.alias',
  1499. 'website_category.aLIas_pinyin'
  1500. )
  1501. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1502. ->orderBy('article.updated_at', 'desc')
  1503. ->limit($parentTextNum)
  1504. ->get()
  1505. ->all();
  1506. if (empty($textArticles)) {
  1507. $textArticles = clone $baseQuery;
  1508. $textArticles = $textArticles->where('catid', $parentCatId)
  1509. ->select(
  1510. 'article.id',
  1511. 'article.title',
  1512. // 'article.imgurl',
  1513. 'article.author',
  1514. 'article.updated_at',
  1515. 'article.introduce',
  1516. 'article.islink',
  1517. 'article.linkurl',
  1518. 'article.copyfrom',
  1519. 'website_category.category_id',
  1520. 'website_category.alias',
  1521. 'website_category.aLIas_pinyin'
  1522. )
  1523. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1524. ->orderBy('article.updated_at', 'desc')
  1525. ->limit($parentTextNum)
  1526. ->get()
  1527. ->all();
  1528. }
  1529. // 查询图片新闻
  1530. $imgArticles = clone $baseQuery;
  1531. $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid', $child_category)
  1532. ->select(
  1533. 'article.id',
  1534. 'article.title',
  1535. 'article.imgurl',
  1536. 'article.author',
  1537. 'article.updated_at',
  1538. 'article.introduce',
  1539. 'article.islink',
  1540. 'article.linkurl',
  1541. 'article.copyfrom',
  1542. 'website_category.category_id',
  1543. 'website_category.alias',
  1544. 'website_category.aLIas_pinyin'
  1545. )
  1546. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1547. ->orderBy('article.updated_at', 'desc')
  1548. ->limit($parentImgNum)
  1549. ->get()
  1550. ->all();
  1551. if (empty($imgArticles)) {
  1552. $imgArticles = clone $baseQuery;
  1553. $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid', $parentCatId)
  1554. ->select(
  1555. 'article.id',
  1556. 'article.title',
  1557. 'article.imgurl',
  1558. 'article.author',
  1559. 'article.updated_at',
  1560. 'article.introduce',
  1561. 'article.islink',
  1562. 'article.linkurl',
  1563. 'article.copyfrom',
  1564. 'website_category.category_id',
  1565. 'website_category.alias',
  1566. 'website_category.aLIas_pinyin'
  1567. )
  1568. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1569. ->orderBy('article.updated_at', 'desc')
  1570. ->limit($parentImgNum)
  1571. ->get()
  1572. ->all();
  1573. }
  1574. }
  1575. $resultItem = [
  1576. 'alias' => $category ? $category->alias : null,
  1577. 'category_id' => $parentCatId,
  1578. 'pinyin' => $pinyin ? $pinyin : null,
  1579. 'imgnum' => $imgArticles ?? [],
  1580. 'textnum' => $textArticles ?? [],
  1581. ];
  1582. return $resultItem;
  1583. }, $data);
  1584. return Result::success($result);
  1585. }
  1586. // 封装处理商品的路由问题
  1587. function processGoods($goods, $data)
  1588. {
  1589. return $goods->map(function ($good) use ($data) {
  1590. $catid = $good->catid ?? 0;
  1591. // $pinyin = '';
  1592. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1593. if (!empty($category->pid) && $category->pid != 0) {
  1594. $level = json_decode($category->category_arr_id);
  1595. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1596. ->whereIn('category_id', $level)
  1597. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1598. ->get(['aLIas_pinyin'])
  1599. ->pluck('aLIas_pinyin')
  1600. ->implode('/');
  1601. } else {
  1602. $pinyin = $category->aLIas_pinyin ?? '';
  1603. }
  1604. if (isset($good->city_id) && !empty($good->city_id)) {
  1605. $city = District::where('id', $good->city_id)->first(['name']);
  1606. $good->city_name = $city->name ?? '';
  1607. }
  1608. // 解析imgurl JSON并取第一条数据
  1609. $imgUrls = json_decode($good->imgurl, true);
  1610. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1611. $good->pinyin = $pinyin;
  1612. return $good;
  1613. });
  1614. }
  1615. /**
  1616. * 获取商城首页-根据栏目id
  1617. * @param array $data
  1618. * @return array
  1619. * */
  1620. function getWebsiteCatidshop(array $data): array
  1621. {
  1622. $input['catid'] = $data['catid'];
  1623. $input['website_id'] = $data['website_id'];
  1624. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1625. $result = array_map(function ($item) use ($input) {
  1626. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1627. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1628. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1629. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1630. if (empty($category) || $category->type != 2) {
  1631. return Result::error("暂无此栏目", 0);
  1632. } else {
  1633. $website['website_id'] = $input['website_id'];
  1634. $goods = Good::where('good.status', 2)
  1635. ->where('good.website_id', $website['website_id'])
  1636. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1637. ->select(
  1638. 'good.id',
  1639. 'good.name',
  1640. 'good.imgurl',
  1641. 'good.description',
  1642. 'good.updated_at',
  1643. 'good.catid',
  1644. 'good.type_id',
  1645. 'good.price',
  1646. 'good.com',
  1647. 'good.level',
  1648. 'good.unit'
  1649. )
  1650. ->orderBy('updated_at', 'desc')
  1651. ->offset($goodStart)
  1652. ->limit($goodNum);
  1653. $all_goods = $goods->get();
  1654. $all_goods = $this->processGoods($all_goods, $website);
  1655. }
  1656. return $all_goods ?? [];
  1657. }
  1658. }, $data);
  1659. return Result::success($result);
  1660. }
  1661. /**
  1662. * 获取商品模块
  1663. * @param array $data
  1664. * @return array
  1665. * */
  1666. public function getWebsiteshop(array $data): array
  1667. {
  1668. $input['id'] = $data['id'];
  1669. $input['website_id'] = $data['website_id'];
  1670. $catid = $data['catid'];
  1671. $data = json_decode($input['id'] ?? '', true) ?? [];
  1672. $result['goods'] = array_map(function ($item) use ($input) {
  1673. // 检查parent元素是否存在且不是undefined
  1674. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  1675. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  1676. $website = $input['website_id'];
  1677. $query = Good::where('good.status', 2)
  1678. ->where('good.website_id', $website);
  1679. switch ($Levelid) {
  1680. case 1:
  1681. case 2:
  1682. case 3:
  1683. $goods = $query->where(function ($q) use ($Levelid) {
  1684. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  1685. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  1686. });
  1687. break;
  1688. case 4:
  1689. $goods = $query;
  1690. break;
  1691. case 5:
  1692. $goods = $query->where('type_id', 1);
  1693. break;
  1694. case 6:
  1695. $goods = $query->where('type_id', 2);
  1696. break;
  1697. default:
  1698. return [];
  1699. }
  1700. $all_goods = $goods
  1701. ->select(
  1702. 'good.id',
  1703. 'good.name',
  1704. 'good.imgurl',
  1705. 'good.description',
  1706. 'good.updated_at',
  1707. 'good.catid',
  1708. 'good.type_id',
  1709. 'good.price',
  1710. 'good.level',
  1711. 'good.website_id'
  1712. )
  1713. ->orderBy('updated_at', 'desc')
  1714. ->offset($goodStart)
  1715. ->limit($goodNum)
  1716. ->get();
  1717. $web['website_id'] = $website;
  1718. $all_goods = $this->processGoods($all_goods, $web);
  1719. }
  1720. return $all_goods;
  1721. }, $data);
  1722. $website = $input['website_id'];
  1723. $result['article'] = Article::where(function ($query) use ($website) {
  1724. $query->where(function ($subQuery) use ($website) {
  1725. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1726. })->orWhereNull("ignore_ids");
  1727. })
  1728. ->where('catid', $catid)
  1729. ->where('article.status', 1)
  1730. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  1731. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  1732. ->orderBy('article.updated_at', 'desc')
  1733. ->first();
  1734. return Result::success($result);
  1735. }
  1736. /**
  1737. * 获取商品分类
  1738. * @param array $data
  1739. * @return array
  1740. * */
  1741. public function getWebsiteshopCat(array $data): array
  1742. {
  1743. $website = $data['website_id'];
  1744. $category = WebsiteCategory::where('website_id', $website)
  1745. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  1746. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  1747. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  1748. ->orderBy('sort')
  1749. ->get();
  1750. $cat = $category->map(function ($item) use ($website) {
  1751. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  1752. $pid = $item->pid ?? 0;
  1753. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  1754. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  1755. ->where('website_id', $website)
  1756. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  1757. ->get(['aLIas_pinyin'])
  1758. ->pluck('aLIas_pinyin')
  1759. ->implode('/');
  1760. } else {
  1761. $pinyin = $item->aLIas_pinyin ?? '';
  1762. }
  1763. $item->pinyin = $pinyin;
  1764. });
  1765. if (empty($category)) {
  1766. return Result::error("栏目查询失败", 0);
  1767. }
  1768. $cat_tree = Result::buildMenuTree($category);
  1769. $web['website_id'] = $website;
  1770. $goods = Good::where('website_id', $website)
  1771. ->where('status', 2)
  1772. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  1773. ->latest('updated_at')
  1774. ->offset(($data['page'] - 1) * $data['pageSize'])
  1775. ->limit($data['pageSize'])
  1776. ->get();
  1777. if (!empty($goods)) {
  1778. if ($goods->count() > 1 && !empty($goods)) {
  1779. $goods = $this->processGoods($goods, $web);
  1780. }
  1781. } else {
  1782. $goods = [];
  1783. }
  1784. $result = [
  1785. 'category' => $cat_tree,
  1786. 'goods' => $goods,
  1787. ];
  1788. // $resul['goods'] = $goods;
  1789. if (empty($result)) {
  1790. return Result::error("查询失败", 0);
  1791. }
  1792. return Result::success($result);
  1793. }
  1794. /*
  1795. * 获取商品列表
  1796. * @param array $data
  1797. * @return array
  1798. * */
  1799. public function getWebsiteshopList(array $data): array
  1800. {
  1801. // return Result::success($data);
  1802. $where = [
  1803. 'status' => 2,
  1804. 'website_id' => $data['website_id'],
  1805. ];
  1806. if((empty($data['catid']) ||!isset($data['catid'])) && (empty($data['keyword']) ||!isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))){
  1807. return Result::error("查询失败", 0);
  1808. }
  1809. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  1810. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid',$data['id'])->orderBy('sort')->first(['category_id']);
  1811. $data['catid'] = $category->category_id ?? 0;
  1812. }
  1813. if(isset($data['keyword']) &&!empty($data['keyword'])){
  1814. array_push($where, ['name', 'like', '%'. $data['keyword'].'%']);
  1815. }
  1816. if(isset($data['type_id']) && !empty($data['type_id'])){
  1817. array_push($where, ['type_id', $data['type_id']]);
  1818. }
  1819. $query = Good::where($where)
  1820. ->when(isset($data['catid']) &&!empty($data['catid']), function ($query) use ($data) {
  1821. $query->where(function($q) use ($data) {
  1822. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '". intval($data['catid']). "') = 1")
  1823. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"". intval($data['catid']). "\"') = 1");
  1824. });
  1825. })
  1826. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  1827. $query->where(function($q) use ($data) {
  1828. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '". intval($data['city_id']). "') = 1")
  1829. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"". intval($data['city_id']). "\"') = 1");
  1830. });
  1831. })
  1832. ->select('good.id', 'good.name', 'good.imgurl', 'good.description', 'good.updated_at', 'good.com',
  1833. 'good.catid','good.type_id','good.website_id','good.cat_arr_id','good.created_at','good.city_id')
  1834. ->latest('updated_at');
  1835. if(isset($data['ismix']) && $data['ismix'] == 1){
  1836. $result['count'] = $query->clone()->count();
  1837. $result['goods'] = $this->processGoods(
  1838. $query->clone()
  1839. ->offset(($data['page'] - 1) * $data['pageSize'])
  1840. ->limit($data['pageSize'])
  1841. ->get(),
  1842. $data
  1843. );
  1844. }else{
  1845. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  1846. // 获取 type_id 为 1 的数据
  1847. $result['type1'] = $this->processGoods(
  1848. $query->clone()
  1849. ->where('type_id', 1)
  1850. ->offset(($data['page'] - 1) * $data['pageSize'])
  1851. ->limit($data['pageSize'])
  1852. ->get(),
  1853. $data
  1854. );
  1855. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  1856. // 获取 type_id 为 2 的数据
  1857. $result['type2'] = $this->processGoods(
  1858. $query->clone()
  1859. ->where('type_id', 2)
  1860. ->offset(($data['page'] - 1) * $data['pageSize'])
  1861. ->limit($data['pageSize'])
  1862. ->get(),
  1863. $data
  1864. );
  1865. }
  1866. if(empty($result)){
  1867. return Result::error("查询失败", 0);
  1868. }
  1869. return Result::success($result);
  1870. }
  1871. /**
  1872. * 获取商品详情
  1873. * @param array $data
  1874. * @return array
  1875. * */
  1876. public function getWebsiteshopInfo(array $data): array
  1877. {
  1878. $where = [
  1879. 'good.status' => 2,
  1880. 'good.website_id' => $data['website_id'],
  1881. 'good.id' => $data['id'],
  1882. ];
  1883. $goods = Good::where($where)
  1884. ->where('good.id', $data['id'])
  1885. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  1886. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  1887. ->first();
  1888. if (empty($goods)) {
  1889. return Result::error("查询失败", 0);
  1890. }
  1891. $goods->imgurl = json_decode($goods->imgurl, true);
  1892. return Result::success($goods);
  1893. }
  1894. /**
  1895. * 封装处理文章的路由问题
  1896. * */
  1897. function processArticles($articles, $data)
  1898. {
  1899. // 检查 $articles 是否为数组或可迭代对象
  1900. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  1901. return $articles->map(function ($article) use ($data) {
  1902. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  1903. $catid = $article->cat_arr_id ?? '';
  1904. }
  1905. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  1906. $catid = $article->category_arr_id ?? '';
  1907. }
  1908. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  1909. $level = json_decode($catid, true);
  1910. if (!is_array($level)) {
  1911. return $article;
  1912. } else {
  1913. $level = array_map('intval', $level);
  1914. }
  1915. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1916. ->where($data)
  1917. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1918. ->pluck('aLIas_pinyin')
  1919. ->implode('/');
  1920. $article->pinyin = $pinyin ?? '';
  1921. return $article;
  1922. });
  1923. } else {
  1924. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  1925. $catid = $articles->cat_arr_id ?? '';
  1926. $level = json_decode($catid, true);
  1927. if (!is_array($level)) {
  1928. return $articles;
  1929. } else {
  1930. $level = array_map('intval', $level);
  1931. }
  1932. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1933. ->where($data)
  1934. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1935. ->pluck('aLIas_pinyin')
  1936. ->implode('/');
  1937. $articles->pinyin = $pinyin ?? '';
  1938. return $articles;
  1939. }
  1940. }
  1941. // 封装处理由问题
  1942. function processJob($job, $data)
  1943. {
  1944. return $job->map(function ($job) use ($data) {
  1945. $category = $job->cat_arr_id ?? '';
  1946. $cityid = $job->city_arr_id ?? '';
  1947. $city = json_decode($cityid, true);
  1948. $pinyin = '';
  1949. $level = json_decode($category, true);
  1950. // 路由
  1951. if (!empty($level) && is_array($level)) {
  1952. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1953. ->where('website_id', $data['website_id']) // 添加网站ID条件
  1954. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1955. ->get(['aLIas_pinyin'])
  1956. ->pluck('aLIas_pinyin')
  1957. ->implode('/');
  1958. if (empty($pinyin)) {
  1959. $pinyin = $pinyin->aLIas_pinyin ?? '';
  1960. }
  1961. $job->pinyin = $pinyin;
  1962. }
  1963. // 取职位-城市 市??省
  1964. if (!empty($city) && is_array($city)) {
  1965. if (isset($city[1]) && !empty($city[1])) {
  1966. $city = District::where('id', $city[1])->first(['name']);
  1967. $job->city_name = $city->name ?? '';
  1968. } else if (isset($city[0]) && !empty($city[0])) {
  1969. $city = District::where('id', $city[0])->first(['name']);
  1970. $job->city_name = $city->name ?? '';
  1971. } else {
  1972. $job->city_name = '全国';
  1973. }
  1974. }
  1975. // 获取简历最后一级地区
  1976. if (isset($job->city_id) && !empty($job->city_id)) {
  1977. $city = District::where('id', $job->city_id)->first(['name']);
  1978. $job->hunt_cityname = $city->name ?? '';
  1979. }
  1980. // 组合详细地址
  1981. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  1982. $address_id = json_decode($job->address_arr_id, true) ?? [];
  1983. if (is_array($address_id) && !empty($address_id)) {
  1984. $address = District::whereIn('id', $address_id)
  1985. ->orderBy('level', 'asc')
  1986. ->get(['name'])
  1987. ->pluck('name')
  1988. ->implode('');
  1989. // $job->address_name = $address ?? '';
  1990. $job->address_name = ($address ?? '') . ($job->address ?? '');
  1991. }
  1992. }
  1993. // 取行业
  1994. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  1995. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  1996. if (!empty($job->industry)) {
  1997. $query->where('hyid', $job->industry);
  1998. } else if (!empty($job->hy_id)) {
  1999. $query->where('hyid', $job->hy_id);
  2000. } else if (!empty($job->company_hy_id)) {
  2001. $query->where('hyid', $job->company_hy_id);
  2002. } else {
  2003. $query->where('hyid', $job->job_industry);
  2004. }
  2005. })->first(['hyname']);
  2006. $job->hy_name = $hy_name->hyname ?? '';
  2007. }
  2008. // 取职位类别
  2009. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2010. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2011. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2012. $job->zw_name = $zw_name->zwname ?? '';
  2013. }
  2014. // 取具体职位
  2015. 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))) {
  2016. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2017. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2018. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2019. }
  2020. // 取工作经验
  2021. if (isset($job->experience) && !empty($job->experience)) {
  2022. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2023. $job->experience_name = $experience->ename ?? '';
  2024. }
  2025. // 取学历
  2026. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2027. $education = $job->educational ?? $job->school_education;
  2028. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2029. $job->education_name = $education->ename ?? '';
  2030. }
  2031. // 语言
  2032. if (isset($job->language) && !empty($job->language)) {
  2033. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2034. $job->language_name = $language->ename ?? '';
  2035. }
  2036. // 薪资
  2037. if (isset($job->salary) && !empty($job->salary)) {
  2038. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2039. $job->salary_name = $salary->ename ?? '';
  2040. }
  2041. // 职位性质
  2042. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2043. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2044. $job->job_nature_name = $job_nature->ename ?? '';
  2045. }
  2046. // 公司规模
  2047. if (isset($job->company_size) && !empty($job->company_size)) {
  2048. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2049. $job->company_size_name = $company_size->ename ?? '';
  2050. }
  2051. // 公司性质
  2052. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2053. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2054. $job->company_nature_name = $company_nature->nature_name ?? '';
  2055. }
  2056. // $job->pinyin = $pinyin;
  2057. return $job;
  2058. });
  2059. }
  2060. /**
  2061. * 获取书籍模块
  2062. * @param array $data
  2063. * @return array
  2064. * */
  2065. public function getWebsiteBook(array $data): array
  2066. {
  2067. $input['id'] = $data['id'];
  2068. $input['website_id'] = $data['website_id'];
  2069. // 将 JSON 字符串转换为 PHP 数组
  2070. $data = json_decode($input['id'], true);
  2071. // 使用 array_map 处理每个元素
  2072. $result = array_map(function ($item) use ($input) {
  2073. // 检查parent元素是否存在且不是undefined
  2074. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2075. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2076. $website = [
  2077. 'website_id' => $input['website_id'],
  2078. ];
  2079. // 查询栏目名称
  2080. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2081. if (empty($category)) {
  2082. $parent_alias = '';
  2083. $parent_pinyin = null;
  2084. $imgBooks = [];
  2085. $textBooks = [];
  2086. } else {
  2087. $parent_alias = $category->alias ?? '';
  2088. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2089. // 查找子分类ID数组
  2090. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2091. array_push($childCategoryIds, $parentCatId);
  2092. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2093. if ($parentImgNum != 0) {
  2094. // 查询图片新闻
  2095. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2096. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2097. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2098. })
  2099. ->where('book.status', 2)
  2100. ->where('book.img_url', '!=', '')
  2101. ->leftJoin('website_category', function ($join) use ($website) {
  2102. $join->on('book.cat_id', '=', 'website_category.category_id')
  2103. ->where('website_category.website_id', '=', $website['website_id']);
  2104. })
  2105. ->select(
  2106. 'book.id',
  2107. 'book.title',
  2108. 'book.img_url',
  2109. 'book.price',
  2110. 'book.market_price',
  2111. 'book.description',
  2112. 'book.cat_id',
  2113. 'book.description',
  2114. 'book.updated_at',
  2115. 'website_category.alias as category_name',
  2116. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2117. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2118. )
  2119. ->orderBy('updated_at', 'desc')
  2120. ->limit($parentImgNum)
  2121. ->get()->all();
  2122. // 查询文字新闻
  2123. }
  2124. if ($parentTextNum != 0) {
  2125. $textBooks = [];
  2126. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2127. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2128. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2129. })
  2130. ->where('book.status', 2)
  2131. ->leftJoin('website_category', function ($join) use ($website) {
  2132. $join->on('book.cat_id', '=', 'website_category.category_id')
  2133. ->where('website_category.website_id', '=', $website['website_id']);
  2134. })
  2135. ->select(
  2136. 'book.id',
  2137. 'book.title',
  2138. 'book.img_url',
  2139. 'book.price',
  2140. 'book.market_price',
  2141. 'book.description',
  2142. 'book.cat_id',
  2143. 'book.description',
  2144. 'book.updated_at',
  2145. 'website_category.alias as category_name',
  2146. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2147. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2148. )
  2149. ->orderBy('updated_at', 'desc')
  2150. ->limit($parentTextNum)
  2151. ->get()->all();
  2152. }
  2153. }
  2154. }
  2155. $resultItem = [
  2156. 'alias' => $parent_alias ?? '',
  2157. 'category_id' => $parentCatId ?? 0,
  2158. 'pinyin' => $parent_pinyin ?? null,
  2159. 'imgnum' => $imgBooks ?? [],
  2160. 'textnum' => $textBooks ?? [],
  2161. ];
  2162. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2163. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2164. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2165. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2166. ->get()->all();
  2167. if (!empty($childCategory)) {
  2168. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2169. // 查询子栏目名称
  2170. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2171. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2172. ->first();
  2173. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2174. $childImgArticles = [];
  2175. $childTextArticles = [];
  2176. $resultItem['child'] = [];
  2177. } else {
  2178. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2179. // 查询子栏目图片新闻
  2180. $childImgArticles = Book::where('cat_id', $childCatId)
  2181. ->where('status', 2)
  2182. ->where('img_url', '!=', '')
  2183. ->leftJoin('website_category', function ($join) use ($website) {
  2184. $join->on('book.cat_id', '=', 'website_category.category_id')
  2185. ->where('website_category.website_id', '=', $website['website_id']);
  2186. })
  2187. ->select(
  2188. 'book.id',
  2189. 'book.title',
  2190. 'book.img_url',
  2191. 'book.price',
  2192. 'book.market_price',
  2193. 'book.description',
  2194. 'book.cat_id',
  2195. 'book.description',
  2196. 'book.updated_at',
  2197. DB::raw("'$child_pinyin' as pinyin")
  2198. )
  2199. ->orderBy('updated_at', 'desc')
  2200. ->limit($childImgNum)
  2201. ->get()->all();
  2202. // 查询子栏目文字新闻
  2203. $childTextArticles = Book::where('cat_id', $childCatId)
  2204. ->where('status', 2)
  2205. ->leftJoin('website_category', function ($join) use ($website) {
  2206. $join->on('book.cat_id', '=', 'website_category.category_id')
  2207. ->where('website_category.website_id', '=', $website['website_id']);
  2208. })
  2209. ->select(
  2210. 'book.id',
  2211. 'book.title',
  2212. 'book.img_url',
  2213. 'book.price',
  2214. 'book.market_price',
  2215. 'book.description',
  2216. 'book.cat_id',
  2217. 'book.description',
  2218. 'book.updated_at',
  2219. DB::raw("'$child_pinyin' as pinyin")
  2220. )
  2221. ->orderBy('updated_at', 'desc')
  2222. ->limit($childTextNum)
  2223. ->get()->all();
  2224. $resultItem['child'] = [
  2225. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2226. 'category_id' => $childCatId,
  2227. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2228. 'all_childcat' => $childCategory,
  2229. 'imgnum' => $childImgArticles,
  2230. 'textnum' => $childTextArticles,
  2231. ];
  2232. }
  2233. }
  2234. } else {
  2235. $resultItem['child'] = [];
  2236. }
  2237. return $resultItem;
  2238. }, $data);
  2239. return Result::success($result);
  2240. }
  2241. /**
  2242. * 获取书刊列表
  2243. * @param array $data
  2244. * @return array
  2245. * */
  2246. public function getWebsiteBookList(array $data): array
  2247. {
  2248. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2249. if (empty($web)) {
  2250. return Result::error("查询失败", 0);
  2251. }
  2252. $catid = $data['id'];
  2253. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2254. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2255. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2256. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2257. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2258. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2259. ->where('pid', $category['pid'])
  2260. ->select(
  2261. 'category_id',
  2262. 'alias',
  2263. 'aLIas_pinyin',
  2264. 'pid',
  2265. 'sort',
  2266. 'is_url',
  2267. 'web_url',
  2268. 'seo_title',
  2269. 'seo_keywords',
  2270. 'seo_description',
  2271. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2272. )
  2273. ->orderBy('sort')
  2274. ->get()->all();
  2275. if (empty($category)) {
  2276. return Result::error("查询失败", 0);
  2277. }
  2278. $query = Book::where('book.status', 2)
  2279. ->where('book.website_id', $data['website_id'])
  2280. ->where('book.cat_id', $catid)
  2281. ->select(
  2282. 'book.id',
  2283. 'book.title',
  2284. 'book.img_url',
  2285. 'book.description',
  2286. 'book.updated_at',
  2287. 'book.cat_id',
  2288. DB::raw("'$pinyin' as pinyin")
  2289. )
  2290. ->orderBy('book.updated_at', 'desc');
  2291. $count = $query->count();
  2292. $query = clone $query;
  2293. $Book = $query
  2294. ->limit($data['pageSize'])
  2295. ->offset(($data['page'] - 1) * $data['pageSize'])
  2296. ->get()->all();
  2297. $result = [
  2298. 'category' => $categorys,
  2299. 'books' => $Book,
  2300. 'count' => $count,
  2301. ];
  2302. // if(empty($result)){
  2303. // return Result::error("查询失败", 0);
  2304. // }
  2305. return Result::success($result);
  2306. }
  2307. /**
  2308. * 获取书刊详情
  2309. * @param array $data
  2310. * @return array
  2311. * */
  2312. public function getWebsiteBookInfo(array $data): array
  2313. {
  2314. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2315. if (empty($web)) {
  2316. return Result::error("查询失败", 0);
  2317. }
  2318. $book = Book::where('status', 2)
  2319. ->where('website_id', $data['website_id'])
  2320. ->where('id', $data['id'])
  2321. ->select(
  2322. 'book.*',
  2323. )
  2324. ->orderBy('updated_at', 'desc')
  2325. ->first();
  2326. if (empty($book)) {
  2327. return Result::error("查询失败", 0);
  2328. }
  2329. // 先查询当前分类的 pid
  2330. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2331. ->where('category_id', $book['cat_id'])
  2332. ->first(['pid', 'category_id']);
  2333. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2334. if (!empty($carpid)) {
  2335. if ($carpid->pid != 0) {
  2336. $pid = $carpid['pid'];
  2337. // $parent_pinyin = '';
  2338. } else {
  2339. $pid = $carpid['category_id'];
  2340. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2341. }
  2342. }
  2343. $categorys = $query->where('pid', $pid)
  2344. ->select(
  2345. 'category_id',
  2346. 'alias',
  2347. 'aLIas_pinyin',
  2348. 'pid',
  2349. 'sort',
  2350. 'is_url',
  2351. 'web_url',
  2352. 'category_arr_id as cat_arr_id',
  2353. )
  2354. ->orderBy('sort')
  2355. ->get();
  2356. $category = $this->processArticle($categorys, $data);
  2357. $result = [
  2358. 'category' => $category,
  2359. 'books' => $book,
  2360. ];
  2361. return Result::success($result);
  2362. }
  2363. /**
  2364. * 尝试
  2365. * @param array $data
  2366. * @return array
  2367. * */
  2368. public function test(array $data): array
  2369. {
  2370. $input['id'] = $data['id'];
  2371. $input['website_id'] = $data['website_id'];
  2372. // 将 JSON 字符串转换为 PHP 数组
  2373. $data = json_decode($input['id'], true);
  2374. $result = [];
  2375. $article = $data;
  2376. $result = array_map(function ($item) use ($input) {
  2377. $website = [
  2378. 'website_id' => $input['website_id'],
  2379. ];
  2380. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2381. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2382. $parent = [
  2383. 0 => $category['category_id'] ?? [],
  2384. 1 => $parentImgNum ?? [],
  2385. 2 => $parentTextNum ?? [],
  2386. ];
  2387. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2388. $child = [];
  2389. $resultItem = [
  2390. // 'alias' => $parent_alias ?? '',
  2391. 'category_id' => $parentCatId ?? 0,
  2392. 'pinyin' => $parentImgNum ?? null,
  2393. 'imgnum' => $parentTextNum ?? [],
  2394. // 'textnum' => $textArticles ?? [],
  2395. ];
  2396. return $parent;
  2397. }, $data);
  2398. return Result::success($result);
  2399. // });
  2400. }
  2401. /**
  2402. * 封装处理文章的路由问题
  2403. * */
  2404. function processArticle($article, $data)
  2405. {
  2406. return $article->map(function ($article) use ($data) {
  2407. $catid = $article->cat_arr_id ?? '';
  2408. $level = json_decode($catid, true);
  2409. $pinyin = '';
  2410. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2411. if (!empty($level) && is_array($level)) {
  2412. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2413. ->where('website_id', $data['website_id'])
  2414. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2415. ->get(['aLIas_pinyin'])
  2416. ->pluck('aLIas_pinyin')
  2417. ->implode('/');
  2418. } else {
  2419. $pinyin = '';
  2420. }
  2421. $article->pinyin = $pinyin;
  2422. return $article;
  2423. });
  2424. }
  2425. /**
  2426. * c端-获取招工招聘下拉选框
  2427. * @param array $data
  2428. * @return array
  2429. * */
  2430. public function getWebsiteJobSelect(array $data): array
  2431. {
  2432. $web = Website::where('id', $data['website_id'])->first();
  2433. if (empty($web)) {
  2434. return Result::error("该网站不存在", 0);
  2435. }
  2436. $hy = JobIndustry::get()->all();
  2437. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2438. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2439. $result = [
  2440. 'hy' => $hy,
  2441. 'zw' => $zw,
  2442. 'jtzw' => $jtzw,
  2443. ];
  2444. if (empty($result)) {
  2445. return Result::error("查询失败", 0);
  2446. }
  2447. return Result::success($result);
  2448. }
  2449. /**
  2450. * c端-获取招工招聘
  2451. * @param array $data
  2452. * @return array
  2453. * */
  2454. public function getWebsiteJob(array $data): array
  2455. {
  2456. $web = Website::where('id', $data['website_id'])->first();
  2457. if (empty($web)) {
  2458. return Result::error("该网站不存在", 0);
  2459. }
  2460. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2461. ->where('job_hunting.website_id', $data['website_id'])
  2462. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2463. $query->where(function ($q) use ($data) {
  2464. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2465. });
  2466. })
  2467. ->select(
  2468. 'job_hunting.id',
  2469. 'job_hunting.cat_arr_id',
  2470. 'job_hunting.job_name_get',
  2471. 'job_hunting.industry',
  2472. 'job_hunting.name',
  2473. 'job_hunting.sexy',
  2474. 'job_hunting.origin',
  2475. 'job_hunting.city_arr_id',
  2476. 'job_hunting.experience',
  2477. 'job_hunting.updated_at',
  2478. 'job_hunting.salary'
  2479. )
  2480. ->orderBy('updated_at', 'desc')
  2481. ->limit($data['job1_num'])
  2482. ->get();
  2483. $web['website_id'] = $data['website_id'];
  2484. if (empty($job_hunting)) {
  2485. $job_huntings = "未查询到相关简历信息";
  2486. } else {
  2487. $job_huntings = $this->processJob($job_hunting, $web);
  2488. }
  2489. // 0:待审核 1:已通过 2:已拒绝
  2490. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2491. ->where('job_recruiting.website_id', $data['website_id'])
  2492. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2493. $query->where(function ($q) use ($data) {
  2494. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2495. });
  2496. })
  2497. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2498. ->select(
  2499. 'job_recruiting.id',
  2500. 'job_recruiting.cat_arr_id',
  2501. 'job_recruiting.title',
  2502. 'job_recruiting.jtzw_id',
  2503. 'job_recruiting.hy_id',
  2504. 'job_recruiting.city_arr_id',
  2505. 'job_recruiting.due_data',
  2506. 'job_recruiting.updated_at',
  2507. 'job_recruiting.experience',
  2508. 'job_recruiting.educational',
  2509. 'job_recruiting.salary',
  2510. 'job_recruiting.zw_id',
  2511. 'job_company.business_name'
  2512. )
  2513. ->orderBy('updated_at', 'desc')
  2514. ->limit($data['job2_num'])
  2515. ->get();
  2516. if (empty($job_recruiting->toArray())) {
  2517. $job_recruitings = "未查询到相关职位信息";
  2518. } else {
  2519. $job_recruitings = $this->processJob($job_recruiting, $web);
  2520. }
  2521. $result = [
  2522. 'job_hunting' => $job_huntings,
  2523. 'job_recuiting' => $job_recruitings,
  2524. ];
  2525. return Result::success($result);
  2526. }
  2527. /**
  2528. * c端-获取招工招聘列表
  2529. * @param array $data
  2530. * @return array
  2531. * */
  2532. public function getWebsiteJobList(array $data): array
  2533. {
  2534. $recruit_where = [];
  2535. $hunt_where = [];
  2536. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2537. if (empty($web)) {
  2538. return Result::error("此网站不存在", 0);
  2539. }
  2540. $website_id['website_id'] = $data['website_id'];
  2541. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2542. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2543. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2544. }
  2545. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2546. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2547. }
  2548. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2549. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2550. }
  2551. if(isset($data['keyword']) && !empty($data['keyword'])){
  2552. array_push($recruit_where, ['title','like','%'.$data['keyword'].'%']);
  2553. }
  2554. $query = JobRecruiting::where('job_recruiting.status', 1)
  2555. ->where('job_recruiting.website_id', $data['website_id'])
  2556. ->where($recruit_where)
  2557. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2558. $query->where(function ($q) use ($data) {
  2559. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2560. });
  2561. })
  2562. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2563. $query->where(function ($q) use ($data) {
  2564. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2565. });
  2566. })
  2567. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2568. ->select(
  2569. 'job_recruiting.id',
  2570. 'job_recruiting.hy_id',
  2571. 'job_recruiting.title',
  2572. 'job_recruiting.zw_id',
  2573. 'job_recruiting.educational',
  2574. 'job_recruiting.jtzw_id',
  2575. 'job_recruiting.city_arr_id',
  2576. 'job_recruiting.due_data',
  2577. 'job_recruiting.experience',
  2578. 'job_recruiting.cat_arr_id',
  2579. 'job_recruiting.updated_at',
  2580. 'job_company.business_name'
  2581. )
  2582. ->orderBy('updated_at', 'desc');
  2583. $recruit_count = $query->count();
  2584. $query = clone $query;
  2585. $JobRecruiting = $query
  2586. ->offset(($data['page'] - 1) * $data['pageSize'])
  2587. ->limit($data['pageSize'])
  2588. ->get();
  2589. if (empty($JobRecruiting)) {
  2590. $JobRecruiting = "暂无相关职位信息";
  2591. } else {
  2592. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2593. }
  2594. }
  2595. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2596. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2597. array_push($hunt_where, ['job', $data['zw_id']]);
  2598. }
  2599. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2600. array_push($hunt_where, ['job_name_get', $data['jtzw_id']]);
  2601. }
  2602. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2603. array_push($hunt_where, ['industry', $data['hy_id']]);
  2604. }
  2605. $query = JobHunting::where('status', 2)
  2606. ->where('job_hunting.website_id', $data['website_id'])
  2607. ->where($hunt_where)
  2608. ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  2609. $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  2610. })
  2611. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2612. $query->where(function ($q) use ($data) {
  2613. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2614. });
  2615. })
  2616. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  2617. $query->where(function ($q) use ($data) {
  2618. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  2619. });
  2620. })
  2621. ->select('id', 'sexy', 'experience', 'origin', 'industry', 'name', 'job', 'job_name_get', 'city_arr_id', 'cat_arr_id', 'created_at', 'updated_at')
  2622. ->orderBy('updated_at', 'desc');
  2623. $hunt_count = $query->count();
  2624. $query = clone $query;
  2625. $JobHunting = $query
  2626. ->offset(($data['page'] - 1) * $data['pageSize'])
  2627. ->limit($data['pageSize'])
  2628. ->get();
  2629. if (empty($JobHunting)) {
  2630. $JobRecruiting = "暂无相关简历信息";
  2631. } else {
  2632. $JobHunting = $this->processJob($JobHunting, $website_id);
  2633. }
  2634. }
  2635. $result = [
  2636. 'JobRecruiting' => $JobRecruiting ?? [],
  2637. 'recruit_count' => $recruit_count ?? 0,
  2638. 'JobHunting' => $JobHunting ?? [],
  2639. 'hunt_count' => $hunt_count ?? 0,
  2640. ];
  2641. return Result::success($result);
  2642. }
  2643. /**
  2644. * c端-获取招工招聘详情
  2645. * @param array $data
  2646. * @return array
  2647. * */
  2648. public function getWebsiteJobInfo(array $data): array
  2649. {
  2650. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2651. if (empty($web)) {
  2652. return Result::error("该网站不存在", 0);
  2653. }
  2654. $webid = [
  2655. 'website_id' => $data['website_id'],
  2656. ];
  2657. // 职位相关信息
  2658. if ($data['type'] == 1) {
  2659. $query = JobRecruiting::where('status', 1)
  2660. ->where('website_id', $data['website_id'])
  2661. ->select('*');
  2662. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2663. $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();
  2664. if (!empty($company)) {
  2665. $result['company'] = $this->processJob($company, $webid);
  2666. }
  2667. $other_job = JobRecruiting::where('status', 1)
  2668. ->where('website_id', $data['website_id'])
  2669. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2670. ->where('id', '!=', $data['id'])
  2671. ->where('user_id', '=', $job[0]['user_id'])
  2672. ->limit($data['pageSize'])
  2673. ->get();
  2674. if (!empty($other_job)) {
  2675. $result['other_job'] = $this->processJob($other_job, $webid);
  2676. }
  2677. } else {
  2678. // 简历相关信息
  2679. $job = JobHunting::where('job_hunting.status', 2)
  2680. ->where('job_hunting.website_id', $data['website_id'])
  2681. ->where('job_hunting.id', $data['id'])
  2682. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2683. ->select('job_hunting.*', 'user_name')
  2684. ->get();
  2685. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  2686. if (!empty($resume->toArray())) {
  2687. $result['resume'] = 1;
  2688. } else {
  2689. $result['resume'] = 0;
  2690. }
  2691. }
  2692. if (empty($job->toArray())) {
  2693. return Result::error("id参数错误", 0);
  2694. }
  2695. if (!empty($job[0]['job_experience'])) {
  2696. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  2697. if (!empty($job_experience)) {
  2698. // $hy = [];
  2699. foreach ($job_experience as $key => $value) {
  2700. // $id = $value['id'];
  2701. $hy[$key] = $value['job_industry'];
  2702. $zw_id[$key] = $value['job_typename'];
  2703. $jtzw_id[$key] = $value['job_name'];
  2704. }
  2705. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  2706. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  2707. // 先将关联表转换为索引数组,提高查找效率
  2708. $hyLookup = [];
  2709. foreach ($hy_table as $item) {
  2710. $hyLookup[$item['hyid']] = $item['hyname'];
  2711. }
  2712. $zwLookup = [];
  2713. foreach ($zw_table as $item) {
  2714. $zwLookup[$item['zwid']] = $item['zwname'];
  2715. }
  2716. foreach ($job_experience as $key => &$value) {
  2717. // 处理行业名称
  2718. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  2719. $value['hy_name'] = $hyLookup[$hy[$key]];
  2720. }
  2721. // 处理职位名称
  2722. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  2723. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  2724. }
  2725. // 处理具体职位名称
  2726. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  2727. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  2728. }
  2729. }
  2730. // 释放引用,防止意外修改后续代码
  2731. unset($value);
  2732. }
  2733. $result['job_experience'] = $job_experience ?? [];
  2734. }
  2735. if (!empty($job[0]['education_experience'])) {
  2736. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  2737. if (!empty($education_experience)) {
  2738. foreach ($education_experience as $key => $value) {
  2739. // $id = $value['id'];
  2740. $education[$key] = $value['school_education'];
  2741. }
  2742. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  2743. // // 先将关联表转换为索引数组,提高查找效率
  2744. $educationLookup = [];
  2745. foreach ($education_table as $item) {
  2746. $educationLookup[$item['evalue']] = $item['ename'];
  2747. }
  2748. foreach ($education_experience as $key => &$value) {
  2749. // 处理学历名称
  2750. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  2751. $value['education_name'] = $educationLookup[$education[$key]];
  2752. }
  2753. }
  2754. }
  2755. $result['education_experience'] = $job_experience ?? [];
  2756. }
  2757. $result['job'] = $this->processJob($job, $webid);
  2758. // // 返现对应的栏目
  2759. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  2760. $category = WebsiteCategory::where('website_id', $data['website_id'])
  2761. ->whereIn('category_id', $catid)
  2762. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  2763. ->orderBy('pid')->get()->all();
  2764. if (!empty($category)) {
  2765. $result['category'] = $category;
  2766. }
  2767. $result['job'] = $job;
  2768. $result['job_experience'] = $job_experience ?? [];
  2769. $result['education_experience'] = $education_experience ?? [];
  2770. if (empty($result)) {
  2771. return Result::error("参数错误", 0);
  2772. }
  2773. return Result::success($result);
  2774. }
  2775. /**
  2776. * c端-申请职位
  2777. * @param array $data
  2778. * @return array
  2779. * */
  2780. public function getWebsiteJobApply(array $data): array
  2781. {
  2782. // 首先验证网站是否存在
  2783. // return Result::success($data);
  2784. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2785. if (empty($web)) {
  2786. return Result::error("该网站不存在", 0);
  2787. }
  2788. // 验证用户是否存在且为个人会员/管理员
  2789. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2790. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2791. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  2792. return Result::error("用户不存在", 0);
  2793. }
  2794. // 去除重复元素和空元素,并保持原始顺序
  2795. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  2796. return !empty($value);
  2797. }));
  2798. // 验证职位是否存在 1:审核通过
  2799. $recruiting = JobRecruiting::where('status', 1)
  2800. ->where('website_id', $data['website_id'])
  2801. ->whereIn('id', $data['recruit_id'])
  2802. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  2803. if (empty($recruiting)) {
  2804. return Result::error("该职位不存在", 0);
  2805. }
  2806. // 简历是否存在
  2807. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  2808. if (empty($hunt_id)) {
  2809. return Result::error("该简历不存在", 0);
  2810. }
  2811. $data['hunt_id'] = $hunt_id['hunt_id'];
  2812. // // 验证是否已投递过该职位
  2813. $apply = JobApply::where('user_id', $data['user_id'])
  2814. ->where('hunt_id', $data['hunt_id'])
  2815. ->where('website_id', $data['website_id'])
  2816. ->whereIn('recruit_id', $data['recruit_id'])
  2817. ->get(['recruit_id']);
  2818. if (!empty($apply->toArray())) {
  2819. return Result::error("您已投递过该职位!");
  2820. }
  2821. $insertData = array_map(function ($recruiting) use ($data) {
  2822. return [
  2823. 'user_id' => $data['user_id'],
  2824. 'hunt_id' => $data['hunt_id'],
  2825. 'website_id' => $data['website_id'],
  2826. 'recruit_id' => $recruiting['recruit_id'],
  2827. 'receiver_id' => $recruiting['receiver_id'],
  2828. 'status' => 1,
  2829. ];
  2830. }, $recruiting);
  2831. // 批量插入数据
  2832. $result = JobApply::insert($insertData);
  2833. if (empty($result)) {
  2834. return Result::error("投递失败", 0);
  2835. }
  2836. return Result::success($result);
  2837. }
  2838. /**
  2839. * 招工招聘-沟通简历
  2840. * @param array $data
  2841. * @return array
  2842. * */
  2843. public function getWebsiteJobResume(array $data): array
  2844. {
  2845. // 首先验证网站是否存在
  2846. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2847. if (empty($web)) {
  2848. return Result::error("该网站不存在", 0);
  2849. }
  2850. // return Result::success($data);
  2851. // 验证用户是否存在且为企业会员/管理员
  2852. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2853. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2854. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2855. return Result::error("用户不存在", 0);
  2856. }
  2857. // 去除重复元素和空元素,并保持原始顺序
  2858. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  2859. return !empty($value);
  2860. }));
  2861. // 验证简历是否存在
  2862. $hunting = JobHunting::where('status', 2)
  2863. ->where('website_id', $data['website_id'])
  2864. ->whereIn('id', $data['hunt_id'])
  2865. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  2866. if (empty($hunting)) {
  2867. return Result::error("该简历不存在", 0);
  2868. }
  2869. // 验证是否已沟通过该简历
  2870. $remuse = JobRemuse::where('user_id', $data['user_id'])
  2871. ->where('recruit_id', $data['recruit_id'])
  2872. ->where('website_id', $data['website_id'])
  2873. ->whereIn('hunt_id', $data['hunt_id'])
  2874. ->get(['hunt_id']);
  2875. if (!empty($remuse->toArray())) {
  2876. return Result::error("您已沟通过该简历!");
  2877. }
  2878. // 准备要插入的数据数组
  2879. $insertData = array_map(function ($hunting) use ($data) {
  2880. return [
  2881. 'user_id' => $data['user_id'],
  2882. 'recruit_id' => $data['recruit_id'],
  2883. 'website_id' => $data['website_id'],
  2884. 'hunt_id' => $hunting['hunt_id'],
  2885. 'receiver_id' => $hunting['receiver_id'],
  2886. 'status' => 1,
  2887. ];
  2888. }, $hunting);
  2889. // 批量插入数据
  2890. $result = JobRemuse::insert($insertData);
  2891. if (empty($result)) {
  2892. return Result::error("沟通失败", 0);
  2893. }
  2894. return Result::success($result);
  2895. }
  2896. /**
  2897. * 招工招聘 -我的职位(企业会员)
  2898. * @param array $data
  2899. * @return array
  2900. */
  2901. public function getWebsiteJobRecruiting(array $data): array
  2902. {
  2903. $web = Website::where('id', $data['website_id'])->first('id');
  2904. if (empty($web)) {
  2905. return Result::error("该网站不存在", 0);
  2906. }
  2907. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2908. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2909. return Result::error("用户暂无权限!", 0);
  2910. }
  2911. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  2912. $result = JobRecruiting::where('website_id', $data['website_id'])
  2913. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  2914. $query->where('user_id', $user['id']);
  2915. })
  2916. ->where('status', 1)
  2917. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  2918. ->orderBy('updated_at', 'desc')
  2919. ->limit($data['pageSize'])
  2920. ->get();
  2921. if (empty($result)) {
  2922. return Result::error("暂无相关职位信息", 0);
  2923. }
  2924. return Result::success($result);
  2925. }
  2926. /**
  2927. * c端 - 验证路由
  2928. * @param array $data
  2929. * @return array
  2930. */
  2931. /**
  2932. * c端 - 验证路由
  2933. * @param array $data
  2934. * @return array
  2935. */
  2936. public function checkWebsiteRoute(array $data): array
  2937. {
  2938. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2939. if (empty($web)) {
  2940. return Result::error("该网站不存在", 0);
  2941. }
  2942. if (isset($data['other_route']) && !empty($data['other_route'])) {
  2943. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  2944. if (empty($whiteRouterInfo)) {
  2945. return Result::error("非法路径地址", 0);
  2946. } else {
  2947. return Result::success($whiteRouterInfo->toArray());
  2948. }
  2949. } else {
  2950. // 验证栏目路由
  2951. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  2952. ->where('aLIas_pinyin', $data['last_route'])
  2953. ->first();
  2954. if (empty($last_category)) {
  2955. return Result::error("该栏目不存在", 0);
  2956. }
  2957. if (isset($data['id']) && !empty($data['id'])) {
  2958. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  2959. switch ($last_category['type']) {
  2960. case 1:
  2961. // 文章
  2962. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  2963. $article = Article::where('status', 1)
  2964. ->where('id', $data['id'])
  2965. ->where(function ($query) use ($data) {
  2966. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  2967. ->orWhereNull("ignore_ids");
  2968. })
  2969. ->first(['cat_arr_id']);
  2970. if (empty($article)) {
  2971. return Result::error("该文章不存在", 0);
  2972. }
  2973. // return Result::success($article);
  2974. break;
  2975. case 2:
  2976. // 商品
  2977. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  2978. $article = Good::where('website_id', $data['website_id'])
  2979. ->where('status', 2)
  2980. ->where('id', $data['id'])
  2981. ->first(['cat_arr_id']);
  2982. if (empty($article)) {
  2983. return Result::error("该商品不存在", 0);
  2984. }
  2985. break;
  2986. case 3:
  2987. // 书刊信息
  2988. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  2989. $article = Book::where('website_id', $data['website_id'])
  2990. ->where('status', 2)
  2991. ->where('id', $data['id'])
  2992. ->first(['id', 'cat_arr_id']);
  2993. if (empty($article)) {
  2994. return Result::error("该书刊不存在", 0);
  2995. }
  2996. break;
  2997. case 4:
  2998. // 招聘
  2999. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核;(只有企业会员需要审核)',
  3000. $article = JobRecruiting::where('website_id', $data['website_id'])
  3001. ->where('status', 1)
  3002. ->where('id', $data['id'])
  3003. ->first(['cat_arr_id']);
  3004. if (empty($article)) {
  3005. return Result::error("该招聘不存在", 0);
  3006. }
  3007. break;
  3008. case 5:
  3009. // 求职
  3010. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3011. $article = JobHunting::where('website_id', $data['website_id'])
  3012. ->where('status', 2)
  3013. ->where('id', $data['id'])
  3014. ->first(['cat_arr_id']);
  3015. if (empty($article)) {
  3016. return Result::error("该求职不存在", 0);
  3017. }
  3018. break;
  3019. case 6:
  3020. // 招工招聘
  3021. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3022. $article = JobRecruiting::where('website_id', $data['website_id'])
  3023. ->where('status', 1)
  3024. ->where('id', $data['id'])
  3025. ->first(['cat_arr_id']);
  3026. if (empty($article)) {
  3027. $article = JobHunting::where('website_id', $data['website_id'])
  3028. ->where('status', 2)
  3029. ->where('id', $data['id'])
  3030. ->first(['cat_arr_id']);
  3031. }
  3032. if (empty($article)) {
  3033. return Result::error("该招工招聘不存在", 0);
  3034. }
  3035. break;
  3036. default:
  3037. return Result::error("该数据不存在", 0);
  3038. break;
  3039. }
  3040. $catid = json_decode($article['cat_arr_id'], true);
  3041. if (empty($catid)) {
  3042. return Result::error("该数据不存在", 0);
  3043. }
  3044. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3045. ->orderByRaw('FIELD(category_id, ' . implode(',', $catid) . ')')
  3046. ->whereIn('category_id', $catid)
  3047. ->pluck('aLIas_pinyin')
  3048. ->implode('/');
  3049. }
  3050. if ($last_category['pid'] != 0) {
  3051. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3052. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3053. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr) . ')')
  3054. ->whereIn('category_id', $cat_arr)
  3055. ->pluck('aLIas_pinyin')
  3056. ->implode('/');
  3057. } else {
  3058. $pinyin = $last_category['aLIas_pinyin'];
  3059. }
  3060. if (empty($pinyin) || $pinyin != $data['all_route']) {
  3061. return Result::error('非法路径!');
  3062. } else {
  3063. return Result::success($pinyin);
  3064. }
  3065. }
  3066. }
  3067. /**
  3068. * 招工招聘 - 获取推荐职位
  3069. * @param array $data
  3070. * @return array
  3071. */
  3072. public function getWebsiteLevelJob(array $data): array
  3073. {
  3074. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3075. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3076. ->where('job_recruiting.status', 1)
  3077. ->where('job_level', $data['job_level'])
  3078. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3079. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3080. ->orderBy('job_recruiting.updated_at', 'desc')
  3081. ->limit($data['pageSize'])
  3082. ->get();
  3083. $web = ['website_id' => $data['website_id']];
  3084. if (!empty($job)) {
  3085. $result = $this->processJob($job, $web);
  3086. }
  3087. if (empty($result)) {
  3088. return Result::error("暂无相关职位信息", 0);
  3089. }
  3090. return Result::success($result);
  3091. }
  3092. /**
  3093. * 验证导航名称是否重复
  3094. * @return void
  3095. */
  3096. //20250226 产品列表
  3097. public function getGoodList(array $data): array
  3098. {
  3099. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3100. unset($data['type_id']);
  3101. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3102. $where = [];
  3103. if ($type_id != '10000') {
  3104. $where = [
  3105. 'good.user_id' => $user_id,
  3106. ];
  3107. }
  3108. //类型
  3109. if (isset($data['type_id']) && $data['type_id']) {
  3110. $where = [
  3111. 'type_id' => $data['type_id'],
  3112. ];
  3113. }
  3114. //名称
  3115. if (isset($data['name']) && $data['name']) {
  3116. $where = [
  3117. 'good.name' => $data['name'],
  3118. ];
  3119. }
  3120. //status
  3121. if (isset($data['status']) && $data['status'] != '') {
  3122. $where = [
  3123. 'good.status' => $data['status'],
  3124. ];
  3125. }
  3126. //status1
  3127. // if (isset($data['status1']) && $data['status1'] == 1) {
  3128. // $status1 = 1;
  3129. // }
  3130. $where1 = [];
  3131. //website_id
  3132. // if (isset($data['website_id']) && $data['website_id']) {
  3133. // $where1 = [
  3134. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3135. // ];
  3136. // }
  3137. // website_name
  3138. if (isset($data['website_name']) && $data['website_name']) {
  3139. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3140. }
  3141. // catid
  3142. if (isset($data['category_name']) && $data['category_name']) {
  3143. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3144. }
  3145. // $result = Good::where($where)
  3146. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3147. $result = Good::where($where)
  3148. ->when(!empty($where1), function ($query) use ($where1) {
  3149. return $query->where($where1);
  3150. })
  3151. //status 1待审核2已审核3已拒绝
  3152. ->when(isset($data['status1']), function ($query) {
  3153. return $query->whereIn('good.status', [1, 3]);
  3154. })
  3155. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3156. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3157. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3158. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3159. ->orderBy("updated_at", "desc")
  3160. ->limit($data['page_size'])
  3161. ->offset(($data['page'] - 1) * $data['page_size'])
  3162. ->get();
  3163. $count = Good::where($where)
  3164. ->when(!empty($where1), function ($query) use ($where1) {
  3165. return $query->where($where1);
  3166. })
  3167. //status 1待审核2已审核3已拒绝
  3168. ->when(isset($data['status1']), function ($query) {
  3169. return $query->whereIn('good.status', [1, 3]);
  3170. })
  3171. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3172. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3173. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3174. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3175. ->orderBy("updated_at", "desc")->count();
  3176. $data = [
  3177. 'rows' => $result->toArray(),
  3178. 'count' => $count,
  3179. ];
  3180. if (empty($result)) {
  3181. return Result::error("此栏目暂无相关产品", 0);
  3182. }
  3183. return Result::success($data);
  3184. }
  3185. public function getGoodInfo(array $data): array
  3186. {
  3187. $result = Good::where('id', $data['id'])->first();
  3188. if (empty($result)) {
  3189. return Result::error("此产品不存在", 0);
  3190. }
  3191. return Result::success($result);
  3192. }
  3193. public function addGood(array $data): array
  3194. {
  3195. // unset($data['city_arr_id']);
  3196. // unset($data['cat_arr_id']);
  3197. $data['city_id'] = end($data['city_arr_id']);
  3198. $data['catid'] = end($data['cat_arr_id']);
  3199. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3200. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3201. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3202. unset($data['imgUrl']); //大小写
  3203. if (isset($data['price']) && $data['price'] == '') {
  3204. $data['price'] = 0;
  3205. }
  3206. if ($data['imgurl'] == '') {
  3207. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3208. preg_match_all($reg, $data['detail'], $matches);
  3209. if (isset($matches[1][0])) {
  3210. //截取varchar240
  3211. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3212. }
  3213. }
  3214. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3215. //提取标题+内容中的关键词
  3216. $data['keyword'] = $data['name'];
  3217. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3218. Jieba::init(); // 初始化 jieba-php
  3219. Finalseg::init();
  3220. $segList = Jieba::cut($data['keyword']);
  3221. $segList1 = array_slice($segList, 0, 8);
  3222. $data['keyword'] = implode(',', $segList1);
  3223. }
  3224. if ($data['description'] == '') {
  3225. //提取内容中的描述
  3226. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3227. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3228. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3229. }
  3230. $result = Good::insert($data);
  3231. if (empty($result)) {
  3232. return Result::error("添加失败", 0);
  3233. }
  3234. return Result::success($result);
  3235. }
  3236. public function updateGood(array $data): array
  3237. {
  3238. $data['city_id'] = end($data['city_arr_id']);
  3239. $data['catid'] = end($data['cat_arr_id']);
  3240. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3241. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3242. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3243. //设置东八区
  3244. date_default_timezone_set('Asia/Shanghai');
  3245. $data['updated_at'] = date('Y-m-d H:i:s');
  3246. if (isset($data['price']) && $data['price'] == '') {
  3247. $data['price'] = 0;
  3248. }
  3249. if ($data['imgurl'] == '') {
  3250. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3251. preg_match_all($reg, $data['detail'], $matches);
  3252. if (isset($matches[1][0])) {
  3253. //截取varchar240
  3254. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3255. }
  3256. }
  3257. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3258. //提取标题+内容中的关键词
  3259. $data['keyword'] = $data['name'];
  3260. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3261. Jieba::init(); // 初始化 jieba-php
  3262. Finalseg::init();
  3263. $segList = Jieba::cut($data['keyword']);
  3264. $segList1 = array_slice($segList, 0, 8);
  3265. $data['keyword'] = implode(',', $segList1);
  3266. }
  3267. if ($data['description'] == '') {
  3268. //提取内容中的描述
  3269. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3270. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3271. }
  3272. $result = Good::where('id', $data['id'])->update($data);
  3273. if (empty($result)) {
  3274. return Result::error("更新失败", 0);
  3275. }
  3276. return Result::success($result);
  3277. }
  3278. public function delGood(array $data): array
  3279. {
  3280. $result = Good::where('id', $data['id'])->delete();
  3281. if (empty($result)) {
  3282. return Result::error("删除失败", 0);
  3283. }
  3284. return Result::success($result);
  3285. }
  3286. //20250226 产品列表
  3287. //20250306 求职信息
  3288. public function getJobHuntingList(array $data): array
  3289. {
  3290. $where = [];
  3291. if (isset($data['username']) && !empty($data['username'])) {
  3292. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3293. }
  3294. //status 1待审核2已审核3已拒绝
  3295. if (isset($data['status']) && $data['status'] != '') {
  3296. $where = [
  3297. 'job_hunting.status' => $data['status'],
  3298. ];
  3299. }
  3300. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3301. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3302. unset($data['type_id']);
  3303. if ($type_id != '10000') {
  3304. $where[] = ['job_hunting.user_id', '=', $user_id];
  3305. }
  3306. $result = JobHunting::where($where)
  3307. ->when(!empty($data['status1']), function ($query) use ($data) {
  3308. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3309. })
  3310. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3311. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3312. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3313. ->orderBy("updated_at", "desc")
  3314. ->limit($data['page_size'])
  3315. ->offset(($data['page'] - 1) * $data['page_size'])
  3316. ->get();
  3317. if (empty($result)) {
  3318. return Result::error("查询失败", 0);
  3319. }
  3320. $count = JobHunting::where($where)
  3321. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3322. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3323. ->count();
  3324. $data = [
  3325. 'rows' => $result->toArray(),
  3326. 'count' => $count,
  3327. ];
  3328. return Result::success($data);
  3329. }
  3330. public function getJobHuntingApply(array $data): array
  3331. {
  3332. var_dump($data, '-----------------test--------1-');
  3333. $where = [];
  3334. if (isset($data['username']) && !empty($data['username'])) {
  3335. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3336. }
  3337. if (isset($data['salary']) && !empty($data['salary'])) {
  3338. $where[] = [
  3339. 'job_hunting.salary',
  3340. '=',
  3341. $data['salary'],
  3342. ];
  3343. }
  3344. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3345. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3346. unset($data['type_id']);
  3347. if ($type_id != '10000') {
  3348. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3349. }
  3350. var_dump($where, '-----------------test---------');
  3351. $result = jobApply::where($where)
  3352. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3353. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3354. // })
  3355. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3356. ->where('job_enum.egroup', '=', 'income')
  3357. ->where('job_hunting.status', 2) //已审核
  3358. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3359. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3360. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3361. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3362. //职位----是申请职位
  3363. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3364. ->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')
  3365. ->orderBy("job_hunting.updated_at", "desc")
  3366. ->limit($data['page_size'])
  3367. ->offset(($data['page'] - 1) * $data['page_size'])
  3368. ->get();
  3369. if (empty($result)) {
  3370. return Result::error("查询失败", 0);
  3371. }
  3372. $count = jobApply::where($where)
  3373. ->where('job_enum.egroup', '=', 'income')
  3374. ->where('job_hunting.status', 2) //已审核
  3375. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3376. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3377. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3378. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3379. //职位----是申请职位
  3380. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3381. ->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')
  3382. ->count();
  3383. $data = [
  3384. 'rows' => $result->toArray(),
  3385. 'count' => $count,
  3386. ];
  3387. return Result::success($data);
  3388. }
  3389. public function addJobHunting(array $data): array
  3390. {
  3391. date_default_timezone_set('Asia/Shanghai');
  3392. unset($data['company_name']);
  3393. unset($data['job_industry']);
  3394. unset($data['job_name']);
  3395. unset($data['department']);
  3396. unset($data['job_timeList']);
  3397. unset($data['job_content']);
  3398. unset($data['job_typename']); //不知道这是啥,
  3399. $data['created_at'] = date('Y-m-d H:i:s');
  3400. $data['updated_at'] = date('Y-m-d H:i:s');
  3401. //根据用户 user_id 只能添加一次
  3402. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3403. if (!empty($result)) {
  3404. return Result::error("您已添加过求职信息", 0);
  3405. }
  3406. var_dump($result, '-----------------test---------');
  3407. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3408. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3409. $cityArr = json_decode($data['city_arr_id'], true);
  3410. $data['city_id'] = end($cityArr);
  3411. } else {
  3412. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3413. $data['city_id'] = end($data['city_arr_id']);
  3414. }
  3415. $result = JobHunting::create($data);
  3416. if (empty($result)) {
  3417. return Result::error("添加失败", 0);
  3418. }
  3419. return Result::success($result);
  3420. }
  3421. public function delJobHunting(array $data): array
  3422. {
  3423. $result = JobHunting::where('id', $data['id'])->delete();
  3424. if (empty($result)) {
  3425. return Result::error("删除失败", 0);
  3426. }
  3427. return Result::success($result);
  3428. }
  3429. public function updateJobHunting(array $data): array
  3430. {
  3431. //设置东八区
  3432. date_default_timezone_set('Asia/Shanghai');
  3433. unset($data['company_name']);
  3434. unset($data['job_industry']);
  3435. unset($data['job_name']);
  3436. unset($data['department']);
  3437. unset($data['job_timeList']);
  3438. unset($data['job_content']);
  3439. unset($data['job_typename']); //不知道这是啥,
  3440. $data['created_at'] = date('Y-m-d H:i:s');
  3441. $data['updated_at'] = date('Y-m-d H:i:s');
  3442. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3443. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3444. $cityArr = json_decode($data['city_arr_id'], true);
  3445. $data['city_id'] = end($cityArr);
  3446. } else {
  3447. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3448. $data['city_id'] = end($data['city_arr_id']);
  3449. }
  3450. $result = JobHunting::where('id', $data['id'])->update($data);
  3451. if (empty($result)) {
  3452. return Result::error("更新失败", 0);
  3453. }
  3454. return Result::success($result);
  3455. }
  3456. public function getJobHuntingInfo(array $data): array
  3457. {
  3458. $result = JobHunting::where('id', $data['id'])->first();
  3459. if (empty($result)) {
  3460. return Result::error("查询失败", 0);
  3461. }
  3462. return Result::success($result);
  3463. }
  3464. public function getJobHuntingData(array $data): array
  3465. {
  3466. $jobEnum = JobEnum::get();
  3467. $jobIndustry = JobIndustry::get();
  3468. $jobNature = JobNature::get();
  3469. $jobPosition = JobPosition::get();
  3470. $data = [
  3471. 'jobEnum' => $jobEnum,
  3472. 'jobIndustry' => $jobIndustry,
  3473. 'jobNature' => $jobNature,
  3474. 'jobPosition' => $jobPosition,
  3475. ];
  3476. return Result::success($data);
  3477. }
  3478. public function delJobHuntingInfo(array $data): array
  3479. {
  3480. $result = JobHunting::where('id', $data['id'])->delete();
  3481. return Result::success();
  3482. }
  3483. //20250324 通知,公告,消息
  3484. public function delNotice(array $data): array
  3485. {
  3486. $result = Notice::where('id', $data['id'])->delete();
  3487. if ($result) {
  3488. return Result::success();
  3489. } else {
  3490. return Result::error("删除失败", 0);
  3491. }
  3492. }
  3493. public function getNoticeInfo(array $data): array
  3494. {
  3495. $result = Notice::where('id', $data['id'])->first();
  3496. if (empty($result)) {
  3497. return Result::error("查询失败", 0);
  3498. }
  3499. return Result::success($result);
  3500. }
  3501. public function addNotice(array $data): array
  3502. {
  3503. date_default_timezone_set('Asia/Shanghai');
  3504. $data['created_at'] = date('Y-m-d H:i:s');
  3505. $data['updated_at'] = date('Y-m-d H:i:s');
  3506. $user_id = UserInfo::
  3507. //city_id不是null
  3508. whereNotNull('city_id')
  3509. ->whereNotNull('department_id')
  3510. ->where(function ($query) use ($data) {
  3511. $query->where(function ($subQuery) use ($data) {
  3512. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3513. });
  3514. })
  3515. ->where(function ($query) use ($data) {
  3516. $query->where(function ($subQuery) use ($data) {
  3517. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3518. });
  3519. })
  3520. ->pluck('user_id')->toArray();
  3521. $user_id = array_unique($user_id);
  3522. $chat_ids = $user_id;
  3523. $user_id = json_encode($user_id);
  3524. $data['re_user_ids'] = $user_id;
  3525. $result = Notice::insertGetId($data);
  3526. if ($result && $data['is_group'] == 1) {
  3527. //chat_group
  3528. $group_id = PublicData::uuid();
  3529. $groupData = [
  3530. 'id' => $group_id,
  3531. 'creator_id' => $data['user_id'],
  3532. 'group_name' => $data['group_name'] ?? '',
  3533. 'profile' => $data['profile'] ?? 0,
  3534. ];
  3535. var_dump($groupData, '-----------------groupData-------');
  3536. $groupResult = ChatGroups::insertGetId($groupData);
  3537. var_dump($groupResult, '-----------------groupid-------');
  3538. $groupMemberData = [
  3539. 'id' => PublicData::uuid(),
  3540. 'user_id' => $data['user_id'],
  3541. 'group_id' => $group_id,
  3542. 'leader' => 2,
  3543. ];
  3544. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  3545. //$chat_ids 去除掉$data['user_id']
  3546. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  3547. //插入群成员表
  3548. $groupMemberDataUser = [];
  3549. $chatData = [];
  3550. foreach ($chat_ids as $key => $value) {
  3551. $groupMemberDataUser[] = [
  3552. 'id' => PublicData::uuid(),
  3553. 'user_id' => $value,
  3554. 'group_id' => $group_id,
  3555. 'leader' => 1,
  3556. ];
  3557. $chatData[] = [
  3558. 'user_id' => $value,
  3559. 'msg_type' => 1,
  3560. 'receiver_id' => $group_id,
  3561. 'content' => '通过通知创建群聊',
  3562. 'group_receiver_id' => $data['user_id'],
  3563. 'action' => 'recieved',
  3564. 'created_at' => date('Y-m-d H:i:s'),
  3565. ];
  3566. }
  3567. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  3568. ChatGroupsMember::insert($groupMemberDataUser);
  3569. //插入一条管理员聊天记录
  3570. $chatData[] = [
  3571. 'user_id' => $data['user_id'],
  3572. 'msg_type' => 1,
  3573. 'receiver_id' => $group_id,
  3574. 'content' => '通过通知创建群聊',
  3575. 'group_receiver_id' => $data['user_id'],
  3576. 'action' => 'said',
  3577. 'created_at' => date('Y-m-d H:i:s'),
  3578. ];
  3579. var_dump($chatData, '-----------------chatData-------');
  3580. $chatResult = ChatRecords::insert($chatData);
  3581. //更新result的 group_id
  3582. $data['group_id'] = $group_id;
  3583. Notice::where(['id' => $result])->update($data);
  3584. }
  3585. if (empty($result)) {
  3586. return Result::error("添加失败", 0);
  3587. }
  3588. return Result::success($result);
  3589. }
  3590. public function updateNotice(array $data): array
  3591. {
  3592. date_default_timezone_set('Asia/Shanghai');
  3593. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  3594. $user_id = UserInfo::
  3595. //city_id不是null
  3596. whereNotNull('city_id')
  3597. ->whereNotNull('department_id')
  3598. ->where(function ($query) use ($data) {
  3599. $query->where(function ($subQuery) use ($data) {
  3600. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3601. });
  3602. })
  3603. ->where(function ($query) use ($data) {
  3604. $query->where(function ($subQuery) use ($data) {
  3605. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3606. });
  3607. })
  3608. ->pluck('user_id')->toArray();
  3609. $user_id = array_unique($user_id);
  3610. $user_id = json_encode($user_id);
  3611. $data['re_user_ids'] = $user_id;
  3612. $data['updated_at'] = date('Y-m-d H:i:s');
  3613. $result = Notice::where('id', $data['id'])->update($data);
  3614. return Result::success($result);
  3615. }
  3616. public function getNoticeList(array $data): array
  3617. {
  3618. $where = [];
  3619. //title
  3620. if (isset($data['title']) && !empty($data['title'])) {
  3621. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  3622. }
  3623. //level
  3624. if (isset($data['level']) && !empty($data['level'])) {
  3625. $where[] = ['notice.level', '=', $data['level']];
  3626. }
  3627. //status
  3628. if (isset($data['status']) && !empty($data['status'])) {
  3629. $where[] = ['notice.status', '=', $data['status']];
  3630. }
  3631. var_dump($data, '------------11111-2----test---------');
  3632. if ($data['type_id'] == 10000) {
  3633. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3634. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3635. })
  3636. ->where($where)
  3637. ->orderBy('updated_at', 'desc')
  3638. ->limit($data['page_size'])
  3639. ->offset(($data['page'] - 1) * $data['page_size'])
  3640. ->get();
  3641. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3642. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3643. })
  3644. ->where($where)
  3645. ->orderBy('updated_at', 'desc')
  3646. ->count();
  3647. } else {
  3648. $result = Notice::where($where)
  3649. // ->where('user_id', $data['user_id'])
  3650. ->Where(function ($query) use ($data) {
  3651. $query->Where(function ($q) use ($data) {
  3652. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3653. ->orWhere('notice.user_id', $data['user_id']);
  3654. });
  3655. })
  3656. ->when(!empty($data['status1']), function ($query) use ($data) {
  3657. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3658. })
  3659. ->orderBy('updated_at', 'desc')
  3660. ->limit($data['page_size'])
  3661. ->offset(($data['page'] - 1) * $data['page_size'])
  3662. ->get();
  3663. $total = Notice::where($where)
  3664. ->when(!empty($data['status1']), function ($query) use ($data) {
  3665. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3666. })
  3667. // ->where('user_id', $data['user_id'])
  3668. ->Where(function ($query) use ($data) {
  3669. $query->Where(function ($q) use ($data) {
  3670. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3671. ->orWhere('notice.user_id', $data['user_id']);
  3672. });
  3673. })
  3674. ->count();
  3675. }
  3676. if (empty($result)) {
  3677. return Result::error("查询失败", 0);
  3678. }
  3679. $data = [
  3680. 'rows' => $result,
  3681. 'count' => $total,
  3682. ];
  3683. return Result::success($data);
  3684. }
  3685. public function getNoticeDetail(array $data): array
  3686. {
  3687. $result = Notice::where('id', $data['id'])->first();
  3688. if (empty($result)) {
  3689. return Result::error("查询失败", 0);
  3690. }
  3691. return Result::success($result);
  3692. }
  3693. public function deleteNotice(array $data): array
  3694. {
  3695. $notice = Notice::where('id', $data['id'])->first();
  3696. if (empty($notice)) {
  3697. return Result::error("删除失败", 0);
  3698. }
  3699. $chat_group_id = $notice->group_id;
  3700. if ($chat_group_id) {
  3701. //删除群聊
  3702. ChatGroups::where('id', $chat_group_id)->delete();
  3703. //删除群成员
  3704. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  3705. //删除群聊记录
  3706. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  3707. }
  3708. $result = Notice::where('id', $data['id'])->delete();
  3709. return Result::success($result);
  3710. }
  3711. public function getMSG(array $data): array
  3712. {
  3713. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  3714. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3715. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  3716. $result = [];
  3717. if ($type_id == 1) {
  3718. //最近的5篇已审的文章
  3719. $apply_articale = Article::where('status', 1)
  3720. ->where('admin_user_id', $user_id)
  3721. ->orderBy('updated_at', 'desc')
  3722. ->limit(5)->get();
  3723. //获取5条单聊未读聊天消息
  3724. $chat = ChatRecords::where('is_read', 0)
  3725. ->where('user_id', $user_id)
  3726. ->where('talk_type', 1)
  3727. ->orderBy('created_at', 'desc')
  3728. ->limit(5)->get();
  3729. //获取5条未读群聊信息
  3730. $chat_group = ChatRecords::where('is_read', 0)
  3731. ->where('user_id', $user_id)
  3732. ->where('talk_type', 2)
  3733. ->orderBy('created_at', 'desc')
  3734. ->limit(5)->get();
  3735. //获取5条用户的已审核商品
  3736. $good = Good::where('status', 2)
  3737. ->where('user_id', $user_id)
  3738. ->orderBy('updated_at', 'desc')
  3739. ->limit(5)->get();
  3740. //获取5条用户待审核的公告
  3741. $notice = Notice::where('status', 2)
  3742. ->where('user_id', $user_id)
  3743. ->orderBy('updated_at', 'desc')
  3744. ->limit(5)->get();
  3745. //获取5条用户的待审核投诉
  3746. $complaint = Complaint::where('status', 2)
  3747. ->where('user_id', $user_id)
  3748. ->orderBy('updated_at', 'desc')
  3749. ->limit(5)->get();
  3750. //获取5条用户的book
  3751. $book = Book::where('status', 2)
  3752. ->where('user_id', $user_id)
  3753. ->orderBy('updated_at', 'desc')
  3754. ->limit(5)->get();
  3755. //获取5条用户的求职
  3756. //获取5条用户的求职 1
  3757. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3758. ->where('job_hunting.user_id', $user_id)
  3759. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3760. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3761. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3762. ->orderBy('updated_at', 'desc')
  3763. ->limit(5)->get();
  3764. //获取5条用户的求职 2
  3765. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3766. ->where('job_recruiting.user_id', $user_id)
  3767. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3768. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3769. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3770. ->orderBy('updated_at', 'desc')
  3771. ->limit(5)->get();
  3772. //人才库 1
  3773. $job_apply = JobApply::where('job_apply.status', 1)
  3774. ->where('job_apply.receiver_id', $user_id)
  3775. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3776. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3777. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3778. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3779. ->select('job_recruiting', 'job_recruiting.', '', '')
  3780. ->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')
  3781. ->orderBy('updated_at', 'desc')
  3782. ->limit(5)->get();
  3783. // 职场机会 2
  3784. $job_resume = JobResume::where('job_resume.status', 1)
  3785. ->where('job_resume.receiver_id', $user_id)
  3786. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3787. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3788. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3789. ->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')
  3790. ->orderBy('updated_at', 'desc')
  3791. ->limit(5)->get();
  3792. // count($chat) + count($chat_group) +
  3793. $count = count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  3794. $result = [
  3795. 'apply_articale' => $apply_articale,
  3796. 'chat' => $chat,
  3797. 'chat_group' => $chat_group,
  3798. 'good' => $good,
  3799. 'notice' => $notice,
  3800. 'complaint' => $complaint,
  3801. 'book' => $book,
  3802. 'job_hunting' => $job_hunting,
  3803. 'job_recruiting' => $job_recruiting,
  3804. 'job_apply' => $job_apply,
  3805. 'job_resume' => $job_resume,
  3806. 'count' => $count,
  3807. ];
  3808. } elseif ($type_id == 2) {
  3809. //最近的5篇已审的文章
  3810. $apply_articale = Article::where('status', 1)
  3811. ->where('admin_user_id', $user_id)
  3812. ->limit(5)->get();
  3813. //获取5条单聊未读聊天消息
  3814. $chat = ChatRecords::where('is_read', 0)
  3815. ->where('user_id', $user_id)
  3816. ->where('talk_type', 1)
  3817. ->orderBy('created_at', 'desc')
  3818. ->limit(5)->get();
  3819. //获取5条未读群聊信息
  3820. $chat_group = ChatRecords::where('is_read', 0)
  3821. ->where('user_id', $user_id)
  3822. ->where('talk_type', 2)
  3823. ->orderBy('created_at', 'desc')
  3824. ->limit(5)->get();
  3825. //获取5条用户的已审核商品
  3826. $good = Good::where('status', 2)
  3827. ->where('user_id', $user_id)
  3828. ->orderBy('updated_at', 'desc')
  3829. ->limit(5)->get();
  3830. //count($chat) + count($chat_group)
  3831. $count = count($apply_articale) + count($good);
  3832. $result = [
  3833. 'apply_articale' => $apply_articale,
  3834. 'chat' => $chat,
  3835. 'chat_group' => $chat_group,
  3836. 'good' => $good,
  3837. 'count' => $count,
  3838. ];
  3839. } elseif ($type_id == 3) {
  3840. //最近的5篇已审的文章
  3841. $apply_articale = Article::where('status', 1)
  3842. ->where('admin_user_id', $user_id)
  3843. ->limit(5)->get();
  3844. //获取5条单聊未读聊天消息
  3845. $chat = ChatRecords::where('is_read', 0)
  3846. ->where('user_id', $user_id)
  3847. ->where('talk_type', 1)
  3848. ->orderBy('created_at', 'desc')
  3849. ->limit(5)->get();
  3850. //获取5条未读群聊信息
  3851. $chat_group = ChatRecords::where('is_read', 0)
  3852. ->where('user_id', $user_id)
  3853. ->where('talk_type', 2)
  3854. ->orderBy('created_at', 'desc')
  3855. ->limit(5)->get();
  3856. //获取5条用户的已审核商品
  3857. $good = Good::where('status', 2)
  3858. ->where('user_id', $user_id)
  3859. ->orderBy('updated_at', 'desc')
  3860. ->limit(5)->get();
  3861. //count($chat) + count($chat_group) +
  3862. $count = count($apply_articale) + count($good);
  3863. $result = [
  3864. 'apply_articale' => $apply_articale,
  3865. 'chat' => $chat,
  3866. 'chat_group' => $chat_group,
  3867. 'good' => $good,
  3868. 'count' => $count,
  3869. ];
  3870. } elseif ($type_id == 4) {
  3871. //最近的5篇已审的文章
  3872. $apply_articale = Article::where('status', 1)
  3873. ->where('admin_user_id', $user_id)
  3874. ->limit(5)->get();
  3875. //获取5条用户的已审核商品
  3876. $good = Good::where('status', 2)
  3877. ->where('user_id', $user_id)
  3878. ->orderBy('updated_at', 'desc')
  3879. ->limit(5)->get();
  3880. $count = count($apply_articale) + count($good);
  3881. $result = [
  3882. 'apply_articale' => $apply_articale,
  3883. 'chat' => '',
  3884. 'chat_group' => '',
  3885. 'good' => $good,
  3886. 'count' => $count,
  3887. ];
  3888. } elseif ($type_id == 10000) {
  3889. //获取未审核的5篇文章
  3890. $apply_articale = Article::where('status', 0)
  3891. ->orderBy('updated_at', 'desc')
  3892. ->limit(5)->get();
  3893. //获取5条单聊未读聊天消息
  3894. $chat = ChatRecords::where('is_read', 0)
  3895. ->where('user_id', $user_id)
  3896. ->where('talk_type', 1)
  3897. ->orderBy('created_at', 'desc')
  3898. ->limit(5)->get();
  3899. //获取5条未读群聊信息
  3900. $chat_group = ChatRecords::where('is_read', 0)
  3901. ->where('user_id', $user_id)
  3902. ->where('talk_type', 2)
  3903. ->orderBy('created_at', 'desc')
  3904. ->limit(5)->get();
  3905. //获取5条用户的已审核商品
  3906. $good = Good::where('status', 1)
  3907. // ->where('user_id', $user_id)
  3908. ->orderBy('updated_at', 'desc')
  3909. ->limit(5)->get();
  3910. //获取5条用户待审核的公告
  3911. $notice = Notice::where('status', 1)
  3912. ->orderBy('updated_at', 'desc')
  3913. ->limit(5)->get();
  3914. //获取5条用户的待审核投诉
  3915. $complaint = Complaint::where('status', 1)
  3916. ->orderBy('updated_at', 'desc')
  3917. ->limit(5)->get();
  3918. //获取5条用户的book
  3919. $book = Book::where('status', 1)
  3920. ->orderBy('updated_at', 'desc')
  3921. ->limit(5)->get();
  3922. //获取5条用户的求职 1
  3923. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3924. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3925. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3926. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3927. ->orderBy('updated_at', 'desc')
  3928. ->limit(5)->get();
  3929. //获取5条用户的求职 2
  3930. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3931. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3932. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3933. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3934. ->orderBy('updated_at', 'desc')
  3935. ->limit(5)->get();
  3936. //人才库 1
  3937. $job_apply = JobApply::where('job_apply.status', 1)
  3938. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3939. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3940. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3941. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3942. ->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')
  3943. ->orderBy('updated_at', 'desc')
  3944. ->limit(5)->get();
  3945. // 职场机会 2
  3946. $job_resume = JobResume::where('job_resume.status', 1)
  3947. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3948. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3949. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3950. ->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')
  3951. ->orderBy('updated_at', 'desc')
  3952. ->limit(5)->get();
  3953. $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);
  3954. $result = [
  3955. 'apply_articale' => $apply_articale,
  3956. 'chat' => $chat,
  3957. 'chat_group' => $chat_group,
  3958. 'good' => $good,
  3959. 'notice' => $notice,
  3960. 'complaint' => $complaint,
  3961. 'book' => $book,
  3962. 'job_hunting' => $job_hunting,
  3963. 'job_recruiting' => $job_recruiting,
  3964. 'job_apply' => $job_apply,
  3965. 'job_resume' => $job_resume,
  3966. 'count' => $count,
  3967. ];
  3968. } elseif ($type_id == 20000) {
  3969. }
  3970. var_dump($type_id, '-----------------test---------');
  3971. return Result::success($result);
  3972. }
  3973. public function getComplaintList(array $data): array
  3974. {
  3975. var_dump($data, '00000001000000000000');
  3976. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3977. unset($data['type_id']);
  3978. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3979. $where = [];
  3980. if ($type_id != 10000 && empty($data['deal_user'])) {
  3981. $where['complaint.user_id'] = $user_id;
  3982. }
  3983. if (!empty($data['title'])) {
  3984. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  3985. }
  3986. if (!empty($data['department_id'])) {
  3987. $where['complaint.department_id'] = $data['department_id'];
  3988. }
  3989. if (!empty($data['deal'])) {
  3990. $where['complaint.deal'] = $data['deal'];
  3991. }
  3992. if (!empty($data['status'])) {
  3993. $where['complaint.status'] = $data['status'];
  3994. }
  3995. var_dump(!empty($data['deal_user']), '----------1');
  3996. var_dump($where, '----------2');
  3997. $result = Complaint::where($where)
  3998. ->when(!empty($data['status1']), function ($query) use ($data) {
  3999. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4000. })
  4001. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4002. //json re_user_ids data[user_id]是不是在里面
  4003. $query->Where(function ($q) use ($data) {
  4004. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4005. ->where('complaint.status', 2);
  4006. });
  4007. })
  4008. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4009. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4010. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4011. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4012. ->orderBy('updated_at', 'desc')
  4013. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4014. //sql输出
  4015. if (empty($result)) {
  4016. return Result::error("暂无投诉信息", 0);
  4017. }
  4018. // 取出数据
  4019. $rows = $result->items();
  4020. $count = $result->total();
  4021. $responseData = [
  4022. 'rows' => $rows,
  4023. 'count' => $count,
  4024. ];
  4025. return Result::success($responseData);
  4026. }
  4027. public function getComplaintInfo(array $data): array
  4028. {
  4029. $result = Complaint::where('id', $data['id'])->first();
  4030. if (empty($result)) {
  4031. return Result::error("查询失败", 0);
  4032. }
  4033. return Result::success($result);
  4034. }
  4035. public function addComplaint(array $data): array
  4036. {
  4037. date_default_timezone_set('Asia/Shanghai');
  4038. $data['created_at'] = date('Y-m-d H:i:s');
  4039. $data['updated_at'] = date('Y-m-d H:i:s');
  4040. $result = Complaint::create($data);
  4041. return Result::success($result);
  4042. }
  4043. public function updateComplaint(array $data): array
  4044. {
  4045. date_default_timezone_set('Asia/Shanghai');
  4046. $data['updated_at'] = date('Y-m-d H:i:s');
  4047. $user_id = $data['user_id'] ?? 0;
  4048. $type_id = $data['type_id'] ?? 0;
  4049. unset($data['user_id']);
  4050. unset($data['type_id']);
  4051. $result = Complaint::where('id', $data['id'])->update($data);
  4052. return Result::success($result);
  4053. }
  4054. public function deleteComplaint(array $data): array
  4055. {
  4056. $result = Complaint::where('id', $data['id'])->delete();
  4057. return Result::success($result);
  4058. }
  4059. public function getComplainInfo(array $data): array
  4060. {
  4061. $result = Complaint::where('id', $data['id'])->first();
  4062. if (empty($result)) {
  4063. return Result::error("查询失败", 0);
  4064. }
  4065. return Result::success($result);
  4066. }
  4067. public function updateComplaintStatus(array $data): array
  4068. {
  4069. date_default_timezone_set('Asia/Shanghai');
  4070. $data['updated_at'] = date('Y-m-d H:i:s');
  4071. $user_id = $data['user_id'] ?? 0;
  4072. $type_id = $data['type_id'] ?? 0;
  4073. unset($data['user_id']);
  4074. unset($data['type_id']);
  4075. //处理, 写入处理人
  4076. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4077. $data['real_deal_user'] = $user_id;
  4078. }
  4079. //如果是deal 23,则判断是不是处理人
  4080. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4081. $complaintInof = Complaint::where('id', $data['id'])
  4082. ->where('real_deal_user', $user_id)
  4083. ->first();
  4084. if (empty($complaintInof)) {
  4085. return Result::error("处理人错误", 0);
  4086. }
  4087. }
  4088. $result = complaint::where('id', $data['id'])->update($data);
  4089. return Result::success($result);
  4090. }
  4091. public function updateGoodStatus(array $data): array
  4092. {
  4093. $user_id = $data['user_id'] ?? 0;
  4094. $type_id = $data['type_id'] ?? 0;
  4095. unset($data['user_id']);
  4096. unset($data['type_id']);
  4097. $result = Good::where('id', $data['id'])->update($data);
  4098. return Result::success($result);
  4099. }
  4100. public function updateJobHuntingStatus(array $data): array
  4101. {
  4102. $user_id = $data['user_id'] ?? 0;
  4103. $type_id = $data['type_id'] ?? 0;
  4104. unset($data['user_id']);
  4105. unset($data['type_id']);
  4106. $result = JobHunting::where('id', $data['id'])->update($data);
  4107. return Result::success($result);
  4108. }
  4109. public function updateNoticeStatus(array $data): array
  4110. {
  4111. $user_id = $data['user_id'] ?? 0;
  4112. $type_id = $data['type_id'] ?? 0;
  4113. unset($data['user_id']);
  4114. unset($data['type_id']);
  4115. $result = Notice::where('id', $data['id'])->update($data);
  4116. return Result::success($result);
  4117. }
  4118. public function getDUser(array $data): array
  4119. {
  4120. if (!empty($data['ids'])) {
  4121. $user = User::whereIn('id', $data['ids'])->getall();
  4122. if (empty($user)) {
  4123. return Result::error('无数据', 0);
  4124. }
  4125. return Result::success($user);
  4126. }
  4127. $where = [];
  4128. if (!empty($data['department_id'])) {
  4129. $where['department_id'] = $data['department_id'];
  4130. }
  4131. if (!empty($data['city_id'])) {
  4132. $where['city_id'] = $data['city_id'];
  4133. }
  4134. $result = User::where('type_id', 2)
  4135. ->where('status', 1)
  4136. ->where($where)
  4137. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4138. ->get();
  4139. if (empty($result)) {
  4140. return Result::error("查询失败", 0);
  4141. }
  4142. return Result::success($result);
  4143. }
  4144. /**
  4145. * 验证导航名称是否重复
  4146. * @return void
  4147. */
  4148. public function checkCategoryName(array $data): array
  4149. {
  4150. $result = Category::when($data, function ($query) use ($data) {
  4151. if (isset($data['name']) && $data['name']) {
  4152. $query->where("name", $data['name']);
  4153. }
  4154. if (isset($data['id']) && $data['id']) {
  4155. $query->where("id", "!=", $data['id']);
  4156. }
  4157. })->first();
  4158. if ($result) {
  4159. return Result::error("已存在");
  4160. } else {
  4161. return Result::success();
  4162. }
  4163. }
  4164. //20250226 产品列表
  4165. // 20250306 -------招聘--------fr
  4166. /*
  4167. * 招聘列表
  4168. * */
  4169. public function getJobRecruitingList(array $data): array
  4170. {
  4171. $where = [];
  4172. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4173. if ($data['checkout'] == 0) {
  4174. $job_status = [0, 2];
  4175. } else {
  4176. $job_status = [1];
  4177. }
  4178. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4179. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4180. }
  4181. $user = User::where('id', $data['user_id'])->first();
  4182. if (empty($user)) {
  4183. return Result::error("用户不存在", 0);
  4184. }
  4185. // 3:企业会员
  4186. if ($user['type_id'] == 3) {
  4187. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4188. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4189. }
  4190. // 如果 $where 为空,则不添加 where 条件
  4191. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4192. return $query->where($where);
  4193. })
  4194. ->whereIn('job_recruiting.status', $job_status)
  4195. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4196. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4197. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4198. ->orderBy("updated_at", "desc")
  4199. ->offset(($data['page'] - 1) * $data['page_size'])
  4200. ->limit($data['page_size'])
  4201. ->get()
  4202. ->all();
  4203. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4204. return $query->where($where);
  4205. })
  4206. ->whereIn('job_recruiting.status', $job_status)
  4207. ->count();
  4208. if (empty($result)) {
  4209. return Result::error("暂无招聘信息", 0);
  4210. }
  4211. return Result::success($result);
  4212. }
  4213. /*
  4214. * 招聘信息添加
  4215. * */
  4216. public function addJobRecruiting(array $data): array
  4217. {
  4218. // return Result::success($data);
  4219. $user = User::where('user.id', $data['user_id'])
  4220. ->where('user.status', 1)
  4221. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4222. ->select(
  4223. 'user.type_id',
  4224. 'user.mobile',
  4225. 'user.email',
  4226. 'user_info.business_name',
  4227. 'user_info.company_hy_id',
  4228. 'user_info.company_nature',
  4229. 'user_info.company_size',
  4230. 'user_info.introduction',
  4231. 'user_info.real_name',
  4232. 'user_info.company_url',
  4233. 'user_info.address_arr_id',
  4234. 'user_info.address'
  4235. )
  4236. ->first();
  4237. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4238. return Result::error("用户不存在", 0);
  4239. }
  4240. $web = Website::where('id', $data['website_id'])->first();
  4241. if (empty($web)) {
  4242. return Result::error("网站不存在", 0);
  4243. }
  4244. // return Result::success($user);
  4245. $data['action_id'] = $data['user_id'];
  4246. $data['user_type'] = $user['type_id'];
  4247. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4248. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4249. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4250. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4251. // 公司地址 管理员必填
  4252. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4253. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4254. // 管理员-企业相关信息
  4255. $company = [
  4256. // 'user_id' => $data['user_id']?? null,
  4257. 'business_name' => $data['business_name'] ?? null,
  4258. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4259. 'company_size' => $data['company_size'] ?? null,
  4260. 'company_nature' => $data['company_nature'] ?? null,
  4261. 'introduction' => $data['introduction'] ?? null,
  4262. 'real_name' => $data['real_name'] ?? null,
  4263. 'mobile' => $data['mobile'] ?? null,
  4264. 'company_url' => $data['company_url'] ?? null,
  4265. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4266. 'address' => $data['address'] ?? null,
  4267. 'email' => $data['email'] ?? null,
  4268. ];
  4269. //去掉相关企业信息
  4270. $job = array_diff_key($data, array_flip(array_keys($company)));
  4271. Db::beginTransaction();
  4272. try {
  4273. // 先添加职位相关信息
  4274. if ($user['type_id'] == 10000) {
  4275. $job['status'] = 1;
  4276. }
  4277. if (empty($data['experience']) || $data['experience'] == '') {
  4278. $job['experience'] = null;
  4279. } else {
  4280. $job['experience'] = $data['experience'];
  4281. }
  4282. $jobId = JobRecruiting::insertGetId($job);
  4283. if (empty($jobId)) {
  4284. Db::rollBack();
  4285. return Result::error("添加失败");
  4286. }
  4287. // 添加公司信息
  4288. $company['user_id'] = $data['user_id'] ?? null;
  4289. $company['job_id'] = $jobId;
  4290. $company['user_type'] = $user['type_id'] ?? null;
  4291. $company['website_id'] = $data['website_id'] ?? null;
  4292. if ($user['type_id'] == 10000) {
  4293. // 管理员添加企业信息
  4294. // return Result::success($company);
  4295. $companyId = JobCompany::insertGetId($company);
  4296. if (empty($companyId)) {
  4297. Db::rollBack();
  4298. return Result::error("添加失败");
  4299. }
  4300. } else {
  4301. // 企业会员添加企业信息
  4302. $company = [
  4303. 'user_id' => $data['user_id'] ?? null,
  4304. 'business_name' => $user['business_name'] ?? null,
  4305. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4306. 'company_size' => $user['company_size'] ?? null,
  4307. 'company_nature' => $user['company_nature'] ?? null,
  4308. 'introduction' => $user['introduction'] ?? null,
  4309. 'real_name' => $user['real_name'] ?? null,
  4310. 'mobile' => $user['mobile'] ?? null,
  4311. 'company_url' => $user['company_url'] ?? null,
  4312. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4313. 'address' => $user['address'] ?? null,
  4314. 'email' => $user['email'] ?? null,
  4315. 'website_id' => $data['website_id'] ?? null,
  4316. 'user_type' => $user['type_id'] ?? null,
  4317. 'job_id' => $jobId,
  4318. ];
  4319. $companyId = JobCompany::insertGetId($company);
  4320. if (empty($companyId)) {
  4321. Db::rollBack();
  4322. return Result::error("添加失败");
  4323. }
  4324. // return Result::success($company);
  4325. }
  4326. Db::commit();
  4327. } catch (\Exception $e) {
  4328. Db::rollBack();
  4329. return Result::error($e->getMessage(), 0);
  4330. }
  4331. $result = [
  4332. 'job_id' => $jobId,
  4333. 'company_id' => $companyId,
  4334. ];
  4335. if (empty($result)) {
  4336. return Result::error("添加失败", 0);
  4337. }
  4338. return Result::success($result);
  4339. }
  4340. /*
  4341. * 获取招聘信息详情
  4342. * */
  4343. public function getJobRecruitingInfo(array $data): array
  4344. {
  4345. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4346. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4347. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4348. ->select(
  4349. 'job_recruiting.*',
  4350. 'website.website_name as website_name',
  4351. 'job_company.business_name',
  4352. 'job_company.company_hy_id',
  4353. 'job_company.company_size',
  4354. 'job_company.company_nature',
  4355. 'job_company.introduction',
  4356. 'job_company.real_name',
  4357. 'job_company.mobile',
  4358. 'job_company.company_url',
  4359. 'job_company.address_arr_id',
  4360. 'job_company.address',
  4361. 'job_company.email'
  4362. )
  4363. ->first();
  4364. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4365. if (!empty($cityId)) {
  4366. if (isset($cityId[1]) && $cityId[1] != null) {
  4367. $city = District::where('id', $cityId[1])->first(['name']);
  4368. } else {
  4369. $city = District::where('id', $cityId[0])->first(['name']);
  4370. }
  4371. $result['city'] = $city['name'] ?? '';
  4372. }
  4373. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4374. if (is_array($addressId) && !empty($addressId)) {
  4375. $address = District::whereIn('id', $addressId)
  4376. ->orderBy('level', 'asc')
  4377. ->get(['name'])
  4378. ->pluck('name')
  4379. ->implode('');
  4380. // $job->address_name = $address ?? '';
  4381. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4382. }
  4383. if (empty($result)) {
  4384. return Result::error("招聘信息不存在", 0);
  4385. }
  4386. // return Result::success($job);
  4387. return Result::success($result);
  4388. }
  4389. /*
  4390. * 修改招聘信息
  4391. * */
  4392. public function upJobRecruiting(array $data): array
  4393. {
  4394. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4395. // return Result::success($job);
  4396. if (empty($job)) {
  4397. return Result::error("招聘信息不存在", 0);
  4398. }
  4399. $user = User::where('id', $data['user_id'])->first();
  4400. // return Result::success($user);
  4401. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4402. return Result::error("用户不存在", 0);
  4403. }
  4404. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4405. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4406. }
  4407. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4408. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4409. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4410. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4411. // 公司地址 管理员必填
  4412. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4413. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4414. // 管理员-企业相关信息
  4415. $company = [
  4416. 'business_name' => $data['business_name'] ?? null,
  4417. 'company_hy_id' => $data['hy_id'] ?? null,
  4418. 'company_size' => $data['company_size'] ?? null,
  4419. 'company_nature' => $data['company_nature'] ?? null,
  4420. 'introduction' => $data['introduction'] ?? null,
  4421. 'real_name' => $data['real_name'] ?? null,
  4422. 'mobile' => $data['mobile'] ?? null,
  4423. 'company_url' => $data['company_url'] ?? null,
  4424. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4425. 'address' => $data['address'] ?? null,
  4426. 'email' => $data['email'] ?? null,
  4427. ];
  4428. //去掉相关企业信息
  4429. $data = array_diff_key($data, array_flip(array_keys($company)));
  4430. $jobId = $data['id'];
  4431. $web = $data['website_id'];
  4432. $data['action_id'] = $data['user_id'];
  4433. unset($data['user_id']);
  4434. unset($data['user_type']);
  4435. unset($data['id']);
  4436. unset($data['website_id']);
  4437. // return Result::success($data);
  4438. Db::beginTransaction();
  4439. try {
  4440. // 管理员修改招聘信息
  4441. if ($user['type_id'] == 10000) {
  4442. $data['website_id'] = $web;
  4443. $company['website_id'] = $data['website_id'];
  4444. $data['status'] = 1;
  4445. } else {
  4446. $data['status'] = 0;
  4447. }
  4448. if (empty($data['experience']) || $data['experience'] == '') {
  4449. $job['experience'] = null;
  4450. } else {
  4451. $job['experience'] = $data['experience'];
  4452. }
  4453. // Db::rollBack();
  4454. // return Result::success($company);
  4455. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4456. if (empty($result['job'])) {
  4457. Db::rollBack();
  4458. return Result::error("修改招聘信息失败");
  4459. }
  4460. // 管理员修改企业相关信息
  4461. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4462. if (empty($result['company'])) {
  4463. Db::rollBack();
  4464. return Result::error("修改企业相关信息失败");
  4465. }
  4466. Db::commit();
  4467. // return Result::success($result);
  4468. } catch (\Exception $e) {
  4469. Db::rollBack();
  4470. return Result::error($e->getMessage(), 0);
  4471. }
  4472. return Result::success($result);
  4473. }
  4474. /*
  4475. * 招聘信息删除
  4476. * */
  4477. public function delJobRecruiting(array $data): array
  4478. {
  4479. $user = User::where('id', $data['user_id'])->first();
  4480. if (empty($user)) {
  4481. return Result::error("用户不存在", 0);
  4482. }
  4483. $job = JobRecruiting::where('id', $data['id'])->first();
  4484. if (empty($job)) {
  4485. return Result::error("招聘信息不存在", 0);
  4486. }
  4487. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4488. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4489. }
  4490. Db::beginTransaction();
  4491. try {
  4492. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4493. if (empty($result['job'])) {
  4494. Db::rollBack();
  4495. return Result::error("删除招聘信息失败");
  4496. }
  4497. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4498. if (empty($result['company'])) {
  4499. Db::rollBack();
  4500. return Result::error("删除企业相关信息失败");
  4501. }
  4502. Db::commit();
  4503. } catch (\Exception $e) {
  4504. Db::rollBack();
  4505. return Result::error($e->getMessage(), 0);
  4506. }
  4507. return Result::success($result);
  4508. }
  4509. /*
  4510. * 获取公司信息
  4511. * */
  4512. public function getJobCompany(array $data): array
  4513. {
  4514. $user = User::where('user.id', $data['user_id'])
  4515. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4516. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4517. ->first();
  4518. // return Result::success($user);
  4519. if (empty($user)) {
  4520. return Result::error("用户不存在", 0);
  4521. }
  4522. if ($user['type_id'] == 3) {
  4523. $result = [
  4524. // 'id' => 0,
  4525. 'user_id' => $data['user_id'],
  4526. 'website_id' => $data['website_id'],
  4527. 'business_name' => $user['business_name'], // 企业名称
  4528. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4529. 'company_nature' => $user['company_nature'], // 公司性质
  4530. 'company_size' => $user['company_size'], // 公司规模
  4531. 'introduction' => $user['introduction'], // 公司简介
  4532. 'real_name' => $user['real_name'], // 企业联系人
  4533. 'mobile' => $user['mobile'], // 企业联系电话
  4534. 'company_url' => $user['company_url'], // 企业网址
  4535. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4536. 'address' => $user['address'], // 企业地址
  4537. 'email' => $user['email'], // 企业邮箱
  4538. ];
  4539. } else {
  4540. return Result::error("用户类型错误", 0);
  4541. }
  4542. if (empty($result)) {
  4543. return Result::error("公司信息不存在", 0);
  4544. }
  4545. return Result::success($result);
  4546. }
  4547. /*
  4548. * 修改公司信息
  4549. * */
  4550. public function upJobCompany(array $data): array
  4551. {
  4552. // return Result::success($data);
  4553. $user = User::where('user.id', $data['user_id'])
  4554. ->where('user.status', 1)
  4555. ->select('user.user_name', 'user.type_id')
  4556. ->first();
  4557. if (empty($user)) {
  4558. return Result::error("用户不存在", 0);
  4559. }
  4560. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4561. $company = [
  4562. 'business_name' => $data['business_name'], // 企业名称
  4563. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4564. 'company_nature' => $data['company_nature'], // 公司性质
  4565. 'company_size' => $data['company_size'], // 公司规模
  4566. 'introduction' => $data['introduction'], // 公司简介
  4567. // 'real_name' => $data['real_name'], // 企业联系人
  4568. 'company_url' => $data['company_url'], // 企业网址
  4569. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4570. 'address' => $data['address'], // 企业详细地址
  4571. ];
  4572. if ($user['type_id'] == 3) {
  4573. Db::beginTransaction();
  4574. try {
  4575. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  4576. 'business_name' => $data['business_name'], // 企业名称
  4577. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4578. 'company_nature' => $data['company_nature'], // 公司性质
  4579. 'company_size' => $data['company_size'], // 公司规模
  4580. 'introduction' => $data['introduction'], // 公司简介
  4581. // 'real_name' => $data['real_name'], // 企业联系人
  4582. 'company_url' => $data['company_url'], // 企业网址
  4583. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4584. 'address' => $data['address'], // 企业详细地址
  4585. ]);
  4586. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  4587. Db::commit();
  4588. } catch (\Exception $e) {
  4589. Db::rollBack();
  4590. return Result::error($e->getMessage(), 0);
  4591. }
  4592. } else {
  4593. return Result::error("用户类型错误", 0);
  4594. }
  4595. if (empty($result)) {
  4596. return Result::error("修改失败", 0);
  4597. }
  4598. return Result::success($result);
  4599. }
  4600. /*
  4601. * 获取省-市
  4602. * */
  4603. public function getJobRecruitingArea(array $data): array
  4604. {
  4605. if (isset($data['pid']) && $data['pid'] != null) {
  4606. $result = District::where('pid', $data['pid'])->get()->all();
  4607. } else {
  4608. $result = District::where('level', 1)->get()->all();
  4609. }
  4610. if (empty($result)) {
  4611. return Result::error("暂无此省市", 0);
  4612. }
  4613. return Result::success($result);
  4614. }
  4615. /*
  4616. * 获取行业分类
  4617. * */
  4618. public function getIndustry(array $data): array
  4619. {
  4620. $result = JobIndustry::get()->all();
  4621. if (empty($result)) {
  4622. return Result::error("暂无行业分类", 0);
  4623. }
  4624. return Result::success($result);
  4625. }
  4626. /*
  4627. * 获取职位
  4628. * */
  4629. public function getPositionList(array $data): array
  4630. {
  4631. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  4632. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  4633. } else {
  4634. $result = JobPosition::where('zwpid', 0)->get()->all();
  4635. }
  4636. if (empty($result)) {
  4637. return Result::error("暂无此职位", 0);
  4638. }
  4639. return Result::success($result);
  4640. }
  4641. /*
  4642. * 获取工作性质-菜单
  4643. * */
  4644. public function getJobNature(array $data): array
  4645. {
  4646. $result = JobEnum::where('egroup', 'nature')->get()->all();
  4647. if (empty($result)) {
  4648. return Result::error("暂无工作性质", 0);
  4649. }
  4650. return Result::success($result);
  4651. }
  4652. /*
  4653. * 获取工作经验-菜单
  4654. * */
  4655. public function getExperience(array $data): array
  4656. {
  4657. $result = JobEnum::where('egroup', 'years')->get()->all();
  4658. if (empty($result)) {
  4659. return Result::error("暂无工作经验", 0);
  4660. }
  4661. return Result::success($result);
  4662. }
  4663. /*
  4664. * 获取学历-菜单
  4665. * */
  4666. public function getEducation(array $data): array
  4667. {
  4668. $result = JobEnum::where('egroup', 'education')->get()->all();
  4669. if (empty($result)) {
  4670. return Result::error("暂无学历", 0);
  4671. }
  4672. return Result::success($result);
  4673. }
  4674. /*
  4675. * 获取薪资-菜单
  4676. * */
  4677. public function getSalary(array $data): array
  4678. {
  4679. $result = JobEnum::where('egroup', 'income')->get()->all();
  4680. if (empty($result)) {
  4681. return Result::error("暂无薪资", 0);
  4682. }
  4683. return Result::success($result);
  4684. }
  4685. /*
  4686. * 获取语言-菜单
  4687. * */
  4688. public function getLanguage(array $data): array
  4689. {
  4690. $result = JobEnum::where('egroup', 'language')->get()->all();
  4691. if (empty($result)) {
  4692. return Result::error("暂无语言", 0);
  4693. }
  4694. return Result::success($result);
  4695. }
  4696. /*
  4697. * 获取掌握程度-菜单
  4698. * */
  4699. public function getLevel(array $data): array
  4700. {
  4701. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  4702. if (empty($result)) {
  4703. return Result::error("暂无工作性质", 0);
  4704. }
  4705. return Result::success($result);
  4706. }
  4707. // 公司信息
  4708. /*
  4709. * 获取公司性质-菜单
  4710. * */
  4711. public function getCompanyNature(array $data): array
  4712. {
  4713. $result = JobNature::get()->all();
  4714. if (empty($result)) {
  4715. return Result::error("暂无公司性质", 0);
  4716. }
  4717. return Result::success($result);
  4718. }
  4719. /*
  4720. * 获取公司规模-菜单
  4721. * */
  4722. public function getCompanySize(array $data): array
  4723. {
  4724. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  4725. if (empty($result)) {
  4726. return Result::error("暂无公司规模", 0);
  4727. }
  4728. return Result::success($result);
  4729. }
  4730. /*
  4731. * 招聘信息审核
  4732. * */
  4733. public function checkJobRecruiting(array $data): array
  4734. {
  4735. $user = User::where('id', $data['user_id'])->first();
  4736. if (empty($user)) {
  4737. return Result::error("用户不存在", 0);
  4738. }
  4739. $job = JobRecruiting::where('id', $data['id'])->first();
  4740. if (empty($job)) {
  4741. return Result::error("招聘信息不存在", 0);
  4742. }
  4743. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  4744. if ($user['type_id'] != 10000) {
  4745. return Result::error("用户暂无权限审核此招聘信息!", 0);
  4746. }
  4747. // 驳回原因
  4748. if ($data['status'] == 2) {
  4749. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  4750. }
  4751. $data['action_id'] = $data['user_id'];
  4752. unset($data['user_id']);
  4753. $result = JobRecruiting::where('id', $data['id'])->update($data);
  4754. if (empty($result)) {
  4755. return Result::error("审核失败", 0);
  4756. }
  4757. return Result::success($result);
  4758. }
  4759. public function myApplyList(array $data): array
  4760. {
  4761. var_dump($data, '------参数');
  4762. $user = User::where('id', $data['user_id'])->first();
  4763. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4764. return Result::error("用户不存在", 0);
  4765. }
  4766. // 1:个人会员 职场机会
  4767. if ($user['type_id'] == 1) {
  4768. $where['user_id'] = $user['id'];
  4769. }
  4770. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  4771. $query->where('user_id', $user['id']);
  4772. })
  4773. ->pluck('recruit_id');
  4774. $where = [];
  4775. if (isset($data['salary']) && $data['salary'] != null) {
  4776. $where['job_recruiting.salary'] = $data['salary'];
  4777. }
  4778. if (isset($data['experience']) && $data['experience'] != null) {
  4779. $where['job_recruiting.experience'] = $data['experience'];
  4780. }
  4781. if (isset($data['business_name']) && $data['business_name'] != null) {
  4782. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4783. }
  4784. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4785. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4786. ->where($where);
  4787. // ->count();
  4788. $count = $query->count();
  4789. $query = clone $query;
  4790. $job = $query
  4791. ->leftJoin('job_enum as income_enum', function ($join) {
  4792. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4793. ->where('income_enum.egroup', 'income');
  4794. })
  4795. ->leftJoin('job_enum as years_enum', function ($join) {
  4796. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4797. ->where('years_enum.egroup', 'years');
  4798. })
  4799. // ->where($where)
  4800. ->orderBy('job_recruiting.updated_at', 'desc')
  4801. ->select(
  4802. 'job_recruiting.id',
  4803. 'job_recruiting.title',
  4804. 'job_company.business_name',
  4805. 'income_enum.evalue as salary_evalue',
  4806. 'income_enum.ename as salary_ename',
  4807. 'years_enum.evalue as experience_evalue',
  4808. 'years_enum.ename as experience_ename',
  4809. 'job_recruiting.updated_at'
  4810. )
  4811. ->offset(($data['page'] - 1) * $data['pageSize'])
  4812. ->limit($data['pageSize'])
  4813. ->get()
  4814. ->all();
  4815. if (empty($job)) {
  4816. return Result::error("暂无招聘信息", 0);
  4817. }
  4818. $result = [
  4819. 'row' => $job,
  4820. 'count' => $count,
  4821. ];
  4822. return Result::success($result);
  4823. }
  4824. /*
  4825. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  4826. * */
  4827. public function getRecruitingList(array $data): array
  4828. {
  4829. $user = User::where('id', $data['user_id'])->first();
  4830. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4831. return Result::error("用户不存在", 0);
  4832. }
  4833. // 1:个人会员 职场机会
  4834. if ($user['type_id'] == 1) {
  4835. $where['user_id'] = $user['id'];
  4836. }
  4837. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  4838. $query->where('receiver_id', $user['id']);
  4839. })
  4840. ->pluck('recruit_id');
  4841. // return Result::success($recruitingId);
  4842. $where = [];
  4843. if (isset($data['salary']) && $data['salary'] != null) {
  4844. $where['job_recruiting.salary'] = $data['salary'];
  4845. }
  4846. if (isset($data['experience']) && $data['experience'] != null) {
  4847. $where['job_recruiting.experience'] = $data['experience'];
  4848. }
  4849. if (isset($data['business_name']) && $data['business_name'] != null) {
  4850. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4851. }
  4852. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4853. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4854. ->where($where);
  4855. // ->count();
  4856. $count = $query->count();
  4857. $query = clone $query;
  4858. $job = $query
  4859. ->leftJoin('job_enum as income_enum', function ($join) {
  4860. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4861. ->where('income_enum.egroup', 'income');
  4862. })
  4863. ->leftJoin('job_enum as years_enum', function ($join) {
  4864. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4865. ->where('years_enum.egroup', 'years');
  4866. })
  4867. // ->where($where)
  4868. ->orderBy('job_recruiting.updated_at', 'desc')
  4869. ->select(
  4870. 'job_recruiting.id',
  4871. 'job_recruiting.title',
  4872. 'job_company.business_name',
  4873. 'income_enum.evalue as salary_evalue',
  4874. 'income_enum.ename as salary_ename',
  4875. 'years_enum.evalue as experience_evalue',
  4876. 'years_enum.ename as experience_ename',
  4877. 'job_recruiting.updated_at'
  4878. )
  4879. ->offset(($data['page'] - 1) * $data['pageSize'])
  4880. ->limit($data['pageSize'])
  4881. ->get()
  4882. ->all();
  4883. if (empty($job)) {
  4884. return Result::error("暂无招聘信息", 0);
  4885. }
  4886. $result = [
  4887. 'row' => $job,
  4888. 'count' => $count,
  4889. ];
  4890. return Result::success($result);
  4891. }
  4892. /*
  4893. * 获取企业会员-招聘信息列表
  4894. * */
  4895. public function getRecruitingInfo(array $data): array
  4896. {
  4897. $user = User::where('id', $data['user_id'])->first();
  4898. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4899. return Result::error("用户不存在", 0);
  4900. }
  4901. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  4902. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4903. ->select(
  4904. 'job_recruiting.*',
  4905. 'job_company.business_name',
  4906. 'job_company.company_hy_id',
  4907. 'job_company.company_size',
  4908. 'job_company.company_nature',
  4909. 'job_company.introduction',
  4910. 'job_company.real_name',
  4911. 'job_company.mobile',
  4912. 'job_company.company_url',
  4913. 'job_company.address_arr_id',
  4914. 'job_company.address',
  4915. 'job_company.email'
  4916. )
  4917. ->get();
  4918. if (empty($recruiting)) {
  4919. return Result::error("暂无招聘信息", 0);
  4920. }
  4921. return Result::success($recruiting);
  4922. }
  4923. /*
  4924. * 获取企业会员-我的沟通
  4925. * */
  4926. public function getJobResumeList(array $data): array
  4927. {
  4928. $user = User::where('id', $data['user_id'])->first();
  4929. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  4930. return Result::error("用户不存在", 0);
  4931. }
  4932. $where = [];
  4933. if (isset($data['salary']) && $data['salary'] != null) {
  4934. $where['job_hunting.salary'] = $data['salary'];
  4935. }
  4936. if (isset($data['user_name']) && $data['user_name'] != null) {
  4937. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  4938. }
  4939. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  4940. $query->where('job_resume.user_id', $user['id']);
  4941. })
  4942. ->when(!empty($where), function ($query) use ($where) {
  4943. $query->where($where);
  4944. })
  4945. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  4946. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  4947. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  4948. ->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');
  4949. $count = $job->count();
  4950. if ($count == 0) {
  4951. return Result::error("暂无沟通记录", 0);
  4952. }
  4953. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  4954. ->offset(($data['page'] - 1) * $data['pageSize'])
  4955. ->limit($data['pageSize'])
  4956. ->get();
  4957. if (empty($jobs)) {
  4958. return Result::error("暂无沟通记录", 0);
  4959. }
  4960. $result['row'] = $this->processJob($jobs, '');
  4961. $result['count'] = $count;
  4962. return Result::success($result);
  4963. }
  4964. // 20250306 招聘
  4965. //20250422 书刊音像
  4966. public function addBook(array $data): array
  4967. {
  4968. // $user_id = $data['user_id'] ?? 0;
  4969. $type_id = $data['type_id'] ?? 0;
  4970. // $website_id = $data['website_id'] ?? 0;
  4971. // unset($data['user_id']);
  4972. unset($data['type_id']);
  4973. // unset($data['website_id']);
  4974. //处理数组
  4975. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  4976. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  4977. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  4978. if ($data['img_url'] == '') {
  4979. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4980. preg_match_all($reg, $data['detail'], $matches);
  4981. if (isset($matches[1][0])) {
  4982. //截取varchar240
  4983. $data['img_url'] = substr($matches[1][0], 0, 240);
  4984. }
  4985. }
  4986. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4987. //提取标题+内容中的关键词
  4988. $data['keyword'] = $data['title'];
  4989. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4990. Jieba::init(); // 初始化 jieba-php
  4991. Finalseg::init();
  4992. $segList = Jieba::cut($data['keyword']);
  4993. $segList1 = array_slice($segList, 0, 8);
  4994. $data['keyword'] = implode(',', $segList1);
  4995. }
  4996. if ($data['description'] == '') {
  4997. //提取内容中的描述
  4998. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4999. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5000. }
  5001. var_dump($data, '--');
  5002. $result = Book::insertGetId($data);
  5003. if (empty($result)) {
  5004. return Result::error("添加失败", 0);
  5005. }
  5006. return Result::success($result);
  5007. }
  5008. public function getBookList(array $data): array
  5009. {
  5010. $where = [];
  5011. if (!empty($data["title"])) {
  5012. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5013. }
  5014. if (!empty($data['website_name'])) {
  5015. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5016. }
  5017. if (!empty($data['status'])) {
  5018. $where[] = ['book.status', '=', $data['status']];
  5019. }
  5020. $user_id = $data['user_id'];
  5021. $type_id = $data['type_id'];
  5022. // $type_id = 4;
  5023. var_dump($type_id, '------1--------');
  5024. if ($type_id != 10000) {
  5025. $where[] = ['book.user_id', '=', $user_id];
  5026. }
  5027. var_dump(!empty($data['status1']), '=-===1');
  5028. $result = Book::where($where)
  5029. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5030. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5031. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5032. ->when(isset($data['status1']), function ($query) use ($data) {
  5033. $query->whereIn('book.status', [1, 3]);
  5034. })
  5035. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5036. ->orderBy("updated_at", "desc")
  5037. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5038. if (empty($result)) {
  5039. return Result::error("暂无数据", 0);
  5040. }
  5041. // 取出数据
  5042. $rows = $result->items();
  5043. $count = $result->total();
  5044. $responseData = [
  5045. 'rows' => $rows,
  5046. 'count' => $count,
  5047. ];
  5048. return Result::success($responseData);
  5049. }
  5050. public function deleteBook(array $data): array
  5051. {
  5052. $result = Book::where('id', $data['id'])->delete();
  5053. if (empty($result)) {
  5054. return Result::error("删除失败", 0);
  5055. }
  5056. return Result::success($result);
  5057. }
  5058. public function updateBook(array $data): array
  5059. {
  5060. // $user_id = $data['user_id'] ?? 0;
  5061. $type_id = $data['type_id'] ?? 0;
  5062. // $website_id = $data['website_id'] ?? 0;
  5063. unset($data['user_id']);
  5064. unset($data['type_id']);
  5065. // unset($data['website_id']);
  5066. //处理数组
  5067. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5068. if ($data['img_url'] == '') {
  5069. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5070. preg_match_all($reg, $data['detail'], $matches);
  5071. if (isset($matches[1][0])) {
  5072. //截取varchar240
  5073. $data['img_url'] = substr($matches[1][0], 0, 240);
  5074. }
  5075. }
  5076. if ($data['keyword'] == '') {
  5077. //提取标题+内容中的关键词
  5078. $data['keyword'] = $data['title'];
  5079. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5080. Jieba::init(); // 初始化 jieba-php
  5081. Finalseg::init();
  5082. $segList = Jieba::cut($data['keyword']);
  5083. $segList1 = array_slice($segList, 0, 8);
  5084. $data['keyword'] = implode(',', $segList1);
  5085. }
  5086. if ($data['description'] == '') {
  5087. //提取内容中的描述
  5088. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5089. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5090. }
  5091. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5092. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5093. $result = Book::where("id", $data["id"])->update($data);
  5094. if (empty($result)) {
  5095. return Result::error("更新失败", 0);
  5096. }
  5097. return Result::success($result);
  5098. }
  5099. public function getBookInfo(array $data): array
  5100. {
  5101. $result = Book::where("id", $data["id"])->first();
  5102. if (empty($result)) {
  5103. return Result::error("获取失败", 0);
  5104. }
  5105. return Result::success($result);
  5106. }
  5107. public function updateBookStatus(array $data): array
  5108. {
  5109. //审核
  5110. unset($data['user_id']);
  5111. $result = Book::where("id", $data["id"])->update($data);
  5112. if (empty($result)) {
  5113. return Result::error("更新失败", 0);
  5114. }
  5115. return Result::success($result);
  5116. }
  5117. //20250422 书刊音像
  5118. /**
  5119. * 贴身宝贝
  5120. * @param array $data
  5121. * @return array
  5122. */
  5123. public function getWebsiteTsbb(array $data): array
  5124. {
  5125. $month = $data['month'] ?? date('m');
  5126. $day = $data['day'] ?? date('d');
  5127. // 使用缓存键
  5128. $cacheKey = "tsbb_data_{$month}_{$day}";
  5129. // 尝试从缓存获取数据
  5130. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5131. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5132. if ($cachedData = $cache->get($cacheKey)) {
  5133. return Result::success(unserialize($cachedData));
  5134. }
  5135. //查询老黄历
  5136. try {
  5137. $date = date('Y-m-d');
  5138. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5139. // 使用 curl 替代 file_get_contents
  5140. $ch = curl_init();
  5141. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5142. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5143. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5144. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5145. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5146. 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');
  5147. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5148. 'Accept: application/json',
  5149. 'Content-Type: application/json',
  5150. 'Referer: https://www.36jxs.com/'
  5151. ]);
  5152. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5153. curl_setopt($ch, CURLOPT_ENCODING, '');
  5154. $almanacResponse = curl_exec($ch);
  5155. var_dump("====:", $almanacResponse);
  5156. if (curl_errno($ch)) {
  5157. var_dump('Curl error:', curl_error($ch));
  5158. throw new \Exception('Curl error: ' . curl_error($ch));
  5159. }
  5160. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5161. curl_close($ch);
  5162. if ($almanacResponse === false) {
  5163. throw new \Exception('Failed to fetch almanac data');
  5164. }
  5165. $almanacData = json_decode($almanacResponse, true);
  5166. if (json_last_error() !== JSON_ERROR_NONE) {
  5167. throw new \Exception('Failed to parse almanac data');
  5168. }
  5169. $almanacInfo = $almanacData['data'] ?? [];
  5170. } catch (\Exception $e) {
  5171. var_dump('Exception:', $e->getMessage());
  5172. $almanacInfo = [];
  5173. }
  5174. // 获取历史上的今天数据
  5175. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5176. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5177. ->orderBy('year', 'asc')
  5178. ->select("title", "id", "year", DB::raw('1 as type'))
  5179. ->limit(16)
  5180. ->get();
  5181. // 获取节日数据 - 从今天开始获取未来4条
  5182. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5183. ->orderBy('showtime', 'asc')
  5184. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5185. ->limit(16)
  5186. ->get();
  5187. //说文解字
  5188. $chartacterList = Character::orderBy('updated_at', 'desc')
  5189. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5190. ->limit(6)
  5191. ->get();
  5192. //谜语沙龙
  5193. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5194. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5195. ->limit(4)
  5196. ->get();
  5197. //成语欣赏
  5198. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5199. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5200. ->limit(32)
  5201. ->get();
  5202. //名联赏析
  5203. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5204. ->select("id", "first", "second", DB::raw('6 as type'))
  5205. ->limit(6)
  5206. ->get();
  5207. // 获取分类文章数据
  5208. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5209. ->pluck('category_id')
  5210. ->toArray();
  5211. // $categoryIds = [627, 628, 629, 630, 631, 632, 633, 634, 635, 636];
  5212. // 使用子查询优化
  5213. $articlesList = DB::table('article')
  5214. ->select([
  5215. 'article.id',
  5216. 'article.title',
  5217. 'article.imgurl',
  5218. 'article.created_at',
  5219. 'category.name as category_name',
  5220. 'category.id as category_id',
  5221. 'website_category.aLIas_pinyin as pinyin',
  5222. DB::raw('100 as type')
  5223. ])
  5224. ->join('category', 'article.catid', '=', 'category.id')
  5225. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5226. ->where('website_category.website_id', $data['website_id'])
  5227. ->where('article.status', 1)
  5228. ->whereIn('category.id', $categoryIds)
  5229. // ->whereRaw('article.created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)')
  5230. ->orderBy('article.created_at', 'desc')
  5231. ->get()
  5232. ->groupBy('category_id')
  5233. ->map(function ($group) {
  5234. // 确保第一条数据有图片
  5235. $firstWithImage = $group->first(function ($item) {
  5236. return !empty($item->imgurl);
  5237. });
  5238. if ($firstWithImage) {
  5239. // 如果有带图片的文章,将其放在第一位
  5240. $group = $group->filter(function ($item) use ($firstWithImage) {
  5241. return $item->id !== $firstWithImage->id;
  5242. })->prepend($firstWithImage);
  5243. }
  5244. return [
  5245. 'category_name' => $group->first()->category_name,
  5246. 'catid' => $group->first()->category_id,
  5247. 'pinyin' => $group->first()->pinyin,
  5248. 'type' => 100,
  5249. 'list' => $group->take(6)->map(function ($item) {
  5250. return [
  5251. 'id' => $item->id,
  5252. 'title' => $item->title,
  5253. 'imgurl' => $item->imgurl,
  5254. 'created_at' => $item->created_at
  5255. ];
  5256. })->values()
  5257. ];
  5258. })
  5259. ->values()
  5260. ->toArray();
  5261. $result = [
  5262. 'almanac' => $almanacInfo,
  5263. 'historyTodayList' => [
  5264. 'category_name' => '历史上的今天',
  5265. 'list' => $historyTodayList,
  5266. 'type' => 1
  5267. ],
  5268. 'festivalList' => [
  5269. 'category_name' => '节日预告',
  5270. 'list' => $festivalList,
  5271. 'type' => 2
  5272. ],
  5273. 'chartacterList' => [
  5274. 'category_name' => '说文解字',
  5275. 'list' => $chartacterList,
  5276. 'type' => 3
  5277. ],
  5278. 'coupletList' => [
  5279. 'category_name' => '名联赏析',
  5280. 'list' => $coupletList,
  5281. 'type' => 6
  5282. ],
  5283. 'riddletList' => [
  5284. 'category_name' => '谜语沙龙',
  5285. 'list' => $riddletList,
  5286. 'type' => 4
  5287. ],
  5288. 'idiomList' => [
  5289. 'category_name' => '成语欣赏',
  5290. 'list' => $idiomList,
  5291. 'type' => 5
  5292. ],
  5293. 'articlesList' => $articlesList
  5294. ];
  5295. // 缓存结果,设置1小时过期
  5296. $cache->set($cacheKey, serialize($result), 3600);
  5297. return Result::success($result);
  5298. }
  5299. /**
  5300. * 获取资讯列表
  5301. */
  5302. public function getWebsiteTsbbList(array $data): array
  5303. {
  5304. $page = $data['page'] ?? 1;
  5305. $pageSize = $data['pageSize'] ?? 10;
  5306. // 如果没有传入月份和日期,则使用今天的日期
  5307. $month = $data['month'] ?? date('m');
  5308. $day = $data['day'] ?? date('d');
  5309. $total = 0;
  5310. $result = [];
  5311. $data['type'] = intval($data['type']);
  5312. var_dump("接收参数:", $data);
  5313. switch ($data['type']) {
  5314. case 1:
  5315. $query = HistoryToday::where(function ($q) use ($month, $day) {
  5316. // 当前月份之后的数据
  5317. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  5318. // 或者当前月份且日期大于等于当前日期的数据
  5319. ->orWhere(function ($q) use ($month, $day) {
  5320. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5321. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  5322. });
  5323. })
  5324. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  5325. $total = $query->count();
  5326. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  5327. ->offset(($page - 1) * $pageSize)
  5328. ->limit($pageSize)
  5329. ->get();
  5330. break;
  5331. case 2:
  5332. $query = Festival::where(function ($q) use ($month, $day) {
  5333. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  5334. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  5335. ->orWhere(function ($q) use ($month, $day) {
  5336. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  5337. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  5338. });
  5339. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  5340. $total = $query->count();
  5341. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  5342. ->offset(($page - 1) * $pageSize)
  5343. ->limit($pageSize)
  5344. ->get();
  5345. break;
  5346. case 3:
  5347. $query = Character::orderBy("updated_at", "desc");
  5348. $total = $query->count();
  5349. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  5350. ->offset(($page - 1) * $pageSize)
  5351. ->limit($pageSize)
  5352. ->get();
  5353. break;
  5354. case 4:
  5355. $query = Riddle::orderBy("updated_at", "desc");
  5356. $total = $query->count();
  5357. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  5358. ->offset(($page - 1) * $pageSize)
  5359. ->limit($pageSize)
  5360. ->get();
  5361. break;
  5362. case 5:
  5363. $query = Idiom::orderBy("updated_at", "desc");
  5364. $total = $query->count();
  5365. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  5366. ->offset(($page - 1) * $pageSize)
  5367. ->limit($pageSize)
  5368. ->get();
  5369. break;
  5370. case 6:
  5371. $query = Couplet::orderBy("updated_at", "desc");
  5372. $total = $query->count();
  5373. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  5374. ->offset(($page - 1) * $pageSize)
  5375. ->limit($pageSize)
  5376. ->get();
  5377. break;
  5378. default:
  5379. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  5380. $total = $query->count();
  5381. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  5382. ->offset(($page - 1) * $pageSize)
  5383. ->limit($pageSize)
  5384. ->get();
  5385. }
  5386. return Result::success([
  5387. 'list' => $result,
  5388. 'total' => $total,
  5389. 'page' => (int)$page,
  5390. 'pageSize' => (int)$pageSize,
  5391. 'month' => $month,
  5392. 'day' => $day
  5393. ]);
  5394. }
  5395. /**
  5396. * 1:历史上的今天
  5397. * 2:节日
  5398. * 3:文章
  5399. *
  5400. * 资讯详情信息
  5401. */
  5402. public function getWebsiteTsbbDetail(array $data): array
  5403. {
  5404. $data['type'] = intval($data['type']);
  5405. switch ($data['type']) {
  5406. case 1:
  5407. $result = HistoryToday::where("id", $data['id'])->first();
  5408. break;
  5409. case 2:
  5410. $result = Festival::where("id", $data['id'])->first();
  5411. break;
  5412. case 3:
  5413. $result = Character::where("id", $data['id'])->first();
  5414. break;
  5415. case 4:
  5416. $result = Riddle::where("id", $data['id'])->first();
  5417. break;
  5418. case 5:
  5419. $result = Idiom::where("id", $data['id'])->first();
  5420. break;
  5421. case 6:
  5422. $result = Couplet::where("id", $data['id'])->first();
  5423. break;
  5424. default:
  5425. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  5426. break;
  5427. }
  5428. return Result::success($result);
  5429. }
  5430. /**
  5431. * 农网导航首页数据
  5432. */
  5433. public function getWebsiteNwHomeList(array $data): array
  5434. {
  5435. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  5436. ->pluck('category_id')
  5437. ->toArray();
  5438. // 使用子查询优化
  5439. $articlesList = DB::table('article')
  5440. ->select([
  5441. 'article.id',
  5442. 'article.title',
  5443. 'article.imgurl',
  5444. 'article.created_at',
  5445. 'category.name as category_name',
  5446. 'category.id as category_id',
  5447. 'website_category.aLIas_pinyin as pinyin',
  5448. 'parent_wc.aLIas_pinyin as parent_pinyin',
  5449. DB::raw('100 as type')
  5450. ])
  5451. ->join('category', 'article.catid', '=', 'category.id')
  5452. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5453. ->leftJoin('website_category as parent_wc', function ($join) {
  5454. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  5455. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  5456. })
  5457. ->where('website_category.website_id', $data['website_id'])
  5458. ->where('article.status', 1)
  5459. ->whereIn('category.id', $categoryIds)
  5460. ->orderBy('article.created_at', 'desc')
  5461. ->get()
  5462. ->groupBy('category_id')
  5463. ->map(function ($group) {
  5464. // 确保第一条数据有图片
  5465. $firstWithImage = $group->first(function ($item) {
  5466. return !empty($item->imgurl);
  5467. });
  5468. if ($firstWithImage) {
  5469. // 如果有带图片的文章,将其放在第一位
  5470. $group = $group->filter(function ($item) use ($firstWithImage) {
  5471. return $item->id !== $firstWithImage->id;
  5472. })->prepend($firstWithImage);
  5473. }
  5474. return [
  5475. 'category_name' => $group->first()->category_name,
  5476. 'catid' => $group->first()->category_id,
  5477. 'pinyin' => $group->first()->pinyin,
  5478. 'parent_pinyin' => $group->first()->parent_pinyin,
  5479. 'list' => $group->take(4)->map(function ($item) {
  5480. return [
  5481. 'id' => $item->id,
  5482. 'title' => $item->title,
  5483. ];
  5484. })->values()
  5485. ];
  5486. })
  5487. ->values()
  5488. ->toArray();
  5489. return Result::success($articlesList);
  5490. }
  5491. /**
  5492. * 模块新闻加强版
  5493. * @param array $data
  5494. * @return array
  5495. */
  5496. public function getWebsiteAllArticle(array $data): array
  5497. {
  5498. // 修正传入的字符串,将单引号替换为双引号
  5499. $input['id'] = $data['id'];
  5500. $input['website_id'] = $data['website_id'];
  5501. // 将 JSON 字符串转换为 PHP 数组
  5502. $data = json_decode($input['id'], true);
  5503. // 使用 array_map 处理每个元素
  5504. $result = array_map(function ($item) use ($input) {
  5505. // 检查parent元素是否存在且不是undefined
  5506. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  5507. $count = explode(',', $item['parent']);
  5508. if (count($count) != 3) {
  5509. return Result::error("参数错误", 0);
  5510. }
  5511. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  5512. $website = [
  5513. 'website_id' => $input['website_id'],
  5514. ];
  5515. // 查询栏目名称
  5516. $categroy = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin', 'type']);
  5517. // 查询图片新闻
  5518. if (isset($parentImgNum) && $parentImgNum != 0 && !empty($categroy)) {
  5519. $imgArticles = Article::where('article.status', 1)
  5520. ->where(function ($query) use ($parentCatId) {
  5521. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  5522. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  5523. })
  5524. ->where(function ($query) use ($website) {
  5525. $query->where(function ($subQuery) use ($website) {
  5526. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 1")
  5527. ->orWhereNull("ignore_ids");
  5528. });
  5529. })
  5530. ->where('imgurl', '!=', '')
  5531. ->leftJoin('website_category', function ($join) use ($website) {
  5532. $join->on('article.catid', '=', 'website_category.category_id')
  5533. ->where('website_category.website_id', '=', $website['website_id']);
  5534. })
  5535. ->select(
  5536. 'article.id',
  5537. 'article.title',
  5538. 'article.imgurl',
  5539. 'article.author',
  5540. 'article.updated_at',
  5541. 'article.introduce',
  5542. 'article.islink',
  5543. 'article.linkurl',
  5544. 'article.copyfrom',
  5545. 'article.cat_arr_id',
  5546. 'article.catid',
  5547. 'website_category.alias as category_name',
  5548. )
  5549. ->orderBy('updated_at', 'desc')
  5550. ->limit($parentImgNum)
  5551. ->get();
  5552. //调取封装路由的方法,处理新闻路由
  5553. if (!empty($imgArticles)) {
  5554. $imgArticles = $this->processArticles($imgArticles, $website);
  5555. }
  5556. }
  5557. // 查询文字新闻
  5558. if (isset($parentTextNum) && $parentTextNum != 0 && !empty($categroy)) {
  5559. $textArticles = [];
  5560. $textArticles = Article::where('article.status', 1)
  5561. ->where(function ($query) use ($parentCatId) {
  5562. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  5563. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  5564. })
  5565. ->where(function ($query) use ($website) {
  5566. $query->where(function ($subQuery) use ($website) {
  5567. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 1")
  5568. ->orWhereNull("ignore_ids");
  5569. });
  5570. })
  5571. ->leftJoin('website_category', function ($join) use ($website) {
  5572. $join->on('article.catid', '=', 'website_category.category_id')
  5573. ->where('website_category.website_id', '=', $website['website_id']);
  5574. })
  5575. ->select(
  5576. 'article.id',
  5577. 'article.title',
  5578. 'article.author',
  5579. 'article.updated_at',
  5580. 'article.cat_arr_id',
  5581. 'article.introduce',
  5582. 'article.islink',
  5583. 'article.linkurl',
  5584. 'article.copyfrom',
  5585. 'article.catid',
  5586. 'website_category.alias as category_name',
  5587. )
  5588. ->orderBy('updated_at', 'desc')
  5589. ->limit($parentTextNum)
  5590. ->get();
  5591. if (!empty($textArticles)) {
  5592. $textArticles = $this->processArticles($textArticles, $website);
  5593. }
  5594. }
  5595. }
  5596. $resultItem = [
  5597. 'alias' => $categroy ? $categroy->alias : null,
  5598. 'category_id' => $categroy ? $categroy->category_id : null,
  5599. 'pinyin' => $categroy ? $categroy->aLIas_pinyin : null,
  5600. 'imgnum' => $imgArticles ?? [],
  5601. 'textnum' => $textArticles ?? [],
  5602. ];
  5603. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  5604. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  5605. $childCategory = WebsiteCategory::where($website)
  5606. ->where("category_id", $childCatId)
  5607. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "') = 1")
  5608. ->first(['alias', 'category_id', 'aLIas_pinyin', 'pid', 'type', 'category_arr_id as cat_arr_id']);
  5609. if (!empty($childCategory)) {
  5610. $childCategory = $this->processArticles($childCategory, $website);
  5611. // 查询此层级的所有子栏目
  5612. $all_childcat = WebsiteCategory::where($website)
  5613. ->where("pid", $childCategory['pid'])
  5614. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "') = 1")
  5615. ->get(['alias', 'category_id', 'aLIas_pinyin', 'pid', 'type', 'category_arr_id as cat_arr_id']);
  5616. $all_childcat = $this->processArticles($all_childcat, $website);
  5617. // 查询子栏目图片新闻
  5618. if (isset($childImgNum) && $childImgNum != 0) {
  5619. $childImgArticles = Article::where('catid', $childCatId)
  5620. ->where('status', 1)
  5621. ->where(function ($query) use ($website) {
  5622. $query->where(function ($subQuery) use ($website) {
  5623. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 1");
  5624. })->orWhereNull("ignore_ids");
  5625. })
  5626. ->select(
  5627. 'article.id',
  5628. 'article.title',
  5629. 'article.imgurl',
  5630. 'article.author',
  5631. 'article.updated_at',
  5632. 'article.introduce',
  5633. 'article.islink',
  5634. 'article.linkurl',
  5635. 'article.catid',
  5636. 'article.cat_arr_id',
  5637. 'article.copyfrom',
  5638. )
  5639. ->where('imgurl', '!=', '')
  5640. ->orderBy('updated_at', 'desc')
  5641. ->limit($childImgNum)
  5642. ->get();
  5643. $childImgArticles = $this->processArticles($childImgArticles, $website);
  5644. }
  5645. // 查询子栏目文字新闻
  5646. if (isset($childTextNum) && $childTextNum != 0) {
  5647. $childTextArticles = Article::where('catid', $childCatId)
  5648. ->where('status', 1)
  5649. ->where(function ($query) use ($website) {
  5650. $query->where(function ($subQuery) use ($website) {
  5651. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 1");
  5652. })->orWhereNull("ignore_ids");
  5653. })
  5654. ->select(
  5655. 'article.id',
  5656. 'article.title',
  5657. 'article.author',
  5658. 'article.updated_at',
  5659. 'article.introduce',
  5660. 'article.islink',
  5661. 'article.linkurl',
  5662. 'article.catid',
  5663. 'article.cat_arr_id',
  5664. 'article.copyfrom',
  5665. )
  5666. ->orderBy('updated_at', 'desc')
  5667. ->limit($childTextNum)
  5668. ->get();
  5669. $childTextArticles = $this->processArticles($childTextArticles, $website);
  5670. }
  5671. }
  5672. $resultItem['child'] = [
  5673. 'alias' => $childCategory ? $childCategory->alias : null,
  5674. 'category_id' => $childCategory ? $childCategory->category_id : null,
  5675. 'type' => $childCategory ? $childCategory->type : null,
  5676. 'pinyin' => $childCategory ? $childCategory->pinyin : null,
  5677. 'all_childcat' => $all_childcat ?? [],
  5678. 'imgnum' => $childImgArticles ?? [],
  5679. 'textnum' => $childTextArticles ?? [],
  5680. ];
  5681. } else {
  5682. $resultItem['child'] = [];
  5683. }
  5684. return $resultItem;
  5685. }, $data);
  5686. return Result::success($result);
  5687. }
  5688. /**
  5689. * 企业管理
  5690. * @param array $data
  5691. * @return array
  5692. */
  5693. public function getCompanyList(array $data): array
  5694. {
  5695. // return Result::success($data);
  5696. $where = [];
  5697. $user = User::where('id', $data['user_id'])->first();
  5698. if(empty($user)){
  5699. return Result::error('用户不存在!');
  5700. }
  5701. if($user['type_id']!= 10000){
  5702. $where['user_id'] = $data['user_id'];
  5703. }
  5704. if(isset($data['title']) && !empty($data['title'])){
  5705. array_push($where, ['company.title', 'like', '%'. $data['title']. '%']);
  5706. }
  5707. if(isset($data['website_name']) && !empty($data['website_name'])){
  5708. array_push($where, ['website.website_name', 'like', '%'. $data['website_name']. '%']);
  5709. }
  5710. if(isset($data['ischeck']) && !empty($data['ischeck'])){
  5711. if($data['ischeck'] == 1){
  5712. if(isset($data['status']) && $data['status'] != ''){
  5713. array_push($where, ['company.status', $data['status']]);
  5714. $query = Company::where($where);
  5715. }else{
  5716. $query = Company::whereIn('company.status', [0,2]);
  5717. }
  5718. }else{
  5719. $query = Company::where('company.status', 1);
  5720. }
  5721. }
  5722. $result = $query->where($where)
  5723. ->leftJoin('website_category', function ($query) {
  5724. $query->on('website_category.category_id', '=', 'company.category_id')
  5725. ->on('website_category.website_id', '=', 'company.website_id');
  5726. })
  5727. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  5728. ->select(
  5729. 'company.id',
  5730. 'company.title',
  5731. 'company.website_id',
  5732. 'company.category_id',
  5733. 'website.website_name',
  5734. 'website_category.alias as category_name',
  5735. 'company.status',
  5736. 'company.updated_at',
  5737. )
  5738. ->orderBy('company.updated_at', 'desc')
  5739. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  5740. if($result->isEmpty()){
  5741. return Result::error("暂无企业", 0);
  5742. }
  5743. return Result::success($result);
  5744. }
  5745. /**
  5746. * 添加企业
  5747. * @param array $data
  5748. * @return array
  5749. */
  5750. public function addCompany(array $data): array
  5751. {
  5752. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  5753. if(isset($data['cat_arr_id']) &&!empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])){
  5754. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  5755. $data['cat_arr_id'] = json_encode($car_arr_id);
  5756. }else{
  5757. $data['cat_arr_id'] = '';
  5758. }
  5759. if ($data['imgurl'] == '') {
  5760. //content中提取图片第一个图,正则提取
  5761. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5762. preg_match_all($reg, $data['content'], $matches);
  5763. if (isset($matches[1][0])) {
  5764. //截取varchar240
  5765. $data['imgurl'] = substr($matches[1][0], 0, 240);
  5766. }
  5767. }
  5768. if ($data['keyword'] == '') {
  5769. //提取标题+内容中的关键词
  5770. $data['keyword'] = $data['title'];
  5771. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5772. Jieba::init(); // 初始化 jieba-php
  5773. Finalseg::init();
  5774. $segList = Jieba::cut($data['keyword']);
  5775. $segList1 = array_slice($segList, 0, 8);
  5776. $data['keyword'] = implode(',', $segList1);
  5777. }
  5778. if ($data['introduce'] == '' || empty($data['introduce'])) {
  5779. //提取内容中的描述
  5780. $data['introduce'] = mb_substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100) ?? '';
  5781. }
  5782. $user = User::where('id', $data['user_id'])->first();
  5783. if(empty($user)){
  5784. return Result::error('用户不存在!');
  5785. }
  5786. if($user['type_id']== 10000){
  5787. $data['status'] = 1;
  5788. }
  5789. if(isset($data['level']) && $data['level'] != null){
  5790. $data['level'] = intval($data['level']);
  5791. }else{
  5792. $data['level'] = null;
  5793. }
  5794. $result = Company::insertGetId($data);
  5795. if ($result) {
  5796. return Result::success($result);
  5797. } else {
  5798. return Result::error('添加失败');
  5799. }
  5800. }
  5801. /**
  5802. * 更新企业
  5803. * @param array $data
  5804. * @return array
  5805. */
  5806. public function upCompany(array $data): array
  5807. {
  5808. if(isset($data['cat_arr_id']) &&!empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])){
  5809. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  5810. $data['cat_arr_id'] = json_encode($car_arr_id);
  5811. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  5812. }else{
  5813. $data['cat_arr_id'] = '';
  5814. }
  5815. if ($data['imgurl'] == '') {
  5816. //content中提取图片第一个图,正则提取
  5817. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5818. preg_match_all($reg, $data['content'], $matches);
  5819. if (isset($matches[1][0])) {
  5820. //截取varchar
  5821. $data['imgurl'] = substr($matches[1][0], 0, 240);
  5822. }
  5823. }
  5824. if ($data['keyword'] == '') {
  5825. //提取标题+内容中的关键词
  5826. $data['keyword'] = $data['title'];
  5827. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5828. Jieba::init(); // 初始化 jieba-php
  5829. Finalseg::init();
  5830. $segList = Jieba::cut($data['keyword']);
  5831. $segList1 = array_slice($segList, 0, 8);
  5832. $data['keyword'] = implode(',', $segList1);
  5833. }
  5834. if ($data['introduce'] == '') {
  5835. //提取内容中的描述
  5836. // var_dump(11111);
  5837. $data['introduce'] = mb_substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  5838. }
  5839. if(isset($data['level']) && $data['level'] != null){
  5840. $data['level'] = intval($data['level']);
  5841. }else{
  5842. $data['level'] = null;
  5843. }
  5844. $user = User::where('id', $data['user_id'])->first();
  5845. if(empty($user)){
  5846. return Result::error('用户不存在!');
  5847. }
  5848. if($user['type_id']== 10000){
  5849. $data['status'] = 1;
  5850. }else{
  5851. $data['status'] = 0;
  5852. }
  5853. $result = Company::where('id', $data['id'])->update($data);
  5854. if ($result) {
  5855. return Result::success($result);
  5856. } else {
  5857. return Result::error('修改失败');
  5858. }
  5859. }
  5860. /**
  5861. * 删除企业
  5862. * @param array $data
  5863. * @return array
  5864. */
  5865. public function delCompany(array $data): array
  5866. {
  5867. $result = Company::where('id', $data['id'])->delete();
  5868. if ($result) {
  5869. return Result::success($result);
  5870. } else {
  5871. return Result::error('删除失败');
  5872. }
  5873. }
  5874. /**
  5875. * 审核企业
  5876. * @param array $data
  5877. * @return array
  5878. */
  5879. public function checkCompany(array $data): array
  5880. {
  5881. $user = User::where('id', $data['user_id'])->first();
  5882. if(empty($user)){
  5883. return Result::error('用户不存在!');
  5884. }
  5885. $company = Company::where('id', $data['id'])->first();
  5886. if(empty($company)){
  5887. return Result::error('企业不存在!');
  5888. }
  5889. // 状态:0:未审核 1:已审核 2:已拒绝
  5890. if($data['status'] == 2 || $data['status'] == '2'){
  5891. $result = Company::where('id', $data['id'])->update(['status' => $data['status'],'reject_reason'=> $data['reason']]);
  5892. }else{
  5893. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  5894. }
  5895. if(empty($result)){
  5896. return Result::error('审核失败!');
  5897. }else{
  5898. return Result::success($result);
  5899. }
  5900. }
  5901. /**
  5902. * 获取企业信息
  5903. * @param array $data
  5904. * @return array
  5905. */
  5906. public function getCompanyInfo(array $data): array
  5907. {
  5908. $result = Company::where('id', $data['id'])->first();
  5909. if(empty($result)){
  5910. return Result::error('企业不存在!');
  5911. }else{
  5912. return Result::success($result);
  5913. }
  5914. }
  5915. /**
  5916. * @param array $data
  5917. * @return array
  5918. */
  5919. public function getWebsiteCompany(array $data): array
  5920. {
  5921. $where['website_id'] = $data['website_id'];
  5922. $where['status'] = 1;
  5923. if(isset($data['category_id']) && !empty($data['category_id'])){
  5924. $where['category_id'] = $data['category_id'];
  5925. }
  5926. if(isset($data['level']) && !empty($data['level'])){
  5927. $where['level'] = $data['level'];
  5928. }
  5929. // return Result::success($where);
  5930. $query = Company::where($where);
  5931. $result['img'] = $this->processArticle(
  5932. $query->clone()
  5933. ->where('imgurl','!=', '')
  5934. ->whereNotNull('imgurl')
  5935. ->select('id','imgurl','title','introduce','description','content','category_id','cat_arr_id')
  5936. ->orderBy('updated_at', 'desc')
  5937. ->limit($data['imgnum'])
  5938. ->get(),
  5939. $data
  5940. );
  5941. $result['text'] = $this->processArticle(
  5942. $query->clone()
  5943. ->select('id','title','introduce','description','content','category_id','cat_arr_id')
  5944. ->orderBy('updated_at', 'desc')
  5945. ->limit($data['textnum'])
  5946. ->get(),
  5947. $data
  5948. );
  5949. if(empty($result)){
  5950. return Result::error("暂无相关公司信息", 0);
  5951. }
  5952. return Result::success($result);
  5953. }
  5954. /**
  5955. * @param array $data
  5956. * @return array
  5957. */
  5958. public function getWebsiteCompanyList(array $data): array
  5959. {
  5960. $where['website_id'] = $data['website_id'];
  5961. $where['status'] = 1;
  5962. if(isset($data['category_id']) && !empty($data['category_id'])){
  5963. $where['category_id'] = $data['category_id'];
  5964. }
  5965. if(isset($data['keyword']) && !empty($data['keyword'])){
  5966. array_push($where, ['title', 'like', '%' . $data['keyword'] . '%']);
  5967. }
  5968. $query = Company::where($where);
  5969. $company = $this->processArticle(
  5970. $query->select('id','title','introduce','description','content','category_id','cat_arr_id')
  5971. ->orderBy('updated_at', 'desc')
  5972. ->offset(($data['page'] - 1) * $data['pageSize'])
  5973. ->limit($data['pageSize'])
  5974. ->get(),
  5975. $data
  5976. );
  5977. if(empty($company)){
  5978. return Result::error("暂无相关公司信息", 0);
  5979. }
  5980. $result = [
  5981. 'count' => $query->clone()->count(),
  5982. 'data' => $company,
  5983. ];
  5984. return Result::success($result);
  5985. }
  5986. /**
  5987. * @param array $data
  5988. * @return array
  5989. */
  5990. public function getWebsiteCompanyInfo(array $data): array
  5991. {
  5992. $company = Company::where('id', $data['id'])
  5993. ->where('status', 1)
  5994. ->where('website_id', $data['website_id'])
  5995. ->select('company.*')
  5996. ->first();
  5997. if(empty($company)){
  5998. return Result::error("暂无相关公司信息", 0);
  5999. }
  6000. return Result::success($company);
  6001. }
  6002. }