NewsService.php 288 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  65. class NewsService implements NewsServiceInterface
  66. {
  67. #[Inject]
  68. protected Redis $redis;
  69. /**
  70. * 获取导航池列表
  71. * @param array $data
  72. * @return array
  73. */
  74. public function getCategoryList(array $data): array
  75. {
  76. $search = $data['name'] ?? '';
  77. $page = (int)($data['page'] ?? 1);
  78. $perPage = (int)($data['pageSize'] ?? 10);
  79. // 1. 查出所有匹配的分类id
  80. if ($search) {
  81. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  82. if (empty($matchedIds)) {
  83. return Result::success(['rows' => [], 'total' => 0]);
  84. }
  85. // 2. 递归查所有父级,直到一级分类
  86. $idsStr = implode(',', $matchedIds);
  87. $sql = "
  88. WITH RECURSIVE parents AS (
  89. SELECT * FROM category WHERE id IN ($idsStr)
  90. UNION ALL
  91. SELECT c.* FROM category c
  92. INNER JOIN parents p ON c.id = p.pid
  93. )
  94. SELECT * FROM parents
  95. ";
  96. $parents = Db::select($sql);
  97. $parentIds = [];
  98. foreach ($parents as $row) {
  99. if ($row->pid == 0) {
  100. $parentIds[] = $row->id;
  101. }
  102. }
  103. $parentIds = array_unique($parentIds);
  104. } else {
  105. // 没有搜索,一级分类就是根
  106. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  107. }
  108. // 3. 一级分类分页
  109. $total = count($parentIds);
  110. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  111. if (empty($parentIds)) {
  112. return Result::success(['rows' => [], 'total' => $total]);
  113. }
  114. // 4. 递归查所有子孙
  115. $idsStr = implode(',', $parentIds);
  116. $sql = "
  117. WITH RECURSIVE subcategories AS (
  118. SELECT * FROM category WHERE id IN ($idsStr)
  119. UNION ALL
  120. SELECT c.* FROM category c
  121. INNER JOIN subcategories s ON c.pid = s.id
  122. )
  123. SELECT * FROM subcategories ORDER BY updated_at DESC
  124. ";
  125. $allCategories = Db::select($sql);
  126. // 5. 组装树结构
  127. $categoryMap = [];
  128. foreach ($allCategories as $cat) {
  129. $cat = (array)$cat;
  130. $cat['children'] = [];
  131. $categoryMap[$cat['id']] = $cat;
  132. }
  133. foreach ($categoryMap as $id => &$cat) {
  134. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  135. $categoryMap[$cat['pid']]['children'][] = &$cat;
  136. }
  137. }
  138. unset($cat);
  139. $categoryTree = [];
  140. foreach ($parentIds as $id) {
  141. if (isset($categoryMap[$id])) {
  142. $categoryTree[] = $categoryMap[$id];
  143. }
  144. }
  145. return Result::success([
  146. 'rows' => $categoryTree,
  147. 'total' => $total,
  148. ]);
  149. }
  150. private function findMatchedCategories($search)
  151. {
  152. if ($search) {
  153. return Category::where('name', 'like', "%{$search}%")
  154. ->orderBy('updated_at', 'desc')
  155. ->get();
  156. }
  157. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  158. ->get();
  159. }
  160. private function findAllParents($categories)
  161. {
  162. $allCategories = [];
  163. foreach ($categories as $category) {
  164. $parentId = $category->pid;
  165. while ($parentId > 0) {
  166. $parent = Category::find($parentId);
  167. if ($parent) {
  168. $allCategories[$parent->id] = $parent;
  169. $parentId = $parent->pid;
  170. } else {
  171. break;
  172. }
  173. }
  174. $allCategories[$category->id] = $category;
  175. }
  176. return array_values($allCategories);
  177. }
  178. private function buildCategoryTree($category, $allRequiredCategories)
  179. {
  180. $categoryData = $category->toArray();
  181. $children = [];
  182. foreach ($allRequiredCategories as $c) {
  183. if ($c->pid === $category->id) {
  184. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  185. }
  186. }
  187. if (!empty($children)) {
  188. $categoryData['children'] = $children;
  189. }
  190. return $categoryData;
  191. }
  192. public function myCategoryList(array $data): array
  193. {
  194. $sszq = $data['sszq'] ?? '';
  195. unset($data['sszq']);
  196. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  197. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  198. $where[] = [
  199. 'pid',
  200. '=',
  201. $data['pid'],
  202. ];
  203. if (isset($data['name'])) {
  204. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  205. }
  206. var_dump($where);
  207. //根据分类id,从category表中取出分类信息
  208. $result = Category::where($where)
  209. ->whereIn('category.id', $catorytids)
  210. ->select('category.*', 'category.id as category_id')->get();
  211. if (empty($result)) {
  212. return Result::error("没有栏目数据");
  213. }
  214. return Result::success($result);
  215. }
  216. /**
  217. * @param array $data
  218. * @return array
  219. */
  220. public function categoryList(array $data): array
  221. {
  222. $where[] = [
  223. 'pid',
  224. '=',
  225. $data['pid']
  226. ];
  227. if (isset($data['name'])) {
  228. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  229. }
  230. var_dump($where);
  231. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  232. if (empty($result)) {
  233. return Result::error("没有栏目数据");
  234. }
  235. return Result::success($result);
  236. }
  237. /**
  238. * @param array $data
  239. * @return array
  240. */
  241. public function addCategory(array $data): array
  242. {
  243. if (isset($data['id'])) {
  244. unset($data['id']);
  245. }
  246. $id = Category::insertGetId($data);
  247. if (empty($id)) {
  248. return Result::error("添加失败");
  249. }
  250. return Result::success(['id' => $id]);
  251. }
  252. /**
  253. * @param array $data
  254. * @return array
  255. */
  256. public function delCategory(array $data): array
  257. {
  258. Db::beginTransaction();
  259. try {
  260. $categoryList = Category::where(['pid' => $data['id']])->get();
  261. if ($categoryList->toArray()) {
  262. Db::rollBack();
  263. return Result::error("分类下面有子分类不能删除");
  264. }
  265. $articleList = Article::where(['catid' => $data['id']])->get();
  266. if ($articleList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有资讯不能删除");
  269. }
  270. $result = Category::where($data)->delete();
  271. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  272. if (!$result) {
  273. Db::rollBack();
  274. return Result::error("删除失败");
  275. }
  276. Db::commit();
  277. return Result::success($result);
  278. } catch (\Exception $e) {
  279. Db::rollBack();
  280. return Result::error("删除失败" . $e->getMessage());
  281. }
  282. }
  283. /**
  284. * @param array $data
  285. * @return array
  286. */
  287. public function updateCategory(array $data): array
  288. {
  289. $where = [
  290. 'id' => $data['id'],
  291. ];
  292. $result = Category::where($where)->update($data);
  293. if ($result) {
  294. return Result::success($result);
  295. } else {
  296. return Result::error("更新失败");
  297. }
  298. }
  299. /**
  300. * 获取导航池信息
  301. * @param array $data
  302. * @return array
  303. */
  304. public function getCategoryInfo(array $data): array
  305. {
  306. $where = [
  307. 'id' => $data['id'],
  308. ];
  309. $result = Category::where($where)->first();
  310. if ($result) {
  311. return Result::success($result);
  312. } else {
  313. return Result::error("更新失败");
  314. }
  315. }
  316. public function getArticleCommend(array $data): array
  317. {
  318. $where = [
  319. 'website_id' => $data['website_id'],
  320. ];
  321. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  322. var_dump($ids);
  323. if (empty($ids)) {
  324. return Result::error("没有推荐数据");
  325. }
  326. //id
  327. $whereArticle = [];
  328. if (isset($data['id'])) {
  329. $whereArticle['id'] = $data['id'];
  330. }
  331. //title like
  332. if (isset($data['title'])) {
  333. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  334. }
  335. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  336. ->where($whereArticle)
  337. ->orderBy('id', 'desc')
  338. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  339. if ($article) {
  340. $data = [
  341. 'rows' => $article->items(),
  342. 'count' => $article->total(),
  343. ];
  344. return Result::success($data);
  345. } else {
  346. return Result::error("获取失败失败");
  347. }
  348. }
  349. /**
  350. * @param array $data
  351. * @return array
  352. */
  353. public function getArticleList(array $data): array
  354. {
  355. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  356. $type_id = $data['type_id'];
  357. unset($data['type_id']);
  358. $user_id = $data['user_id'];
  359. unset($data['user_id']);
  360. $where = [];
  361. $status1 = [];
  362. if (isset($data['id']) && $data['id']) {
  363. array_push($where, ['article.id', '=', $data['id']]);
  364. }
  365. if (isset($data['title']) && $data['title']) {
  366. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  367. }
  368. if (isset($data['category_name']) && $data['category_name']) {
  369. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  370. }
  371. if (isset($data['catid']) && $data['catid']) {
  372. array_push($where, ['article.catid', '=', $data['catid']]);
  373. }
  374. if (isset($data['author']) && $data['author']) {
  375. array_push($where, ['article.author', '=', $data['author']]);
  376. }
  377. if (isset($data['islink']) && $data['islink'] !== "") {
  378. array_push($where, ['article.islink', '=', $data['islink']]);
  379. }
  380. if (isset($data['status']) && $data['status'] !== "") {
  381. array_push($where, ['article.status', '=', $data['status']]);
  382. }
  383. if (isset($data['status1'])) {
  384. $status1 = json_decode(($data['status1']));
  385. }
  386. //不是管理员展示个人数据;
  387. if ($type_id != 10000) {
  388. $where[] = ['article.admin_user_id', '=', $user_id];
  389. }
  390. $rep = Article::where($where)
  391. ->whereNotIn('article.status', [404])
  392. ->when($status1, function ($query) use ($status1) {
  393. if (isset($status1) && $status1) {
  394. $query->whereIn('article.status', $status1);
  395. }
  396. })
  397. ->leftJoin('category', 'article.catid', 'category.id')
  398. ->leftJoin('website_category', function ($join) {
  399. $join->on('article.web_site_id', '=', 'website_category.website_id')
  400. ->on('article.catid', '=', 'website_category.category_id');
  401. })
  402. ->select("article.*", "category.name as category_name", "website_category.alias")
  403. ->orderBy("article.updated_at", "desc")
  404. ->limit($data['pageSize'])
  405. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  406. $count = Article::where($where)->whereNotIn('article.status', [404])
  407. ->when($status1, function ($query) use ($status1) {
  408. if (isset($status1) && $status1) {
  409. $query->whereIn('article.status', $status1);
  410. }
  411. })
  412. ->leftJoin('category', 'article.catid', 'category.id')->count();
  413. $data = [
  414. 'rows' => $rep->toArray(),
  415. 'count' => $count,
  416. ];
  417. if (empty($rep)) {
  418. return Result::error("没有信息数据");
  419. }
  420. return Result::success($data);
  421. }
  422. /**
  423. * @param array $data
  424. * @return array
  425. */
  426. public function addArticle(array $data): array
  427. {
  428. var_dump($data, '----------12-----------1');
  429. unset($data['user_type']);
  430. unset($data['nav_add_pool_id']);
  431. // unset($data['commend_id']);
  432. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  433. Db::beginTransaction();
  434. try {
  435. //处理投票
  436. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  437. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  438. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  439. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  440. unset($data['is_survey']);
  441. unset($data['survey_name']);
  442. unset($data['suvey_array']);
  443. // unset($data['website_id']);
  444. // unset($data['web_site_id']);
  445. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  446. if ($data['hits'] == '') {
  447. $data['hits'] = 0;
  448. }
  449. if ($data['is_original'] == '') {
  450. $data['is_original'] = 0;
  451. }
  452. if ($data['status'] == '') {
  453. $data['status'] = 0;
  454. }
  455. $articleData = $data;
  456. unset($articleData['content']);
  457. //自动处理缩略图、关键字、描述
  458. if ($articleData['imgurl'] == '') {
  459. //如果没有图,设置level=0
  460. $levelArr = json_decode($articleData['level'], true);
  461. var_dump($levelArr, '----------levelArr-----------1');
  462. //content中提取图片第一个图,正则提取
  463. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  464. preg_match_all($reg, $data['content'], $matches);
  465. if (isset($matches[1][0])) {
  466. //截取varchar240
  467. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  468. //如果有图,设置level=3
  469. if (!in_array(3, $levelArr)) {
  470. $levelArr[] = 3;
  471. }
  472. $articleData['level'] = json_encode($levelArr);
  473. } else {
  474. if (!in_array(0, $levelArr)) {
  475. $levelArr[] = 0;
  476. }
  477. $articleData['level'] = json_encode($levelArr);
  478. }
  479. }
  480. var_dump($articleData['level'], '----------$articleData[level]----------1');
  481. if ($articleData['keyword'] == '') {
  482. //提取标题+内容中的关键词
  483. $articleData['keyword'] = $data['title'];
  484. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  485. Jieba::init(); // 初始化 jieba-php
  486. Finalseg::init();
  487. $segList = Jieba::cut($articleData['keyword']);
  488. $segList1 = array_slice($segList, 0, 8);
  489. $articleData['keyword'] = implode(',', $segList1);
  490. }
  491. if ($articleData['introduce'] == '') {
  492. //提取内容中的描述
  493. $content = $data['content'];
  494. // 去除 <style> 和 <script> 标签及其内容
  495. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  496. // 去除所有 HTML 标签
  497. $content = strip_tags($content);
  498. // 去除 HTML 实体
  499. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  500. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  501. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  502. // 去除多余空白
  503. $content = preg_replace('/\s+/u', '', $content);
  504. // 截取 100 个字符
  505. $articleData['introduce'] = mb_substr($content, 0, 100);
  506. }
  507. if ($articleData['status'] == 0) {
  508. $this->sendMessage([
  509. 'talk_type' => 100,
  510. 'title' => $articleData['title'],
  511. 'content' => '提交了审核',
  512. 'messageType' => 2,
  513. ]);
  514. }
  515. $id = Article::insertGetId($articleData);
  516. $articleDataContent = [
  517. 'article_id' => $id,
  518. 'content' => $data['content'],
  519. ];
  520. ArticleData::insertGetId($articleDataContent);
  521. //处理投票
  522. if ($is_survey == 1) {
  523. //生成年月日时分秒+8位随机数
  524. $uuid = date('YmdHis') . rand(10000000, 99999999);
  525. var_dump($suvey_array, 'suvey_array________');
  526. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  527. var_dump($suveys_array, '---------------------1');
  528. var_dump($suvey_array, '---------------------2');
  529. $suvey_data = [];
  530. foreach ($suveys_array as $key => $value) {
  531. if ($value == '') {
  532. continue;
  533. }
  534. if (is_array($value)) {
  535. $suvey_data[] = [
  536. 'sur_id' => $uuid,
  537. 'art_id' => $id,
  538. 'website_id' => $website_id ?? 2,
  539. 'survey_name' => $survey_name,
  540. 'choice_name' => $value[1],
  541. 'is_other' => 1,
  542. 'other_id' => 0,
  543. 'results' => 0,
  544. ];
  545. } else {
  546. $suvey_data[] = [
  547. 'sur_id' => $uuid,
  548. 'art_id' => $id,
  549. 'website_id' => $website_id ?? 2,
  550. 'survey_name' => $survey_name,
  551. 'choice_name' => $value,
  552. 'is_other' => 0,
  553. 'other_id' => 0,
  554. 'results' => 0,
  555. ];
  556. }
  557. if (empty($suvey_data)) {
  558. throw new \Exception("投票数据为空");
  559. }
  560. }
  561. $result = ArticleSurvey::insert($suvey_data);
  562. if (!$result) {
  563. throw new \Exception("投票失败,ArticleSurvey插入失败");
  564. }
  565. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  566. if (!$result) {
  567. throw new \Exception("投票失败,更新主表失败");
  568. }
  569. }
  570. Db::commit();
  571. return Result::success(['id' => $id]);
  572. } catch (\Throwable $ex) {
  573. Db::rollBack();
  574. var_dump($ex->getMessage());
  575. return Result::error("创建失败", 0);
  576. }
  577. }
  578. /**
  579. * @param array $data
  580. * @return array
  581. */
  582. public function delArticle(array $data): array
  583. {
  584. $result = Article::where($data)->delete();
  585. //survey投票删除
  586. articleSurvey::where(['art_id' => $data['id']])->delete();
  587. if (!$result) {
  588. return Result::error("删除失败");
  589. }
  590. return Result::success($result);
  591. }
  592. /**
  593. * @param array $data
  594. * @return array
  595. */
  596. public function updateArticle(array $data): array
  597. {
  598. var_dump($data, '----------12-----------1');
  599. Db::beginTransaction();
  600. unset($data['user_type']);
  601. // unset($data['web_site_id']);
  602. unset($data['nav_add_pool_id']);
  603. try {
  604. //处理投票
  605. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  606. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  607. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  608. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  609. unset($data['is_survey']);
  610. unset($data['survey_name']);
  611. unset($data['suvey_array']);
  612. unset($data['website_id']);
  613. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  614. if ($data['hits'] == '') {
  615. $data['hits'] = 0;
  616. }
  617. if ($data['is_original'] == '') {
  618. $data['is_original'] = 0;
  619. }
  620. if ($data['status'] == '') {
  621. $data['status'] = 0;
  622. }
  623. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  624. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  625. $articleData = $data;
  626. unset($articleData['content']);
  627. unset($articleData['status_name']);
  628. unset($articleData['name']);
  629. unset($articleData['content']);
  630. unset($articleData['pid_arr']);
  631. unset($articleData['pid']);
  632. //自动处理缩略图、关键字、描述
  633. if ($articleData['imgurl'] == '') {
  634. //如果没有图,设置level=0
  635. $levelArr = json_decode($articleData['level'], true);
  636. var_dump($levelArr, '----------levelArr-----------1');
  637. //content中提取图片第一个图,正则提取
  638. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  639. preg_match_all($reg, $data['content'], $matches);
  640. if (isset($matches[1][0])) {
  641. //截取varchar240
  642. // 截取到第一个<
  643. $articleData['imgurl'] = $matches[1][0];
  644. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  645. $pos = strpos($articleData['imgurl'], '"');
  646. if ($pos !== false) {
  647. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  648. }
  649. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  650. //如果有图,设置level=3
  651. if (!in_array(3, $levelArr)) {
  652. $levelArr[] = 3;
  653. }
  654. $articleData['level'] = json_encode($levelArr);
  655. } else {
  656. if (!in_array(0, $levelArr)) {
  657. $levelArr[] = 0;
  658. }
  659. $articleData['level'] = json_encode($levelArr);
  660. }
  661. }
  662. var_dump($articleData['level'], '----------$articleData[level]----------1');
  663. if ($articleData['keyword'] == '') {
  664. //提取标题+内容中的关键词
  665. $articleData['keyword'] = $data['title'];
  666. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  667. Jieba::init(); // 初始化 jieba-php
  668. Finalseg::init();
  669. $segList = Jieba::cut($articleData['keyword']);
  670. $segList1 = array_slice($segList, 0, 8);
  671. $articleData['keyword'] = implode(',', $segList1);
  672. }
  673. if ($articleData['introduce'] == '') {
  674. //提取内容中的描述
  675. $content = $data['content'];
  676. // 去除 <style> 和 <script> 标签及其内容
  677. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  678. // 去除所有 HTML 标签
  679. $content = strip_tags($content);
  680. // 去除 HTML 实体
  681. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  682. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  683. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  684. // 去除多余空白
  685. $content = preg_replace('/\s+/u', '', $content);
  686. // 截取 100 个字符
  687. $articleData['introduce'] = mb_substr($content, 0, 100);
  688. }
  689. if ($articleData['status'] == 0) {
  690. $this->sendMessage([
  691. 'talk_type' => 100,
  692. 'title' => $articleData['title'],
  693. 'content' => '提交了审核',
  694. 'messageType' => 2,
  695. ]);
  696. }
  697. $id = Article::where(['id' => $data['id']])->update($articleData);
  698. $articleDataContent = [
  699. 'content' => $data['content'],
  700. ];
  701. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  702. //处理投票
  703. $id = $data['id'];
  704. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  705. var_dump($suvey_array, 'suvey_array________delete');
  706. //处理投票
  707. if ($is_survey == 1) {
  708. //生成年月日时分秒+8位随机数
  709. $uuid = date('YmdHis') . rand(10000000, 99999999);
  710. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  711. var_dump($suveys_array, '---------------------1');
  712. $suvey_data = [];
  713. if (is_array($suveys_array)) {
  714. foreach ($suveys_array as $key => $value) {
  715. if ($value == '') {
  716. continue;
  717. }
  718. if (is_array($value)) {
  719. $suvey_data[] = [
  720. 'sur_id' => $uuid,
  721. 'art_id' => $id,
  722. 'website_id' => $website_id ?? 2,
  723. 'survey_name' => $survey_name,
  724. 'choice_name' => $value[1],
  725. 'is_other' => 1,
  726. 'other_id' => 0,
  727. 'results' => 0,
  728. ];
  729. } else {
  730. $suvey_data[] = [
  731. 'sur_id' => $uuid,
  732. 'art_id' => $id,
  733. 'website_id' => $website_id ?? 2,
  734. 'survey_name' => $survey_name,
  735. 'choice_name' => $value,
  736. 'is_other' => 0,
  737. 'other_id' => 0,
  738. 'results' => 0,
  739. ];
  740. }
  741. if (empty($suvey_data)) {
  742. throw new \Exception("投票数据为空");
  743. }
  744. }
  745. }
  746. $result = ArticleSurvey::insert($suvey_data);
  747. if (!$result) {
  748. throw new \Exception("投票失败");
  749. }
  750. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  751. if (!$result) {
  752. throw new \Exception("投票失败");
  753. }
  754. } else {
  755. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  756. }
  757. Db::commit();
  758. return Result::success([]);
  759. } catch (\Throwable $ex) {
  760. Db::rollBack();
  761. var_dump($ex->getMessage());
  762. return Result::error("更新失败" . $ex->getMessage(), 0);
  763. }
  764. }
  765. /**
  766. * 更新资讯状态
  767. * @param array $data
  768. * @return array
  769. */
  770. public function upArticleStatus(array $data): array
  771. {
  772. $articleData = Article::where(['id' => $data['id']])->first();
  773. if ($data['status'] == 1) {
  774. $this->sendMessage([
  775. 'talk_type' => 101,
  776. 'title' => $articleData['title'],
  777. 'content' => '审核通过',
  778. 'messageType' => 2,
  779. 'user_id' => $articleData['admin_user_id'],
  780. ]);
  781. }
  782. if ($data['status'] == 2) {
  783. $this->sendMessage([
  784. 'talk_type' => 101,
  785. 'title' => $articleData['title'],
  786. 'content' => '审核拒绝',
  787. 'messageType' => 2,
  788. 'user_id' => $articleData['admin_user_id'],
  789. ]);
  790. }
  791. if ($data['status'] == 0) {
  792. $this->sendMessage([
  793. 'talk_type' => 100,
  794. 'title' => $articleData['title'],
  795. 'content' => '提交了审核',
  796. 'messageType' => 2,
  797. ]);
  798. }
  799. $result = Article::where(['id' => $data['id']])->update($data);
  800. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  801. //article_ignore 表插入数据 db操作
  802. //转成数组
  803. //删掉数据重新写入
  804. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  805. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  806. $insert_data = [];
  807. foreach ($website_ids as $key => $value) {
  808. $insert_data[] = [
  809. 'article_id' => $data['id'],
  810. 'website_id' => $value,
  811. ];
  812. }
  813. DB::table('article_ignore')->insert($insert_data);
  814. }
  815. if ($result) {
  816. return Result::success();
  817. } else {
  818. return Result::error("更新状态失败", 0);
  819. }
  820. }
  821. /**
  822. * 获取新闻详情
  823. * @param array $data
  824. * @return array
  825. */
  826. public function getArticleInfo(array $data): array
  827. {
  828. $where = [
  829. 'article.id' => $data['id'],
  830. // 'article.status' => 1,
  831. ];
  832. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  833. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  834. $info = $result;
  835. // var_dump($info, 'info');
  836. $info['survey_array'] = $articleSurvey;
  837. if ($result) {
  838. return Result::success($info);
  839. } else {
  840. return Result::error("查询失败", 0);
  841. }
  842. }
  843. /**
  844. * 获取头条新闻
  845. * @param array $data
  846. * @return array
  847. */
  848. public function getWebsiteArticlett(array $data): array
  849. {
  850. $website_id = $data['website_id'];
  851. $website = Website::where('id', $data['website_id'])->first();
  852. if(empty($website)){
  853. return Result::error("网站不存在",0);
  854. }
  855. $categorys = $this->processArticlePro($website_id);
  856. $catiall = $categorys['catiall'];
  857. $categoryIds = $categorys['categoryIds'];
  858. $where = [
  859. 'status' => 1
  860. ];
  861. // $website_column = $website['column'];
  862. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  863. $website_column = json_decode($website['website_column_arr_id'],true);
  864. }
  865. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  866. // return Result::success($diff_pid_categoryIds);
  867. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  868. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  869. }
  870. // $website_id = $data['website_id'];
  871. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  872. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  873. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  874. switch ($data['level']) {
  875. case 1:
  876. case 2:
  877. case 3:
  878. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  879. $query = Article::where($where)
  880. ->where('level', 'like', '%' . $data['level'] . '%')
  881. ->orderBy('updated_at', 'desc');
  882. break;
  883. case 4: //最新资讯
  884. $query = Article::where($where)->orderBy('updated_at', 'desc');
  885. break;
  886. case 5: //资讯推荐
  887. $query = Article::where($where)
  888. ->where('updated_at', '>', $month);
  889. break;
  890. case 7: //资讯分类
  891. if (isset($data['id']) && !empty($data['id'])) {
  892. $keyword = Article::where('id', $data['id'])->value('keyword');
  893. $keywordArray = explode(',', $keyword);
  894. $whereL7 = [];
  895. foreach ($keywordArray as $k => $v) {
  896. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  897. }
  898. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  899. break;
  900. } else {
  901. return Result::error("请输入资讯ID", 0);
  902. break;
  903. }
  904. default:
  905. break;
  906. }
  907. // $whereL7 = [];
  908. // if(isset($data['id']) && !empty($data['id'])){
  909. // $keyword = Article::where('id', $data['id'])->value('keyword');
  910. // $keywordArray = explode(',', $keyword);
  911. // foreach ($keywordArray as $k => $v) {
  912. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  913. // }
  914. // }
  915. // $query = Article::where($where)
  916. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  917. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  918. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  919. // }
  920. // if($data['level'] == 7){
  921. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  922. // }
  923. // if($data['level'] == 4){
  924. // $query = $query->inRandomOrder()
  925. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  926. // }
  927. // if($data['level'] == 5){
  928. // $query = $query->orderBy('updated_at','desc');
  929. // }
  930. // });
  931. if ($data['textnum'] > 0) {
  932. $query = clone $query;
  933. $result['text'] = $query
  934. ->whereIn('catid', $categoryIds)
  935. ->leftJoinSub(function ($query) use ($website_id) {
  936. $query->from('article_ignore')
  937. ->where('website_id', $website_id);
  938. }, 'article_ignore', function ($join) {
  939. $join->on('article_ignore.article_id', '=', 'article.id');
  940. })
  941. ->where(function ($query) use ($website_id) {
  942. $query->whereNull('article_ignore.article_id')
  943. ->orWhere('article_ignore.website_id', '!=', $website_id);
  944. })
  945. ->select(
  946. 'article.id',
  947. 'article.title',
  948. 'article.author',
  949. 'article.updated_at',
  950. 'article.introduce',
  951. 'article.islink',
  952. 'article.linkurl',
  953. 'article.copyfrom',
  954. 'article.cat_arr_id',
  955. 'article.catid',
  956. 'article.level'
  957. )
  958. ->offset($data['placeid'])
  959. ->limit($data['textnum'])
  960. ->get()->all();
  961. foreach ($result['text'] as $k => $v) {
  962. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  963. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  964. }
  965. }
  966. if ($data['imgnum'] > 0) {
  967. $query = clone $query;
  968. $result['img'] = $query
  969. ->whereIn('catid', $categoryIds)
  970. ->where('article.imgurl', '!=', '')
  971. ->select(
  972. 'article.id',
  973. 'article.title',
  974. 'article.imgurl',
  975. 'article.author',
  976. 'article.updated_at',
  977. 'article.introduce',
  978. 'article.islink',
  979. 'article.linkurl',
  980. 'article.copyfrom',
  981. 'article.cat_arr_id',
  982. 'article.catid',
  983. 'article.level'
  984. )
  985. ->offset($data['placeid'])
  986. ->limit($data['imgnum'])
  987. ->get()->all();
  988. foreach ($result['img'] as $k => $v) {
  989. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  990. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  991. }
  992. }
  993. if (empty($result)) {
  994. return Result::error("暂无相关资讯", 0);
  995. }
  996. return Result::success($result);
  997. }
  998. /**
  999. * 获取模块新闻
  1000. * @param array $data
  1001. * @return array
  1002. */
  1003. public function getWebsiteModelArticles(array $data): array
  1004. {
  1005. $catid = $data['catid'];
  1006. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1007. $category = $category->toArray();
  1008. if (!empty($category)) {
  1009. $where = [
  1010. 'status' => 1,
  1011. 'catid' => $catid,
  1012. ];
  1013. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1014. // 1:文字新闻;2:轮播图;3:图文;
  1015. // 级别:0:未分类
  1016. // 3:推荐图片
  1017. if ($data['level'] == 1) {
  1018. $data['level'] = 0;
  1019. }
  1020. $result = Article::where($where)
  1021. ->where(function ($query) use ($data) {
  1022. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1023. ->orWhereNull("level")
  1024. ->orWhereRaw("level = '[]'");
  1025. })
  1026. ->where(function ($query) use ($data) {
  1027. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1028. ->orWhereNull("ignore_ids");
  1029. })
  1030. ->orderBy("updated_at", "desc")
  1031. ->offset($placeid)
  1032. ->limit($data['pagesize'])
  1033. ->get();
  1034. if (empty($result)) {
  1035. return Result::error("此栏目暂无相关新闻", 0);
  1036. }
  1037. } else {
  1038. return Result::error("此网站暂无此栏目", 0);
  1039. }
  1040. return Result::success($result);
  1041. }
  1042. /**
  1043. *获取新闻列表
  1044. * @param array $data
  1045. * @return array
  1046. */
  1047. public function getWebsiteArticleList(array $data): array
  1048. {
  1049. // return Result::success($data);
  1050. $where[] = ['status', '=', 1];
  1051. $website_id = $data['website_id'];
  1052. $website = Website::where('id', $data['website_id'])->first();
  1053. if(empty($website)){
  1054. return Result::error("网站不存在",0);
  1055. }
  1056. // $website_column = $website['column'];
  1057. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  1058. $website_column = json_decode($website['website_column_arr_id'],true);
  1059. }
  1060. $categorys = $this->processArticlePro($website_id);
  1061. $cat_1st_arr = $categorys['cat_1st_arr'];
  1062. $catiall = $categorys['catiall'];
  1063. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1064. // return Result::success($diff_pid_categoryIds);
  1065. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1066. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1067. }
  1068. if (isset($data['catid']) && !empty($data['catid'])) {
  1069. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1070. if (empty($category)) {
  1071. return Result::error("此网站暂无此栏目", 0);
  1072. }
  1073. array_push($where, ['catid', '=', $data['catid']]);
  1074. }
  1075. // return Result::success($where);
  1076. $query = Article::where($where)
  1077. ->leftJoinSub(function ($query) use ($website_id) {
  1078. $query->from('article_ignore')
  1079. ->where('website_id', $website_id);
  1080. }, 'article_ignore', function ($join) {
  1081. $join->on('article_ignore.article_id', '=', 'article.id');
  1082. })
  1083. ->where(function ($query) use ($website_id) {
  1084. $query->whereNull('article_ignore.article_id')
  1085. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1086. })
  1087. ->select(
  1088. 'article.id',
  1089. 'article.title',
  1090. 'article.imgurl',
  1091. 'article.author',
  1092. 'article.updated_at',
  1093. 'article.introduce',
  1094. 'article.islink',
  1095. 'article.linkurl',
  1096. 'article.copyfrom',
  1097. 'article.cat_arr_id',
  1098. 'article.catid'
  1099. );
  1100. $count = $query->count();
  1101. $rep = $query->orderBy("updated_at", "desc")
  1102. ->offset(($data['page'] - 1) * $data['pageSize'])
  1103. ->limit($data['pageSize'])
  1104. ->get()->all();
  1105. $categorys = $this->processArticlePro($website_id);
  1106. $cat_1st_arr = $categorys['cat_1st_arr'];
  1107. $catiall = $categorys['catiall'];
  1108. // $web['website_id'] = $data['website_id'];
  1109. foreach ($rep as $k => $v) {
  1110. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1111. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1112. }
  1113. // $rep = $this->processArticles($rep,$web);
  1114. $data = [
  1115. 'rows' => $rep,
  1116. 'count' => $count,
  1117. ];
  1118. if (empty($rep)) {
  1119. return Result::error("没有信息数据");
  1120. }
  1121. return Result::success($data);
  1122. }
  1123. /**
  1124. * 前端-获取新闻详情
  1125. * @param array $data
  1126. * @return array
  1127. */
  1128. public function selectWebsiteArticleInfo(array $data): array
  1129. {
  1130. $where = [
  1131. 'article.id' => $data['id'],
  1132. 'article.status' => 1,
  1133. ];
  1134. $result = Article::where($where)
  1135. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1136. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1137. ->where(function ($query) use ($data) {
  1138. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1139. ->orWhereNull("ignore_ids");
  1140. })
  1141. ->select(
  1142. 'article.*',
  1143. 'article_data.content',
  1144. 'article_data.article_id',
  1145. 'article_extend.website_url',
  1146. 'article_extend.email',
  1147. 'article_extend.contacts',
  1148. 'article_extend.contacts_mobile',
  1149. 'article_extend.contacts_address',
  1150. 'article_extend.zip_code',
  1151. 'article_extend.enterprise_name'
  1152. )
  1153. ->first();
  1154. if (empty($result)) {
  1155. return Result::error("暂无此新闻!", 0);
  1156. }
  1157. if (!empty($result['publiced_at'])) {
  1158. $result['updated_at'] = $result['publiced_at'];
  1159. }
  1160. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1161. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1162. ->where('website_category.website_id', $data['website_id'])
  1163. ->where(['website_category.category_id' => $result['catid']])
  1164. ->first();
  1165. if (empty($category)) {
  1166. return Result::error("查询失败", 0);
  1167. }
  1168. //手动推荐文章
  1169. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1170. if (empty($commend_ids)) {
  1171. $commendArticle = [];
  1172. } else {
  1173. //去除不存在的文章ID
  1174. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1175. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1176. ->where('article.status', 1)
  1177. ->where('website_category.website_id', $data['website_id'])
  1178. ->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')
  1179. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1180. // ->orderBy('article.updated_at', 'desc')
  1181. ->limit(5)
  1182. ->get();
  1183. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1184. foreach ($commendArticle as $k => $v) {
  1185. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1186. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1187. $cat_arr_id = array_unique($cat_arr_id);
  1188. // 从website_category取出alias_pinyin
  1189. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1190. ->whereIn('category_id', $cat_arr_id)
  1191. ->pluck('alias_pinyin', 'category_id')
  1192. ->toArray();
  1193. // 将cat_arr_id的json转成路径/隔开
  1194. $path_parts = [];
  1195. foreach ($cat_arr_id as $cat_id) {
  1196. if (isset($cat_arr[$cat_id])) {
  1197. $path_parts[] = $cat_arr[$cat_id];
  1198. }
  1199. }
  1200. $v->alias_pinyin = implode('/', $path_parts);
  1201. } else {
  1202. $v->alias_pinyin = '';
  1203. }
  1204. }
  1205. }
  1206. $result['category_id'] = $category['category_id'];
  1207. $result['cat_name'] = $category['alias'];
  1208. $result['website_name'] = $category['website_name'] ?? "";
  1209. $result['suffix'] = $category['suffix'] ?? "";
  1210. $result['commendArticle'] = $commendArticle;
  1211. $result['commend_ids'] = $commend_ids;
  1212. return Result::success($result);
  1213. }
  1214. /**
  1215. * 前端-获取网站调查问卷
  1216. * @param array $data
  1217. * @return array
  1218. */
  1219. public function getWebsiteSurvey(array $data): array
  1220. {
  1221. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1222. $website = Website::where('id', $data['website_id'])->first();
  1223. if (empty($website)) {
  1224. return Result::error("暂无此网站", 0);
  1225. }
  1226. }
  1227. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1228. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1229. if (empty($article)) {
  1230. return Result::error("暂无此文章", 0);
  1231. }
  1232. // return Result::error($data,0);
  1233. $where['art_id'] = $data['art_id'];
  1234. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1235. } else {
  1236. $survey = Article::where(function ($query) {
  1237. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1238. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1239. })
  1240. ->where('status', 1)
  1241. ->where('is_survey', 1)
  1242. ->select('survey_id')
  1243. ->orderBy('updated_at', 'desc')
  1244. ->first();
  1245. if (empty($survey)) {
  1246. return Result::error("暂无调查问卷", 0);
  1247. }
  1248. $where['sur_id'] = $survey['survey_id'];
  1249. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1250. }
  1251. // return Result::success($where);
  1252. $result = ArticleSurvey::where($where)
  1253. ->where(function ($query) {
  1254. $query->where('is_other', 0)
  1255. ->orWhere(function ($subQuery) {
  1256. $subQuery->where('is_other', 1)
  1257. ->where('other_id', 0);
  1258. });
  1259. })
  1260. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1261. ->select('article_survey.*', 'article.survey_type')
  1262. ->get()->all();
  1263. if (empty($result)) {
  1264. return Result::error("此文章暂无调查问卷", 0);
  1265. }
  1266. return Result::success($result);
  1267. }
  1268. /**
  1269. * 前端-添加网站调查问卷选项
  1270. * @param array $data
  1271. * @return array
  1272. */
  1273. public function addWebsiteSurveyOption(array $data): array
  1274. {
  1275. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1276. $website = Website::where('id', $data['website_id'])->first();
  1277. if (empty($website)) {
  1278. return Result::error("暂无此网站", 0);
  1279. }
  1280. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1281. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1282. if (empty($survey)) {
  1283. return Result::error("此调查问卷不可添加选项", 0);
  1284. }
  1285. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1286. $choice = [
  1287. 'art_id' => $survey['art_id'],
  1288. 'website_id' => $data['website_id'],
  1289. 'survey_name' => $survey['survey_name'],
  1290. 'choice_name' => $data['choice_name'],
  1291. 'sur_id' => $survey['sur_id'],
  1292. 'is_other' => 1,
  1293. 'other_id' => $survey['id'],
  1294. ];
  1295. $result = ArticleSurvey::insertGetId($choice);
  1296. if (empty($result)) {
  1297. return Result::error("添加失败", 0);
  1298. }
  1299. return Result::success($result);
  1300. }
  1301. }
  1302. return Result::error("添加失败", 0);
  1303. }
  1304. return Result::error("添加失败", 0);
  1305. }
  1306. /**
  1307. * 前端-调查问卷投票
  1308. * @param array $data
  1309. * @return array
  1310. */
  1311. public function addWebsiteSurveyVote(array $data): array
  1312. {
  1313. // return Result::success($data);
  1314. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1315. $website = Website::where('id', $data['website_id'])->first();
  1316. if (empty($website)) {
  1317. return Result::error("暂无此网站", 0);
  1318. }
  1319. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1320. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1321. // return Result::success($survey);
  1322. if (empty($is_survey)) {
  1323. return Result::error("此调查问卷不存在", 0);
  1324. }
  1325. // return Result::success($survey);
  1326. // 调查问卷类型
  1327. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1328. //多选 若是json型则转化成数组类型
  1329. if (strpos($data['choice_id'], '[') === 0) {
  1330. $data['choice_id'] = json_decode($data['choice_id'], true);
  1331. } else {
  1332. // 单选 也转换成数组
  1333. $data['choice_id'] = [$data['choice_id']];
  1334. }
  1335. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1336. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1337. // ->where('website_id',$data['website_id'])
  1338. ->where('is_other', 1)
  1339. ->where('other_id', 0)
  1340. ->first();
  1341. if (!empty($other)) {
  1342. return Result::error("请选择已有的选项!", 0);
  1343. }
  1344. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1345. // ->where('website_id',$data['website_id'])
  1346. ->where('is_other', 1)
  1347. ->where('other_id', '!=', 0)
  1348. ->first();
  1349. // return Result::success($choice['other']);
  1350. $choice_id = $data['choice_id'];
  1351. if (!empty($choice['other'])) {
  1352. // array_push($data['choice_id'],$choice['other']['other_id']);
  1353. if (!empty($choice_id)) {
  1354. $key = array_search($choice['other']['id'], $choice_id);
  1355. if ($key !== false) {
  1356. unset($choice_id[$key]);
  1357. $choice_id = array_values($choice_id);
  1358. }
  1359. array_push($choice_id, $choice['other']['other_id']);
  1360. } else {
  1361. $choice_id[0] = $choice['other']['other_id'];
  1362. }
  1363. array_push($data['choice_id'], $choice['other']['other_id']);
  1364. }
  1365. // return Result::success($data);
  1366. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1367. // ->where('website_id',$data['website_id'])
  1368. ->increment('results', 1);
  1369. if (empty($choice)) {
  1370. return Result::error("请选择已有的选项!", 0);
  1371. }
  1372. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1373. // ->where('website_id',$data['website_id'])
  1374. ->where('other_id', 0)
  1375. ->get();
  1376. $survey['choice'] = $choice_id;
  1377. return Result::success($survey);
  1378. }
  1379. return Result::error("参数必填!");
  1380. }
  1381. return Result::error("此调查问卷不存在", 0);
  1382. }
  1383. return Result::error("参数必填!");
  1384. }
  1385. /**
  1386. * 后端-获取网站调查问卷列表
  1387. * @param array $data
  1388. * @return array
  1389. */
  1390. public function getSurveyList(array $data): array
  1391. {
  1392. $where = [];
  1393. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1394. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1395. }
  1396. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1397. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1398. }
  1399. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1400. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1401. }
  1402. // return Result::success($where);
  1403. if (!empty($where)) {
  1404. $query = Article::where($where)->where(function ($q) {
  1405. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1406. });
  1407. } else {
  1408. $query = Article::where(function ($q) {
  1409. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1410. });
  1411. }
  1412. $count = $query->count();
  1413. $survey = $query->orderByDesc('id')
  1414. ->limit($data['pageSize'])
  1415. ->offset(($data['page'] - 1) * $data['pageSize'])
  1416. ->get();
  1417. if (empty($survey->toArray())) {
  1418. return Result::error("暂无调查问卷!", 0);
  1419. }
  1420. $result = [
  1421. 'rows' => $survey,
  1422. 'count' => $count,
  1423. ];
  1424. return Result::success($result);
  1425. }
  1426. /**
  1427. * 后端-获取网站调查问卷详情
  1428. * @param array $data
  1429. * @return array
  1430. */
  1431. public function getSurveyInfo(array $data): array
  1432. {
  1433. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1434. $where = ['sur_id' => $data['sur_id']];
  1435. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1436. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1437. ->select('article_survey.*', 'article.survey_type')
  1438. ->get()->all();
  1439. if (empty($choose)) {
  1440. return Result::error("此调查问卷不存在", 0);
  1441. }
  1442. $resultsArray = array_column($choose, 'results');
  1443. $total = array_sum($resultsArray);
  1444. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1445. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1446. // $total = 0;
  1447. if (!empty($other)) {
  1448. $total = $total + $other['results'];
  1449. $other['choice_name'] = '(其他)';
  1450. if (!empty($others)) {
  1451. $other['hasChildren'] = true;
  1452. // array_push($other,['hasChildren','=',true]);
  1453. $other['children'] = $others;
  1454. $other_choices = [$other->toArray()];
  1455. $mer_choice = array_merge($choose, $other_choices);
  1456. $value_choice = array_values($mer_choice);
  1457. } else {
  1458. // return Result::error('1111');
  1459. $other_choices = [$other->toArray()];
  1460. $other_choices = array_merge($choose, $other_choices);
  1461. $value_choice = array_values($other_choices);
  1462. // return Result::success($result);
  1463. }
  1464. } else {
  1465. $value_choice = $choose;
  1466. }
  1467. $result = [
  1468. 'choose' => $value_choice,
  1469. 'total' => $total,
  1470. ];
  1471. }
  1472. return Result::success($result);
  1473. }
  1474. /**
  1475. * 前端-搜索新闻列表
  1476. * @param array $data
  1477. * @return array
  1478. */
  1479. public function selectWebsiteArticle(array $data): array
  1480. {
  1481. $website = Website::where('id', $data['website_id'])->first();
  1482. if(empty($website)){
  1483. return Result::error("网站不存在",0);
  1484. }
  1485. // $website_column = $website['column'];
  1486. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  1487. $website_column = json_decode($website['website_column_arr_id'],true);
  1488. }
  1489. $website_id = $data['website_id'];
  1490. $categorys = $this->processArticlePro($website_id);
  1491. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1492. // return Result::success($diff_pid_categoryIds);
  1493. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1494. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1495. }
  1496. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1497. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1498. $catiall = $categorys['catiall'];
  1499. $categoryIds = $categorys['categoryIds'];
  1500. // return Result::success($categoryIds);
  1501. $query = Article::where('status', 1)
  1502. ->whereIn('catid', $categoryIds)
  1503. ->leftJoinSub(function ($query) use ($website_id) {
  1504. $query->from('article_ignore')
  1505. ->where('website_id', $website_id);
  1506. }, 'article_ignore', function ($join) {
  1507. $join->on('article_ignore.article_id', '=', 'article.id');
  1508. })
  1509. ->where(function ($query) use ($website_id) {
  1510. $query->whereNull('article_ignore.article_id')
  1511. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1512. });
  1513. // ->get()->all();
  1514. // return Result::success($query);
  1515. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1516. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1517. }
  1518. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1519. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1520. }
  1521. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1522. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1523. }
  1524. // 计算总数
  1525. $count = $query->count();
  1526. // return Result::success($count);
  1527. // 分页查询
  1528. $articles = $query
  1529. ->select(
  1530. 'article.id',
  1531. 'article.title',
  1532. 'article.imgurl',
  1533. 'article.author',
  1534. 'article.updated_at',
  1535. 'article.introduce',
  1536. 'article.islink',
  1537. 'article.linkurl',
  1538. 'article.copyfrom',
  1539. 'article.cat_arr_id',
  1540. 'article.catid',
  1541. 'article.department_arr_id',
  1542. 'article.city_arr_id',
  1543. )
  1544. ->orderBy("updated_at", "desc")
  1545. ->offset(($data['page'] - 1) * $data['pageSize'])
  1546. ->limit($data['pageSize'])
  1547. ->get();
  1548. // return Result::success($articles);
  1549. foreach ($articles as $k => $v) {
  1550. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1551. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1552. }
  1553. if (empty($articles)) {
  1554. return Result::error("没有符合条件的资讯数据");
  1555. }
  1556. $result = [
  1557. 'rows' => $articles,
  1558. 'count' => $count,
  1559. ];
  1560. return Result::success($result);
  1561. }
  1562. /**
  1563. * 模块新闻加强版
  1564. * @param array $data
  1565. * @return array
  1566. */
  1567. public function getWebsiteCatidArticle(array $data): array
  1568. {
  1569. $where = [
  1570. 'website_category.category_id' => $data['catid'],
  1571. 'website_category.website_id' => $data['website_id'],
  1572. ];
  1573. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1574. $child_catnum = $data['child_catnum'] ?? 1;
  1575. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1576. $childCategoryIds = array_column($category['child'], 'category_id');
  1577. if (empty($childCategoryIds)) {
  1578. return Result::error("暂无子栏目", 0);
  1579. }
  1580. $imgArticles = [];
  1581. $textArticles = [];
  1582. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1583. // 初始化子分类图片新闻和文字新闻数组
  1584. // 查询所有子级栏目的图文新闻
  1585. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1586. ->where(function ($query) use ($data) {
  1587. $query->where(function ($subQuery) use ($data) {
  1588. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1589. })->orWhereNull("ignore_ids");
  1590. })
  1591. ->where('status', 1)
  1592. ->where('imgurl', '!=', '')
  1593. ->select('*')
  1594. ->orderBy('updated_at', 'desc')
  1595. ->limit($data['child_imgnum'])
  1596. ->get();
  1597. }
  1598. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1599. // 查询所有子级栏目的文字新闻
  1600. $textArticles = Article::where('catid', $childCategoryIds[0])
  1601. ->where('status', 1)
  1602. ->where(function ($query) use ($data) {
  1603. $query->where(function ($subQuery) use ($data) {
  1604. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1605. })->orWhereNull("ignore_ids");
  1606. })
  1607. ->select('*')
  1608. ->orderBy('updated_at', 'desc')
  1609. ->limit($data['child_textnum'])
  1610. ->get();
  1611. }
  1612. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1613. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1614. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1615. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1616. return $child;
  1617. }, $category['child']);
  1618. }
  1619. // }
  1620. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1621. $category['img'] = WebsiteCategory::where($where)
  1622. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1623. ->where('article.status', 1)
  1624. ->where('article.imgurl', '!=', '')
  1625. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1626. ->orderBy('article.updated_at', 'desc')
  1627. ->limit($data['img_num'])
  1628. ->get();
  1629. }
  1630. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1631. $category['text'] = WebsiteCategory::where($where)
  1632. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1633. ->where('article.status', 1)
  1634. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1635. ->orderBy('article.updated_at', 'desc')
  1636. ->limit($data['text_num'])
  1637. ->get();
  1638. }
  1639. // $category = $category->get();
  1640. if (empty($category)) {
  1641. return Result::error("查询失败", 0);
  1642. }
  1643. return Result::success($category);
  1644. }
  1645. /**
  1646. * 模块新闻加强plus版
  1647. * @param array $data
  1648. * @return array
  1649. */
  1650. public function getWebsiteAllArticle(array $data): array
  1651. {
  1652. // return Result::success($data);
  1653. $time1 = microtime(true);
  1654. $wetbsite_id = $data['website_id'] ?? 2;
  1655. $data = json_decode($data['id'], true);
  1656. $website = Website::where('id', $wetbsite_id)->first();
  1657. if(empty($website)){
  1658. return Result::error("网站不存在",0);
  1659. }
  1660. // return Result::success($website);
  1661. $website_column = $website['website_column_arr_id'] ?? '[]';
  1662. $website_column = json_decode($website_column,true);
  1663. $categorys = $this->processArticlePro($wetbsite_id);
  1664. $cat_1st_arr = $categorys['cat_1st_arr'];
  1665. $catiall = $categorys['catiall'];
  1666. // return Result::success($catiall);
  1667. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1668. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1669. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1670. }
  1671. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1672. // return Result::success($categorys);
  1673. $parent_category = array_column($data, 'parent');
  1674. $parent_cat = [];
  1675. $child_category = array_column($data, 'child');
  1676. if (!empty($parent_category)) {
  1677. foreach ($parent_category as $key => $value) {
  1678. $arr = array_map('intval', explode(',', $value));
  1679. $parent_cat[$key] = $arr[0] ?? 0;
  1680. $parent_category = $arr[0] ?? 0;
  1681. $article_imgnum = $arr[1] ?? 0;
  1682. $article_textnum = $arr[2] ?? 0;
  1683. if ($parent_category != 0) {
  1684. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1685. // return Result::success($category_arr);
  1686. if ($article_imgnum != 0) {
  1687. $img_article = Article::whereIn('catid', $category_arr)
  1688. ->where('status', 1)
  1689. ->where('imgurl', '!=', '')
  1690. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1691. $query->from('article_ignore')
  1692. ->where('website_id', $wetbsite_id);
  1693. }, 'article_ignore', function ($join) {
  1694. $join->on('article_ignore.article_id', '=', 'article.id');
  1695. })
  1696. ->where(function ($query) use ($wetbsite_id) {
  1697. $query->whereNull('article_ignore.article_id')
  1698. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1699. })
  1700. ->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')
  1701. ->orderBy('updated_at', 'desc')
  1702. ->limit($article_imgnum)
  1703. ->get()->all();
  1704. foreach ($img_article as $k => $v) {
  1705. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1706. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1707. }
  1708. } else {
  1709. $img_article = [];
  1710. }
  1711. if ($article_textnum != 0) {
  1712. $text_article = Article::whereIn('catid', $category_arr)
  1713. ->where('status', 1)
  1714. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1715. $query->from('article_ignore')
  1716. ->where('website_id', $wetbsite_id);
  1717. }, 'article_ignore', function ($join) {
  1718. $join->on('article_ignore.article_id', '=', 'article.id');
  1719. })
  1720. ->where(function ($query) use ($wetbsite_id) {
  1721. $query->whereNull('article_ignore.article_id')
  1722. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1723. })
  1724. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1725. ->orderBy('updated_at', 'desc')
  1726. ->limit($article_textnum)
  1727. ->get()->all();
  1728. foreach ($text_article as $k => $v) {
  1729. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1730. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1731. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1732. }
  1733. } else {
  1734. $text_article = [];
  1735. }
  1736. $catiall[$parent_category]['imgnum'] = $img_article;
  1737. $catiall[$parent_category]['textnum'] = $text_article;
  1738. $parent[$key] = $catiall[$parent_category];
  1739. } else {
  1740. $parent[$key] = '';
  1741. }
  1742. }
  1743. }
  1744. if (!empty($child_category)) {
  1745. foreach ($child_category as $key => $value) {
  1746. $arr = array_map('intval', explode(',', $value));
  1747. $parent_category = $parent_cat[$key];
  1748. $child_category = $arr[0] ?? 0;
  1749. $article_imgnum = $arr[1] ?? 0;
  1750. $article_textnum = $arr[2] ?? 0;
  1751. if ($child_category != 0) {
  1752. $all_childcat = $cat_1st_arr[$parent_category];
  1753. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1754. // 从 $websiteInfoIndexed 中获取对应的数据
  1755. $info = $websiteInfoIndexed[$v];
  1756. // 返回一个包含所需信息的数组
  1757. return [
  1758. 'alias' => $info->alias,
  1759. 'category_id' => $info->category_id,
  1760. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1761. 'pid' => $info->pid,
  1762. 'type' => $info->type,
  1763. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1764. 'pinyin' => $info->pinyin,
  1765. ];
  1766. }, $all_childcat);
  1767. if ($article_imgnum != 0) {
  1768. $img_article = Article::where('catid', $child_category)
  1769. ->where('status', 1)
  1770. ->where('imgurl', '!=', '')
  1771. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1772. $query->from('article_ignore')
  1773. ->where('website_id', $wetbsite_id);
  1774. }, 'article_ignore', function ($join) {
  1775. $join->on('article_ignore.article_id', '=', 'article.id');
  1776. })
  1777. ->where(function ($query) use ($wetbsite_id) {
  1778. $query->whereNull('article_ignore.article_id')
  1779. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1780. })
  1781. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1782. ->orderBy('updated_at', 'desc')
  1783. ->limit($article_imgnum)
  1784. ->get()->all();
  1785. foreach ($img_article as $k => $v) {
  1786. // var_dump($v);
  1787. // var_dump($k);
  1788. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1789. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1790. }
  1791. } else {
  1792. $img_article = [];
  1793. }
  1794. if ($article_textnum != 0) {
  1795. $text_article = Article::where('catid', $child_category)
  1796. ->where('status', 1)
  1797. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1798. $query->from('article_ignore')
  1799. ->where('website_id', $wetbsite_id);
  1800. }, 'article_ignore', function ($join) {
  1801. $join->on('article_ignore.article_id', '=', 'article.id');
  1802. })
  1803. ->where(function ($query) use ($wetbsite_id) {
  1804. $query->whereNull('article_ignore.article_id')
  1805. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1806. })
  1807. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1808. ->orderBy('updated_at', 'desc')
  1809. ->limit($article_textnum)
  1810. ->get()->all();
  1811. foreach ($text_article as $k => $v) {
  1812. // var_dump($v);
  1813. // var_dump($k);
  1814. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1815. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1816. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1817. }
  1818. } else {
  1819. $text_article = [];
  1820. }
  1821. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1822. $catiall[$child_category]['imgnum'] = $img_article;
  1823. $catiall[$child_category]['textnum'] = $text_article;
  1824. $child[$key] = $catiall[$child_category];
  1825. // var_dump($pids);
  1826. } else {
  1827. $child[$key] = '';
  1828. }
  1829. }
  1830. }
  1831. foreach ($parent as $key => $value) {
  1832. $result[$key] = $value;
  1833. if (!empty($child[$key])) {
  1834. // var_dump($child[$key]);
  1835. $result[$key]['child'] = $child[$key];
  1836. // $value[$key]['child'] = $child[$key];
  1837. } else {
  1838. $result[$key]['child'] = [
  1839. "alias" => null,
  1840. "category_id" => null,
  1841. "type" => null,
  1842. "pinyin" => null,
  1843. "all_childcat" => [],
  1844. "imgnum" => [],
  1845. "textnum" => []
  1846. ];
  1847. }
  1848. }
  1849. return Result::success($result);
  1850. }
  1851. /**
  1852. * 辅助方法:获取文章列表
  1853. */
  1854. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1855. {
  1856. sleep(1);
  1857. $query = Article::where('article.status', 1)
  1858. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1859. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1860. ->where(function ($query) use ($website) {
  1861. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1862. })
  1863. ->leftJoin('website_category', function ($join) use ($website) {
  1864. $join->on('article.catid', '=', 'website_category.category_id')
  1865. ->where('website_category.website_id', '=', $website['website_id']);
  1866. })
  1867. ->select(
  1868. 'article.id',
  1869. 'article.title',
  1870. 'article.imgurl',
  1871. 'article.author',
  1872. 'article.updated_at',
  1873. 'article.introduce',
  1874. 'article.islink',
  1875. 'article.linkurl',
  1876. 'article.copyfrom',
  1877. 'article.cat_arr_id',
  1878. 'article.catid',
  1879. 'website_category.alias as category_name'
  1880. )
  1881. ->orderBy('updated_at', 'desc')
  1882. ->limit($limit);
  1883. // 如果是图片文章,添加图片URL条件
  1884. if ($isImageArticle) {
  1885. $query->where('imgurl', '!=', '');
  1886. } else {
  1887. // 文字文章不需要imgurl字段
  1888. $query->addSelect('article.introduce');
  1889. }
  1890. $articles = $query->get();
  1891. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1892. }
  1893. /**
  1894. * 乡村网-获取特殊新闻模块
  1895. * @param array $data
  1896. * @return array
  1897. */
  1898. public function getWebsiteArticles(array $data): array
  1899. {
  1900. $website_id = $data['website_id'];
  1901. $website = Website::where('id', $website_id)->first();
  1902. if(empty($website)){
  1903. return Result::error("网站不存在",0);
  1904. }
  1905. // return Result::success($website);
  1906. $website_column = $website['website_column_arr_id'] ?? '[]';
  1907. $website_column = json_decode($website_column, true);
  1908. $catids = json_decode($data['id'], true);
  1909. $parent_category = array_column($catids, 'parent');
  1910. if(!empty($parent_category) && is_array($parent_category)) {
  1911. $categorys = $this->processArticlePro($website_id);
  1912. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1913. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1914. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1915. }
  1916. $catiall = $categorys['catiall'];
  1917. $cat_1st_arr = $categorys['cat_1st_arr'];
  1918. // return Result::success($categorys);
  1919. foreach ($parent_category as $key => $value) {
  1920. $arr = array_map('intval', explode(',', $value));
  1921. $parent_category = $arr[0] ?? 0;
  1922. $article_imgnum = $arr[1] ?? 0;
  1923. $article_textnum = $arr[2] ?? 0;
  1924. if ($parent_category != 0) {
  1925. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1926. // return Result::success($category_arr);
  1927. if ($article_imgnum != 0) {
  1928. $img_article = Article::whereIn('catid', $category_arr)
  1929. ->where('status', 1)
  1930. ->where('imgurl', '!=', '')
  1931. ->leftJoinSub(function ($query) use ($website_id) {
  1932. $query->from('article_ignore')
  1933. ->where('website_id', $website_id);
  1934. }, 'article_ignore', function ($join) {
  1935. $join->on('article_ignore.article_id', '=', 'article.id');
  1936. })
  1937. ->where(function ($query) use ($website_id) {
  1938. $query->whereNull('article_ignore.article_id')
  1939. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1940. })
  1941. ->select(
  1942. 'id',
  1943. 'title',
  1944. 'imgurl',
  1945. 'author',
  1946. 'updated_at',
  1947. 'introduce',
  1948. 'islink',
  1949. 'linkurl',
  1950. 'copyfrom',
  1951. 'cat_arr_id',
  1952. 'catid as category_id'
  1953. )
  1954. ->orderBy('updated_at', 'desc')
  1955. ->limit($article_imgnum)
  1956. ->get()->all();
  1957. foreach ($img_article as $k => $v) {
  1958. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1959. // return Result::success($v);
  1960. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1961. }
  1962. } else {
  1963. $img_article = [];
  1964. }
  1965. if ($article_textnum != 0) {
  1966. $text_article = Article::whereIn('catid', $category_arr)
  1967. ->where('status', 1)
  1968. ->leftJoinSub(function ($query) use ($website_id) {
  1969. $query->from('article_ignore')
  1970. ->where('website_id', $website_id);
  1971. }, 'article_ignore', function ($join) {
  1972. $join->on('article_ignore.article_id', '=', 'article.id');
  1973. })
  1974. ->where(function ($query) use ($website_id) {
  1975. $query->whereNull('article_ignore.article_id')
  1976. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1977. })
  1978. ->select(
  1979. 'id',
  1980. 'title',
  1981. 'author',
  1982. 'updated_at',
  1983. 'introduce',
  1984. 'islink',
  1985. 'linkurl',
  1986. 'copyfrom',
  1987. 'cat_arr_id',
  1988. 'catid as category_id'
  1989. )
  1990. ->orderBy('updated_at', 'desc')
  1991. ->limit($article_textnum)
  1992. ->get()->all();
  1993. foreach ($text_article as $k => $v) {
  1994. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1995. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1996. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1997. }
  1998. } else {
  1999. $text_article = [];
  2000. }
  2001. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2002. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2003. $parent[$key] = $catiall[$parent_category];
  2004. } else {
  2005. $parent[$key] = [];
  2006. }
  2007. }
  2008. }
  2009. return Result::success($parent);
  2010. }
  2011. // 封装处理商品的路由问题
  2012. function processGoods($goods, $data)
  2013. {
  2014. return $goods->map(function ($good) use ($data) {
  2015. $catid = $good->catid ?? 0;
  2016. // $pinyin = '';
  2017. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2018. if (!empty($category->pid) && $category->pid != 0) {
  2019. $level = json_decode($category->category_arr_id, true);
  2020. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2021. ->whereIn('category_id', $level)
  2022. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2023. ->get(['aLIas_pinyin'])
  2024. ->pluck('aLIas_pinyin')
  2025. ->implode('/');
  2026. } else {
  2027. $pinyin = $category->aLIas_pinyin ?? '';
  2028. }
  2029. if (isset($good->city_id) && !empty($good->city_id)) {
  2030. $city = District::where('id', $good->city_id)->first(['name']);
  2031. $good->city_name = $city->name ?? '';
  2032. }
  2033. // 解析imgurl JSON并取第一条数据
  2034. $imgUrls = json_decode($good->imgurl, true);
  2035. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2036. $good->pinyin = $pinyin;
  2037. return $good;
  2038. });
  2039. }
  2040. /**
  2041. * 获取商城首页-根据栏目id
  2042. * @param array $data
  2043. * @return array
  2044. * */
  2045. function getWebsiteCatidshop(array $data): array
  2046. {
  2047. $input['catid'] = $data['catid'];
  2048. $input['website_id'] = $data['website_id'];
  2049. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2050. $result = array_map(function ($item) use ($input) {
  2051. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2052. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2053. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2054. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2055. if (empty($category) || $category->type != 2) {
  2056. return Result::error("暂无此栏目", 0);
  2057. } else {
  2058. $website['website_id'] = $input['website_id'];
  2059. $goods = Good::where('good.status', 2)
  2060. ->where('good.website_id', $website['website_id'])
  2061. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2062. ->select(
  2063. 'good.id',
  2064. 'good.name',
  2065. 'good.imgurl',
  2066. 'good.description',
  2067. 'good.updated_at',
  2068. 'good.catid',
  2069. 'good.type_id',
  2070. 'good.price',
  2071. 'good.com',
  2072. 'good.level',
  2073. 'good.unit'
  2074. )
  2075. ->orderBy('updated_at', 'desc')
  2076. ->offset($goodStart)
  2077. ->limit($goodNum);
  2078. $all_goods = $goods->get();
  2079. $all_goods = $this->processGoods($all_goods, $website);
  2080. }
  2081. return $all_goods ?? [];
  2082. }
  2083. }, $data);
  2084. return Result::success($result);
  2085. }
  2086. /**
  2087. * 获取商品模块
  2088. * @param array $data
  2089. * @return array
  2090. * */
  2091. public function getWebsiteshop(array $data): array
  2092. {
  2093. $input['id'] = $data['id'];
  2094. $input['website_id'] = $data['website_id'];
  2095. $catid = $data['catid'];
  2096. $data = json_decode($input['id'] ?? '', true) ?? [];
  2097. $result['goods'] = array_map(function ($item) use ($input) {
  2098. // 检查parent元素是否存在且不是undefined
  2099. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2100. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2101. $website = $input['website_id'];
  2102. $query = Good::where('good.status', 2)
  2103. ->where('good.website_id', $website);
  2104. switch ($Levelid) {
  2105. case 1:
  2106. case 2:
  2107. case 3:
  2108. $goods = $query->where(function ($q) use ($Levelid) {
  2109. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2110. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2111. });
  2112. break;
  2113. case 4:
  2114. $goods = $query;
  2115. break;
  2116. case 5:
  2117. $goods = $query->where('type_id', 1);
  2118. break;
  2119. case 6:
  2120. $goods = $query->where('type_id', 2);
  2121. break;
  2122. default:
  2123. return [];
  2124. }
  2125. $all_goods = $goods
  2126. ->select(
  2127. 'good.id',
  2128. 'good.name',
  2129. 'good.imgurl',
  2130. 'good.description',
  2131. 'good.updated_at',
  2132. 'good.catid',
  2133. 'good.type_id',
  2134. 'good.price',
  2135. 'good.level',
  2136. 'good.website_id'
  2137. )
  2138. ->orderBy('updated_at', 'desc')
  2139. ->offset($goodStart)
  2140. ->limit($goodNum)
  2141. ->get();
  2142. $web['website_id'] = $website;
  2143. $all_goods = $this->processGoods($all_goods, $web);
  2144. }
  2145. return $all_goods;
  2146. }, $data);
  2147. $website = $input['website_id'];
  2148. $result['article'] = Article::where(function ($query) use ($website) {
  2149. $query->where(function ($subQuery) use ($website) {
  2150. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2151. })->orWhereNull("ignore_ids");
  2152. })
  2153. ->where('catid', $catid)
  2154. ->where('article.status', 1)
  2155. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2156. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2157. ->orderBy('article.updated_at', 'desc')
  2158. ->first();
  2159. return Result::success($result);
  2160. }
  2161. /**
  2162. * 获取商品分类
  2163. * @param array $data
  2164. * @return array
  2165. * */
  2166. public function getWebsiteshopCat(array $data): array
  2167. {
  2168. $website = $data['website_id'];
  2169. $category = WebsiteCategory::where('website_id', $website)
  2170. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2171. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2172. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2173. ->orderBy('sort')
  2174. ->get();
  2175. $cat = $category->map(function ($item) use ($website) {
  2176. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2177. $pid = $item->pid ?? 0;
  2178. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2179. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2180. ->where('website_id', $website)
  2181. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2182. ->get(['aLIas_pinyin'])
  2183. ->pluck('aLIas_pinyin')
  2184. ->implode('/');
  2185. } else {
  2186. $pinyin = $item->aLIas_pinyin ?? '';
  2187. }
  2188. $item->pinyin = $pinyin;
  2189. });
  2190. if (empty($category)) {
  2191. return Result::error("栏目查询失败", 0);
  2192. }
  2193. $cat_tree = Result::buildMenuTree($category);
  2194. $web['website_id'] = $website;
  2195. $goods = Good::where('website_id', $website)
  2196. ->where('status', 2)
  2197. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2198. ->latest('updated_at')
  2199. ->offset(($data['page'] - 1) * $data['pageSize'])
  2200. ->limit($data['pageSize'])
  2201. ->get();
  2202. if (!empty($goods)) {
  2203. if ($goods->count() > 1 && !empty($goods)) {
  2204. $goods = $this->processGoods($goods, $web);
  2205. }
  2206. } else {
  2207. $goods = [];
  2208. }
  2209. $result = [
  2210. 'category' => $cat_tree,
  2211. 'goods' => $goods,
  2212. ];
  2213. // $resul['goods'] = $goods;
  2214. if (empty($result)) {
  2215. return Result::error("查询失败", 0);
  2216. }
  2217. return Result::success($result);
  2218. }
  2219. /*
  2220. * 获取商品列表
  2221. * @param array $data
  2222. * @return array
  2223. * */
  2224. public function getWebsiteshopList(array $data): array
  2225. {
  2226. // return Result::success($data);
  2227. $where = [
  2228. 'status' => 2,
  2229. 'website_id' => $data['website_id'],
  2230. ];
  2231. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2232. // return Result::error("查询失败", 0);
  2233. // }
  2234. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2235. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2236. $data['catid'] = $category->category_id ?? 0;
  2237. }
  2238. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2239. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2240. }
  2241. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2242. array_push($where, ['type_id', $data['type_id']]);
  2243. }
  2244. $query = Good::where($where)
  2245. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2246. $query->where(function ($q) use ($data) {
  2247. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2248. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2249. });
  2250. })
  2251. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2252. $query->where(function ($q) use ($data) {
  2253. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2254. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2255. });
  2256. })
  2257. ->select(
  2258. 'good.id',
  2259. 'good.name',
  2260. 'good.imgurl',
  2261. 'good.description',
  2262. 'good.updated_at',
  2263. 'good.com',
  2264. 'good.catid',
  2265. 'good.type_id',
  2266. 'good.website_id',
  2267. 'good.cat_arr_id',
  2268. 'good.created_at',
  2269. 'good.city_id'
  2270. )
  2271. ->latest('updated_at');
  2272. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2273. $result['count'] = $query->clone()->count();
  2274. $result['goods'] = $this->processGoods(
  2275. $query->clone()
  2276. ->offset(($data['page'] - 1) * $data['pageSize'])
  2277. ->limit($data['pageSize'])
  2278. ->get(),
  2279. $data
  2280. );
  2281. } else {
  2282. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2283. // 获取 type_id 为 1 的数据
  2284. $result['type1'] = $this->processGoods(
  2285. $query->clone()
  2286. ->where('type_id', 1)
  2287. ->offset(($data['page'] - 1) * $data['pageSize'])
  2288. ->limit($data['pageSize'])
  2289. ->get(),
  2290. $data
  2291. );
  2292. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2293. // 获取 type_id 为 2 的数据
  2294. $result['type2'] = $this->processGoods(
  2295. $query->clone()
  2296. ->where('type_id', 2)
  2297. ->offset(($data['page'] - 1) * $data['pageSize'])
  2298. ->limit($data['pageSize'])
  2299. ->get(),
  2300. $data
  2301. );
  2302. }
  2303. if (empty($result)) {
  2304. return Result::error("查询失败", 0);
  2305. }
  2306. return Result::success($result);
  2307. }
  2308. /**
  2309. * 获取商品详情
  2310. * @param array $data
  2311. * @return array
  2312. * */
  2313. public function getWebsiteshopInfo(array $data): array
  2314. {
  2315. $where = [
  2316. 'good.status' => 2,
  2317. 'good.website_id' => $data['website_id'],
  2318. 'good.id' => $data['id'],
  2319. ];
  2320. $goods = Good::where($where)
  2321. ->where('good.id', $data['id'])
  2322. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2323. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2324. ->first();
  2325. if (empty($goods)) {
  2326. return Result::error("查询失败", 0);
  2327. }
  2328. $goods->imgurl = json_decode($goods->imgurl, true);
  2329. return Result::success($goods);
  2330. }
  2331. /**
  2332. * plus pro 处理文章路由问题
  2333. */
  2334. function processArticlePro($website_id)
  2335. {
  2336. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2337. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2338. // // 取出category_id 对应的aLIas_pinyin
  2339. // $categoryIds = array_column($categorys, 'category_id');
  2340. // $categoryPIds = array_column($categorys, 'pid');
  2341. // $aliasPinyins = array_column($categorys, 'path');
  2342. // $alias = array_column($categorys, 'alias');
  2343. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2344. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2345. // // return Result::success($cat_arr);
  2346. // // $catiall = [];
  2347. // //一级所有子级的记录
  2348. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2349. // return [
  2350. // 'cat_1st_arr' => $cat_alias_arr,
  2351. // 'catiall' => $cat_arr,
  2352. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2353. // 'categoryIds' => $categoryIds,
  2354. // ];
  2355. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2356. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2357. // 取出category_id 对应的aLIas_pinyin
  2358. $categoryIds = array_column($categorys, 'category_id');
  2359. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function($pid) {
  2360. return $pid != 0;
  2361. })));
  2362. $category_path = array_column($categorys, 'path');
  2363. $cat_arr = array_combine($categoryIds, $category_path);
  2364. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2365. $catiall = [];
  2366. //一级所有子级的记录
  2367. $cat_1st_arr = [];
  2368. foreach ($categorys as $key => $value) {
  2369. // $category_arr_id = json_decode($value->category_arr_id);
  2370. // $pinyin_str = '';
  2371. // // 算出一级 并且算出子级
  2372. if ($value->pid != 0 && in_array($value->pid,$categoryIds)) {
  2373. $cat_1st_arr[$value->pid][] = $value->category_id;
  2374. }
  2375. // foreach ($category_arr_id as $k => $v) {
  2376. // $pinyin_str .= $cat_arr[$v] . '/';
  2377. // }
  2378. // $pinyin_str = rtrim($pinyin_str, '/');
  2379. $catiall[$value->category_id]['alias'] = $value->alias;
  2380. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2381. $catiall[$value->category_id]['type'] = $value->type;
  2382. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2383. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2384. }
  2385. return [
  2386. 'cat_1st_arr' => $cat_1st_arr,
  2387. 'catiall' => $catiall,
  2388. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2389. 'categoryIds' => $categoryIds,
  2390. 'diff_pid_categoryIds' => array_diff($categoryPIds,$categoryIds),
  2391. 'categoryPIds' => $categoryPIds,
  2392. ];
  2393. }
  2394. /**
  2395. * 封装处理文章的路由问题
  2396. * */
  2397. function processArticles($articles, $data)
  2398. {
  2399. // 检查 $articles 是否为数组或可迭代对象
  2400. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2401. return $articles->map(function ($article) use ($data) {
  2402. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2403. $catid = $article->cat_arr_id ?? '';
  2404. }
  2405. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2406. $catid = $article->category_arr_id ?? '';
  2407. }
  2408. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2409. $level = json_decode($catid, true);
  2410. if (!is_array($level)) {
  2411. return $article;
  2412. } else {
  2413. $level = array_map('intval', $level);
  2414. }
  2415. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2416. ->where($data)
  2417. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2418. ->pluck('aLIas_pinyin')
  2419. ->implode('/');
  2420. $article->pinyin = $pinyin ?? '';
  2421. return $article;
  2422. });
  2423. } else {
  2424. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2425. $catid = $articles->cat_arr_id ?? '';
  2426. $level = json_decode($catid, true);
  2427. if (!is_array($level)) {
  2428. return $articles;
  2429. } else {
  2430. $level = array_map('intval', $level);
  2431. }
  2432. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2433. ->where($data)
  2434. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2435. ->pluck('aLIas_pinyin')
  2436. ->implode('/');
  2437. $articles->pinyin = $pinyin ?? '';
  2438. return $articles;
  2439. }
  2440. }
  2441. // 封装处理由问题
  2442. function processJob($job, $data)
  2443. {
  2444. return $job->map(function ($job) use ($data) {
  2445. $category = $job->cat_arr_id ?? '';
  2446. $cityid = $job->city_arr_id ?? '';
  2447. $city = json_decode($cityid, true);
  2448. $pinyin = '';
  2449. $level = json_decode($category, true);
  2450. // 路由
  2451. if (!empty($level) && is_array($level)) {
  2452. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2453. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2454. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2455. ->get(['aLIas_pinyin'])
  2456. ->pluck('aLIas_pinyin')
  2457. ->implode('/');
  2458. if (empty($pinyin)) {
  2459. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2460. }
  2461. $job->pinyin = $pinyin;
  2462. }
  2463. // 取职位-城市 市??省
  2464. if (!empty($city) && is_array($city)) {
  2465. if (isset($city[1]) && !empty($city[1])) {
  2466. $city = District::where('id', $city[1])->first(['name']);
  2467. $job->city_name = $city->name ?? '';
  2468. } else if (isset($city[0]) && !empty($city[0])) {
  2469. $city = District::where('id', $city[0])->first(['name']);
  2470. $job->city_name = $city->name ?? '';
  2471. } else {
  2472. $job->city_name = '全国';
  2473. }
  2474. }
  2475. // 获取简历最后一级地区
  2476. if (isset($job->city_id) && !empty($job->city_id)) {
  2477. $city = District::where('id', $job->city_id)->first(['name']);
  2478. $job->hunt_cityname = $city->name ?? '';
  2479. }
  2480. // 组合详细地址
  2481. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2482. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2483. if (is_array($address_id) && !empty($address_id)) {
  2484. $address = District::whereIn('id', $address_id)
  2485. ->orderBy('level', 'asc')
  2486. ->get(['name'])
  2487. ->pluck('name')
  2488. ->implode('');
  2489. // $job->address_name = $address ?? '';
  2490. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2491. }
  2492. }
  2493. // 取行业
  2494. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2495. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2496. if (!empty($job->industry)) {
  2497. $query->where('hyid', $job->industry);
  2498. } else if (!empty($job->hy_id)) {
  2499. $query->where('hyid', $job->hy_id);
  2500. } else if (!empty($job->company_hy_id)) {
  2501. $query->where('hyid', $job->company_hy_id);
  2502. } else {
  2503. $query->where('hyid', $job->job_industry);
  2504. }
  2505. })->first(['hyname']);
  2506. $job->hy_name = $hy_name->hyname ?? '';
  2507. }
  2508. // 取职位类别
  2509. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2510. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2511. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2512. $job->zw_name = $zw_name->zwname ?? '';
  2513. }
  2514. // 取具体职位
  2515. 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))) {
  2516. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2517. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2518. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2519. }
  2520. // 取工作经验
  2521. if (isset($job->experience) && !empty($job->experience)) {
  2522. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2523. $job->experience_name = $experience->ename ?? '';
  2524. }
  2525. // 取学历
  2526. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2527. $education = $job->educational ?? $job->school_education;
  2528. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2529. $job->education_name = $education->ename ?? '';
  2530. }
  2531. // 语言
  2532. if (isset($job->language) && !empty($job->language)) {
  2533. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2534. $job->language_name = $language->ename ?? '';
  2535. }
  2536. // 薪资
  2537. if (isset($job->salary) && !empty($job->salary)) {
  2538. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2539. $job->salary_name = $salary->ename ?? '';
  2540. }
  2541. // 职位性质
  2542. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2543. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2544. $job->job_nature_name = $job_nature->ename ?? '';
  2545. }
  2546. // 公司规模
  2547. if (isset($job->company_size) && !empty($job->company_size)) {
  2548. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2549. $job->company_size_name = $company_size->ename ?? '';
  2550. }
  2551. // 公司性质
  2552. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2553. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2554. $job->company_nature_name = $company_nature->nature_name ?? '';
  2555. }
  2556. // $job->pinyin = $pinyin;
  2557. return $job;
  2558. });
  2559. }
  2560. /**
  2561. * 获取书籍模块
  2562. * @param array $data
  2563. * @return array
  2564. * */
  2565. public function getWebsiteBook(array $data): array
  2566. {
  2567. $input['id'] = $data['id'];
  2568. $input['website_id'] = $data['website_id'];
  2569. // 将 JSON 字符串转换为 PHP 数组
  2570. $data = json_decode($input['id'], true);
  2571. // 使用 array_map 处理每个元素
  2572. $result = array_map(function ($item) use ($input) {
  2573. // 检查parent元素是否存在且不是undefined
  2574. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2575. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2576. $website = [
  2577. 'website_id' => $input['website_id'],
  2578. ];
  2579. // 查询栏目名称
  2580. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2581. if (empty($category)) {
  2582. $parent_alias = '';
  2583. $parent_pinyin = null;
  2584. $imgBooks = [];
  2585. $textBooks = [];
  2586. } else {
  2587. $parent_alias = $category->alias ?? '';
  2588. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2589. // 查找子分类ID数组
  2590. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2591. array_push($childCategoryIds, $parentCatId);
  2592. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2593. if ($parentImgNum != 0) {
  2594. // 查询图片新闻
  2595. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2596. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2597. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2598. })
  2599. ->where('book.status', 2)
  2600. ->where('book.img_url', '!=', '')
  2601. ->leftJoin('website_category', function ($join) use ($website) {
  2602. $join->on('book.cat_id', '=', 'website_category.category_id')
  2603. ->where('website_category.website_id', '=', $website['website_id']);
  2604. })
  2605. ->select(
  2606. 'book.id',
  2607. 'book.title',
  2608. 'book.img_url',
  2609. 'book.price',
  2610. 'book.market_price',
  2611. 'book.description',
  2612. 'book.cat_id',
  2613. 'book.description',
  2614. 'book.updated_at',
  2615. 'website_category.alias as category_name',
  2616. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2617. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2618. )
  2619. ->orderBy('updated_at', 'desc')
  2620. ->limit($parentImgNum)
  2621. ->get()->all();
  2622. // 查询文字新闻
  2623. }
  2624. if ($parentTextNum != 0) {
  2625. $textBooks = [];
  2626. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2627. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2628. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2629. })
  2630. ->where('book.status', 2)
  2631. ->leftJoin('website_category', function ($join) use ($website) {
  2632. $join->on('book.cat_id', '=', 'website_category.category_id')
  2633. ->where('website_category.website_id', '=', $website['website_id']);
  2634. })
  2635. ->select(
  2636. 'book.id',
  2637. 'book.title',
  2638. 'book.img_url',
  2639. 'book.price',
  2640. 'book.market_price',
  2641. 'book.description',
  2642. 'book.cat_id',
  2643. 'book.description',
  2644. 'book.updated_at',
  2645. 'website_category.alias as category_name',
  2646. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2647. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2648. )
  2649. ->orderBy('updated_at', 'desc')
  2650. ->limit($parentTextNum)
  2651. ->get()->all();
  2652. }
  2653. }
  2654. }
  2655. $resultItem = [
  2656. 'alias' => $parent_alias ?? '',
  2657. 'category_id' => $parentCatId ?? 0,
  2658. 'pinyin' => $parent_pinyin ?? null,
  2659. 'imgnum' => $imgBooks ?? [],
  2660. 'textnum' => $textBooks ?? [],
  2661. ];
  2662. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2663. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2664. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2665. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2666. ->get()->all();
  2667. if (!empty($childCategory)) {
  2668. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2669. // 查询子栏目名称
  2670. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2671. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2672. ->first();
  2673. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2674. $childImgArticles = [];
  2675. $childTextArticles = [];
  2676. $resultItem['child'] = [];
  2677. } else {
  2678. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2679. // 查询子栏目图片新闻
  2680. $childImgArticles = Book::where('cat_id', $childCatId)
  2681. ->where('status', 2)
  2682. ->where('img_url', '!=', '')
  2683. ->leftJoin('website_category', function ($join) use ($website) {
  2684. $join->on('book.cat_id', '=', 'website_category.category_id')
  2685. ->where('website_category.website_id', '=', $website['website_id']);
  2686. })
  2687. ->select(
  2688. 'book.id',
  2689. 'book.title',
  2690. 'book.img_url',
  2691. 'book.price',
  2692. 'book.market_price',
  2693. 'book.description',
  2694. 'book.cat_id',
  2695. 'book.description',
  2696. 'book.updated_at',
  2697. DB::raw("'$child_pinyin' as pinyin")
  2698. )
  2699. ->orderBy('updated_at', 'desc')
  2700. ->limit($childImgNum)
  2701. ->get()->all();
  2702. // 查询子栏目文字新闻
  2703. $childTextArticles = Book::where('cat_id', $childCatId)
  2704. ->where('status', 2)
  2705. ->leftJoin('website_category', function ($join) use ($website) {
  2706. $join->on('book.cat_id', '=', 'website_category.category_id')
  2707. ->where('website_category.website_id', '=', $website['website_id']);
  2708. })
  2709. ->select(
  2710. 'book.id',
  2711. 'book.title',
  2712. 'book.img_url',
  2713. 'book.price',
  2714. 'book.market_price',
  2715. 'book.description',
  2716. 'book.cat_id',
  2717. 'book.description',
  2718. 'book.updated_at',
  2719. DB::raw("'$child_pinyin' as pinyin")
  2720. )
  2721. ->orderBy('updated_at', 'desc')
  2722. ->limit($childTextNum)
  2723. ->get()->all();
  2724. $resultItem['child'] = [
  2725. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2726. 'category_id' => $childCatId,
  2727. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2728. 'all_childcat' => $childCategory,
  2729. 'imgnum' => $childImgArticles,
  2730. 'textnum' => $childTextArticles,
  2731. ];
  2732. }
  2733. }
  2734. } else {
  2735. $resultItem['child'] = [];
  2736. }
  2737. return $resultItem;
  2738. }, $data);
  2739. return Result::success($result);
  2740. }
  2741. /**
  2742. * 获取书刊列表
  2743. * @param array $data
  2744. * @return array
  2745. * */
  2746. public function getWebsiteBookList(array $data): array
  2747. {
  2748. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2749. if (empty($web)) {
  2750. return Result::error("查询失败", 0);
  2751. }
  2752. $catid = $data['id'];
  2753. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2754. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2755. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2756. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2757. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2758. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2759. ->where('pid', $category['pid'])
  2760. ->select(
  2761. 'category_id',
  2762. 'alias',
  2763. 'aLIas_pinyin',
  2764. 'pid',
  2765. 'sort',
  2766. 'is_url',
  2767. 'web_url',
  2768. 'seo_title',
  2769. 'seo_keywords',
  2770. 'seo_description',
  2771. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2772. )
  2773. ->orderBy('sort')
  2774. ->get()->all();
  2775. if (empty($category)) {
  2776. return Result::error("查询失败", 0);
  2777. }
  2778. $query = Book::where('book.status', 2)
  2779. ->where('book.website_id', $data['website_id'])
  2780. ->where('book.cat_id', $catid)
  2781. ->select(
  2782. 'book.id',
  2783. 'book.title',
  2784. 'book.img_url',
  2785. 'book.description',
  2786. 'book.updated_at',
  2787. 'book.cat_id',
  2788. DB::raw("'$pinyin' as pinyin")
  2789. )
  2790. ->orderBy('book.updated_at', 'desc');
  2791. $count = $query->count();
  2792. $query = clone $query;
  2793. $Book = $query
  2794. ->limit($data['pageSize'])
  2795. ->offset(($data['page'] - 1) * $data['pageSize'])
  2796. ->get()->all();
  2797. $result = [
  2798. 'category' => $categorys,
  2799. 'books' => $Book,
  2800. 'count' => $count,
  2801. ];
  2802. // if(empty($result)){
  2803. // return Result::error("查询失败", 0);
  2804. // }
  2805. return Result::success($result);
  2806. }
  2807. /**
  2808. * 获取书刊详情
  2809. * @param array $data
  2810. * @return array
  2811. * */
  2812. public function getWebsiteBookInfo(array $data): array
  2813. {
  2814. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2815. if (empty($web)) {
  2816. return Result::error("查询失败", 0);
  2817. }
  2818. $book = Book::where('status', 2)
  2819. ->where('website_id', $data['website_id'])
  2820. ->where('id', $data['id'])
  2821. ->select(
  2822. 'book.*',
  2823. )
  2824. ->orderBy('updated_at', 'desc')
  2825. ->first();
  2826. if (empty($book)) {
  2827. return Result::error("查询失败", 0);
  2828. }
  2829. // 先查询当前分类的 pid
  2830. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2831. ->where('category_id', $book['cat_id'])
  2832. ->first(['pid', 'category_id']);
  2833. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2834. if (!empty($carpid)) {
  2835. if ($carpid->pid != 0) {
  2836. $pid = $carpid['pid'];
  2837. // $parent_pinyin = '';
  2838. } else {
  2839. $pid = $carpid['category_id'];
  2840. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2841. }
  2842. }
  2843. $categorys = $query->where('pid', $pid)
  2844. ->select(
  2845. 'category_id',
  2846. 'alias',
  2847. 'aLIas_pinyin',
  2848. 'pid',
  2849. 'sort',
  2850. 'is_url',
  2851. 'web_url',
  2852. 'category_arr_id as cat_arr_id',
  2853. )
  2854. ->orderBy('sort')
  2855. ->get();
  2856. $category = $this->processArticle($categorys, $data);
  2857. $result = [
  2858. 'category' => $category,
  2859. 'books' => $book,
  2860. ];
  2861. return Result::success($result);
  2862. }
  2863. /**
  2864. * 尝试
  2865. * @param array $data
  2866. * @return array
  2867. * */
  2868. public function test(array $data): array
  2869. {
  2870. $input['id'] = $data['id'];
  2871. $input['website_id'] = $data['website_id'];
  2872. // 将 JSON 字符串转换为 PHP 数组
  2873. $data = json_decode($input['id'], true);
  2874. $result = [];
  2875. $article = $data;
  2876. $result = array_map(function ($item) use ($input) {
  2877. $website = [
  2878. 'website_id' => $input['website_id'],
  2879. ];
  2880. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2881. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2882. $parent = [
  2883. 0 => $category['category_id'] ?? [],
  2884. 1 => $parentImgNum ?? [],
  2885. 2 => $parentTextNum ?? [],
  2886. ];
  2887. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2888. $child = [];
  2889. $resultItem = [
  2890. // 'alias' => $parent_alias ?? '',
  2891. 'category_id' => $parentCatId ?? 0,
  2892. 'pinyin' => $parentImgNum ?? null,
  2893. 'imgnum' => $parentTextNum ?? [],
  2894. // 'textnum' => $textArticles ?? [],
  2895. ];
  2896. return $parent;
  2897. }, $data);
  2898. return Result::success($result);
  2899. // });
  2900. }
  2901. /**
  2902. * 封装处理文章的路由问题
  2903. * */
  2904. function processArticle($article, $data)
  2905. {
  2906. return $article->map(function ($article) use ($data) {
  2907. $catid = $article->cat_arr_id ?? '';
  2908. $level = json_decode($catid, true);
  2909. $pinyin = '';
  2910. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2911. if (!empty($level) && is_array($level)) {
  2912. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2913. ->where('website_id', $data['website_id'])
  2914. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2915. ->get(['aLIas_pinyin'])
  2916. ->pluck('aLIas_pinyin')
  2917. ->implode('/');
  2918. } else {
  2919. $pinyin = '';
  2920. }
  2921. $article->pinyin = $pinyin;
  2922. return $article;
  2923. });
  2924. }
  2925. /**
  2926. * c端-获取招工招聘下拉选框
  2927. * @param array $data
  2928. * @return array
  2929. * */
  2930. public function getWebsiteJobSelect(array $data): array
  2931. {
  2932. $web = Website::where('id', $data['website_id'])->first();
  2933. if (empty($web)) {
  2934. return Result::error("该网站不存在", 0);
  2935. }
  2936. $hy = JobIndustry::get()->all();
  2937. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2938. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2939. $result = [
  2940. 'hy' => $hy,
  2941. 'zw' => $zw,
  2942. 'jtzw' => $jtzw,
  2943. ];
  2944. if (empty($result)) {
  2945. return Result::error("查询失败", 0);
  2946. }
  2947. return Result::success($result);
  2948. }
  2949. /**
  2950. * c端-获取招工招聘
  2951. * @param array $data
  2952. * @return array
  2953. * */
  2954. public function getWebsiteJob(array $data): array
  2955. {
  2956. $web = Website::where('id', $data['website_id'])->first();
  2957. if (empty($web)) {
  2958. return Result::error("该网站不存在", 0);
  2959. }
  2960. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2961. ->where('job_hunting.website_id', $data['website_id'])
  2962. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2963. $query->where(function ($q) use ($data) {
  2964. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2965. });
  2966. })
  2967. ->select(
  2968. 'job_hunting.id',
  2969. 'job_hunting.cat_arr_id',
  2970. 'job_hunting.job_name_get',
  2971. 'job_hunting.industry',
  2972. 'job_hunting.name',
  2973. 'job_hunting.sexy',
  2974. 'job_hunting.origin',
  2975. 'job_hunting.city_arr_id',
  2976. 'job_hunting.experience',
  2977. 'job_hunting.updated_at',
  2978. 'job_hunting.salary'
  2979. )
  2980. ->orderBy('updated_at', 'desc')
  2981. ->limit($data['job1_num'])
  2982. ->get();
  2983. $web['website_id'] = $data['website_id'];
  2984. if (empty($job_hunting)) {
  2985. $job_huntings = "未查询到相关简历信息";
  2986. } else {
  2987. $job_huntings = $this->processJob($job_hunting, $web);
  2988. }
  2989. // 0:待审核 1:已通过 2:已拒绝
  2990. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2991. ->where('job_recruiting.website_id', $data['website_id'])
  2992. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2993. $query->where(function ($q) use ($data) {
  2994. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2995. });
  2996. })
  2997. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2998. ->select(
  2999. 'job_recruiting.id',
  3000. 'job_recruiting.cat_arr_id',
  3001. 'job_recruiting.title',
  3002. 'job_recruiting.jtzw_id',
  3003. 'job_recruiting.hy_id',
  3004. 'job_recruiting.city_arr_id',
  3005. 'job_recruiting.due_data',
  3006. 'job_recruiting.updated_at',
  3007. 'job_recruiting.experience',
  3008. 'job_recruiting.educational',
  3009. 'job_recruiting.salary',
  3010. 'job_recruiting.zw_id',
  3011. 'job_company.business_name'
  3012. )
  3013. ->orderBy('updated_at', 'desc')
  3014. ->limit($data['job2_num'])
  3015. ->get();
  3016. if (empty($job_recruiting->toArray())) {
  3017. $job_recruitings = "未查询到相关职位信息";
  3018. } else {
  3019. $job_recruitings = $this->processJob($job_recruiting, $web);
  3020. }
  3021. $result = [
  3022. 'job_hunting' => $job_huntings,
  3023. 'job_recuiting' => $job_recruitings,
  3024. ];
  3025. return Result::success($result);
  3026. }
  3027. /**
  3028. * c端-获取招工招聘列表
  3029. * @param array $data
  3030. * @return array
  3031. * */
  3032. public function getWebsiteJobList(array $data): array
  3033. {
  3034. $recruit_where = [];
  3035. $hunt_where = [];
  3036. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3037. if (empty($web)) {
  3038. return Result::error("此网站不存在", 0);
  3039. }
  3040. $website_id['website_id'] = $data['website_id'];
  3041. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3042. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3043. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3044. }
  3045. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3046. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3047. }
  3048. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3049. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3050. }
  3051. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3052. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3053. }
  3054. $query = JobRecruiting::where('job_recruiting.status', 1)
  3055. ->where('job_recruiting.website_id', $data['website_id'])
  3056. ->where($recruit_where)
  3057. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3058. $query->where(function ($q) use ($data) {
  3059. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3060. });
  3061. })
  3062. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3063. $query->where(function ($q) use ($data) {
  3064. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3065. });
  3066. })
  3067. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3068. ->select(
  3069. 'job_recruiting.id',
  3070. 'job_recruiting.hy_id',
  3071. 'job_recruiting.title',
  3072. 'job_recruiting.zw_id',
  3073. 'job_recruiting.educational',
  3074. 'job_recruiting.jtzw_id',
  3075. 'job_recruiting.city_arr_id',
  3076. 'job_recruiting.due_data',
  3077. 'job_recruiting.experience',
  3078. 'job_recruiting.cat_arr_id',
  3079. 'job_recruiting.updated_at',
  3080. 'job_company.business_name'
  3081. )
  3082. ->orderBy('job_recruiting.updated_at', 'desc');
  3083. $recruit_count = $query->count();
  3084. $query = clone $query;
  3085. $JobRecruiting = $query
  3086. ->offset(($data['page'] - 1) * $data['pageSize'])
  3087. ->limit($data['pageSize'])
  3088. ->get();
  3089. if (empty($JobRecruiting)) {
  3090. $JobRecruiting = "暂无相关职位信息";
  3091. } else {
  3092. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3093. }
  3094. }
  3095. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3096. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3097. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3098. }
  3099. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3100. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3101. }
  3102. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3103. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3104. }
  3105. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3106. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3107. }
  3108. $query = JobHunting::where('job_hunting.status', 2)
  3109. ->where('job_hunting.website_id', $data['website_id'])
  3110. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3111. ->where($hunt_where)
  3112. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3113. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3114. // })
  3115. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3116. $query->where(function ($q) use ($data) {
  3117. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3118. });
  3119. })
  3120. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3121. $query->where(function ($q) use ($data) {
  3122. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3123. });
  3124. })
  3125. ->select(
  3126. 'job_hunting.id',
  3127. 'job_hunting.sexy',
  3128. 'job_hunting.experience',
  3129. 'job_hunting.origin',
  3130. 'job_hunting.industry',
  3131. 'job_hunting.name',
  3132. 'job_hunting.job',
  3133. 'job_hunting.job_name_get',
  3134. 'job_hunting.city_arr_id',
  3135. 'job_hunting.cat_arr_id',
  3136. 'job_hunting.created_at',
  3137. 'job_hunting.updated_at',
  3138. 'job_position.zwname as job_name'
  3139. )
  3140. ->orderBy('job_hunting.updated_at', 'desc');
  3141. $hunt_count = $query->count();
  3142. $query = clone $query;
  3143. $JobHunting = $query
  3144. ->offset(($data['page'] - 1) * $data['pageSize'])
  3145. ->limit($data['pageSize'])
  3146. ->get();
  3147. if (empty($JobHunting)) {
  3148. $JobRecruiting = "暂无相关简历信息";
  3149. } else {
  3150. $JobHunting = $this->processJob($JobHunting, $website_id);
  3151. }
  3152. }
  3153. $result = [
  3154. 'JobRecruiting' => $JobRecruiting ?? [],
  3155. 'recruit_count' => $recruit_count ?? 0,
  3156. 'JobHunting' => $JobHunting ?? [],
  3157. 'hunt_count' => $hunt_count ?? 0,
  3158. ];
  3159. return Result::success($result);
  3160. }
  3161. /**
  3162. * c端-获取招工招聘详情
  3163. * @param array $data
  3164. * @return array
  3165. * */
  3166. public function getWebsiteJobInfo(array $data): array
  3167. {
  3168. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3169. if (empty($web)) {
  3170. return Result::error("该网站不存在", 0);
  3171. }
  3172. $webid = [
  3173. 'website_id' => $data['website_id'],
  3174. ];
  3175. // 职位相关信息
  3176. if ($data['type'] == 1) {
  3177. $query = JobRecruiting::where('status', 1)
  3178. ->where('website_id', $data['website_id'])
  3179. ->select('*');
  3180. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3181. $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();
  3182. if (!empty($company)) {
  3183. $result['company'] = $this->processJob($company, $webid);
  3184. }
  3185. $other_job = JobRecruiting::where('status', 1)
  3186. ->where('website_id', $data['website_id'])
  3187. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3188. ->where('id', '!=', $data['id'])
  3189. ->where('user_id', '=', $job[0]['user_id'])
  3190. ->limit($data['pageSize'])
  3191. ->get();
  3192. if (!empty($other_job)) {
  3193. $result['other_job'] = $this->processJob($other_job, $webid);
  3194. }
  3195. } else {
  3196. // 简历相关信息
  3197. $job = JobHunting::where('job_hunting.status', 2)
  3198. ->where('job_hunting.website_id', $data['website_id'])
  3199. ->where('job_hunting.id', $data['id'])
  3200. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3201. ->select('job_hunting.*', 'user_name')
  3202. ->get();
  3203. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3204. if (!empty($resume->toArray())) {
  3205. $result['resume'] = 1;
  3206. } else {
  3207. $result['resume'] = 0;
  3208. }
  3209. }
  3210. if (empty($job->toArray())) {
  3211. return Result::error("id参数错误", 0);
  3212. }
  3213. if (!empty($job[0]['job_experience'])) {
  3214. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3215. if (!empty($job_experience)) {
  3216. // $hy = [];
  3217. foreach ($job_experience as $key => $value) {
  3218. // $id = $value['id'];
  3219. $hy[$key] = $value['job_industry'];
  3220. $zw_id[$key] = $value['job_typename'];
  3221. $jtzw_id[$key] = $value['job_name'];
  3222. }
  3223. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3224. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3225. // 先将关联表转换为索引数组,提高查找效率
  3226. $hyLookup = [];
  3227. foreach ($hy_table as $item) {
  3228. $hyLookup[$item['hyid']] = $item['hyname'];
  3229. }
  3230. $zwLookup = [];
  3231. foreach ($zw_table as $item) {
  3232. $zwLookup[$item['zwid']] = $item['zwname'];
  3233. }
  3234. foreach ($job_experience as $key => &$value) {
  3235. // 处理行业名称
  3236. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3237. $value['hy_name'] = $hyLookup[$hy[$key]];
  3238. }
  3239. // 处理职位名称
  3240. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3241. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3242. }
  3243. // 处理具体职位名称
  3244. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3245. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3246. }
  3247. }
  3248. // 释放引用,防止意外修改后续代码
  3249. unset($value);
  3250. }
  3251. $result['job_experience'] = $job_experience ?? [];
  3252. }
  3253. if (!empty($job[0]['education_experience'])) {
  3254. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3255. if (!empty($education_experience)) {
  3256. foreach ($education_experience as $key => $value) {
  3257. // $id = $value['id'];
  3258. $education[$key] = $value['school_education'];
  3259. }
  3260. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3261. // // 先将关联表转换为索引数组,提高查找效率
  3262. $educationLookup = [];
  3263. foreach ($education_table as $item) {
  3264. $educationLookup[$item['evalue']] = $item['ename'];
  3265. }
  3266. foreach ($education_experience as $key => &$value) {
  3267. // 处理学历名称
  3268. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3269. $value['education_name'] = $educationLookup[$education[$key]];
  3270. }
  3271. }
  3272. }
  3273. $result['education_experience'] = $job_experience ?? [];
  3274. }
  3275. $result['job'] = $this->processJob($job, $webid);
  3276. // // 返现对应的栏目
  3277. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3278. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3279. ->whereIn('category_id', $catid)
  3280. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3281. ->orderBy('pid')->get()->all();
  3282. if (!empty($category)) {
  3283. $result['category'] = $category;
  3284. }
  3285. $result['job'] = $job;
  3286. $result['job_experience'] = $job_experience ?? [];
  3287. $result['education_experience'] = $education_experience ?? [];
  3288. if (empty($result)) {
  3289. return Result::error("参数错误", 0);
  3290. }
  3291. return Result::success($result);
  3292. }
  3293. /**
  3294. * c端-申请职位
  3295. * @param array $data
  3296. * @return array
  3297. * */
  3298. public function getWebsiteJobApply(array $data): array
  3299. {
  3300. // 首先验证网站是否存在
  3301. // return Result::success($data);
  3302. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3303. if (empty($web)) {
  3304. return Result::error("该网站不存在", 0);
  3305. }
  3306. // 验证用户是否存在且为个人会员/管理员
  3307. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3308. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3309. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3310. return Result::error("用户不存在", 0);
  3311. }
  3312. // 去除重复元素和空元素,并保持原始顺序
  3313. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3314. return !empty($value);
  3315. }));
  3316. // 验证职位是否存在 1:审核通过
  3317. $recruiting = JobRecruiting::where('status', 1)
  3318. ->where('website_id', $data['website_id'])
  3319. ->whereIn('id', $data['recruit_id'])
  3320. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3321. if (empty($recruiting)) {
  3322. return Result::error("该职位不存在", 0);
  3323. }
  3324. // 简历是否存在
  3325. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3326. if (empty($hunt_id)) {
  3327. return Result::error("该简历不存在", 0);
  3328. }
  3329. $data['hunt_id'] = $hunt_id['hunt_id'];
  3330. // // 验证是否已投递过该职位
  3331. $apply = JobApply::where('user_id', $data['user_id'])
  3332. ->where('hunt_id', $data['hunt_id'])
  3333. ->where('website_id', $data['website_id'])
  3334. ->whereIn('recruit_id', $data['recruit_id'])
  3335. ->get(['recruit_id']);
  3336. if (!empty($apply->toArray())) {
  3337. return Result::error("您已投递过该职位!");
  3338. }
  3339. $insertData = array_map(function ($recruiting) use ($data) {
  3340. return [
  3341. 'user_id' => $data['user_id'],
  3342. 'hunt_id' => $data['hunt_id'],
  3343. 'website_id' => $data['website_id'],
  3344. 'recruit_id' => $recruiting['recruit_id'],
  3345. 'receiver_id' => $recruiting['receiver_id'],
  3346. 'status' => 1,
  3347. ];
  3348. }, $recruiting);
  3349. // 批量插入数据
  3350. $result = JobApply::insert($insertData);
  3351. if (empty($result)) {
  3352. return Result::error("投递失败", 0);
  3353. }
  3354. return Result::success($result);
  3355. }
  3356. /**
  3357. * 招工招聘-沟通简历
  3358. * @param array $data
  3359. * @return array
  3360. * */
  3361. public function getWebsiteJobResume(array $data): array
  3362. {
  3363. // 首先验证网站是否存在
  3364. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3365. if (empty($web)) {
  3366. return Result::error("该网站不存在", 0);
  3367. }
  3368. // return Result::success($data);
  3369. // 验证用户是否存在且为企业会员/管理员
  3370. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3371. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3372. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3373. return Result::error("用户不存在", 0);
  3374. }
  3375. // 去除重复元素和空元素,并保持原始顺序
  3376. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3377. return !empty($value);
  3378. }));
  3379. // 验证简历是否存在
  3380. $hunting = JobHunting::where('status', 2)
  3381. ->where('website_id', $data['website_id'])
  3382. ->whereIn('id', $data['hunt_id'])
  3383. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3384. if (empty($hunting)) {
  3385. return Result::error("该简历不存在", 0);
  3386. }
  3387. // 验证是否已沟通过该简历
  3388. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3389. ->where('recruit_id', $data['recruit_id'])
  3390. ->where('website_id', $data['website_id'])
  3391. ->whereIn('hunt_id', $data['hunt_id'])
  3392. ->get(['hunt_id']);
  3393. if (!empty($remuse->toArray())) {
  3394. return Result::error("您已沟通过该简历!");
  3395. }
  3396. // 准备要插入的数据数组
  3397. $insertData = array_map(function ($hunting) use ($data) {
  3398. return [
  3399. 'user_id' => $data['user_id'],
  3400. 'recruit_id' => $data['recruit_id'],
  3401. 'website_id' => $data['website_id'],
  3402. 'hunt_id' => $hunting['hunt_id'],
  3403. 'receiver_id' => $hunting['receiver_id'],
  3404. 'status' => 1,
  3405. ];
  3406. }, $hunting);
  3407. // 批量插入数据
  3408. $result = JobRemuse::insert($insertData);
  3409. if (empty($result)) {
  3410. return Result::error("沟通失败", 0);
  3411. }
  3412. return Result::success($result);
  3413. }
  3414. /**
  3415. * 招工招聘 -我的职位(企业会员)
  3416. * @param array $data
  3417. * @return array
  3418. */
  3419. public function getWebsiteJobRecruiting(array $data): array
  3420. {
  3421. $web = Website::where('id', $data['website_id'])->first('id');
  3422. if (empty($web)) {
  3423. return Result::error("该网站不存在", 0);
  3424. }
  3425. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3426. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3427. return Result::error("用户暂无权限!", 0);
  3428. }
  3429. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3430. $result = JobRecruiting::where('website_id', $data['website_id'])
  3431. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3432. $query->where('user_id', $user['id']);
  3433. })
  3434. ->where('status', 1)
  3435. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3436. ->orderBy('updated_at', 'desc')
  3437. ->limit($data['pageSize'])
  3438. ->get();
  3439. if (empty($result)) {
  3440. return Result::error("暂无相关职位信息", 0);
  3441. }
  3442. return Result::success($result);
  3443. }
  3444. /**
  3445. * c端 - 验证路由
  3446. * @param array $data
  3447. * @return array
  3448. */
  3449. /**
  3450. * c端 - 验证路由
  3451. * @param array $data
  3452. * @return array
  3453. */
  3454. public function checkWebsiteRoute(array $data): array
  3455. {
  3456. // 测试001111111222
  3457. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3458. if (empty($web)) {
  3459. return Result::error("该网站不存在", 0);
  3460. } elseif ($web['status'] != 1) {
  3461. return Result::error("网站已经关闭", 0);
  3462. }
  3463. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3464. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3465. // 验证路由是否存在
  3466. if (empty($whiteRouterInfo)) {
  3467. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3468. }
  3469. if (!empty($whiteRouterInfo)) {
  3470. return Result::success($whiteRouterInfo->toArray());
  3471. }
  3472. }
  3473. // 验证栏目路由
  3474. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3475. ->where('aLIas_pinyin', $data['last_route'])
  3476. ->get()->all();
  3477. if (count($last_category) == 0) {
  3478. return Result::error("该栏目不存在", 0);
  3479. }
  3480. if (count($last_category) > 1) {
  3481. return Result::error("该子级栏目存在多个,路由验证失败!", 0);
  3482. }
  3483. if (count($last_category) == 1) {
  3484. $last_category = $last_category[0];
  3485. }
  3486. // return Result::success($last_category);
  3487. if (isset($data['id']) && !empty($data['id'])) {
  3488. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3489. switch ($last_category['type']) {
  3490. case 1:
  3491. // 文章
  3492. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3493. $article = Article::where('status', 1)
  3494. ->where('id', $data['id'])
  3495. ->where(function ($query) use ($data) {
  3496. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3497. ->orWhereNull("ignore_ids");
  3498. })
  3499. ->first(['cat_arr_id']);
  3500. if (empty($article)) {
  3501. return Result::error("该文章不存在", 0);
  3502. }
  3503. // return Result::success($article);
  3504. break;
  3505. case 2:
  3506. // 商品
  3507. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3508. $article = Good::where('website_id', $data['website_id'])
  3509. ->where('status', 2)
  3510. ->where('id', $data['id'])
  3511. ->first(['cat_arr_id']);
  3512. if (empty($article)) {
  3513. return Result::error("该商品不存在", 0);
  3514. }
  3515. break;
  3516. case 3:
  3517. // 书刊信息
  3518. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3519. $article = Book::where('website_id', $data['website_id'])
  3520. ->where('status', 2)
  3521. ->where('id', $data['id'])
  3522. ->first(['id', 'cat_arr_id']);
  3523. if (empty($article)) {
  3524. return Result::error("该书刊不存在", 0);
  3525. }
  3526. break;
  3527. case 4:
  3528. // 招聘
  3529. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3530. $article = JobRecruiting::where('website_id', $data['website_id'])
  3531. ->where('status', 1)
  3532. ->where('id', $data['id'])
  3533. ->first(['cat_arr_id']);
  3534. if (empty($article)) {
  3535. return Result::error("该招聘不存在", 0);
  3536. }
  3537. break;
  3538. case 5:
  3539. // 求职
  3540. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3541. $article = JobHunting::where('website_id', $data['website_id'])
  3542. ->where('status', 2)
  3543. ->where('id', $data['id'])
  3544. ->first(['cat_arr_id']);
  3545. if (empty($article)) {
  3546. return Result::error("该求职不存在", 0);
  3547. }
  3548. break;
  3549. case 6:
  3550. // 企业
  3551. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3552. $article = Company::
  3553. // where('website_id', $data['website_id'])
  3554. // ->
  3555. where('status', 1)
  3556. ->where('id', $data['id'])
  3557. ->first(['cat_arr_id']);
  3558. if (empty($article)) {
  3559. return Result::error("该企业不存在", 0);
  3560. }
  3561. break;
  3562. case 7:
  3563. // 项目
  3564. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3565. $article = Project::where('website_id', $data['website_id'])
  3566. ->where('status', 1)
  3567. ->where('id', $data['id'])
  3568. ->first(['cat_arr_id']);
  3569. if (empty($article)) {
  3570. return Result::error("该项目不存在", 0);
  3571. }
  3572. break;
  3573. default:
  3574. return Result::error("该数据不存在", 0);
  3575. break;
  3576. }
  3577. $catid = 0;
  3578. $catidArray = json_decode($article['cat_arr_id'], true);
  3579. $catid = !empty($catidArray) ? end($catidArray) : null;
  3580. // return Result::success($article['cat_arr_id']);
  3581. if (empty($catid)) {
  3582. return Result::error("该数据不存在", 0);
  3583. }
  3584. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3585. ->where('category_id',$catid)
  3586. ->first('path')
  3587. ->toArray();
  3588. }else{
  3589. // if ($last_category['pid'] != 0) {
  3590. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3591. $catid = !empty($cat_arr) ? end($cat_arr) : null;
  3592. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3593. ->where('category_id',$catid)
  3594. ->where('path',$data['all_route'])
  3595. ->first('path')
  3596. ->toArray();
  3597. // } else {
  3598. // $pinyin[0] = $last_category['aLIas_pinyin'];
  3599. // }
  3600. }
  3601. // return Result::success($pinyin[0]);
  3602. if (empty($pinyin) || count($pinyin)>1 || $pinyin['path'] != $data['all_route']) {
  3603. return Result::error('非法路径!');
  3604. } else {
  3605. return Result::success($pinyin);
  3606. }
  3607. }
  3608. /**
  3609. * 招工招聘 - 获取推荐职位
  3610. * @param array $data
  3611. * @return array
  3612. */
  3613. public function getWebsiteLevelJob(array $data): array
  3614. {
  3615. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3616. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3617. ->where('job_recruiting.status', 1)
  3618. ->where('job_level', $data['job_level'])
  3619. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3620. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3621. ->orderBy('job_recruiting.updated_at', 'desc')
  3622. ->limit($data['pageSize'])
  3623. ->get();
  3624. $web = ['website_id' => $data['website_id']];
  3625. if (!empty($job)) {
  3626. $result = $this->processJob($job, $web);
  3627. }
  3628. if (empty($result)) {
  3629. return Result::error("暂无相关职位信息", 0);
  3630. }
  3631. return Result::success($result);
  3632. }
  3633. /**
  3634. * 验证导航名称是否重复
  3635. * @return void
  3636. */
  3637. //20250226 产品列表
  3638. public function getGoodList(array $data): array
  3639. {
  3640. var_dump($data, '---------1-2--');
  3641. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3642. unset($data['user_type_id']);
  3643. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3644. $where = [];
  3645. if ($type_id != '10000') {
  3646. $where = [
  3647. 'good.user_id' => $user_id,
  3648. ];
  3649. }
  3650. //类型
  3651. if (isset($data['type_id']) && $data['type_id']) {
  3652. $where['good.type_id'] = $data['type_id'];
  3653. }
  3654. //名称
  3655. if (isset($data['name']) && $data['name']) {
  3656. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3657. }
  3658. //status
  3659. if (isset($data['status']) && $data['status'] != '') {
  3660. $where['good.status'] = $data['status'];
  3661. }
  3662. //status1
  3663. // if (isset($data['status1']) && $data['status1'] == 1) {
  3664. // $status1 = 1;
  3665. // }
  3666. $where1 = [];
  3667. //website_id
  3668. // if (isset($data['website_id']) && $data['website_id']) {
  3669. // $where1 = [
  3670. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3671. // ];
  3672. // }
  3673. // website_name
  3674. if (isset($data['website_name']) && $data['website_name']) {
  3675. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3676. }
  3677. // catid
  3678. if (isset($data['category_name']) && $data['category_name']) {
  3679. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3680. }
  3681. // $result = Good::where($where)
  3682. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3683. var_dump($where, '---------1---');
  3684. $result = Good::where($where)
  3685. ->when(!empty($where1), function ($query) use ($where1) {
  3686. return $query->where($where1);
  3687. })
  3688. //status 1待审核2已审核3已拒绝
  3689. ->when(isset($data['status1']), function ($query) {
  3690. return $query->whereIn('good.status', [1, 3]);
  3691. })
  3692. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3693. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3694. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3695. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3696. ->orderBy("updated_at", "desc")
  3697. ->limit($data['page_size'])
  3698. ->offset(($data['page'] - 1) * $data['page_size'])
  3699. ->get();
  3700. $count = Good::where($where)
  3701. ->when(!empty($where1), function ($query) use ($where1) {
  3702. return $query->where($where1);
  3703. })
  3704. //status 1待审核2已审核3已拒绝
  3705. ->when(isset($data['status1']), function ($query) {
  3706. return $query->whereIn('good.status', [1, 3]);
  3707. })
  3708. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3709. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3710. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3711. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3712. ->orderBy("updated_at", "desc")->count();
  3713. $data = [
  3714. 'rows' => $result->toArray(),
  3715. 'count' => $count,
  3716. ];
  3717. if (empty($result)) {
  3718. return Result::error("此栏目暂无相关产品", 0);
  3719. }
  3720. return Result::success($data);
  3721. }
  3722. public function getGoodInfo(array $data): array
  3723. {
  3724. $result = Good::where('id', $data['id'])->first();
  3725. if (empty($result)) {
  3726. return Result::error("此产品不存在", 0);
  3727. }
  3728. return Result::success($result);
  3729. }
  3730. public function addGood(array $data): array
  3731. {
  3732. // unset($data['city_arr_id']);
  3733. // unset($data['cat_arr_id']);
  3734. $data['city_id'] = end($data['city_arr_id']);
  3735. $data['catid'] = end($data['cat_arr_id']);
  3736. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3737. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3738. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3739. unset($data['imgUrl']); //大小写
  3740. if (isset($data['price']) && $data['price'] == '') {
  3741. $data['price'] = 0;
  3742. }
  3743. if ($data['imgurl'] == '') {
  3744. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3745. preg_match_all($reg, $data['detail'], $matches);
  3746. if (isset($matches[1][0])) {
  3747. //截取varchar240
  3748. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3749. }
  3750. }
  3751. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3752. //提取标题+内容中的关键词
  3753. $data['keyword'] = $data['name'];
  3754. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3755. Jieba::init(); // 初始化 jieba-php
  3756. Finalseg::init();
  3757. $segList = Jieba::cut($data['keyword']);
  3758. $segList1 = array_slice($segList, 0, 8);
  3759. $data['keyword'] = implode(',', $segList1);
  3760. }
  3761. if ($data['description'] == '') {
  3762. //提取内容中的描述
  3763. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3764. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3765. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3766. }
  3767. if ($data['status'] == 1) {
  3768. $this->sendMessage([
  3769. 'talk_type' => 200,
  3770. 'title' => $data['name'],
  3771. 'content' => '提交了审核',
  3772. 'messageType' => 3,
  3773. ]);
  3774. }
  3775. $result = Good::insert($data);
  3776. if (empty($result)) {
  3777. return Result::error("添加失败", 0);
  3778. }
  3779. return Result::success($result);
  3780. }
  3781. public function updateGood(array $data): array
  3782. {
  3783. $data['city_id'] = end($data['city_arr_id']);
  3784. $data['catid'] = end($data['cat_arr_id']);
  3785. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3786. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3787. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3788. //设置东八区
  3789. date_default_timezone_set('Asia/Shanghai');
  3790. $data['updated_at'] = date('Y-m-d H:i:s');
  3791. if (isset($data['price']) && $data['price'] == '') {
  3792. $data['price'] = 0;
  3793. }
  3794. if ($data['imgurl'] == '') {
  3795. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3796. preg_match_all($reg, $data['detail'], $matches);
  3797. if (isset($matches[1][0])) {
  3798. //截取varchar240
  3799. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3800. }
  3801. }
  3802. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3803. //提取标题+内容中的关键词
  3804. $data['keyword'] = $data['name'];
  3805. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3806. Jieba::init(); // 初始化 jieba-php
  3807. Finalseg::init();
  3808. $segList = Jieba::cut($data['keyword']);
  3809. $segList1 = array_slice($segList, 0, 8);
  3810. $data['keyword'] = implode(',', $segList1);
  3811. }
  3812. if ($data['description'] == '') {
  3813. //提取内容中的描述
  3814. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3815. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3816. }
  3817. if ($data['status'] == 1) {
  3818. $this->sendMessage([
  3819. 'talk_type' => 200,
  3820. 'title' => $data['name'],
  3821. 'content' => '提交了审核',
  3822. 'messageType' => 3,
  3823. ]);
  3824. }
  3825. $result = Good::where('id', $data['id'])->update($data);
  3826. if (empty($result)) {
  3827. return Result::error("更新失败", 0);
  3828. }
  3829. return Result::success($result);
  3830. }
  3831. public function delGood(array $data): array
  3832. {
  3833. $result = Good::where('id', $data['id'])->delete();
  3834. if (empty($result)) {
  3835. return Result::error("删除失败", 0);
  3836. }
  3837. return Result::success($result);
  3838. }
  3839. //20250226 产品列表
  3840. //20250306 求职信息
  3841. public function getJobHuntingList(array $data): array
  3842. {
  3843. $where = [];
  3844. if (isset($data['username']) && !empty($data['username'])) {
  3845. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3846. }
  3847. //status 1待审核2已审核3已拒绝
  3848. if (isset($data['status']) && $data['status'] != '') {
  3849. $where = [
  3850. 'job_hunting.status' => $data['status'],
  3851. ];
  3852. }
  3853. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3854. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3855. unset($data['type_id']);
  3856. if ($type_id != '10000') {
  3857. $where[] = ['job_hunting.user_id', '=', $user_id];
  3858. }
  3859. $result = JobHunting::where($where)
  3860. ->when(!empty($data['status1']), function ($query) use ($data) {
  3861. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3862. })
  3863. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3864. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3865. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3866. ->orderBy("updated_at", "desc")
  3867. ->limit($data['page_size'])
  3868. ->offset(($data['page'] - 1) * $data['page_size'])
  3869. ->get();
  3870. if (empty($result)) {
  3871. return Result::error("查询失败", 0);
  3872. }
  3873. $count = JobHunting::where($where)
  3874. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3875. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3876. ->count();
  3877. $data = [
  3878. 'rows' => $result->toArray(),
  3879. 'count' => $count,
  3880. ];
  3881. return Result::success($data);
  3882. }
  3883. public function getJobHuntingApply(array $data): array
  3884. {
  3885. var_dump($data, '-----------------test--------1-');
  3886. $where = [];
  3887. if (isset($data['username']) && !empty($data['username'])) {
  3888. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3889. }
  3890. if (isset($data['salary']) && !empty($data['salary'])) {
  3891. $where[] = [
  3892. 'job_hunting.salary',
  3893. '=',
  3894. $data['salary'],
  3895. ];
  3896. }
  3897. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3898. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3899. unset($data['type_id']);
  3900. if ($type_id != '10000') {
  3901. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3902. }
  3903. var_dump($where, '-----------------test---------');
  3904. $result = jobApply::where($where)
  3905. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3906. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3907. // })
  3908. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3909. ->where('job_enum.egroup', '=', 'income')
  3910. ->where('job_hunting.status', 2) //已审核
  3911. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3912. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3913. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3914. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3915. //职位----是申请职位
  3916. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3917. ->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')
  3918. ->orderBy("job_hunting.updated_at", "desc")
  3919. ->limit($data['page_size'])
  3920. ->offset(($data['page'] - 1) * $data['page_size'])
  3921. ->get();
  3922. if (empty($result)) {
  3923. return Result::error("查询失败", 0);
  3924. }
  3925. $count = jobApply::where($where)
  3926. ->where('job_enum.egroup', '=', 'income')
  3927. ->where('job_hunting.status', 2) //已审核
  3928. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3929. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3930. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3931. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3932. //职位----是申请职位
  3933. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3934. ->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')
  3935. ->count();
  3936. $data = [
  3937. 'rows' => $result->toArray(),
  3938. 'count' => $count,
  3939. ];
  3940. return Result::success($data);
  3941. }
  3942. public function addJobHunting(array $data): array
  3943. {
  3944. date_default_timezone_set('Asia/Shanghai');
  3945. unset($data['company_name']);
  3946. unset($data['job_industry']);
  3947. unset($data['job_name']);
  3948. unset($data['department']);
  3949. unset($data['job_timeList']);
  3950. unset($data['job_content']);
  3951. unset($data['job_typename']); //不知道这是啥,
  3952. $data['created_at'] = date('Y-m-d H:i:s');
  3953. $data['updated_at'] = date('Y-m-d H:i:s');
  3954. //根据用户 user_id 只能添加一次
  3955. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3956. if (!empty($result)) {
  3957. return Result::error("您已添加过求职信息", 0);
  3958. }
  3959. var_dump($result, '-----------------test---------');
  3960. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3961. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3962. $cityArr = json_decode($data['city_arr_id'], true);
  3963. $data['city_id'] = end($cityArr);
  3964. } else {
  3965. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3966. $data['city_id'] = end($data['city_arr_id']);
  3967. }
  3968. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3969. $this->sendMessage([
  3970. 'talk_type' => 600,
  3971. 'title' => $data['name'],
  3972. 'content' => '提交了审核',
  3973. 'messageType' => 11,
  3974. ]);
  3975. }
  3976. $result = JobHunting::create($data);
  3977. if (empty($result)) {
  3978. return Result::error("添加失败", 0);
  3979. }
  3980. return Result::success($result);
  3981. }
  3982. public function delJobHunting(array $data): array
  3983. {
  3984. $result = JobHunting::where('id', $data['id'])->delete();
  3985. if (empty($result)) {
  3986. return Result::error("删除失败", 0);
  3987. }
  3988. return Result::success($result);
  3989. }
  3990. public function updateJobHunting(array $data): array
  3991. {
  3992. //设置东八区
  3993. date_default_timezone_set('Asia/Shanghai');
  3994. unset($data['company_name']);
  3995. unset($data['job_industry']);
  3996. unset($data['job_name']);
  3997. unset($data['department']);
  3998. unset($data['job_timeList']);
  3999. unset($data['job_content']);
  4000. unset($data['job_typename']); //不知道这是啥,
  4001. $data['created_at'] = date('Y-m-d H:i:s');
  4002. $data['updated_at'] = date('Y-m-d H:i:s');
  4003. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4004. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4005. $cityArr = json_decode($data['city_arr_id'], true);
  4006. $data['city_id'] = end($cityArr);
  4007. } else {
  4008. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4009. $data['city_id'] = end($data['city_arr_id']);
  4010. }
  4011. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4012. $this->sendMessage([
  4013. 'talk_type' => 600,
  4014. 'title' => $data['name'],
  4015. 'content' => '提交了审核',
  4016. 'messageType' => 11,
  4017. ]);
  4018. }
  4019. $result = JobHunting::where('id', $data['id'])->update($data);
  4020. if (empty($result)) {
  4021. return Result::error("更新失败", 0);
  4022. }
  4023. return Result::success($result);
  4024. }
  4025. public function getJobHuntingInfo(array $data): array
  4026. {
  4027. $result = JobHunting::where('id', $data['id'])->first();
  4028. if (empty($result)) {
  4029. return Result::error("查询失败", 0);
  4030. }
  4031. return Result::success($result);
  4032. }
  4033. public function getJobHuntingData(array $data): array
  4034. {
  4035. $jobEnum = JobEnum::get();
  4036. $jobIndustry = JobIndustry::get();
  4037. $jobNature = JobNature::get();
  4038. $jobPosition = JobPosition::get();
  4039. $data = [
  4040. 'jobEnum' => $jobEnum,
  4041. 'jobIndustry' => $jobIndustry,
  4042. 'jobNature' => $jobNature,
  4043. 'jobPosition' => $jobPosition,
  4044. ];
  4045. return Result::success($data);
  4046. }
  4047. public function delJobHuntingInfo(array $data): array
  4048. {
  4049. $result = JobHunting::where('id', $data['id'])->delete();
  4050. return Result::success();
  4051. }
  4052. //20250324 通知,公告,消息
  4053. public function delNotice(array $data): array
  4054. {
  4055. $result = Notice::where('id', $data['id'])->delete();
  4056. if ($result) {
  4057. return Result::success();
  4058. } else {
  4059. return Result::error("删除失败", 0);
  4060. }
  4061. }
  4062. public function getNoticeInfo(array $data): array
  4063. {
  4064. $result = Notice::where('id', $data['id'])->first();
  4065. // var_dump($result['re_user_ids'], '--------------------');
  4066. if (empty($result)) {
  4067. return Result::error("查询失败", 0);
  4068. }
  4069. return Result::success($result);
  4070. }
  4071. public function readNotice(array $data): array
  4072. {
  4073. $result = Notice::where('id', $data['id'])->first();
  4074. // var_dump($result['re_user_ids'], '--------------------');
  4075. if (empty($result)) {
  4076. return Result::error("查询失败", 0);
  4077. }
  4078. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4079. $re_user_ids = json_decode($result['re_user_ids'], true);
  4080. var_dump($re_user_ids, '--------------1---test---------');
  4081. var_dump($data, '--------------1---test---------');
  4082. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4083. //如果已经存在,就不再添加
  4084. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4085. $read_id = json_decode($result['read_id'], true);
  4086. if (!is_array($read_id)) {
  4087. $read_id = [];
  4088. }
  4089. if (!in_array($data['user_id'], $read_id)) {
  4090. $read_id[] = $data['user_id'];
  4091. $result['read_id'] = json_encode($read_id);
  4092. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4093. }
  4094. } else {
  4095. //如果不存在,就添加
  4096. $result['read_id'] = json_encode([$data['user_id']]);
  4097. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4098. }
  4099. }
  4100. return Result::success($result);
  4101. }
  4102. public function addNotice(array $data): array
  4103. {
  4104. date_default_timezone_set('Asia/Shanghai');
  4105. $data['created_at'] = date('Y-m-d H:i:s');
  4106. $data['updated_at'] = date('Y-m-d H:i:s');
  4107. $user_id = UserInfo::
  4108. //city_id不是null
  4109. whereNotNull('city_id')
  4110. ->whereNotNull('department_id')
  4111. ->where(function ($query) use ($data) {
  4112. $query->where(function ($subQuery) use ($data) {
  4113. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4114. });
  4115. })
  4116. ->where(function ($query) use ($data) {
  4117. $query->where(function ($subQuery) use ($data) {
  4118. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4119. });
  4120. })
  4121. ->pluck('user_id')->toArray();
  4122. $user_id = array_unique($user_id);
  4123. $chat_ids = $user_id;
  4124. $user_id = json_encode($user_id);
  4125. $data['re_user_ids'] = $user_id;
  4126. $this->sendMessage([
  4127. 'talk_type' => 700,
  4128. 'title' => $data['title'],
  4129. 'content' => '提交了审核',
  4130. 'messageType' => 5,
  4131. ]);
  4132. $result = Notice::insertGetId($data);
  4133. if (empty($result)) {
  4134. return Result::error("添加失败", 0);
  4135. }
  4136. return Result::success($result);
  4137. }
  4138. public function updateNotice(array $data): array
  4139. {
  4140. date_default_timezone_set('Asia/Shanghai');
  4141. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4142. $user_id = UserInfo::
  4143. //city_id不是null
  4144. whereNotNull('city_id')
  4145. ->whereNotNull('department_id')
  4146. ->where(function ($query) use ($data) {
  4147. $query->where(function ($subQuery) use ($data) {
  4148. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4149. });
  4150. })
  4151. ->where(function ($query) use ($data) {
  4152. $query->where(function ($subQuery) use ($data) {
  4153. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4154. });
  4155. })
  4156. ->pluck('user_id')->toArray();
  4157. $user_id = array_unique($user_id);
  4158. $user_id = json_encode($user_id);
  4159. $data['re_user_ids'] = $user_id;
  4160. $data['updated_at'] = date('Y-m-d H:i:s');
  4161. $this->sendMessage([
  4162. 'talk_type' => 700,
  4163. 'title' => $data['title'],
  4164. 'content' => '提交了审核',
  4165. 'messageType' => 5,
  4166. ]);
  4167. $result = Notice::where('id', $data['id'])->update($data);
  4168. return Result::success($result);
  4169. }
  4170. public function getNoticeList(array $data): array
  4171. {
  4172. $where = [];
  4173. //title
  4174. if (isset($data['title']) && !empty($data['title'])) {
  4175. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4176. }
  4177. //level
  4178. if (isset($data['level']) && !empty($data['level'])) {
  4179. $where[] = ['notice.level', '=', $data['level']];
  4180. }
  4181. //status
  4182. if (isset($data['status']) && !empty($data['status'])) {
  4183. $where[] = ['notice.status', '=', $data['status']];
  4184. }
  4185. //type
  4186. if (isset($data['type']) && !empty($data['type'])) {
  4187. $where[] = ['notice.type', '=', $data['type']];
  4188. }
  4189. var_dump($data, '------------11111-2----test---------');
  4190. if ($data['type_id'] == 10000) {
  4191. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4192. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4193. })
  4194. ->where($where)
  4195. ->orderBy('updated_at', 'desc')
  4196. ->limit($data['page_size'])
  4197. ->offset(($data['page'] - 1) * $data['page_size'])
  4198. ->get();
  4199. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4200. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4201. })
  4202. ->where($where)
  4203. ->orderBy('updated_at', 'desc')
  4204. ->count();
  4205. } else {
  4206. $result = Notice::where($where)
  4207. // ->where('user_id', $data['user_id'])
  4208. ->Where(function ($query) use ($data) {
  4209. $query->Where(function ($q) use ($data) {
  4210. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4211. ->orWhere('notice.user_id', $data['user_id']);
  4212. });
  4213. })
  4214. ->when(!empty($data['status1']), function ($query) use ($data) {
  4215. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4216. })
  4217. ->orderBy('updated_at', 'desc')
  4218. ->limit($data['page_size'])
  4219. ->offset(($data['page'] - 1) * $data['page_size'])
  4220. ->get();
  4221. $total = Notice::where($where)
  4222. ->when(!empty($data['status1']), function ($query) use ($data) {
  4223. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4224. })
  4225. // ->where('user_id', $data['user_id'])
  4226. ->Where(function ($query) use ($data) {
  4227. $query->Where(function ($q) use ($data) {
  4228. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4229. ->orWhere('notice.user_id', $data['user_id']);
  4230. });
  4231. })
  4232. ->count();
  4233. }
  4234. if (empty($result)) {
  4235. return Result::error("查询失败", 0);
  4236. }
  4237. $data = [
  4238. 'rows' => $result,
  4239. 'count' => $total,
  4240. ];
  4241. return Result::success($data);
  4242. }
  4243. public function noticeList(array $data): array
  4244. {
  4245. $where = [];
  4246. //title
  4247. if (isset($data['title']) && !empty($data['title'])) {
  4248. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4249. }
  4250. //level
  4251. if (isset($data['level']) && !empty($data['level'])) {
  4252. $where[] = ['notice.level', '=', $data['level']];
  4253. }
  4254. //status
  4255. if (isset($data['status']) && !empty($data['status'])) {
  4256. $where[] = ['notice.status', '=', $data['status']];
  4257. }
  4258. //type
  4259. if (isset($data['type']) && !empty($data['type'])) {
  4260. $where[] = ['notice.type', '=', $data['type']];
  4261. }
  4262. var_dump($data, '------------11111-2----test---------');
  4263. if ($data['type_id'] == 10000) {
  4264. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4265. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4266. })
  4267. ->where($where)
  4268. ->orderBy('updated_at', 'desc')
  4269. ->limit($data['page_size'])
  4270. ->offset(($data['page'] - 1) * $data['page_size'])
  4271. ->get();
  4272. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4273. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4274. })
  4275. ->where($where)
  4276. ->orderBy('updated_at', 'desc')
  4277. ->count();
  4278. } else {
  4279. $result = Notice::where($where)
  4280. // ->where('user_id', $data['user_id'])
  4281. ->Where(function ($query) use ($data) {
  4282. $query->Where(function ($q) use ($data) {
  4283. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4284. ->orWhere('notice.user_id', $data['user_id']);
  4285. });
  4286. })
  4287. ->when(!empty($data['status1']), function ($query) use ($data) {
  4288. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4289. })
  4290. ->orderBy('updated_at', 'desc')
  4291. ->limit($data['page_size'])
  4292. ->offset(($data['page'] - 1) * $data['page_size'])
  4293. ->get();
  4294. $total = Notice::where($where)
  4295. ->when(!empty($data['status1']), function ($query) use ($data) {
  4296. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4297. })
  4298. // ->where('user_id', $data['user_id'])
  4299. ->Where(function ($query) use ($data) {
  4300. $query->Where(function ($q) use ($data) {
  4301. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4302. ->orWhere('notice.user_id', $data['user_id']);
  4303. });
  4304. })
  4305. ->count();
  4306. }
  4307. if (empty($result)) {
  4308. return Result::error("查询失败", 0);
  4309. }
  4310. $data = [
  4311. 'rows' => $result,
  4312. 'count' => $total,
  4313. ];
  4314. return Result::success($data);
  4315. }
  4316. public function getNoticeDetail(array $data): array
  4317. {
  4318. $result = Notice::where('id', $data['id'])->first();
  4319. if (empty($result)) {
  4320. return Result::error("查询失败", 0);
  4321. }
  4322. return Result::success($result);
  4323. }
  4324. public function deleteNotice(array $data): array
  4325. {
  4326. $notice = Notice::where('id', $data['id'])->first();
  4327. if (empty($notice)) {
  4328. return Result::error("删除失败", 0);
  4329. }
  4330. $chat_group_id = $notice->group_id;
  4331. if ($chat_group_id) {
  4332. //删除群聊
  4333. ChatGroups::where('id', $chat_group_id)->delete();
  4334. //删除群成员
  4335. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4336. //删除群聊记录
  4337. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4338. }
  4339. $result = Notice::where('id', $data['id'])->delete();
  4340. return Result::success($result);
  4341. }
  4342. public function complaintList(array $data): array
  4343. {
  4344. var_dump($data, '---------1---------');
  4345. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4346. unset($data['type_id']);
  4347. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4348. $where = [];
  4349. if ($type_id != 10000 && empty($data['deal_user'])) {
  4350. // $where['complaint.user_id'] = $user_id;
  4351. }
  4352. if (!empty($data['title'])) {
  4353. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4354. }
  4355. if (!empty($data['department_id'])) {
  4356. $where['complaint.department_id'] = $data['department_id'];
  4357. }
  4358. if (!empty($data['deal'])) {
  4359. $where['complaint.deal'] = $data['deal'];
  4360. }
  4361. if (!empty($data['status'])) {
  4362. $where['complaint.status'] = $data['status'];
  4363. }
  4364. var_dump(!empty($data['deal_user']), '----------1');
  4365. var_dump($where, '----------2');
  4366. $result = Complaint::where($where)
  4367. ->when(!empty($data['status1']), function ($query) use ($data) {
  4368. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4369. })
  4370. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4371. //json re_user_ids data[user_id]是不是在里面
  4372. $query->Where(function ($q) use ($data) {
  4373. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4374. ->where('complaint.status', 2);
  4375. });
  4376. })
  4377. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4378. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4379. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4380. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4381. ->orderBy('updated_at', 'desc')
  4382. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4383. //sql输出
  4384. if (empty($result)) {
  4385. return Result::error("暂无投诉信息", 0);
  4386. }
  4387. // 取出数据
  4388. $rows = $result->items();
  4389. $count = $result->total();
  4390. $responseData = [
  4391. 'rows' => $rows,
  4392. 'count' => $count,
  4393. ];
  4394. return Result::success($responseData);
  4395. }
  4396. public function getComplaintList(array $data): array
  4397. {
  4398. var_dump($data, '00000001000000000000');
  4399. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4400. unset($data['type_id']);
  4401. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4402. $where = [];
  4403. if ($type_id != 10000 && empty($data['deal_user'])) {
  4404. $where['complaint.user_id'] = $user_id;
  4405. }
  4406. if (!empty($data['title'])) {
  4407. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4408. }
  4409. if (!empty($data['department_id'])) {
  4410. $where['complaint.department_id'] = $data['department_id'];
  4411. }
  4412. if (!empty($data['deal'])) {
  4413. $where['complaint.deal'] = $data['deal'];
  4414. }
  4415. if (!empty($data['status'])) {
  4416. $where['complaint.status'] = $data['status'];
  4417. }
  4418. var_dump(!empty($data['deal_user']), '----------1');
  4419. var_dump($where, '----------2');
  4420. $result = Complaint::where($where)
  4421. ->when(!empty($data['status1']), function ($query) use ($data) {
  4422. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4423. })
  4424. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4425. // //json re_user_ids data[user_id]是不是在里面
  4426. // $query->Where(function ($q) use ($data) {
  4427. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4428. // ->where('complaint.status', 2);
  4429. // });
  4430. // })
  4431. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4432. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4433. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4434. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4435. ->orderBy('updated_at', 'desc')
  4436. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4437. //sql输出
  4438. if (empty($result)) {
  4439. return Result::error("暂无投诉信息", 0);
  4440. }
  4441. // 取出数据
  4442. $rows = $result->items();
  4443. $count = $result->total();
  4444. $responseData = [
  4445. 'rows' => $rows,
  4446. 'count' => $count,
  4447. ];
  4448. return Result::success($responseData);
  4449. }
  4450. public function getComplaintInfo(array $data): array
  4451. {
  4452. $result = Complaint::where('id', $data['id'])->first();
  4453. if (empty($result)) {
  4454. return Result::error("查询失败", 0);
  4455. }
  4456. return Result::success($result);
  4457. }
  4458. public function readComplaint(array $data): array
  4459. {
  4460. $result = Complaint::where('id', $data['id'])->first();
  4461. if (empty($result)) {
  4462. return Result::error("查询失败", 0);
  4463. }
  4464. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4465. $re_user_ids = json_decode($result['re_user_ids'], true);
  4466. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4467. //如果已经存在,就不再添加
  4468. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4469. $read_id = json_decode($result['read_id'], true);
  4470. if (!is_array($read_id)) {
  4471. $read_id = [];
  4472. }
  4473. if (!in_array($data['user_id'], $read_id)) {
  4474. $read_id[] = $data['user_id'];
  4475. $result['read_id'] = json_encode($read_id);
  4476. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4477. }
  4478. } else {
  4479. //如果不存在,就添加
  4480. $result['read_id'] = json_encode([$data['user_id']]);
  4481. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4482. }
  4483. }
  4484. return Result::success($result);
  4485. }
  4486. public function addComplaint(array $data): array
  4487. {
  4488. date_default_timezone_set('Asia/Shanghai');
  4489. $data['created_at'] = date('Y-m-d H:i:s');
  4490. $data['updated_at'] = date('Y-m-d H:i:s');
  4491. $this->sendMessage([
  4492. 'talk_type' => 800,
  4493. 'title' => $data['title'],
  4494. 'content' => '提交了审核',
  4495. 'messageType' => 6,
  4496. ]);
  4497. $result = Complaint::create($data);
  4498. return Result::success($result);
  4499. }
  4500. public function updateComplaint(array $data): array
  4501. {
  4502. date_default_timezone_set('Asia/Shanghai');
  4503. $data['updated_at'] = date('Y-m-d H:i:s');
  4504. $user_id = $data['user_id'] ?? 0;
  4505. $type_id = $data['type_id'] ?? 0;
  4506. unset($data['user_id']);
  4507. unset($data['type_id']);
  4508. $this->sendMessage([
  4509. 'talk_type' => 800,
  4510. 'title' => $data['title'],
  4511. 'content' => '提交了审核',
  4512. 'messageType' => 6,
  4513. ]);
  4514. $result = Complaint::where('id', $data['id'])->update($data);
  4515. return Result::success($result);
  4516. }
  4517. public function deleteComplaint(array $data): array
  4518. {
  4519. $result = Complaint::where('id', $data['id'])->delete();
  4520. return Result::success($result);
  4521. }
  4522. public function getComplainInfo(array $data): array
  4523. {
  4524. $result = Complaint::where('id', $data['id'])->first();
  4525. if (empty($result)) {
  4526. return Result::error("查询失败", 0);
  4527. }
  4528. return Result::success($result);
  4529. }
  4530. public function updateComplaintStatus(array $data): array
  4531. {
  4532. date_default_timezone_set('Asia/Shanghai');
  4533. $data['updated_at'] = date('Y-m-d H:i:s');
  4534. $user_id = $data['user_id'] ?? 0;
  4535. $type_id = $data['type_id'] ?? 0;
  4536. unset($data['user_id']);
  4537. unset($data['type_id']);
  4538. //处理, 写入处理人
  4539. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4540. $data['real_deal_user'] = $user_id;
  4541. }
  4542. //如果是deal 23,则判断是不是处理人
  4543. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4544. $complaintInof = Complaint::where('id', $data['id'])
  4545. ->where('real_deal_user', $user_id)
  4546. ->first();
  4547. if (empty($complaintInof)) {
  4548. return Result::error("处理人错误", 0);
  4549. }
  4550. }
  4551. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4552. if ($data['status'] == 1) {
  4553. $this->sendMessage([
  4554. 'talk_type' => 800,
  4555. 'title' => $complaintInfo['title'],
  4556. 'content' => '提交了审核',
  4557. 'messageType' => 6,
  4558. ]);
  4559. }
  4560. if ($data['status'] == 2 && !isset($data['deal'])) {
  4561. $this->sendMessage([
  4562. 'talk_type' => 801,
  4563. 'title' => $complaintInfo['title'],
  4564. 'content' => '审核通过',
  4565. 'messageType' => 6,
  4566. 'user_id' => $complaintInfo['user_id'],
  4567. ]);
  4568. $this->sendMessage([
  4569. 'talk_type' => 802,
  4570. 'title' => $complaintInfo['title'],
  4571. 'content' => '待处理',
  4572. 'messageType' => 6,
  4573. 'user_id' => $complaintInfo['re_user_ids'],
  4574. ]);
  4575. }
  4576. if ($data['status'] == 3 && !isset($data['deal'])) {
  4577. $this->sendMessage([
  4578. 'talk_type' => 801,
  4579. 'title' => $complaintInfo['title'],
  4580. 'content' => '审核拒绝',
  4581. 'messageType' => 6,
  4582. 'user_id' => $complaintInfo['user_id'],
  4583. ]);
  4584. }
  4585. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4586. $this->sendMessage([
  4587. 'talk_type' => 802,
  4588. 'title' => $complaintInfo['title'],
  4589. 'content' => '处理中',
  4590. 'messageType' => 6,
  4591. 'user_id' => $complaintInfo['re_user_ids'],
  4592. ]);
  4593. }
  4594. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4595. $this->sendMessage([
  4596. 'talk_type' => 802,
  4597. 'title' => $complaintInfo['title'],
  4598. 'content' => '不予处理',
  4599. 'messageType' => 6,
  4600. 'user_id' => $complaintInfo['re_user_ids'],
  4601. ]);
  4602. }
  4603. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4604. $this->sendMessage([
  4605. 'talk_type' => 802,
  4606. 'title' => $complaintInfo['title'],
  4607. 'content' => '已完结',
  4608. 'messageType' => 6,
  4609. 'user_id' => $complaintInfo['re_user_ids'],
  4610. ]);
  4611. }
  4612. $result = complaint::where('id', $data['id'])->update($data);
  4613. return Result::success($result);
  4614. }
  4615. public function updateGoodStatus(array $data): array
  4616. {
  4617. $user_id = $data['user_id'] ?? 0;
  4618. $type_id = $data['type_id'] ?? 0;
  4619. unset($data['user_id']);
  4620. unset($data['type_id']);
  4621. $goodInfo = Good::where('id', $data['id'])->first();
  4622. if ($data['status'] == 2) {
  4623. $this->sendMessage([
  4624. 'talk_type' => 201,
  4625. 'title' => $goodInfo['name'],
  4626. 'content' => '审核通过',
  4627. 'messageType' => 3,
  4628. 'user_id' => $goodInfo['user_id'],
  4629. ]);
  4630. }
  4631. if ($data['status'] == 3) {
  4632. $this->sendMessage([
  4633. 'talk_type' => 201,
  4634. 'title' => $goodInfo['name'],
  4635. 'content' => '审核拒绝',
  4636. 'messageType' => 3,
  4637. 'user_id' => $goodInfo['user_id'],
  4638. ]);
  4639. }
  4640. if ($data['status'] == 1) {
  4641. $this->sendMessage([
  4642. 'talk_type' => 200,
  4643. 'title' => $goodInfo['name'],
  4644. 'content' => '提交了审核',
  4645. 'messageType' => 3,
  4646. ]);
  4647. }
  4648. $result = Good::where('id', $data['id'])->update($data);
  4649. return Result::success($result);
  4650. }
  4651. public function updateJobHuntingStatus(array $data): array
  4652. {
  4653. $user_id = $data['user_id'] ?? 0;
  4654. $type_id = $data['type_id'] ?? 0;
  4655. unset($data['user_id']);
  4656. unset($data['type_id']);
  4657. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4658. if ($data['status'] == 2) {
  4659. $this->sendMessage([
  4660. 'talk_type' => 601,
  4661. 'title' => $jogHuntingInfo['name'],
  4662. 'content' => '审核通过',
  4663. 'messageType' => 11,
  4664. 'user_id' => $jogHuntingInfo['user_id'],
  4665. ]);
  4666. }
  4667. if ($data['status'] == 3) {
  4668. $this->sendMessage([
  4669. 'talk_type' => 601,
  4670. 'title' => $jogHuntingInfo['name'],
  4671. 'content' => '审核拒绝',
  4672. 'messageType' => 11,
  4673. 'user_id' => $jogHuntingInfo['user_id'],
  4674. ]);
  4675. }
  4676. if ($data['status'] == 1) {
  4677. $this->sendMessage([
  4678. 'talk_type' => 600,
  4679. 'title' => $jogHuntingInfo['name'],
  4680. 'content' => '提交了审核',
  4681. 'messageType' => 11,
  4682. ]);
  4683. }
  4684. $result = JobHunting::where('id', $data['id'])->update($data);
  4685. return Result::success($result);
  4686. }
  4687. public function updateNoticeStatus(array $data): array
  4688. {
  4689. $user_id = $data['user_id'] ?? 0;
  4690. $type_id = $data['type_id'] ?? 0;
  4691. unset($data['user_id']);
  4692. unset($data['type_id']);
  4693. //查询公告
  4694. $notice = Notice::where('id', $data['id'])->first();
  4695. if (empty($notice)) {
  4696. return Result::error("公告不存在", 0);
  4697. }
  4698. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4699. if ($data['status'] == 2 && $notice['is_group'] == 1 && $notice['status'] == 1 && empty($notice['group_id'])) {
  4700. //chat_group
  4701. $group_id = PublicData::uuid();
  4702. $groupData = [
  4703. 'id' => $group_id,
  4704. 'creator_id' => $notice['user_id'],
  4705. 'group_name' => $notice['group_name'] ?? '',
  4706. 'profile' => $notice['profile'] ?? 0,
  4707. ];
  4708. var_dump($groupData, '-----------------groupData-------');
  4709. $groupResult = ChatGroups::insertGetId($groupData);
  4710. var_dump($groupResult, '-----------------groupid-------');
  4711. $groupMemberData = [
  4712. 'id' => PublicData::uuid(),
  4713. 'user_id' => $notice['user_id'],
  4714. 'group_id' => $group_id,
  4715. 'leader' => 2,
  4716. ];
  4717. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4718. //$chat_ids 去除掉$data['user_id']
  4719. $chat_ids = json_decode($notice['re_user_ids'], true);
  4720. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4721. //插入群成员表
  4722. $groupMemberDataUser = [];
  4723. $chatData = [];
  4724. foreach ($chat_ids as $key => $value) {
  4725. $groupMemberDataUser[] = [
  4726. 'id' => PublicData::uuid(),
  4727. 'user_id' => $value,
  4728. 'group_id' => $group_id,
  4729. 'leader' => 1,
  4730. ];
  4731. $chatData[] = [
  4732. 'user_id' => $value,
  4733. 'msg_type' => 1,
  4734. 'receiver_id' => $group_id,
  4735. 'content' => '通过通知创建群聊',
  4736. 'group_receiver_id' => $notice['user_id'],
  4737. 'action' => 'recieved',
  4738. 'created_at' => date('Y-m-d H:i:s'),
  4739. ];
  4740. }
  4741. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4742. ChatGroupsMember::insert($groupMemberDataUser);
  4743. //插入一条管理员聊天记录
  4744. $chatData[] = [
  4745. 'user_id' => $notice['user_id'],
  4746. 'msg_type' => 1,
  4747. 'receiver_id' => $group_id,
  4748. 'content' => '通过通知创建群聊',
  4749. 'group_receiver_id' => $notice['user_id'],
  4750. 'action' => 'said',
  4751. 'created_at' => date('Y-m-d H:i:s'),
  4752. ];
  4753. var_dump($chatData, '-----------------chatData-------');
  4754. $chatResult = ChatRecords::insert($chatData);
  4755. //更新result的 group_id
  4756. $data['group_id'] = $group_id;
  4757. Notice::where(['id' => $data['id']])->update($data);
  4758. }
  4759. $result = Notice::where('id', $data['id'])->update($data);
  4760. $noticeInfo = Notice::where('id', $data['id'])->first();
  4761. if ($data['status'] == 2) {
  4762. $this->sendMessage([
  4763. 'talk_type' => 701,
  4764. 'title' => $noticeInfo['title'],
  4765. 'content' => '审核通过',
  4766. 'messageType' => 3,
  4767. 'user_id' => $noticeInfo['user_id'],
  4768. ]);
  4769. }
  4770. if ($data['status'] == 3) {
  4771. $this->sendMessage([
  4772. 'talk_type' => 701,
  4773. 'title' => $noticeInfo['title'],
  4774. 'content' => '审核拒绝',
  4775. 'messageType' => 3,
  4776. 'user_id' => $noticeInfo['user_id'],
  4777. ]);
  4778. }
  4779. if ($data['status'] == 1) {
  4780. $this->sendMessage([
  4781. 'talk_type' => 700,
  4782. 'title' => $noticeInfo['title'],
  4783. 'content' => '提交了审核',
  4784. 'messageType' => 3,
  4785. ]);
  4786. }
  4787. return Result::success($result);
  4788. }
  4789. public function getDUser(array $data): array
  4790. {
  4791. if (!empty($data['ids'])) {
  4792. $user = User::whereIn('id', $data['ids'])->getall();
  4793. if (empty($user)) {
  4794. return Result::error('无数据', 0);
  4795. }
  4796. return Result::success($user);
  4797. }
  4798. $where = [];
  4799. if (!empty($data['department_id'])) {
  4800. $where['department_id'] = $data['department_id'];
  4801. }
  4802. if (!empty($data['city_id'])) {
  4803. $where['city_id'] = $data['city_id'];
  4804. }
  4805. $result = User::where('type_id', 2)
  4806. ->where('status', 1)
  4807. ->where($where)
  4808. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4809. ->get();
  4810. if (empty($result)) {
  4811. return Result::error("查询失败", 0);
  4812. }
  4813. return Result::success($result);
  4814. }
  4815. /**
  4816. * 验证导航名称是否重复
  4817. * @return void
  4818. */
  4819. public function checkCategoryName(array $data): array
  4820. {
  4821. $result = Category::when($data, function ($query) use ($data) {
  4822. if (isset($data['name']) && $data['name']) {
  4823. $query->where("name", $data['name']);
  4824. }
  4825. if (isset($data['id']) && $data['id']) {
  4826. $query->where("id", "!=", $data['id']);
  4827. }
  4828. })->first();
  4829. if ($result) {
  4830. return Result::error("已存在");
  4831. } else {
  4832. return Result::success();
  4833. }
  4834. }
  4835. //20250226 产品列表
  4836. // 20250306 -------招聘--------fr
  4837. /*
  4838. * 招聘列表
  4839. * */
  4840. public function getJobRecruitingList(array $data): array
  4841. {
  4842. $where = [];
  4843. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4844. if ($data['checkout'] == 0) {
  4845. $job_status = [0, 2];
  4846. } else {
  4847. $job_status = [1];
  4848. }
  4849. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4850. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4851. }
  4852. $user = User::where('id', $data['user_id'])->first();
  4853. if (empty($user)) {
  4854. return Result::error("用户不存在", 0);
  4855. }
  4856. // 3:企业会员
  4857. if ($user['type_id'] == 3) {
  4858. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4859. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4860. }
  4861. // 如果 $where 为空,则不添加 where 条件
  4862. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4863. return $query->where($where);
  4864. })
  4865. ->whereIn('job_recruiting.status', $job_status)
  4866. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4867. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4868. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4869. ->orderBy("updated_at", "desc")
  4870. ->offset(($data['page'] - 1) * $data['page_size'])
  4871. ->limit($data['page_size'])
  4872. ->get()
  4873. ->all();
  4874. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4875. return $query->where($where);
  4876. })
  4877. ->whereIn('job_recruiting.status', $job_status)
  4878. ->count();
  4879. if (empty($result)) {
  4880. return Result::error("暂无招聘信息", 0);
  4881. }
  4882. return Result::success($result);
  4883. }
  4884. /*
  4885. * 招聘信息添加
  4886. * */
  4887. public function addJobRecruiting(array $data): array
  4888. {
  4889. // var_dump('添加招聘进入news------data',$data);
  4890. // return Result::success($data);
  4891. $user = User::where('user.id', $data['user_id'])
  4892. ->where('user.status', 1)
  4893. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4894. ->select(
  4895. 'user.type_id',
  4896. 'user.mobile',
  4897. 'user.email',
  4898. 'user_info.business_name',
  4899. 'user_info.company_hy_id',
  4900. 'user_info.company_nature',
  4901. 'user_info.company_size',
  4902. 'user_info.introduction',
  4903. 'user_info.real_name',
  4904. 'user_info.company_url',
  4905. 'user_info.address_arr_id',
  4906. 'user_info.address'
  4907. )
  4908. ->first();
  4909. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4910. return Result::error("用户不存在", 0);
  4911. }
  4912. $web = Website::where('id', $data['website_id'])->first();
  4913. if (empty($web)) {
  4914. return Result::error("网站不存在", 0);
  4915. }
  4916. // var_dump('添加招聘进入news---user---user',$user);
  4917. // return Result::success($user);
  4918. $data['action_id'] = $data['user_id'] ?? null;
  4919. $data['user_type'] = $user['type_id'] ?? null;
  4920. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  4921. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  4922. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  4923. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  4924. // 公司地址 管理员必填
  4925. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  4926. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  4927. // 管理员-企业相关信息
  4928. $company = [
  4929. // 'user_id' => $data['user_id']?? null,
  4930. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  4931. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  4932. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  4933. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  4934. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  4935. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  4936. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  4937. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  4938. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  4939. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  4940. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  4941. ];
  4942. //去掉相关企业信息
  4943. $job = array_diff_key($data, array_flip(array_keys($company)));
  4944. // var_dump('添加招聘进入news---job---user',$job);
  4945. Db::beginTransaction();
  4946. try {
  4947. // // 先添加职位相关信息
  4948. if ($user['type_id'] == 10000) {
  4949. $job['status'] = 1;
  4950. }
  4951. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  4952. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  4953. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  4954. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  4955. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  4956. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  4957. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  4958. // return Result::success($job);
  4959. $jobId = JobRecruiting::insertGetId($job);
  4960. if (empty($jobId)) {
  4961. Db::rollBack();
  4962. return Result::error("添加失败");
  4963. }
  4964. // 添加公司信息
  4965. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  4966. $company['job_id'] = $jobId;
  4967. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  4968. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  4969. if ($user['type_id'] == 10000) {
  4970. // 管理员添加企业信息
  4971. $companyId = JobCompany::insertGetId($company);
  4972. if (empty($companyId)) {
  4973. Db::rollBack();
  4974. return Result::error("添加失败");
  4975. }
  4976. } else {
  4977. // 企业会员添加企业信息
  4978. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  4979. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  4980. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  4981. $company['job_id'] = $jobId;
  4982. $companyId = JobCompany::insertGetId($company);
  4983. if (empty($companyId)) {
  4984. Db::rollBack();
  4985. return Result::error("添加失败");
  4986. }
  4987. }
  4988. Db::commit();
  4989. $result = [
  4990. 'job_id' => $jobId,
  4991. 'company_id' => $companyId,
  4992. ];
  4993. return Result::success($result);
  4994. } catch (\Exception $e) {
  4995. Db::rollBack();
  4996. return Result::error($e->getMessage(), 0);
  4997. }
  4998. // return Result::success($result);
  4999. }
  5000. /*
  5001. * 获取招聘信息详情
  5002. * */
  5003. public function getJobRecruitingInfo(array $data): array
  5004. {
  5005. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5006. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5007. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5008. ->select(
  5009. 'job_recruiting.*',
  5010. 'website.website_name as website_name',
  5011. 'job_company.business_name',
  5012. 'job_company.company_hy_id',
  5013. 'job_company.company_size',
  5014. 'job_company.company_nature',
  5015. 'job_company.introduction',
  5016. 'job_company.real_name',
  5017. 'job_company.mobile',
  5018. 'job_company.company_url',
  5019. 'job_company.address_arr_id',
  5020. 'job_company.address',
  5021. 'job_company.email'
  5022. )
  5023. ->first();
  5024. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5025. if (!empty($cityId)) {
  5026. if (isset($cityId[1]) && $cityId[1] != null) {
  5027. $city = District::where('id', $cityId[1])->first(['name']);
  5028. } else {
  5029. $city = District::where('id', $cityId[0])->first(['name']);
  5030. }
  5031. $result['city'] = $city['name'] ?? '';
  5032. }
  5033. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5034. if (is_array($addressId) && !empty($addressId)) {
  5035. $address = District::whereIn('id', $addressId)
  5036. ->orderBy('level', 'asc')
  5037. ->get(['name'])
  5038. ->pluck('name')
  5039. ->implode('');
  5040. // $job->address_name = $address ?? '';
  5041. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5042. }
  5043. if (empty($result)) {
  5044. return Result::error("招聘信息不存在", 0);
  5045. }
  5046. // return Result::success($job);
  5047. return Result::success($result);
  5048. }
  5049. /*
  5050. * 修改招聘信息
  5051. * */
  5052. public function upJobRecruiting(array $data): array
  5053. {
  5054. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5055. // return Result::success($job);
  5056. if (empty($job)) {
  5057. return Result::error("招聘信息不存在", 0);
  5058. }
  5059. $user = User::where('id', $data['user_id'])->first();
  5060. // return Result::success($user);
  5061. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5062. return Result::error("用户不存在", 0);
  5063. }
  5064. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5065. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5066. }
  5067. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5068. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5069. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5070. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5071. // 公司地址 管理员必填
  5072. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5073. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5074. // 管理员-企业相关信息
  5075. $company = [
  5076. // 'user_id' => $data['user_id']?? null,
  5077. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5078. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5079. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5080. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5081. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5082. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5083. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5084. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5085. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5086. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5087. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5088. ];
  5089. //去掉相关企业信息
  5090. $data = array_diff_key($data, array_flip(array_keys($company)));
  5091. $jobId = $data['id'];
  5092. $web = $data['website_id'];
  5093. $data['action_id'] = $data['user_id'];
  5094. unset($data['user_id']);
  5095. unset($data['user_type']);
  5096. unset($data['id']);
  5097. unset($data['website_id']);
  5098. // return Result::success($data);
  5099. Db::beginTransaction();
  5100. try {
  5101. // 管理员修改招聘信息
  5102. if ($user['type_id'] == 10000) {
  5103. $data['website_id'] = $web;
  5104. $company['website_id'] = $data['website_id'];
  5105. $data['status'] = 1;
  5106. } else {
  5107. $data['status'] = 0;
  5108. }
  5109. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5110. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5111. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5112. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5113. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5114. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5115. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5116. // return Result::success($job);
  5117. // Db::rollBack();
  5118. // return Result::success($company);
  5119. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5120. $this->sendMessage([
  5121. 'talk_type' => 500,
  5122. 'title' => $data['title'],
  5123. 'content' => '提交了审核',
  5124. 'messageType' => 10,
  5125. ]);
  5126. }
  5127. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5128. if (empty($result['job'])) {
  5129. Db::rollBack();
  5130. return Result::error("修改招聘信息失败");
  5131. }
  5132. // 管理员修改企业相关信息
  5133. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5134. if (empty($result['company'])) {
  5135. Db::rollBack();
  5136. return Result::error("修改企业相关信息失败");
  5137. }
  5138. Db::commit();
  5139. // return Result::success($result);
  5140. } catch (\Exception $e) {
  5141. Db::rollBack();
  5142. return Result::error($e->getMessage(), 0);
  5143. }
  5144. return Result::success($result);
  5145. }
  5146. /*
  5147. * 招聘信息删除
  5148. * */
  5149. public function delJobRecruiting(array $data): array
  5150. {
  5151. $user = User::where('id', $data['user_id'])->first();
  5152. if (empty($user)) {
  5153. return Result::error("用户不存在", 0);
  5154. }
  5155. $job = JobRecruiting::where('id', $data['id'])->first();
  5156. if (empty($job)) {
  5157. return Result::error("招聘信息不存在", 0);
  5158. }
  5159. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5160. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5161. }
  5162. Db::beginTransaction();
  5163. try {
  5164. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5165. if (empty($result['job'])) {
  5166. Db::rollBack();
  5167. return Result::error("删除招聘信息失败");
  5168. }
  5169. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5170. if (empty($result['company'])) {
  5171. Db::rollBack();
  5172. return Result::error("删除企业相关信息失败");
  5173. }
  5174. Db::commit();
  5175. } catch (\Exception $e) {
  5176. Db::rollBack();
  5177. return Result::error($e->getMessage(), 0);
  5178. }
  5179. return Result::success($result);
  5180. }
  5181. /*
  5182. * 获取公司信息
  5183. * */
  5184. public function getJobCompany(array $data): array
  5185. {
  5186. $user = User::where('user.id', $data['user_id'])
  5187. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5188. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5189. ->first();
  5190. // return Result::success($user);
  5191. if (empty($user)) {
  5192. return Result::error("用户不存在", 0);
  5193. }
  5194. if ($user['type_id'] == 3) {
  5195. $result = [
  5196. // 'id' => 0,
  5197. 'user_id' => $data['user_id'],
  5198. 'website_id' => $data['website_id'],
  5199. 'business_name' => $user['business_name'], // 企业名称
  5200. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5201. 'company_nature' => $user['company_nature'], // 公司性质
  5202. 'company_size' => $user['company_size'], // 公司规模
  5203. 'introduction' => $user['introduction'], // 公司简介
  5204. 'real_name' => $user['real_name'], // 企业联系人
  5205. 'mobile' => $user['mobile'], // 企业联系电话
  5206. 'company_url' => $user['company_url'], // 企业网址
  5207. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5208. 'address' => $user['address'], // 企业地址
  5209. 'email' => $user['email'], // 企业邮箱
  5210. ];
  5211. } else {
  5212. return Result::error("用户类型错误", 0);
  5213. }
  5214. if (empty($result)) {
  5215. return Result::error("公司信息不存在", 0);
  5216. }
  5217. return Result::success($result);
  5218. }
  5219. /*
  5220. * 修改公司信息
  5221. * */
  5222. public function upJobCompany(array $data): array
  5223. {
  5224. // return Result::success($data);
  5225. $user = User::where('user.id', $data['user_id'])
  5226. ->where('user.status', 1)
  5227. ->select('user.user_name', 'user.type_id')
  5228. ->first();
  5229. if (empty($user)) {
  5230. return Result::error("用户不存在", 0);
  5231. }
  5232. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5233. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5234. $company = [
  5235. 'business_name' => $data['business_name'], // 企业名称
  5236. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5237. 'company_nature' => $data['company_nature'], // 公司性质
  5238. 'company_size' => $data['company_size'], // 公司规模
  5239. 'introduction' => $data['introduction'], // 公司简介
  5240. // 'real_name' => $data['real_name'], // 企业联系人
  5241. 'company_url' => $data['company_url'], // 企业网址
  5242. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5243. 'address' => $data['address'], // 企业详细地址
  5244. // 'email' => $data['email'], // 企业邮箱
  5245. ];
  5246. if ($user['type_id'] == 3) {
  5247. Db::beginTransaction();
  5248. try {
  5249. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5250. 'business_name' => $data['business_name'], // 企业名称
  5251. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5252. 'company_nature' => $data['company_nature'], // 公司性质
  5253. 'company_size' => $data['company_size'], // 公司规模
  5254. 'introduction' => $data['introduction'], // 公司简介
  5255. // 'real_name' => $data['real_name'], // 企业联系人
  5256. 'company_url' => $data['company_url'], // 企业网址
  5257. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5258. 'address' => $data['address'], // 企业详细地址
  5259. ]);
  5260. if (empty($result['userinfo'])) {
  5261. Db::rollBack();
  5262. return Result::error('修改企业会员信息失败!');
  5263. }
  5264. $result['user'] = User::where('id', $data['user_id'])->update([
  5265. 'email' => $data['email'], // 企业邮箱
  5266. ]);
  5267. if (empty($result['user'])) {
  5268. Db::rollBack();
  5269. return Result::error('修改个人中心信息失败!');
  5270. }
  5271. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5272. if (!empty($job_company)) {
  5273. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5274. if (empty($result['job_company'])) {
  5275. Db::rollBack();
  5276. return Result::error('修改企业会员信息失败!');
  5277. }
  5278. }
  5279. Db::commit();
  5280. return Result::success($result);
  5281. } catch (\Exception $e) {
  5282. Db::rollBack();
  5283. return Result::error($e->getMessage(), 0);
  5284. }
  5285. } else {
  5286. return Result::error("用户类型错误", 0);
  5287. }
  5288. }
  5289. /*
  5290. * 获取省-市
  5291. * */
  5292. public function getJobRecruitingArea(array $data): array
  5293. {
  5294. if (isset($data['pid']) && $data['pid'] != null) {
  5295. $result = District::where('pid', $data['pid'])->get()->all();
  5296. } else {
  5297. $result = District::where('level', 1)->get()->all();
  5298. }
  5299. if (empty($result)) {
  5300. return Result::error("暂无此省市", 0);
  5301. }
  5302. return Result::success($result);
  5303. }
  5304. /*
  5305. * 获取行业分类
  5306. * */
  5307. public function getIndustry(array $data): array
  5308. {
  5309. $result = JobIndustry::get()->all();
  5310. if (empty($result)) {
  5311. return Result::error("暂无行业分类", 0);
  5312. }
  5313. return Result::success($result);
  5314. }
  5315. /*
  5316. * 获取职位
  5317. * */
  5318. public function getPositionList(array $data): array
  5319. {
  5320. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5321. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5322. } else {
  5323. $result = JobPosition::where('zwpid', 0)->get()->all();
  5324. }
  5325. if (empty($result)) {
  5326. return Result::error("暂无此职位", 0);
  5327. }
  5328. return Result::success($result);
  5329. }
  5330. /*
  5331. * 获取工作性质-菜单
  5332. * */
  5333. public function getJobNature(array $data): array
  5334. {
  5335. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5336. if (empty($result)) {
  5337. return Result::error("暂无工作性质", 0);
  5338. }
  5339. return Result::success($result);
  5340. }
  5341. /*
  5342. * 获取工作经验-菜单
  5343. * */
  5344. public function getExperience(array $data): array
  5345. {
  5346. $result = JobEnum::where('egroup', 'years')->get()->all();
  5347. if (empty($result)) {
  5348. return Result::error("暂无工作经验", 0);
  5349. }
  5350. return Result::success($result);
  5351. }
  5352. /*
  5353. * 获取学历-菜单
  5354. * */
  5355. public function getEducation(array $data): array
  5356. {
  5357. $result = JobEnum::where('egroup', 'education')->get()->all();
  5358. if (empty($result)) {
  5359. return Result::error("暂无学历", 0);
  5360. }
  5361. return Result::success($result);
  5362. }
  5363. /*
  5364. * 获取薪资-菜单
  5365. * */
  5366. public function getSalary(array $data): array
  5367. {
  5368. $result = JobEnum::where('egroup', 'income')->get()->all();
  5369. if (empty($result)) {
  5370. return Result::error("暂无薪资", 0);
  5371. }
  5372. return Result::success($result);
  5373. }
  5374. /*
  5375. * 获取语言-菜单
  5376. * */
  5377. public function getLanguage(array $data): array
  5378. {
  5379. $result = JobEnum::where('egroup', 'language')->get()->all();
  5380. if (empty($result)) {
  5381. return Result::error("暂无语言", 0);
  5382. }
  5383. return Result::success($result);
  5384. }
  5385. /*
  5386. * 获取掌握程度-菜单
  5387. * */
  5388. public function getLevel(array $data): array
  5389. {
  5390. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5391. if (empty($result)) {
  5392. return Result::error("暂无工作性质", 0);
  5393. }
  5394. return Result::success($result);
  5395. }
  5396. // 公司信息
  5397. /*
  5398. * 获取公司性质-菜单
  5399. * */
  5400. public function getCompanyNature(array $data): array
  5401. {
  5402. $result = JobNature::get()->all();
  5403. if (empty($result)) {
  5404. return Result::error("暂无公司性质", 0);
  5405. }
  5406. return Result::success($result);
  5407. }
  5408. /*
  5409. * 获取公司规模-菜单
  5410. * */
  5411. public function getCompanySize(array $data): array
  5412. {
  5413. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5414. if (empty($result)) {
  5415. return Result::error("暂无公司规模", 0);
  5416. }
  5417. return Result::success($result);
  5418. }
  5419. /*
  5420. * 招聘信息审核
  5421. * */
  5422. public function checkJobRecruiting(array $data): array
  5423. {
  5424. $user = User::where('id', $data['user_id'])->first();
  5425. if (empty($user)) {
  5426. return Result::error("用户不存在", 0);
  5427. }
  5428. $job = JobRecruiting::where('id', $data['id'])->first();
  5429. if (empty($job)) {
  5430. return Result::error("招聘信息不存在", 0);
  5431. }
  5432. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5433. if ($user['type_id'] != 10000) {
  5434. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5435. }
  5436. // 驳回原因
  5437. if ($data['status'] == 2) {
  5438. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5439. }
  5440. $data['action_id'] = $data['user_id'];
  5441. unset($data['user_id']);
  5442. if ($data['status'] == 1) {
  5443. $this->sendMessage([
  5444. 'talk_type' => 501,
  5445. 'title' => $job['title'],
  5446. 'content' => '审核通过',
  5447. 'messageType' => 10,
  5448. 'user_id' => $job['user_id'],
  5449. ]);
  5450. }
  5451. if ($data['status'] == 2) {
  5452. $this->sendMessage([
  5453. 'talk_type' => 501,
  5454. 'title' => $job['title'],
  5455. 'content' => '审核拒绝',
  5456. 'messageType' => 10,
  5457. 'user_id' => $job['user_id'],
  5458. ]);
  5459. }
  5460. if ($data['status'] == 0) {
  5461. $this->sendMessage([
  5462. 'talk_type' => 500,
  5463. 'title' => $job['title'],
  5464. 'content' => '提交了审核',
  5465. 'messageType' => 10,
  5466. ]);
  5467. }
  5468. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5469. if (empty($result)) {
  5470. return Result::error("审核失败", 0);
  5471. }
  5472. return Result::success($result);
  5473. }
  5474. public function myApplyList(array $data): array
  5475. {
  5476. var_dump($data, '------参数');
  5477. $user = User::where('id', $data['user_id'])->first();
  5478. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5479. return Result::error("用户不存在", 0);
  5480. }
  5481. // 1:个人会员 职场机会
  5482. if ($user['type_id'] == 1) {
  5483. $where['user_id'] = $user['id'];
  5484. }
  5485. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5486. $query->where('user_id', $user['id']);
  5487. })
  5488. ->pluck('recruit_id');
  5489. $where = [];
  5490. if (isset($data['salary']) && $data['salary'] != null) {
  5491. $where['job_recruiting.salary'] = $data['salary'];
  5492. }
  5493. if (isset($data['experience']) && $data['experience'] != null) {
  5494. $where['job_recruiting.experience'] = $data['experience'];
  5495. }
  5496. if (isset($data['business_name']) && $data['business_name'] != null) {
  5497. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5498. }
  5499. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5500. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5501. ->where($where);
  5502. // ->count();
  5503. $count = $query->count();
  5504. $query = clone $query;
  5505. $job = $query
  5506. ->leftJoin('job_enum as income_enum', function ($join) {
  5507. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5508. ->where('income_enum.egroup', 'income');
  5509. })
  5510. ->leftJoin('job_enum as years_enum', function ($join) {
  5511. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5512. ->where('years_enum.egroup', 'years');
  5513. })
  5514. // ->where($where)
  5515. ->orderBy('job_recruiting.updated_at', 'desc')
  5516. ->select(
  5517. 'job_recruiting.id',
  5518. 'job_recruiting.title',
  5519. 'job_company.business_name',
  5520. 'income_enum.evalue as salary_evalue',
  5521. 'income_enum.ename as salary_ename',
  5522. 'years_enum.evalue as experience_evalue',
  5523. 'years_enum.ename as experience_ename',
  5524. 'job_recruiting.updated_at'
  5525. )
  5526. ->offset(($data['page'] - 1) * $data['pageSize'])
  5527. ->limit($data['pageSize'])
  5528. ->get()
  5529. ->all();
  5530. if (empty($job)) {
  5531. return Result::error("暂无招聘信息", 0);
  5532. }
  5533. $result = [
  5534. 'row' => $job,
  5535. 'count' => $count,
  5536. ];
  5537. return Result::success($result);
  5538. }
  5539. public function readJobApply(array $data): array
  5540. {
  5541. $result = JobApply::where('id', $data['id'])->first();
  5542. if (empty($result)) {
  5543. return Result::error("查询失败", 0);
  5544. }
  5545. $result = JobApply::where('id', $data['id'])->update([
  5546. 'status' => 2,
  5547. ]);
  5548. return Result::success($result);
  5549. }
  5550. /*
  5551. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5552. * */
  5553. public function getRecruitingList(array $data): array
  5554. {
  5555. $user = User::where('id', $data['user_id'])->first();
  5556. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5557. return Result::error("用户不存在", 0);
  5558. }
  5559. // 1:个人会员 职场机会
  5560. if ($user['type_id'] == 1) {
  5561. $where['user_id'] = $user['id'];
  5562. }
  5563. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5564. $query->where('receiver_id', $user['id']);
  5565. })
  5566. ->pluck('recruit_id');
  5567. // return Result::success($recruitingId);
  5568. $where = [];
  5569. if (isset($data['salary']) && $data['salary'] != null) {
  5570. $where['job_recruiting.salary'] = $data['salary'];
  5571. }
  5572. if (isset($data['experience']) && $data['experience'] != null) {
  5573. $where['job_recruiting.experience'] = $data['experience'];
  5574. }
  5575. if (isset($data['business_name']) && $data['business_name'] != null) {
  5576. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5577. }
  5578. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5579. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5580. ->where($where);
  5581. // ->count();
  5582. $count = $query->count();
  5583. $query = clone $query;
  5584. $job = $query
  5585. ->leftJoin('job_enum as income_enum', function ($join) {
  5586. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5587. ->where('income_enum.egroup', 'income');
  5588. })
  5589. ->leftJoin('job_enum as years_enum', function ($join) {
  5590. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5591. ->where('years_enum.egroup', 'years');
  5592. })
  5593. // ->where($where)
  5594. ->orderBy('job_recruiting.updated_at', 'desc')
  5595. ->select(
  5596. 'job_recruiting.id',
  5597. 'job_recruiting.title',
  5598. 'job_company.business_name',
  5599. 'income_enum.evalue as salary_evalue',
  5600. 'income_enum.ename as salary_ename',
  5601. 'years_enum.evalue as experience_evalue',
  5602. 'years_enum.ename as experience_ename',
  5603. 'job_recruiting.updated_at'
  5604. )
  5605. ->offset(($data['page'] - 1) * $data['pageSize'])
  5606. ->limit($data['pageSize'])
  5607. ->get()
  5608. ->all();
  5609. if (empty($job)) {
  5610. return Result::error("暂无招聘信息", 0);
  5611. }
  5612. $result = [
  5613. 'row' => $job,
  5614. 'count' => $count,
  5615. ];
  5616. return Result::success($result);
  5617. }
  5618. /*
  5619. * 获取企业会员-招聘信息列表
  5620. * */
  5621. public function getRecruitingInfo(array $data): array
  5622. {
  5623. $user = User::where('id', $data['user_id'])->first();
  5624. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5625. return Result::error("用户不存在", 0);
  5626. }
  5627. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5628. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5629. ->select(
  5630. 'job_recruiting.*',
  5631. 'job_company.business_name',
  5632. 'job_company.company_hy_id',
  5633. 'job_company.company_size',
  5634. 'job_company.company_nature',
  5635. 'job_company.introduction',
  5636. 'job_company.real_name',
  5637. 'job_company.mobile',
  5638. 'job_company.company_url',
  5639. 'job_company.address_arr_id',
  5640. 'job_company.address',
  5641. 'job_company.email'
  5642. )
  5643. ->get();
  5644. if (empty($recruiting)) {
  5645. return Result::error("暂无招聘信息", 0);
  5646. }
  5647. return Result::success($recruiting);
  5648. }
  5649. /*
  5650. * 获取企业会员-我的沟通
  5651. * */
  5652. public function getJobResumeList(array $data): array
  5653. {
  5654. $user = User::where('id', $data['user_id'])->first();
  5655. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5656. return Result::error("用户不存在", 0);
  5657. }
  5658. $where = [];
  5659. if (isset($data['salary']) && $data['salary'] != null) {
  5660. $where['job_hunting.salary'] = $data['salary'];
  5661. }
  5662. if (isset($data['user_name']) && $data['user_name'] != null) {
  5663. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5664. }
  5665. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5666. $query->where('job_resume.user_id', $user['id']);
  5667. })
  5668. ->when(!empty($where), function ($query) use ($where) {
  5669. $query->where($where);
  5670. })
  5671. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5672. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5673. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5674. ->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');
  5675. $count = $job->count();
  5676. if ($count == 0) {
  5677. return Result::error("暂无沟通记录", 0);
  5678. }
  5679. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5680. ->offset(($data['page'] - 1) * $data['pageSize'])
  5681. ->limit($data['pageSize'])
  5682. ->get();
  5683. if (empty($jobs)) {
  5684. return Result::error("暂无沟通记录", 0);
  5685. }
  5686. $result['row'] = $this->processJob($jobs, '');
  5687. $result['count'] = $count;
  5688. return Result::success($result);
  5689. }
  5690. public function readJobResume(array $data): array
  5691. {
  5692. $result = JobResume::where('id', $data['id'])->first();
  5693. if (empty($result)) {
  5694. return Result::error("查询失败", 0);
  5695. }
  5696. $result = JobResume::where('id', $data['id'])->update([
  5697. 'status' => 2,
  5698. ]);
  5699. return Result::success($result);
  5700. }
  5701. // 20250306 招聘
  5702. //20250422 书刊音像
  5703. public function addBook(array $data): array
  5704. {
  5705. $user_id = $data['user_id'] ?? 0;
  5706. $type_id = $data['type_id'] ?? 0;
  5707. // $website_id = $data['website_id'] ?? 0;
  5708. // unset($data['user_id']);
  5709. unset($data['type_id']);
  5710. // unset($data['website_id']);
  5711. //处理数组
  5712. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5713. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5714. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5715. if ($data['img_url'] == '') {
  5716. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5717. preg_match_all($reg, $data['detail'], $matches);
  5718. if (isset($matches[1][0])) {
  5719. //截取varchar240
  5720. $data['img_url'] = substr($matches[1][0], 0, 240);
  5721. }
  5722. }
  5723. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5724. //提取标题+内容中的关键词
  5725. $data['keyword'] = $data['title'];
  5726. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5727. Jieba::init(); // 初始化 jieba-php
  5728. Finalseg::init();
  5729. $segList = Jieba::cut($data['keyword']);
  5730. $segList1 = array_slice($segList, 0, 8);
  5731. $data['keyword'] = implode(',', $segList1);
  5732. }
  5733. if ($data['description'] == '') {
  5734. //提取内容中的描述
  5735. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5736. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5737. }
  5738. var_dump($data, '--');
  5739. if ($data['status'] == 1) {
  5740. $this->sendMessage([
  5741. 'talk_type' => 400,
  5742. 'title' => $data['title'],
  5743. 'content' => '提交了审核',
  5744. 'messageType' => 7,
  5745. ]);
  5746. }
  5747. $result = Book::insertGetId($data);
  5748. if (empty($result)) {
  5749. return Result::error("添加失败", 0);
  5750. }
  5751. return Result::success($result);
  5752. }
  5753. public function getBookList(array $data): array
  5754. {
  5755. $where = [];
  5756. if (!empty($data["title"])) {
  5757. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5758. }
  5759. if (!empty($data['website_name'])) {
  5760. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5761. }
  5762. if (!empty($data['status'])) {
  5763. $where[] = ['book.status', '=', $data['status']];
  5764. }
  5765. $user_id = $data['user_id'];
  5766. $type_id = $data['type_id'];
  5767. // $type_id = 4;
  5768. var_dump($type_id, '------1--------');
  5769. if ($type_id != 10000) {
  5770. $where[] = ['book.user_id', '=', $user_id];
  5771. }
  5772. var_dump(!empty($data['status1']), '=-===1');
  5773. $result = Book::where($where)
  5774. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5775. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5776. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5777. ->when(isset($data['status1']), function ($query) use ($data) {
  5778. $query->whereIn('book.status', [1, 3]);
  5779. })
  5780. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5781. ->orderBy("updated_at", "desc")
  5782. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5783. if (empty($result)) {
  5784. return Result::error("暂无数据", 0);
  5785. }
  5786. // 取出数据
  5787. $rows = $result->items();
  5788. $count = $result->total();
  5789. $responseData = [
  5790. 'rows' => $rows,
  5791. 'count' => $count,
  5792. ];
  5793. return Result::success($responseData);
  5794. }
  5795. public function deleteBook(array $data): array
  5796. {
  5797. $result = Book::where('id', $data['id'])->delete();
  5798. if (empty($result)) {
  5799. return Result::error("删除失败", 0);
  5800. }
  5801. return Result::success($result);
  5802. }
  5803. public function updateBook(array $data): array
  5804. {
  5805. // $user_id = $data['user_id'] ?? 0;
  5806. $type_id = $data['type_id'] ?? 0;
  5807. // $website_id = $data['website_id'] ?? 0;
  5808. unset($data['user_id']);
  5809. unset($data['type_id']);
  5810. // unset($data['website_id']);
  5811. //处理数组
  5812. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5813. if ($data['img_url'] == '') {
  5814. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5815. preg_match_all($reg, $data['detail'], $matches);
  5816. if (isset($matches[1][0])) {
  5817. //截取varchar240
  5818. $data['img_url'] = substr($matches[1][0], 0, 240);
  5819. }
  5820. }
  5821. if ($data['keyword'] == '') {
  5822. //提取标题+内容中的关键词
  5823. $data['keyword'] = $data['title'];
  5824. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5825. Jieba::init(); // 初始化 jieba-php
  5826. Finalseg::init();
  5827. $segList = Jieba::cut($data['keyword']);
  5828. $segList1 = array_slice($segList, 0, 8);
  5829. $data['keyword'] = implode(',', $segList1);
  5830. }
  5831. if ($data['description'] == '') {
  5832. //提取内容中的描述
  5833. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5834. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5835. }
  5836. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5837. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5838. if ($data['status'] == 1) {
  5839. $this->sendMessage([
  5840. 'talk_type' => 400,
  5841. 'title' => $data['title'],
  5842. 'content' => '提交了审核',
  5843. 'messageType' => 7,
  5844. ]);
  5845. }
  5846. $result = Book::where("id", $data["id"])->update($data);
  5847. if (empty($result)) {
  5848. return Result::error("更新失败", 0);
  5849. }
  5850. return Result::success($result);
  5851. }
  5852. public function getBookInfo(array $data): array
  5853. {
  5854. $result = Book::where("id", $data["id"])->first();
  5855. if (empty($result)) {
  5856. return Result::error("获取失败", 0);
  5857. }
  5858. return Result::success($result);
  5859. }
  5860. public function updateBookStatus(array $data): array
  5861. {
  5862. //审核
  5863. unset($data['user_id']);
  5864. $bookInfo = Book::where("id", $data["id"])->first();
  5865. var_dump($bookInfo, '----');
  5866. if ($data['status'] == 2) {
  5867. $this->sendMessage([
  5868. 'talk_type' => 401,
  5869. 'title' => $bookInfo['title'],
  5870. 'content' => '审核通过',
  5871. 'messageType' => 7,
  5872. 'user_id' => $bookInfo['user_id'],
  5873. ]);
  5874. }
  5875. if ($data['status'] == 3) {
  5876. $this->sendMessage([
  5877. 'talk_type' => 401,
  5878. 'title' => $bookInfo['title'],
  5879. 'content' => '审核拒绝',
  5880. 'messageType' => 7,
  5881. 'user_id' => $bookInfo['user_id'],
  5882. ]);
  5883. }
  5884. if ($data['status'] == 1) {
  5885. $this->sendMessage([
  5886. 'talk_type' => 400,
  5887. 'title' => $bookInfo['title'],
  5888. 'content' => '提交了审核',
  5889. 'messageType' => 7,
  5890. // 'user_id'=>$bookInfo['user_id'],
  5891. ]);
  5892. }
  5893. $result = Book::where("id", $data["id"])->update($data);
  5894. if (empty($result)) {
  5895. return Result::error("更新失败", 0);
  5896. }
  5897. return Result::success($result);
  5898. }
  5899. //20250422 书刊音像
  5900. /**
  5901. * 贴身宝贝
  5902. * @param array $data
  5903. * @return array
  5904. */
  5905. public function getWebsiteTsbb(array $data): array
  5906. {
  5907. $month = $data['month'] ?? date('m');
  5908. $day = $data['day'] ?? date('d');
  5909. // 使用缓存键
  5910. $cacheKey = "tsbb_data_{$month}_{$day}";
  5911. // 尝试从缓存获取数据
  5912. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5913. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5914. if ($cachedData = $cache->get($cacheKey)) {
  5915. return Result::success(unserialize($cachedData));
  5916. }
  5917. //查询老黄历
  5918. try {
  5919. $date = date('Y-m-d');
  5920. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5921. // 使用 curl 替代 file_get_contents
  5922. $ch = curl_init();
  5923. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5924. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5925. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5926. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5927. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5928. 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');
  5929. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5930. 'Accept: application/json',
  5931. 'Content-Type: application/json',
  5932. 'Referer: https://www.36jxs.com/'
  5933. ]);
  5934. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5935. curl_setopt($ch, CURLOPT_ENCODING, '');
  5936. $almanacResponse = curl_exec($ch);
  5937. var_dump("====:", $almanacResponse);
  5938. if (curl_errno($ch)) {
  5939. var_dump('Curl error:', curl_error($ch));
  5940. throw new \Exception('Curl error: ' . curl_error($ch));
  5941. }
  5942. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5943. curl_close($ch);
  5944. if ($almanacResponse === false) {
  5945. throw new \Exception('Failed to fetch almanac data');
  5946. }
  5947. $almanacData = json_decode($almanacResponse, true);
  5948. if (json_last_error() !== JSON_ERROR_NONE) {
  5949. throw new \Exception('Failed to parse almanac data');
  5950. }
  5951. $almanacInfo = $almanacData['data'] ?? [];
  5952. } catch (\Exception $e) {
  5953. var_dump('Exception:', $e->getMessage());
  5954. $almanacInfo = [];
  5955. }
  5956. // 获取历史上的今天数据
  5957. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5958. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5959. ->orderBy('year', 'asc')
  5960. ->select("title", "id", "year", DB::raw('1 as type'))
  5961. ->limit(16)
  5962. ->get();
  5963. // 获取节日数据 - 从今天开始获取未来4条
  5964. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5965. ->orderBy('showtime', 'asc')
  5966. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5967. ->limit(16)
  5968. ->get();
  5969. //说文解字
  5970. $chartacterList = Character::orderBy('updated_at', 'desc')
  5971. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5972. ->limit(6)
  5973. ->get();
  5974. //谜语沙龙
  5975. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5976. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5977. ->limit(4)
  5978. ->get();
  5979. //成语欣赏
  5980. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5981. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5982. ->limit(32)
  5983. ->get();
  5984. //名联赏析
  5985. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5986. ->select("id", "first", "second", DB::raw('6 as type'))
  5987. ->limit(6)
  5988. ->get();
  5989. // 获取分类文章数据
  5990. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5991. ->pluck('category_id')
  5992. ->toArray();
  5993. $articlesList = [];
  5994. foreach ($categoryIds as $catid) {
  5995. // 先查有图片的
  5996. $withImg = DB::table('article')
  5997. ->where('status', 1)
  5998. ->where('catid', $catid)
  5999. ->whereNotNull('imgurl')
  6000. ->where('imgurl', '!=', '')
  6001. ->orderBy('updated_at', 'desc')
  6002. ->limit(6)
  6003. ->get();
  6004. $count = $withImg->count();
  6005. if ($count < 6) {
  6006. // 不足6条再查无图片的补足
  6007. $withoutImg = DB::table('article')
  6008. ->where('status', 1)
  6009. ->where('catid', $catid)
  6010. ->where(function ($q) {
  6011. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6012. })
  6013. ->orderBy('updated_at', 'desc')
  6014. ->limit(6 - $count)
  6015. ->get();
  6016. $articles = $withImg->concat($withoutImg);
  6017. } else {
  6018. $articles = $withImg;
  6019. }
  6020. // 组装
  6021. $category = \App\Model\Category::find($catid);
  6022. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6023. $articlesList[] = [
  6024. 'category_name' => $category ? $category->name : '',
  6025. 'catid' => $catid,
  6026. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6027. 'type' => 100,
  6028. 'list' => $articles->map(function ($item) {
  6029. return [
  6030. 'id' => $item->id,
  6031. 'title' => $item->title,
  6032. 'imgurl' => $item->imgurl,
  6033. 'created_at' => $item->created_at
  6034. ];
  6035. })->values()
  6036. ];
  6037. }
  6038. $result = [
  6039. 'almanac' => $almanacInfo,
  6040. 'historyTodayList' => [
  6041. 'category_name' => '历史上的今天',
  6042. 'list' => $historyTodayList,
  6043. 'type' => 1
  6044. ],
  6045. 'festivalList' => [
  6046. 'category_name' => '节日预告',
  6047. 'list' => $festivalList,
  6048. 'type' => 2
  6049. ],
  6050. 'chartacterList' => [
  6051. 'category_name' => '说文解字',
  6052. 'list' => $chartacterList,
  6053. 'type' => 3
  6054. ],
  6055. 'coupletList' => [
  6056. 'category_name' => '名联赏析',
  6057. 'list' => $coupletList,
  6058. 'type' => 6
  6059. ],
  6060. 'riddletList' => [
  6061. 'category_name' => '谜语沙龙',
  6062. 'list' => $riddletList,
  6063. 'type' => 4
  6064. ],
  6065. 'idiomList' => [
  6066. 'category_name' => '成语欣赏',
  6067. 'list' => $idiomList,
  6068. 'type' => 5
  6069. ],
  6070. 'articlesList' => $articlesList
  6071. ];
  6072. // 缓存结果,设置1小时过期
  6073. $cache->set($cacheKey, serialize($result), 3600);
  6074. return Result::success($result);
  6075. }
  6076. /**
  6077. * 获取资讯列表
  6078. */
  6079. public function getWebsiteTsbbList(array $data): array
  6080. {
  6081. $page = $data['page'] ?? 1;
  6082. $pageSize = $data['pageSize'] ?? 10;
  6083. // 如果没有传入月份和日期,则使用今天的日期
  6084. $month = $data['month'] ?? date('m');
  6085. $day = $data['day'] ?? date('d');
  6086. $total = 0;
  6087. $result = [];
  6088. $data['type'] = intval($data['type']);
  6089. var_dump("接收参数:", $data);
  6090. switch ($data['type']) {
  6091. case 1:
  6092. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6093. // 当前月份之后的数据
  6094. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6095. // 或者当前月份且日期大于等于当前日期的数据
  6096. ->orWhere(function ($q) use ($month, $day) {
  6097. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6098. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6099. });
  6100. })
  6101. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6102. $total = $query->count();
  6103. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6104. ->offset(($page - 1) * $pageSize)
  6105. ->limit($pageSize)
  6106. ->get();
  6107. break;
  6108. case 2:
  6109. $query = Festival::where(function ($q) use ($month, $day) {
  6110. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6111. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6112. ->orWhere(function ($q) use ($month, $day) {
  6113. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6114. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6115. });
  6116. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6117. $total = $query->count();
  6118. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6119. ->offset(($page - 1) * $pageSize)
  6120. ->limit($pageSize)
  6121. ->get();
  6122. break;
  6123. case 3:
  6124. $query = Character::orderBy("updated_at", "desc");
  6125. $total = $query->count();
  6126. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6127. ->offset(($page - 1) * $pageSize)
  6128. ->limit($pageSize)
  6129. ->get();
  6130. break;
  6131. case 4:
  6132. $query = Riddle::orderBy("updated_at", "desc");
  6133. $total = $query->count();
  6134. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6135. ->offset(($page - 1) * $pageSize)
  6136. ->limit($pageSize)
  6137. ->get();
  6138. break;
  6139. case 5:
  6140. $query = Idiom::orderBy("updated_at", "desc");
  6141. $total = $query->count();
  6142. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6143. ->offset(($page - 1) * $pageSize)
  6144. ->limit($pageSize)
  6145. ->get();
  6146. break;
  6147. case 6:
  6148. $query = Couplet::orderBy("updated_at", "desc");
  6149. $total = $query->count();
  6150. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6151. ->offset(($page - 1) * $pageSize)
  6152. ->limit($pageSize)
  6153. ->get();
  6154. break;
  6155. default:
  6156. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6157. $total = $query->count();
  6158. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6159. ->offset(($page - 1) * $pageSize)
  6160. ->limit($pageSize)
  6161. ->get();
  6162. }
  6163. return Result::success([
  6164. 'list' => $result,
  6165. 'total' => $total,
  6166. 'page' => (int)$page,
  6167. 'pageSize' => (int)$pageSize,
  6168. 'month' => $month,
  6169. 'day' => $day
  6170. ]);
  6171. }
  6172. /**
  6173. * 1:历史上的今天
  6174. * 2:节日
  6175. * 3:文章
  6176. *
  6177. * 资讯详情信息
  6178. */
  6179. public function getWebsiteTsbbDetail(array $data): array
  6180. {
  6181. $data['type'] = intval($data['type']);
  6182. switch ($data['type']) {
  6183. case 1:
  6184. $result = HistoryToday::where("id", $data['id'])->first();
  6185. break;
  6186. case 2:
  6187. $result = Festival::where("id", $data['id'])->first();
  6188. break;
  6189. case 3:
  6190. $result = Character::where("id", $data['id'])->first();
  6191. break;
  6192. case 4:
  6193. $result = Riddle::where("id", $data['id'])->first();
  6194. break;
  6195. case 5:
  6196. $result = Idiom::where("id", $data['id'])->first();
  6197. break;
  6198. case 6:
  6199. $result = Couplet::where("id", $data['id'])->first();
  6200. break;
  6201. default:
  6202. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6203. break;
  6204. }
  6205. return Result::success($result);
  6206. }
  6207. /**
  6208. * 农网导航首页数据
  6209. */
  6210. public function getWebsiteNwHomeList(array $data): array
  6211. {
  6212. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6213. ->pluck('category_id')
  6214. ->toArray();
  6215. // 使用子查询优化
  6216. $articlesList = DB::table('article')
  6217. ->select([
  6218. 'article.id',
  6219. 'article.title',
  6220. 'article.imgurl',
  6221. 'article.created_at',
  6222. 'category.name as category_name',
  6223. 'category.id as category_id',
  6224. 'website_category.aLIas_pinyin as pinyin',
  6225. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6226. DB::raw('100 as type')
  6227. ])
  6228. ->join('category', 'article.catid', '=', 'category.id')
  6229. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6230. ->leftJoin('website_category as parent_wc', function ($join) {
  6231. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6232. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6233. })
  6234. ->where('website_category.website_id', $data['website_id'])
  6235. ->where('article.status', 1)
  6236. ->whereIn('category.id', $categoryIds)
  6237. ->orderBy('article.created_at', 'desc')
  6238. ->get()
  6239. ->groupBy('category_id')
  6240. ->map(function ($group) {
  6241. // 确保第一条数据有图片
  6242. $firstWithImage = $group->first(function ($item) {
  6243. return !empty($item->imgurl);
  6244. });
  6245. if ($firstWithImage) {
  6246. // 如果有带图片的文章,将其放在第一位
  6247. $group = $group->filter(function ($item) use ($firstWithImage) {
  6248. return $item->id !== $firstWithImage->id;
  6249. })->prepend($firstWithImage);
  6250. }
  6251. return [
  6252. 'category_name' => $group->first()->category_name,
  6253. 'catid' => $group->first()->category_id,
  6254. 'pinyin' => $group->first()->pinyin,
  6255. 'parent_pinyin' => $group->first()->parent_pinyin,
  6256. 'list' => $group->take(4)->map(function ($item) {
  6257. return [
  6258. 'id' => $item->id,
  6259. 'title' => $item->title,
  6260. ];
  6261. })->values()
  6262. ];
  6263. })
  6264. ->values()
  6265. ->toArray();
  6266. return Result::success($articlesList);
  6267. }
  6268. /**
  6269. * 企业管理
  6270. * @param array $data
  6271. * @return array
  6272. */
  6273. public function getCompanyList(array $data): array
  6274. {
  6275. // return Result::success($data);
  6276. $where = [];
  6277. $user = User::where('id', $data['user_id'])->first();
  6278. if (empty($user)) {
  6279. return Result::error('用户不存在!');
  6280. }
  6281. if ($user['type_id'] != 10000) {
  6282. $where['user_id'] = $data['user_id'];
  6283. }
  6284. if (isset($data['title']) && !empty($data['title'])) {
  6285. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6286. }
  6287. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6288. array_push($where, ['website.id', $data['website_id']]);
  6289. }
  6290. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6291. if ($data['ischeck'] == 1) {
  6292. if (isset($data['status']) && $data['status'] != '') {
  6293. array_push($where, ['company.status', $data['status']]);
  6294. $query = Company::where($where);
  6295. } else {
  6296. $query = Company::whereIn('company.status', [0, 2]);
  6297. }
  6298. } else {
  6299. $query = Company::where('company.status', 1);
  6300. }
  6301. }
  6302. $result = $query->where($where)
  6303. ->leftJoin('website_category', function ($query) {
  6304. $query->on('website_category.category_id', '=', 'company.category_id')
  6305. ->on('website_category.website_id', '=', 'company.website_id');
  6306. })
  6307. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6308. ->select(
  6309. 'company.id',
  6310. 'company.title',
  6311. 'company.website_id',
  6312. 'company.category_id',
  6313. 'website.website_name',
  6314. 'website_category.alias as category_name',
  6315. 'company.status',
  6316. 'company.updated_at',
  6317. 'company.user_id'
  6318. )
  6319. ->orderBy('company.updated_at', 'desc')
  6320. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6321. if ($result->isEmpty()) {
  6322. return Result::error("暂无企业", 0);
  6323. }
  6324. return Result::success($result);
  6325. }
  6326. /**
  6327. * 添加企业
  6328. * @param array $data
  6329. * @return array
  6330. */
  6331. public function addCompany(array $data): array
  6332. {
  6333. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6334. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6335. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6336. $data['cat_arr_id'] = json_encode($car_arr_id);
  6337. } else {
  6338. $data['cat_arr_id'] = '';
  6339. }
  6340. if ($data['imgurl'] == '') {
  6341. //content中提取图片第一个图,正则提取
  6342. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6343. preg_match_all($reg, $data['content'], $matches);
  6344. if (isset($matches[1][0])) {
  6345. //截取varchar240
  6346. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6347. }
  6348. }
  6349. if ($data['keyword'] == '') {
  6350. //提取标题+内容中的关键词
  6351. $data['keyword'] = $data['title'];
  6352. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6353. Jieba::init(); // 初始化 jieba-php
  6354. Finalseg::init();
  6355. $segList = Jieba::cut($data['keyword']);
  6356. $segList1 = array_slice($segList, 0, 8);
  6357. $data['keyword'] = implode(',', $segList1);
  6358. }
  6359. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6360. //提取内容中的描述
  6361. $content = $data['content'];
  6362. // 去除 <style> 和 <script> 标签及其内容
  6363. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6364. // 去除所有 HTML 标签
  6365. $content = strip_tags($content);
  6366. // 去除 HTML 实体
  6367. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6368. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6369. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6370. // 去除多余空白
  6371. $content = preg_replace('/\s+/u', '', $content);
  6372. // 截取 100 个字符
  6373. $data['introduce'] = mb_substr($content, 0, 100);
  6374. }
  6375. $user = User::where('id', $data['user_id'])->first();
  6376. if (empty($user)) {
  6377. return Result::error('用户不存在!');
  6378. }
  6379. if ($user['type_id'] == 10000) {
  6380. $data['status'] = 1;
  6381. }
  6382. if (isset($data['level']) && $data['level'] != null) {
  6383. $data['level'] = intval($data['level']);
  6384. } else {
  6385. $data['level'] = null;
  6386. }
  6387. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6388. $this->sendMessage([
  6389. 'talk_type' => 900,
  6390. 'title' => $data['title'],
  6391. 'content' => '提交了审核',
  6392. 'messageType' => 8,
  6393. ]);
  6394. }
  6395. $result = Company::insertGetId($data);
  6396. if ($result) {
  6397. return Result::success($result);
  6398. } else {
  6399. return Result::error('添加失败');
  6400. }
  6401. }
  6402. /**
  6403. * 更新企业
  6404. * @param array $data
  6405. * @return array
  6406. */
  6407. public function upCompany(array $data): array
  6408. {
  6409. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6410. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6411. $data['cat_arr_id'] = json_encode($car_arr_id);
  6412. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6413. } else {
  6414. $data['cat_arr_id'] = '';
  6415. }
  6416. if ($data['imgurl'] == '') {
  6417. //content中提取图片第一个图,正则提取
  6418. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6419. preg_match_all($reg, $data['content'], $matches);
  6420. if (isset($matches[1][0])) {
  6421. //截取varchar
  6422. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6423. }
  6424. }
  6425. if ($data['keyword'] == '') {
  6426. //提取标题+内容中的关键词
  6427. $data['keyword'] = $data['title'];
  6428. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6429. Jieba::init(); // 初始化 jieba-php
  6430. Finalseg::init();
  6431. $segList = Jieba::cut($data['keyword']);
  6432. $segList1 = array_slice($segList, 0, 8);
  6433. $data['keyword'] = implode(',', $segList1);
  6434. }
  6435. if ($data['introduce'] == '') {
  6436. //提取内容中的描述
  6437. $content = $data['content'];
  6438. // 去除 <style> 和 <script> 标签及其内容
  6439. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6440. // 去除所有 HTML 标签
  6441. $content = strip_tags($content);
  6442. // 去除 HTML 实体
  6443. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6444. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6445. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6446. // 去除多余空白
  6447. $content = preg_replace('/\s+/u', '', $content);
  6448. // 截取 100 个字符
  6449. $data['introduce'] = mb_substr($content, 0, 100);
  6450. }
  6451. if (isset($data['level']) && $data['level'] != null) {
  6452. $data['level'] = intval($data['level']);
  6453. } else {
  6454. $data['level'] = null;
  6455. }
  6456. $user = User::where('id', $data['user_id'])->first();
  6457. if (empty($user)) {
  6458. return Result::error('用户不存在!');
  6459. }
  6460. if ($user['type_id'] == 10000) {
  6461. $data['status'] = 1;
  6462. } else {
  6463. $data['status'] = 0;
  6464. }
  6465. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6466. $this->sendMessage([
  6467. 'talk_type' => 900,
  6468. 'title' => $data['title'],
  6469. 'content' => '提交了审核',
  6470. 'messageType' => 8,
  6471. ]);
  6472. }
  6473. $result = Company::where('id', $data['id'])->update($data);
  6474. if ($result) {
  6475. return Result::success($result);
  6476. } else {
  6477. return Result::error('修改失败');
  6478. }
  6479. }
  6480. /**
  6481. * 删除企业
  6482. * @param array $data
  6483. * @return array
  6484. */
  6485. public function delCompany(array $data): array
  6486. {
  6487. $result = Company::where('id', $data['id'])->delete();
  6488. if ($result) {
  6489. return Result::success($result);
  6490. } else {
  6491. return Result::error('删除失败');
  6492. }
  6493. }
  6494. /**
  6495. * 审核企业
  6496. * @param array $data
  6497. * @return array
  6498. */
  6499. public function checkCompany(array $data): array
  6500. {
  6501. $user = User::where('id', $data['user_id'])->first();
  6502. if (empty($user)) {
  6503. return Result::error('用户不存在!');
  6504. }
  6505. $company = Company::where('id', $data['id'])->first();
  6506. if (empty($company)) {
  6507. return Result::error('企业不存在!');
  6508. }
  6509. // 状态:0:未审核 1:已审核 2:已拒绝
  6510. if ($data['status'] == 2 || $data['status'] == '2') {
  6511. $this->sendMessage([
  6512. 'talk_type' => 901,
  6513. 'title' => $company['title'],
  6514. 'content' => '审核拒绝',
  6515. 'messageType' => 8,
  6516. 'user_id' => $company['user_id'],
  6517. ]);
  6518. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6519. } else {
  6520. if ($data['status'] == 1) {
  6521. $this->sendMessage([
  6522. 'talk_type' => 901,
  6523. 'title' => $company['title'],
  6524. 'content' => '审核通过',
  6525. 'messageType' => 8,
  6526. 'user_id' => $company['user_id'],
  6527. ]);
  6528. } else if ($data['status'] == 0) {
  6529. $this->sendMessage([
  6530. 'talk_type' => 900,
  6531. 'title' => $company['title'],
  6532. 'content' => '提交了审核',
  6533. 'messageType' => 8,
  6534. ]);
  6535. }
  6536. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6537. }
  6538. if (empty($result)) {
  6539. return Result::error('审核失败!');
  6540. } else {
  6541. return Result::success($result);
  6542. }
  6543. }
  6544. /**
  6545. * 获取企业信息
  6546. * @param array $data
  6547. * @return array
  6548. */
  6549. public function getCompanyInfo(array $data): array
  6550. {
  6551. $result = Company::where('id', $data['id'])->first();
  6552. $city_arr = json_decode($result['city_arr_id']);
  6553. $result['city_name'] = District::whereIn('id', $city_arr)
  6554. ->pluck('name')
  6555. ->implode('-');
  6556. if (empty($result)) {
  6557. return Result::error('企业不存在!');
  6558. } else {
  6559. return Result::success($result);
  6560. }
  6561. }
  6562. /**
  6563. * @param array $data
  6564. * @return array
  6565. */
  6566. public function getWebsiteCompany(array $data): array
  6567. {
  6568. $categorys = json_decode($data['id'], true);
  6569. $category_arr = $this->processArticlePro($data['website_id']);
  6570. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6571. $catiall = $category_arr['catiall'];
  6572. $categoryIds = $category_arr['categoryIds'];
  6573. // return Result::success($category_arr);
  6574. foreach ($categorys as $key => $value) {
  6575. if (array_key_exists('level', $value)) {
  6576. $parts = explode(',', $value['level']);
  6577. $level = $parts[0] ?? null;
  6578. $imgnum = $parts[1] ?? null;
  6579. $textnum = $parts[2] ?? null;
  6580. if (!empty($textnum) && $textnum > 0) {
  6581. $text_num = Company::where('level', $level)
  6582. ->whereIn('category_id', $categoryIds)
  6583. ->where('status', 1)
  6584. ->select(
  6585. 'company.id',
  6586. 'company.title',
  6587. 'company.description',
  6588. 'company.updated_at',
  6589. 'company.category_id',
  6590. 'company.cat_arr_id'
  6591. )
  6592. ->orderBy('updated_at', 'desc')
  6593. ->limit($textnum)
  6594. ->get()->all();
  6595. }
  6596. if (!empty($imgnum) && $imgnum > 0) {
  6597. $img_num = Company::where('level', $level)
  6598. ->whereIn('category_id', $categoryIds)
  6599. ->where('status', 1)
  6600. ->where('imgurl', '!=', '')
  6601. ->whereNotNull('imgurl')
  6602. ->select(
  6603. 'company.id',
  6604. 'company.title',
  6605. 'company.description',
  6606. 'company.updated_at',
  6607. 'company.imgurl as imgs',
  6608. 'company.category_id',
  6609. 'company.cat_arr_id'
  6610. )
  6611. ->orderBy('updated_at', 'desc')
  6612. ->limit($imgnum)
  6613. ->get()->all();
  6614. }
  6615. }
  6616. if (array_key_exists('id', $value)) {
  6617. $parts = explode(',', $value['id']);
  6618. $category_id = $parts[0] ?? null;
  6619. $imgnum = $parts[1] ?? null;
  6620. $textnum = $parts[2] ?? null;
  6621. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6622. if (!empty($textnum) && $textnum > 0) {
  6623. $text_num = Company::whereIn('category_id', $category_arr)
  6624. // ->where('website_id', $data['website_id'])
  6625. ->where('status', 1)
  6626. ->select(
  6627. 'company.id',
  6628. 'company.title',
  6629. 'company.description',
  6630. 'company.updated_at',
  6631. 'company.category_id',
  6632. 'company.cat_arr_id'
  6633. )
  6634. ->orderBy('updated_at', 'desc')
  6635. ->limit($textnum)
  6636. ->get()->all();
  6637. }
  6638. if (!empty($imgnum) && $imgnum > 0) {
  6639. $img_num = Company::whereIn('category_id', $category_arr)
  6640. // ->where('website_id', $data['website_id'])
  6641. ->where('status', 1)
  6642. ->where('imgurl', '!=', '')
  6643. ->whereNotNull('imgurl')
  6644. ->select(
  6645. 'company.id',
  6646. 'company.title',
  6647. 'company.description',
  6648. 'company.updated_at',
  6649. 'company.imgurl as imgs',
  6650. 'company.category_id',
  6651. 'company.cat_arr_id'
  6652. )
  6653. ->orderBy('updated_at', 'desc')
  6654. ->limit($imgnum)
  6655. ->get()->all();
  6656. }
  6657. }
  6658. if (!empty($text_num)) {
  6659. foreach ($text_num as $k => $v) {
  6660. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6661. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6662. }
  6663. }
  6664. if (!empty($img_num)) {
  6665. foreach ($img_num as $k => $v) {
  6666. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6667. $imgurl = json_decode($v['imgs'], true);
  6668. if (!empty($imgurl)) {
  6669. $img_num[$k]->imgurl = $imgurl[0];
  6670. }
  6671. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6672. }
  6673. }
  6674. $company[$key]['img_num'] = $img_num ?? [];
  6675. $company[$key]['text_num'] = $text_num ?? [];
  6676. }
  6677. if (empty($company)) {
  6678. return Result::error("暂无相关企业信息", 0);
  6679. }
  6680. return Result::success($company);
  6681. }
  6682. /**
  6683. * @param array $data
  6684. * @return array
  6685. */
  6686. public function getWebsiteCompanyList(array $data): array
  6687. {
  6688. $where['website_id'] = $data['website_id'];
  6689. $where['status'] = 1;
  6690. $categoryIds = [];
  6691. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6692. $category_id = $data['category_id'];
  6693. }
  6694. $category_arr = $this->processArticlePro($data['website_id']);
  6695. $categoryIds = $category_arr['categoryIds'];
  6696. // return Result::success($cat_1st_arr);
  6697. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  6698. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  6699. })
  6700. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  6701. $query->whereIn('category_id', $categoryIds);
  6702. })
  6703. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  6704. $query->where('category_id', $category_id);
  6705. })
  6706. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6707. ->orderBy('updated_at', 'desc')
  6708. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6709. if (empty($company)) {
  6710. return Result::error("暂无相关公司信息", 0);
  6711. }
  6712. $result = [
  6713. 'count' => $company->total(),
  6714. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  6715. ];
  6716. return Result::success($result);
  6717. }
  6718. /**
  6719. * 获取项目列表
  6720. * @param array $data
  6721. * @return array
  6722. */
  6723. public function getProjectList(array $data): array
  6724. {
  6725. $where = [];
  6726. $user = User::where('id', $data['user_id'])->first();
  6727. if (empty($user)) {
  6728. return Result::error('用户不存在!');
  6729. }
  6730. if ($user->type_id != 10000) {
  6731. array_push($where, ['project.user_id', $data['user_id']]);
  6732. }
  6733. $query = Project::query();
  6734. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6735. array_push($where, ['project.website_id', $data['website_id']]);
  6736. }
  6737. if (isset($data['title']) && !empty($data['title'])) {
  6738. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6739. }
  6740. if ($data['status'] != 3) {
  6741. array_push($where, ['project.status', $data['status']]);
  6742. }
  6743. $query = Project::where($where)
  6744. ->when($data['status'] == 3, function ($query) {
  6745. $query->whereIn('project.status', [0, 2]);
  6746. });
  6747. $count = $query->clone()
  6748. ->count();
  6749. $rows = $query->clone()
  6750. ->leftJoin('website', 'project.website_id', 'website.id')
  6751. ->leftJoin('website_category', function ($join) {
  6752. $join->on('project.website_id', '=', 'website_category.website_id')
  6753. ->on('project.category_id', '=', 'website_category.category_id');
  6754. })
  6755. ->select(
  6756. 'project.id',
  6757. 'project.title',
  6758. 'project.updated_at',
  6759. 'project.status',
  6760. 'website.website_name',
  6761. 'website_category.alias as category_name',
  6762. 'project.website_id',
  6763. 'project.user_id'
  6764. )
  6765. ->orderBy('project.updated_at', 'desc')
  6766. ->offset(($data['page'] - 1) * $data['pageSize'])
  6767. ->limit($data['pageSize'])
  6768. ->get();
  6769. if ($rows->isEmpty()) {
  6770. return Result::error("暂无相关项目信息", 0);
  6771. }
  6772. $result = [
  6773. 'count' => $count,
  6774. 'rows' => $rows,
  6775. ];
  6776. return Result::success($result);
  6777. }
  6778. /**
  6779. * 添加项目
  6780. * @param array $data
  6781. * @return array
  6782. */
  6783. public function addProject(array $data): array
  6784. {
  6785. $user = User::where('id', $data['user_id'])->first();
  6786. if (empty($user)) {
  6787. return Result::error("暂无相关用户信息", 0);
  6788. }
  6789. if ($user->type_id == 10000) {
  6790. $data['status'] = 1;
  6791. } else {
  6792. $data['status'] = 0;
  6793. }
  6794. if ($data['keyword'] == '') {
  6795. //提取标题+内容中的关键词
  6796. $data['keyword'] = $data['title'];
  6797. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6798. Jieba::init(); // 初始化 jieba-php
  6799. Finalseg::init();
  6800. $segList = Jieba::cut($data['keyword']);
  6801. $segList1 = array_slice($segList, 0, 8);
  6802. $data['keyword'] = implode(',', $segList1);
  6803. }
  6804. if ($data['description'] == '') {
  6805. //提取内容中的描述
  6806. // var_dump(11111);
  6807. //提取内容中的描述
  6808. $content = $data['introduce'];
  6809. // 去除 <style> 和 <script> 标签及其内容
  6810. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6811. // 去除所有 HTML 标签
  6812. $content = strip_tags($content);
  6813. // 去除 HTML 实体
  6814. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6815. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6816. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6817. // 去除多余空白
  6818. $content = preg_replace('/\s+/u', '', $content);
  6819. // 截取 100 个字符
  6820. $data['description'] = mb_substr($content, 0, 100);
  6821. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6822. }
  6823. if ($data['status'] == 0) {
  6824. $this->sendMessage([
  6825. 'talk_type' => 1000,
  6826. 'title' => $data['title'],
  6827. 'content' => '提交了审核',
  6828. 'messageType' => 9,
  6829. ]);
  6830. }
  6831. $project = Project::insertGetId($data);
  6832. if (empty($project)) {
  6833. return Result::error("暂无相关项目信息", 0);
  6834. }
  6835. return Result::success($project);
  6836. }
  6837. /**
  6838. * 更新项目
  6839. * @param array $data
  6840. * @return array
  6841. */
  6842. public function upProject(array $data): array
  6843. {
  6844. $project = Project::where('id', $data['id'])->first();
  6845. if (empty($project)) {
  6846. return Result::error("暂无相关项目信息", 0);
  6847. }
  6848. $id = $data['id'];
  6849. unset($data['id']);
  6850. $user = User::where('id', $data['user_id'])->first();
  6851. if (empty($user)) {
  6852. return Result::error("暂无相关用户信息", 0);
  6853. }
  6854. if ($user->type_id == 10000) {
  6855. $data['status'] = 1;
  6856. } else {
  6857. $data['status'] = 0;
  6858. }
  6859. unset($data['user_id']);
  6860. if ($data['keyword'] == '') {
  6861. //提取标题+内容中的关键词
  6862. $data['keyword'] = $data['title'];
  6863. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6864. Jieba::init(); // 初始化 jieba-php
  6865. Finalseg::init();
  6866. $segList = Jieba::cut($data['keyword']);
  6867. $segList1 = array_slice($segList, 0, 8);
  6868. $data['keyword'] = implode(',', $segList1);
  6869. }
  6870. if ($data['description'] == '') {
  6871. //提取内容中的描述
  6872. // var_dump(11111);
  6873. //提取内容中的描述
  6874. $content = $data['introduce'];
  6875. // 去除 <style> 和 <script> 标签及其内容
  6876. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6877. // 去除所有 HTML 标签
  6878. $content = strip_tags($content);
  6879. // 去除 HTML 实体
  6880. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6881. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6882. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6883. // 去除多余空白
  6884. $content = preg_replace('/\s+/u', '', $content);
  6885. // 截取 100 个字符
  6886. $data['description'] = mb_substr($content, 0, 100);
  6887. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6888. }
  6889. if ($data['status'] == 0) {
  6890. $this->sendMessage([
  6891. 'talk_type' => 1000,
  6892. 'title' => $data['title'],
  6893. 'content' => '提交了审核',
  6894. 'messageType' => 9,
  6895. ]);
  6896. }
  6897. $result = Project::where('id', $id)->update($data);
  6898. if (empty($result)) {
  6899. return Result::error("更新失败", 0);
  6900. }
  6901. return Result::success($result);
  6902. }
  6903. /**
  6904. * 删除项目
  6905. * @param array $data
  6906. * @return array
  6907. */
  6908. public function delProject(array $data): array
  6909. {
  6910. $user = User::where('id', $data['user_id'])->first();
  6911. if (empty($user)) {
  6912. return Result::error("暂无相关用户信息", 0);
  6913. }
  6914. $project = Project::where('id', $data['id'])->first();
  6915. if (empty($project)) {
  6916. return Result::error("暂无相关项目信息", 0);
  6917. }
  6918. $result = Project::where('id', $data['id'])->delete();
  6919. if (empty($result)) {
  6920. return Result::error("删除失败", 0);
  6921. }
  6922. return Result::success($result);
  6923. }
  6924. /**
  6925. * 审核项目
  6926. * @param array $data
  6927. * @return array
  6928. */
  6929. public function checkProject(array $data): array
  6930. {
  6931. $user = User::where('id', $data['user_id'])->first();
  6932. if (empty($user)) {
  6933. return Result::error("暂无相关用户信息", 0);
  6934. }
  6935. // 0:未审核; 1:已审核; 2:已拒绝;
  6936. if ($user->type_id != 10000) {
  6937. if ($data['status'] == 1 || $data['status'] == 2) {
  6938. return Result::error("此用户权限不足", 0);
  6939. }
  6940. }
  6941. $project = Project::where('id', $data['id'])->first();
  6942. if (empty($project)) {
  6943. return Result::error("暂无相关项目信息", 0);
  6944. }
  6945. if ($data['status'] == 2) {
  6946. $this->sendMessage([
  6947. 'talk_type' => 1001,
  6948. 'title' => $project['title'],
  6949. 'content' => '审核拒绝',
  6950. 'messageType' => 9,
  6951. 'user_id' => $project['user_id'],
  6952. ]);
  6953. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  6954. } else {
  6955. if ($data['status'] == 1) {
  6956. $this->sendMessage([
  6957. 'talk_type' => 1001,
  6958. 'title' => $project['title'],
  6959. 'content' => '审核通过',
  6960. 'messageType' => 9,
  6961. 'user_id' => $project['user_id'],
  6962. ]);
  6963. } else if ($data['status'] == 0) {
  6964. $this->sendMessage([
  6965. 'talk_type' => 1000,
  6966. 'title' => $project['title'],
  6967. 'content' => '提交了审核',
  6968. 'messageType' => 9,
  6969. ]);
  6970. }
  6971. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  6972. }
  6973. if (empty($result)) {
  6974. return Result::error("审核失败", 0);
  6975. }
  6976. return Result::success($result);
  6977. }
  6978. /**
  6979. * 获取项目详情
  6980. * @param array $data
  6981. * @return array
  6982. */
  6983. public function getProjectInfo(array $data): array
  6984. {
  6985. $project = Project::where('id', $data['id'])->first();
  6986. if (empty($project)) {
  6987. return Result::error("暂无相关项目信息", 0);
  6988. }
  6989. return Result::success($project);
  6990. }
  6991. public function getWebsiteCompanyInfo(array $data): array
  6992. {
  6993. $company = Company::where('id', $data['id'])
  6994. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  6995. ->where('status', 1)
  6996. // ->where('website_id', $data['website_id'])
  6997. ->select('company.*', 'job_industry.hyname as hy_name')
  6998. ->first();
  6999. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7000. switch ($company->jobnature_id) {
  7001. case null:
  7002. $company->jobnature_name = '';
  7003. break;
  7004. case 0:
  7005. $company->jobnature_name = '市场监督';
  7006. break;
  7007. case 1:
  7008. $company->jobnature_name = '信访纪检';
  7009. break;
  7010. case 2:
  7011. $company->jobnature_name = '公检法司';
  7012. break;
  7013. case 3:
  7014. $company->jobnature_name = '高关注机构';
  7015. break;
  7016. default:
  7017. $company->jobnature_name = '';
  7018. break;
  7019. }
  7020. $city_arr = $company->city_arr_id;
  7021. if (!empty($city_arr)) {
  7022. $city_arr = json_decode($city_arr, true);
  7023. $cityNames = District::whereIn('id', $city_arr)
  7024. ->pluck('name')
  7025. ->implode('-');
  7026. $company->city_name = $cityNames;
  7027. } else {
  7028. $company->city_name = '';
  7029. }
  7030. if (empty($company)) {
  7031. return Result::error("暂无相关公司信息", 0);
  7032. }
  7033. return Result::success($company);
  7034. }
  7035. public function getMSG(array $data): array
  7036. {
  7037. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7038. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7039. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7040. $result = [];
  7041. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7042. //最近的5篇已审的文章
  7043. $apply_articale = Article::where('status', 1)
  7044. ->where('admin_user_id', $user_id)
  7045. ->orderBy('updated_at', 'desc')
  7046. // ->limit(5)
  7047. ->get();
  7048. //获取5条用户的已审核商品
  7049. $good = Good::where('status', 2)
  7050. ->where('user_id', $user_id)
  7051. ->orderBy('updated_at', 'desc')
  7052. // ->limit(5)
  7053. ->get();
  7054. //获取5条用户待审核的公告
  7055. $notice = Notice::where('status', 2)
  7056. ->where('user_id', $user_id)
  7057. ->orderBy('updated_at', 'desc')
  7058. ->limit(5)->get();
  7059. //获取5条用户的待审核投诉
  7060. $complaint = Complaint::where('status', 2)
  7061. ->where('user_id', $user_id)
  7062. ->orderBy('updated_at', 'desc')
  7063. // ->limit(5)
  7064. ->get();
  7065. //获取5条用户的book
  7066. $book = Book::where('status', 2)
  7067. ->where('user_id', $user_id)
  7068. ->orderBy('updated_at', 'desc')
  7069. // ->limit(5)
  7070. ->get();
  7071. //获取5条用户的求职
  7072. //获取5条用户的求职 1
  7073. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7074. ->where('job_hunting.user_id', $user_id)
  7075. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7076. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7077. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7078. ->orderBy('updated_at', 'desc')
  7079. // ->limit(5)
  7080. ->get();
  7081. //获取5条用户的求职 2
  7082. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7083. ->where('job_recruiting.user_id', $user_id)
  7084. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7085. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7086. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7087. ->orderBy('updated_at', 'desc')
  7088. // ->limit(5)
  7089. ->get();
  7090. //人才库 1
  7091. $job_apply = JobApply::where('job_apply.status', 1)
  7092. ->where('job_apply.receiver_id', $user_id)
  7093. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7094. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7095. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7096. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7097. ->select('job_recruiting', 'job_recruiting.', '', '')
  7098. ->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')
  7099. ->orderBy('updated_at', 'desc')
  7100. // ->limit(5)
  7101. ->get();
  7102. // 职场机会 2
  7103. $job_resume = JobResume::where('job_resume.status', 1)
  7104. ->where('job_resume.receiver_id', $user_id)
  7105. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7106. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7107. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7108. ->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')
  7109. ->orderBy('updated_at', 'desc')
  7110. // ->limit(5)
  7111. ->get();
  7112. //获取5条用户待处理的投诉
  7113. $complaint_deal = Complaint::where('status', 2)
  7114. ->where('deal', 1)
  7115. ->whereJsonContains('re_user_ids', $user_id)
  7116. ->orderBy('updated_at', 'desc')
  7117. // ->limit(5)
  7118. ->get();
  7119. //获取 被通知者未读信息
  7120. $notice_unread = Notice::where('status', 2)
  7121. ->whereJsonContains('re_user_ids', $user_id)
  7122. //未读消息
  7123. ->where(function ($query) use ($user_id) {
  7124. $query->whereJsonDoesntContain('read_id', $user_id)
  7125. ->orWhereNull('read_id');
  7126. })
  7127. ->orderBy('updated_at', 'desc')
  7128. ->get();
  7129. $complaint_unread = Complaint::where('status', 2)
  7130. ->whereJsonContains('re_user_ids', $user_id)
  7131. //未读消息
  7132. ->where(function ($query) use ($user_id) {
  7133. $query->whereJsonDoesntContain('read_id', $user_id)
  7134. ->orWhereNull('read_id');
  7135. })
  7136. ->orderBy('updated_at', 'desc')
  7137. ->get();
  7138. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7139. $complany = Company::where('status', 1)
  7140. ->where('user_id', $user_id)
  7141. ->orderBy('updated_at', 'desc')
  7142. // ->limit(5)
  7143. ->get();
  7144. //获取5条单聊未读聊天消息
  7145. // $chat = ChatRecords::where('is_read', 0)
  7146. // ->where('user_id', $user_id)
  7147. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7148. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7149. // ->where('action', 'recieved')
  7150. // ->where('talk_type', 1)
  7151. // ->orderBy('created_at', 'desc')
  7152. // // ->limit(5)
  7153. // ->get();
  7154. //获取5条未读群聊信息
  7155. // $chat_group = ChatRecords::where('is_read', 0)
  7156. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7157. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7158. // ->where('user_id', $user_id)
  7159. // ->where('talk_type', 2)
  7160. // ->orderBy('created_at', 'desc')
  7161. // // ->limit(5)
  7162. // ->get();
  7163. //获取5条用户的待审核项目
  7164. $project = Project::where('status', 1)
  7165. ->where('user_id', $user_id)
  7166. ->orderBy('updated_at', 'desc')
  7167. // ->limit(5)
  7168. ->get();
  7169. // count($chat) + count($chat_group) +
  7170. $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)
  7171. + count($complany)
  7172. + count($project)
  7173. + count($notice_unread)
  7174. + count($complaint_unread)
  7175. // + count($chat) + count($chat_group)
  7176. ;
  7177. $result = [
  7178. 'apply_articale' => $apply_articale,
  7179. // 'chat' => $chat,
  7180. // 'chat_group' => $chat_group,
  7181. 'good' => $good,
  7182. 'notice' => $notice,
  7183. 'complaint' => $complaint,
  7184. 'book' => $book,
  7185. 'job_hunting' => $job_hunting,
  7186. 'job_recruiting' => $job_recruiting,
  7187. 'job_apply' => $job_apply,
  7188. 'job_resume' => $job_resume,
  7189. 'complaint_deal' => $complaint_deal,
  7190. 'complany' => $complany,
  7191. 'project' => $project,
  7192. 'notice_unread' => $notice_unread,
  7193. 'complaint_unread' => $complaint_unread,
  7194. 'count' => $count,
  7195. ];
  7196. } elseif ($type_id == 12) {
  7197. //最近的5篇已审的文章
  7198. $apply_articale = Article::where('status', 1)
  7199. ->where('admin_user_id', $user_id)
  7200. ->limit(5)->get();
  7201. //获取5条单聊未读聊天消息
  7202. $chat = ChatRecords::where('is_read', 0)
  7203. ->where('user_id', $user_id)
  7204. ->where('talk_type', 1)
  7205. ->orderBy('created_at', 'desc')
  7206. ->limit(5)->get();
  7207. //获取5条未读群聊信息
  7208. $chat_group = ChatRecords::where('is_read', 0)
  7209. ->where('user_id', $user_id)
  7210. ->where('talk_type', 2)
  7211. ->orderBy('created_at', 'desc')
  7212. ->limit(5)->get();
  7213. //获取5条用户的已审核商品
  7214. $good = Good::where('status', 2)
  7215. ->where('user_id', $user_id)
  7216. ->orderBy('updated_at', 'desc')
  7217. ->limit(5)->get();
  7218. //获取5条用户的book
  7219. $book = Book::where('status', 2)
  7220. ->where('user_id', $user_id)
  7221. ->orderBy('updated_at', 'desc')
  7222. ->limit(5)->get();
  7223. //获取5条用户的求职
  7224. //获取5条用户的求职 1
  7225. //count($chat) + count($chat_group)
  7226. $count = count($apply_articale) + count($good);
  7227. $result = [
  7228. 'apply_articale' => $apply_articale,
  7229. 'chat' => $chat,
  7230. 'chat_group' => $chat_group,
  7231. 'good' => $good,
  7232. 'book' => $book,
  7233. 'count' => $count,
  7234. ];
  7235. } elseif ($type_id == 13) {
  7236. //最近的5篇已审的文章
  7237. $apply_articale = Article::where('status', 1)
  7238. ->where('admin_user_id', $user_id)
  7239. ->limit(5)->get();
  7240. //获取5条单聊未读聊天消息
  7241. $chat = ChatRecords::where('is_read', 0)
  7242. ->where('user_id', $user_id)
  7243. ->where('talk_type', 1)
  7244. ->orderBy('created_at', 'desc')
  7245. ->limit(5)->get();
  7246. //获取5条未读群聊信息
  7247. $chat_group = ChatRecords::where('is_read', 0)
  7248. ->where('user_id', $user_id)
  7249. ->where('talk_type', 2)
  7250. ->orderBy('created_at', 'desc')
  7251. ->limit(5)->get();
  7252. //获取5条用户的已审核商品
  7253. $good = Good::where('status', 2)
  7254. ->where('user_id', $user_id)
  7255. ->orderBy('updated_at', 'desc')
  7256. ->limit(5)->get();
  7257. //count($chat) + count($chat_group) +
  7258. $count = count($apply_articale) + count($good);
  7259. $result = [
  7260. 'apply_articale' => $apply_articale,
  7261. 'chat' => $chat,
  7262. 'chat_group' => $chat_group,
  7263. 'good' => $good,
  7264. 'count' => $count,
  7265. ];
  7266. } elseif ($type_id == 14) {
  7267. //最近的5篇已审的文章
  7268. $apply_articale = Article::where('status', 1)
  7269. ->where('admin_user_id', $user_id)
  7270. // ->limit(5)
  7271. ->get();
  7272. //获取5条用户的已审核商品
  7273. $good = Good::where('status', 2)
  7274. ->where('user_id', $user_id)
  7275. ->orderBy('updated_at', 'desc')
  7276. // ->limit(5)
  7277. ->get();
  7278. $count = count($apply_articale) + count($good);
  7279. $result = [
  7280. 'apply_articale' => $apply_articale,
  7281. 'chat' => '',
  7282. 'chat_group' => '',
  7283. 'good' => $good,
  7284. 'count' => $count,
  7285. ];
  7286. } elseif ($type_id == 10000) {
  7287. //获取未审核的5篇文章
  7288. $apply_articale = Article::where('status', 0)
  7289. ->orderBy('updated_at', 'desc')
  7290. // ->limit(5)
  7291. ->get();
  7292. //获取5条单聊未读聊天消息
  7293. //获取5条单聊未读聊天消息
  7294. // $chat = ChatRecords::where('is_read', 0)
  7295. // ->where('user_id', $user_id)
  7296. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7297. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7298. // ->where('action', 'recieved')
  7299. // ->where('talk_type', 1)
  7300. // ->orderBy('created_at', 'desc')
  7301. // // ->limit(5)
  7302. // ->get();
  7303. // //获取5条未读群聊信息
  7304. // $chat_group = ChatRecords::where('is_read', 0)
  7305. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7306. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7307. // ->where('user_id', $user_id)
  7308. // ->where('talk_type', 2)
  7309. // ->orderBy('created_at', 'desc')
  7310. // // ->limit(5)
  7311. // ->get();
  7312. //获取5条用户的已审核商品
  7313. $good = Good::where('status', 1)
  7314. // ->where('user_id', $user_id)
  7315. ->orderBy('updated_at', 'desc')
  7316. // ->limit(5)
  7317. ->get();
  7318. //获取5条用户待审核的公告
  7319. $notice = Notice::where('status', 1)
  7320. ->orderBy('updated_at', 'desc')
  7321. // ->limit(5)
  7322. ->get();
  7323. //获取5条用户的待审核投诉
  7324. $complaint = Complaint::where('status', 1)
  7325. ->orderBy('updated_at', 'desc')
  7326. // ->limit(5)
  7327. ->get();
  7328. //获取5条用户的book
  7329. $book = Book::where('status', 1)
  7330. ->orderBy('updated_at', 'desc')
  7331. // ->limit(5)
  7332. ->get();
  7333. //获取5条用户的求职 1
  7334. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7335. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7336. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7337. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7338. ->orderBy('updated_at', 'desc')
  7339. // ->limit(5)
  7340. ->get();
  7341. //获取5条用户的求职 2
  7342. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7343. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7344. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7345. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7346. ->orderBy('updated_at', 'desc')
  7347. // ->limit(5)
  7348. ->get();
  7349. //人才库 1
  7350. $job_apply = JobApply::where('job_apply.status', 1)
  7351. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7352. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7353. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7354. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7355. ->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')
  7356. ->orderBy('updated_at', 'desc')
  7357. // ->limit(5)
  7358. ->get();
  7359. // 职场机会 2
  7360. $job_resume = JobResume::where('job_resume.status', 1)
  7361. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7362. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7363. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7364. ->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')
  7365. ->orderBy('updated_at', 'desc')
  7366. // ->limit(5)
  7367. ->get();
  7368. //待审核数据com pro
  7369. $complany = Company::where('status', 0)
  7370. ->orderBy('updated_at', 'desc')
  7371. // ->limit(5)
  7372. ->get();
  7373. $project = Project::where('status', 0)
  7374. ->orderBy('updated_at', 'desc')
  7375. // ->limit(5)
  7376. ->get();
  7377. $count =
  7378. // count($chat) +
  7379. // count($chat_group) +
  7380. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7381. // + count($job_apply)
  7382. // + count($job_resume)
  7383. + count($complany)
  7384. + count($project);
  7385. $result = [
  7386. 'apply_articale' => $apply_articale,
  7387. // 'chat' => $chat,
  7388. // 'chat_group' => $chat_group,
  7389. 'good' => $good,
  7390. 'notice' => $notice,
  7391. 'complaint' => $complaint,
  7392. 'book' => $book,
  7393. 'job_hunting' => $job_hunting,
  7394. 'job_recruiting' => $job_recruiting,
  7395. // 'job_apply' => $job_apply,
  7396. // 'job_resume' => $job_resume,
  7397. 'complany' => $complany,
  7398. 'project' => $project,
  7399. 'count' => $count,
  7400. ];
  7401. } elseif ($type_id == 20000) {
  7402. }
  7403. var_dump($type_id, '-----------------test---------');
  7404. return Result::success($result);
  7405. }
  7406. /**
  7407. * @param array $data
  7408. * @return array
  7409. */
  7410. public function getWebsiteProject(array $data): array
  7411. {
  7412. $categorys = json_decode($data['id'], true);
  7413. if (!empty($categorys)) {
  7414. $category_arr = $this->processArticlePro($data['website_id']);
  7415. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7416. $catiall = $category_arr['catiall'];
  7417. // return Result::success($catiall);
  7418. foreach ($categorys as $key => $val) {
  7419. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7420. $level = explode(',', $val['level'])[0];
  7421. $imgnum = explode(',', $val['level'])[1] ?? null;
  7422. $textnum = explode(',', $val['level'])[2] ?? null;
  7423. if ($level == 1) {
  7424. if (!empty($textnum) && $textnum > 0) {
  7425. $text_num = Project::where('level', $level)
  7426. ->where('website_id', $data['website_id'])
  7427. ->where('status', 1)
  7428. ->select(
  7429. 'project.id',
  7430. 'project.title',
  7431. 'project.description',
  7432. 'project.updated_at',
  7433. 'project.category_id',
  7434. 'project.cat_arr_id'
  7435. )
  7436. ->orderBy('updated_at', 'desc')
  7437. ->limit($textnum)
  7438. ->get()->all();
  7439. }
  7440. if (!empty($imgnum) && $imgnum > 0) {
  7441. $img_num = Project::where('level', $level)
  7442. ->where('website_id', $data['website_id'])
  7443. ->where('status', 1)
  7444. ->where('imgurl', '!=', '')
  7445. ->whereNotNull('imgurl')
  7446. ->select(
  7447. 'project.id',
  7448. 'project.title',
  7449. 'project.description',
  7450. 'project.updated_at',
  7451. 'project.imgurl as imgs',
  7452. 'project.category_id',
  7453. 'project.cat_arr_id'
  7454. )
  7455. ->orderBy('updated_at', 'desc')
  7456. ->limit($imgnum)
  7457. ->get()->all();
  7458. }
  7459. } else {
  7460. if (!empty($textnum) && $textnum > 0) {
  7461. $text_num = Project::where('website_id', $data['website_id'])
  7462. ->where('status', 1)
  7463. ->select(
  7464. 'project.id',
  7465. 'project.title',
  7466. 'project.description',
  7467. 'project.updated_at',
  7468. 'project.category_id',
  7469. 'project.cat_arr_id',
  7470. 'project.website_id',
  7471. 'project.updated_at',
  7472. 'project.created_at'
  7473. )
  7474. ->orderBy('updated_at', 'desc')
  7475. ->limit($textnum)
  7476. ->get()->all();
  7477. }
  7478. if (!empty($imgnum) && $imgnum > 0) {
  7479. $img_num = Project::where('website_id', $data['website_id'])
  7480. ->where('status', 1)
  7481. ->where('imgurl', '!=', '')
  7482. ->whereNotNull('imgurl')
  7483. ->select(
  7484. 'project.id',
  7485. 'project.title',
  7486. 'project.description',
  7487. 'project.updated_at',
  7488. 'project.imgurl as imgs',
  7489. 'project.category_id',
  7490. 'project.cat_arr_id'
  7491. )
  7492. ->orderBy('updated_at', 'desc')
  7493. ->limit($imgnum)
  7494. ->get()->all();
  7495. }
  7496. }
  7497. }
  7498. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7499. $category_ids = explode(',', $val['id'])[0];
  7500. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7501. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7502. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7503. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7504. $text_num = Project::whereIn('category_id', $category_arr)
  7505. ->where('website_id', $data['website_id'])
  7506. ->where('status', 1)
  7507. ->select(
  7508. 'project.id',
  7509. 'project.title',
  7510. 'project.description',
  7511. 'project.updated_at',
  7512. 'project.category_id',
  7513. 'project.cat_arr_id'
  7514. )
  7515. ->orderBy('updated_at', 'desc')
  7516. ->limit($cat_textnum)
  7517. ->get()->all();
  7518. }
  7519. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7520. $img_num = Project::whereIn('category_id', $category_arr)
  7521. ->where('website_id', $data['website_id'])
  7522. ->where('status', 1)
  7523. ->where('imgurl', '!=', '')
  7524. ->whereNotNull('imgurl')
  7525. ->select(
  7526. 'project.id',
  7527. 'project.title',
  7528. 'project.description',
  7529. 'project.updated_at',
  7530. 'project.imgurl as imgs',
  7531. 'project.category_id',
  7532. 'project.cat_arr_id'
  7533. )
  7534. ->orderBy('updated_at', 'desc')
  7535. ->limit($cat_imgnum)
  7536. ->get()->all();
  7537. }
  7538. }
  7539. if (!empty($img_num)) {
  7540. foreach ($img_num as $k => $v) {
  7541. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7542. $imgurl = json_decode($v['imgs'], true);
  7543. if (!empty($imgurl)) {
  7544. $img_num[$k]->imgurl = $imgurl[0];
  7545. }
  7546. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7547. }
  7548. }
  7549. if (!empty($text_num)) {
  7550. foreach ($text_num as $k => $v) {
  7551. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7552. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7553. }
  7554. }
  7555. $project[$key]['img_num'] = $img_num ?? [];
  7556. $project[$key]['text_num'] = $text_num ?? [];
  7557. }
  7558. }
  7559. if (empty($project)) {
  7560. return Result::error("暂无相关项目信息", 0);
  7561. }
  7562. return Result::success($project);
  7563. }
  7564. /**
  7565. * @param array $data
  7566. * @return array
  7567. */
  7568. public function getWebsiteProjectInfo(array $data): array
  7569. {
  7570. $project = Project::where('id', $data['id'])
  7571. ->where('status', 1)
  7572. ->where('website_id', $data['website_id'])
  7573. ->select('project.*')
  7574. ->first();
  7575. if (empty($project)) {
  7576. return Result::error("暂无相关项目信息", 0);
  7577. }
  7578. return Result::success($project);
  7579. }
  7580. /**
  7581. * @param array $data
  7582. * @return array
  7583. */
  7584. public function getWebsiteProjectList(array $data): array
  7585. {
  7586. $where = [];
  7587. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7588. $where['category_id'] = $data['category_id'];
  7589. }
  7590. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7591. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7592. }
  7593. $query = Project::where($where)
  7594. ->where('status', 1)
  7595. ->where('website_id', $data['website_id'])
  7596. ->select(
  7597. 'project.id',
  7598. 'project.title',
  7599. 'project.description',
  7600. 'project.imgurl as imgs',
  7601. 'project.category_id',
  7602. 'project.cat_arr_id'
  7603. )
  7604. ->orderBy('updated_at', 'desc');
  7605. $count = $query->count();
  7606. $project = $query->clone()
  7607. ->offset(($data['page'] - 1) * $data['pageSize'])
  7608. ->limit($data['pageSize'])
  7609. ->get()->all();
  7610. if (empty($project)) {
  7611. return Result::error("暂无相关项目信息", 0);
  7612. }
  7613. $categorys = $this->processArticlePro($data['website_id']);
  7614. $catiall = $categorys['catiall'];
  7615. foreach ($project as $key => $val) {
  7616. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7617. if (!empty($val['imgs'])) {
  7618. $imgurl = json_decode($val['imgs'], true);
  7619. if (!empty($imgurl)) {
  7620. $project[$key]->imgurl = $imgurl[0];
  7621. }
  7622. } else {
  7623. $project[$key]->imgurl = '';
  7624. }
  7625. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7626. }
  7627. $result = [
  7628. 'rows' => $project,
  7629. 'count' => $count,
  7630. ];
  7631. return Result::success($result);
  7632. }
  7633. /**
  7634. * @param array $data
  7635. * @return array
  7636. */
  7637. public function getWebsiteCategoryJob(array $data): array
  7638. {
  7639. $categorys = json_decode($data['id'], true);
  7640. if (!empty($categorys)) {
  7641. $category_arr = $this->processArticlePro($data['website_id']);
  7642. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7643. $catiall = $category_arr['catiall'];
  7644. foreach ($categorys as $key => $val) {
  7645. if (isset($val['id']) && !empty($val['id'])) {
  7646. $catid = explode(',', $val['id'])[0] ?? null;
  7647. $type = explode(',', $val['id'])[1] ?? null;
  7648. $textnum = explode(',', $val['id'])[2] ?? null;
  7649. }
  7650. // 4:招聘;5:求职;
  7651. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7652. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7653. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7654. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7655. ->where('job_recruiting.status', 1)
  7656. ->where('job_recruiting.website_id', $data['website_id'])
  7657. ->select(
  7658. 'job_recruiting.id',
  7659. 'job_recruiting.title',
  7660. 'job_company.business_name',
  7661. 'job_recruiting.updated_at',
  7662. 'job_recruiting.cat_arr_id'
  7663. )
  7664. ->orderBy('job_recruiting.updated_at', 'desc')
  7665. ->limit($textnum)
  7666. ->get()->all();
  7667. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7668. // 状态 审核状态,1待审核2已审核3已拒绝
  7669. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7670. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7671. ->where('job_hunting.status', 2)
  7672. ->where('job_hunting.website_id', $data['website_id'])
  7673. ->select(
  7674. 'job_hunting.id',
  7675. 'job_hunting.name',
  7676. 'job_hunting.cat_arr_id',
  7677. 'job_position.zwname as job_name',
  7678. 'job_hunting.updated_at'
  7679. )
  7680. ->orderBy('updated_at', 'desc')
  7681. ->limit($textnum)
  7682. ->get()->all();
  7683. } else {
  7684. $job = [];
  7685. }
  7686. // var_dump($catid.'222uuuuuuu'.$key);
  7687. if (!empty($job)) {
  7688. foreach ($job as $k => $value) {
  7689. if (isset($value->cat_arr_id)) {
  7690. $catArr = json_decode($value->cat_arr_id, true);
  7691. $catId = end($catArr);
  7692. } else {
  7693. continue;
  7694. }
  7695. if (isset($catiall[$catId])) {
  7696. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7697. }
  7698. }
  7699. }
  7700. // var_dump($catid.'xxxxx'.$key);
  7701. $result[$key] = $job ?? [];
  7702. }
  7703. }
  7704. if (empty($result)) {
  7705. return Result::error("暂无相关分类信息", 0);
  7706. }
  7707. return Result::success($result);
  7708. }
  7709. /**
  7710. * 发送消息
  7711. * @param array $messageData
  7712. * @return void
  7713. */
  7714. public function sendMessage($messageData)
  7715. {
  7716. $msg = [
  7717. 'talk_type' => $messageData['talk_type'],
  7718. 'title' => $messageData['title'],
  7719. 'content' => $messageData['content'],
  7720. 'messageType' => $messageData['messageType'],
  7721. 'user_id' => $messageData['user_id'] ?? '',
  7722. 'time' => microtime(),
  7723. ];
  7724. $message = new MqProducer($msg);
  7725. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7726. $producer->produce($message);
  7727. }
  7728. }