NewsService.php 295 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. use App\Model\GroupMemberImp;
  65. use App\Model\GroupImp;
  66. use App\Model\GroupTalkImp;
  67. use App\Model\GroupTalkMessagerImp;
  68. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  69. class NewsService implements NewsServiceInterface
  70. {
  71. #[Inject]
  72. protected Redis $redis;
  73. /**
  74. * 获取导航池列表
  75. * @param array $data
  76. * @return array
  77. */
  78. public function getCategoryList(array $data): array
  79. {
  80. $search = $data['name'] ?? '';
  81. $page = (int)($data['page'] ?? 1);
  82. $perPage = (int)($data['pageSize'] ?? 10);
  83. // 1. 查出所有匹配的分类id
  84. if ($search) {
  85. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  86. if (empty($matchedIds)) {
  87. return Result::success(['rows' => [], 'total' => 0]);
  88. }
  89. // 2. 递归查所有父级,直到一级分类
  90. $idsStr = implode(',', $matchedIds);
  91. $sql = "
  92. WITH RECURSIVE parents AS (
  93. SELECT * FROM category WHERE id IN ($idsStr)
  94. UNION ALL
  95. SELECT c.* FROM category c
  96. INNER JOIN parents p ON c.id = p.pid
  97. )
  98. SELECT * FROM parents
  99. ";
  100. $parents = Db::select($sql);
  101. $parentIds = [];
  102. foreach ($parents as $row) {
  103. if ($row->pid == 0) {
  104. $parentIds[] = $row->id;
  105. }
  106. }
  107. $parentIds = array_unique($parentIds);
  108. } else {
  109. // 没有搜索,一级分类就是根
  110. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  111. }
  112. // 3. 一级分类分页
  113. $total = count($parentIds);
  114. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  115. if (empty($parentIds)) {
  116. return Result::success(['rows' => [], 'total' => $total]);
  117. }
  118. // 4. 递归查所有子孙
  119. $idsStr = implode(',', $parentIds);
  120. $sql = "
  121. WITH RECURSIVE subcategories AS (
  122. SELECT * FROM category WHERE id IN ($idsStr)
  123. UNION ALL
  124. SELECT c.* FROM category c
  125. INNER JOIN subcategories s ON c.pid = s.id
  126. )
  127. SELECT * FROM subcategories ORDER BY updated_at DESC
  128. ";
  129. $allCategories = Db::select($sql);
  130. // 5. 组装树结构
  131. $categoryMap = [];
  132. foreach ($allCategories as $cat) {
  133. $cat = (array)$cat;
  134. $cat['children'] = [];
  135. $categoryMap[$cat['id']] = $cat;
  136. }
  137. foreach ($categoryMap as $id => &$cat) {
  138. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  139. $categoryMap[$cat['pid']]['children'][] = &$cat;
  140. }
  141. }
  142. unset($cat);
  143. $categoryTree = [];
  144. foreach ($parentIds as $id) {
  145. if (isset($categoryMap[$id])) {
  146. $categoryTree[] = $categoryMap[$id];
  147. }
  148. }
  149. return Result::success([
  150. 'rows' => $categoryTree,
  151. 'total' => $total,
  152. ]);
  153. }
  154. private function findMatchedCategories($search)
  155. {
  156. if ($search) {
  157. return Category::where('name', 'like', "%{$search}%")
  158. ->orderBy('updated_at', 'desc')
  159. ->get();
  160. }
  161. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  162. ->get();
  163. }
  164. private function findAllParents($categories)
  165. {
  166. $allCategories = [];
  167. foreach ($categories as $category) {
  168. $parentId = $category->pid;
  169. while ($parentId > 0) {
  170. $parent = Category::find($parentId);
  171. if ($parent) {
  172. $allCategories[$parent->id] = $parent;
  173. $parentId = $parent->pid;
  174. } else {
  175. break;
  176. }
  177. }
  178. $allCategories[$category->id] = $category;
  179. }
  180. return array_values($allCategories);
  181. }
  182. private function buildCategoryTree($category, $allRequiredCategories)
  183. {
  184. $categoryData = $category->toArray();
  185. $children = [];
  186. foreach ($allRequiredCategories as $c) {
  187. if ($c->pid === $category->id) {
  188. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  189. }
  190. }
  191. if (!empty($children)) {
  192. $categoryData['children'] = $children;
  193. }
  194. return $categoryData;
  195. }
  196. public function myCategoryList(array $data): array
  197. {
  198. $sszq = $data['sszq'] ?? '';
  199. unset($data['sszq']);
  200. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  201. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  202. $where[] = [
  203. 'pid',
  204. '=',
  205. $data['pid'],
  206. ];
  207. if (isset($data['name'])) {
  208. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  209. }
  210. var_dump($where);
  211. //根据分类id,从category表中取出分类信息
  212. $result = Category::where($where)
  213. ->whereIn('category.id', $catorytids)
  214. ->select('category.*', 'category.id as category_id')->get();
  215. if (empty($result)) {
  216. return Result::error("没有栏目数据");
  217. }
  218. return Result::success($result);
  219. }
  220. /**
  221. * @param array $data
  222. * @return array
  223. */
  224. public function categoryList(array $data): array
  225. {
  226. $where[] = [
  227. 'pid',
  228. '=',
  229. $data['pid']
  230. ];
  231. if (isset($data['name'])) {
  232. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  233. }
  234. var_dump($where);
  235. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  236. if (empty($result)) {
  237. return Result::error("没有栏目数据");
  238. }
  239. return Result::success($result);
  240. }
  241. /**
  242. * @param array $data
  243. * @return array
  244. */
  245. public function addCategory(array $data): array
  246. {
  247. if (isset($data['id'])) {
  248. unset($data['id']);
  249. }
  250. $id = Category::insertGetId($data);
  251. if (empty($id)) {
  252. return Result::error("添加失败");
  253. }
  254. return Result::success(['id' => $id]);
  255. }
  256. /**
  257. * @param array $data
  258. * @return array
  259. */
  260. public function delCategory(array $data): array
  261. {
  262. Db::beginTransaction();
  263. try {
  264. $categoryList = Category::where(['pid' => $data['id']])->get();
  265. if ($categoryList->toArray()) {
  266. Db::rollBack();
  267. return Result::error("分类下面有子分类不能删除");
  268. }
  269. $articleList = Article::where(['catid' => $data['id']])->get();
  270. if ($articleList->toArray()) {
  271. Db::rollBack();
  272. return Result::error("分类下面有资讯不能删除");
  273. }
  274. $result = Category::where($data)->delete();
  275. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  276. if (!$result) {
  277. Db::rollBack();
  278. return Result::error("删除失败");
  279. }
  280. Db::commit();
  281. return Result::success($result);
  282. } catch (\Exception $e) {
  283. Db::rollBack();
  284. return Result::error("删除失败" . $e->getMessage());
  285. }
  286. }
  287. /**
  288. * @param array $data
  289. * @return array
  290. */
  291. public function updateCategory(array $data): array
  292. {
  293. $where = [
  294. 'id' => $data['id'],
  295. ];
  296. $result = Category::where($where)->update($data);
  297. if ($result) {
  298. return Result::success($result);
  299. } else {
  300. return Result::error("更新失败");
  301. }
  302. }
  303. /**
  304. * 获取导航池信息
  305. * @param array $data
  306. * @return array
  307. */
  308. public function getCategoryInfo(array $data): array
  309. {
  310. $where = [
  311. 'id' => $data['id'],
  312. ];
  313. $result = Category::where($where)->first();
  314. if ($result) {
  315. return Result::success($result);
  316. } else {
  317. return Result::error("更新失败");
  318. }
  319. }
  320. public function getArticleCommend(array $data): array
  321. {
  322. $where = [
  323. 'website_id' => $data['website_id'],
  324. ];
  325. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  326. var_dump($ids);
  327. if (empty($ids)) {
  328. return Result::error("没有推荐数据");
  329. }
  330. //id
  331. $whereArticle = [];
  332. if (isset($data['id'])) {
  333. $whereArticle['id'] = $data['id'];
  334. }
  335. //title like
  336. if (isset($data['title'])) {
  337. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  338. }
  339. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  340. ->where($whereArticle)
  341. ->orderBy('id', 'desc')
  342. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  343. if ($article) {
  344. $data = [
  345. 'rows' => $article->items(),
  346. 'count' => $article->total(),
  347. ];
  348. return Result::success($data);
  349. } else {
  350. return Result::error("获取失败失败");
  351. }
  352. }
  353. /**
  354. * @param array $data
  355. * @return array
  356. */
  357. public function getArticleList(array $data): array
  358. {
  359. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  360. $type_id = $data['type_id'];
  361. unset($data['type_id']);
  362. $user_id = $data['user_id'];
  363. unset($data['user_id']);
  364. $where = [];
  365. $status1 = [];
  366. if (isset($data['id']) && $data['id']) {
  367. array_push($where, ['article.id', '=', $data['id']]);
  368. }
  369. if (isset($data['title']) && $data['title']) {
  370. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  371. }
  372. if (isset($data['category_name']) && $data['category_name']) {
  373. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  374. }
  375. if (isset($data['catid']) && $data['catid']) {
  376. array_push($where, ['article.catid', '=', $data['catid']]);
  377. }
  378. if (isset($data['author']) && $data['author']) {
  379. array_push($where, ['article.author', '=', $data['author']]);
  380. }
  381. if (isset($data['islink']) && $data['islink'] !== "") {
  382. array_push($where, ['article.islink', '=', $data['islink']]);
  383. }
  384. if (isset($data['status']) && $data['status'] !== "") {
  385. array_push($where, ['article.status', '=', $data['status']]);
  386. }
  387. if (isset($data['status1'])) {
  388. $status1 = json_decode(($data['status1']));
  389. }
  390. //不是管理员展示个人数据;
  391. if ($type_id != 10000) {
  392. $where[] = ['article.admin_user_id', '=', $user_id];
  393. }
  394. $startTime = microtime(true);
  395. $rep = Article::query()
  396. // 预加载相关关联
  397. ->with([
  398. 'category' => function ($query) {
  399. $query->select('id', 'name');
  400. },
  401. 'websiteCategory' => function ($query) {
  402. $query->select('website_id', 'category_id', 'alias');
  403. }
  404. ])
  405. // 构建where条件
  406. ->when(isset($data['id']) && $data['id'], function ($query) use ($data) {
  407. $query->where('article.id', '=', $data['id']);
  408. })
  409. ->when(isset($data['title']) && $data['title'], function ($query) use ($data) {
  410. $query->where('article.title', 'like', '%' . $data['title'] . '%');
  411. })
  412. ->when(isset($data['category_name']) && $data['category_name'], function ($query) use ($data) {
  413. // 使用子查询替代左连接进行模糊搜索
  414. $query->whereHas('category', function ($subQuery) use ($data) {
  415. $subQuery->where('name', 'like', '%' . $data['category_name'] . '%');
  416. });
  417. })
  418. ->when(isset($data['catid']) && $data['catid'], function ($query) use ($data) {
  419. $query->where('article.catid', '=', $data['catid']);
  420. })
  421. ->when(isset($data['author']) && $data['author'], function ($query) use ($data) {
  422. $query->where('article.author', '=', $data['author']);
  423. })
  424. ->when(isset($data['islink']) && $data['islink'] !== "", function ($query) use ($data) {
  425. $query->where('article.islink', '=', $data['islink']);
  426. })
  427. ->when(isset($data['status']) && $data['status'] !== "", function ($query) use ($data) {
  428. $query->where('article.status', '=', $data['status']);
  429. })
  430. ->when(isset($data['status1']) && $data['status1'], function ($query) use ($data) {
  431. // 安全地处理JSON字符串
  432. $status1 = is_array($data['status1']) ? $data['status1'] : json_decode($data['status1'], true) ?? [];
  433. if (!empty($status1)) {
  434. $query->whereIn('article.status', $status1);
  435. }
  436. })
  437. // 非管理员限制
  438. ->when($type_id != 10000, function ($query) use ($user_id) {
  439. $query->where('article.admin_user_id', '=', $user_id);
  440. })
  441. // 基础条件
  442. ->whereNotIn('article.status', [404])
  443. // 排序和分页
  444. ->orderBy('article.updated_at', 'desc')
  445. ->paginate($data['pageSize'], ["article.*"]);
  446. // 获取结果并格式化
  447. $data = [
  448. 'rows' => $rep->items(),
  449. 'count' => $rep->total(),
  450. ];
  451. // 执行查询
  452. $endTime = microtime(true);
  453. $executionTime = ($endTime - $startTime) * 1000;
  454. echo "查询执行时间: {$executionTime}ms\n";
  455. return Result::success($data);
  456. }
  457. /**
  458. * @param array $data
  459. * @return array
  460. */
  461. public function addArticle(array $data): array
  462. {
  463. var_dump($data, '----------12-----------1');
  464. unset($data['user_type']);
  465. unset($data['nav_add_pool_id']);
  466. // unset($data['commend_id']);
  467. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  468. Db::beginTransaction();
  469. try {
  470. //处理投票
  471. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  472. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  473. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  474. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  475. unset($data['is_survey']);
  476. unset($data['survey_name']);
  477. unset($data['suvey_array']);
  478. // unset($data['website_id']);
  479. // unset($data['web_site_id']);
  480. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  481. if ($data['hits'] == '') {
  482. $data['hits'] = 0;
  483. }
  484. if ($data['is_original'] == '') {
  485. $data['is_original'] = 0;
  486. }
  487. if ($data['status'] == '') {
  488. $data['status'] = 0;
  489. }
  490. $articleData = $data;
  491. unset($articleData['content']);
  492. //自动处理缩略图、关键字、描述
  493. if ($articleData['imgurl'] == '') {
  494. //如果没有图,设置level=0
  495. $levelArr = json_decode($articleData['level'], true);
  496. var_dump($levelArr, '----------levelArr-----------1');
  497. //content中提取图片第一个图,正则提取
  498. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  499. preg_match_all($reg, $data['content'], $matches);
  500. if (isset($matches[1][0])) {
  501. //截取varchar240
  502. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  503. //如果有图,设置level=3
  504. if (!in_array(3, $levelArr)) {
  505. $levelArr[] = 3;
  506. }
  507. $articleData['level'] = json_encode($levelArr);
  508. } else {
  509. if (!in_array(0, $levelArr)) {
  510. $levelArr[] = 0;
  511. }
  512. $articleData['level'] = json_encode($levelArr);
  513. }
  514. }
  515. var_dump($articleData['level'], '----------$articleData[level]----------1');
  516. if ($articleData['keyword'] == '') {
  517. //提取标题+内容中的关键词
  518. $articleData['keyword'] = $data['title'];
  519. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  520. Jieba::init(); // 初始化 jieba-php
  521. Finalseg::init();
  522. $segList = Jieba::cut($articleData['keyword']);
  523. $segList1 = array_slice($segList, 0, 8);
  524. $articleData['keyword'] = implode(',', $segList1);
  525. }
  526. if ($articleData['introduce'] == '') {
  527. //提取内容中的描述
  528. $content = $data['content'];
  529. // 去除 <style> 和 <script> 标签及其内容
  530. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  531. // 去除所有 HTML 标签
  532. $content = strip_tags($content);
  533. // 去除 HTML 实体
  534. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  535. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  536. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  537. // 去除多余空白
  538. $content = preg_replace('/\s+/u', '', $content);
  539. // 截取 100 个字符
  540. $articleData['introduce'] = mb_substr($content, 0, 100);
  541. }
  542. if ($articleData['status'] == 0) {
  543. $this->sendMessage([
  544. 'talk_type' => 100,
  545. 'title' => $articleData['title'],
  546. 'content' => '提交了审核',
  547. 'messageType' => 2,
  548. ]);
  549. }
  550. $id = Article::insertGetId($articleData);
  551. $articleDataContent = [
  552. 'article_id' => $id,
  553. 'content' => $data['content'],
  554. ];
  555. ArticleData::insertGetId($articleDataContent);
  556. //处理投票
  557. if ($is_survey == 1) {
  558. //生成年月日时分秒+8位随机数
  559. $uuid = date('YmdHis') . rand(10000000, 99999999);
  560. var_dump($suvey_array, 'suvey_array________');
  561. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  562. var_dump($suveys_array, '---------------------1');
  563. var_dump($suvey_array, '---------------------2');
  564. $suvey_data = [];
  565. foreach ($suveys_array as $key => $value) {
  566. if ($value == '') {
  567. continue;
  568. }
  569. if (is_array($value)) {
  570. $suvey_data[] = [
  571. 'sur_id' => $uuid,
  572. 'art_id' => $id,
  573. 'website_id' => $website_id ?? 2,
  574. 'survey_name' => $survey_name,
  575. 'choice_name' => $value[1],
  576. 'is_other' => 1,
  577. 'other_id' => 0,
  578. 'results' => 0,
  579. ];
  580. } else {
  581. $suvey_data[] = [
  582. 'sur_id' => $uuid,
  583. 'art_id' => $id,
  584. 'website_id' => $website_id ?? 2,
  585. 'survey_name' => $survey_name,
  586. 'choice_name' => $value,
  587. 'is_other' => 0,
  588. 'other_id' => 0,
  589. 'results' => 0,
  590. ];
  591. }
  592. if (empty($suvey_data)) {
  593. throw new \Exception("投票数据为空");
  594. }
  595. }
  596. $result = ArticleSurvey::insert($suvey_data);
  597. if (!$result) {
  598. throw new \Exception("投票失败,ArticleSurvey插入失败");
  599. }
  600. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  601. if (!$result) {
  602. throw new \Exception("投票失败,更新主表失败");
  603. }
  604. }
  605. Db::commit();
  606. return Result::success(['id' => $id]);
  607. } catch (\Throwable $ex) {
  608. Db::rollBack();
  609. var_dump($ex->getMessage());
  610. return Result::error("创建失败", 0);
  611. }
  612. }
  613. /**
  614. * @param array $data
  615. * @return array
  616. */
  617. public function delArticle(array $data): array
  618. {
  619. $result = Article::where($data)->delete();
  620. //survey投票删除
  621. articleSurvey::where(['art_id' => $data['id']])->delete();
  622. if (!$result) {
  623. return Result::error("删除失败");
  624. }
  625. return Result::success($result);
  626. }
  627. /**
  628. * @param array $data
  629. * @return array
  630. */
  631. public function updateArticle(array $data): array
  632. {
  633. var_dump($data, '----------12-----------1');
  634. Db::beginTransaction();
  635. unset($data['user_type']);
  636. // unset($data['web_site_id']);
  637. unset($data['nav_add_pool_id']);
  638. try {
  639. //处理投票
  640. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  641. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  642. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  643. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  644. unset($data['is_survey']);
  645. unset($data['survey_name']);
  646. unset($data['suvey_array']);
  647. unset($data['website_id']);
  648. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  649. if ($data['hits'] == '') {
  650. $data['hits'] = 0;
  651. }
  652. if ($data['is_original'] == '') {
  653. $data['is_original'] = 0;
  654. }
  655. if ($data['status'] == '') {
  656. $data['status'] = 0;
  657. }
  658. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  659. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  660. $articleData = $data;
  661. unset($articleData['content']);
  662. unset($articleData['status_name']);
  663. unset($articleData['name']);
  664. unset($articleData['content']);
  665. unset($articleData['pid_arr']);
  666. unset($articleData['pid']);
  667. //自动处理缩略图、关键字、描述
  668. if ($articleData['imgurl'] == '') {
  669. //如果没有图,设置level=0
  670. $levelArr = json_decode($articleData['level'], true);
  671. var_dump($levelArr, '----------levelArr-----------1');
  672. //content中提取图片第一个图,正则提取
  673. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  674. preg_match_all($reg, $data['content'], $matches);
  675. if (isset($matches[1][0])) {
  676. //截取varchar240
  677. // 截取到第一个<
  678. $articleData['imgurl'] = $matches[1][0];
  679. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  680. $pos = strpos($articleData['imgurl'], '"');
  681. if ($pos !== false) {
  682. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  683. }
  684. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  685. //如果有图,设置level=3
  686. if (!in_array(3, $levelArr)) {
  687. $levelArr[] = 3;
  688. }
  689. $articleData['level'] = json_encode($levelArr);
  690. } else {
  691. if (!in_array(0, $levelArr)) {
  692. $levelArr[] = 0;
  693. }
  694. $articleData['level'] = json_encode($levelArr);
  695. }
  696. }
  697. var_dump($articleData['level'], '----------$articleData[level]----------1');
  698. if ($articleData['keyword'] == '') {
  699. //提取标题+内容中的关键词
  700. $articleData['keyword'] = $data['title'];
  701. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  702. Jieba::init(); // 初始化 jieba-php
  703. Finalseg::init();
  704. $segList = Jieba::cut($articleData['keyword']);
  705. $segList1 = array_slice($segList, 0, 8);
  706. $articleData['keyword'] = implode(',', $segList1);
  707. }
  708. if ($articleData['introduce'] == '') {
  709. //提取内容中的描述
  710. $content = $data['content'];
  711. // 去除 <style> 和 <script> 标签及其内容
  712. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  713. // 去除所有 HTML 标签
  714. $content = strip_tags($content);
  715. // 去除 HTML 实体
  716. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  717. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  718. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  719. // 去除多余空白
  720. $content = preg_replace('/\s+/u', '', $content);
  721. // 截取 100 个字符
  722. $articleData['introduce'] = mb_substr($content, 0, 100);
  723. }
  724. if ($articleData['status'] == 0) {
  725. $this->sendMessage([
  726. 'talk_type' => 100,
  727. 'title' => $articleData['title'],
  728. 'content' => '提交了审核',
  729. 'messageType' => 2,
  730. ]);
  731. }
  732. $id = Article::where(['id' => $data['id']])->update($articleData);
  733. $articleDataContent = [
  734. 'content' => $data['content'],
  735. ];
  736. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  737. //处理投票
  738. $id = $data['id'];
  739. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  740. var_dump($suvey_array, 'suvey_array________delete');
  741. //处理投票
  742. if ($is_survey == 1) {
  743. //生成年月日时分秒+8位随机数
  744. $uuid = date('YmdHis') . rand(10000000, 99999999);
  745. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  746. var_dump($suveys_array, '---------------------1');
  747. $suvey_data = [];
  748. if (is_array($suveys_array)) {
  749. foreach ($suveys_array as $key => $value) {
  750. if ($value == '') {
  751. continue;
  752. }
  753. if (is_array($value)) {
  754. $suvey_data[] = [
  755. 'sur_id' => $uuid,
  756. 'art_id' => $id,
  757. 'website_id' => $website_id ?? 2,
  758. 'survey_name' => $survey_name,
  759. 'choice_name' => $value[1],
  760. 'is_other' => 1,
  761. 'other_id' => 0,
  762. 'results' => 0,
  763. ];
  764. } else {
  765. $suvey_data[] = [
  766. 'sur_id' => $uuid,
  767. 'art_id' => $id,
  768. 'website_id' => $website_id ?? 2,
  769. 'survey_name' => $survey_name,
  770. 'choice_name' => $value,
  771. 'is_other' => 0,
  772. 'other_id' => 0,
  773. 'results' => 0,
  774. ];
  775. }
  776. if (empty($suvey_data)) {
  777. throw new \Exception("投票数据为空");
  778. }
  779. }
  780. }
  781. $result = ArticleSurvey::insert($suvey_data);
  782. if (!$result) {
  783. throw new \Exception("投票失败");
  784. }
  785. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  786. if (!$result) {
  787. throw new \Exception("投票失败");
  788. }
  789. } else {
  790. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  791. }
  792. Db::commit();
  793. return Result::success([]);
  794. } catch (\Throwable $ex) {
  795. Db::rollBack();
  796. var_dump($ex->getMessage());
  797. return Result::error("更新失败" . $ex->getMessage(), 0);
  798. }
  799. }
  800. /**
  801. * 更新资讯状态
  802. * @param array $data
  803. * @return array
  804. */
  805. public function upArticleStatus(array $data): array
  806. {
  807. $articleData = Article::where(['id' => $data['id']])->first();
  808. //发送10次
  809. // for ($i = 0; $i < 10; $i++) {
  810. // $this->sendMessage([
  811. // 'talk_type' => 100,
  812. // 'title' => $i . $articleData['title'],
  813. // 'content' => '审核通过',
  814. // 'messageType' => 2,
  815. // 'user_id' => $articleData['admin_user_id'],
  816. // ]);
  817. // }
  818. // var_dump($data['status'], 'status');
  819. // return Result::success();
  820. if ($data['status'] == 1) {
  821. $this->sendMessage([
  822. 'talk_type' => 101,
  823. 'title' => $articleData['title'],
  824. 'content' => '审核通过',
  825. 'messageType' => 2,
  826. 'user_id' => $articleData['admin_user_id'],
  827. ]);
  828. }
  829. if ($data['status'] == 2) {
  830. $this->sendMessage([
  831. 'talk_type' => 101,
  832. 'title' => $articleData['title'],
  833. 'content' => '审核拒绝',
  834. 'messageType' => 2,
  835. 'user_id' => $articleData['admin_user_id'],
  836. ]);
  837. }
  838. if ($data['status'] == 0) {
  839. $this->sendMessage([
  840. 'talk_type' => 100,
  841. 'title' => $articleData['title'],
  842. 'content' => '提交了审核',
  843. 'messageType' => 2,
  844. ]);
  845. }
  846. $result = Article::where(['id' => $data['id']])->update($data);
  847. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  848. //article_ignore 表插入数据 db操作
  849. //转成数组
  850. //删掉数据重新写入
  851. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  852. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  853. $insert_data = [];
  854. foreach ($website_ids as $key => $value) {
  855. $insert_data[] = [
  856. 'article_id' => $data['id'],
  857. 'website_id' => $value,
  858. ];
  859. }
  860. DB::table('article_ignore')->insert($insert_data);
  861. }
  862. if ($result) {
  863. return Result::success();
  864. } else {
  865. return Result::error("更新状态失败", 0);
  866. }
  867. }
  868. /**
  869. * 获取新闻详情
  870. * @param array $data
  871. * @return array
  872. */
  873. public function getArticleInfo(array $data): array
  874. {
  875. $where = [
  876. 'article.id' => $data['id'],
  877. // 'article.status' => 1,
  878. ];
  879. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  880. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  881. $info = $result;
  882. // var_dump($info, 'info');
  883. $info['survey_array'] = $articleSurvey;
  884. if ($result) {
  885. return Result::success($info);
  886. } else {
  887. return Result::error("查询失败", 0);
  888. }
  889. }
  890. /**
  891. * 获取头条新闻
  892. * @param array $data
  893. * @return array
  894. */
  895. public function getWebsiteArticlett(array $data): array
  896. {
  897. $website_id = $data['website_id'];
  898. $website = Website::where('id', $data['website_id'])->first();
  899. if (empty($website)) {
  900. return Result::error("网站不存在", 0);
  901. }
  902. $categorys = $this->processArticlePro($website_id);
  903. $catiall = $categorys['catiall'];
  904. $categoryIds = $categorys['categoryIds'];
  905. $where = [
  906. 'status' => 1
  907. ];
  908. // $website_column = $website['column'];
  909. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  910. $website_column = json_decode($website['website_column_arr_id'], true);
  911. }
  912. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  913. // return Result::success($diff_pid_categoryIds);
  914. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  915. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  916. }
  917. // $website_id = $data['website_id'];
  918. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  919. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  920. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  921. switch ($data['level']) {
  922. case 1:
  923. case 2:
  924. case 3:
  925. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  926. $query = Article::where($where)
  927. ->where('level', 'like', '%' . $data['level'] . '%')
  928. ->orderBy('updated_at', 'desc');
  929. break;
  930. case 4: //最新资讯
  931. $query = Article::where($where)->orderBy('updated_at', 'desc');
  932. break;
  933. case 5: //资讯推荐
  934. $query = Article::where($where)
  935. ->where('updated_at', '>', $month);
  936. break;
  937. case 7: //资讯分类
  938. if (isset($data['id']) && !empty($data['id'])) {
  939. $keyword = Article::where('id', $data['id'])->value('keyword');
  940. $keywordArray = explode(',', $keyword);
  941. $whereL7 = [];
  942. foreach ($keywordArray as $k => $v) {
  943. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  944. }
  945. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  946. break;
  947. } else {
  948. return Result::error("请输入资讯ID", 0);
  949. break;
  950. }
  951. default:
  952. break;
  953. }
  954. // $whereL7 = [];
  955. // if(isset($data['id']) && !empty($data['id'])){
  956. // $keyword = Article::where('id', $data['id'])->value('keyword');
  957. // $keywordArray = explode(',', $keyword);
  958. // foreach ($keywordArray as $k => $v) {
  959. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  960. // }
  961. // }
  962. // $query = Article::where($where)
  963. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  964. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  965. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  966. // }
  967. // if($data['level'] == 7){
  968. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  969. // }
  970. // if($data['level'] == 4){
  971. // $query = $query->inRandomOrder()
  972. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  973. // }
  974. // if($data['level'] == 5){
  975. // $query = $query->orderBy('updated_at','desc');
  976. // }
  977. // });
  978. if ($data['textnum'] > 0) {
  979. $query = clone $query;
  980. $result['text'] = $query
  981. ->whereIn('catid', $categoryIds)
  982. ->leftJoinSub(function ($query) use ($website_id) {
  983. $query->from('article_ignore')
  984. ->where('website_id', $website_id);
  985. }, 'article_ignore', function ($join) {
  986. $join->on('article_ignore.article_id', '=', 'article.id');
  987. })
  988. ->where(function ($query) use ($website_id) {
  989. $query->whereNull('article_ignore.article_id')
  990. ->orWhere('article_ignore.website_id', '!=', $website_id);
  991. })
  992. ->select(
  993. 'article.id',
  994. 'article.title',
  995. 'article.author',
  996. 'article.updated_at',
  997. 'article.introduce',
  998. 'article.islink',
  999. 'article.linkurl',
  1000. 'article.copyfrom',
  1001. 'article.cat_arr_id',
  1002. 'article.catid',
  1003. 'article.level'
  1004. )
  1005. ->offset($data['placeid'])
  1006. ->limit($data['textnum'])
  1007. ->get()->all();
  1008. foreach ($result['text'] as $k => $v) {
  1009. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1010. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1011. }
  1012. }
  1013. if ($data['imgnum'] > 0) {
  1014. $query = clone $query;
  1015. $result['img'] = $query
  1016. ->whereIn('catid', $categoryIds)
  1017. ->where('article.imgurl', '!=', '')
  1018. ->select(
  1019. 'article.id',
  1020. 'article.title',
  1021. 'article.imgurl',
  1022. 'article.author',
  1023. 'article.updated_at',
  1024. 'article.introduce',
  1025. 'article.islink',
  1026. 'article.linkurl',
  1027. 'article.copyfrom',
  1028. 'article.cat_arr_id',
  1029. 'article.catid',
  1030. 'article.level'
  1031. )
  1032. ->offset($data['placeid'])
  1033. ->limit($data['imgnum'])
  1034. ->get()->all();
  1035. foreach ($result['img'] as $k => $v) {
  1036. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1037. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1038. }
  1039. }
  1040. if (empty($result)) {
  1041. return Result::error("暂无相关资讯", 0);
  1042. }
  1043. return Result::success($result);
  1044. }
  1045. /**
  1046. * 获取模块新闻
  1047. * @param array $data
  1048. * @return array
  1049. */
  1050. public function getWebsiteModelArticles(array $data): array
  1051. {
  1052. $catid = $data['catid'];
  1053. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1054. $category = $category->toArray();
  1055. if (!empty($category)) {
  1056. $where = [
  1057. 'status' => 1,
  1058. 'catid' => $catid,
  1059. ];
  1060. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1061. // 1:文字新闻;2:轮播图;3:图文;
  1062. // 级别:0:未分类
  1063. // 3:推荐图片
  1064. if ($data['level'] == 1) {
  1065. $data['level'] = 0;
  1066. }
  1067. $result = Article::where($where)
  1068. ->where(function ($query) use ($data) {
  1069. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1070. ->orWhereNull("level")
  1071. ->orWhereRaw("level = '[]'");
  1072. })
  1073. ->where(function ($query) use ($data) {
  1074. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1075. ->orWhereNull("ignore_ids");
  1076. })
  1077. ->orderBy("updated_at", "desc")
  1078. ->offset($placeid)
  1079. ->limit($data['pagesize'])
  1080. ->get();
  1081. if (empty($result)) {
  1082. return Result::error("此栏目暂无相关新闻", 0);
  1083. }
  1084. } else {
  1085. return Result::error("此网站暂无此栏目", 0);
  1086. }
  1087. return Result::success($result);
  1088. }
  1089. /**
  1090. *获取新闻列表
  1091. * @param array $data
  1092. * @return array
  1093. */
  1094. public function getWebsiteArticleList(array $data): array
  1095. {
  1096. // return Result::success($data);
  1097. $where[] = ['status', '=', 1];
  1098. $website_id = $data['website_id'];
  1099. $website = Website::where('id', $data['website_id'])->first();
  1100. if (empty($website)) {
  1101. return Result::error("网站不存在", 0);
  1102. }
  1103. // $website_column = $website['column'];
  1104. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1105. $website_column = json_decode($website['website_column_arr_id'], true);
  1106. }
  1107. $categorys = $this->processArticlePro($website_id);
  1108. $cat_1st_arr = $categorys['cat_1st_arr'];
  1109. $catiall = $categorys['catiall'];
  1110. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1111. // return Result::success($diff_pid_categoryIds);
  1112. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1113. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1114. }
  1115. if (isset($data['catid']) && !empty($data['catid'])) {
  1116. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1117. if (empty($category)) {
  1118. return Result::error("此网站暂无此栏目", 0);
  1119. }
  1120. array_push($where, ['catid', '=', $data['catid']]);
  1121. }
  1122. // return Result::success($where);
  1123. $query = Article::where($where)
  1124. ->leftJoinSub(function ($query) use ($website_id) {
  1125. $query->from('article_ignore')
  1126. ->where('website_id', $website_id);
  1127. }, 'article_ignore', function ($join) {
  1128. $join->on('article_ignore.article_id', '=', 'article.id');
  1129. })
  1130. ->where(function ($query) use ($website_id) {
  1131. $query->whereNull('article_ignore.article_id')
  1132. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1133. })
  1134. ->select(
  1135. 'article.id',
  1136. 'article.title',
  1137. 'article.imgurl',
  1138. 'article.author',
  1139. 'article.updated_at',
  1140. 'article.introduce',
  1141. 'article.islink',
  1142. 'article.linkurl',
  1143. 'article.copyfrom',
  1144. 'article.cat_arr_id',
  1145. 'article.catid'
  1146. );
  1147. $count = $query->count();
  1148. $rep = $query->orderBy("updated_at", "desc")
  1149. ->offset(($data['page'] - 1) * $data['pageSize'])
  1150. ->limit($data['pageSize'])
  1151. ->get()->all();
  1152. $categorys = $this->processArticlePro($website_id);
  1153. $cat_1st_arr = $categorys['cat_1st_arr'];
  1154. $catiall = $categorys['catiall'];
  1155. // $web['website_id'] = $data['website_id'];
  1156. foreach ($rep as $k => $v) {
  1157. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1158. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1159. }
  1160. // $rep = $this->processArticles($rep,$web);
  1161. $data = [
  1162. 'rows' => $rep,
  1163. 'count' => $count,
  1164. ];
  1165. if (empty($rep)) {
  1166. return Result::error("没有信息数据");
  1167. }
  1168. return Result::success($data);
  1169. }
  1170. /**
  1171. * 前端-获取新闻详情
  1172. * @param array $data
  1173. * @return array
  1174. */
  1175. public function selectWebsiteArticleInfo(array $data): array
  1176. {
  1177. $where = [
  1178. 'article.id' => $data['id'],
  1179. 'article.status' => 1,
  1180. ];
  1181. $result = Article::where($where)
  1182. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1183. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1184. ->where(function ($query) use ($data) {
  1185. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1186. ->orWhereNull("ignore_ids");
  1187. })
  1188. ->select(
  1189. 'article.*',
  1190. 'article_data.content',
  1191. 'article_data.article_id',
  1192. 'article_extend.website_url',
  1193. 'article_extend.email',
  1194. 'article_extend.contacts',
  1195. 'article_extend.contacts_mobile',
  1196. 'article_extend.contacts_address',
  1197. 'article_extend.zip_code',
  1198. 'article_extend.enterprise_name'
  1199. )
  1200. ->first();
  1201. if (empty($result)) {
  1202. return Result::error("暂无此新闻!", 0);
  1203. }
  1204. if (!empty($result['publiced_at'])) {
  1205. $result['updated_at'] = $result['publiced_at'];
  1206. }
  1207. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1208. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1209. ->where('website_category.website_id', $data['website_id'])
  1210. ->where(['website_category.category_id' => $result['catid']])
  1211. ->first();
  1212. if (empty($category)) {
  1213. return Result::error("查询失败", 0);
  1214. }
  1215. //手动推荐文章
  1216. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1217. if (empty($commend_ids)) {
  1218. $commendArticle = [];
  1219. } else {
  1220. //去除不存在的文章ID
  1221. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1222. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1223. ->where('article.status', 1)
  1224. ->where('website_category.website_id', $data['website_id'])
  1225. ->select('article.id', 'article.cat_arr_id', 'article.title', 'article.catid', 'article.imgurl', 'article.hits', 'article.created_at', 'website_category.alias', 'website_category.alias_pinyin', 'website_category.website_id')
  1226. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1227. // ->orderBy('article.updated_at', 'desc')
  1228. ->limit(5)
  1229. ->get();
  1230. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1231. foreach ($commendArticle as $k => $v) {
  1232. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1233. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1234. $cat_arr_id = array_unique($cat_arr_id);
  1235. // 从website_category取出alias_pinyin
  1236. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1237. ->whereIn('category_id', $cat_arr_id)
  1238. ->pluck('alias_pinyin', 'category_id')
  1239. ->toArray();
  1240. // 将cat_arr_id的json转成路径/隔开
  1241. $path_parts = [];
  1242. foreach ($cat_arr_id as $cat_id) {
  1243. if (isset($cat_arr[$cat_id])) {
  1244. $path_parts[] = $cat_arr[$cat_id];
  1245. }
  1246. }
  1247. $v->alias_pinyin = implode('/', $path_parts);
  1248. } else {
  1249. $v->alias_pinyin = '';
  1250. }
  1251. }
  1252. }
  1253. $result['category_id'] = $category['category_id'];
  1254. $result['cat_name'] = $category['alias'];
  1255. $result['website_name'] = $category['website_name'] ?? "";
  1256. $result['suffix'] = $category['suffix'] ?? "";
  1257. $result['commendArticle'] = $commendArticle;
  1258. $result['commend_ids'] = $commend_ids;
  1259. return Result::success($result);
  1260. }
  1261. /**
  1262. * 前端-获取网站调查问卷
  1263. * @param array $data
  1264. * @return array
  1265. */
  1266. public function getWebsiteSurvey(array $data): array
  1267. {
  1268. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1269. $website = Website::where('id', $data['website_id'])->first();
  1270. if (empty($website)) {
  1271. return Result::error("暂无此网站", 0);
  1272. }
  1273. }
  1274. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1275. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1276. if (empty($article)) {
  1277. return Result::error("暂无此文章", 0);
  1278. }
  1279. // return Result::error($data,0);
  1280. $where['art_id'] = $data['art_id'];
  1281. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1282. } else {
  1283. $survey = Article::where(function ($query) {
  1284. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1285. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1286. })
  1287. ->where('status', 1)
  1288. ->where('is_survey', 1)
  1289. ->select('survey_id')
  1290. ->orderBy('updated_at', 'desc')
  1291. ->first();
  1292. if (empty($survey)) {
  1293. return Result::error("暂无调查问卷", 0);
  1294. }
  1295. $where['sur_id'] = $survey['survey_id'];
  1296. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1297. }
  1298. // return Result::success($where);
  1299. $result = ArticleSurvey::where($where)
  1300. ->where(function ($query) {
  1301. $query->where('is_other', 0)
  1302. ->orWhere(function ($subQuery) {
  1303. $subQuery->where('is_other', 1)
  1304. ->where('other_id', 0);
  1305. });
  1306. })
  1307. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1308. ->select('article_survey.*', 'article.survey_type')
  1309. ->get()->all();
  1310. if (empty($result)) {
  1311. return Result::error("此文章暂无调查问卷", 0);
  1312. }
  1313. return Result::success($result);
  1314. }
  1315. /**
  1316. * 前端-添加网站调查问卷选项
  1317. * @param array $data
  1318. * @return array
  1319. */
  1320. public function addWebsiteSurveyOption(array $data): array
  1321. {
  1322. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1323. $website = Website::where('id', $data['website_id'])->first();
  1324. if (empty($website)) {
  1325. return Result::error("暂无此网站", 0);
  1326. }
  1327. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1328. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1329. if (empty($survey)) {
  1330. return Result::error("此调查问卷不可添加选项", 0);
  1331. }
  1332. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1333. $choice = [
  1334. 'art_id' => $survey['art_id'],
  1335. 'website_id' => $data['website_id'],
  1336. 'survey_name' => $survey['survey_name'],
  1337. 'choice_name' => $data['choice_name'],
  1338. 'sur_id' => $survey['sur_id'],
  1339. 'is_other' => 1,
  1340. 'other_id' => $survey['id'],
  1341. ];
  1342. $result = ArticleSurvey::insertGetId($choice);
  1343. if (empty($result)) {
  1344. return Result::error("添加失败", 0);
  1345. }
  1346. return Result::success($result);
  1347. }
  1348. }
  1349. return Result::error("添加失败", 0);
  1350. }
  1351. return Result::error("添加失败", 0);
  1352. }
  1353. /**
  1354. * 前端-调查问卷投票
  1355. * @param array $data
  1356. * @return array
  1357. */
  1358. public function addWebsiteSurveyVote(array $data): array
  1359. {
  1360. // return Result::success($data);
  1361. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1362. $website = Website::where('id', $data['website_id'])->first();
  1363. if (empty($website)) {
  1364. return Result::error("暂无此网站", 0);
  1365. }
  1366. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1367. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1368. // return Result::success($survey);
  1369. if (empty($is_survey)) {
  1370. return Result::error("此调查问卷不存在", 0);
  1371. }
  1372. // return Result::success($survey);
  1373. // 调查问卷类型
  1374. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1375. //多选 若是json型则转化成数组类型
  1376. if (strpos($data['choice_id'], '[') === 0) {
  1377. $data['choice_id'] = json_decode($data['choice_id'], true);
  1378. } else {
  1379. // 单选 也转换成数组
  1380. $data['choice_id'] = [$data['choice_id']];
  1381. }
  1382. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1383. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1384. // ->where('website_id',$data['website_id'])
  1385. ->where('is_other', 1)
  1386. ->where('other_id', 0)
  1387. ->first();
  1388. if (!empty($other)) {
  1389. return Result::error("请选择已有的选项!", 0);
  1390. }
  1391. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1392. // ->where('website_id',$data['website_id'])
  1393. ->where('is_other', 1)
  1394. ->where('other_id', '!=', 0)
  1395. ->first();
  1396. // return Result::success($choice['other']);
  1397. $choice_id = $data['choice_id'];
  1398. if (!empty($choice['other'])) {
  1399. // array_push($data['choice_id'],$choice['other']['other_id']);
  1400. if (!empty($choice_id)) {
  1401. $key = array_search($choice['other']['id'], $choice_id);
  1402. if ($key !== false) {
  1403. unset($choice_id[$key]);
  1404. $choice_id = array_values($choice_id);
  1405. }
  1406. array_push($choice_id, $choice['other']['other_id']);
  1407. } else {
  1408. $choice_id[0] = $choice['other']['other_id'];
  1409. }
  1410. array_push($data['choice_id'], $choice['other']['other_id']);
  1411. }
  1412. // return Result::success($data);
  1413. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1414. // ->where('website_id',$data['website_id'])
  1415. ->increment('results', 1);
  1416. if (empty($choice)) {
  1417. return Result::error("请选择已有的选项!", 0);
  1418. }
  1419. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1420. // ->where('website_id',$data['website_id'])
  1421. ->where('other_id', 0)
  1422. ->get();
  1423. $survey['choice'] = $choice_id;
  1424. return Result::success($survey);
  1425. }
  1426. return Result::error("参数必填!");
  1427. }
  1428. return Result::error("此调查问卷不存在", 0);
  1429. }
  1430. return Result::error("参数必填!");
  1431. }
  1432. /**
  1433. * 后端-获取网站调查问卷列表
  1434. * @param array $data
  1435. * @return array
  1436. */
  1437. public function getSurveyList(array $data): array
  1438. {
  1439. $where = [];
  1440. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1441. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1442. }
  1443. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1444. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1445. }
  1446. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1447. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1448. }
  1449. // return Result::success($where);
  1450. if (!empty($where)) {
  1451. $query = Article::where($where)->where(function ($q) {
  1452. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1453. });
  1454. } else {
  1455. $query = Article::where(function ($q) {
  1456. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1457. });
  1458. }
  1459. $count = $query->count();
  1460. $survey = $query->orderByDesc('id')
  1461. ->limit($data['pageSize'])
  1462. ->offset(($data['page'] - 1) * $data['pageSize'])
  1463. ->get();
  1464. if (empty($survey->toArray())) {
  1465. return Result::error("暂无调查问卷!", 0);
  1466. }
  1467. $result = [
  1468. 'rows' => $survey,
  1469. 'count' => $count,
  1470. ];
  1471. return Result::success($result);
  1472. }
  1473. /**
  1474. * 后端-获取网站调查问卷详情
  1475. * @param array $data
  1476. * @return array
  1477. */
  1478. public function getSurveyInfo(array $data): array
  1479. {
  1480. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1481. $where = ['sur_id' => $data['sur_id']];
  1482. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1483. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1484. ->select('article_survey.*', 'article.survey_type')
  1485. ->get()->all();
  1486. if (empty($choose)) {
  1487. return Result::error("此调查问卷不存在", 0);
  1488. }
  1489. $resultsArray = array_column($choose, 'results');
  1490. $total = array_sum($resultsArray);
  1491. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1492. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1493. // $total = 0;
  1494. if (!empty($other)) {
  1495. $total = $total + $other['results'];
  1496. $other['choice_name'] = '(其他)';
  1497. if (!empty($others)) {
  1498. $other['hasChildren'] = true;
  1499. // array_push($other,['hasChildren','=',true]);
  1500. $other['children'] = $others;
  1501. $other_choices = [$other->toArray()];
  1502. $mer_choice = array_merge($choose, $other_choices);
  1503. $value_choice = array_values($mer_choice);
  1504. } else {
  1505. // return Result::error('1111');
  1506. $other_choices = [$other->toArray()];
  1507. $other_choices = array_merge($choose, $other_choices);
  1508. $value_choice = array_values($other_choices);
  1509. // return Result::success($result);
  1510. }
  1511. } else {
  1512. $value_choice = $choose;
  1513. }
  1514. $result = [
  1515. 'choose' => $value_choice,
  1516. 'total' => $total,
  1517. ];
  1518. }
  1519. return Result::success($result);
  1520. }
  1521. /**
  1522. * 前端-搜索新闻列表
  1523. * @param array $data
  1524. * @return array
  1525. */
  1526. public function selectWebsiteArticle(array $data): array
  1527. {
  1528. $website = Website::where('id', $data['website_id'])->first();
  1529. if (empty($website)) {
  1530. return Result::error("网站不存在", 0);
  1531. }
  1532. // $website_column = $website['column'];
  1533. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1534. $website_column = json_decode($website['website_column_arr_id'], true);
  1535. }
  1536. $website_id = $data['website_id'];
  1537. $categorys = $this->processArticlePro($website_id);
  1538. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1539. // return Result::success($diff_pid_categoryIds);
  1540. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1541. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1542. }
  1543. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1544. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1545. $catiall = $categorys['catiall'];
  1546. $categoryIds = $categorys['categoryIds'];
  1547. // return Result::success($categoryIds);
  1548. $query = Article::where('status', 1)
  1549. ->whereIn('catid', $categoryIds)
  1550. ->leftJoinSub(function ($query) use ($website_id) {
  1551. $query->from('article_ignore')
  1552. ->where('website_id', $website_id);
  1553. }, 'article_ignore', function ($join) {
  1554. $join->on('article_ignore.article_id', '=', 'article.id');
  1555. })
  1556. ->where(function ($query) use ($website_id) {
  1557. $query->whereNull('article_ignore.article_id')
  1558. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1559. });
  1560. // ->get()->all();
  1561. // return Result::success($query);
  1562. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1563. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1564. }
  1565. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1566. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1567. }
  1568. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1569. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1570. }
  1571. // 计算总数
  1572. $count = $query->count();
  1573. // return Result::success($count);
  1574. // 分页查询
  1575. $articles = $query
  1576. ->select(
  1577. 'article.id',
  1578. 'article.title',
  1579. 'article.imgurl',
  1580. 'article.author',
  1581. 'article.updated_at',
  1582. 'article.introduce',
  1583. 'article.islink',
  1584. 'article.linkurl',
  1585. 'article.copyfrom',
  1586. 'article.cat_arr_id',
  1587. 'article.catid',
  1588. 'article.department_arr_id',
  1589. 'article.city_arr_id',
  1590. )
  1591. ->orderBy("updated_at", "desc")
  1592. ->offset(($data['page'] - 1) * $data['pageSize'])
  1593. ->limit($data['pageSize'])
  1594. ->get();
  1595. // return Result::success($articles);
  1596. foreach ($articles as $k => $v) {
  1597. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1598. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1599. }
  1600. if (empty($articles)) {
  1601. return Result::error("没有符合条件的资讯数据");
  1602. }
  1603. $result = [
  1604. 'rows' => $articles,
  1605. 'count' => $count,
  1606. ];
  1607. return Result::success($result);
  1608. }
  1609. /**
  1610. * 模块新闻加强版
  1611. * @param array $data
  1612. * @return array
  1613. */
  1614. public function getWebsiteCatidArticle(array $data): array
  1615. {
  1616. $where = [
  1617. 'website_category.category_id' => $data['catid'],
  1618. 'website_category.website_id' => $data['website_id'],
  1619. ];
  1620. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1621. $child_catnum = $data['child_catnum'] ?? 1;
  1622. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1623. $childCategoryIds = array_column($category['child'], 'category_id');
  1624. if (empty($childCategoryIds)) {
  1625. return Result::error("暂无子栏目", 0);
  1626. }
  1627. $imgArticles = [];
  1628. $textArticles = [];
  1629. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1630. // 初始化子分类图片新闻和文字新闻数组
  1631. // 查询所有子级栏目的图文新闻
  1632. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1633. ->where(function ($query) use ($data) {
  1634. $query->where(function ($subQuery) use ($data) {
  1635. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1636. })->orWhereNull("ignore_ids");
  1637. })
  1638. ->where('status', 1)
  1639. ->where('imgurl', '!=', '')
  1640. ->select('*')
  1641. ->orderBy('updated_at', 'desc')
  1642. ->limit($data['child_imgnum'])
  1643. ->get();
  1644. }
  1645. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1646. // 查询所有子级栏目的文字新闻
  1647. $textArticles = Article::where('catid', $childCategoryIds[0])
  1648. ->where('status', 1)
  1649. ->where(function ($query) use ($data) {
  1650. $query->where(function ($subQuery) use ($data) {
  1651. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1652. })->orWhereNull("ignore_ids");
  1653. })
  1654. ->select('*')
  1655. ->orderBy('updated_at', 'desc')
  1656. ->limit($data['child_textnum'])
  1657. ->get();
  1658. }
  1659. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1660. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1661. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1662. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1663. return $child;
  1664. }, $category['child']);
  1665. }
  1666. // }
  1667. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1668. $category['img'] = WebsiteCategory::where($where)
  1669. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1670. ->where('article.status', 1)
  1671. ->where('article.imgurl', '!=', '')
  1672. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1673. ->orderBy('article.updated_at', 'desc')
  1674. ->limit($data['img_num'])
  1675. ->get();
  1676. }
  1677. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1678. $category['text'] = WebsiteCategory::where($where)
  1679. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1680. ->where('article.status', 1)
  1681. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1682. ->orderBy('article.updated_at', 'desc')
  1683. ->limit($data['text_num'])
  1684. ->get();
  1685. }
  1686. // $category = $category->get();
  1687. if (empty($category)) {
  1688. return Result::error("查询失败", 0);
  1689. }
  1690. return Result::success($category);
  1691. }
  1692. /**
  1693. * 模块新闻加强plus版
  1694. * @param array $data
  1695. * @return array
  1696. */
  1697. public function getWebsiteAllArticle(array $data): array
  1698. {
  1699. // return Result::success($data);
  1700. $time1 = microtime(true);
  1701. $wetbsite_id = $data['website_id'] ?? 2;
  1702. $data = json_decode($data['id'], true);
  1703. $website = Website::where('id', $wetbsite_id)->first();
  1704. if (empty($website)) {
  1705. return Result::error("网站不存在", 0);
  1706. }
  1707. // return Result::success($website);
  1708. $website_column = $website['website_column_arr_id'] ?? '[]';
  1709. $website_column = json_decode($website_column, true);
  1710. $categorys = $this->processArticlePro($wetbsite_id);
  1711. $cat_1st_arr = $categorys['cat_1st_arr'];
  1712. $catiall = $categorys['catiall'];
  1713. // return Result::success($catiall);
  1714. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1715. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1716. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1717. }
  1718. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1719. // return Result::success($categorys);
  1720. $parent_category = array_column($data, 'parent');
  1721. $parent_cat = [];
  1722. $child_category = array_column($data, 'child');
  1723. if (!empty($parent_category)) {
  1724. foreach ($parent_category as $key => $value) {
  1725. $arr = array_map('intval', explode(',', $value));
  1726. $parent_cat[$key] = $arr[0] ?? 0;
  1727. $parent_category = $arr[0] ?? 0;
  1728. $article_imgnum = $arr[1] ?? 0;
  1729. $article_textnum = $arr[2] ?? 0;
  1730. if ($parent_category != 0) {
  1731. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1732. // return Result::success($category_arr);
  1733. if ($article_imgnum != 0) {
  1734. $img_article = Article::whereIn('catid', $category_arr)
  1735. ->where('status', 1)
  1736. ->where('imgurl', '!=', '')
  1737. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1738. $query->from('article_ignore')
  1739. ->where('website_id', $wetbsite_id);
  1740. }, 'article_ignore', function ($join) {
  1741. $join->on('article_ignore.article_id', '=', 'article.id');
  1742. })
  1743. ->where(function ($query) use ($wetbsite_id) {
  1744. $query->whereNull('article_ignore.article_id')
  1745. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1746. })
  1747. ->select('article.id', 'article.title', 'article.imgurl', 'article.author', 'article.updated_at', 'article.introduce', 'article.islink', 'article.linkurl', 'article.copyfrom', 'article.cat_arr_id', 'article.catid')
  1748. ->orderBy('updated_at', 'desc')
  1749. ->limit($article_imgnum)
  1750. ->get()->all();
  1751. foreach ($img_article as $k => $v) {
  1752. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1753. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1754. }
  1755. } else {
  1756. $img_article = [];
  1757. }
  1758. if ($article_textnum != 0) {
  1759. $text_article = Article::whereIn('catid', $category_arr)
  1760. ->where('status', 1)
  1761. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1762. $query->from('article_ignore')
  1763. ->where('website_id', $wetbsite_id);
  1764. }, 'article_ignore', function ($join) {
  1765. $join->on('article_ignore.article_id', '=', 'article.id');
  1766. })
  1767. ->where(function ($query) use ($wetbsite_id) {
  1768. $query->whereNull('article_ignore.article_id')
  1769. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1770. })
  1771. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1772. ->orderBy('updated_at', 'desc')
  1773. ->limit($article_textnum)
  1774. ->get()->all();
  1775. foreach ($text_article as $k => $v) {
  1776. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1777. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1778. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1779. }
  1780. } else {
  1781. $text_article = [];
  1782. }
  1783. $catiall[$parent_category]['imgnum'] = $img_article;
  1784. $catiall[$parent_category]['textnum'] = $text_article;
  1785. $parent[$key] = $catiall[$parent_category];
  1786. } else {
  1787. $parent[$key] = '';
  1788. }
  1789. }
  1790. }
  1791. if (!empty($child_category)) {
  1792. foreach ($child_category as $key => $value) {
  1793. $arr = array_map('intval', explode(',', $value));
  1794. $parent_category = $parent_cat[$key];
  1795. $child_category = $arr[0] ?? 0;
  1796. $article_imgnum = $arr[1] ?? 0;
  1797. $article_textnum = $arr[2] ?? 0;
  1798. if ($child_category != 0) {
  1799. $all_childcat = $cat_1st_arr[$parent_category];
  1800. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1801. // 从 $websiteInfoIndexed 中获取对应的数据
  1802. $info = $websiteInfoIndexed[$v];
  1803. // 返回一个包含所需信息的数组
  1804. return [
  1805. 'alias' => $info->alias,
  1806. 'category_id' => $info->category_id,
  1807. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1808. 'pid' => $info->pid,
  1809. 'type' => $info->type,
  1810. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1811. 'pinyin' => $info->pinyin,
  1812. ];
  1813. }, $all_childcat);
  1814. if ($article_imgnum != 0) {
  1815. $img_article = Article::where('catid', $child_category)
  1816. ->where('status', 1)
  1817. ->where('imgurl', '!=', '')
  1818. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1819. $query->from('article_ignore')
  1820. ->where('website_id', $wetbsite_id);
  1821. }, 'article_ignore', function ($join) {
  1822. $join->on('article_ignore.article_id', '=', 'article.id');
  1823. })
  1824. ->where(function ($query) use ($wetbsite_id) {
  1825. $query->whereNull('article_ignore.article_id')
  1826. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1827. })
  1828. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1829. ->orderBy('updated_at', 'desc')
  1830. ->limit($article_imgnum)
  1831. ->get()->all();
  1832. foreach ($img_article as $k => $v) {
  1833. // var_dump($v);
  1834. // var_dump($k);
  1835. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1836. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1837. }
  1838. } else {
  1839. $img_article = [];
  1840. }
  1841. if ($article_textnum != 0) {
  1842. $text_article = Article::where('catid', $child_category)
  1843. ->where('status', 1)
  1844. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1845. $query->from('article_ignore')
  1846. ->where('website_id', $wetbsite_id);
  1847. }, 'article_ignore', function ($join) {
  1848. $join->on('article_ignore.article_id', '=', 'article.id');
  1849. })
  1850. ->where(function ($query) use ($wetbsite_id) {
  1851. $query->whereNull('article_ignore.article_id')
  1852. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1853. })
  1854. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1855. ->orderBy('updated_at', 'desc')
  1856. ->limit($article_textnum)
  1857. ->get()->all();
  1858. foreach ($text_article as $k => $v) {
  1859. // var_dump($v);
  1860. // var_dump($k);
  1861. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1862. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1863. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1864. }
  1865. } else {
  1866. $text_article = [];
  1867. }
  1868. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1869. $catiall[$child_category]['imgnum'] = $img_article;
  1870. $catiall[$child_category]['textnum'] = $text_article;
  1871. $child[$key] = $catiall[$child_category];
  1872. // var_dump($pids);
  1873. } else {
  1874. $child[$key] = '';
  1875. }
  1876. }
  1877. }
  1878. foreach ($parent as $key => $value) {
  1879. $result[$key] = $value;
  1880. if (!empty($child[$key])) {
  1881. // var_dump($child[$key]);
  1882. $result[$key]['child'] = $child[$key];
  1883. // $value[$key]['child'] = $child[$key];
  1884. } else {
  1885. $result[$key]['child'] = [
  1886. "alias" => null,
  1887. "category_id" => null,
  1888. "type" => null,
  1889. "pinyin" => null,
  1890. "all_childcat" => [],
  1891. "imgnum" => [],
  1892. "textnum" => []
  1893. ];
  1894. }
  1895. }
  1896. return Result::success($result);
  1897. }
  1898. /**
  1899. * 辅助方法:获取文章列表
  1900. */
  1901. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1902. {
  1903. sleep(1);
  1904. $query = Article::where('article.status', 1)
  1905. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1906. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1907. ->where(function ($query) use ($website) {
  1908. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1909. })
  1910. ->leftJoin('website_category', function ($join) use ($website) {
  1911. $join->on('article.catid', '=', 'website_category.category_id')
  1912. ->where('website_category.website_id', '=', $website['website_id']);
  1913. })
  1914. ->select(
  1915. 'article.id',
  1916. 'article.title',
  1917. 'article.imgurl',
  1918. 'article.author',
  1919. 'article.updated_at',
  1920. 'article.introduce',
  1921. 'article.islink',
  1922. 'article.linkurl',
  1923. 'article.copyfrom',
  1924. 'article.cat_arr_id',
  1925. 'article.catid',
  1926. 'website_category.alias as category_name'
  1927. )
  1928. ->orderBy('updated_at', 'desc')
  1929. ->limit($limit);
  1930. // 如果是图片文章,添加图片URL条件
  1931. if ($isImageArticle) {
  1932. $query->where('imgurl', '!=', '');
  1933. } else {
  1934. // 文字文章不需要imgurl字段
  1935. $query->addSelect('article.introduce');
  1936. }
  1937. $articles = $query->get();
  1938. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1939. }
  1940. /**
  1941. * 乡村网-获取特殊新闻模块
  1942. * @param array $data
  1943. * @return array
  1944. */
  1945. public function getWebsiteArticles(array $data): array
  1946. {
  1947. $website_id = $data['website_id'];
  1948. $website = Website::where('id', $website_id)->first();
  1949. if (empty($website)) {
  1950. return Result::error("网站不存在", 0);
  1951. }
  1952. // return Result::success($website);
  1953. $website_column = $website['website_column_arr_id'] ?? '[]';
  1954. $website_column = json_decode($website_column, true);
  1955. $catids = json_decode($data['id'], true);
  1956. $parent_category = array_column($catids, 'parent');
  1957. if (!empty($parent_category) && is_array($parent_category)) {
  1958. $categorys = $this->processArticlePro($website_id);
  1959. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1960. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1961. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1962. }
  1963. $catiall = $categorys['catiall'];
  1964. $cat_1st_arr = $categorys['cat_1st_arr'];
  1965. // return Result::success($categorys);
  1966. foreach ($parent_category as $key => $value) {
  1967. $arr = array_map('intval', explode(',', $value));
  1968. $parent_category = $arr[0] ?? 0;
  1969. $article_imgnum = $arr[1] ?? 0;
  1970. $article_textnum = $arr[2] ?? 0;
  1971. if ($parent_category != 0) {
  1972. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1973. // return Result::success($category_arr);
  1974. if ($article_imgnum != 0) {
  1975. $img_article = Article::whereIn('catid', $category_arr)
  1976. ->where('status', 1)
  1977. ->where('imgurl', '!=', '')
  1978. ->leftJoinSub(function ($query) use ($website_id) {
  1979. $query->from('article_ignore')
  1980. ->where('website_id', $website_id);
  1981. }, 'article_ignore', function ($join) {
  1982. $join->on('article_ignore.article_id', '=', 'article.id');
  1983. })
  1984. ->where(function ($query) use ($website_id) {
  1985. $query->whereNull('article_ignore.article_id')
  1986. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1987. })
  1988. ->select(
  1989. 'id',
  1990. 'title',
  1991. 'imgurl',
  1992. 'author',
  1993. 'updated_at',
  1994. 'introduce',
  1995. 'islink',
  1996. 'linkurl',
  1997. 'copyfrom',
  1998. 'cat_arr_id',
  1999. 'catid as category_id'
  2000. )
  2001. ->orderBy('updated_at', 'desc')
  2002. ->limit($article_imgnum)
  2003. ->get()->all();
  2004. foreach ($img_article as $k => $v) {
  2005. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2006. // return Result::success($v);
  2007. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2008. }
  2009. } else {
  2010. $img_article = [];
  2011. }
  2012. if ($article_textnum != 0) {
  2013. $text_article = Article::whereIn('catid', $category_arr)
  2014. ->where('status', 1)
  2015. ->leftJoinSub(function ($query) use ($website_id) {
  2016. $query->from('article_ignore')
  2017. ->where('website_id', $website_id);
  2018. }, 'article_ignore', function ($join) {
  2019. $join->on('article_ignore.article_id', '=', 'article.id');
  2020. })
  2021. ->where(function ($query) use ($website_id) {
  2022. $query->whereNull('article_ignore.article_id')
  2023. ->orWhere('article_ignore.website_id', '!=', $website_id);
  2024. })
  2025. ->select(
  2026. 'id',
  2027. 'title',
  2028. 'author',
  2029. 'updated_at',
  2030. 'introduce',
  2031. 'islink',
  2032. 'linkurl',
  2033. 'copyfrom',
  2034. 'cat_arr_id',
  2035. 'catid as category_id'
  2036. )
  2037. ->orderBy('updated_at', 'desc')
  2038. ->limit($article_textnum)
  2039. ->get()->all();
  2040. foreach ($text_article as $k => $v) {
  2041. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2042. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2043. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2044. }
  2045. } else {
  2046. $text_article = [];
  2047. }
  2048. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2049. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2050. $parent[$key] = $catiall[$parent_category];
  2051. } else {
  2052. $parent[$key] = [];
  2053. }
  2054. }
  2055. }
  2056. return Result::success($parent);
  2057. }
  2058. // 封装处理商品的路由问题
  2059. function processGoods($goods, $data)
  2060. {
  2061. return $goods->map(function ($good) use ($data) {
  2062. $catid = $good->catid ?? 0;
  2063. // $pinyin = '';
  2064. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2065. if (!empty($category->pid) && $category->pid != 0) {
  2066. $level = json_decode($category->category_arr_id, true);
  2067. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2068. ->whereIn('category_id', $level)
  2069. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2070. ->get(['aLIas_pinyin'])
  2071. ->pluck('aLIas_pinyin')
  2072. ->implode('/');
  2073. } else {
  2074. $pinyin = $category->aLIas_pinyin ?? '';
  2075. }
  2076. if (isset($good->city_id) && !empty($good->city_id)) {
  2077. $city = District::where('id', $good->city_id)->first(['name']);
  2078. $good->city_name = $city->name ?? '';
  2079. }
  2080. // 解析imgurl JSON并取第一条数据
  2081. $imgUrls = json_decode($good->imgurl, true);
  2082. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2083. $good->pinyin = $pinyin;
  2084. return $good;
  2085. });
  2086. }
  2087. /**
  2088. * 获取商城首页-根据栏目id
  2089. * @param array $data
  2090. * @return array
  2091. * */
  2092. function getWebsiteCatidshop(array $data): array
  2093. {
  2094. $input['catid'] = $data['catid'];
  2095. $input['website_id'] = $data['website_id'];
  2096. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2097. $result = array_map(function ($item) use ($input) {
  2098. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2099. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2100. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2101. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2102. if (empty($category) || $category->type != 2) {
  2103. return Result::error("暂无此栏目", 0);
  2104. } else {
  2105. $website['website_id'] = $input['website_id'];
  2106. $goods = Good::where('good.status', 2)
  2107. ->where('good.website_id', $website['website_id'])
  2108. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2109. ->select(
  2110. 'good.id',
  2111. 'good.name',
  2112. 'good.imgurl',
  2113. 'good.description',
  2114. 'good.updated_at',
  2115. 'good.catid',
  2116. 'good.type_id',
  2117. 'good.price',
  2118. 'good.com',
  2119. 'good.level',
  2120. 'good.unit'
  2121. )
  2122. ->orderBy('updated_at', 'desc')
  2123. ->offset($goodStart)
  2124. ->limit($goodNum);
  2125. $all_goods = $goods->get();
  2126. $all_goods = $this->processGoods($all_goods, $website);
  2127. }
  2128. return $all_goods ?? [];
  2129. }
  2130. }, $data);
  2131. return Result::success($result);
  2132. }
  2133. /**
  2134. * 获取商品模块
  2135. * @param array $data
  2136. * @return array
  2137. * */
  2138. public function getWebsiteshop(array $data): array
  2139. {
  2140. $input['id'] = $data['id'];
  2141. $input['website_id'] = $data['website_id'];
  2142. $catid = $data['catid'];
  2143. $data = json_decode($input['id'] ?? '', true) ?? [];
  2144. $result['goods'] = array_map(function ($item) use ($input) {
  2145. // 检查parent元素是否存在且不是undefined
  2146. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2147. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2148. $website = $input['website_id'];
  2149. $query = Good::where('good.status', 2)
  2150. ->where('good.website_id', $website);
  2151. switch ($Levelid) {
  2152. case 1:
  2153. case 2:
  2154. case 3:
  2155. $goods = $query->where(function ($q) use ($Levelid) {
  2156. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2157. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2158. });
  2159. break;
  2160. case 4:
  2161. $goods = $query;
  2162. break;
  2163. case 5:
  2164. $goods = $query->where('type_id', 1);
  2165. break;
  2166. case 6:
  2167. $goods = $query->where('type_id', 2);
  2168. break;
  2169. default:
  2170. return [];
  2171. }
  2172. $all_goods = $goods
  2173. ->select(
  2174. 'good.id',
  2175. 'good.name',
  2176. 'good.imgurl',
  2177. 'good.description',
  2178. 'good.updated_at',
  2179. 'good.catid',
  2180. 'good.type_id',
  2181. 'good.price',
  2182. 'good.level',
  2183. 'good.website_id'
  2184. )
  2185. ->orderBy('updated_at', 'desc')
  2186. ->offset($goodStart)
  2187. ->limit($goodNum)
  2188. ->get();
  2189. $web['website_id'] = $website;
  2190. $all_goods = $this->processGoods($all_goods, $web);
  2191. }
  2192. return $all_goods;
  2193. }, $data);
  2194. $website = $input['website_id'];
  2195. $result['article'] = Article::where(function ($query) use ($website) {
  2196. $query->where(function ($subQuery) use ($website) {
  2197. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2198. })->orWhereNull("ignore_ids");
  2199. })
  2200. ->where('catid', $catid)
  2201. ->where('article.status', 1)
  2202. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2203. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2204. ->orderBy('article.updated_at', 'desc')
  2205. ->first();
  2206. return Result::success($result);
  2207. }
  2208. /**
  2209. * 获取商品分类
  2210. * @param array $data
  2211. * @return array
  2212. * */
  2213. public function getWebsiteshopCat(array $data): array
  2214. {
  2215. $website = $data['website_id'];
  2216. $category = WebsiteCategory::where('website_id', $website)
  2217. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2218. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2219. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2220. ->orderBy('sort')
  2221. ->get();
  2222. $cat = $category->map(function ($item) use ($website) {
  2223. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2224. $pid = $item->pid ?? 0;
  2225. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2226. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2227. ->where('website_id', $website)
  2228. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2229. ->get(['aLIas_pinyin'])
  2230. ->pluck('aLIas_pinyin')
  2231. ->implode('/');
  2232. } else {
  2233. $pinyin = $item->aLIas_pinyin ?? '';
  2234. }
  2235. $item->pinyin = $pinyin;
  2236. });
  2237. if (empty($category)) {
  2238. return Result::error("栏目查询失败", 0);
  2239. }
  2240. $cat_tree = Result::buildMenuTree($category);
  2241. $web['website_id'] = $website;
  2242. $goods = Good::where('website_id', $website)
  2243. ->where('status', 2)
  2244. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2245. ->latest('updated_at')
  2246. ->offset(($data['page'] - 1) * $data['pageSize'])
  2247. ->limit($data['pageSize'])
  2248. ->get();
  2249. if (!empty($goods)) {
  2250. if ($goods->count() > 1 && !empty($goods)) {
  2251. $goods = $this->processGoods($goods, $web);
  2252. }
  2253. } else {
  2254. $goods = [];
  2255. }
  2256. $result = [
  2257. 'category' => $cat_tree,
  2258. 'goods' => $goods,
  2259. ];
  2260. // $resul['goods'] = $goods;
  2261. if (empty($result)) {
  2262. return Result::error("查询失败", 0);
  2263. }
  2264. return Result::success($result);
  2265. }
  2266. /*
  2267. * 获取商品列表
  2268. * @param array $data
  2269. * @return array
  2270. * */
  2271. public function getWebsiteshopList(array $data): array
  2272. {
  2273. // return Result::success($data);
  2274. $where = [
  2275. 'status' => 2,
  2276. 'website_id' => $data['website_id'],
  2277. ];
  2278. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2279. // return Result::error("查询失败", 0);
  2280. // }
  2281. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2282. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2283. $data['catid'] = $category->category_id ?? 0;
  2284. }
  2285. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2286. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2287. }
  2288. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2289. array_push($where, ['type_id', $data['type_id']]);
  2290. }
  2291. $query = Good::where($where)
  2292. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2293. $query->where(function ($q) use ($data) {
  2294. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2295. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2296. });
  2297. })
  2298. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2299. $query->where(function ($q) use ($data) {
  2300. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2301. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2302. });
  2303. })
  2304. ->select(
  2305. 'good.id',
  2306. 'good.name',
  2307. 'good.imgurl',
  2308. 'good.description',
  2309. 'good.updated_at',
  2310. 'good.com',
  2311. 'good.catid',
  2312. 'good.type_id',
  2313. 'good.website_id',
  2314. 'good.cat_arr_id',
  2315. 'good.created_at',
  2316. 'good.city_id'
  2317. )
  2318. ->latest('updated_at');
  2319. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2320. $result['count'] = $query->clone()->count();
  2321. $result['goods'] = $this->processGoods(
  2322. $query->clone()
  2323. ->offset(($data['page'] - 1) * $data['pageSize'])
  2324. ->limit($data['pageSize'])
  2325. ->get(),
  2326. $data
  2327. );
  2328. } else {
  2329. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2330. // 获取 type_id 为 1 的数据
  2331. $result['type1'] = $this->processGoods(
  2332. $query->clone()
  2333. ->where('type_id', 1)
  2334. ->offset(($data['page'] - 1) * $data['pageSize'])
  2335. ->limit($data['pageSize'])
  2336. ->get(),
  2337. $data
  2338. );
  2339. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2340. // 获取 type_id 为 2 的数据
  2341. $result['type2'] = $this->processGoods(
  2342. $query->clone()
  2343. ->where('type_id', 2)
  2344. ->offset(($data['page'] - 1) * $data['pageSize'])
  2345. ->limit($data['pageSize'])
  2346. ->get(),
  2347. $data
  2348. );
  2349. }
  2350. if (empty($result)) {
  2351. return Result::error("查询失败", 0);
  2352. }
  2353. return Result::success($result);
  2354. }
  2355. /**
  2356. * 获取商品详情
  2357. * @param array $data
  2358. * @return array
  2359. * */
  2360. public function getWebsiteshopInfo(array $data): array
  2361. {
  2362. $where = [
  2363. 'good.status' => 2,
  2364. 'good.website_id' => $data['website_id'],
  2365. 'good.id' => $data['id'],
  2366. ];
  2367. $goods = Good::where($where)
  2368. ->where('good.id', $data['id'])
  2369. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2370. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2371. ->first();
  2372. if (empty($goods)) {
  2373. return Result::error("查询失败", 0);
  2374. }
  2375. $goods->imgurl = json_decode($goods->imgurl, true);
  2376. return Result::success($goods);
  2377. }
  2378. /**
  2379. * plus pro 处理文章路由问题
  2380. */
  2381. function processArticlePro($website_id)
  2382. {
  2383. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2384. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2385. // // 取出category_id 对应的aLIas_pinyin
  2386. // $categoryIds = array_column($categorys, 'category_id');
  2387. // $categoryPIds = array_column($categorys, 'pid');
  2388. // $aliasPinyins = array_column($categorys, 'path');
  2389. // $alias = array_column($categorys, 'alias');
  2390. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2391. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2392. // // return Result::success($cat_arr);
  2393. // // $catiall = [];
  2394. // //一级所有子级的记录
  2395. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2396. // return [
  2397. // 'cat_1st_arr' => $cat_alias_arr,
  2398. // 'catiall' => $cat_arr,
  2399. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2400. // 'categoryIds' => $categoryIds,
  2401. // ];
  2402. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2403. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2404. // 取出category_id 对应的aLIas_pinyin
  2405. $categoryIds = array_column($categorys, 'category_id');
  2406. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2407. return $pid != 0;
  2408. })));
  2409. $category_path = array_column($categorys, 'path');
  2410. $cat_arr = array_combine($categoryIds, $category_path);
  2411. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2412. $catiall = [];
  2413. //一级所有子级的记录
  2414. $cat_1st_arr = [];
  2415. foreach ($categorys as $key => $value) {
  2416. // $category_arr_id = json_decode($value->category_arr_id);
  2417. // $pinyin_str = '';
  2418. // // 算出一级 并且算出子级
  2419. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2420. $cat_1st_arr[$value->pid][] = $value->category_id;
  2421. }
  2422. // foreach ($category_arr_id as $k => $v) {
  2423. // $pinyin_str .= $cat_arr[$v] . '/';
  2424. // }
  2425. // $pinyin_str = rtrim($pinyin_str, '/');
  2426. $catiall[$value->category_id]['alias'] = $value->alias;
  2427. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2428. $catiall[$value->category_id]['type'] = $value->type;
  2429. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2430. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2431. }
  2432. return [
  2433. 'cat_1st_arr' => $cat_1st_arr,
  2434. 'catiall' => $catiall,
  2435. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2436. 'categoryIds' => $categoryIds,
  2437. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2438. 'categoryPIds' => $categoryPIds,
  2439. ];
  2440. }
  2441. /**
  2442. * 封装处理文章的路由问题
  2443. * */
  2444. function processArticles($articles, $data)
  2445. {
  2446. // 检查 $articles 是否为数组或可迭代对象
  2447. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2448. return $articles->map(function ($article) use ($data) {
  2449. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2450. $catid = $article->cat_arr_id ?? '';
  2451. }
  2452. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2453. $catid = $article->category_arr_id ?? '';
  2454. }
  2455. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2456. $level = json_decode($catid, true);
  2457. if (!is_array($level)) {
  2458. return $article;
  2459. } else {
  2460. $level = array_map('intval', $level);
  2461. }
  2462. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2463. ->where($data)
  2464. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2465. ->pluck('aLIas_pinyin')
  2466. ->implode('/');
  2467. $article->pinyin = $pinyin ?? '';
  2468. return $article;
  2469. });
  2470. } else {
  2471. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2472. $catid = $articles->cat_arr_id ?? '';
  2473. $level = json_decode($catid, true);
  2474. if (!is_array($level)) {
  2475. return $articles;
  2476. } else {
  2477. $level = array_map('intval', $level);
  2478. }
  2479. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2480. ->where($data)
  2481. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2482. ->pluck('aLIas_pinyin')
  2483. ->implode('/');
  2484. $articles->pinyin = $pinyin ?? '';
  2485. return $articles;
  2486. }
  2487. }
  2488. // 封装处理由问题
  2489. function processJob($job, $data)
  2490. {
  2491. return $job->map(function ($job) use ($data) {
  2492. $category = $job->cat_arr_id ?? '';
  2493. $cityid = $job->city_arr_id ?? '';
  2494. $city = json_decode($cityid, true);
  2495. $pinyin = '';
  2496. $level = json_decode($category, true);
  2497. // 路由
  2498. if (!empty($level) && is_array($level)) {
  2499. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2500. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2501. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2502. ->get(['aLIas_pinyin'])
  2503. ->pluck('aLIas_pinyin')
  2504. ->implode('/');
  2505. if (empty($pinyin)) {
  2506. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2507. }
  2508. $job->pinyin = $pinyin;
  2509. }
  2510. // 取职位-城市 市??省
  2511. if (!empty($city) && is_array($city)) {
  2512. if (isset($city[1]) && !empty($city[1])) {
  2513. $city = District::where('id', $city[1])->first(['name']);
  2514. $job->city_name = $city->name ?? '';
  2515. } else if (isset($city[0]) && !empty($city[0])) {
  2516. $city = District::where('id', $city[0])->first(['name']);
  2517. $job->city_name = $city->name ?? '';
  2518. } else {
  2519. $job->city_name = '全国';
  2520. }
  2521. }
  2522. // 获取简历最后一级地区
  2523. if (isset($job->city_id) && !empty($job->city_id)) {
  2524. $city = District::where('id', $job->city_id)->first(['name']);
  2525. $job->hunt_cityname = $city->name ?? '';
  2526. }
  2527. // 组合详细地址
  2528. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2529. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2530. if (is_array($address_id) && !empty($address_id)) {
  2531. $address = District::whereIn('id', $address_id)
  2532. ->orderBy('level', 'asc')
  2533. ->get(['name'])
  2534. ->pluck('name')
  2535. ->implode('');
  2536. // $job->address_name = $address ?? '';
  2537. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2538. }
  2539. }
  2540. // 取行业
  2541. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2542. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2543. if (!empty($job->industry)) {
  2544. $query->where('hyid', $job->industry);
  2545. } else if (!empty($job->hy_id)) {
  2546. $query->where('hyid', $job->hy_id);
  2547. } else if (!empty($job->company_hy_id)) {
  2548. $query->where('hyid', $job->company_hy_id);
  2549. } else {
  2550. $query->where('hyid', $job->job_industry);
  2551. }
  2552. })->first(['hyname']);
  2553. $job->hy_name = $hy_name->hyname ?? '';
  2554. }
  2555. // 取职位类别
  2556. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2557. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2558. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2559. $job->zw_name = $zw_name->zwname ?? '';
  2560. }
  2561. // 取具体职位
  2562. 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))) {
  2563. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2564. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2565. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2566. }
  2567. // 取工作经验
  2568. if (isset($job->experience) && !empty($job->experience)) {
  2569. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2570. $job->experience_name = $experience->ename ?? '';
  2571. }
  2572. // 取学历
  2573. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2574. $education = $job->educational ?? $job->school_education;
  2575. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2576. $job->education_name = $education->ename ?? '';
  2577. }
  2578. // 语言
  2579. if (isset($job->language) && !empty($job->language)) {
  2580. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2581. $job->language_name = $language->ename ?? '';
  2582. }
  2583. // 薪资
  2584. if (isset($job->salary) && !empty($job->salary)) {
  2585. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2586. $job->salary_name = $salary->ename ?? '';
  2587. }
  2588. // 职位性质
  2589. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2590. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2591. $job->job_nature_name = $job_nature->ename ?? '';
  2592. }
  2593. // 公司规模
  2594. if (isset($job->company_size) && !empty($job->company_size)) {
  2595. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2596. $job->company_size_name = $company_size->ename ?? '';
  2597. }
  2598. // 公司性质
  2599. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2600. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2601. $job->company_nature_name = $company_nature->nature_name ?? '';
  2602. }
  2603. // $job->pinyin = $pinyin;
  2604. return $job;
  2605. });
  2606. }
  2607. /**
  2608. * 获取书籍模块
  2609. * @param array $data
  2610. * @return array
  2611. * */
  2612. public function getWebsiteBook(array $data): array
  2613. {
  2614. $input['id'] = $data['id'];
  2615. $input['website_id'] = $data['website_id'];
  2616. // 将 JSON 字符串转换为 PHP 数组
  2617. $data = json_decode($input['id'], true);
  2618. // 使用 array_map 处理每个元素
  2619. $result = array_map(function ($item) use ($input) {
  2620. // 检查parent元素是否存在且不是undefined
  2621. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2622. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2623. $website = [
  2624. 'website_id' => $input['website_id'],
  2625. ];
  2626. // 查询栏目名称
  2627. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2628. if (empty($category)) {
  2629. $parent_alias = '';
  2630. $parent_pinyin = null;
  2631. $imgBooks = [];
  2632. $textBooks = [];
  2633. } else {
  2634. $parent_alias = $category->alias ?? '';
  2635. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2636. // 查找子分类ID数组
  2637. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2638. array_push($childCategoryIds, $parentCatId);
  2639. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2640. if ($parentImgNum != 0) {
  2641. // 查询图片新闻
  2642. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2643. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2644. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2645. })
  2646. ->where('book.status', 2)
  2647. ->where('book.img_url', '!=', '')
  2648. ->where('book.website_id', $website['website_id'])
  2649. ->leftJoin('website_category', function ($join) use ($website) {
  2650. $join->on('book.cat_id', '=', 'website_category.category_id')
  2651. ->where('website_category.website_id', '=', $website['website_id']);
  2652. })
  2653. ->select(
  2654. 'book.id',
  2655. 'book.title',
  2656. 'book.img_url',
  2657. 'book.price',
  2658. 'book.market_price',
  2659. 'book.description',
  2660. 'book.cat_id',
  2661. 'book.description',
  2662. 'book.updated_at',
  2663. 'website_category.alias as category_name',
  2664. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2665. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2666. )
  2667. ->orderBy('updated_at', 'desc')
  2668. ->limit($parentImgNum)
  2669. ->get()->all();
  2670. // 查询文字新闻
  2671. }
  2672. if ($parentTextNum != 0) {
  2673. $textBooks = [];
  2674. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2675. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2676. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2677. })
  2678. ->where('book.status', 2)
  2679. ->where('book.website_id', $website['website_id'])
  2680. ->leftJoin('website_category', function ($join) use ($website) {
  2681. $join->on('book.cat_id', '=', 'website_category.category_id')
  2682. ->where('website_category.website_id', '=', $website['website_id']);
  2683. })
  2684. ->select(
  2685. 'book.id',
  2686. 'book.title',
  2687. 'book.img_url',
  2688. 'book.price',
  2689. 'book.market_price',
  2690. 'book.description',
  2691. 'book.cat_id',
  2692. 'book.description',
  2693. 'book.updated_at',
  2694. 'website_category.alias as category_name',
  2695. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2696. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2697. )
  2698. ->orderBy('updated_at', 'desc')
  2699. ->limit($parentTextNum)
  2700. ->get()->all();
  2701. }
  2702. }
  2703. }
  2704. $resultItem = [
  2705. 'alias' => $parent_alias ?? '',
  2706. 'category_id' => $parentCatId ?? 0,
  2707. 'pinyin' => $parent_pinyin ?? null,
  2708. 'imgnum' => $imgBooks ?? [],
  2709. 'textnum' => $textBooks ?? [],
  2710. ];
  2711. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2712. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2713. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2714. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2715. ->get()->all();
  2716. if (!empty($childCategory)) {
  2717. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2718. // 查询子栏目名称
  2719. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2720. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2721. ->first();
  2722. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2723. $childImgArticles = [];
  2724. $childTextArticles = [];
  2725. $resultItem['child'] = [];
  2726. } else {
  2727. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2728. // 查询子栏目图片新闻
  2729. $childImgArticles = Book::where('cat_id', $childCatId)
  2730. ->where('status', 2)
  2731. ->where('img_url', '!=', '')
  2732. ->leftJoin('website_category', function ($join) use ($website) {
  2733. $join->on('book.cat_id', '=', 'website_category.category_id')
  2734. ->where('website_category.website_id', '=', $website['website_id']);
  2735. })
  2736. ->select(
  2737. 'book.id',
  2738. 'book.title',
  2739. 'book.img_url',
  2740. 'book.price',
  2741. 'book.market_price',
  2742. 'book.description',
  2743. 'book.cat_id',
  2744. 'book.description',
  2745. 'book.updated_at',
  2746. DB::raw("'$child_pinyin' as pinyin")
  2747. )
  2748. ->orderBy('updated_at', 'desc')
  2749. ->limit($childImgNum)
  2750. ->get()->all();
  2751. // 查询子栏目文字新闻
  2752. $childTextArticles = Book::where('cat_id', $childCatId)
  2753. ->where('status', 2)
  2754. ->leftJoin('website_category', function ($join) use ($website) {
  2755. $join->on('book.cat_id', '=', 'website_category.category_id')
  2756. ->where('website_category.website_id', '=', $website['website_id']);
  2757. })
  2758. ->select(
  2759. 'book.id',
  2760. 'book.title',
  2761. 'book.img_url',
  2762. 'book.price',
  2763. 'book.market_price',
  2764. 'book.description',
  2765. 'book.cat_id',
  2766. 'book.description',
  2767. 'book.updated_at',
  2768. DB::raw("'$child_pinyin' as pinyin")
  2769. )
  2770. ->orderBy('updated_at', 'desc')
  2771. ->limit($childTextNum)
  2772. ->get()->all();
  2773. $resultItem['child'] = [
  2774. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2775. 'category_id' => $childCatId,
  2776. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2777. 'all_childcat' => $childCategory,
  2778. 'imgnum' => $childImgArticles,
  2779. 'textnum' => $childTextArticles,
  2780. ];
  2781. }
  2782. }
  2783. } else {
  2784. $resultItem['child'] = [];
  2785. }
  2786. return $resultItem;
  2787. }, $data);
  2788. return Result::success($result);
  2789. }
  2790. /**
  2791. * 获取书刊列表
  2792. * @param array $data
  2793. * @return array
  2794. * */
  2795. public function getWebsiteBookList(array $data): array
  2796. {
  2797. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2798. if (empty($web)) {
  2799. return Result::error("查询失败", 0);
  2800. }
  2801. $catid = $data['id'];
  2802. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2803. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2804. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2805. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2806. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2807. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2808. ->where('pid', $category['pid'])
  2809. ->select(
  2810. 'category_id',
  2811. 'alias',
  2812. 'aLIas_pinyin',
  2813. 'pid',
  2814. 'sort',
  2815. 'is_url',
  2816. 'web_url',
  2817. 'seo_title',
  2818. 'seo_keywords',
  2819. 'seo_description',
  2820. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2821. )
  2822. ->orderBy('sort')
  2823. ->get()->all();
  2824. if (empty($category)) {
  2825. return Result::error("查询失败", 0);
  2826. }
  2827. $query = Book::where('book.status', 2)
  2828. ->where('book.website_id', $data['website_id'])
  2829. ->where('book.cat_id', $catid)
  2830. ->select(
  2831. 'book.id',
  2832. 'book.title',
  2833. 'book.img_url',
  2834. 'book.description',
  2835. 'book.updated_at',
  2836. 'book.cat_id',
  2837. DB::raw("'$pinyin' as pinyin")
  2838. )
  2839. ->orderBy('book.updated_at', 'desc');
  2840. $count = $query->count();
  2841. $query = clone $query;
  2842. $Book = $query
  2843. ->limit($data['pageSize'])
  2844. ->offset(($data['page'] - 1) * $data['pageSize'])
  2845. ->get()->all();
  2846. $result = [
  2847. 'category' => $categorys,
  2848. 'books' => $Book,
  2849. 'count' => $count,
  2850. ];
  2851. // if(empty($result)){
  2852. // return Result::error("查询失败", 0);
  2853. // }
  2854. return Result::success($result);
  2855. }
  2856. /**
  2857. * 获取书刊详情
  2858. * @param array $data
  2859. * @return array
  2860. * */
  2861. public function getWebsiteBookInfo(array $data): array
  2862. {
  2863. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2864. if (empty($web)) {
  2865. return Result::error("查询失败", 0);
  2866. }
  2867. $book = Book::where('status', 2)
  2868. ->where('website_id', $data['website_id'])
  2869. ->where('id', $data['id'])
  2870. ->select(
  2871. 'book.*',
  2872. )
  2873. ->orderBy('updated_at', 'desc')
  2874. ->first();
  2875. if (empty($book)) {
  2876. return Result::error("查询失败", 0);
  2877. }
  2878. // 先查询当前分类的 pid
  2879. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2880. ->where('category_id', $book['cat_id'])
  2881. ->first(['pid', 'category_id']);
  2882. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2883. if (!empty($carpid)) {
  2884. if ($carpid->pid != 0) {
  2885. $pid = $carpid['pid'];
  2886. // $parent_pinyin = '';
  2887. } else {
  2888. $pid = $carpid['category_id'];
  2889. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2890. }
  2891. }
  2892. $categorys = $query->where('pid', $pid)
  2893. ->select(
  2894. 'category_id',
  2895. 'alias',
  2896. 'aLIas_pinyin',
  2897. 'pid',
  2898. 'sort',
  2899. 'is_url',
  2900. 'web_url',
  2901. 'category_arr_id as cat_arr_id',
  2902. )
  2903. ->orderBy('sort')
  2904. ->get();
  2905. $category = $this->processArticle($categorys, $data);
  2906. $result = [
  2907. 'category' => $category,
  2908. 'books' => $book,
  2909. ];
  2910. return Result::success($result);
  2911. }
  2912. /**
  2913. * 尝试
  2914. * @param array $data
  2915. * @return array
  2916. * */
  2917. public function test(array $data): array
  2918. {
  2919. $input['id'] = $data['id'];
  2920. $input['website_id'] = $data['website_id'];
  2921. // 将 JSON 字符串转换为 PHP 数组
  2922. $data = json_decode($input['id'], true);
  2923. $result = [];
  2924. $article = $data;
  2925. $result = array_map(function ($item) use ($input) {
  2926. $website = [
  2927. 'website_id' => $input['website_id'],
  2928. ];
  2929. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2930. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2931. $parent = [
  2932. 0 => $category['category_id'] ?? [],
  2933. 1 => $parentImgNum ?? [],
  2934. 2 => $parentTextNum ?? [],
  2935. ];
  2936. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2937. $child = [];
  2938. $resultItem = [
  2939. // 'alias' => $parent_alias ?? '',
  2940. 'category_id' => $parentCatId ?? 0,
  2941. 'pinyin' => $parentImgNum ?? null,
  2942. 'imgnum' => $parentTextNum ?? [],
  2943. // 'textnum' => $textArticles ?? [],
  2944. ];
  2945. return $parent;
  2946. }, $data);
  2947. return Result::success($result);
  2948. // });
  2949. }
  2950. /**
  2951. * 封装处理文章的路由问题
  2952. * */
  2953. function processArticle($article, $data)
  2954. {
  2955. return $article->map(function ($article) use ($data) {
  2956. $catid = $article->cat_arr_id ?? '';
  2957. $level = json_decode($catid, true);
  2958. $pinyin = '';
  2959. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2960. if (!empty($level) && is_array($level)) {
  2961. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2962. ->where('website_id', $data['website_id'])
  2963. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2964. ->get(['aLIas_pinyin'])
  2965. ->pluck('aLIas_pinyin')
  2966. ->implode('/');
  2967. } else {
  2968. $pinyin = '';
  2969. }
  2970. $article->pinyin = $pinyin;
  2971. return $article;
  2972. });
  2973. }
  2974. /**
  2975. * c端-获取招工招聘下拉选框
  2976. * @param array $data
  2977. * @return array
  2978. * */
  2979. public function getWebsiteJobSelect(array $data): array
  2980. {
  2981. $web = Website::where('id', $data['website_id'])->first();
  2982. if (empty($web)) {
  2983. return Result::error("该网站不存在", 0);
  2984. }
  2985. $hy = JobIndustry::get()->all();
  2986. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2987. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2988. $result = [
  2989. 'hy' => $hy,
  2990. 'zw' => $zw,
  2991. 'jtzw' => $jtzw,
  2992. ];
  2993. if (empty($result)) {
  2994. return Result::error("查询失败", 0);
  2995. }
  2996. return Result::success($result);
  2997. }
  2998. /**
  2999. * c端-获取招工招聘
  3000. * @param array $data
  3001. * @return array
  3002. * */
  3003. public function getWebsiteJob(array $data): array
  3004. {
  3005. $web = Website::where('id', $data['website_id'])->first();
  3006. if (empty($web)) {
  3007. return Result::error("该网站不存在", 0);
  3008. }
  3009. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3010. ->where('job_hunting.website_id', $data['website_id'])
  3011. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3012. $query->where(function ($q) use ($data) {
  3013. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3014. });
  3015. })
  3016. ->select(
  3017. 'job_hunting.id',
  3018. 'job_hunting.catid',
  3019. 'job_hunting.cat_arr_id',
  3020. 'job_hunting.job_name_get',
  3021. 'job_hunting.industry',
  3022. 'job_hunting.name',
  3023. 'job_hunting.sexy',
  3024. 'job_hunting.origin',
  3025. 'job_hunting.city_arr_id',
  3026. 'job_hunting.experience',
  3027. 'job_hunting.updated_at',
  3028. 'job_hunting.salary',
  3029. 'job_hunting.skillList',
  3030. 'job_hunting.slelf_evaluation',
  3031. )
  3032. ->orderBy('updated_at', 'desc')
  3033. ->limit($data['job1_num'])
  3034. ->get();
  3035. $web['website_id'] = $data['website_id'];
  3036. if (empty($job_hunting)) {
  3037. $job_huntings = "未查询到相关简历信息";
  3038. } else {
  3039. $job_huntings = $this->processJob($job_hunting, $web);
  3040. }
  3041. // 0:待审核 1:已通过 2:已拒绝
  3042. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3043. ->where('job_recruiting.website_id', $data['website_id'])
  3044. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3045. $query->where(function ($q) use ($data) {
  3046. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3047. });
  3048. })
  3049. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3050. ->select(
  3051. 'job_recruiting.id',
  3052. 'job_recruiting.catid',
  3053. 'job_recruiting.cat_arr_id',
  3054. 'job_recruiting.title',
  3055. 'job_recruiting.jtzw_id',
  3056. 'job_recruiting.hy_id',
  3057. 'job_recruiting.city_arr_id',
  3058. 'job_recruiting.due_data',
  3059. 'job_recruiting.updated_at',
  3060. 'job_recruiting.experience',
  3061. 'job_recruiting.educational',
  3062. 'job_recruiting.salary',
  3063. 'job_recruiting.zw_id',
  3064. 'job_company.business_name',
  3065. 'job_recruiting.keyword',
  3066. 'job_recruiting.description',
  3067. )
  3068. ->orderBy('updated_at', 'desc')
  3069. ->limit($data['job2_num'])
  3070. ->get();
  3071. if (empty($job_recruiting->toArray())) {
  3072. $job_recruitings = "未查询到相关职位信息";
  3073. } else {
  3074. $job_recruitings = $this->processJob($job_recruiting, $web);
  3075. }
  3076. $result = [
  3077. 'job_hunting' => $job_huntings,
  3078. 'job_recuiting' => $job_recruitings,
  3079. ];
  3080. return Result::success($result);
  3081. }
  3082. /**
  3083. * c端-获取招工招聘列表
  3084. * @param array $data
  3085. * @return array
  3086. * */
  3087. public function getWebsiteJobList(array $data): array
  3088. {
  3089. $recruit_where = [];
  3090. $hunt_where = [];
  3091. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3092. if (empty($web)) {
  3093. return Result::error("此网站不存在", 0);
  3094. }
  3095. $website_id['website_id'] = $data['website_id'];
  3096. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3097. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3098. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3099. }
  3100. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3101. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3102. }
  3103. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3104. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3105. }
  3106. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3107. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3108. }
  3109. $query = JobRecruiting::where('job_recruiting.status', 1)
  3110. ->where('job_recruiting.website_id', $data['website_id'])
  3111. ->where($recruit_where)
  3112. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3113. $query->where(function ($q) use ($data) {
  3114. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3115. });
  3116. })
  3117. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3118. $query->where(function ($q) use ($data) {
  3119. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3120. });
  3121. })
  3122. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3123. ->select(
  3124. 'job_recruiting.id',
  3125. 'job_recruiting.catid',
  3126. 'job_recruiting.hy_id',
  3127. 'job_recruiting.title',
  3128. 'job_recruiting.zw_id',
  3129. 'job_recruiting.educational',
  3130. 'job_recruiting.jtzw_id',
  3131. 'job_recruiting.city_arr_id',
  3132. 'job_recruiting.due_data',
  3133. 'job_recruiting.experience',
  3134. 'job_recruiting.cat_arr_id',
  3135. 'job_recruiting.updated_at',
  3136. 'job_company.business_name',
  3137. 'job_recruiting.keyword',
  3138. 'job_recruiting.description',
  3139. )
  3140. ->orderBy('job_recruiting.updated_at', 'desc');
  3141. $recruit_count = $query->count();
  3142. $query = clone $query;
  3143. $JobRecruiting = $query
  3144. ->offset(($data['page'] - 1) * $data['pageSize'])
  3145. ->limit($data['pageSize'])
  3146. ->get();
  3147. if (empty($JobRecruiting)) {
  3148. $JobRecruiting = "暂无相关职位信息";
  3149. } else {
  3150. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3151. }
  3152. }
  3153. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3154. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3155. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3156. }
  3157. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3158. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3159. }
  3160. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3161. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3162. }
  3163. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3164. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3165. }
  3166. $query = JobHunting::where('job_hunting.status', 2)
  3167. ->where('job_hunting.website_id', $data['website_id'])
  3168. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3169. ->where($hunt_where)
  3170. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3171. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3172. // })
  3173. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3174. $query->where(function ($q) use ($data) {
  3175. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3176. });
  3177. })
  3178. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3179. $query->where(function ($q) use ($data) {
  3180. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3181. });
  3182. })
  3183. ->select(
  3184. 'job_hunting.id',
  3185. 'job_hunting.catid',
  3186. 'job_hunting.sexy',
  3187. 'job_hunting.experience',
  3188. 'job_hunting.origin',
  3189. 'job_hunting.industry',
  3190. 'job_hunting.name',
  3191. 'job_hunting.job',
  3192. 'job_hunting.job_name_get',
  3193. 'job_hunting.city_arr_id',
  3194. 'job_hunting.cat_arr_id',
  3195. 'job_hunting.created_at',
  3196. 'job_hunting.updated_at',
  3197. 'job_position.zwname as job_name',
  3198. 'job_hunting.skillList',
  3199. 'job_hunting.slelf_evaluation',
  3200. )
  3201. ->orderBy('job_hunting.updated_at', 'desc');
  3202. $hunt_count = $query->count();
  3203. $query = clone $query;
  3204. $JobHunting = $query
  3205. ->offset(($data['page'] - 1) * $data['pageSize'])
  3206. ->limit($data['pageSize'])
  3207. ->get();
  3208. if (empty($JobHunting)) {
  3209. $JobRecruiting = "暂无相关简历信息";
  3210. } else {
  3211. $JobHunting = $this->processJob($JobHunting, $website_id);
  3212. }
  3213. }
  3214. $result = [
  3215. 'JobRecruiting' => $JobRecruiting ?? [],
  3216. 'recruit_count' => $recruit_count ?? 0,
  3217. 'JobHunting' => $JobHunting ?? [],
  3218. 'hunt_count' => $hunt_count ?? 0,
  3219. ];
  3220. return Result::success($result);
  3221. }
  3222. /**
  3223. * c端-获取招工招聘详情
  3224. * @param array $data
  3225. * @return array
  3226. * */
  3227. public function getWebsiteJobInfo(array $data): array
  3228. {
  3229. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3230. if (empty($web)) {
  3231. return Result::error("该网站不存在", 0);
  3232. }
  3233. $webid = [
  3234. 'website_id' => $data['website_id'],
  3235. ];
  3236. // 职位相关信息
  3237. if ($data['type'] == 1) {
  3238. $query = JobRecruiting::where('status', 1)
  3239. ->where('website_id', $data['website_id'])
  3240. ->select('*');
  3241. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3242. $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();
  3243. if (!empty($company)) {
  3244. $result['company'] = $this->processJob($company, $webid);
  3245. }
  3246. $other_job = JobRecruiting::where('status', 1)
  3247. ->where('website_id', $data['website_id'])
  3248. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3249. ->where('id', '!=', $data['id'])
  3250. ->where('user_id', '=', $job[0]['user_id'])
  3251. ->limit($data['pageSize'])
  3252. ->get();
  3253. if (!empty($other_job)) {
  3254. $result['other_job'] = $this->processJob($other_job, $webid);
  3255. }
  3256. } else {
  3257. // 简历相关信息
  3258. $job = JobHunting::where('job_hunting.status', 2)
  3259. ->where('job_hunting.website_id', $data['website_id'])
  3260. ->where('job_hunting.id', $data['id'])
  3261. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3262. ->select('job_hunting.*', 'user_name')
  3263. ->get();
  3264. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3265. if (!empty($resume->toArray())) {
  3266. $result['resume'] = 1;
  3267. } else {
  3268. $result['resume'] = 0;
  3269. }
  3270. }
  3271. if (empty($job->toArray())) {
  3272. return Result::error("id参数错误", 0);
  3273. }
  3274. if (!empty($job[0]['job_experience'])) {
  3275. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3276. if (!empty($job_experience)) {
  3277. // $hy = [];
  3278. foreach ($job_experience as $key => $value) {
  3279. // $id = $value['id'];
  3280. $hy[$key] = $value['job_industry'];
  3281. $zw_id[$key] = $value['job_typename'];
  3282. $jtzw_id[$key] = $value['job_name'];
  3283. }
  3284. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3285. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3286. // 先将关联表转换为索引数组,提高查找效率
  3287. $hyLookup = [];
  3288. foreach ($hy_table as $item) {
  3289. $hyLookup[$item['hyid']] = $item['hyname'];
  3290. }
  3291. $zwLookup = [];
  3292. foreach ($zw_table as $item) {
  3293. $zwLookup[$item['zwid']] = $item['zwname'];
  3294. }
  3295. foreach ($job_experience as $key => &$value) {
  3296. // 处理行业名称
  3297. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3298. $value['hy_name'] = $hyLookup[$hy[$key]];
  3299. }
  3300. // 处理职位名称
  3301. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3302. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3303. }
  3304. // 处理具体职位名称
  3305. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3306. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3307. }
  3308. }
  3309. // 释放引用,防止意外修改后续代码
  3310. unset($value);
  3311. }
  3312. $result['job_experience'] = $job_experience ?? [];
  3313. }
  3314. if (!empty($job[0]['education_experience'])) {
  3315. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3316. if (!empty($education_experience)) {
  3317. foreach ($education_experience as $key => $value) {
  3318. // $id = $value['id'];
  3319. $education[$key] = $value['school_education'];
  3320. }
  3321. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3322. // // 先将关联表转换为索引数组,提高查找效率
  3323. $educationLookup = [];
  3324. foreach ($education_table as $item) {
  3325. $educationLookup[$item['evalue']] = $item['ename'];
  3326. }
  3327. foreach ($education_experience as $key => &$value) {
  3328. // 处理学历名称
  3329. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3330. $value['education_name'] = $educationLookup[$education[$key]];
  3331. }
  3332. }
  3333. }
  3334. $result['education_experience'] = $job_experience ?? [];
  3335. }
  3336. $result['job'] = $this->processJob($job, $webid);
  3337. // // 返现对应的栏目
  3338. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3339. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3340. ->whereIn('category_id', $catid)
  3341. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3342. ->orderBy('pid')->get()->all();
  3343. if (!empty($category)) {
  3344. $result['category'] = $category;
  3345. }
  3346. $result['job'] = $job;
  3347. $result['job_experience'] = $job_experience ?? [];
  3348. $result['education_experience'] = $education_experience ?? [];
  3349. if (empty($result)) {
  3350. return Result::error("参数错误", 0);
  3351. }
  3352. return Result::success($result);
  3353. }
  3354. /**
  3355. * c端-申请职位
  3356. * @param array $data
  3357. * @return array
  3358. * */
  3359. public function getWebsiteJobApply(array $data): array
  3360. {
  3361. // 首先验证网站是否存在
  3362. // return Result::success($data);
  3363. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3364. if (empty($web)) {
  3365. return Result::error("该网站不存在", 0);
  3366. }
  3367. // 验证用户是否存在且为个人会员/管理员
  3368. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3369. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3370. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3371. return Result::error("用户不存在", 0);
  3372. }
  3373. // 去除重复元素和空元素,并保持原始顺序
  3374. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3375. return !empty($value);
  3376. }));
  3377. // 验证职位是否存在 1:审核通过
  3378. $recruiting = JobRecruiting::where('status', 1)
  3379. ->where('website_id', $data['website_id'])
  3380. ->whereIn('id', $data['recruit_id'])
  3381. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3382. if (empty($recruiting)) {
  3383. return Result::error("该职位不存在", 0);
  3384. }
  3385. // 简历是否存在
  3386. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3387. if (empty($hunt_id)) {
  3388. return Result::error("该简历不存在", 0);
  3389. }
  3390. $data['hunt_id'] = $hunt_id['hunt_id'];
  3391. // // 验证是否已投递过该职位
  3392. $apply = JobApply::where('user_id', $data['user_id'])
  3393. ->where('hunt_id', $data['hunt_id'])
  3394. ->where('website_id', $data['website_id'])
  3395. ->whereIn('recruit_id', $data['recruit_id'])
  3396. ->get(['recruit_id']);
  3397. if (!empty($apply->toArray())) {
  3398. return Result::error("您已投递过该职位!");
  3399. }
  3400. $insertData = array_map(function ($recruiting) use ($data) {
  3401. return [
  3402. 'user_id' => $data['user_id'],
  3403. 'hunt_id' => $data['hunt_id'],
  3404. 'website_id' => $data['website_id'],
  3405. 'recruit_id' => $recruiting['recruit_id'],
  3406. 'receiver_id' => $recruiting['receiver_id'],
  3407. 'status' => 1,
  3408. ];
  3409. }, $recruiting);
  3410. // 批量插入数据
  3411. $result = JobApply::insert($insertData);
  3412. if (empty($result)) {
  3413. return Result::error("投递失败", 0);
  3414. }
  3415. return Result::success($result);
  3416. }
  3417. /**
  3418. * 招工招聘-沟通简历
  3419. * @param array $data
  3420. * @return array
  3421. * */
  3422. public function getWebsiteJobResume(array $data): array
  3423. {
  3424. // 首先验证网站是否存在
  3425. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3426. if (empty($web)) {
  3427. return Result::error("该网站不存在", 0);
  3428. }
  3429. // return Result::success($data);
  3430. // 验证用户是否存在且为企业会员/管理员
  3431. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3432. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3433. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3434. return Result::error("用户不存在", 0);
  3435. }
  3436. // 去除重复元素和空元素,并保持原始顺序
  3437. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3438. return !empty($value);
  3439. }));
  3440. // 验证简历是否存在
  3441. $hunting = JobHunting::where('status', 2)
  3442. ->where('website_id', $data['website_id'])
  3443. ->whereIn('id', $data['hunt_id'])
  3444. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3445. if (empty($hunting)) {
  3446. return Result::error("该简历不存在", 0);
  3447. }
  3448. // 验证是否已沟通过该简历
  3449. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3450. ->where('recruit_id', $data['recruit_id'])
  3451. ->where('website_id', $data['website_id'])
  3452. ->whereIn('hunt_id', $data['hunt_id'])
  3453. ->get(['hunt_id']);
  3454. if (!empty($remuse->toArray())) {
  3455. return Result::error("您已沟通过该简历!");
  3456. }
  3457. // 准备要插入的数据数组
  3458. $insertData = array_map(function ($hunting) use ($data) {
  3459. return [
  3460. 'user_id' => $data['user_id'],
  3461. 'recruit_id' => $data['recruit_id'],
  3462. 'website_id' => $data['website_id'],
  3463. 'hunt_id' => $hunting['hunt_id'],
  3464. 'receiver_id' => $hunting['receiver_id'],
  3465. 'status' => 1,
  3466. ];
  3467. }, $hunting);
  3468. // 批量插入数据
  3469. $result = JobRemuse::insert($insertData);
  3470. if (empty($result)) {
  3471. return Result::error("沟通失败", 0);
  3472. }
  3473. return Result::success($result);
  3474. }
  3475. /**
  3476. * 招工招聘 -我的职位(企业会员)
  3477. * @param array $data
  3478. * @return array
  3479. */
  3480. public function getWebsiteJobRecruiting(array $data): array
  3481. {
  3482. $web = Website::where('id', $data['website_id'])->first('id');
  3483. if (empty($web)) {
  3484. return Result::error("该网站不存在", 0);
  3485. }
  3486. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3487. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3488. return Result::error("用户暂无权限!", 0);
  3489. }
  3490. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3491. $result = JobRecruiting::where('website_id', $data['website_id'])
  3492. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3493. $query->where('user_id', $user['id']);
  3494. })
  3495. ->where('status', 1)
  3496. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3497. ->orderBy('updated_at', 'desc')
  3498. ->limit($data['pageSize'])
  3499. ->get();
  3500. if (empty($result)) {
  3501. return Result::error("暂无相关职位信息", 0);
  3502. }
  3503. return Result::success($result);
  3504. }
  3505. /**
  3506. * c端 - 验证路由
  3507. * @param array $data
  3508. * @return array
  3509. */
  3510. /**
  3511. * c端 - 验证路由
  3512. * @param array $data
  3513. * @return array
  3514. */
  3515. public function checkWebsiteRoute(array $data): array
  3516. {
  3517. // 测试001111111222
  3518. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3519. if (empty($web)) {
  3520. return Result::error("该网站不存在", 0);
  3521. } elseif ($web['status'] != 1) {
  3522. return Result::error("网站已经关闭", 0);
  3523. }
  3524. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3525. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3526. // 验证路由是否存在
  3527. if (empty($whiteRouterInfo)) {
  3528. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3529. }
  3530. if (!empty($whiteRouterInfo)) {
  3531. return Result::success($whiteRouterInfo->toArray());
  3532. }
  3533. }
  3534. // 验证栏目路由
  3535. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3536. ->where('path', $data['all_route'])
  3537. ->get()->all();
  3538. if (count($last_category) == 0) {
  3539. return Result::error("该栏目不存在", 0);
  3540. }
  3541. if (count($last_category) > 1) {
  3542. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3543. }
  3544. if (count($last_category) == 1) {
  3545. $last_category = $last_category[0];
  3546. }
  3547. // return Result::success($last_category);
  3548. if (isset($data['id']) && !empty($data['id'])) {
  3549. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3550. switch ($last_category['type']) {
  3551. case 1:
  3552. // 文章
  3553. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3554. $article = Article::where('status', 1)
  3555. ->where('id', $data['id'])
  3556. ->where(function ($query) use ($data) {
  3557. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3558. ->orWhereNull("ignore_ids");
  3559. })
  3560. ->first(['catid']);
  3561. if (empty($article)) {
  3562. return Result::error("该文章不存在", 0);
  3563. }
  3564. // return Result::success($article);
  3565. break;
  3566. case 2:
  3567. // 商品
  3568. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3569. $article = Good::where('website_id', $data['website_id'])
  3570. ->where('status', 2)
  3571. ->where('id', $data['id'])
  3572. ->first(['cat_arr_id']);
  3573. if (empty($article)) {
  3574. return Result::error("该商品不存在", 0);
  3575. }
  3576. break;
  3577. case 3:
  3578. // 书刊信息
  3579. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3580. $article = Book::where('website_id', $data['website_id'])
  3581. ->where('status', 2)
  3582. ->where('id', $data['id'])
  3583. ->first(['id', 'cat_arr_id']);
  3584. if (empty($article)) {
  3585. return Result::error("该书刊不存在", 0);
  3586. }
  3587. break;
  3588. case 4:
  3589. // 招聘
  3590. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3591. $article = JobRecruiting::where('website_id', $data['website_id'])
  3592. ->where('status', 1)
  3593. ->where('id', $data['id'])
  3594. ->first(['cat_arr_id']);
  3595. if (empty($article)) {
  3596. return Result::error("该招聘不存在", 0);
  3597. }
  3598. break;
  3599. case 5:
  3600. // 求职
  3601. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3602. $article = JobHunting::where('website_id', $data['website_id'])
  3603. ->where('status', 2)
  3604. ->where('id', $data['id'])
  3605. ->first(['cat_arr_id']);
  3606. if (empty($article)) {
  3607. return Result::error("该求职不存在", 0);
  3608. }
  3609. break;
  3610. case 6:
  3611. // 企业
  3612. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3613. $article = Company::
  3614. // where('website_id', $data['website_id'])
  3615. // ->
  3616. where('status', 1)
  3617. ->where('id', $data['id'])
  3618. ->first(['cat_arr_id']);
  3619. if (empty($article)) {
  3620. return Result::error("该企业不存在", 0);
  3621. }
  3622. break;
  3623. case 7:
  3624. // 项目
  3625. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3626. $article = Project::where('website_id', $data['website_id'])
  3627. ->where('status', 1)
  3628. ->where('id', $data['id'])
  3629. ->first(['cat_arr_id']);
  3630. if (empty($article)) {
  3631. return Result::error("该项目不存在", 0);
  3632. }
  3633. break;
  3634. default:
  3635. return Result::error("该数据不存在", 0);
  3636. break;
  3637. }
  3638. // return Result::success($article);
  3639. // $catid =0 ;
  3640. if (!isset($article['cat_arr_id'])) {
  3641. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  3642. } else {
  3643. $catidArray = json_decode($article['cat_arr_id'], true);
  3644. $catid = !empty($catidArray) ? end($catidArray) : null;
  3645. }
  3646. // return Result::success($catid);
  3647. // // return Result::success($article['cat_arr_id']);
  3648. if (empty($catid)) {
  3649. return Result::error("该栏目路径不存在", 0);
  3650. }
  3651. $path = WebsiteCategory::where('website_id', $data['website_id'])
  3652. ->where('category_id', $catid)
  3653. ->first('path');
  3654. }
  3655. // else{
  3656. // // if ($last_category['pid'] != 0) {
  3657. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  3658. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  3659. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3660. // ->where('category_id',$catid)
  3661. // ->where('path',$data['all_route'])
  3662. // ->first('path');
  3663. // // } else {
  3664. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  3665. // // }
  3666. // }
  3667. // return Result::success($path);
  3668. if (!empty($path) && $path['path'] != $data['all_route']) {
  3669. return Result::error('非法路径!');
  3670. } else {
  3671. return Result::success($last_category['path']);
  3672. }
  3673. }
  3674. /**
  3675. * 招工招聘 - 获取推荐职位
  3676. * @param array $data
  3677. * @return array
  3678. */
  3679. public function getWebsiteLevelJob(array $data): array
  3680. {
  3681. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3682. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3683. ->where('job_recruiting.status', 1)
  3684. ->where('job_level', $data['job_level'])
  3685. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3686. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3687. ->orderBy('job_recruiting.updated_at', 'desc')
  3688. ->limit($data['pageSize'])
  3689. ->get();
  3690. $web = ['website_id' => $data['website_id']];
  3691. if (!empty($job)) {
  3692. $result = $this->processJob($job, $web);
  3693. }
  3694. if (empty($result)) {
  3695. return Result::error("暂无相关职位信息", 0);
  3696. }
  3697. return Result::success($result);
  3698. }
  3699. /**
  3700. * 验证导航名称是否重复
  3701. * @return void
  3702. */
  3703. //20250226 产品列表
  3704. public function getGoodList(array $data): array
  3705. {
  3706. var_dump($data, '---------1-2--');
  3707. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3708. unset($data['user_type_id']);
  3709. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3710. $where = [];
  3711. if ($type_id != '10000') {
  3712. $where = [
  3713. 'good.user_id' => $user_id,
  3714. ];
  3715. }
  3716. //类型
  3717. if (isset($data['type_id']) && $data['type_id']) {
  3718. $where['good.type_id'] = $data['type_id'];
  3719. }
  3720. //名称
  3721. if (isset($data['name']) && $data['name']) {
  3722. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3723. }
  3724. //status
  3725. if (isset($data['status']) && $data['status'] != '') {
  3726. $where['good.status'] = $data['status'];
  3727. }
  3728. //status1
  3729. // if (isset($data['status1']) && $data['status1'] == 1) {
  3730. // $status1 = 1;
  3731. // }
  3732. $where1 = [];
  3733. //website_id
  3734. // if (isset($data['website_id']) && $data['website_id']) {
  3735. // $where1 = [
  3736. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3737. // ];
  3738. // }
  3739. // website_name
  3740. if (isset($data['website_name']) && $data['website_name']) {
  3741. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3742. }
  3743. // catid
  3744. if (isset($data['category_name']) && $data['category_name']) {
  3745. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3746. }
  3747. // $result = Good::where($where)
  3748. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3749. var_dump($where, '---------1---');
  3750. $result = Good::where($where)
  3751. ->when(!empty($where1), function ($query) use ($where1) {
  3752. return $query->where($where1);
  3753. })
  3754. //status 1待审核2已审核3已拒绝
  3755. ->when(isset($data['status1']), function ($query) {
  3756. return $query->whereIn('good.status', [1, 3]);
  3757. })
  3758. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3759. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3760. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3761. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3762. ->orderBy("updated_at", "desc")
  3763. ->limit($data['page_size'])
  3764. ->offset(($data['page'] - 1) * $data['page_size'])
  3765. ->get();
  3766. $count = Good::where($where)
  3767. ->when(!empty($where1), function ($query) use ($where1) {
  3768. return $query->where($where1);
  3769. })
  3770. //status 1待审核2已审核3已拒绝
  3771. ->when(isset($data['status1']), function ($query) {
  3772. return $query->whereIn('good.status', [1, 3]);
  3773. })
  3774. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3775. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3776. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3777. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3778. ->orderBy("updated_at", "desc")->count();
  3779. $data = [
  3780. 'rows' => $result->toArray(),
  3781. 'count' => $count,
  3782. ];
  3783. if (empty($result)) {
  3784. return Result::error("此栏目暂无相关产品", 0);
  3785. }
  3786. return Result::success($data);
  3787. }
  3788. public function getGoodInfo(array $data): array
  3789. {
  3790. $result = Good::where('id', $data['id'])->first();
  3791. if (empty($result)) {
  3792. return Result::error("此产品不存在", 0);
  3793. }
  3794. return Result::success($result);
  3795. }
  3796. public function addGood(array $data): array
  3797. {
  3798. // unset($data['city_arr_id']);
  3799. // unset($data['cat_arr_id']);
  3800. $data['city_id'] = end($data['city_arr_id']);
  3801. $data['catid'] = end($data['cat_arr_id']);
  3802. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3803. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3804. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3805. unset($data['imgUrl']); //大小写
  3806. if (isset($data['price']) && $data['price'] == '') {
  3807. $data['price'] = 0;
  3808. }
  3809. if ($data['imgurl'] == '') {
  3810. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3811. preg_match_all($reg, $data['detail'], $matches);
  3812. if (isset($matches[1][0])) {
  3813. //截取varchar240
  3814. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3815. }
  3816. }
  3817. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3818. //提取标题+内容中的关键词
  3819. $data['keyword'] = $data['name'];
  3820. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3821. Jieba::init(); // 初始化 jieba-php
  3822. Finalseg::init();
  3823. $segList = Jieba::cut($data['keyword']);
  3824. $segList1 = array_slice($segList, 0, 8);
  3825. $data['keyword'] = implode(',', $segList1);
  3826. }
  3827. if ($data['description'] == '') {
  3828. //提取内容中的描述
  3829. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3830. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3831. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3832. }
  3833. if ($data['status'] == 1) {
  3834. $this->sendMessage([
  3835. 'talk_type' => 200,
  3836. 'title' => $data['name'],
  3837. 'content' => '提交了审核',
  3838. 'messageType' => 3,
  3839. ]);
  3840. }
  3841. $result = Good::insert($data);
  3842. if (empty($result)) {
  3843. return Result::error("添加失败", 0);
  3844. }
  3845. return Result::success($result);
  3846. }
  3847. public function updateGood(array $data): array
  3848. {
  3849. $data['city_id'] = end($data['city_arr_id']);
  3850. $data['catid'] = end($data['cat_arr_id']);
  3851. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3852. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3853. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3854. //设置东八区
  3855. date_default_timezone_set('Asia/Shanghai');
  3856. $data['updated_at'] = date('Y-m-d H:i:s');
  3857. if (isset($data['price']) && $data['price'] == '') {
  3858. $data['price'] = 0;
  3859. }
  3860. if ($data['imgurl'] == '') {
  3861. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3862. preg_match_all($reg, $data['detail'], $matches);
  3863. if (isset($matches[1][0])) {
  3864. //截取varchar240
  3865. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3866. }
  3867. }
  3868. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3869. //提取标题+内容中的关键词
  3870. $data['keyword'] = $data['name'];
  3871. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3872. Jieba::init(); // 初始化 jieba-php
  3873. Finalseg::init();
  3874. $segList = Jieba::cut($data['keyword']);
  3875. $segList1 = array_slice($segList, 0, 8);
  3876. $data['keyword'] = implode(',', $segList1);
  3877. }
  3878. if ($data['description'] == '') {
  3879. //提取内容中的描述
  3880. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3881. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3882. }
  3883. if ($data['status'] == 1) {
  3884. $this->sendMessage([
  3885. 'talk_type' => 200,
  3886. 'title' => $data['name'],
  3887. 'content' => '提交了审核',
  3888. 'messageType' => 3,
  3889. ]);
  3890. }
  3891. $result = Good::where('id', $data['id'])->update($data);
  3892. if (empty($result)) {
  3893. return Result::error("更新失败", 0);
  3894. }
  3895. return Result::success($result);
  3896. }
  3897. public function delGood(array $data): array
  3898. {
  3899. $result = Good::where('id', $data['id'])->delete();
  3900. if (empty($result)) {
  3901. return Result::error("删除失败", 0);
  3902. }
  3903. return Result::success($result);
  3904. }
  3905. //20250226 产品列表
  3906. //20250306 求职信息
  3907. public function getJobHuntingList(array $data): array
  3908. {
  3909. $where = [];
  3910. if (isset($data['username']) && !empty($data['username'])) {
  3911. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3912. }
  3913. //status 1待审核2已审核3已拒绝
  3914. if (isset($data['status']) && $data['status'] != '') {
  3915. $where = [
  3916. 'job_hunting.status' => $data['status'],
  3917. ];
  3918. }
  3919. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3920. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3921. unset($data['type_id']);
  3922. if ($type_id != '10000') {
  3923. $where[] = ['job_hunting.user_id', '=', $user_id];
  3924. }
  3925. $result = JobHunting::where($where)
  3926. ->when(!empty($data['status1']), function ($query) use ($data) {
  3927. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3928. })
  3929. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3930. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3931. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3932. ->orderBy("updated_at", "desc")
  3933. ->limit($data['page_size'])
  3934. ->offset(($data['page'] - 1) * $data['page_size'])
  3935. ->get();
  3936. if (empty($result)) {
  3937. return Result::error("查询失败", 0);
  3938. }
  3939. $count = JobHunting::where($where)
  3940. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3941. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3942. ->count();
  3943. $data = [
  3944. 'rows' => $result->toArray(),
  3945. 'count' => $count,
  3946. ];
  3947. return Result::success($data);
  3948. }
  3949. public function getJobHuntingApply(array $data): array
  3950. {
  3951. var_dump($data, '-----------------test--------1-');
  3952. $where = [];
  3953. if (isset($data['username']) && !empty($data['username'])) {
  3954. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3955. }
  3956. if (isset($data['salary']) && !empty($data['salary'])) {
  3957. $where[] = [
  3958. 'job_hunting.salary',
  3959. '=',
  3960. $data['salary'],
  3961. ];
  3962. }
  3963. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3964. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3965. unset($data['type_id']);
  3966. if ($type_id != '10000') {
  3967. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3968. }
  3969. var_dump($where, '-----------------test---------');
  3970. $result = jobApply::where($where)
  3971. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3972. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3973. // })
  3974. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3975. ->where('job_enum.egroup', '=', 'income')
  3976. ->where('job_hunting.status', 2) //已审核
  3977. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3978. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3979. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3980. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3981. //职位----是申请职位
  3982. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3983. ->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')
  3984. ->orderBy("job_hunting.updated_at", "desc")
  3985. ->limit($data['page_size'])
  3986. ->offset(($data['page'] - 1) * $data['page_size'])
  3987. ->get();
  3988. if (empty($result)) {
  3989. return Result::error("查询失败", 0);
  3990. }
  3991. $count = jobApply::where($where)
  3992. ->where('job_enum.egroup', '=', 'income')
  3993. ->where('job_hunting.status', 2) //已审核
  3994. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3995. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3996. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3997. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3998. //职位----是申请职位
  3999. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4000. ->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')
  4001. ->count();
  4002. $data = [
  4003. 'rows' => $result->toArray(),
  4004. 'count' => $count,
  4005. ];
  4006. return Result::success($data);
  4007. }
  4008. public function addJobHunting(array $data): array
  4009. {
  4010. date_default_timezone_set('Asia/Shanghai');
  4011. unset($data['company_name']);
  4012. unset($data['job_industry']);
  4013. unset($data['job_name']);
  4014. unset($data['department']);
  4015. unset($data['job_timeList']);
  4016. unset($data['job_content']);
  4017. unset($data['job_typename']); //不知道这是啥,
  4018. $data['created_at'] = date('Y-m-d H:i:s');
  4019. $data['updated_at'] = date('Y-m-d H:i:s');
  4020. //根据用户 user_id 只能添加一次
  4021. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4022. if (!empty($result)) {
  4023. return Result::error("您已添加过求职信息", 0);
  4024. }
  4025. var_dump($result, '-----------------test---------');
  4026. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4027. if (is_string($data['city_arr_id'])) {
  4028. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4029. $cityArr = json_decode($data['city_arr_id'], true);
  4030. // 确保 $cityArr 是数组
  4031. if (is_array($cityArr)) {
  4032. $data['city_id'] = end($cityArr);
  4033. }
  4034. } else {
  4035. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4036. if (is_array($data['city_arr_id'])) {
  4037. $data['city_id'] = end($data['city_arr_id']);
  4038. }
  4039. }
  4040. }
  4041. // 处理求职所绑定栏目
  4042. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4043. if (is_string($data['cat_arr_id'])) {
  4044. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4045. // 先清理可能存在的无效 JSON 字符
  4046. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4047. $catArr = json_decode($cleanedCatArrStr, true);
  4048. // 检查 JSON 解码是否成功且结果是数组
  4049. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4050. $data['catid'] = end($catArr);
  4051. }
  4052. } else {
  4053. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4054. if (is_array($data['cat_arr_id'])) {
  4055. $data['catid'] = end($data['cat_arr_id']);
  4056. }
  4057. }
  4058. }
  4059. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4060. $this->sendMessage([
  4061. 'talk_type' => 600,
  4062. 'title' => $data['name'],
  4063. 'content' => '提交了审核',
  4064. 'messageType' => 11,
  4065. ]);
  4066. }
  4067. $result = JobHunting::create($data);
  4068. if (empty($result)) {
  4069. return Result::error("添加失败", 0);
  4070. }
  4071. return Result::success($result);
  4072. }
  4073. public function delJobHunting(array $data): array
  4074. {
  4075. $result = JobHunting::where('id', $data['id'])->delete();
  4076. if (empty($result)) {
  4077. return Result::error("删除失败", 0);
  4078. }
  4079. return Result::success($result);
  4080. }
  4081. public function updateJobHunting(array $data): array
  4082. {
  4083. //设置东八区
  4084. date_default_timezone_set('Asia/Shanghai');
  4085. unset($data['company_name']);
  4086. unset($data['job_industry']);
  4087. unset($data['job_name']);
  4088. unset($data['department']);
  4089. unset($data['job_timeList']);
  4090. unset($data['job_content']);
  4091. unset($data['job_typename']); //不知道这是啥,
  4092. $data['created_at'] = date('Y-m-d H:i:s');
  4093. $data['updated_at'] = date('Y-m-d H:i:s');
  4094. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4095. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4096. $cityArr = json_decode($data['city_arr_id'], true);
  4097. $data['city_id'] = end($cityArr);
  4098. } else {
  4099. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4100. $data['city_id'] = end($data['city_arr_id']);
  4101. }
  4102. // 处理求职所绑定栏目
  4103. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4104. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4105. $catArr = json_decode($data['cat_arr_id'], true);
  4106. $data['catid'] = end($catArr);
  4107. } else {
  4108. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4109. $data['catid'] = end($data['cat_arr_id']);
  4110. }
  4111. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4112. $this->sendMessage([
  4113. 'talk_type' => 600,
  4114. 'title' => $data['name'],
  4115. 'content' => '提交了审核',
  4116. 'messageType' => 11,
  4117. ]);
  4118. }
  4119. $result = JobHunting::where('id', $data['id'])->update($data);
  4120. if (empty($result)) {
  4121. return Result::error("更新失败", 0);
  4122. }
  4123. return Result::success($result);
  4124. }
  4125. public function getJobHuntingInfo(array $data): array
  4126. {
  4127. $result = JobHunting::where('id', $data['id'])->first();
  4128. if (empty($result)) {
  4129. return Result::error("查询失败", 0);
  4130. }
  4131. return Result::success($result);
  4132. }
  4133. public function getJobHuntingData(array $data): array
  4134. {
  4135. $jobEnum = JobEnum::get();
  4136. $jobIndustry = JobIndustry::get();
  4137. $jobNature = JobNature::get();
  4138. $jobPosition = JobPosition::get();
  4139. $data = [
  4140. 'jobEnum' => $jobEnum,
  4141. 'jobIndustry' => $jobIndustry,
  4142. 'jobNature' => $jobNature,
  4143. 'jobPosition' => $jobPosition,
  4144. ];
  4145. return Result::success($data);
  4146. }
  4147. public function delJobHuntingInfo(array $data): array
  4148. {
  4149. $result = JobHunting::where('id', $data['id'])->delete();
  4150. return Result::success();
  4151. }
  4152. //20250324 通知,公告,消息
  4153. public function delNotice(array $data): array
  4154. {
  4155. $result = Notice::where('id', $data['id'])->delete();
  4156. if ($result) {
  4157. return Result::success();
  4158. } else {
  4159. return Result::error("删除失败", 0);
  4160. }
  4161. }
  4162. public function getNoticeInfo(array $data): array
  4163. {
  4164. $result = Notice::where('id', $data['id'])->first();
  4165. // var_dump($result['re_user_ids'], '--------------------');
  4166. if (empty($result)) {
  4167. return Result::error("查询失败", 0);
  4168. }
  4169. return Result::success($result);
  4170. }
  4171. public function readNotice(array $data): array
  4172. {
  4173. $result = Notice::where('id', $data['id'])->first();
  4174. // var_dump($result['re_user_ids'], '--------------------');
  4175. if (empty($result)) {
  4176. return Result::error("查询失败", 0);
  4177. }
  4178. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4179. $re_user_ids = json_decode($result['re_user_ids'], true);
  4180. var_dump($re_user_ids, '--------------1---test---------');
  4181. var_dump($data, '--------------1---test---------');
  4182. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4183. //如果已经存在,就不再添加
  4184. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4185. $read_id = json_decode($result['read_id'], true);
  4186. if (!is_array($read_id)) {
  4187. $read_id = [];
  4188. }
  4189. if (!in_array($data['user_id'], $read_id)) {
  4190. $read_id[] = $data['user_id'];
  4191. $result['read_id'] = json_encode($read_id);
  4192. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4193. }
  4194. } else {
  4195. //如果不存在,就添加
  4196. $result['read_id'] = json_encode([$data['user_id']]);
  4197. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4198. }
  4199. }
  4200. return Result::success($result);
  4201. }
  4202. public function addNotice(array $data): array
  4203. {
  4204. date_default_timezone_set('Asia/Shanghai');
  4205. $data['created_at'] = date('Y-m-d H:i:s');
  4206. $data['updated_at'] = date('Y-m-d H:i:s');
  4207. // $data['level'] = "1,2,3,4,5";
  4208. $level = json_decode($data['level'], true);
  4209. $user_id = UserInfo::
  4210. //city_id不是null
  4211. whereNotNull('city_id')
  4212. ->whereNotNull('department_id')
  4213. ->where(function ($query) use ($data) {
  4214. $query->where(function ($subQuery) use ($data) {
  4215. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4216. });
  4217. })
  4218. ->where(function ($query) use ($data) {
  4219. $query->where(function ($subQuery) use ($data) {
  4220. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4221. });
  4222. })
  4223. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4224. $query->whereIn('level', $level);
  4225. })
  4226. ->pluck('user_id')->toArray();
  4227. $user_id = array_unique($user_id);
  4228. $chat_ids = $user_id;
  4229. $user_id = json_encode($user_id);
  4230. $data['re_user_ids'] = $user_id;
  4231. $this->sendMessage([
  4232. 'talk_type' => 700,
  4233. 'title' => $data['title'],
  4234. 'content' => '提交了审核',
  4235. 'messageType' => 5,
  4236. ]);
  4237. $result = Notice::insertGetId($data);
  4238. if (empty($result)) {
  4239. return Result::error("添加失败", 0);
  4240. }
  4241. return Result::success($result);
  4242. }
  4243. public function updateNotice(array $data): array
  4244. {
  4245. date_default_timezone_set('Asia/Shanghai');
  4246. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4247. $user_id = UserInfo::
  4248. //city_id不是null
  4249. whereNotNull('city_id')
  4250. ->whereNotNull('department_id')
  4251. ->where(function ($query) use ($data) {
  4252. $query->where(function ($subQuery) use ($data) {
  4253. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4254. });
  4255. })
  4256. ->where(function ($query) use ($data) {
  4257. $query->where(function ($subQuery) use ($data) {
  4258. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4259. });
  4260. })
  4261. ->pluck('user_id')->toArray();
  4262. $user_id = array_unique($user_id);
  4263. $user_id = json_encode($user_id);
  4264. $data['re_user_ids'] = $user_id;
  4265. $data['updated_at'] = date('Y-m-d H:i:s');
  4266. $this->sendMessage([
  4267. 'talk_type' => 700,
  4268. 'title' => $data['title'],
  4269. 'content' => '提交了审核',
  4270. 'messageType' => 5,
  4271. ]);
  4272. $result = Notice::where('id', $data['id'])->update($data);
  4273. return Result::success($result);
  4274. }
  4275. public function getNoticeList(array $data): array
  4276. {
  4277. $where = [];
  4278. //title
  4279. if (isset($data['title']) && !empty($data['title'])) {
  4280. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4281. }
  4282. //level
  4283. if (isset($data['level']) && !empty($data['level'])) {
  4284. $where[] = ['notice.level', '=', $data['level']];
  4285. }
  4286. //status
  4287. if (isset($data['status']) && !empty($data['status'])) {
  4288. $where[] = ['notice.status', '=', $data['status']];
  4289. }
  4290. //type
  4291. if (isset($data['type']) && !empty($data['type'])) {
  4292. $where[] = ['notice.type', '=', $data['type']];
  4293. }
  4294. var_dump($data, '------------11111-2----test---------');
  4295. if ($data['type_id'] == 10000) {
  4296. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4297. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4298. })
  4299. ->where($where)
  4300. ->orderBy('updated_at', 'desc')
  4301. ->limit($data['page_size'])
  4302. ->offset(($data['page'] - 1) * $data['page_size'])
  4303. ->get();
  4304. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4305. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4306. })
  4307. ->where($where)
  4308. ->orderBy('updated_at', 'desc')
  4309. ->count();
  4310. } else {
  4311. $result = Notice::where($where)
  4312. // ->where('user_id', $data['user_id'])
  4313. ->Where(function ($query) use ($data) {
  4314. $query->Where(function ($q) use ($data) {
  4315. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4316. ->orWhere('notice.user_id', $data['user_id']);
  4317. });
  4318. })
  4319. ->when(!empty($data['status1']), function ($query) use ($data) {
  4320. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4321. })
  4322. ->orderBy('updated_at', 'desc')
  4323. ->limit($data['page_size'])
  4324. ->offset(($data['page'] - 1) * $data['page_size'])
  4325. ->get();
  4326. $total = Notice::where($where)
  4327. ->when(!empty($data['status1']), function ($query) use ($data) {
  4328. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4329. })
  4330. // ->where('user_id', $data['user_id'])
  4331. ->Where(function ($query) use ($data) {
  4332. $query->Where(function ($q) use ($data) {
  4333. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4334. ->orWhere('notice.user_id', $data['user_id']);
  4335. });
  4336. })
  4337. ->count();
  4338. }
  4339. if (empty($result)) {
  4340. return Result::error("查询失败", 0);
  4341. }
  4342. $data = [
  4343. 'rows' => $result,
  4344. 'count' => $total,
  4345. ];
  4346. return Result::success($data);
  4347. }
  4348. public function noticeList(array $data): array
  4349. {
  4350. $where = [];
  4351. //title
  4352. if (isset($data['title']) && !empty($data['title'])) {
  4353. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4354. }
  4355. //level
  4356. if (isset($data['level']) && !empty($data['level'])) {
  4357. $where[] = ['notice.level', '=', $data['level']];
  4358. }
  4359. //status
  4360. if (isset($data['status']) && !empty($data['status'])) {
  4361. $where[] = ['notice.status', '=', $data['status']];
  4362. }
  4363. //type
  4364. if (isset($data['type']) && !empty($data['type'])) {
  4365. $where[] = ['notice.type', '=', $data['type']];
  4366. }
  4367. var_dump($data, '------------11111-2----test---------');
  4368. if ($data['type_id'] == 10000) {
  4369. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4370. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4371. })
  4372. ->where($where)
  4373. ->orderBy('updated_at', 'desc')
  4374. ->limit($data['page_size'])
  4375. ->offset(($data['page'] - 1) * $data['page_size'])
  4376. ->get();
  4377. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4378. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4379. })
  4380. ->where($where)
  4381. ->orderBy('updated_at', 'desc')
  4382. ->count();
  4383. } else {
  4384. $result = Notice::where($where)
  4385. // ->where('user_id', $data['user_id'])
  4386. ->Where(function ($query) use ($data) {
  4387. $query->Where(function ($q) use ($data) {
  4388. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4389. ->orWhere('notice.user_id', $data['user_id']);
  4390. });
  4391. })
  4392. ->when(!empty($data['status1']), function ($query) use ($data) {
  4393. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4394. })
  4395. ->orderBy('updated_at', 'desc')
  4396. ->limit($data['page_size'])
  4397. ->offset(($data['page'] - 1) * $data['page_size'])
  4398. ->get();
  4399. $total = Notice::where($where)
  4400. ->when(!empty($data['status1']), function ($query) use ($data) {
  4401. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4402. })
  4403. // ->where('user_id', $data['user_id'])
  4404. ->Where(function ($query) use ($data) {
  4405. $query->Where(function ($q) use ($data) {
  4406. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4407. ->orWhere('notice.user_id', $data['user_id']);
  4408. });
  4409. })
  4410. ->count();
  4411. }
  4412. if (empty($result)) {
  4413. return Result::error("查询失败", 0);
  4414. }
  4415. $data = [
  4416. 'rows' => $result,
  4417. 'count' => $total,
  4418. ];
  4419. return Result::success($data);
  4420. }
  4421. public function getNoticeDetail(array $data): array
  4422. {
  4423. $result = Notice::where('id', $data['id'])->first();
  4424. if (empty($result)) {
  4425. return Result::error("查询失败", 0);
  4426. }
  4427. return Result::success($result);
  4428. }
  4429. public function deleteNotice(array $data): array
  4430. {
  4431. $notice = Notice::where('id', $data['id'])->first();
  4432. if (empty($notice)) {
  4433. return Result::error("删除失败", 0);
  4434. }
  4435. $chat_group_id = $notice->group_id;
  4436. if ($chat_group_id) {
  4437. //删除群聊
  4438. ChatGroups::where('id', $chat_group_id)->delete();
  4439. //删除群成员
  4440. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4441. //删除群聊记录
  4442. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4443. }
  4444. $result = Notice::where('id', $data['id'])->delete();
  4445. return Result::success($result);
  4446. }
  4447. public function complaintList(array $data): array
  4448. {
  4449. var_dump($data, '---------1---------');
  4450. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4451. unset($data['type_id']);
  4452. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4453. $where = [];
  4454. if ($type_id != 10000 && empty($data['deal_user'])) {
  4455. // $where['complaint.user_id'] = $user_id;
  4456. }
  4457. if (!empty($data['title'])) {
  4458. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4459. }
  4460. if (!empty($data['department_id'])) {
  4461. $where['complaint.department_id'] = $data['department_id'];
  4462. }
  4463. if (!empty($data['deal'])) {
  4464. $where['complaint.deal'] = $data['deal'];
  4465. }
  4466. if (!empty($data['status'])) {
  4467. $where['complaint.status'] = $data['status'];
  4468. }
  4469. var_dump(!empty($data['deal_user']), '----------1');
  4470. var_dump($where, '----------2');
  4471. $result = Complaint::where($where)
  4472. ->when(!empty($data['status1']), function ($query) use ($data) {
  4473. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4474. })
  4475. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4476. //json re_user_ids data[user_id]是不是在里面
  4477. $query->Where(function ($q) use ($data) {
  4478. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4479. ->where('complaint.status', 2);
  4480. });
  4481. })
  4482. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4483. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4484. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4485. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4486. ->orderBy('updated_at', 'desc')
  4487. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4488. //sql输出
  4489. if (empty($result)) {
  4490. return Result::error("暂无投诉信息", 0);
  4491. }
  4492. // 取出数据
  4493. $rows = $result->items();
  4494. $count = $result->total();
  4495. $responseData = [
  4496. 'rows' => $rows,
  4497. 'count' => $count,
  4498. ];
  4499. return Result::success($responseData);
  4500. }
  4501. public function getComplaintList(array $data): array
  4502. {
  4503. var_dump($data, '00000001000000000000');
  4504. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4505. unset($data['type_id']);
  4506. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4507. $where = [];
  4508. if ($type_id != 10000 && empty($data['deal_user'])) {
  4509. $where['complaint.user_id'] = $user_id;
  4510. }
  4511. if (!empty($data['title'])) {
  4512. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4513. }
  4514. if (!empty($data['department_id'])) {
  4515. $where['complaint.department_id'] = $data['department_id'];
  4516. }
  4517. if (!empty($data['deal'])) {
  4518. $where['complaint.deal'] = $data['deal'];
  4519. }
  4520. if (!empty($data['status'])) {
  4521. $where['complaint.status'] = $data['status'];
  4522. }
  4523. var_dump(!empty($data['deal_user']), '----------1');
  4524. var_dump($where, '----------2');
  4525. $result = Complaint::where($where)
  4526. ->when(!empty($data['status1']), function ($query) use ($data) {
  4527. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4528. })
  4529. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4530. // //json re_user_ids data[user_id]是不是在里面
  4531. // $query->Where(function ($q) use ($data) {
  4532. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4533. // ->where('complaint.status', 2);
  4534. // });
  4535. // })
  4536. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4537. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4538. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4539. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4540. ->orderBy('updated_at', 'desc')
  4541. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4542. //sql输出
  4543. if (empty($result)) {
  4544. return Result::error("暂无投诉信息", 0);
  4545. }
  4546. // 取出数据
  4547. $rows = $result->items();
  4548. $count = $result->total();
  4549. $responseData = [
  4550. 'rows' => $rows,
  4551. 'count' => $count,
  4552. ];
  4553. return Result::success($responseData);
  4554. }
  4555. public function getComplaintInfo(array $data): array
  4556. {
  4557. $result = Complaint::where('id', $data['id'])->first();
  4558. if (empty($result)) {
  4559. return Result::error("查询失败", 0);
  4560. }
  4561. return Result::success($result);
  4562. }
  4563. public function readComplaint(array $data): array
  4564. {
  4565. $result = Complaint::where('id', $data['id'])->first();
  4566. if (empty($result)) {
  4567. return Result::error("查询失败", 0);
  4568. }
  4569. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4570. $re_user_ids = json_decode($result['re_user_ids'], true);
  4571. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4572. //如果已经存在,就不再添加
  4573. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4574. $read_id = json_decode($result['read_id'], true);
  4575. if (!is_array($read_id)) {
  4576. $read_id = [];
  4577. }
  4578. if (!in_array($data['user_id'], $read_id)) {
  4579. $read_id[] = $data['user_id'];
  4580. $result['read_id'] = json_encode($read_id);
  4581. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4582. }
  4583. } else {
  4584. //如果不存在,就添加
  4585. $result['read_id'] = json_encode([$data['user_id']]);
  4586. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4587. }
  4588. }
  4589. return Result::success($result);
  4590. }
  4591. public function addComplaint(array $data): array
  4592. {
  4593. date_default_timezone_set('Asia/Shanghai');
  4594. $data['created_at'] = date('Y-m-d H:i:s');
  4595. $data['updated_at'] = date('Y-m-d H:i:s');
  4596. $this->sendMessage([
  4597. 'talk_type' => 800,
  4598. 'title' => $data['title'],
  4599. 'content' => '提交了审核',
  4600. 'messageType' => 6,
  4601. ]);
  4602. $result = Complaint::create($data);
  4603. return Result::success($result);
  4604. }
  4605. public function updateComplaint(array $data): array
  4606. {
  4607. date_default_timezone_set('Asia/Shanghai');
  4608. $data['updated_at'] = date('Y-m-d H:i:s');
  4609. $user_id = $data['user_id'] ?? 0;
  4610. $type_id = $data['type_id'] ?? 0;
  4611. unset($data['user_id']);
  4612. unset($data['type_id']);
  4613. $this->sendMessage([
  4614. 'talk_type' => 800,
  4615. 'title' => $data['title'],
  4616. 'content' => '提交了审核',
  4617. 'messageType' => 6,
  4618. ]);
  4619. $result = Complaint::where('id', $data['id'])->update($data);
  4620. return Result::success($result);
  4621. }
  4622. public function deleteComplaint(array $data): array
  4623. {
  4624. $result = Complaint::where('id', $data['id'])->delete();
  4625. return Result::success($result);
  4626. }
  4627. public function getComplainInfo(array $data): array
  4628. {
  4629. $result = Complaint::where('id', $data['id'])->first();
  4630. if (empty($result)) {
  4631. return Result::error("查询失败", 0);
  4632. }
  4633. return Result::success($result);
  4634. }
  4635. public function updateComplaintStatus(array $data): array
  4636. {
  4637. date_default_timezone_set('Asia/Shanghai');
  4638. $data['updated_at'] = date('Y-m-d H:i:s');
  4639. $user_id = $data['user_id'] ?? 0;
  4640. $type_id = $data['type_id'] ?? 0;
  4641. unset($data['user_id']);
  4642. unset($data['type_id']);
  4643. //处理, 写入处理人
  4644. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4645. $data['real_deal_user'] = $user_id;
  4646. }
  4647. //如果是deal 23,则判断是不是处理人
  4648. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4649. $complaintInof = Complaint::where('id', $data['id'])
  4650. ->where('real_deal_user', $user_id)
  4651. ->first();
  4652. if (empty($complaintInof)) {
  4653. return Result::error("处理人错误", 0);
  4654. }
  4655. }
  4656. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4657. if ($data['status'] == 1) {
  4658. $this->sendMessage([
  4659. 'talk_type' => 800,
  4660. 'title' => $complaintInfo['title'],
  4661. 'content' => '提交了审核',
  4662. 'messageType' => 6,
  4663. ]);
  4664. }
  4665. if ($data['status'] == 2 && !isset($data['deal'])) {
  4666. $this->sendMessage([
  4667. 'talk_type' => 801,
  4668. 'title' => $complaintInfo['title'],
  4669. 'content' => '审核通过',
  4670. 'messageType' => 6,
  4671. 'user_id' => $complaintInfo['user_id'],
  4672. ]);
  4673. $this->sendMessage([
  4674. 'talk_type' => 802,
  4675. 'title' => $complaintInfo['title'],
  4676. 'content' => '待处理',
  4677. 'messageType' => 6,
  4678. 'user_id' => $complaintInfo['re_user_ids'],
  4679. ]);
  4680. }
  4681. if ($data['status'] == 3 && !isset($data['deal'])) {
  4682. $this->sendMessage([
  4683. 'talk_type' => 801,
  4684. 'title' => $complaintInfo['title'],
  4685. 'content' => '审核拒绝',
  4686. 'messageType' => 6,
  4687. 'user_id' => $complaintInfo['user_id'],
  4688. ]);
  4689. }
  4690. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4691. $this->sendMessage([
  4692. 'talk_type' => 802,
  4693. 'title' => $complaintInfo['title'],
  4694. 'content' => '处理中',
  4695. 'messageType' => 6,
  4696. 'user_id' => $complaintInfo['re_user_ids'],
  4697. ]);
  4698. }
  4699. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4700. $this->sendMessage([
  4701. 'talk_type' => 802,
  4702. 'title' => $complaintInfo['title'],
  4703. 'content' => '不予处理',
  4704. 'messageType' => 6,
  4705. 'user_id' => $complaintInfo['re_user_ids'],
  4706. ]);
  4707. }
  4708. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4709. $this->sendMessage([
  4710. 'talk_type' => 802,
  4711. 'title' => $complaintInfo['title'],
  4712. 'content' => '已完结',
  4713. 'messageType' => 6,
  4714. 'user_id' => $complaintInfo['re_user_ids'],
  4715. ]);
  4716. }
  4717. $result = complaint::where('id', $data['id'])->update($data);
  4718. return Result::success($result);
  4719. }
  4720. public function updateGoodStatus(array $data): array
  4721. {
  4722. $user_id = $data['user_id'] ?? 0;
  4723. $type_id = $data['type_id'] ?? 0;
  4724. unset($data['user_id']);
  4725. unset($data['type_id']);
  4726. $goodInfo = Good::where('id', $data['id'])->first();
  4727. if ($data['status'] == 2) {
  4728. $this->sendMessage([
  4729. 'talk_type' => 201,
  4730. 'title' => $goodInfo['name'],
  4731. 'content' => '审核通过',
  4732. 'messageType' => 3,
  4733. 'user_id' => $goodInfo['user_id'],
  4734. ]);
  4735. }
  4736. if ($data['status'] == 3) {
  4737. $this->sendMessage([
  4738. 'talk_type' => 201,
  4739. 'title' => $goodInfo['name'],
  4740. 'content' => '审核拒绝',
  4741. 'messageType' => 3,
  4742. 'user_id' => $goodInfo['user_id'],
  4743. ]);
  4744. }
  4745. if ($data['status'] == 1) {
  4746. $this->sendMessage([
  4747. 'talk_type' => 200,
  4748. 'title' => $goodInfo['name'],
  4749. 'content' => '提交了审核',
  4750. 'messageType' => 3,
  4751. ]);
  4752. }
  4753. $result = Good::where('id', $data['id'])->update($data);
  4754. return Result::success($result);
  4755. }
  4756. public function updateJobHuntingStatus(array $data): array
  4757. {
  4758. $user_id = $data['user_id'] ?? 0;
  4759. $type_id = $data['type_id'] ?? 0;
  4760. unset($data['user_id']);
  4761. unset($data['type_id']);
  4762. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4763. if ($data['status'] == 2) {
  4764. $this->sendMessage([
  4765. 'talk_type' => 601,
  4766. 'title' => $jogHuntingInfo['name'],
  4767. 'content' => '审核通过',
  4768. 'messageType' => 11,
  4769. 'user_id' => $jogHuntingInfo['user_id'],
  4770. ]);
  4771. }
  4772. if ($data['status'] == 3) {
  4773. $this->sendMessage([
  4774. 'talk_type' => 601,
  4775. 'title' => $jogHuntingInfo['name'],
  4776. 'content' => '审核拒绝',
  4777. 'messageType' => 11,
  4778. 'user_id' => $jogHuntingInfo['user_id'],
  4779. ]);
  4780. }
  4781. if ($data['status'] == 1) {
  4782. $this->sendMessage([
  4783. 'talk_type' => 600,
  4784. 'title' => $jogHuntingInfo['name'],
  4785. 'content' => '提交了审核',
  4786. 'messageType' => 11,
  4787. ]);
  4788. }
  4789. $result = JobHunting::where('id', $data['id'])->update($data);
  4790. return Result::success($result);
  4791. }
  4792. public function updateNoticeStatus(array $data): array
  4793. {
  4794. $user_id = $data['user_id'] ?? 0;
  4795. $type_id = $data['type_id'] ?? 0;
  4796. unset($data['user_id']);
  4797. unset($data['type_id']);
  4798. //查询公告
  4799. $notice = Notice::where('id', $data['id'])->first();
  4800. if (empty($notice)) {
  4801. return Result::error("公告不存在", 0);
  4802. }
  4803. //$chat_ids 去除掉$data['user_id']
  4804. $chat_ids = json_decode($notice['re_user_ids'], true);
  4805. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4806. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4807. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  4808. //chat_group
  4809. $group_id = PublicData::uuid();
  4810. $groupData = [
  4811. 'id' => $group_id,
  4812. 'creator_id' => $notice['user_id'],
  4813. 'group_name' => $notice['group_name'] ?? '',
  4814. 'profile' => $notice['profile'] ?? 0,
  4815. ];
  4816. var_dump($groupData, '-----------------groupData-------');
  4817. $groupResult = ChatGroups::insertGetId($groupData);
  4818. var_dump($groupResult, '-----------------groupid-------');
  4819. $groupMemberData = [
  4820. 'id' => PublicData::uuid(),
  4821. 'user_id' => $notice['user_id'],
  4822. 'group_id' => $group_id,
  4823. 'leader' => 2,
  4824. ];
  4825. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4826. //插入群成员表
  4827. $groupMemberDataUser = [];
  4828. $chatData = [];
  4829. foreach ($chat_ids as $key => $value) {
  4830. $groupMemberDataUser[] = [
  4831. 'id' => PublicData::uuid(),
  4832. 'user_id' => $value,
  4833. 'group_id' => $group_id,
  4834. 'leader' => 1,
  4835. ];
  4836. $chatData[] = [
  4837. 'user_id' => $value,
  4838. 'msg_type' => 1,
  4839. 'receiver_id' => $group_id,
  4840. 'content' => '通过通知创建群聊',
  4841. 'group_receiver_id' => $notice['user_id'],
  4842. 'action' => 'recieved',
  4843. 'created_at' => date('Y-m-d H:i:s'),
  4844. ];
  4845. }
  4846. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4847. ChatGroupsMember::insert($groupMemberDataUser);
  4848. //插入一条管理员聊天记录
  4849. $chatData[] = [
  4850. 'user_id' => $notice['user_id'],
  4851. 'msg_type' => 1,
  4852. 'receiver_id' => $group_id,
  4853. 'content' => '通过通知创建群聊',
  4854. 'group_receiver_id' => $notice['user_id'],
  4855. 'action' => 'said',
  4856. 'created_at' => date('Y-m-d H:i:s'),
  4857. ];
  4858. var_dump($chatData, '-----------------chatData-------');
  4859. $chatResult = ChatRecords::insert($chatData);
  4860. //处理imp
  4861. $group = [
  4862. 'type' => 1,
  4863. 'name' => $notice['group_name'] ?? '',
  4864. 'profile' => '',
  4865. 'avatar' => '',
  4866. 'creator_id' => $notice['user_id'],
  4867. ];
  4868. $groupResult = GroupImp::insertGetId($group);
  4869. var_dump($groupResult, '获取imp group_id');
  4870. $groupMember = [
  4871. 'user_id' => $notice['user_id'],
  4872. 'group_id' => $groupResult,
  4873. 'leader' => 1,
  4874. 'join_time' => Date('Y-m-d H:i:s')
  4875. ];
  4876. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  4877. $talk_session = [
  4878. 'user_id' => $notice['user_id'],
  4879. 'to_from_id' => $groupResult,
  4880. 'talk_mode' => 2,
  4881. 'created_at' => Date('Y-m-d H:i:s'),
  4882. 'updated_at' => Date('Y-m-d H:i:s'),
  4883. ];
  4884. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  4885. //被通知人员处理
  4886. foreach ($chat_ids as $key => $value) {
  4887. $groupMemberdata[] = [
  4888. 'user_id' => $value,
  4889. 'group_id' => $groupResult,
  4890. 'leader' => 3,
  4891. 'join_time' => Date('Y-m-d H:i:s')
  4892. ];
  4893. $talk_sessionData[] = [
  4894. 'user_id' => $value,
  4895. 'to_from_id' => $groupResult,
  4896. 'talk_mode' => 2,
  4897. 'created_at' => Date('Y-m-d H:i:s'),
  4898. 'updated_at' => Date('Y-m-d H:i:s'),
  4899. ];
  4900. }
  4901. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  4902. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  4903. $group_id = $groupResult;
  4904. //更新result的 group_id
  4905. $data['group_id'] = $group_id;
  4906. Notice::where(['id' => $data['id']])->update($data);
  4907. }
  4908. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  4909. //删除掉信息
  4910. GroupImp::where('id', $notice['group_id'])->delete();
  4911. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  4912. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  4913. foreach ($chat_ids as $key => $value) {
  4914. }
  4915. //聊天记录删除
  4916. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  4917. $data['group_id'] = null;
  4918. Notice::where(['id' => $data['id']])->update($data);
  4919. }
  4920. $result = Notice::where('id', $data['id'])->update($data);
  4921. $noticeInfo = Notice::where('id', $data['id'])->first();
  4922. if ($data['status'] == 2) {
  4923. $this->sendMessage([
  4924. 'talk_type' => 701,
  4925. 'title' => $noticeInfo['title'],
  4926. 'content' => '审核通过',
  4927. 'messageType' => 3,
  4928. 'user_id' => $noticeInfo['user_id'],
  4929. ]);
  4930. }
  4931. if ($data['status'] == 3) {
  4932. $this->sendMessage([
  4933. 'talk_type' => 701,
  4934. 'title' => $noticeInfo['title'],
  4935. 'content' => '审核拒绝',
  4936. 'messageType' => 3,
  4937. 'user_id' => $noticeInfo['user_id'],
  4938. ]);
  4939. }
  4940. if ($data['status'] == 1) {
  4941. $this->sendMessage([
  4942. 'talk_type' => 700,
  4943. 'title' => $noticeInfo['title'],
  4944. 'content' => '提交了审核',
  4945. 'messageType' => 3,
  4946. ]);
  4947. }
  4948. return Result::success($result);
  4949. }
  4950. public function getDUser(array $data): array
  4951. {
  4952. if (!empty($data['ids'])) {
  4953. $user = User::whereIn('id', $data['ids'])->getall();
  4954. if (empty($user)) {
  4955. return Result::error('无数据', 0);
  4956. }
  4957. return Result::success($user);
  4958. }
  4959. $where = [];
  4960. if (!empty($data['department_id'])) {
  4961. $where['department_id'] = $data['department_id'];
  4962. }
  4963. if (!empty($data['city_id'])) {
  4964. $where['city_id'] = $data['city_id'];
  4965. }
  4966. $result = User::where('type_id', 2)
  4967. ->where('status', 1)
  4968. ->where($where)
  4969. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4970. ->get();
  4971. if (empty($result)) {
  4972. return Result::error("查询失败", 0);
  4973. }
  4974. return Result::success($result);
  4975. }
  4976. /**
  4977. * 验证导航名称是否重复
  4978. * @return void
  4979. */
  4980. public function checkCategoryName(array $data): array
  4981. {
  4982. $result = Category::when($data, function ($query) use ($data) {
  4983. if (isset($data['name']) && $data['name']) {
  4984. $query->where("name", $data['name']);
  4985. }
  4986. if (isset($data['id']) && $data['id']) {
  4987. $query->where("id", "!=", $data['id']);
  4988. }
  4989. })->first();
  4990. if ($result) {
  4991. return Result::error("已存在");
  4992. } else {
  4993. return Result::success();
  4994. }
  4995. }
  4996. //20250226 产品列表
  4997. // 20250306 -------招聘--------fr
  4998. /*
  4999. * 招聘列表
  5000. * */
  5001. public function getJobRecruitingList(array $data): array
  5002. {
  5003. $where = [];
  5004. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5005. if ($data['checkout'] == 0) {
  5006. $job_status = [0, 2];
  5007. } else {
  5008. $job_status = [1];
  5009. }
  5010. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5011. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5012. }
  5013. $user = User::where('id', $data['user_id'])->first();
  5014. if (empty($user)) {
  5015. return Result::error("用户不存在", 0);
  5016. }
  5017. // 3:企业会员
  5018. if ($user['type_id'] == 3) {
  5019. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5020. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5021. }
  5022. // 如果 $where 为空,则不添加 where 条件
  5023. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5024. return $query->where($where);
  5025. })
  5026. ->whereIn('job_recruiting.status', $job_status)
  5027. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5028. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5029. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5030. ->orderBy("updated_at", "desc")
  5031. ->offset(($data['page'] - 1) * $data['page_size'])
  5032. ->limit($data['page_size'])
  5033. ->get()
  5034. ->all();
  5035. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5036. return $query->where($where);
  5037. })
  5038. ->whereIn('job_recruiting.status', $job_status)
  5039. ->count();
  5040. if (empty($result)) {
  5041. return Result::error("暂无招聘信息", 0);
  5042. }
  5043. return Result::success($result);
  5044. }
  5045. /*
  5046. * 招聘信息添加
  5047. * */
  5048. public function addJobRecruiting(array $data): array
  5049. {
  5050. // var_dump('添加招聘进入news------data',$data);
  5051. // return Result::success($data);
  5052. $user = User::where('user.id', $data['user_id'])
  5053. ->where('user.status', 1)
  5054. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5055. ->select(
  5056. 'user.type_id',
  5057. 'user.mobile',
  5058. 'user.email',
  5059. 'user_info.business_name',
  5060. 'user_info.company_hy_id',
  5061. 'user_info.company_nature',
  5062. 'user_info.company_size',
  5063. 'user_info.introduction',
  5064. 'user_info.real_name',
  5065. 'user_info.company_url',
  5066. 'user_info.address_arr_id',
  5067. 'user_info.address'
  5068. )
  5069. ->first();
  5070. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5071. return Result::error("用户不存在", 0);
  5072. }
  5073. $web = Website::where('id', $data['website_id'])->first();
  5074. if (empty($web)) {
  5075. return Result::error("网站不存在", 0);
  5076. }
  5077. // var_dump('添加招聘进入news---user---user',$user);
  5078. // 处理招聘关键词
  5079. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5080. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5081. } else {
  5082. Jieba::init(); // 初始化 jieba-php
  5083. Finalseg::init();
  5084. $segList = Jieba::cut($data['title']);
  5085. $segList1 = array_slice($segList, 0, 8);
  5086. $data['keyword'] = implode(',', $segList1);
  5087. }
  5088. // return Result::success($user);
  5089. $data['action_id'] = $data['user_id'] ?? null;
  5090. $data['user_type'] = $user['type_id'] ?? null;
  5091. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5092. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5093. $data['catid'] = end($data['cat_arr_id']);
  5094. } else {
  5095. $data['catid'] = 0;
  5096. }
  5097. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5098. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5099. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5100. // 公司地址 管理员必填
  5101. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5102. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5103. // 管理员-企业相关信息
  5104. $company = [
  5105. // 'user_id' => $data['user_id']?? null,
  5106. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5107. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5108. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5109. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5110. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5111. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5112. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5113. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5114. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5115. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5116. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5117. ];
  5118. //去掉相关企业信息
  5119. $job = array_diff_key($data, array_flip(array_keys($company)));
  5120. // var_dump('添加招聘进入news---job---user',$job);
  5121. Db::beginTransaction();
  5122. try {
  5123. // // 先添加职位相关信息
  5124. if ($user['type_id'] == 10000) {
  5125. $job['status'] = 1;
  5126. }
  5127. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5128. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5129. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5130. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5131. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5132. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5133. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5134. // return Result::success($job);
  5135. $jobId = JobRecruiting::insertGetId($job);
  5136. if (empty($jobId)) {
  5137. Db::rollBack();
  5138. return Result::error("添加失败");
  5139. }
  5140. // 添加公司信息
  5141. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5142. $company['job_id'] = $jobId;
  5143. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5144. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5145. if ($user['type_id'] == 10000) {
  5146. // 管理员添加企业信息
  5147. $companyId = JobCompany::insertGetId($company);
  5148. if (empty($companyId)) {
  5149. Db::rollBack();
  5150. return Result::error("添加失败");
  5151. }
  5152. } else {
  5153. // 企业会员添加企业信息
  5154. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5155. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5156. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5157. $company['job_id'] = $jobId;
  5158. $companyId = JobCompany::insertGetId($company);
  5159. if (empty($companyId)) {
  5160. Db::rollBack();
  5161. return Result::error("添加失败");
  5162. }
  5163. }
  5164. Db::commit();
  5165. $result = [
  5166. 'job_id' => $jobId,
  5167. 'company_id' => $companyId,
  5168. ];
  5169. return Result::success($result);
  5170. } catch (\Exception $e) {
  5171. Db::rollBack();
  5172. return Result::error($e->getMessage(), 0);
  5173. }
  5174. // return Result::success($result);
  5175. }
  5176. /*
  5177. * 获取招聘信息详情
  5178. * */
  5179. public function getJobRecruitingInfo(array $data): array
  5180. {
  5181. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5182. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5183. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5184. ->select(
  5185. 'job_recruiting.*',
  5186. 'website.website_name as website_name',
  5187. 'job_company.business_name',
  5188. 'job_company.company_hy_id',
  5189. 'job_company.company_size',
  5190. 'job_company.company_nature',
  5191. 'job_company.introduction',
  5192. 'job_company.real_name',
  5193. 'job_company.mobile',
  5194. 'job_company.company_url',
  5195. 'job_company.address_arr_id',
  5196. 'job_company.address',
  5197. 'job_company.email'
  5198. )
  5199. ->first();
  5200. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5201. if (!empty($cityId)) {
  5202. if (isset($cityId[1]) && $cityId[1] != null) {
  5203. $city = District::where('id', $cityId[1])->first(['name']);
  5204. } else {
  5205. $city = District::where('id', $cityId[0])->first(['name']);
  5206. }
  5207. $result['city'] = $city['name'] ?? '';
  5208. }
  5209. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5210. if (is_array($addressId) && !empty($addressId)) {
  5211. $address = District::whereIn('id', $addressId)
  5212. ->orderBy('level', 'asc')
  5213. ->get(['name'])
  5214. ->pluck('name')
  5215. ->implode('');
  5216. // $job->address_name = $address ?? '';
  5217. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5218. }
  5219. if (empty($result)) {
  5220. return Result::error("招聘信息不存在", 0);
  5221. }
  5222. // return Result::success($job);
  5223. return Result::success($result);
  5224. }
  5225. /*
  5226. * 修改招聘信息
  5227. * */
  5228. public function upJobRecruiting(array $data): array
  5229. {
  5230. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5231. // return Result::success($job);
  5232. if (empty($job)) {
  5233. return Result::error("招聘信息不存在", 0);
  5234. }
  5235. $user = User::where('id', $data['user_id'])->first();
  5236. // return Result::success($user);
  5237. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5238. return Result::error("用户不存在", 0);
  5239. }
  5240. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5241. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5242. }
  5243. // 处理招聘关键词
  5244. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5245. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5246. } else {
  5247. Jieba::init(); // 初始化 jieba-php
  5248. Finalseg::init();
  5249. $segList = Jieba::cut($data['title']);
  5250. $segList1 = array_slice($segList, 0, 8);
  5251. $data['keyword'] = implode(',', $segList1);
  5252. }
  5253. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5254. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5255. $data['catid'] = end($data['cat_arr_id']);
  5256. } else {
  5257. }
  5258. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5259. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5260. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5261. // 公司地址 管理员必填
  5262. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5263. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5264. // 管理员-企业相关信息
  5265. $company = [
  5266. // 'user_id' => $data['user_id']?? null,
  5267. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5268. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5269. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5270. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5271. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5272. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5273. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5274. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5275. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5276. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5277. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5278. ];
  5279. //去掉相关企业信息
  5280. $data = array_diff_key($data, array_flip(array_keys($company)));
  5281. $jobId = $data['id'];
  5282. $web = $data['website_id'];
  5283. $data['action_id'] = $data['user_id'];
  5284. unset($data['user_id']);
  5285. unset($data['user_type']);
  5286. unset($data['id']);
  5287. unset($data['website_id']);
  5288. // return Result::success($data);
  5289. Db::beginTransaction();
  5290. try {
  5291. // 管理员修改招聘信息
  5292. if ($user['type_id'] == 10000) {
  5293. $data['website_id'] = $web;
  5294. $company['website_id'] = $data['website_id'];
  5295. $data['status'] = 1;
  5296. } else {
  5297. $data['status'] = 0;
  5298. }
  5299. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5300. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5301. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5302. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5303. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5304. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5305. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5306. // return Result::success($job);
  5307. // Db::rollBack();
  5308. // return Result::success($company);
  5309. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5310. $this->sendMessage([
  5311. 'talk_type' => 500,
  5312. 'title' => $data['title'],
  5313. 'content' => '提交了审核',
  5314. 'messageType' => 10,
  5315. ]);
  5316. }
  5317. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5318. if (empty($result['job'])) {
  5319. Db::rollBack();
  5320. return Result::error("修改招聘信息失败");
  5321. }
  5322. // 管理员修改企业相关信息
  5323. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5324. if (empty($result['company'])) {
  5325. Db::rollBack();
  5326. return Result::error("修改企业相关信息失败");
  5327. }
  5328. Db::commit();
  5329. // return Result::success($result);
  5330. } catch (\Exception $e) {
  5331. Db::rollBack();
  5332. return Result::error($e->getMessage(), 0);
  5333. }
  5334. return Result::success($result);
  5335. }
  5336. /*
  5337. * 招聘信息删除
  5338. * */
  5339. public function delJobRecruiting(array $data): array
  5340. {
  5341. $user = User::where('id', $data['user_id'])->first();
  5342. if (empty($user)) {
  5343. return Result::error("用户不存在", 0);
  5344. }
  5345. $job = JobRecruiting::where('id', $data['id'])->first();
  5346. if (empty($job)) {
  5347. return Result::error("招聘信息不存在", 0);
  5348. }
  5349. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5350. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5351. }
  5352. Db::beginTransaction();
  5353. try {
  5354. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5355. if (empty($result['job'])) {
  5356. Db::rollBack();
  5357. return Result::error("删除招聘信息失败");
  5358. }
  5359. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5360. if (empty($result['company'])) {
  5361. Db::rollBack();
  5362. return Result::error("删除企业相关信息失败");
  5363. }
  5364. Db::commit();
  5365. } catch (\Exception $e) {
  5366. Db::rollBack();
  5367. return Result::error($e->getMessage(), 0);
  5368. }
  5369. return Result::success($result);
  5370. }
  5371. /*
  5372. * 获取公司信息
  5373. * */
  5374. public function getJobCompany(array $data): array
  5375. {
  5376. $user = User::where('user.id', $data['user_id'])
  5377. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5378. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5379. ->first();
  5380. // return Result::success($user);
  5381. if (empty($user)) {
  5382. return Result::error("用户不存在", 0);
  5383. }
  5384. if ($user['type_id'] == 3) {
  5385. $result = [
  5386. // 'id' => 0,
  5387. 'user_id' => $data['user_id'],
  5388. 'website_id' => $data['website_id'],
  5389. 'business_name' => $user['business_name'], // 企业名称
  5390. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5391. 'company_nature' => $user['company_nature'], // 公司性质
  5392. 'company_size' => $user['company_size'], // 公司规模
  5393. 'introduction' => $user['introduction'], // 公司简介
  5394. 'real_name' => $user['real_name'], // 企业联系人
  5395. 'mobile' => $user['mobile'], // 企业联系电话
  5396. 'company_url' => $user['company_url'], // 企业网址
  5397. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5398. 'address' => $user['address'], // 企业地址
  5399. 'email' => $user['email'], // 企业邮箱
  5400. ];
  5401. } else {
  5402. return Result::error("用户类型错误", 0);
  5403. }
  5404. if (empty($result)) {
  5405. return Result::error("公司信息不存在", 0);
  5406. }
  5407. return Result::success($result);
  5408. }
  5409. /*
  5410. * 修改公司信息
  5411. * */
  5412. public function upJobCompany(array $data): array
  5413. {
  5414. // return Result::success($data);
  5415. $user = User::where('user.id', $data['user_id'])
  5416. ->where('user.status', 1)
  5417. ->select('user.user_name', 'user.type_id')
  5418. ->first();
  5419. if (empty($user)) {
  5420. return Result::error("用户不存在", 0);
  5421. }
  5422. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5423. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5424. $company = [
  5425. 'business_name' => $data['business_name'], // 企业名称
  5426. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5427. 'company_nature' => $data['company_nature'], // 公司性质
  5428. 'company_size' => $data['company_size'], // 公司规模
  5429. 'introduction' => $data['introduction'], // 公司简介
  5430. // 'real_name' => $data['real_name'], // 企业联系人
  5431. 'company_url' => $data['company_url'], // 企业网址
  5432. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5433. 'address' => $data['address'], // 企业详细地址
  5434. // 'email' => $data['email'], // 企业邮箱
  5435. ];
  5436. if ($user['type_id'] == 3) {
  5437. Db::beginTransaction();
  5438. try {
  5439. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5440. 'business_name' => $data['business_name'], // 企业名称
  5441. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5442. 'company_nature' => $data['company_nature'], // 公司性质
  5443. 'company_size' => $data['company_size'], // 公司规模
  5444. 'introduction' => $data['introduction'], // 公司简介
  5445. // 'real_name' => $data['real_name'], // 企业联系人
  5446. 'company_url' => $data['company_url'], // 企业网址
  5447. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5448. 'address' => $data['address'], // 企业详细地址
  5449. ]);
  5450. if (empty($result['userinfo'])) {
  5451. Db::rollBack();
  5452. return Result::error('修改企业会员信息失败!');
  5453. }
  5454. $result['user'] = User::where('id', $data['user_id'])->update([
  5455. 'email' => $data['email'], // 企业邮箱
  5456. ]);
  5457. if (empty($result['user'])) {
  5458. Db::rollBack();
  5459. return Result::error('修改个人中心信息失败!');
  5460. }
  5461. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5462. if (!empty($job_company)) {
  5463. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5464. if (empty($result['job_company'])) {
  5465. Db::rollBack();
  5466. return Result::error('修改企业会员信息失败!');
  5467. }
  5468. }
  5469. Db::commit();
  5470. return Result::success($result);
  5471. } catch (\Exception $e) {
  5472. Db::rollBack();
  5473. return Result::error($e->getMessage(), 0);
  5474. }
  5475. } else {
  5476. return Result::error("用户类型错误", 0);
  5477. }
  5478. }
  5479. /*
  5480. * 获取省-市
  5481. * */
  5482. public function getJobRecruitingArea(array $data): array
  5483. {
  5484. if (isset($data['pid']) && $data['pid'] != null) {
  5485. $result = District::where('pid', $data['pid'])->get()->all();
  5486. } else {
  5487. $result = District::where('level', 1)->get()->all();
  5488. }
  5489. if (empty($result)) {
  5490. return Result::error("暂无此省市", 0);
  5491. }
  5492. return Result::success($result);
  5493. }
  5494. /*
  5495. * 获取行业分类
  5496. * */
  5497. public function getIndustry(array $data): array
  5498. {
  5499. $result = JobIndustry::get()->all();
  5500. if (empty($result)) {
  5501. return Result::error("暂无行业分类", 0);
  5502. }
  5503. return Result::success($result);
  5504. }
  5505. /*
  5506. * 获取职位
  5507. * */
  5508. public function getPositionList(array $data): array
  5509. {
  5510. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5511. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5512. } else {
  5513. $result = JobPosition::where('zwpid', 0)->get()->all();
  5514. }
  5515. if (empty($result)) {
  5516. return Result::error("暂无此职位", 0);
  5517. }
  5518. return Result::success($result);
  5519. }
  5520. /*
  5521. * 获取工作性质-菜单
  5522. * */
  5523. public function getJobNature(array $data): array
  5524. {
  5525. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5526. if (empty($result)) {
  5527. return Result::error("暂无工作性质", 0);
  5528. }
  5529. return Result::success($result);
  5530. }
  5531. /*
  5532. * 获取工作经验-菜单
  5533. * */
  5534. public function getExperience(array $data): array
  5535. {
  5536. $result = JobEnum::where('egroup', 'years')->get()->all();
  5537. if (empty($result)) {
  5538. return Result::error("暂无工作经验", 0);
  5539. }
  5540. return Result::success($result);
  5541. }
  5542. /*
  5543. * 获取学历-菜单
  5544. * */
  5545. public function getEducation(array $data): array
  5546. {
  5547. $result = JobEnum::where('egroup', 'education')->get()->all();
  5548. if (empty($result)) {
  5549. return Result::error("暂无学历", 0);
  5550. }
  5551. return Result::success($result);
  5552. }
  5553. /*
  5554. * 获取薪资-菜单
  5555. * */
  5556. public function getSalary(array $data): array
  5557. {
  5558. $result = JobEnum::where('egroup', 'income')->get()->all();
  5559. if (empty($result)) {
  5560. return Result::error("暂无薪资", 0);
  5561. }
  5562. return Result::success($result);
  5563. }
  5564. /*
  5565. * 获取语言-菜单
  5566. * */
  5567. public function getLanguage(array $data): array
  5568. {
  5569. $result = JobEnum::where('egroup', 'language')->get()->all();
  5570. if (empty($result)) {
  5571. return Result::error("暂无语言", 0);
  5572. }
  5573. return Result::success($result);
  5574. }
  5575. /*
  5576. * 获取掌握程度-菜单
  5577. * */
  5578. public function getLevel(array $data): array
  5579. {
  5580. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5581. if (empty($result)) {
  5582. return Result::error("暂无工作性质", 0);
  5583. }
  5584. return Result::success($result);
  5585. }
  5586. // 公司信息
  5587. /*
  5588. * 获取公司性质-菜单
  5589. * */
  5590. public function getCompanyNature(array $data): array
  5591. {
  5592. $result = JobNature::get()->all();
  5593. if (empty($result)) {
  5594. return Result::error("暂无公司性质", 0);
  5595. }
  5596. return Result::success($result);
  5597. }
  5598. /*
  5599. * 获取公司规模-菜单
  5600. * */
  5601. public function getCompanySize(array $data): array
  5602. {
  5603. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5604. if (empty($result)) {
  5605. return Result::error("暂无公司规模", 0);
  5606. }
  5607. return Result::success($result);
  5608. }
  5609. /*
  5610. * 招聘信息审核
  5611. * */
  5612. public function checkJobRecruiting(array $data): array
  5613. {
  5614. $user = User::where('id', $data['user_id'])->first();
  5615. if (empty($user)) {
  5616. return Result::error("用户不存在", 0);
  5617. }
  5618. $job = JobRecruiting::where('id', $data['id'])->first();
  5619. if (empty($job)) {
  5620. return Result::error("招聘信息不存在", 0);
  5621. }
  5622. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5623. if ($user['type_id'] != 10000) {
  5624. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5625. }
  5626. // 驳回原因
  5627. if ($data['status'] == 2) {
  5628. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5629. }
  5630. $data['action_id'] = $data['user_id'];
  5631. unset($data['user_id']);
  5632. if ($data['status'] == 1) {
  5633. $this->sendMessage([
  5634. 'talk_type' => 501,
  5635. 'title' => $job['title'],
  5636. 'content' => '审核通过',
  5637. 'messageType' => 10,
  5638. 'user_id' => $job['user_id'],
  5639. ]);
  5640. }
  5641. if ($data['status'] == 2) {
  5642. $this->sendMessage([
  5643. 'talk_type' => 501,
  5644. 'title' => $job['title'],
  5645. 'content' => '审核拒绝',
  5646. 'messageType' => 10,
  5647. 'user_id' => $job['user_id'],
  5648. ]);
  5649. }
  5650. if ($data['status'] == 0) {
  5651. $this->sendMessage([
  5652. 'talk_type' => 500,
  5653. 'title' => $job['title'],
  5654. 'content' => '提交了审核',
  5655. 'messageType' => 10,
  5656. ]);
  5657. }
  5658. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5659. if (empty($result)) {
  5660. return Result::error("审核失败", 0);
  5661. }
  5662. return Result::success($result);
  5663. }
  5664. public function myApplyList(array $data): array
  5665. {
  5666. var_dump($data, '------参数');
  5667. $user = User::where('id', $data['user_id'])->first();
  5668. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5669. return Result::error("用户不存在", 0);
  5670. }
  5671. // 1:个人会员 职场机会
  5672. if ($user['type_id'] == 1) {
  5673. $where['user_id'] = $user['id'];
  5674. }
  5675. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5676. $query->where('user_id', $user['id']);
  5677. })
  5678. ->pluck('recruit_id');
  5679. $where = [];
  5680. if (isset($data['salary']) && $data['salary'] != null) {
  5681. $where['job_recruiting.salary'] = $data['salary'];
  5682. }
  5683. if (isset($data['experience']) && $data['experience'] != null) {
  5684. $where['job_recruiting.experience'] = $data['experience'];
  5685. }
  5686. if (isset($data['business_name']) && $data['business_name'] != null) {
  5687. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5688. }
  5689. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5690. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5691. ->where($where);
  5692. // ->count();
  5693. $count = $query->count();
  5694. $query = clone $query;
  5695. $job = $query
  5696. ->leftJoin('job_enum as income_enum', function ($join) {
  5697. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5698. ->where('income_enum.egroup', 'income');
  5699. })
  5700. ->leftJoin('job_enum as years_enum', function ($join) {
  5701. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5702. ->where('years_enum.egroup', 'years');
  5703. })
  5704. // ->where($where)
  5705. ->orderBy('job_recruiting.updated_at', 'desc')
  5706. ->select(
  5707. 'job_recruiting.id',
  5708. 'job_recruiting.title',
  5709. 'job_company.business_name',
  5710. 'income_enum.evalue as salary_evalue',
  5711. 'income_enum.ename as salary_ename',
  5712. 'years_enum.evalue as experience_evalue',
  5713. 'years_enum.ename as experience_ename',
  5714. 'job_recruiting.updated_at'
  5715. )
  5716. ->offset(($data['page'] - 1) * $data['pageSize'])
  5717. ->limit($data['pageSize'])
  5718. ->get()
  5719. ->all();
  5720. if (empty($job)) {
  5721. return Result::error("暂无招聘信息", 0);
  5722. }
  5723. $result = [
  5724. 'row' => $job,
  5725. 'count' => $count,
  5726. ];
  5727. return Result::success($result);
  5728. }
  5729. public function readJobApply(array $data): array
  5730. {
  5731. $result = JobApply::where('id', $data['id'])->first();
  5732. if (empty($result)) {
  5733. return Result::error("查询失败", 0);
  5734. }
  5735. $result = JobApply::where('id', $data['id'])->update([
  5736. 'status' => 2,
  5737. ]);
  5738. return Result::success($result);
  5739. }
  5740. /*
  5741. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5742. * */
  5743. public function getRecruitingList(array $data): array
  5744. {
  5745. $user = User::where('id', $data['user_id'])->first();
  5746. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5747. return Result::error("用户不存在", 0);
  5748. }
  5749. // 1:个人会员 职场机会
  5750. if ($user['type_id'] == 1) {
  5751. $where['user_id'] = $user['id'];
  5752. }
  5753. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5754. $query->where('receiver_id', $user['id']);
  5755. })
  5756. ->pluck('recruit_id');
  5757. // return Result::success($recruitingId);
  5758. $where = [];
  5759. if (isset($data['salary']) && $data['salary'] != null) {
  5760. $where['job_recruiting.salary'] = $data['salary'];
  5761. }
  5762. if (isset($data['experience']) && $data['experience'] != null) {
  5763. $where['job_recruiting.experience'] = $data['experience'];
  5764. }
  5765. if (isset($data['business_name']) && $data['business_name'] != null) {
  5766. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5767. }
  5768. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5769. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5770. ->where($where);
  5771. // ->count();
  5772. $count = $query->count();
  5773. $query = clone $query;
  5774. $job = $query
  5775. ->leftJoin('job_enum as income_enum', function ($join) {
  5776. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5777. ->where('income_enum.egroup', 'income');
  5778. })
  5779. ->leftJoin('job_enum as years_enum', function ($join) {
  5780. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5781. ->where('years_enum.egroup', 'years');
  5782. })
  5783. // ->where($where)
  5784. ->orderBy('job_recruiting.updated_at', 'desc')
  5785. ->select(
  5786. 'job_recruiting.id',
  5787. 'job_recruiting.title',
  5788. 'job_company.business_name',
  5789. 'income_enum.evalue as salary_evalue',
  5790. 'income_enum.ename as salary_ename',
  5791. 'years_enum.evalue as experience_evalue',
  5792. 'years_enum.ename as experience_ename',
  5793. 'job_recruiting.updated_at'
  5794. )
  5795. ->offset(($data['page'] - 1) * $data['pageSize'])
  5796. ->limit($data['pageSize'])
  5797. ->get()
  5798. ->all();
  5799. if (empty($job)) {
  5800. return Result::error("暂无招聘信息", 0);
  5801. }
  5802. $result = [
  5803. 'row' => $job,
  5804. 'count' => $count,
  5805. ];
  5806. return Result::success($result);
  5807. }
  5808. /*
  5809. * 获取企业会员-招聘信息列表
  5810. * */
  5811. public function getRecruitingInfo(array $data): array
  5812. {
  5813. $user = User::where('id', $data['user_id'])->first();
  5814. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5815. return Result::error("用户不存在", 0);
  5816. }
  5817. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5818. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5819. ->select(
  5820. 'job_recruiting.*',
  5821. 'job_company.business_name',
  5822. 'job_company.company_hy_id',
  5823. 'job_company.company_size',
  5824. 'job_company.company_nature',
  5825. 'job_company.introduction',
  5826. 'job_company.real_name',
  5827. 'job_company.mobile',
  5828. 'job_company.company_url',
  5829. 'job_company.address_arr_id',
  5830. 'job_company.address',
  5831. 'job_company.email'
  5832. )
  5833. ->get();
  5834. if (empty($recruiting)) {
  5835. return Result::error("暂无招聘信息", 0);
  5836. }
  5837. return Result::success($recruiting);
  5838. }
  5839. /*
  5840. * 获取企业会员-我的沟通
  5841. * */
  5842. public function getJobResumeList(array $data): array
  5843. {
  5844. $user = User::where('id', $data['user_id'])->first();
  5845. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5846. return Result::error("用户不存在", 0);
  5847. }
  5848. $where = [];
  5849. if (isset($data['salary']) && $data['salary'] != null) {
  5850. $where['job_hunting.salary'] = $data['salary'];
  5851. }
  5852. if (isset($data['user_name']) && $data['user_name'] != null) {
  5853. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5854. }
  5855. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5856. $query->where('job_resume.user_id', $user['id']);
  5857. })
  5858. ->when(!empty($where), function ($query) use ($where) {
  5859. $query->where($where);
  5860. })
  5861. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5862. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5863. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5864. ->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');
  5865. $count = $job->count();
  5866. if ($count == 0) {
  5867. return Result::error("暂无沟通记录", 0);
  5868. }
  5869. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5870. ->offset(($data['page'] - 1) * $data['pageSize'])
  5871. ->limit($data['pageSize'])
  5872. ->get();
  5873. if (empty($jobs)) {
  5874. return Result::error("暂无沟通记录", 0);
  5875. }
  5876. $result['row'] = $this->processJob($jobs, '');
  5877. $result['count'] = $count;
  5878. return Result::success($result);
  5879. }
  5880. public function readJobResume(array $data): array
  5881. {
  5882. $result = JobResume::where('id', $data['id'])->first();
  5883. if (empty($result)) {
  5884. return Result::error("查询失败", 0);
  5885. }
  5886. $result = JobResume::where('id', $data['id'])->update([
  5887. 'status' => 2,
  5888. ]);
  5889. return Result::success($result);
  5890. }
  5891. // 20250306 招聘
  5892. //20250422 书刊音像
  5893. public function addBook(array $data): array
  5894. {
  5895. $user_id = $data['user_id'] ?? 0;
  5896. $type_id = $data['type_id'] ?? 0;
  5897. // $website_id = $data['website_id'] ?? 0;
  5898. // unset($data['user_id']);
  5899. unset($data['type_id']);
  5900. // unset($data['website_id']);
  5901. //处理数组
  5902. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5903. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5904. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5905. if ($data['img_url'] == '') {
  5906. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5907. preg_match_all($reg, $data['detail'], $matches);
  5908. if (isset($matches[1][0])) {
  5909. //截取varchar240
  5910. $data['img_url'] = substr($matches[1][0], 0, 240);
  5911. }
  5912. }
  5913. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5914. //提取标题+内容中的关键词
  5915. $data['keyword'] = $data['title'];
  5916. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5917. Jieba::init(); // 初始化 jieba-php
  5918. Finalseg::init();
  5919. $segList = Jieba::cut($data['keyword']);
  5920. $segList1 = array_slice($segList, 0, 8);
  5921. $data['keyword'] = implode(',', $segList1);
  5922. }
  5923. if ($data['description'] == '') {
  5924. //提取内容中的描述
  5925. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5926. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5927. }
  5928. var_dump($data, '--');
  5929. if ($data['status'] == 1) {
  5930. $this->sendMessage([
  5931. 'talk_type' => 400,
  5932. 'title' => $data['title'],
  5933. 'content' => '提交了审核',
  5934. 'messageType' => 7,
  5935. ]);
  5936. }
  5937. $result = Book::insertGetId($data);
  5938. if (empty($result)) {
  5939. return Result::error("添加失败", 0);
  5940. }
  5941. return Result::success($result);
  5942. }
  5943. public function getBookList(array $data): array
  5944. {
  5945. $where = [];
  5946. if (!empty($data["title"])) {
  5947. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5948. }
  5949. if (!empty($data['website_name'])) {
  5950. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5951. }
  5952. if (!empty($data['status'])) {
  5953. $where[] = ['book.status', '=', $data['status']];
  5954. }
  5955. $user_id = $data['user_id'];
  5956. $type_id = $data['type_id'];
  5957. // $type_id = 4;
  5958. var_dump($type_id, '------1--------');
  5959. if ($type_id != 10000) {
  5960. $where[] = ['book.user_id', '=', $user_id];
  5961. }
  5962. var_dump(!empty($data['status1']), '=-===1');
  5963. $result = Book::where($where)
  5964. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5965. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5966. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5967. ->when(isset($data['status1']), function ($query) use ($data) {
  5968. $query->whereIn('book.status', [1, 3]);
  5969. })
  5970. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5971. ->orderBy("updated_at", "desc")
  5972. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5973. if (empty($result)) {
  5974. return Result::error("暂无数据", 0);
  5975. }
  5976. // 取出数据
  5977. $rows = $result->items();
  5978. $count = $result->total();
  5979. $responseData = [
  5980. 'rows' => $rows,
  5981. 'count' => $count,
  5982. ];
  5983. return Result::success($responseData);
  5984. }
  5985. public function deleteBook(array $data): array
  5986. {
  5987. $result = Book::where('id', $data['id'])->delete();
  5988. if (empty($result)) {
  5989. return Result::error("删除失败", 0);
  5990. }
  5991. return Result::success($result);
  5992. }
  5993. public function updateBook(array $data): array
  5994. {
  5995. // $user_id = $data['user_id'] ?? 0;
  5996. $type_id = $data['type_id'] ?? 0;
  5997. // $website_id = $data['website_id'] ?? 0;
  5998. unset($data['user_id']);
  5999. unset($data['type_id']);
  6000. // unset($data['website_id']);
  6001. //处理数组
  6002. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6003. if ($data['img_url'] == '') {
  6004. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6005. preg_match_all($reg, $data['detail'], $matches);
  6006. if (isset($matches[1][0])) {
  6007. //截取varchar240
  6008. $data['img_url'] = substr($matches[1][0], 0, 240);
  6009. }
  6010. }
  6011. if ($data['keyword'] == '') {
  6012. //提取标题+内容中的关键词
  6013. $data['keyword'] = $data['title'];
  6014. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6015. Jieba::init(); // 初始化 jieba-php
  6016. Finalseg::init();
  6017. $segList = Jieba::cut($data['keyword']);
  6018. $segList1 = array_slice($segList, 0, 8);
  6019. $data['keyword'] = implode(',', $segList1);
  6020. }
  6021. if ($data['description'] == '') {
  6022. //提取内容中的描述
  6023. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6024. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6025. }
  6026. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6027. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6028. if ($data['status'] == 1) {
  6029. $this->sendMessage([
  6030. 'talk_type' => 400,
  6031. 'title' => $data['title'],
  6032. 'content' => '提交了审核',
  6033. 'messageType' => 7,
  6034. ]);
  6035. }
  6036. $result = Book::where("id", $data["id"])->update($data);
  6037. if (empty($result)) {
  6038. return Result::error("更新失败", 0);
  6039. }
  6040. return Result::success($result);
  6041. }
  6042. public function getBookInfo(array $data): array
  6043. {
  6044. $result = Book::where("id", $data["id"])->first();
  6045. if (empty($result)) {
  6046. return Result::error("获取失败", 0);
  6047. }
  6048. return Result::success($result);
  6049. }
  6050. public function updateBookStatus(array $data): array
  6051. {
  6052. //审核
  6053. unset($data['user_id']);
  6054. $bookInfo = Book::where("id", $data["id"])->first();
  6055. var_dump($bookInfo, '----');
  6056. if ($data['status'] == 2) {
  6057. $this->sendMessage([
  6058. 'talk_type' => 401,
  6059. 'title' => $bookInfo['title'],
  6060. 'content' => '审核通过',
  6061. 'messageType' => 7,
  6062. 'user_id' => $bookInfo['user_id'],
  6063. ]);
  6064. }
  6065. if ($data['status'] == 3) {
  6066. $this->sendMessage([
  6067. 'talk_type' => 401,
  6068. 'title' => $bookInfo['title'],
  6069. 'content' => '审核拒绝',
  6070. 'messageType' => 7,
  6071. 'user_id' => $bookInfo['user_id'],
  6072. ]);
  6073. }
  6074. if ($data['status'] == 1) {
  6075. $this->sendMessage([
  6076. 'talk_type' => 400,
  6077. 'title' => $bookInfo['title'],
  6078. 'content' => '提交了审核',
  6079. 'messageType' => 7,
  6080. // 'user_id'=>$bookInfo['user_id'],
  6081. ]);
  6082. }
  6083. $result = Book::where("id", $data["id"])->update($data);
  6084. if (empty($result)) {
  6085. return Result::error("更新失败", 0);
  6086. }
  6087. return Result::success($result);
  6088. }
  6089. //20250422 书刊音像
  6090. /**
  6091. * 贴身宝贝
  6092. * @param array $data
  6093. * @return array
  6094. */
  6095. public function getWebsiteTsbb(array $data): array
  6096. {
  6097. $month = $data['month'] ?? date('m');
  6098. $day = $data['day'] ?? date('d');
  6099. // 使用缓存键
  6100. $cacheKey = "tsbb_data_{$month}_{$day}";
  6101. // 尝试从缓存获取数据
  6102. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6103. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6104. if ($cachedData = $cache->get($cacheKey)) {
  6105. return Result::success(unserialize($cachedData));
  6106. }
  6107. //查询老黄历
  6108. try {
  6109. $date = date('Y-m-d');
  6110. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6111. // 使用 curl 替代 file_get_contents
  6112. $ch = curl_init();
  6113. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6114. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6115. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6116. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6117. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6118. 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');
  6119. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6120. 'Accept: application/json',
  6121. 'Content-Type: application/json',
  6122. 'Referer: https://www.36jxs.com/'
  6123. ]);
  6124. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6125. curl_setopt($ch, CURLOPT_ENCODING, '');
  6126. $almanacResponse = curl_exec($ch);
  6127. var_dump("====:", $almanacResponse);
  6128. if (curl_errno($ch)) {
  6129. var_dump('Curl error:', curl_error($ch));
  6130. throw new \Exception('Curl error: ' . curl_error($ch));
  6131. }
  6132. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6133. curl_close($ch);
  6134. if ($almanacResponse === false) {
  6135. throw new \Exception('Failed to fetch almanac data');
  6136. }
  6137. $almanacData = json_decode($almanacResponse, true);
  6138. if (json_last_error() !== JSON_ERROR_NONE) {
  6139. throw new \Exception('Failed to parse almanac data');
  6140. }
  6141. $almanacInfo = $almanacData['data'] ?? [];
  6142. } catch (\Exception $e) {
  6143. var_dump('Exception:', $e->getMessage());
  6144. $almanacInfo = [];
  6145. }
  6146. // 获取历史上的今天数据
  6147. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6148. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6149. ->orderBy('year', 'asc')
  6150. ->select("title", "id", "year", DB::raw('1 as type'))
  6151. ->limit(16)
  6152. ->get();
  6153. // 获取节日数据 - 从今天开始获取未来4条
  6154. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6155. ->orderBy('showtime', 'asc')
  6156. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6157. ->limit(16)
  6158. ->get();
  6159. //说文解字
  6160. $chartacterList = Character::orderBy('updated_at', 'desc')
  6161. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6162. ->limit(6)
  6163. ->get();
  6164. //谜语沙龙
  6165. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6166. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6167. ->limit(4)
  6168. ->get();
  6169. //成语欣赏
  6170. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6171. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6172. ->limit(32)
  6173. ->get();
  6174. //名联赏析
  6175. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6176. ->select("id", "first", "second", DB::raw('6 as type'))
  6177. ->limit(6)
  6178. ->get();
  6179. // 获取分类文章数据
  6180. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6181. ->pluck('category_id')
  6182. ->toArray();
  6183. $articlesList = [];
  6184. foreach ($categoryIds as $catid) {
  6185. // 先查有图片的
  6186. $withImg = DB::table('article')
  6187. ->where('status', 1)
  6188. ->where('catid', $catid)
  6189. ->whereNotNull('imgurl')
  6190. ->where('imgurl', '!=', '')
  6191. ->orderBy('updated_at', 'desc')
  6192. ->limit(6)
  6193. ->get();
  6194. $count = $withImg->count();
  6195. if ($count < 6) {
  6196. // 不足6条再查无图片的补足
  6197. $withoutImg = DB::table('article')
  6198. ->where('status', 1)
  6199. ->where('catid', $catid)
  6200. ->where(function ($q) {
  6201. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6202. })
  6203. ->orderBy('updated_at', 'desc')
  6204. ->limit(6 - $count)
  6205. ->get();
  6206. $articles = $withImg->concat($withoutImg);
  6207. } else {
  6208. $articles = $withImg;
  6209. }
  6210. // 组装
  6211. $category = \App\Model\Category::find($catid);
  6212. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6213. $articlesList[] = [
  6214. 'category_name' => $category ? $category->name : '',
  6215. 'catid' => $catid,
  6216. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6217. 'type' => 100,
  6218. 'list' => $articles->map(function ($item) {
  6219. return [
  6220. 'id' => $item->id,
  6221. 'title' => $item->title,
  6222. 'imgurl' => $item->imgurl,
  6223. 'created_at' => $item->created_at
  6224. ];
  6225. })->values()
  6226. ];
  6227. }
  6228. $result = [
  6229. 'almanac' => $almanacInfo,
  6230. 'historyTodayList' => [
  6231. 'category_name' => '历史上的今天',
  6232. 'list' => $historyTodayList,
  6233. 'type' => 1
  6234. ],
  6235. 'festivalList' => [
  6236. 'category_name' => '节日预告',
  6237. 'list' => $festivalList,
  6238. 'type' => 2
  6239. ],
  6240. 'chartacterList' => [
  6241. 'category_name' => '说文解字',
  6242. 'list' => $chartacterList,
  6243. 'type' => 3
  6244. ],
  6245. 'coupletList' => [
  6246. 'category_name' => '名联赏析',
  6247. 'list' => $coupletList,
  6248. 'type' => 6
  6249. ],
  6250. 'riddletList' => [
  6251. 'category_name' => '谜语沙龙',
  6252. 'list' => $riddletList,
  6253. 'type' => 4
  6254. ],
  6255. 'idiomList' => [
  6256. 'category_name' => '成语欣赏',
  6257. 'list' => $idiomList,
  6258. 'type' => 5
  6259. ],
  6260. 'articlesList' => $articlesList
  6261. ];
  6262. // 缓存结果,设置1小时过期
  6263. $cache->set($cacheKey, serialize($result), 3600);
  6264. return Result::success($result);
  6265. }
  6266. /**
  6267. * 获取资讯列表
  6268. */
  6269. public function getWebsiteTsbbList(array $data): array
  6270. {
  6271. $page = $data['page'] ?? 1;
  6272. $pageSize = $data['pageSize'] ?? 10;
  6273. // 如果没有传入月份和日期,则使用今天的日期
  6274. $month = $data['month'] ?? date('m');
  6275. $day = $data['day'] ?? date('d');
  6276. $total = 0;
  6277. $result = [];
  6278. $data['type'] = intval($data['type']);
  6279. var_dump("接收参数:", $data);
  6280. switch ($data['type']) {
  6281. case 1:
  6282. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6283. // 当前月份之后的数据
  6284. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6285. // 或者当前月份且日期大于等于当前日期的数据
  6286. ->orWhere(function ($q) use ($month, $day) {
  6287. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6288. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6289. });
  6290. })
  6291. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6292. $total = $query->count();
  6293. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6294. ->offset(($page - 1) * $pageSize)
  6295. ->limit($pageSize)
  6296. ->get();
  6297. break;
  6298. case 2:
  6299. $query = Festival::where(function ($q) use ($month, $day) {
  6300. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6301. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6302. ->orWhere(function ($q) use ($month, $day) {
  6303. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6304. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6305. });
  6306. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6307. $total = $query->count();
  6308. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6309. ->offset(($page - 1) * $pageSize)
  6310. ->limit($pageSize)
  6311. ->get();
  6312. break;
  6313. case 3:
  6314. $query = Character::orderBy("updated_at", "desc");
  6315. $total = $query->count();
  6316. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6317. ->offset(($page - 1) * $pageSize)
  6318. ->limit($pageSize)
  6319. ->get();
  6320. break;
  6321. case 4:
  6322. $query = Riddle::orderBy("updated_at", "desc");
  6323. $total = $query->count();
  6324. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6325. ->offset(($page - 1) * $pageSize)
  6326. ->limit($pageSize)
  6327. ->get();
  6328. break;
  6329. case 5:
  6330. $query = Idiom::orderBy("updated_at", "desc");
  6331. $total = $query->count();
  6332. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6333. ->offset(($page - 1) * $pageSize)
  6334. ->limit($pageSize)
  6335. ->get();
  6336. break;
  6337. case 6:
  6338. $query = Couplet::orderBy("updated_at", "desc");
  6339. $total = $query->count();
  6340. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6341. ->offset(($page - 1) * $pageSize)
  6342. ->limit($pageSize)
  6343. ->get();
  6344. break;
  6345. default:
  6346. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6347. $total = $query->count();
  6348. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6349. ->offset(($page - 1) * $pageSize)
  6350. ->limit($pageSize)
  6351. ->get();
  6352. }
  6353. return Result::success([
  6354. 'list' => $result,
  6355. 'total' => $total,
  6356. 'page' => (int)$page,
  6357. 'pageSize' => (int)$pageSize,
  6358. 'month' => $month,
  6359. 'day' => $day
  6360. ]);
  6361. }
  6362. /**
  6363. * 1:历史上的今天
  6364. * 2:节日
  6365. * 3:文章
  6366. *
  6367. * 资讯详情信息
  6368. */
  6369. public function getWebsiteTsbbDetail(array $data): array
  6370. {
  6371. $data['type'] = intval($data['type']);
  6372. switch ($data['type']) {
  6373. case 1:
  6374. $result = HistoryToday::where("id", $data['id'])->first();
  6375. break;
  6376. case 2:
  6377. $result = Festival::where("id", $data['id'])->first();
  6378. break;
  6379. case 3:
  6380. $result = Character::where("id", $data['id'])->first();
  6381. break;
  6382. case 4:
  6383. $result = Riddle::where("id", $data['id'])->first();
  6384. break;
  6385. case 5:
  6386. $result = Idiom::where("id", $data['id'])->first();
  6387. break;
  6388. case 6:
  6389. $result = Couplet::where("id", $data['id'])->first();
  6390. break;
  6391. default:
  6392. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6393. break;
  6394. }
  6395. return Result::success($result);
  6396. }
  6397. /**
  6398. * 农网导航首页数据
  6399. */
  6400. public function getWebsiteNwHomeList(array $data): array
  6401. {
  6402. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6403. ->pluck('category_id')
  6404. ->toArray();
  6405. // 使用子查询优化
  6406. $articlesList = DB::table('article')
  6407. ->select([
  6408. 'article.id',
  6409. 'article.title',
  6410. 'article.imgurl',
  6411. 'article.created_at',
  6412. 'category.name as category_name',
  6413. 'category.id as category_id',
  6414. 'website_category.aLIas_pinyin as pinyin',
  6415. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6416. DB::raw('100 as type')
  6417. ])
  6418. ->join('category', 'article.catid', '=', 'category.id')
  6419. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6420. ->leftJoin('website_category as parent_wc', function ($join) {
  6421. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6422. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6423. })
  6424. ->where('website_category.website_id', $data['website_id'])
  6425. ->where('article.status', 1)
  6426. ->whereIn('category.id', $categoryIds)
  6427. ->orderBy('article.created_at', 'desc')
  6428. ->get()
  6429. ->groupBy('category_id')
  6430. ->map(function ($group) {
  6431. // 确保第一条数据有图片
  6432. $firstWithImage = $group->first(function ($item) {
  6433. return !empty($item->imgurl);
  6434. });
  6435. if ($firstWithImage) {
  6436. // 如果有带图片的文章,将其放在第一位
  6437. $group = $group->filter(function ($item) use ($firstWithImage) {
  6438. return $item->id !== $firstWithImage->id;
  6439. })->prepend($firstWithImage);
  6440. }
  6441. return [
  6442. 'category_name' => $group->first()->category_name,
  6443. 'catid' => $group->first()->category_id,
  6444. 'pinyin' => $group->first()->pinyin,
  6445. 'parent_pinyin' => $group->first()->parent_pinyin,
  6446. 'list' => $group->take(4)->map(function ($item) {
  6447. return [
  6448. 'id' => $item->id,
  6449. 'title' => $item->title,
  6450. ];
  6451. })->values()
  6452. ];
  6453. })
  6454. ->values()
  6455. ->toArray();
  6456. return Result::success($articlesList);
  6457. }
  6458. /**
  6459. * 企业管理
  6460. * @param array $data
  6461. * @return array
  6462. */
  6463. public function getCompanyList(array $data): array
  6464. {
  6465. // return Result::success($data);
  6466. $where = [];
  6467. $user = User::where('id', $data['user_id'])->first();
  6468. if (empty($user)) {
  6469. return Result::error('用户不存在!');
  6470. }
  6471. if ($user['type_id'] != 10000) {
  6472. $where['user_id'] = $data['user_id'];
  6473. }
  6474. if (isset($data['title']) && !empty($data['title'])) {
  6475. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6476. }
  6477. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6478. array_push($where, ['website.id', $data['website_id']]);
  6479. }
  6480. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6481. if ($data['ischeck'] == 1) {
  6482. if (isset($data['status']) && $data['status'] != '') {
  6483. array_push($where, ['company.status', $data['status']]);
  6484. $query = Company::where($where);
  6485. } else {
  6486. $query = Company::whereIn('company.status', [0, 2]);
  6487. }
  6488. } else {
  6489. $query = Company::where('company.status', 1);
  6490. }
  6491. }
  6492. $result = $query->where($where)
  6493. ->leftJoin('website_category', function ($query) {
  6494. $query->on('website_category.category_id', '=', 'company.category_id')
  6495. ->on('website_category.website_id', '=', 'company.website_id');
  6496. })
  6497. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6498. ->select(
  6499. 'company.id',
  6500. 'company.title',
  6501. 'company.website_id',
  6502. 'company.category_id',
  6503. 'website.website_name',
  6504. 'website_category.alias as category_name',
  6505. 'company.status',
  6506. 'company.updated_at',
  6507. 'company.user_id'
  6508. )
  6509. ->orderBy('company.updated_at', 'desc')
  6510. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6511. if ($result->isEmpty()) {
  6512. return Result::error("暂无企业", 0);
  6513. }
  6514. return Result::success($result);
  6515. }
  6516. /**
  6517. * 添加企业
  6518. * @param array $data
  6519. * @return array
  6520. */
  6521. public function addCompany(array $data): array
  6522. {
  6523. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6524. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6525. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6526. $data['cat_arr_id'] = json_encode($car_arr_id);
  6527. } else {
  6528. $data['cat_arr_id'] = '';
  6529. }
  6530. if ($data['imgurl'] == '') {
  6531. //content中提取图片第一个图,正则提取
  6532. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6533. preg_match_all($reg, $data['content'], $matches);
  6534. if (isset($matches[1][0])) {
  6535. //截取varchar240
  6536. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6537. }
  6538. }
  6539. if ($data['keyword'] == '') {
  6540. //提取标题+内容中的关键词
  6541. $data['keyword'] = $data['title'];
  6542. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6543. Jieba::init(); // 初始化 jieba-php
  6544. Finalseg::init();
  6545. $segList = Jieba::cut($data['keyword']);
  6546. $segList1 = array_slice($segList, 0, 8);
  6547. $data['keyword'] = implode(',', $segList1);
  6548. }
  6549. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6550. //提取内容中的描述
  6551. $content = $data['content'];
  6552. // 去除 <style> 和 <script> 标签及其内容
  6553. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6554. // 去除所有 HTML 标签
  6555. $content = strip_tags($content);
  6556. // 去除 HTML 实体
  6557. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6558. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6559. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6560. // 去除多余空白
  6561. $content = preg_replace('/\s+/u', '', $content);
  6562. // 截取 100 个字符
  6563. $data['introduce'] = mb_substr($content, 0, 100);
  6564. }
  6565. $user = User::where('id', $data['user_id'])->first();
  6566. if (empty($user)) {
  6567. return Result::error('用户不存在!');
  6568. }
  6569. if ($user['type_id'] == 10000) {
  6570. $data['status'] = 1;
  6571. }
  6572. if (isset($data['level']) && $data['level'] != null) {
  6573. $data['level'] = intval($data['level']);
  6574. } else {
  6575. $data['level'] = null;
  6576. }
  6577. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6578. $this->sendMessage([
  6579. 'talk_type' => 900,
  6580. 'title' => $data['title'],
  6581. 'content' => '提交了审核',
  6582. 'messageType' => 8,
  6583. ]);
  6584. }
  6585. $result = Company::insertGetId($data);
  6586. if ($result) {
  6587. return Result::success($result);
  6588. } else {
  6589. return Result::error('添加失败');
  6590. }
  6591. }
  6592. /**
  6593. * 更新企业
  6594. * @param array $data
  6595. * @return array
  6596. */
  6597. public function upCompany(array $data): array
  6598. {
  6599. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6600. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6601. $data['cat_arr_id'] = json_encode($car_arr_id);
  6602. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6603. } else {
  6604. $data['cat_arr_id'] = '';
  6605. }
  6606. if ($data['imgurl'] == '') {
  6607. //content中提取图片第一个图,正则提取
  6608. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6609. preg_match_all($reg, $data['content'], $matches);
  6610. if (isset($matches[1][0])) {
  6611. //截取varchar
  6612. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6613. }
  6614. }
  6615. if ($data['keyword'] == '') {
  6616. //提取标题+内容中的关键词
  6617. $data['keyword'] = $data['title'];
  6618. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6619. Jieba::init(); // 初始化 jieba-php
  6620. Finalseg::init();
  6621. $segList = Jieba::cut($data['keyword']);
  6622. $segList1 = array_slice($segList, 0, 8);
  6623. $data['keyword'] = implode(',', $segList1);
  6624. }
  6625. if ($data['introduce'] == '') {
  6626. //提取内容中的描述
  6627. $content = $data['content'];
  6628. // 去除 <style> 和 <script> 标签及其内容
  6629. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6630. // 去除所有 HTML 标签
  6631. $content = strip_tags($content);
  6632. // 去除 HTML 实体
  6633. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6634. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6635. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6636. // 去除多余空白
  6637. $content = preg_replace('/\s+/u', '', $content);
  6638. // 截取 100 个字符
  6639. $data['introduce'] = mb_substr($content, 0, 100);
  6640. }
  6641. if (isset($data['level']) && $data['level'] != null) {
  6642. $data['level'] = intval($data['level']);
  6643. } else {
  6644. $data['level'] = null;
  6645. }
  6646. $user = User::where('id', $data['user_id'])->first();
  6647. if (empty($user)) {
  6648. return Result::error('用户不存在!');
  6649. }
  6650. if ($user['type_id'] == 10000) {
  6651. $data['status'] = 1;
  6652. } else {
  6653. $data['status'] = 0;
  6654. }
  6655. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6656. $this->sendMessage([
  6657. 'talk_type' => 900,
  6658. 'title' => $data['title'],
  6659. 'content' => '提交了审核',
  6660. 'messageType' => 8,
  6661. ]);
  6662. }
  6663. $result = Company::where('id', $data['id'])->update($data);
  6664. if ($result) {
  6665. return Result::success($result);
  6666. } else {
  6667. return Result::error('修改失败');
  6668. }
  6669. }
  6670. /**
  6671. * 删除企业
  6672. * @param array $data
  6673. * @return array
  6674. */
  6675. public function delCompany(array $data): array
  6676. {
  6677. $result = Company::where('id', $data['id'])->delete();
  6678. if ($result) {
  6679. return Result::success($result);
  6680. } else {
  6681. return Result::error('删除失败');
  6682. }
  6683. }
  6684. /**
  6685. * 审核企业
  6686. * @param array $data
  6687. * @return array
  6688. */
  6689. public function checkCompany(array $data): array
  6690. {
  6691. $user = User::where('id', $data['user_id'])->first();
  6692. if (empty($user)) {
  6693. return Result::error('用户不存在!');
  6694. }
  6695. $company = Company::where('id', $data['id'])->first();
  6696. if (empty($company)) {
  6697. return Result::error('企业不存在!');
  6698. }
  6699. // 状态:0:未审核 1:已审核 2:已拒绝
  6700. if ($data['status'] == 2 || $data['status'] == '2') {
  6701. $this->sendMessage([
  6702. 'talk_type' => 901,
  6703. 'title' => $company['title'],
  6704. 'content' => '审核拒绝',
  6705. 'messageType' => 8,
  6706. 'user_id' => $company['user_id'],
  6707. ]);
  6708. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6709. } else {
  6710. if ($data['status'] == 1) {
  6711. $this->sendMessage([
  6712. 'talk_type' => 901,
  6713. 'title' => $company['title'],
  6714. 'content' => '审核通过',
  6715. 'messageType' => 8,
  6716. 'user_id' => $company['user_id'],
  6717. ]);
  6718. } else if ($data['status'] == 0) {
  6719. $this->sendMessage([
  6720. 'talk_type' => 900,
  6721. 'title' => $company['title'],
  6722. 'content' => '提交了审核',
  6723. 'messageType' => 8,
  6724. ]);
  6725. }
  6726. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6727. }
  6728. if (empty($result)) {
  6729. return Result::error('审核失败!');
  6730. } else {
  6731. return Result::success($result);
  6732. }
  6733. }
  6734. /**
  6735. * 获取企业信息
  6736. * @param array $data
  6737. * @return array
  6738. */
  6739. public function getCompanyInfo(array $data): array
  6740. {
  6741. $result = Company::where('id', $data['id'])->first();
  6742. $city_arr = json_decode($result['city_arr_id']);
  6743. $result['city_name'] = District::whereIn('id', $city_arr)
  6744. ->pluck('name')
  6745. ->implode('-');
  6746. if (empty($result)) {
  6747. return Result::error('企业不存在!');
  6748. } else {
  6749. return Result::success($result);
  6750. }
  6751. }
  6752. /**
  6753. * @param array $data
  6754. * @return array
  6755. */
  6756. public function getWebsiteCompany(array $data): array
  6757. {
  6758. $categorys = json_decode($data['id'], true);
  6759. $category_arr = $this->processArticlePro($data['website_id']);
  6760. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6761. $catiall = $category_arr['catiall'];
  6762. $categoryIds = $category_arr['categoryIds'];
  6763. // return Result::success($category_arr);
  6764. foreach ($categorys as $key => $value) {
  6765. if (array_key_exists('level', $value)) {
  6766. $parts = explode(',', $value['level']);
  6767. $level = $parts[0] ?? null;
  6768. $imgnum = $parts[1] ?? null;
  6769. $textnum = $parts[2] ?? null;
  6770. if (!empty($textnum) && $textnum > 0) {
  6771. $text_num = Company::where('level', $level)
  6772. ->whereIn('category_id', $categoryIds)
  6773. ->where('status', 1)
  6774. ->select(
  6775. 'company.id',
  6776. 'company.title',
  6777. 'company.description',
  6778. 'company.updated_at',
  6779. 'company.category_id',
  6780. 'company.cat_arr_id'
  6781. )
  6782. ->orderBy('updated_at', 'desc')
  6783. ->limit($textnum)
  6784. ->get()->all();
  6785. }
  6786. if (!empty($imgnum) && $imgnum > 0) {
  6787. $img_num = Company::where('level', $level)
  6788. ->whereIn('category_id', $categoryIds)
  6789. ->where('status', 1)
  6790. ->where('imgurl', '!=', '')
  6791. ->whereNotNull('imgurl')
  6792. ->select(
  6793. 'company.id',
  6794. 'company.title',
  6795. 'company.description',
  6796. 'company.updated_at',
  6797. 'company.imgurl as imgs',
  6798. 'company.category_id',
  6799. 'company.cat_arr_id'
  6800. )
  6801. ->orderBy('updated_at', 'desc')
  6802. ->limit($imgnum)
  6803. ->get()->all();
  6804. }
  6805. }
  6806. if (array_key_exists('id', $value)) {
  6807. $parts = explode(',', $value['id']);
  6808. $category_id = $parts[0] ?? null;
  6809. $imgnum = $parts[1] ?? null;
  6810. $textnum = $parts[2] ?? null;
  6811. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6812. if (!empty($textnum) && $textnum > 0) {
  6813. $text_num = Company::whereIn('category_id', $category_arr)
  6814. // ->where('website_id', $data['website_id'])
  6815. ->where('status', 1)
  6816. ->select(
  6817. 'company.id',
  6818. 'company.title',
  6819. 'company.description',
  6820. 'company.updated_at',
  6821. 'company.category_id',
  6822. 'company.cat_arr_id'
  6823. )
  6824. ->orderBy('updated_at', 'desc')
  6825. ->limit($textnum)
  6826. ->get()->all();
  6827. }
  6828. if (!empty($imgnum) && $imgnum > 0) {
  6829. $img_num = Company::whereIn('category_id', $category_arr)
  6830. // ->where('website_id', $data['website_id'])
  6831. ->where('status', 1)
  6832. ->where('imgurl', '!=', '')
  6833. ->whereNotNull('imgurl')
  6834. ->select(
  6835. 'company.id',
  6836. 'company.title',
  6837. 'company.description',
  6838. 'company.updated_at',
  6839. 'company.imgurl as imgs',
  6840. 'company.category_id',
  6841. 'company.cat_arr_id'
  6842. )
  6843. ->orderBy('updated_at', 'desc')
  6844. ->limit($imgnum)
  6845. ->get()->all();
  6846. }
  6847. }
  6848. if (!empty($text_num)) {
  6849. foreach ($text_num as $k => $v) {
  6850. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6851. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6852. }
  6853. }
  6854. if (!empty($img_num)) {
  6855. foreach ($img_num as $k => $v) {
  6856. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6857. $imgurl = json_decode($v['imgs'], true);
  6858. if (!empty($imgurl)) {
  6859. $img_num[$k]->imgurl = $imgurl[0];
  6860. }
  6861. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6862. }
  6863. }
  6864. $company[$key]['img_num'] = $img_num ?? [];
  6865. $company[$key]['text_num'] = $text_num ?? [];
  6866. }
  6867. if (empty($company)) {
  6868. return Result::error("暂无相关企业信息", 0);
  6869. }
  6870. return Result::success($company);
  6871. }
  6872. /**
  6873. * @param array $data
  6874. * @return array
  6875. */
  6876. public function getWebsiteCompanyList(array $data): array
  6877. {
  6878. $where['website_id'] = $data['website_id'];
  6879. $where['status'] = 1;
  6880. $categoryIds = [];
  6881. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6882. $category_id = $data['category_id'];
  6883. }
  6884. $category_arr = $this->processArticlePro($data['website_id']);
  6885. $categoryIds = $category_arr['categoryIds'];
  6886. // return Result::success($cat_1st_arr);
  6887. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  6888. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  6889. })
  6890. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  6891. $query->whereIn('category_id', $categoryIds);
  6892. })
  6893. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  6894. $query->where('category_id', $category_id);
  6895. })
  6896. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6897. ->orderBy('updated_at', 'desc')
  6898. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6899. if (empty($company)) {
  6900. return Result::error("暂无相关公司信息", 0);
  6901. }
  6902. $result = [
  6903. 'count' => $company->total(),
  6904. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  6905. ];
  6906. return Result::success($result);
  6907. }
  6908. /**
  6909. * 获取项目列表
  6910. * @param array $data
  6911. * @return array
  6912. */
  6913. public function getProjectList(array $data): array
  6914. {
  6915. $where = [];
  6916. $user = User::where('id', $data['user_id'])->first();
  6917. if (empty($user)) {
  6918. return Result::error('用户不存在!');
  6919. }
  6920. if ($user->type_id != 10000) {
  6921. array_push($where, ['project.user_id', $data['user_id']]);
  6922. }
  6923. $query = Project::query();
  6924. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6925. array_push($where, ['project.website_id', $data['website_id']]);
  6926. }
  6927. if (isset($data['title']) && !empty($data['title'])) {
  6928. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6929. }
  6930. if ($data['status'] != 3) {
  6931. array_push($where, ['project.status', $data['status']]);
  6932. }
  6933. $query = Project::where($where)
  6934. ->when($data['status'] == 3, function ($query) {
  6935. $query->whereIn('project.status', [0, 2]);
  6936. });
  6937. $count = $query->clone()
  6938. ->count();
  6939. $rows = $query->clone()
  6940. ->leftJoin('website', 'project.website_id', 'website.id')
  6941. ->leftJoin('website_category', function ($join) {
  6942. $join->on('project.website_id', '=', 'website_category.website_id')
  6943. ->on('project.category_id', '=', 'website_category.category_id');
  6944. })
  6945. ->select(
  6946. 'project.id',
  6947. 'project.title',
  6948. 'project.updated_at',
  6949. 'project.status',
  6950. 'website.website_name',
  6951. 'website_category.alias as category_name',
  6952. 'project.website_id',
  6953. 'project.user_id'
  6954. )
  6955. ->orderBy('project.updated_at', 'desc')
  6956. ->offset(($data['page'] - 1) * $data['pageSize'])
  6957. ->limit($data['pageSize'])
  6958. ->get();
  6959. if ($rows->isEmpty()) {
  6960. return Result::error("暂无相关项目信息", 0);
  6961. }
  6962. $result = [
  6963. 'count' => $count,
  6964. 'rows' => $rows,
  6965. ];
  6966. return Result::success($result);
  6967. }
  6968. /**
  6969. * 添加项目
  6970. * @param array $data
  6971. * @return array
  6972. */
  6973. public function addProject(array $data): array
  6974. {
  6975. $user = User::where('id', $data['user_id'])->first();
  6976. if (empty($user)) {
  6977. return Result::error("暂无相关用户信息", 0);
  6978. }
  6979. if ($user->type_id == 10000) {
  6980. $data['status'] = 1;
  6981. } else {
  6982. $data['status'] = 0;
  6983. }
  6984. if ($data['keyword'] == '') {
  6985. //提取标题+内容中的关键词
  6986. $data['keyword'] = $data['title'];
  6987. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6988. Jieba::init(); // 初始化 jieba-php
  6989. Finalseg::init();
  6990. $segList = Jieba::cut($data['keyword']);
  6991. $segList1 = array_slice($segList, 0, 8);
  6992. $data['keyword'] = implode(',', $segList1);
  6993. }
  6994. if ($data['description'] == '') {
  6995. //提取内容中的描述
  6996. // var_dump(11111);
  6997. //提取内容中的描述
  6998. $content = $data['introduce'];
  6999. // 去除 <style> 和 <script> 标签及其内容
  7000. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7001. // 去除所有 HTML 标签
  7002. $content = strip_tags($content);
  7003. // 去除 HTML 实体
  7004. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7005. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7006. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7007. // 去除多余空白
  7008. $content = preg_replace('/\s+/u', '', $content);
  7009. // 截取 100 个字符
  7010. $data['description'] = mb_substr($content, 0, 100);
  7011. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7012. }
  7013. if ($data['status'] == 0) {
  7014. $this->sendMessage([
  7015. 'talk_type' => 1000,
  7016. 'title' => $data['title'],
  7017. 'content' => '提交了审核',
  7018. 'messageType' => 9,
  7019. ]);
  7020. }
  7021. $project = Project::insertGetId($data);
  7022. if (empty($project)) {
  7023. return Result::error("暂无相关项目信息", 0);
  7024. }
  7025. return Result::success($project);
  7026. }
  7027. /**
  7028. * 更新项目
  7029. * @param array $data
  7030. * @return array
  7031. */
  7032. public function upProject(array $data): array
  7033. {
  7034. $project = Project::where('id', $data['id'])->first();
  7035. if (empty($project)) {
  7036. return Result::error("暂无相关项目信息", 0);
  7037. }
  7038. $id = $data['id'];
  7039. unset($data['id']);
  7040. $user = User::where('id', $data['user_id'])->first();
  7041. if (empty($user)) {
  7042. return Result::error("暂无相关用户信息", 0);
  7043. }
  7044. if ($user->type_id == 10000) {
  7045. $data['status'] = 1;
  7046. } else {
  7047. $data['status'] = 0;
  7048. }
  7049. unset($data['user_id']);
  7050. if ($data['keyword'] == '') {
  7051. //提取标题+内容中的关键词
  7052. $data['keyword'] = $data['title'];
  7053. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7054. Jieba::init(); // 初始化 jieba-php
  7055. Finalseg::init();
  7056. $segList = Jieba::cut($data['keyword']);
  7057. $segList1 = array_slice($segList, 0, 8);
  7058. $data['keyword'] = implode(',', $segList1);
  7059. }
  7060. if ($data['description'] == '') {
  7061. //提取内容中的描述
  7062. // var_dump(11111);
  7063. //提取内容中的描述
  7064. $content = $data['introduce'];
  7065. // 去除 <style> 和 <script> 标签及其内容
  7066. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7067. // 去除所有 HTML 标签
  7068. $content = strip_tags($content);
  7069. // 去除 HTML 实体
  7070. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7071. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7072. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7073. // 去除多余空白
  7074. $content = preg_replace('/\s+/u', '', $content);
  7075. // 截取 100 个字符
  7076. $data['description'] = mb_substr($content, 0, 100);
  7077. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7078. }
  7079. if ($data['status'] == 0) {
  7080. $this->sendMessage([
  7081. 'talk_type' => 1000,
  7082. 'title' => $data['title'],
  7083. 'content' => '提交了审核',
  7084. 'messageType' => 9,
  7085. ]);
  7086. }
  7087. $result = Project::where('id', $id)->update($data);
  7088. if (empty($result)) {
  7089. return Result::error("更新失败", 0);
  7090. }
  7091. return Result::success($result);
  7092. }
  7093. /**
  7094. * 删除项目
  7095. * @param array $data
  7096. * @return array
  7097. */
  7098. public function delProject(array $data): array
  7099. {
  7100. $user = User::where('id', $data['user_id'])->first();
  7101. if (empty($user)) {
  7102. return Result::error("暂无相关用户信息", 0);
  7103. }
  7104. $project = Project::where('id', $data['id'])->first();
  7105. if (empty($project)) {
  7106. return Result::error("暂无相关项目信息", 0);
  7107. }
  7108. $result = Project::where('id', $data['id'])->delete();
  7109. if (empty($result)) {
  7110. return Result::error("删除失败", 0);
  7111. }
  7112. return Result::success($result);
  7113. }
  7114. /**
  7115. * 审核项目
  7116. * @param array $data
  7117. * @return array
  7118. */
  7119. public function checkProject(array $data): array
  7120. {
  7121. $user = User::where('id', $data['user_id'])->first();
  7122. if (empty($user)) {
  7123. return Result::error("暂无相关用户信息", 0);
  7124. }
  7125. // 0:未审核; 1:已审核; 2:已拒绝;
  7126. if ($user->type_id != 10000) {
  7127. if ($data['status'] == 1 || $data['status'] == 2) {
  7128. return Result::error("此用户权限不足", 0);
  7129. }
  7130. }
  7131. $project = Project::where('id', $data['id'])->first();
  7132. if (empty($project)) {
  7133. return Result::error("暂无相关项目信息", 0);
  7134. }
  7135. if ($data['status'] == 2) {
  7136. $this->sendMessage([
  7137. 'talk_type' => 1001,
  7138. 'title' => $project['title'],
  7139. 'content' => '审核拒绝',
  7140. 'messageType' => 9,
  7141. 'user_id' => $project['user_id'],
  7142. ]);
  7143. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7144. } else {
  7145. if ($data['status'] == 1) {
  7146. $this->sendMessage([
  7147. 'talk_type' => 1001,
  7148. 'title' => $project['title'],
  7149. 'content' => '审核通过',
  7150. 'messageType' => 9,
  7151. 'user_id' => $project['user_id'],
  7152. ]);
  7153. } else if ($data['status'] == 0) {
  7154. $this->sendMessage([
  7155. 'talk_type' => 1000,
  7156. 'title' => $project['title'],
  7157. 'content' => '提交了审核',
  7158. 'messageType' => 9,
  7159. ]);
  7160. }
  7161. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7162. }
  7163. if (empty($result)) {
  7164. return Result::error("审核失败", 0);
  7165. }
  7166. return Result::success($result);
  7167. }
  7168. /**
  7169. * 获取项目详情
  7170. * @param array $data
  7171. * @return array
  7172. */
  7173. public function getProjectInfo(array $data): array
  7174. {
  7175. $project = Project::where('id', $data['id'])->first();
  7176. if (empty($project)) {
  7177. return Result::error("暂无相关项目信息", 0);
  7178. }
  7179. return Result::success($project);
  7180. }
  7181. public function getWebsiteCompanyInfo(array $data): array
  7182. {
  7183. $company = Company::where('id', $data['id'])
  7184. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7185. ->where('status', 1)
  7186. // ->where('website_id', $data['website_id'])
  7187. ->select('company.*', 'job_industry.hyname as hy_name')
  7188. ->first();
  7189. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7190. switch ($company->jobnature_id) {
  7191. case null:
  7192. $company->jobnature_name = '';
  7193. break;
  7194. case 0:
  7195. $company->jobnature_name = '市场监督';
  7196. break;
  7197. case 1:
  7198. $company->jobnature_name = '信访纪检';
  7199. break;
  7200. case 2:
  7201. $company->jobnature_name = '公检法司';
  7202. break;
  7203. case 3:
  7204. $company->jobnature_name = '高关注机构';
  7205. break;
  7206. default:
  7207. $company->jobnature_name = '';
  7208. break;
  7209. }
  7210. $city_arr = $company->city_arr_id;
  7211. if (!empty($city_arr)) {
  7212. $city_arr = json_decode($city_arr, true);
  7213. $cityNames = District::whereIn('id', $city_arr)
  7214. ->pluck('name')
  7215. ->implode('-');
  7216. $company->city_name = $cityNames;
  7217. } else {
  7218. $company->city_name = '';
  7219. }
  7220. if (empty($company)) {
  7221. return Result::error("暂无相关公司信息", 0);
  7222. }
  7223. return Result::success($company);
  7224. }
  7225. public function getMSG(array $data): array
  7226. {
  7227. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7228. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7229. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7230. $result = [];
  7231. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7232. //最近的5篇已审的文章
  7233. $apply_articale = Article::where('status', 1)
  7234. ->where('admin_user_id', $user_id)
  7235. ->orderBy('updated_at', 'desc')
  7236. // ->limit(5)
  7237. ->get();
  7238. //获取5条用户的已审核商品
  7239. $good = Good::where('status', 2)
  7240. ->where('user_id', $user_id)
  7241. ->orderBy('updated_at', 'desc')
  7242. // ->limit(5)
  7243. ->get();
  7244. //获取5条用户待审核的公告
  7245. $notice = Notice::where('status', 2)
  7246. ->where('user_id', $user_id)
  7247. ->orderBy('updated_at', 'desc')
  7248. ->limit(5)->get();
  7249. //获取5条用户的待审核投诉
  7250. $complaint = Complaint::where('status', 2)
  7251. ->where('user_id', $user_id)
  7252. ->orderBy('updated_at', 'desc')
  7253. // ->limit(5)
  7254. ->get();
  7255. //获取5条用户的book
  7256. $book = Book::where('status', 2)
  7257. ->where('user_id', $user_id)
  7258. ->orderBy('updated_at', 'desc')
  7259. // ->limit(5)
  7260. ->get();
  7261. //获取5条用户的求职
  7262. //获取5条用户的求职 1
  7263. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7264. ->where('job_hunting.user_id', $user_id)
  7265. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7266. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7267. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7268. ->orderBy('updated_at', 'desc')
  7269. // ->limit(5)
  7270. ->get();
  7271. //获取5条用户的求职 2
  7272. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7273. ->where('job_recruiting.user_id', $user_id)
  7274. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7275. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7276. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7277. ->orderBy('updated_at', 'desc')
  7278. // ->limit(5)
  7279. ->get();
  7280. //人才库 1
  7281. $job_apply = JobApply::where('job_apply.status', 1)
  7282. ->where('job_apply.receiver_id', $user_id)
  7283. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7284. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7285. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7286. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7287. ->select('job_recruiting', 'job_recruiting.', '', '')
  7288. ->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')
  7289. ->orderBy('updated_at', 'desc')
  7290. // ->limit(5)
  7291. ->get();
  7292. // 职场机会 2
  7293. $job_resume = JobResume::where('job_resume.status', 1)
  7294. ->where('job_resume.receiver_id', $user_id)
  7295. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7296. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7297. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7298. ->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')
  7299. ->orderBy('updated_at', 'desc')
  7300. // ->limit(5)
  7301. ->get();
  7302. //获取5条用户待处理的投诉
  7303. $complaint_deal = Complaint::where('status', 2)
  7304. ->where('deal', 1)
  7305. ->whereJsonContains('re_user_ids', $user_id)
  7306. ->orderBy('updated_at', 'desc')
  7307. // ->limit(5)
  7308. ->get();
  7309. //获取 被通知者未读信息
  7310. $notice_unread = Notice::where('status', 2)
  7311. ->whereJsonContains('re_user_ids', $user_id)
  7312. //未读消息
  7313. ->where(function ($query) use ($user_id) {
  7314. $query->whereJsonDoesntContain('read_id', $user_id)
  7315. ->orWhereNull('read_id');
  7316. })
  7317. ->orderBy('updated_at', 'desc')
  7318. ->get();
  7319. $complaint_unread = Complaint::where('status', 2)
  7320. ->whereJsonContains('re_user_ids', $user_id)
  7321. //未读消息
  7322. ->where(function ($query) use ($user_id) {
  7323. $query->whereJsonDoesntContain('read_id', $user_id)
  7324. ->orWhereNull('read_id');
  7325. })
  7326. ->orderBy('updated_at', 'desc')
  7327. ->get();
  7328. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7329. $complany = Company::where('status', 1)
  7330. ->where('user_id', $user_id)
  7331. ->orderBy('updated_at', 'desc')
  7332. // ->limit(5)
  7333. ->get();
  7334. //获取5条单聊未读聊天消息
  7335. // $chat = ChatRecords::where('is_read', 0)
  7336. // ->where('user_id', $user_id)
  7337. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7338. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7339. // ->where('action', 'recieved')
  7340. // ->where('talk_type', 1)
  7341. // ->orderBy('created_at', 'desc')
  7342. // // ->limit(5)
  7343. // ->get();
  7344. //获取5条未读群聊信息
  7345. // $chat_group = ChatRecords::where('is_read', 0)
  7346. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7347. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7348. // ->where('user_id', $user_id)
  7349. // ->where('talk_type', 2)
  7350. // ->orderBy('created_at', 'desc')
  7351. // // ->limit(5)
  7352. // ->get();
  7353. //获取5条用户的待审核项目
  7354. $project = Project::where('status', 1)
  7355. ->where('user_id', $user_id)
  7356. ->orderBy('updated_at', 'desc')
  7357. // ->limit(5)
  7358. ->get();
  7359. // count($chat) + count($chat_group) +
  7360. $count = count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume) + count($complaint_deal)
  7361. + count($complany)
  7362. + count($project)
  7363. + count($notice_unread)
  7364. + count($complaint_unread)
  7365. // + count($chat) + count($chat_group)
  7366. ;
  7367. $result = [
  7368. 'apply_articale' => $apply_articale,
  7369. // 'chat' => $chat,
  7370. // 'chat_group' => $chat_group,
  7371. 'good' => $good,
  7372. 'notice' => $notice,
  7373. 'complaint' => $complaint,
  7374. 'book' => $book,
  7375. 'job_hunting' => $job_hunting,
  7376. 'job_recruiting' => $job_recruiting,
  7377. 'job_apply' => $job_apply,
  7378. 'job_resume' => $job_resume,
  7379. 'complaint_deal' => $complaint_deal,
  7380. 'complany' => $complany,
  7381. 'project' => $project,
  7382. 'notice_unread' => $notice_unread,
  7383. 'complaint_unread' => $complaint_unread,
  7384. 'count' => $count,
  7385. ];
  7386. } elseif ($type_id == 12) {
  7387. //最近的5篇已审的文章
  7388. $apply_articale = Article::where('status', 1)
  7389. ->where('admin_user_id', $user_id)
  7390. ->limit(5)->get();
  7391. //获取5条单聊未读聊天消息
  7392. $chat = ChatRecords::where('is_read', 0)
  7393. ->where('user_id', $user_id)
  7394. ->where('talk_type', 1)
  7395. ->orderBy('created_at', 'desc')
  7396. ->limit(5)->get();
  7397. //获取5条未读群聊信息
  7398. $chat_group = ChatRecords::where('is_read', 0)
  7399. ->where('user_id', $user_id)
  7400. ->where('talk_type', 2)
  7401. ->orderBy('created_at', 'desc')
  7402. ->limit(5)->get();
  7403. //获取5条用户的已审核商品
  7404. $good = Good::where('status', 2)
  7405. ->where('user_id', $user_id)
  7406. ->orderBy('updated_at', 'desc')
  7407. ->limit(5)->get();
  7408. //获取5条用户的book
  7409. $book = Book::where('status', 2)
  7410. ->where('user_id', $user_id)
  7411. ->orderBy('updated_at', 'desc')
  7412. ->limit(5)->get();
  7413. //获取5条用户的求职
  7414. //获取5条用户的求职 1
  7415. //count($chat) + count($chat_group)
  7416. $count = count($apply_articale) + count($good);
  7417. $result = [
  7418. 'apply_articale' => $apply_articale,
  7419. 'chat' => $chat,
  7420. 'chat_group' => $chat_group,
  7421. 'good' => $good,
  7422. 'book' => $book,
  7423. 'count' => $count,
  7424. ];
  7425. } elseif ($type_id == 13) {
  7426. //最近的5篇已审的文章
  7427. $apply_articale = Article::where('status', 1)
  7428. ->where('admin_user_id', $user_id)
  7429. ->limit(5)->get();
  7430. //获取5条单聊未读聊天消息
  7431. $chat = ChatRecords::where('is_read', 0)
  7432. ->where('user_id', $user_id)
  7433. ->where('talk_type', 1)
  7434. ->orderBy('created_at', 'desc')
  7435. ->limit(5)->get();
  7436. //获取5条未读群聊信息
  7437. $chat_group = ChatRecords::where('is_read', 0)
  7438. ->where('user_id', $user_id)
  7439. ->where('talk_type', 2)
  7440. ->orderBy('created_at', 'desc')
  7441. ->limit(5)->get();
  7442. //获取5条用户的已审核商品
  7443. $good = Good::where('status', 2)
  7444. ->where('user_id', $user_id)
  7445. ->orderBy('updated_at', 'desc')
  7446. ->limit(5)->get();
  7447. //count($chat) + count($chat_group) +
  7448. $count = count($apply_articale) + count($good);
  7449. $result = [
  7450. 'apply_articale' => $apply_articale,
  7451. 'chat' => $chat,
  7452. 'chat_group' => $chat_group,
  7453. 'good' => $good,
  7454. 'count' => $count,
  7455. ];
  7456. } elseif ($type_id == 14) {
  7457. //最近的5篇已审的文章
  7458. $apply_articale = Article::where('status', 1)
  7459. ->where('admin_user_id', $user_id)
  7460. // ->limit(5)
  7461. ->get();
  7462. //获取5条用户的已审核商品
  7463. $good = Good::where('status', 2)
  7464. ->where('user_id', $user_id)
  7465. ->orderBy('updated_at', 'desc')
  7466. // ->limit(5)
  7467. ->get();
  7468. $count = count($apply_articale) + count($good);
  7469. $result = [
  7470. 'apply_articale' => $apply_articale,
  7471. 'chat' => '',
  7472. 'chat_group' => '',
  7473. 'good' => $good,
  7474. 'count' => $count,
  7475. ];
  7476. } elseif ($type_id == 10000) {
  7477. //获取未审核的5篇文章
  7478. $apply_articale = Article::where('status', 0)
  7479. ->orderBy('updated_at', 'desc')
  7480. // ->limit(5)
  7481. ->get();
  7482. //获取5条单聊未读聊天消息
  7483. //获取5条单聊未读聊天消息
  7484. // $chat = ChatRecords::where('is_read', 0)
  7485. // ->where('user_id', $user_id)
  7486. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7487. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7488. // ->where('action', 'recieved')
  7489. // ->where('talk_type', 1)
  7490. // ->orderBy('created_at', 'desc')
  7491. // // ->limit(5)
  7492. // ->get();
  7493. // //获取5条未读群聊信息
  7494. // $chat_group = ChatRecords::where('is_read', 0)
  7495. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7496. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7497. // ->where('user_id', $user_id)
  7498. // ->where('talk_type', 2)
  7499. // ->orderBy('created_at', 'desc')
  7500. // // ->limit(5)
  7501. // ->get();
  7502. //获取5条用户的已审核商品
  7503. $good = Good::where('status', 1)
  7504. // ->where('user_id', $user_id)
  7505. ->orderBy('updated_at', 'desc')
  7506. // ->limit(5)
  7507. ->get();
  7508. //获取5条用户待审核的公告
  7509. $notice = Notice::where('status', 1)
  7510. ->orderBy('updated_at', 'desc')
  7511. // ->limit(5)
  7512. ->get();
  7513. //获取5条用户的待审核投诉
  7514. $complaint = Complaint::where('status', 1)
  7515. ->orderBy('updated_at', 'desc')
  7516. // ->limit(5)
  7517. ->get();
  7518. //获取5条用户的book
  7519. $book = Book::where('status', 1)
  7520. ->orderBy('updated_at', 'desc')
  7521. // ->limit(5)
  7522. ->get();
  7523. //获取5条用户的求职 1
  7524. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7525. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7526. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7527. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7528. ->orderBy('updated_at', 'desc')
  7529. // ->limit(5)
  7530. ->get();
  7531. //获取5条用户的求职 2
  7532. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7533. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7534. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7535. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7536. ->orderBy('updated_at', 'desc')
  7537. // ->limit(5)
  7538. ->get();
  7539. //人才库 1
  7540. $job_apply = JobApply::where('job_apply.status', 1)
  7541. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7542. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7543. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7544. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7545. ->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')
  7546. ->orderBy('updated_at', 'desc')
  7547. // ->limit(5)
  7548. ->get();
  7549. // 职场机会 2
  7550. $job_resume = JobResume::where('job_resume.status', 1)
  7551. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7552. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7553. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7554. ->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')
  7555. ->orderBy('updated_at', 'desc')
  7556. // ->limit(5)
  7557. ->get();
  7558. //待审核数据com pro
  7559. $complany = Company::where('status', 0)
  7560. ->orderBy('updated_at', 'desc')
  7561. // ->limit(5)
  7562. ->get();
  7563. $project = Project::where('status', 0)
  7564. ->orderBy('updated_at', 'desc')
  7565. // ->limit(5)
  7566. ->get();
  7567. $count =
  7568. // count($chat) +
  7569. // count($chat_group) +
  7570. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7571. // + count($job_apply)
  7572. // + count($job_resume)
  7573. + count($complany)
  7574. + count($project);
  7575. $result = [
  7576. 'apply_articale' => $apply_articale,
  7577. // 'chat' => $chat,
  7578. // 'chat_group' => $chat_group,
  7579. 'good' => $good,
  7580. 'notice' => $notice,
  7581. 'complaint' => $complaint,
  7582. 'book' => $book,
  7583. 'job_hunting' => $job_hunting,
  7584. 'job_recruiting' => $job_recruiting,
  7585. // 'job_apply' => $job_apply,
  7586. // 'job_resume' => $job_resume,
  7587. 'complany' => $complany,
  7588. 'project' => $project,
  7589. 'count' => $count,
  7590. ];
  7591. } elseif ($type_id == 20000) {
  7592. }
  7593. var_dump($type_id, '-----------------test---------');
  7594. return Result::success($result);
  7595. }
  7596. /**
  7597. * @param array $data
  7598. * @return array
  7599. */
  7600. public function getWebsiteProject(array $data): array
  7601. {
  7602. $categorys = json_decode($data['id'], true);
  7603. if (!empty($categorys)) {
  7604. $category_arr = $this->processArticlePro($data['website_id']);
  7605. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7606. $catiall = $category_arr['catiall'];
  7607. // return Result::success($catiall);
  7608. foreach ($categorys as $key => $val) {
  7609. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7610. $level = explode(',', $val['level'])[0];
  7611. $imgnum = explode(',', $val['level'])[1] ?? null;
  7612. $textnum = explode(',', $val['level'])[2] ?? null;
  7613. if ($level == 1) {
  7614. if (!empty($textnum) && $textnum > 0) {
  7615. $text_num = Project::where('level', $level)
  7616. ->where('website_id', $data['website_id'])
  7617. ->where('status', 1)
  7618. ->select(
  7619. 'project.id',
  7620. 'project.title',
  7621. 'project.description',
  7622. 'project.updated_at',
  7623. 'project.category_id',
  7624. 'project.cat_arr_id'
  7625. )
  7626. ->orderBy('updated_at', 'desc')
  7627. ->limit($textnum)
  7628. ->get()->all();
  7629. }
  7630. if (!empty($imgnum) && $imgnum > 0) {
  7631. $img_num = Project::where('level', $level)
  7632. ->where('website_id', $data['website_id'])
  7633. ->where('status', 1)
  7634. ->where('imgurl', '!=', '')
  7635. ->whereNotNull('imgurl')
  7636. ->select(
  7637. 'project.id',
  7638. 'project.title',
  7639. 'project.description',
  7640. 'project.updated_at',
  7641. 'project.imgurl as imgs',
  7642. 'project.category_id',
  7643. 'project.cat_arr_id'
  7644. )
  7645. ->orderBy('updated_at', 'desc')
  7646. ->limit($imgnum)
  7647. ->get()->all();
  7648. }
  7649. } else {
  7650. if (!empty($textnum) && $textnum > 0) {
  7651. $text_num = Project::where('website_id', $data['website_id'])
  7652. ->where('status', 1)
  7653. ->select(
  7654. 'project.id',
  7655. 'project.title',
  7656. 'project.description',
  7657. 'project.updated_at',
  7658. 'project.category_id',
  7659. 'project.cat_arr_id',
  7660. 'project.website_id',
  7661. 'project.updated_at',
  7662. 'project.created_at'
  7663. )
  7664. ->orderBy('updated_at', 'desc')
  7665. ->limit($textnum)
  7666. ->get()->all();
  7667. }
  7668. if (!empty($imgnum) && $imgnum > 0) {
  7669. $img_num = Project::where('website_id', $data['website_id'])
  7670. ->where('status', 1)
  7671. ->where('imgurl', '!=', '')
  7672. ->whereNotNull('imgurl')
  7673. ->select(
  7674. 'project.id',
  7675. 'project.title',
  7676. 'project.description',
  7677. 'project.updated_at',
  7678. 'project.imgurl as imgs',
  7679. 'project.category_id',
  7680. 'project.cat_arr_id'
  7681. )
  7682. ->orderBy('updated_at', 'desc')
  7683. ->limit($imgnum)
  7684. ->get()->all();
  7685. }
  7686. }
  7687. }
  7688. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7689. $category_ids = explode(',', $val['id'])[0];
  7690. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7691. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7692. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7693. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7694. $text_num = Project::whereIn('category_id', $category_arr)
  7695. ->where('website_id', $data['website_id'])
  7696. ->where('status', 1)
  7697. ->select(
  7698. 'project.id',
  7699. 'project.title',
  7700. 'project.description',
  7701. 'project.updated_at',
  7702. 'project.category_id',
  7703. 'project.cat_arr_id'
  7704. )
  7705. ->orderBy('updated_at', 'desc')
  7706. ->limit($cat_textnum)
  7707. ->get()->all();
  7708. }
  7709. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7710. $img_num = Project::whereIn('category_id', $category_arr)
  7711. ->where('website_id', $data['website_id'])
  7712. ->where('status', 1)
  7713. ->where('imgurl', '!=', '')
  7714. ->whereNotNull('imgurl')
  7715. ->select(
  7716. 'project.id',
  7717. 'project.title',
  7718. 'project.description',
  7719. 'project.updated_at',
  7720. 'project.imgurl as imgs',
  7721. 'project.category_id',
  7722. 'project.cat_arr_id'
  7723. )
  7724. ->orderBy('updated_at', 'desc')
  7725. ->limit($cat_imgnum)
  7726. ->get()->all();
  7727. }
  7728. }
  7729. if (!empty($img_num)) {
  7730. foreach ($img_num as $k => $v) {
  7731. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7732. $imgurl = json_decode($v['imgs'], true);
  7733. if (!empty($imgurl)) {
  7734. $img_num[$k]->imgurl = $imgurl[0];
  7735. }
  7736. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7737. }
  7738. }
  7739. if (!empty($text_num)) {
  7740. foreach ($text_num as $k => $v) {
  7741. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7742. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7743. }
  7744. }
  7745. $project[$key]['img_num'] = $img_num ?? [];
  7746. $project[$key]['text_num'] = $text_num ?? [];
  7747. }
  7748. }
  7749. if (empty($project)) {
  7750. return Result::error("暂无相关项目信息", 0);
  7751. }
  7752. return Result::success($project);
  7753. }
  7754. /**
  7755. * @param array $data
  7756. * @return array
  7757. */
  7758. public function getWebsiteProjectInfo(array $data): array
  7759. {
  7760. $project = Project::where('id', $data['id'])
  7761. ->where('status', 1)
  7762. ->where('website_id', $data['website_id'])
  7763. ->select('project.*')
  7764. ->first();
  7765. if (empty($project)) {
  7766. return Result::error("暂无相关项目信息", 0);
  7767. }
  7768. return Result::success($project);
  7769. }
  7770. /**
  7771. * @param array $data
  7772. * @return array
  7773. */
  7774. public function getWebsiteProjectList(array $data): array
  7775. {
  7776. $where = [];
  7777. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7778. $where['category_id'] = $data['category_id'];
  7779. }
  7780. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7781. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7782. }
  7783. $query = Project::where($where)
  7784. ->where('status', 1)
  7785. ->where('website_id', $data['website_id'])
  7786. ->select(
  7787. 'project.id',
  7788. 'project.title',
  7789. 'project.description',
  7790. 'project.imgurl as imgs',
  7791. 'project.category_id',
  7792. 'project.cat_arr_id'
  7793. )
  7794. ->orderBy('updated_at', 'desc');
  7795. $count = $query->count();
  7796. $project = $query->clone()
  7797. ->offset(($data['page'] - 1) * $data['pageSize'])
  7798. ->limit($data['pageSize'])
  7799. ->get()->all();
  7800. if (empty($project)) {
  7801. return Result::error("暂无相关项目信息", 0);
  7802. }
  7803. $categorys = $this->processArticlePro($data['website_id']);
  7804. $catiall = $categorys['catiall'];
  7805. foreach ($project as $key => $val) {
  7806. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7807. if (!empty($val['imgs'])) {
  7808. $imgurl = json_decode($val['imgs'], true);
  7809. if (!empty($imgurl)) {
  7810. $project[$key]->imgurl = $imgurl[0];
  7811. }
  7812. } else {
  7813. $project[$key]->imgurl = '';
  7814. }
  7815. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7816. }
  7817. $result = [
  7818. 'rows' => $project,
  7819. 'count' => $count,
  7820. ];
  7821. return Result::success($result);
  7822. }
  7823. /**
  7824. * @param array $data
  7825. * @return array
  7826. */
  7827. public function getWebsiteCategoryJob(array $data): array
  7828. {
  7829. $categorys = json_decode($data['id'], true);
  7830. if (!empty($categorys)) {
  7831. $category_arr = $this->processArticlePro($data['website_id']);
  7832. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7833. $catiall = $category_arr['catiall'];
  7834. foreach ($categorys as $key => $val) {
  7835. if (isset($val['id']) && !empty($val['id'])) {
  7836. $catid = explode(',', $val['id'])[0] ?? null;
  7837. $type = explode(',', $val['id'])[1] ?? null;
  7838. $textnum = explode(',', $val['id'])[2] ?? null;
  7839. }
  7840. // 4:招聘;5:求职;
  7841. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7842. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7843. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7844. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7845. ->where('job_recruiting.status', 1)
  7846. ->where('job_recruiting.website_id', $data['website_id'])
  7847. ->select(
  7848. 'job_recruiting.id',
  7849. 'job_recruiting.title',
  7850. 'job_company.business_name',
  7851. 'job_recruiting.updated_at',
  7852. 'job_recruiting.cat_arr_id',
  7853. 'job_recruiting.keyword',
  7854. 'job_recruiting.description'
  7855. )
  7856. ->orderBy('job_recruiting.updated_at', 'desc')
  7857. ->limit($textnum)
  7858. ->get()->all();
  7859. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7860. // 状态 审核状态,1待审核2已审核3已拒绝
  7861. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7862. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7863. ->where('job_hunting.status', 2)
  7864. ->where('job_hunting.website_id', $data['website_id'])
  7865. ->select(
  7866. 'job_hunting.id',
  7867. 'job_hunting.name',
  7868. 'job_hunting.cat_arr_id',
  7869. 'job_position.zwname as job_name',
  7870. 'job_hunting.updated_at',
  7871. 'job_hunting.keyword',
  7872. 'job_hunting.slelf_evaluation'
  7873. )
  7874. ->orderBy('updated_at', 'desc')
  7875. ->limit($textnum)
  7876. ->get()->all();
  7877. } else {
  7878. $job = [];
  7879. }
  7880. // var_dump($catid.'222uuuuuuu'.$key);
  7881. if (!empty($job)) {
  7882. foreach ($job as $k => $value) {
  7883. if (isset($value->cat_arr_id)) {
  7884. $catArr = json_decode($value->cat_arr_id, true);
  7885. $catId = end($catArr);
  7886. } else {
  7887. continue;
  7888. }
  7889. if (isset($catiall[$catId])) {
  7890. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7891. }
  7892. }
  7893. }
  7894. // var_dump($catid.'xxxxx'.$key);
  7895. $result[$key] = $job ?? [];
  7896. }
  7897. }
  7898. if (empty($result)) {
  7899. return Result::error("暂无相关分类信息", 0);
  7900. }
  7901. return Result::success($result);
  7902. }
  7903. /**
  7904. * 发送消息
  7905. * @param array $messageData
  7906. * @return void
  7907. */
  7908. public function sendMessage($messageData)
  7909. {
  7910. $msg = [
  7911. 'talk_type' => $messageData['talk_type'],
  7912. 'title' => $messageData['title'],
  7913. 'content' => $messageData['content'],
  7914. 'messageType' => $messageData['messageType'],
  7915. 'user_id' => $messageData['user_id'] ?? '',
  7916. 'time' => microtime(),
  7917. ];
  7918. $message = new MqProducer($msg);
  7919. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7920. $producer->produce($message);
  7921. }
  7922. }