NewsService.php 285 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. use App\Model\GroupMemberImp;
  65. use App\Model\GroupImp;
  66. use App\Model\GroupTalkImp;
  67. use App\Model\GroupTalkMessagerImp;
  68. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  69. class NewsService implements NewsServiceInterface
  70. {
  71. #[Inject]
  72. protected Redis $redis;
  73. /**
  74. * 获取导航池列表
  75. * @param array $data
  76. * @return array
  77. */
  78. public function getCategoryList(array $data): array
  79. {
  80. $search = $data['name'] ?? '';
  81. $page = (int)($data['page'] ?? 1);
  82. $perPage = (int)($data['pageSize'] ?? 10);
  83. // 1. 查出所有匹配的分类id
  84. if ($search) {
  85. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  86. if (empty($matchedIds)) {
  87. return Result::success(['rows' => [], 'total' => 0]);
  88. }
  89. // 2. 递归查所有父级,直到一级分类
  90. $idsStr = implode(',', $matchedIds);
  91. $sql = "
  92. WITH RECURSIVE parents AS (
  93. SELECT * FROM category WHERE id IN ($idsStr)
  94. UNION ALL
  95. SELECT c.* FROM category c
  96. INNER JOIN parents p ON c.id = p.pid
  97. )
  98. SELECT * FROM parents
  99. ";
  100. $parents = Db::select($sql);
  101. $parentIds = [];
  102. foreach ($parents as $row) {
  103. if ($row->pid == 0) {
  104. $parentIds[] = $row->id;
  105. }
  106. }
  107. $parentIds = array_unique($parentIds);
  108. } else {
  109. // 没有搜索,一级分类就是根
  110. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  111. }
  112. // 3. 一级分类分页
  113. $total = count($parentIds);
  114. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  115. if (empty($parentIds)) {
  116. return Result::success(['rows' => [], 'total' => $total]);
  117. }
  118. // 4. 递归查所有子孙
  119. $idsStr = implode(',', $parentIds);
  120. $sql = "
  121. WITH RECURSIVE subcategories AS (
  122. SELECT * FROM category WHERE id IN ($idsStr)
  123. UNION ALL
  124. SELECT c.* FROM category c
  125. INNER JOIN subcategories s ON c.pid = s.id
  126. )
  127. SELECT * FROM subcategories ORDER BY updated_at DESC
  128. ";
  129. $allCategories = Db::select($sql);
  130. // 5. 组装树结构
  131. $categoryMap = [];
  132. foreach ($allCategories as $cat) {
  133. $cat = (array)$cat;
  134. $cat['children'] = [];
  135. $categoryMap[$cat['id']] = $cat;
  136. }
  137. foreach ($categoryMap as $id => &$cat) {
  138. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  139. $categoryMap[$cat['pid']]['children'][] = &$cat;
  140. }
  141. }
  142. unset($cat);
  143. $categoryTree = [];
  144. foreach ($parentIds as $id) {
  145. if (isset($categoryMap[$id])) {
  146. $categoryTree[] = $categoryMap[$id];
  147. }
  148. }
  149. return Result::success([
  150. 'rows' => $categoryTree,
  151. 'total' => $total,
  152. ]);
  153. }
  154. private function findMatchedCategories($search)
  155. {
  156. if ($search) {
  157. return Category::where('name', 'like', "%{$search}%")
  158. ->orderBy('updated_at', 'desc')
  159. ->get();
  160. }
  161. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  162. ->get();
  163. }
  164. private function findAllParents($categories)
  165. {
  166. $allCategories = [];
  167. foreach ($categories as $category) {
  168. $parentId = $category->pid;
  169. while ($parentId > 0) {
  170. $parent = Category::find($parentId);
  171. if ($parent) {
  172. $allCategories[$parent->id] = $parent;
  173. $parentId = $parent->pid;
  174. } else {
  175. break;
  176. }
  177. }
  178. $allCategories[$category->id] = $category;
  179. }
  180. return array_values($allCategories);
  181. }
  182. private function buildCategoryTree($category, $allRequiredCategories)
  183. {
  184. $categoryData = $category->toArray();
  185. $children = [];
  186. foreach ($allRequiredCategories as $c) {
  187. if ($c->pid === $category->id) {
  188. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  189. }
  190. }
  191. if (!empty($children)) {
  192. $categoryData['children'] = $children;
  193. }
  194. return $categoryData;
  195. }
  196. public function myCategoryList(array $data): array
  197. {
  198. $sszq = $data['sszq'] ?? '';
  199. unset($data['sszq']);
  200. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  201. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  202. $where[] = [
  203. 'pid',
  204. '=',
  205. $data['pid'],
  206. ];
  207. if (isset($data['name'])) {
  208. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  209. }
  210. var_dump($where);
  211. //根据分类id,从category表中取出分类信息
  212. $result = Category::where($where)
  213. ->whereIn('category.id', $catorytids)
  214. ->select('category.*', 'category.id as category_id')->get();
  215. if (empty($result)) {
  216. return Result::error("没有栏目数据");
  217. }
  218. return Result::success($result);
  219. }
  220. /**
  221. * @param array $data
  222. * @return array
  223. */
  224. public function categoryList(array $data): array
  225. {
  226. $where[] = [
  227. 'pid',
  228. '=',
  229. $data['pid']
  230. ];
  231. if (isset($data['name'])) {
  232. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  233. }
  234. var_dump($where);
  235. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  236. if (empty($result)) {
  237. return Result::error("没有栏目数据");
  238. }
  239. return Result::success($result);
  240. }
  241. /**
  242. * @param array $data
  243. * @return array
  244. */
  245. public function addCategory(array $data): array
  246. {
  247. if (isset($data['id'])) {
  248. unset($data['id']);
  249. }
  250. $id = Category::insertGetId($data);
  251. if (empty($id)) {
  252. return Result::error("添加失败");
  253. }
  254. return Result::success(['id' => $id]);
  255. }
  256. /**
  257. * @param array $data
  258. * @return array
  259. */
  260. public function delCategory(array $data): array
  261. {
  262. Db::beginTransaction();
  263. try {
  264. $categoryList = Category::where(['pid' => $data['id']])->get();
  265. if ($categoryList->toArray()) {
  266. Db::rollBack();
  267. return Result::error("分类下面有子分类不能删除");
  268. }
  269. $articleList = Article::where(['catid' => $data['id']])->get();
  270. if ($articleList->toArray()) {
  271. Db::rollBack();
  272. return Result::error("分类下面有资讯不能删除");
  273. }
  274. $result = Category::where($data)->delete();
  275. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  276. if (!$result) {
  277. Db::rollBack();
  278. return Result::error("删除失败");
  279. }
  280. Db::commit();
  281. return Result::success($result);
  282. } catch (\Exception $e) {
  283. Db::rollBack();
  284. return Result::error("删除失败" . $e->getMessage());
  285. }
  286. }
  287. /**
  288. * @param array $data
  289. * @return array
  290. */
  291. public function updateCategory(array $data): array
  292. {
  293. $where = [
  294. 'id' => $data['id'],
  295. ];
  296. $result = Category::where($where)->update($data);
  297. if ($result) {
  298. return Result::success($result);
  299. } else {
  300. return Result::error("更新失败");
  301. }
  302. }
  303. /**
  304. * 获取导航池信息
  305. * @param array $data
  306. * @return array
  307. */
  308. public function getCategoryInfo(array $data): array
  309. {
  310. $where = [
  311. 'id' => $data['id'],
  312. ];
  313. $result = Category::where($where)->first();
  314. if ($result) {
  315. return Result::success($result);
  316. } else {
  317. return Result::error("更新失败");
  318. }
  319. }
  320. public function getArticleCommend(array $data): array
  321. {
  322. $where = [
  323. 'website_id' => $data['website_id'],
  324. ];
  325. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  326. var_dump($ids);
  327. if (empty($ids)) {
  328. return Result::error("没有推荐数据");
  329. }
  330. //id
  331. $whereArticle = [];
  332. if (isset($data['id'])) {
  333. $whereArticle['id'] = $data['id'];
  334. }
  335. //title like
  336. if (isset($data['title'])) {
  337. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  338. }
  339. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  340. ->where($whereArticle)
  341. ->orderBy('id', 'desc')
  342. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  343. if ($article) {
  344. $data = [
  345. 'rows' => $article->items(),
  346. 'count' => $article->total(),
  347. ];
  348. return Result::success($data);
  349. } else {
  350. return Result::error("获取失败失败");
  351. }
  352. }
  353. /**
  354. * @param array $data
  355. * @return array
  356. */
  357. public function getArticleList(array $data): array
  358. {
  359. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  360. $type_id = $data['type_id'];
  361. unset($data['type_id']);
  362. $user_id = $data['user_id'];
  363. unset($data['user_id']);
  364. $where = [];
  365. $status1 = [];
  366. if (isset($data['id']) && $data['id']) {
  367. array_push($where, ['article.id', '=', $data['id']]);
  368. }
  369. if (isset($data['title']) && $data['title']) {
  370. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  371. }
  372. if (isset($data['category_name']) && $data['category_name']) {
  373. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  374. }
  375. if (isset($data['catid']) && $data['catid']) {
  376. array_push($where, ['article.catid', '=', $data['catid']]);
  377. }
  378. if (isset($data['author']) && $data['author']) {
  379. array_push($where, ['article.author', '=', $data['author']]);
  380. }
  381. if (isset($data['islink']) && $data['islink'] !== "") {
  382. array_push($where, ['article.islink', '=', $data['islink']]);
  383. }
  384. if (isset($data['status']) && $data['status'] !== "") {
  385. array_push($where, ['article.status', '=', $data['status']]);
  386. }
  387. if (isset($data['status1'])) {
  388. $status1 = json_decode(($data['status1']));
  389. }
  390. //不是管理员展示个人数据;
  391. if ($type_id != 10000) {
  392. $where[] = ['article.admin_user_id', '=', $user_id];
  393. }
  394. $rep = Article::where($where)
  395. ->whereNotIn('article.status', [404])
  396. ->when($status1, function ($query) use ($status1) {
  397. if (isset($status1) && $status1) {
  398. $query->whereIn('article.status', $status1);
  399. }
  400. })
  401. ->leftJoin('category', 'article.catid', 'category.id')
  402. ->leftJoin('website_category', function ($join) {
  403. $join->on('article.web_site_id', '=', 'website_category.website_id')
  404. ->on('article.catid', '=', 'website_category.category_id');
  405. })
  406. ->select("article.*", "category.name as category_name", "website_category.alias")
  407. ->orderBy("article.updated_at", "desc")
  408. ->limit($data['pageSize'])
  409. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  410. $count = Article::where($where)->whereNotIn('article.status', [404])
  411. ->when($status1, function ($query) use ($status1) {
  412. if (isset($status1) && $status1) {
  413. $query->whereIn('article.status', $status1);
  414. }
  415. })
  416. ->leftJoin('category', 'article.catid', 'category.id')->count();
  417. $data = [
  418. 'rows' => $rep->toArray(),
  419. 'count' => $count,
  420. ];
  421. if (empty($rep)) {
  422. return Result::error("没有信息数据");
  423. }
  424. return Result::success($data);
  425. }
  426. /**
  427. * @param array $data
  428. * @return array
  429. */
  430. public function addArticle(array $data): array
  431. {
  432. var_dump($data, '----------12-----------1');
  433. unset($data['user_type']);
  434. unset($data['nav_add_pool_id']);
  435. // unset($data['commend_id']);
  436. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  437. Db::beginTransaction();
  438. try {
  439. //处理投票
  440. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  441. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  442. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  443. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  444. unset($data['is_survey']);
  445. unset($data['survey_name']);
  446. unset($data['suvey_array']);
  447. // unset($data['website_id']);
  448. // unset($data['web_site_id']);
  449. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  450. if ($data['hits'] == '') {
  451. $data['hits'] = 0;
  452. }
  453. if ($data['is_original'] == '') {
  454. $data['is_original'] = 0;
  455. }
  456. if ($data['status'] == '') {
  457. $data['status'] = 0;
  458. }
  459. $articleData = $data;
  460. unset($articleData['content']);
  461. //自动处理缩略图、关键字、描述
  462. if ($articleData['imgurl'] == '') {
  463. //如果没有图,设置level=0
  464. $levelArr = json_decode($articleData['level'], true);
  465. var_dump($levelArr, '----------levelArr-----------1');
  466. //content中提取图片第一个图,正则提取
  467. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  468. preg_match_all($reg, $data['content'], $matches);
  469. if (isset($matches[1][0])) {
  470. //截取varchar240
  471. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  472. //如果有图,设置level=3
  473. if (!in_array(3, $levelArr)) {
  474. $levelArr[] = 3;
  475. }
  476. $articleData['level'] = json_encode($levelArr);
  477. } else {
  478. if (!in_array(0, $levelArr)) {
  479. $levelArr[] = 0;
  480. }
  481. $articleData['level'] = json_encode($levelArr);
  482. }
  483. }
  484. var_dump($articleData['level'], '----------$articleData[level]----------1');
  485. if ($articleData['keyword'] == '') {
  486. //提取标题+内容中的关键词
  487. $articleData['keyword'] = $data['title'];
  488. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  489. Jieba::init(); // 初始化 jieba-php
  490. Finalseg::init();
  491. $segList = Jieba::cut($articleData['keyword']);
  492. $segList1 = array_slice($segList, 0, 8);
  493. $articleData['keyword'] = implode(',', $segList1);
  494. }
  495. if ($articleData['introduce'] == '') {
  496. //提取内容中的描述
  497. $content = $data['content'];
  498. // 去除 <style> 和 <script> 标签及其内容
  499. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  500. // 去除所有 HTML 标签
  501. $content = strip_tags($content);
  502. // 去除 HTML 实体
  503. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  504. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  505. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  506. // 去除多余空白
  507. $content = preg_replace('/\s+/u', '', $content);
  508. // 截取 100 个字符
  509. $articleData['introduce'] = mb_substr($content, 0, 100);
  510. }
  511. if ($articleData['status'] == 0) {
  512. $this->sendMessage([
  513. 'talk_type' => 100,
  514. 'title' => $articleData['title'],
  515. 'content' => '提交了审核',
  516. 'messageType' => 2,
  517. ]);
  518. }
  519. $id = Article::insertGetId($articleData);
  520. $articleDataContent = [
  521. 'article_id' => $id,
  522. 'content' => $data['content'],
  523. ];
  524. ArticleData::insertGetId($articleDataContent);
  525. //处理投票
  526. if ($is_survey == 1) {
  527. //生成年月日时分秒+8位随机数
  528. $uuid = date('YmdHis') . rand(10000000, 99999999);
  529. var_dump($suvey_array, 'suvey_array________');
  530. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  531. var_dump($suveys_array, '---------------------1');
  532. var_dump($suvey_array, '---------------------2');
  533. $suvey_data = [];
  534. foreach ($suveys_array as $key => $value) {
  535. if ($value == '') {
  536. continue;
  537. }
  538. if (is_array($value)) {
  539. $suvey_data[] = [
  540. 'sur_id' => $uuid,
  541. 'art_id' => $id,
  542. 'website_id' => $website_id ?? 2,
  543. 'survey_name' => $survey_name,
  544. 'choice_name' => $value[1],
  545. 'is_other' => 1,
  546. 'other_id' => 0,
  547. 'results' => 0,
  548. ];
  549. } else {
  550. $suvey_data[] = [
  551. 'sur_id' => $uuid,
  552. 'art_id' => $id,
  553. 'website_id' => $website_id ?? 2,
  554. 'survey_name' => $survey_name,
  555. 'choice_name' => $value,
  556. 'is_other' => 0,
  557. 'other_id' => 0,
  558. 'results' => 0,
  559. ];
  560. }
  561. if (empty($suvey_data)) {
  562. throw new \Exception("投票数据为空");
  563. }
  564. }
  565. $result = ArticleSurvey::insert($suvey_data);
  566. if (!$result) {
  567. throw new \Exception("投票失败,ArticleSurvey插入失败");
  568. }
  569. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  570. if (!$result) {
  571. throw new \Exception("投票失败,更新主表失败");
  572. }
  573. }
  574. Db::commit();
  575. return Result::success(['id' => $id]);
  576. } catch (\Throwable $ex) {
  577. Db::rollBack();
  578. var_dump($ex->getMessage());
  579. return Result::error("创建失败", 0);
  580. }
  581. }
  582. /**
  583. * @param array $data
  584. * @return array
  585. */
  586. public function delArticle(array $data): array
  587. {
  588. $result = Article::where($data)->delete();
  589. //survey投票删除
  590. articleSurvey::where(['art_id' => $data['id']])->delete();
  591. if (!$result) {
  592. return Result::error("删除失败");
  593. }
  594. return Result::success($result);
  595. }
  596. /**
  597. * @param array $data
  598. * @return array
  599. */
  600. public function updateArticle(array $data): array
  601. {
  602. var_dump($data, '----------12-----------1');
  603. Db::beginTransaction();
  604. unset($data['user_type']);
  605. // unset($data['web_site_id']);
  606. unset($data['nav_add_pool_id']);
  607. try {
  608. //处理投票
  609. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  610. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  611. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  612. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  613. unset($data['is_survey']);
  614. unset($data['survey_name']);
  615. unset($data['suvey_array']);
  616. unset($data['website_id']);
  617. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  618. if ($data['hits'] == '') {
  619. $data['hits'] = 0;
  620. }
  621. if ($data['is_original'] == '') {
  622. $data['is_original'] = 0;
  623. }
  624. if ($data['status'] == '') {
  625. $data['status'] = 0;
  626. }
  627. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  628. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  629. $articleData = $data;
  630. unset($articleData['content']);
  631. unset($articleData['status_name']);
  632. unset($articleData['name']);
  633. unset($articleData['content']);
  634. unset($articleData['pid_arr']);
  635. unset($articleData['pid']);
  636. //自动处理缩略图、关键字、描述
  637. if ($articleData['imgurl'] == '') {
  638. //如果没有图,设置level=0
  639. $levelArr = json_decode($articleData['level'], true);
  640. var_dump($levelArr, '----------levelArr-----------1');
  641. //content中提取图片第一个图,正则提取
  642. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  643. preg_match_all($reg, $data['content'], $matches);
  644. if (isset($matches[1][0])) {
  645. //截取varchar240
  646. // 截取到第一个<
  647. $articleData['imgurl'] = $matches[1][0];
  648. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  649. $pos = strpos($articleData['imgurl'], '"');
  650. if ($pos !== false) {
  651. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  652. }
  653. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  654. //如果有图,设置level=3
  655. if (!in_array(3, $levelArr)) {
  656. $levelArr[] = 3;
  657. }
  658. $articleData['level'] = json_encode($levelArr);
  659. } else {
  660. if (!in_array(0, $levelArr)) {
  661. $levelArr[] = 0;
  662. }
  663. $articleData['level'] = json_encode($levelArr);
  664. }
  665. }
  666. var_dump($articleData['level'], '----------$articleData[level]----------1');
  667. if ($articleData['keyword'] == '') {
  668. //提取标题+内容中的关键词
  669. $articleData['keyword'] = $data['title'];
  670. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  671. Jieba::init(); // 初始化 jieba-php
  672. Finalseg::init();
  673. $segList = Jieba::cut($articleData['keyword']);
  674. $segList1 = array_slice($segList, 0, 8);
  675. $articleData['keyword'] = implode(',', $segList1);
  676. }
  677. if ($articleData['introduce'] == '') {
  678. //提取内容中的描述
  679. $content = $data['content'];
  680. // 去除 <style> 和 <script> 标签及其内容
  681. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  682. // 去除所有 HTML 标签
  683. $content = strip_tags($content);
  684. // 去除 HTML 实体
  685. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  686. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  687. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  688. // 去除多余空白
  689. $content = preg_replace('/\s+/u', '', $content);
  690. // 截取 100 个字符
  691. $articleData['introduce'] = mb_substr($content, 0, 100);
  692. }
  693. if ($articleData['status'] == 0) {
  694. $this->sendMessage([
  695. 'talk_type' => 100,
  696. 'title' => $articleData['title'],
  697. 'content' => '提交了审核',
  698. 'messageType' => 2,
  699. ]);
  700. }
  701. $id = Article::where(['id' => $data['id']])->update($articleData);
  702. $articleDataContent = [
  703. 'content' => $data['content'],
  704. ];
  705. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  706. //处理投票
  707. $id = $data['id'];
  708. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  709. var_dump($suvey_array, 'suvey_array________delete');
  710. //处理投票
  711. if ($is_survey == 1) {
  712. //生成年月日时分秒+8位随机数
  713. $uuid = date('YmdHis') . rand(10000000, 99999999);
  714. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  715. var_dump($suveys_array, '---------------------1');
  716. $suvey_data = [];
  717. if (is_array($suveys_array)) {
  718. foreach ($suveys_array as $key => $value) {
  719. if ($value == '') {
  720. continue;
  721. }
  722. if (is_array($value)) {
  723. $suvey_data[] = [
  724. 'sur_id' => $uuid,
  725. 'art_id' => $id,
  726. 'website_id' => $website_id ?? 2,
  727. 'survey_name' => $survey_name,
  728. 'choice_name' => $value[1],
  729. 'is_other' => 1,
  730. 'other_id' => 0,
  731. 'results' => 0,
  732. ];
  733. } else {
  734. $suvey_data[] = [
  735. 'sur_id' => $uuid,
  736. 'art_id' => $id,
  737. 'website_id' => $website_id ?? 2,
  738. 'survey_name' => $survey_name,
  739. 'choice_name' => $value,
  740. 'is_other' => 0,
  741. 'other_id' => 0,
  742. 'results' => 0,
  743. ];
  744. }
  745. if (empty($suvey_data)) {
  746. throw new \Exception("投票数据为空");
  747. }
  748. }
  749. }
  750. $result = ArticleSurvey::insert($suvey_data);
  751. if (!$result) {
  752. throw new \Exception("投票失败");
  753. }
  754. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  755. if (!$result) {
  756. throw new \Exception("投票失败");
  757. }
  758. } else {
  759. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  760. }
  761. Db::commit();
  762. return Result::success([]);
  763. } catch (\Throwable $ex) {
  764. Db::rollBack();
  765. var_dump($ex->getMessage());
  766. return Result::error("更新失败" . $ex->getMessage(), 0);
  767. }
  768. }
  769. /**
  770. * 更新资讯状态
  771. * @param array $data
  772. * @return array
  773. */
  774. public function upArticleStatus(array $data): array
  775. {
  776. $articleData = Article::where(['id' => $data['id']])->first();
  777. //发送10次
  778. for ($i = 0; $i < 10; $i++) {
  779. $this->sendMessage([
  780. 'talk_type' => 100,
  781. 'title' => $i . $articleData['title'],
  782. 'content' => '审核通过',
  783. 'messageType' => 2,
  784. 'user_id' => $articleData['admin_user_id'],
  785. ]);
  786. }
  787. var_dump($data['status'], 'status');
  788. return Result::success();
  789. if ($data['status'] == 1) {
  790. $this->sendMessage([
  791. 'talk_type' => 101,
  792. 'title' => $articleData['title'],
  793. 'content' => '审核通过',
  794. 'messageType' => 2,
  795. 'user_id' => $articleData['admin_user_id'],
  796. ]);
  797. }
  798. if ($data['status'] == 2) {
  799. $this->sendMessage([
  800. 'talk_type' => 101,
  801. 'title' => $articleData['title'],
  802. 'content' => '审核拒绝',
  803. 'messageType' => 2,
  804. 'user_id' => $articleData['admin_user_id'],
  805. ]);
  806. }
  807. if ($data['status'] == 0) {
  808. $this->sendMessage([
  809. 'talk_type' => 100,
  810. 'title' => $articleData['title'],
  811. 'content' => '提交了审核',
  812. 'messageType' => 2,
  813. ]);
  814. }
  815. $result = Article::where(['id' => $data['id']])->update($data);
  816. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  817. //article_ignore 表插入数据 db操作
  818. //转成数组
  819. //删掉数据重新写入
  820. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  821. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  822. $insert_data = [];
  823. foreach ($website_ids as $key => $value) {
  824. $insert_data[] = [
  825. 'article_id' => $data['id'],
  826. 'website_id' => $value,
  827. ];
  828. }
  829. DB::table('article_ignore')->insert($insert_data);
  830. }
  831. if ($result) {
  832. return Result::success();
  833. } else {
  834. return Result::error("更新状态失败", 0);
  835. }
  836. }
  837. /**
  838. * 获取新闻详情
  839. * @param array $data
  840. * @return array
  841. */
  842. public function getArticleInfo(array $data): array
  843. {
  844. $where = [
  845. 'article.id' => $data['id'],
  846. // 'article.status' => 1,
  847. ];
  848. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  849. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  850. $info = $result;
  851. // var_dump($info, 'info');
  852. $info['survey_array'] = $articleSurvey;
  853. if ($result) {
  854. return Result::success($info);
  855. } else {
  856. return Result::error("查询失败", 0);
  857. }
  858. }
  859. /**
  860. * 获取头条新闻
  861. * @param array $data
  862. * @return array
  863. */
  864. public function getWebsiteArticlett(array $data): array
  865. {
  866. $website_id = $data['website_id'];
  867. $categorys = $this->processArticlePro($website_id);
  868. $catiall = $categorys['catiall'];
  869. $categoryIds = $categorys['categoryIds'];
  870. $where = [
  871. 'status' => 1
  872. ];
  873. $website_id = $data['website_id'];
  874. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  875. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  876. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  877. switch ($data['level']) {
  878. case 1:
  879. case 2:
  880. case 3:
  881. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  882. $query = Article::where($where)
  883. ->where('level', 'like', '%' . $data['level'] . '%')
  884. ->orderBy('updated_at', 'desc');
  885. break;
  886. case 4: //最新资讯
  887. $query = Article::where($where)->orderBy('updated_at', 'desc');
  888. break;
  889. case 5: //资讯推荐
  890. $query = Article::where($where)
  891. ->where('updated_at', '>', $month);
  892. break;
  893. case 7: //资讯分类
  894. if (isset($data['id']) && !empty($data['id'])) {
  895. $keyword = Article::where('id', $data['id'])->value('keyword');
  896. $keywordArray = explode(',', $keyword);
  897. $whereL7 = [];
  898. foreach ($keywordArray as $k => $v) {
  899. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  900. }
  901. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  902. break;
  903. } else {
  904. return Result::error("请输入资讯ID", 0);
  905. break;
  906. }
  907. default:
  908. break;
  909. }
  910. // $whereL7 = [];
  911. // if(isset($data['id']) && !empty($data['id'])){
  912. // $keyword = Article::where('id', $data['id'])->value('keyword');
  913. // $keywordArray = explode(',', $keyword);
  914. // foreach ($keywordArray as $k => $v) {
  915. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  916. // }
  917. // }
  918. // $query = Article::where($where)
  919. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  920. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  921. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  922. // }
  923. // if($data['level'] == 7){
  924. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  925. // }
  926. // if($data['level'] == 4){
  927. // $query = $query->inRandomOrder()
  928. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  929. // }
  930. // if($data['level'] == 5){
  931. // $query = $query->orderBy('updated_at','desc');
  932. // }
  933. // });
  934. if ($data['textnum'] > 0) {
  935. $query = clone $query;
  936. $result['text'] = $query
  937. ->whereIn('catid', $categoryIds)
  938. ->leftJoinSub(function ($query) use ($website_id) {
  939. $query->from('article_ignore')
  940. ->where('website_id', $website_id);
  941. }, 'article_ignore', function ($join) {
  942. $join->on('article_ignore.article_id', '=', 'article.id');
  943. })
  944. ->where(function ($query) use ($website_id) {
  945. $query->whereNull('article_ignore.article_id')
  946. ->orWhere('article_ignore.website_id', '!=', $website_id);
  947. })
  948. ->select(
  949. 'article.id',
  950. 'article.title',
  951. 'article.author',
  952. 'article.updated_at',
  953. 'article.introduce',
  954. 'article.islink',
  955. 'article.linkurl',
  956. 'article.copyfrom',
  957. 'article.cat_arr_id',
  958. 'article.catid',
  959. 'article.level'
  960. )
  961. ->offset($data['placeid'])
  962. ->limit($data['textnum'])
  963. ->get()->all();
  964. foreach ($result['text'] as $k => $v) {
  965. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  966. }
  967. }
  968. if ($data['imgnum'] > 0) {
  969. $query = clone $query;
  970. $result['img'] = $query
  971. ->whereIn('catid', $categoryIds)
  972. ->where('article.imgurl', '!=', '')
  973. ->select(
  974. 'article.id',
  975. 'article.title',
  976. 'article.imgurl',
  977. 'article.author',
  978. 'article.updated_at',
  979. 'article.introduce',
  980. 'article.islink',
  981. 'article.linkurl',
  982. 'article.copyfrom',
  983. 'article.cat_arr_id',
  984. 'article.catid',
  985. 'article.level'
  986. )
  987. ->offset($data['placeid'])
  988. ->limit($data['imgnum'])
  989. ->get()->all();
  990. foreach ($result['img'] as $k => $v) {
  991. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  992. }
  993. }
  994. if (empty($result)) {
  995. return Result::error("暂无相关资讯", 0);
  996. }
  997. return Result::success($result);
  998. }
  999. /**
  1000. * 获取模块新闻
  1001. * @param array $data
  1002. * @return array
  1003. */
  1004. public function getWebsiteModelArticles(array $data): array
  1005. {
  1006. $catid = $data['catid'];
  1007. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1008. $category = $category->toArray();
  1009. if (!empty($category)) {
  1010. $where = [
  1011. 'status' => 1,
  1012. 'catid' => $catid,
  1013. ];
  1014. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1015. // 1:文字新闻;2:轮播图;3:图文;
  1016. // 级别:0:未分类
  1017. // 3:推荐图片
  1018. if ($data['level'] == 1) {
  1019. $data['level'] = 0;
  1020. }
  1021. $result = Article::where($where)
  1022. ->where(function ($query) use ($data) {
  1023. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1024. ->orWhereNull("level")
  1025. ->orWhereRaw("level = '[]'");
  1026. })
  1027. ->where(function ($query) use ($data) {
  1028. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1029. ->orWhereNull("ignore_ids");
  1030. })
  1031. ->orderBy("updated_at", "desc")
  1032. ->offset($placeid)
  1033. ->limit($data['pagesize'])
  1034. ->get();
  1035. if (empty($result)) {
  1036. return Result::error("此栏目暂无相关新闻", 0);
  1037. }
  1038. } else {
  1039. return Result::error("此网站暂无此栏目", 0);
  1040. }
  1041. return Result::success($result);
  1042. }
  1043. /**
  1044. *获取新闻列表
  1045. * @param array $data
  1046. * @return array
  1047. */
  1048. public function getWebsiteArticleList(array $data): array
  1049. {
  1050. // return Result::success($data);
  1051. $where[] = ['status', '=', 1];
  1052. $website_id = $data['website_id'];
  1053. if (isset($data['catid']) && !empty($data['catid'])) {
  1054. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1055. if (empty($category)) {
  1056. return Result::error("此网站暂无此栏目", 0);
  1057. }
  1058. array_push($where, ['catid', '=', $data['catid']]);
  1059. }
  1060. // return Result::success($where);
  1061. $query = Article::where($where)
  1062. ->leftJoinSub(function ($query) use ($website_id) {
  1063. $query->from('article_ignore')
  1064. ->where('website_id', $website_id);
  1065. }, 'article_ignore', function ($join) {
  1066. $join->on('article_ignore.article_id', '=', 'article.id');
  1067. })
  1068. ->where(function ($query) use ($website_id) {
  1069. $query->whereNull('article_ignore.article_id')
  1070. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1071. })
  1072. ->select(
  1073. 'article.id',
  1074. 'article.title',
  1075. 'article.imgurl',
  1076. 'article.author',
  1077. 'article.updated_at',
  1078. 'article.introduce',
  1079. 'article.islink',
  1080. 'article.linkurl',
  1081. 'article.copyfrom',
  1082. 'article.cat_arr_id',
  1083. 'article.catid'
  1084. );
  1085. $count = $query->count();
  1086. $rep = $query->orderBy("updated_at", "desc")
  1087. ->offset(($data['page'] - 1) * $data['pageSize'])
  1088. ->limit($data['pageSize'])
  1089. ->get()->all();
  1090. $categorys = $this->processArticlePro($website_id);
  1091. $cat_1st_arr = $categorys['cat_1st_arr'];
  1092. $catiall = $categorys['catiall'];
  1093. // $web['website_id'] = $data['website_id'];
  1094. foreach ($rep as $k => $v) {
  1095. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1096. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1097. }
  1098. // $rep = $this->processArticles($rep,$web);
  1099. $data = [
  1100. 'rows' => $rep,
  1101. 'count' => $count,
  1102. ];
  1103. if (empty($rep)) {
  1104. return Result::error("没有信息数据");
  1105. }
  1106. return Result::success($data);
  1107. }
  1108. /**
  1109. * 前端-获取新闻详情
  1110. * @param array $data
  1111. * @return array
  1112. */
  1113. public function selectWebsiteArticleInfo(array $data): array
  1114. {
  1115. $where = [
  1116. 'article.id' => $data['id'],
  1117. 'article.status' => 1,
  1118. ];
  1119. $result = Article::where($where)
  1120. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1121. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1122. ->where(function ($query) use ($data) {
  1123. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1124. ->orWhereNull("ignore_ids");
  1125. })
  1126. ->select(
  1127. 'article.*',
  1128. 'article_data.content',
  1129. 'article_data.article_id',
  1130. 'article_extend.website_url',
  1131. 'article_extend.email',
  1132. 'article_extend.contacts',
  1133. 'article_extend.contacts_mobile',
  1134. 'article_extend.contacts_address',
  1135. 'article_extend.zip_code',
  1136. 'article_extend.enterprise_name'
  1137. )
  1138. ->first();
  1139. if (empty($result)) {
  1140. return Result::error("暂无此新闻!", 0);
  1141. }
  1142. if (!empty($result['publiced_at'])) {
  1143. $result['updated_at'] = $result['publiced_at'];
  1144. }
  1145. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1146. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1147. ->where('website_category.website_id', $data['website_id'])
  1148. ->where(['website_category.category_id' => $result['catid']])
  1149. ->first();
  1150. if (empty($category)) {
  1151. return Result::error("查询失败", 0);
  1152. }
  1153. //手动推荐文章
  1154. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1155. if (empty($commend_ids)) {
  1156. $commendArticle = [];
  1157. } else {
  1158. //去除不存在的文章ID
  1159. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1160. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1161. ->where('article.status', 1)
  1162. ->where('website_category.website_id', $data['website_id'])
  1163. ->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')
  1164. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1165. // ->orderBy('article.updated_at', 'desc')
  1166. ->limit(5)
  1167. ->get();
  1168. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1169. foreach ($commendArticle as $k => $v) {
  1170. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1171. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1172. $cat_arr_id = array_unique($cat_arr_id);
  1173. // 从website_category取出alias_pinyin
  1174. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1175. ->whereIn('category_id', $cat_arr_id)
  1176. ->pluck('alias_pinyin', 'category_id')
  1177. ->toArray();
  1178. // 将cat_arr_id的json转成路径/隔开
  1179. $path_parts = [];
  1180. foreach ($cat_arr_id as $cat_id) {
  1181. if (isset($cat_arr[$cat_id])) {
  1182. $path_parts[] = $cat_arr[$cat_id];
  1183. }
  1184. }
  1185. $v->alias_pinyin = implode('/', $path_parts);
  1186. } else {
  1187. $v->alias_pinyin = '';
  1188. }
  1189. }
  1190. }
  1191. $result['category_id'] = $category['category_id'];
  1192. $result['cat_name'] = $category['alias'];
  1193. $result['website_name'] = $category['website_name'] ?? "";
  1194. $result['suffix'] = $category['suffix'] ?? "";
  1195. $result['commendArticle'] = $commendArticle;
  1196. $result['commend_ids'] = $commend_ids;
  1197. return Result::success($result);
  1198. }
  1199. /**
  1200. * 前端-获取网站调查问卷
  1201. * @param array $data
  1202. * @return array
  1203. */
  1204. public function getWebsiteSurvey(array $data): array
  1205. {
  1206. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1207. $website = Website::where('id', $data['website_id'])->first();
  1208. if (empty($website)) {
  1209. return Result::error("暂无此网站", 0);
  1210. }
  1211. }
  1212. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1213. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1214. if (empty($article)) {
  1215. return Result::error("暂无此文章", 0);
  1216. }
  1217. // return Result::error($data,0);
  1218. $where['art_id'] = $data['art_id'];
  1219. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1220. } else {
  1221. $survey = Article::where(function ($query) {
  1222. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1223. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1224. })
  1225. ->where('status', 1)
  1226. ->where('is_survey', 1)
  1227. ->select('survey_id')
  1228. ->orderBy('updated_at', 'desc')
  1229. ->first();
  1230. if (empty($survey)) {
  1231. return Result::error("暂无调查问卷", 0);
  1232. }
  1233. $where['sur_id'] = $survey['survey_id'];
  1234. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1235. }
  1236. // return Result::success($where);
  1237. $result = ArticleSurvey::where($where)
  1238. ->where(function ($query) {
  1239. $query->where('is_other', 0)
  1240. ->orWhere(function ($subQuery) {
  1241. $subQuery->where('is_other', 1)
  1242. ->where('other_id', 0);
  1243. });
  1244. })
  1245. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1246. ->select('article_survey.*', 'article.survey_type')
  1247. ->get()->all();
  1248. if (empty($result)) {
  1249. return Result::error("此文章暂无调查问卷", 0);
  1250. }
  1251. return Result::success($result);
  1252. }
  1253. /**
  1254. * 前端-添加网站调查问卷选项
  1255. * @param array $data
  1256. * @return array
  1257. */
  1258. public function addWebsiteSurveyOption(array $data): array
  1259. {
  1260. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1261. $website = Website::where('id', $data['website_id'])->first();
  1262. if (empty($website)) {
  1263. return Result::error("暂无此网站", 0);
  1264. }
  1265. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1266. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1267. if (empty($survey)) {
  1268. return Result::error("此调查问卷不可添加选项", 0);
  1269. }
  1270. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1271. $choice = [
  1272. 'art_id' => $survey['art_id'],
  1273. 'website_id' => $data['website_id'],
  1274. 'survey_name' => $survey['survey_name'],
  1275. 'choice_name' => $data['choice_name'],
  1276. 'sur_id' => $survey['sur_id'],
  1277. 'is_other' => 1,
  1278. 'other_id' => $survey['id'],
  1279. ];
  1280. $result = ArticleSurvey::insertGetId($choice);
  1281. if (empty($result)) {
  1282. return Result::error("添加失败", 0);
  1283. }
  1284. return Result::success($result);
  1285. }
  1286. }
  1287. return Result::error("添加失败", 0);
  1288. }
  1289. return Result::error("添加失败", 0);
  1290. }
  1291. /**
  1292. * 前端-调查问卷投票
  1293. * @param array $data
  1294. * @return array
  1295. */
  1296. public function addWebsiteSurveyVote(array $data): array
  1297. {
  1298. // return Result::success($data);
  1299. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1300. $website = Website::where('id', $data['website_id'])->first();
  1301. if (empty($website)) {
  1302. return Result::error("暂无此网站", 0);
  1303. }
  1304. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1305. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1306. // return Result::success($survey);
  1307. if (empty($is_survey)) {
  1308. return Result::error("此调查问卷不存在", 0);
  1309. }
  1310. // return Result::success($survey);
  1311. // 调查问卷类型
  1312. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1313. //多选 若是json型则转化成数组类型
  1314. if (strpos($data['choice_id'], '[') === 0) {
  1315. $data['choice_id'] = json_decode($data['choice_id'], true);
  1316. } else {
  1317. // 单选 也转换成数组
  1318. $data['choice_id'] = [$data['choice_id']];
  1319. }
  1320. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1321. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1322. // ->where('website_id',$data['website_id'])
  1323. ->where('is_other', 1)
  1324. ->where('other_id', 0)
  1325. ->first();
  1326. if (!empty($other)) {
  1327. return Result::error("请选择已有的选项!", 0);
  1328. }
  1329. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1330. // ->where('website_id',$data['website_id'])
  1331. ->where('is_other', 1)
  1332. ->where('other_id', '!=', 0)
  1333. ->first();
  1334. // return Result::success($choice['other']);
  1335. $choice_id = $data['choice_id'];
  1336. if (!empty($choice['other'])) {
  1337. // array_push($data['choice_id'],$choice['other']['other_id']);
  1338. if (!empty($choice_id)) {
  1339. $key = array_search($choice['other']['id'], $choice_id);
  1340. if ($key !== false) {
  1341. unset($choice_id[$key]);
  1342. $choice_id = array_values($choice_id);
  1343. }
  1344. array_push($choice_id, $choice['other']['other_id']);
  1345. } else {
  1346. $choice_id[0] = $choice['other']['other_id'];
  1347. }
  1348. array_push($data['choice_id'], $choice['other']['other_id']);
  1349. }
  1350. // return Result::success($data);
  1351. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1352. // ->where('website_id',$data['website_id'])
  1353. ->increment('results', 1);
  1354. if (empty($choice)) {
  1355. return Result::error("请选择已有的选项!", 0);
  1356. }
  1357. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1358. // ->where('website_id',$data['website_id'])
  1359. ->where('other_id', 0)
  1360. ->get();
  1361. $survey['choice'] = $choice_id;
  1362. return Result::success($survey);
  1363. }
  1364. return Result::error("参数必填!");
  1365. }
  1366. return Result::error("此调查问卷不存在", 0);
  1367. }
  1368. return Result::error("参数必填!");
  1369. }
  1370. /**
  1371. * 后端-获取网站调查问卷列表
  1372. * @param array $data
  1373. * @return array
  1374. */
  1375. public function getSurveyList(array $data): array
  1376. {
  1377. $where = [];
  1378. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1379. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1380. }
  1381. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1382. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1383. }
  1384. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1385. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1386. }
  1387. // return Result::success($where);
  1388. if (!empty($where)) {
  1389. $query = Article::where($where)->where(function ($q) {
  1390. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1391. });
  1392. } else {
  1393. $query = Article::where(function ($q) {
  1394. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1395. });
  1396. }
  1397. $count = $query->count();
  1398. $survey = $query->orderByDesc('id')
  1399. ->limit($data['pageSize'])
  1400. ->offset(($data['page'] - 1) * $data['pageSize'])
  1401. ->get();
  1402. if (empty($survey->toArray())) {
  1403. return Result::error("暂无调查问卷!", 0);
  1404. }
  1405. $result = [
  1406. 'rows' => $survey,
  1407. 'count' => $count,
  1408. ];
  1409. return Result::success($result);
  1410. }
  1411. /**
  1412. * 后端-获取网站调查问卷详情
  1413. * @param array $data
  1414. * @return array
  1415. */
  1416. public function getSurveyInfo(array $data): array
  1417. {
  1418. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1419. $where = ['sur_id' => $data['sur_id']];
  1420. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1421. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1422. ->select('article_survey.*', 'article.survey_type')
  1423. ->get()->all();
  1424. if (empty($choose)) {
  1425. return Result::error("此调查问卷不存在", 0);
  1426. }
  1427. $resultsArray = array_column($choose, 'results');
  1428. $total = array_sum($resultsArray);
  1429. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1430. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1431. // $total = 0;
  1432. if (!empty($other)) {
  1433. $total = $total + $other['results'];
  1434. $other['choice_name'] = '(其他)';
  1435. if (!empty($others)) {
  1436. $other['hasChildren'] = true;
  1437. // array_push($other,['hasChildren','=',true]);
  1438. $other['children'] = $others;
  1439. $other_choices = [$other->toArray()];
  1440. $mer_choice = array_merge($choose, $other_choices);
  1441. $value_choice = array_values($mer_choice);
  1442. } else {
  1443. // return Result::error('1111');
  1444. $other_choices = [$other->toArray()];
  1445. $other_choices = array_merge($choose, $other_choices);
  1446. $value_choice = array_values($other_choices);
  1447. // return Result::success($result);
  1448. }
  1449. } else {
  1450. $value_choice = $choose;
  1451. }
  1452. $result = [
  1453. 'choose' => $value_choice,
  1454. 'total' => $total,
  1455. ];
  1456. }
  1457. return Result::success($result);
  1458. }
  1459. /**
  1460. * 前端-搜索新闻列表
  1461. * @param array $data
  1462. * @return array
  1463. */
  1464. public function selectWebsiteArticle(array $data): array
  1465. {
  1466. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1467. $website_id = $data['website_id'];
  1468. $categorys = $this->processArticlePro($website_id);
  1469. $catiall = $categorys['catiall'];
  1470. $query = Article::where('status', 1)
  1471. ->whereIn('catid', $category)
  1472. ->leftJoinSub(function ($query) use ($website_id) {
  1473. $query->from('article_ignore')
  1474. ->where('website_id', $website_id);
  1475. }, 'article_ignore', function ($join) {
  1476. $join->on('article_ignore.article_id', '=', 'article.id');
  1477. })
  1478. ->where(function ($query) use ($website_id) {
  1479. $query->whereNull('article_ignore.article_id')
  1480. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1481. });
  1482. // return Result::success($all_articles);
  1483. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1484. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1485. }
  1486. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1487. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1488. }
  1489. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1490. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1491. }
  1492. // 计算总数
  1493. $count = $query->count();
  1494. // 分页查询
  1495. $articles = $query
  1496. ->select(
  1497. 'article.id',
  1498. 'article.title',
  1499. 'article.imgurl',
  1500. 'article.author',
  1501. 'article.updated_at',
  1502. 'article.introduce',
  1503. 'article.islink',
  1504. 'article.linkurl',
  1505. 'article.copyfrom',
  1506. 'article.cat_arr_id',
  1507. 'article.catid',
  1508. 'article.department_arr_id',
  1509. 'article.city_arr_id',
  1510. )
  1511. ->orderBy("updated_at", "desc")
  1512. ->offset(($data['page'] - 1) * $data['pageSize'])
  1513. ->limit($data['pageSize'])
  1514. ->get();
  1515. foreach ($articles as $k => $v) {
  1516. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1517. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1518. }
  1519. if (empty($articles)) {
  1520. return Result::error("没有符合条件的资讯数据");
  1521. }
  1522. $result = [
  1523. 'rows' => $articles,
  1524. 'count' => $count,
  1525. ];
  1526. return Result::success($result);
  1527. }
  1528. /**
  1529. * 模块新闻加强版
  1530. * @param array $data
  1531. * @return array
  1532. */
  1533. public function getWebsiteCatidArticle(array $data): array
  1534. {
  1535. $where = [
  1536. 'website_category.category_id' => $data['catid'],
  1537. 'website_category.website_id' => $data['website_id'],
  1538. ];
  1539. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1540. $child_catnum = $data['child_catnum'] ?? 1;
  1541. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1542. $childCategoryIds = array_column($category['child'], 'category_id');
  1543. if (empty($childCategoryIds)) {
  1544. return Result::error("暂无子栏目", 0);
  1545. }
  1546. $imgArticles = [];
  1547. $textArticles = [];
  1548. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1549. // 初始化子分类图片新闻和文字新闻数组
  1550. // 查询所有子级栏目的图文新闻
  1551. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1552. ->where(function ($query) use ($data) {
  1553. $query->where(function ($subQuery) use ($data) {
  1554. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1555. })->orWhereNull("ignore_ids");
  1556. })
  1557. ->where('status', 1)
  1558. ->where('imgurl', '!=', '')
  1559. ->select('*')
  1560. ->orderBy('updated_at', 'desc')
  1561. ->limit($data['child_imgnum'])
  1562. ->get();
  1563. }
  1564. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1565. // 查询所有子级栏目的文字新闻
  1566. $textArticles = Article::where('catid', $childCategoryIds[0])
  1567. ->where('status', 1)
  1568. ->where(function ($query) use ($data) {
  1569. $query->where(function ($subQuery) use ($data) {
  1570. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1571. })->orWhereNull("ignore_ids");
  1572. })
  1573. ->select('*')
  1574. ->orderBy('updated_at', 'desc')
  1575. ->limit($data['child_textnum'])
  1576. ->get();
  1577. }
  1578. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1579. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1580. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1581. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1582. return $child;
  1583. }, $category['child']);
  1584. }
  1585. // }
  1586. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1587. $category['img'] = WebsiteCategory::where($where)
  1588. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1589. ->where('article.status', 1)
  1590. ->where('article.imgurl', '!=', '')
  1591. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1592. ->orderBy('article.updated_at', 'desc')
  1593. ->limit($data['img_num'])
  1594. ->get();
  1595. }
  1596. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1597. $category['text'] = WebsiteCategory::where($where)
  1598. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1599. ->where('article.status', 1)
  1600. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1601. ->orderBy('article.updated_at', 'desc')
  1602. ->limit($data['text_num'])
  1603. ->get();
  1604. }
  1605. // $category = $category->get();
  1606. if (empty($category)) {
  1607. return Result::error("查询失败", 0);
  1608. }
  1609. return Result::success($category);
  1610. }
  1611. /**
  1612. * 模块新闻加强plus版
  1613. * @param array $data
  1614. * @return array
  1615. */
  1616. public function getWebsiteAllArticle(array $data): array
  1617. {
  1618. $time1 = microtime(true);
  1619. $wetbsite_id = $data['website_id'] ?? 2;
  1620. $data = json_decode($data['id'], true);
  1621. $categorys = $this->processArticlePro($wetbsite_id);
  1622. $cat_1st_arr = $categorys['cat_1st_arr'];
  1623. $catiall = $categorys['catiall'];
  1624. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1625. $parent_category = array_column($data, 'parent');
  1626. $parent_cat = [];
  1627. $child_category = array_column($data, 'child');
  1628. if (!empty($parent_category)) {
  1629. foreach ($parent_category as $key => $value) {
  1630. $arr = array_map('intval', explode(',', $value));
  1631. $parent_cat[$key] = $arr[0] ?? 0;
  1632. $parent_category = $arr[0] ?? 0;
  1633. $article_imgnum = $arr[1] ?? 0;
  1634. $article_textnum = $arr[2] ?? 0;
  1635. if ($parent_category != 0) {
  1636. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1637. // return Result::success($category_arr);
  1638. if ($article_imgnum != 0) {
  1639. $img_article = Article::whereIn('catid', $category_arr)
  1640. ->where('status', 1)
  1641. ->where('imgurl', '!=', '')
  1642. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1643. $query->from('article_ignore')
  1644. ->where('website_id', $wetbsite_id);
  1645. }, 'article_ignore', function ($join) {
  1646. $join->on('article_ignore.article_id', '=', 'article.id');
  1647. })
  1648. ->where(function ($query) use ($wetbsite_id) {
  1649. $query->whereNull('article_ignore.article_id')
  1650. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1651. })
  1652. ->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')
  1653. ->orderBy('updated_at', 'desc')
  1654. ->limit($article_imgnum)
  1655. ->get()->all();
  1656. foreach ($img_article as $k => $v) {
  1657. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1658. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1659. }
  1660. } else {
  1661. $img_article = [];
  1662. }
  1663. if ($article_textnum != 0) {
  1664. $text_article = Article::whereIn('catid', $category_arr)
  1665. ->where('status', 1)
  1666. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1667. $query->from('article_ignore')
  1668. ->where('website_id', $wetbsite_id);
  1669. }, 'article_ignore', function ($join) {
  1670. $join->on('article_ignore.article_id', '=', 'article.id');
  1671. })
  1672. ->where(function ($query) use ($wetbsite_id) {
  1673. $query->whereNull('article_ignore.article_id')
  1674. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1675. })
  1676. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1677. ->orderBy('updated_at', 'desc')
  1678. ->limit($article_textnum)
  1679. ->get()->all();
  1680. foreach ($text_article as $k => $v) {
  1681. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1682. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1683. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1684. }
  1685. } else {
  1686. $text_article = [];
  1687. }
  1688. $catiall[$parent_category]['imgnum'] = $img_article;
  1689. $catiall[$parent_category]['textnum'] = $text_article;
  1690. $parent[$key] = $catiall[$parent_category];
  1691. } else {
  1692. $parent[$key] = '';
  1693. }
  1694. }
  1695. }
  1696. if (!empty($child_category)) {
  1697. foreach ($child_category as $key => $value) {
  1698. $arr = array_map('intval', explode(',', $value));
  1699. $parent_category = $parent_cat[$key];
  1700. $child_category = $arr[0] ?? 0;
  1701. $article_imgnum = $arr[1] ?? 0;
  1702. $article_textnum = $arr[2] ?? 0;
  1703. if ($child_category != 0) {
  1704. $all_childcat = $cat_1st_arr[$parent_category];
  1705. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1706. // 从 $websiteInfoIndexed 中获取对应的数据
  1707. $info = $websiteInfoIndexed[$v];
  1708. // 返回一个包含所需信息的数组
  1709. return [
  1710. 'alias' => $info->alias,
  1711. 'category_id' => $info->category_id,
  1712. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1713. 'pid' => $info->pid,
  1714. 'type' => $info->type,
  1715. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1716. 'pinyin' => $info->pinyin,
  1717. ];
  1718. }, $all_childcat);
  1719. if ($article_imgnum != 0) {
  1720. $img_article = Article::where('catid', $child_category)
  1721. ->where('status', 1)
  1722. ->where('imgurl', '!=', '')
  1723. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1724. $query->from('article_ignore')
  1725. ->where('website_id', $wetbsite_id);
  1726. }, 'article_ignore', function ($join) {
  1727. $join->on('article_ignore.article_id', '=', 'article.id');
  1728. })
  1729. ->where(function ($query) use ($wetbsite_id) {
  1730. $query->whereNull('article_ignore.article_id')
  1731. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1732. })
  1733. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1734. ->orderBy('updated_at', 'desc')
  1735. ->limit($article_imgnum)
  1736. ->get()->all();
  1737. foreach ($img_article as $k => $v) {
  1738. // var_dump($v);
  1739. // var_dump($k);
  1740. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1741. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1742. }
  1743. } else {
  1744. $img_article = [];
  1745. }
  1746. if ($article_textnum != 0) {
  1747. $text_article = Article::where('catid', $child_category)
  1748. ->where('status', 1)
  1749. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1750. $query->from('article_ignore')
  1751. ->where('website_id', $wetbsite_id);
  1752. }, 'article_ignore', function ($join) {
  1753. $join->on('article_ignore.article_id', '=', 'article.id');
  1754. })
  1755. ->where(function ($query) use ($wetbsite_id) {
  1756. $query->whereNull('article_ignore.article_id')
  1757. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1758. })
  1759. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1760. ->orderBy('updated_at', 'desc')
  1761. ->limit($article_textnum)
  1762. ->get()->all();
  1763. foreach ($text_article as $k => $v) {
  1764. // var_dump($v);
  1765. // var_dump($k);
  1766. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1767. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1768. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1769. }
  1770. } else {
  1771. $text_article = [];
  1772. }
  1773. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1774. $catiall[$child_category]['imgnum'] = $img_article;
  1775. $catiall[$child_category]['textnum'] = $text_article;
  1776. $child[$key] = $catiall[$child_category];
  1777. // var_dump($pids);
  1778. } else {
  1779. $child[$key] = '';
  1780. }
  1781. }
  1782. }
  1783. foreach ($parent as $key => $value) {
  1784. $result[$key] = $value;
  1785. if (!empty($child[$key])) {
  1786. // var_dump($child[$key]);
  1787. $result[$key]['child'] = $child[$key];
  1788. // $value[$key]['child'] = $child[$key];
  1789. } else {
  1790. $result[$key]['child'] = [
  1791. "alias" => null,
  1792. "category_id" => null,
  1793. "type" => null,
  1794. "pinyin" => null,
  1795. "all_childcat" => [],
  1796. "imgnum" => [],
  1797. "textnum" => []
  1798. ];
  1799. }
  1800. }
  1801. return Result::success($result);
  1802. }
  1803. /**
  1804. * 辅助方法:获取文章列表
  1805. */
  1806. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1807. {
  1808. sleep(1);
  1809. $query = Article::where('article.status', 1)
  1810. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1811. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1812. ->where(function ($query) use ($website) {
  1813. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1814. })
  1815. ->leftJoin('website_category', function ($join) use ($website) {
  1816. $join->on('article.catid', '=', 'website_category.category_id')
  1817. ->where('website_category.website_id', '=', $website['website_id']);
  1818. })
  1819. ->select(
  1820. 'article.id',
  1821. 'article.title',
  1822. 'article.imgurl',
  1823. 'article.author',
  1824. 'article.updated_at',
  1825. 'article.introduce',
  1826. 'article.islink',
  1827. 'article.linkurl',
  1828. 'article.copyfrom',
  1829. 'article.cat_arr_id',
  1830. 'article.catid',
  1831. 'website_category.alias as category_name'
  1832. )
  1833. ->orderBy('updated_at', 'desc')
  1834. ->limit($limit);
  1835. // 如果是图片文章,添加图片URL条件
  1836. if ($isImageArticle) {
  1837. $query->where('imgurl', '!=', '');
  1838. } else {
  1839. // 文字文章不需要imgurl字段
  1840. $query->addSelect('article.introduce');
  1841. }
  1842. $articles = $query->get();
  1843. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1844. }
  1845. /**
  1846. * 乡村网-获取特殊新闻模块
  1847. * @param array $data
  1848. * @return array
  1849. */
  1850. public function getWebsiteArticles(array $data): array
  1851. {
  1852. $website_id = $data['website_id'];
  1853. $catids = json_decode($data['id'], true);
  1854. $parent_category = array_column($catids, 'parent');
  1855. if (!empty($parent_category) && is_array($parent_category)) {
  1856. $categorys = $this->processArticlePro($website_id);
  1857. $catiall = $categorys['catiall'];
  1858. $cat_1st_arr = $categorys['cat_1st_arr'];
  1859. // return Result::success($categorys);
  1860. foreach ($parent_category as $key => $value) {
  1861. $arr = array_map('intval', explode(',', $value));
  1862. $parent_category = $arr[0] ?? 0;
  1863. $article_imgnum = $arr[1] ?? 0;
  1864. $article_textnum = $arr[2] ?? 0;
  1865. if ($parent_category != 0) {
  1866. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1867. // return Result::success($category_arr);
  1868. if ($article_imgnum != 0) {
  1869. $img_article = Article::whereIn('catid', $category_arr)
  1870. ->where('status', 1)
  1871. ->where('imgurl', '!=', '')
  1872. ->leftJoinSub(function ($query) use ($website_id) {
  1873. $query->from('article_ignore')
  1874. ->where('website_id', $website_id);
  1875. }, 'article_ignore', function ($join) {
  1876. $join->on('article_ignore.article_id', '=', 'article.id');
  1877. })
  1878. ->where(function ($query) use ($website_id) {
  1879. $query->whereNull('article_ignore.article_id')
  1880. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1881. })
  1882. ->select(
  1883. 'id',
  1884. 'title',
  1885. 'imgurl',
  1886. 'author',
  1887. 'updated_at',
  1888. 'introduce',
  1889. 'islink',
  1890. 'linkurl',
  1891. 'copyfrom',
  1892. 'cat_arr_id',
  1893. 'catid as category_id'
  1894. )
  1895. ->orderBy('updated_at', 'desc')
  1896. ->limit($article_imgnum)
  1897. ->get()->all();
  1898. foreach ($img_article as $k => $v) {
  1899. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1900. // return Result::success($v);
  1901. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1902. }
  1903. } else {
  1904. $img_article = [];
  1905. }
  1906. if ($article_textnum != 0) {
  1907. $text_article = Article::whereIn('catid', $category_arr)
  1908. ->where('status', 1)
  1909. ->leftJoinSub(function ($query) use ($website_id) {
  1910. $query->from('article_ignore')
  1911. ->where('website_id', $website_id);
  1912. }, 'article_ignore', function ($join) {
  1913. $join->on('article_ignore.article_id', '=', 'article.id');
  1914. })
  1915. ->where(function ($query) use ($website_id) {
  1916. $query->whereNull('article_ignore.article_id')
  1917. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1918. })
  1919. ->select(
  1920. 'id',
  1921. 'title',
  1922. 'author',
  1923. 'updated_at',
  1924. 'introduce',
  1925. 'islink',
  1926. 'linkurl',
  1927. 'copyfrom',
  1928. 'cat_arr_id',
  1929. 'catid as category_id'
  1930. )
  1931. ->orderBy('updated_at', 'desc')
  1932. ->limit($article_textnum)
  1933. ->get()->all();
  1934. foreach ($text_article as $k => $v) {
  1935. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1936. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1937. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1938. }
  1939. } else {
  1940. $text_article = [];
  1941. }
  1942. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  1943. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  1944. $parent[$key] = $catiall[$parent_category];
  1945. } else {
  1946. $parent[$key] = [];
  1947. }
  1948. }
  1949. }
  1950. return Result::success($parent);
  1951. }
  1952. // 封装处理商品的路由问题
  1953. function processGoods($goods, $data)
  1954. {
  1955. return $goods->map(function ($good) use ($data) {
  1956. $catid = $good->catid ?? 0;
  1957. // $pinyin = '';
  1958. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1959. if (!empty($category->pid) && $category->pid != 0) {
  1960. $level = json_decode($category->category_arr_id, true);
  1961. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1962. ->whereIn('category_id', $level)
  1963. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1964. ->get(['aLIas_pinyin'])
  1965. ->pluck('aLIas_pinyin')
  1966. ->implode('/');
  1967. } else {
  1968. $pinyin = $category->aLIas_pinyin ?? '';
  1969. }
  1970. if (isset($good->city_id) && !empty($good->city_id)) {
  1971. $city = District::where('id', $good->city_id)->first(['name']);
  1972. $good->city_name = $city->name ?? '';
  1973. }
  1974. // 解析imgurl JSON并取第一条数据
  1975. $imgUrls = json_decode($good->imgurl, true);
  1976. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1977. $good->pinyin = $pinyin;
  1978. return $good;
  1979. });
  1980. }
  1981. /**
  1982. * 获取商城首页-根据栏目id
  1983. * @param array $data
  1984. * @return array
  1985. * */
  1986. function getWebsiteCatidshop(array $data): array
  1987. {
  1988. $input['catid'] = $data['catid'];
  1989. $input['website_id'] = $data['website_id'];
  1990. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1991. $result = array_map(function ($item) use ($input) {
  1992. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1993. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1994. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1995. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1996. if (empty($category) || $category->type != 2) {
  1997. return Result::error("暂无此栏目", 0);
  1998. } else {
  1999. $website['website_id'] = $input['website_id'];
  2000. $goods = Good::where('good.status', 2)
  2001. ->where('good.website_id', $website['website_id'])
  2002. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2003. ->select(
  2004. 'good.id',
  2005. 'good.name',
  2006. 'good.imgurl',
  2007. 'good.description',
  2008. 'good.updated_at',
  2009. 'good.catid',
  2010. 'good.type_id',
  2011. 'good.price',
  2012. 'good.com',
  2013. 'good.level',
  2014. 'good.unit'
  2015. )
  2016. ->orderBy('updated_at', 'desc')
  2017. ->offset($goodStart)
  2018. ->limit($goodNum);
  2019. $all_goods = $goods->get();
  2020. $all_goods = $this->processGoods($all_goods, $website);
  2021. }
  2022. return $all_goods ?? [];
  2023. }
  2024. }, $data);
  2025. return Result::success($result);
  2026. }
  2027. /**
  2028. * 获取商品模块
  2029. * @param array $data
  2030. * @return array
  2031. * */
  2032. public function getWebsiteshop(array $data): array
  2033. {
  2034. $input['id'] = $data['id'];
  2035. $input['website_id'] = $data['website_id'];
  2036. $catid = $data['catid'];
  2037. $data = json_decode($input['id'] ?? '', true) ?? [];
  2038. $result['goods'] = array_map(function ($item) use ($input) {
  2039. // 检查parent元素是否存在且不是undefined
  2040. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2041. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2042. $website = $input['website_id'];
  2043. $query = Good::where('good.status', 2)
  2044. ->where('good.website_id', $website);
  2045. switch ($Levelid) {
  2046. case 1:
  2047. case 2:
  2048. case 3:
  2049. $goods = $query->where(function ($q) use ($Levelid) {
  2050. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2051. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2052. });
  2053. break;
  2054. case 4:
  2055. $goods = $query;
  2056. break;
  2057. case 5:
  2058. $goods = $query->where('type_id', 1);
  2059. break;
  2060. case 6:
  2061. $goods = $query->where('type_id', 2);
  2062. break;
  2063. default:
  2064. return [];
  2065. }
  2066. $all_goods = $goods
  2067. ->select(
  2068. 'good.id',
  2069. 'good.name',
  2070. 'good.imgurl',
  2071. 'good.description',
  2072. 'good.updated_at',
  2073. 'good.catid',
  2074. 'good.type_id',
  2075. 'good.price',
  2076. 'good.level',
  2077. 'good.website_id'
  2078. )
  2079. ->orderBy('updated_at', 'desc')
  2080. ->offset($goodStart)
  2081. ->limit($goodNum)
  2082. ->get();
  2083. $web['website_id'] = $website;
  2084. $all_goods = $this->processGoods($all_goods, $web);
  2085. }
  2086. return $all_goods;
  2087. }, $data);
  2088. $website = $input['website_id'];
  2089. $result['article'] = Article::where(function ($query) use ($website) {
  2090. $query->where(function ($subQuery) use ($website) {
  2091. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2092. })->orWhereNull("ignore_ids");
  2093. })
  2094. ->where('catid', $catid)
  2095. ->where('article.status', 1)
  2096. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2097. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2098. ->orderBy('article.updated_at', 'desc')
  2099. ->first();
  2100. return Result::success($result);
  2101. }
  2102. /**
  2103. * 获取商品分类
  2104. * @param array $data
  2105. * @return array
  2106. * */
  2107. public function getWebsiteshopCat(array $data): array
  2108. {
  2109. $website = $data['website_id'];
  2110. $category = WebsiteCategory::where('website_id', $website)
  2111. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2112. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2113. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2114. ->orderBy('sort')
  2115. ->get();
  2116. $cat = $category->map(function ($item) use ($website) {
  2117. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2118. $pid = $item->pid ?? 0;
  2119. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2120. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2121. ->where('website_id', $website)
  2122. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2123. ->get(['aLIas_pinyin'])
  2124. ->pluck('aLIas_pinyin')
  2125. ->implode('/');
  2126. } else {
  2127. $pinyin = $item->aLIas_pinyin ?? '';
  2128. }
  2129. $item->pinyin = $pinyin;
  2130. });
  2131. if (empty($category)) {
  2132. return Result::error("栏目查询失败", 0);
  2133. }
  2134. $cat_tree = Result::buildMenuTree($category);
  2135. $web['website_id'] = $website;
  2136. $goods = Good::where('website_id', $website)
  2137. ->where('status', 2)
  2138. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2139. ->latest('updated_at')
  2140. ->offset(($data['page'] - 1) * $data['pageSize'])
  2141. ->limit($data['pageSize'])
  2142. ->get();
  2143. if (!empty($goods)) {
  2144. if ($goods->count() > 1 && !empty($goods)) {
  2145. $goods = $this->processGoods($goods, $web);
  2146. }
  2147. } else {
  2148. $goods = [];
  2149. }
  2150. $result = [
  2151. 'category' => $cat_tree,
  2152. 'goods' => $goods,
  2153. ];
  2154. // $resul['goods'] = $goods;
  2155. if (empty($result)) {
  2156. return Result::error("查询失败", 0);
  2157. }
  2158. return Result::success($result);
  2159. }
  2160. /*
  2161. * 获取商品列表
  2162. * @param array $data
  2163. * @return array
  2164. * */
  2165. public function getWebsiteshopList(array $data): array
  2166. {
  2167. // return Result::success($data);
  2168. $where = [
  2169. 'status' => 2,
  2170. 'website_id' => $data['website_id'],
  2171. ];
  2172. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2173. // return Result::error("查询失败", 0);
  2174. // }
  2175. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2176. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2177. $data['catid'] = $category->category_id ?? 0;
  2178. }
  2179. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2180. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2181. }
  2182. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2183. array_push($where, ['type_id', $data['type_id']]);
  2184. }
  2185. $query = Good::where($where)
  2186. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2187. $query->where(function ($q) use ($data) {
  2188. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2189. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2190. });
  2191. })
  2192. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2193. $query->where(function ($q) use ($data) {
  2194. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2195. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2196. });
  2197. })
  2198. ->select(
  2199. 'good.id',
  2200. 'good.name',
  2201. 'good.imgurl',
  2202. 'good.description',
  2203. 'good.updated_at',
  2204. 'good.com',
  2205. 'good.catid',
  2206. 'good.type_id',
  2207. 'good.website_id',
  2208. 'good.cat_arr_id',
  2209. 'good.created_at',
  2210. 'good.city_id'
  2211. )
  2212. ->latest('updated_at');
  2213. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2214. $result['count'] = $query->clone()->count();
  2215. $result['goods'] = $this->processGoods(
  2216. $query->clone()
  2217. ->offset(($data['page'] - 1) * $data['pageSize'])
  2218. ->limit($data['pageSize'])
  2219. ->get(),
  2220. $data
  2221. );
  2222. } else {
  2223. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2224. // 获取 type_id 为 1 的数据
  2225. $result['type1'] = $this->processGoods(
  2226. $query->clone()
  2227. ->where('type_id', 1)
  2228. ->offset(($data['page'] - 1) * $data['pageSize'])
  2229. ->limit($data['pageSize'])
  2230. ->get(),
  2231. $data
  2232. );
  2233. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2234. // 获取 type_id 为 2 的数据
  2235. $result['type2'] = $this->processGoods(
  2236. $query->clone()
  2237. ->where('type_id', 2)
  2238. ->offset(($data['page'] - 1) * $data['pageSize'])
  2239. ->limit($data['pageSize'])
  2240. ->get(),
  2241. $data
  2242. );
  2243. }
  2244. if (empty($result)) {
  2245. return Result::error("查询失败", 0);
  2246. }
  2247. return Result::success($result);
  2248. }
  2249. /**
  2250. * 获取商品详情
  2251. * @param array $data
  2252. * @return array
  2253. * */
  2254. public function getWebsiteshopInfo(array $data): array
  2255. {
  2256. $where = [
  2257. 'good.status' => 2,
  2258. 'good.website_id' => $data['website_id'],
  2259. 'good.id' => $data['id'],
  2260. ];
  2261. $goods = Good::where($where)
  2262. ->where('good.id', $data['id'])
  2263. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2264. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2265. ->first();
  2266. if (empty($goods)) {
  2267. return Result::error("查询失败", 0);
  2268. }
  2269. $goods->imgurl = json_decode($goods->imgurl, true);
  2270. return Result::success($goods);
  2271. }
  2272. /**
  2273. * plus pro 处理文章路由问题
  2274. */
  2275. function processArticlePro($website_id)
  2276. {
  2277. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2278. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2279. // 取出category_id 对应的aLIas_pinyin
  2280. $categoryIds = array_column($categorys, 'category_id');
  2281. $categoryPIds = array_column($categorys, 'pid');
  2282. $aliasPinyins = array_column($categorys, 'aLIas_pinyin');
  2283. $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2284. // return Result::success($categorys);
  2285. $catiall = [];
  2286. //一级所有子级的记录
  2287. $cat_1st_arr = [];
  2288. foreach ($categorys as $key => $value) {
  2289. $category_arr_id = json_decode($value->category_arr_id);
  2290. $pinyin_str = '';
  2291. // 算出一级 并且算出子级
  2292. if ($value->pid != 0) {
  2293. $cat_1st_arr[$value->pid][] = $value->category_id;
  2294. }
  2295. foreach ($category_arr_id as $k => $v) {
  2296. $pinyin_str .= $cat_arr[$v] . '/';
  2297. }
  2298. $pinyin_str = rtrim($pinyin_str, '/');
  2299. $catiall[$value->category_id]['alias'] = $value->alias;
  2300. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2301. $catiall[$value->category_id]['type'] = $value->type;
  2302. $catiall[$value->category_id]['pinyin'] = $pinyin_str;
  2303. $websiteInfoIndexed[$value->category_id]->pinyin = $pinyin_str;
  2304. }
  2305. return [
  2306. 'cat_1st_arr' => $cat_1st_arr,
  2307. 'catiall' => $catiall,
  2308. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2309. 'categoryIds' => $categoryIds,
  2310. ];
  2311. }
  2312. /**
  2313. * 封装处理文章的路由问题
  2314. * */
  2315. function processArticles($articles, $data)
  2316. {
  2317. // 检查 $articles 是否为数组或可迭代对象
  2318. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2319. return $articles->map(function ($article) use ($data) {
  2320. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2321. $catid = $article->cat_arr_id ?? '';
  2322. }
  2323. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2324. $catid = $article->category_arr_id ?? '';
  2325. }
  2326. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2327. $level = json_decode($catid, true);
  2328. if (!is_array($level)) {
  2329. return $article;
  2330. } else {
  2331. $level = array_map('intval', $level);
  2332. }
  2333. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2334. ->where($data)
  2335. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2336. ->pluck('aLIas_pinyin')
  2337. ->implode('/');
  2338. $article->pinyin = $pinyin ?? '';
  2339. return $article;
  2340. });
  2341. } else {
  2342. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2343. $catid = $articles->cat_arr_id ?? '';
  2344. $level = json_decode($catid, true);
  2345. if (!is_array($level)) {
  2346. return $articles;
  2347. } else {
  2348. $level = array_map('intval', $level);
  2349. }
  2350. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2351. ->where($data)
  2352. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2353. ->pluck('aLIas_pinyin')
  2354. ->implode('/');
  2355. $articles->pinyin = $pinyin ?? '';
  2356. return $articles;
  2357. }
  2358. }
  2359. // 封装处理由问题
  2360. function processJob($job, $data)
  2361. {
  2362. return $job->map(function ($job) use ($data) {
  2363. $category = $job->cat_arr_id ?? '';
  2364. $cityid = $job->city_arr_id ?? '';
  2365. $city = json_decode($cityid, true);
  2366. $pinyin = '';
  2367. $level = json_decode($category, true);
  2368. // 路由
  2369. if (!empty($level) && is_array($level)) {
  2370. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2371. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2372. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2373. ->get(['aLIas_pinyin'])
  2374. ->pluck('aLIas_pinyin')
  2375. ->implode('/');
  2376. if (empty($pinyin)) {
  2377. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2378. }
  2379. $job->pinyin = $pinyin;
  2380. }
  2381. // 取职位-城市 市??省
  2382. if (!empty($city) && is_array($city)) {
  2383. if (isset($city[1]) && !empty($city[1])) {
  2384. $city = District::where('id', $city[1])->first(['name']);
  2385. $job->city_name = $city->name ?? '';
  2386. } else if (isset($city[0]) && !empty($city[0])) {
  2387. $city = District::where('id', $city[0])->first(['name']);
  2388. $job->city_name = $city->name ?? '';
  2389. } else {
  2390. $job->city_name = '全国';
  2391. }
  2392. }
  2393. // 获取简历最后一级地区
  2394. if (isset($job->city_id) && !empty($job->city_id)) {
  2395. $city = District::where('id', $job->city_id)->first(['name']);
  2396. $job->hunt_cityname = $city->name ?? '';
  2397. }
  2398. // 组合详细地址
  2399. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2400. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2401. if (is_array($address_id) && !empty($address_id)) {
  2402. $address = District::whereIn('id', $address_id)
  2403. ->orderBy('level', 'asc')
  2404. ->get(['name'])
  2405. ->pluck('name')
  2406. ->implode('');
  2407. // $job->address_name = $address ?? '';
  2408. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2409. }
  2410. }
  2411. // 取行业
  2412. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2413. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2414. if (!empty($job->industry)) {
  2415. $query->where('hyid', $job->industry);
  2416. } else if (!empty($job->hy_id)) {
  2417. $query->where('hyid', $job->hy_id);
  2418. } else if (!empty($job->company_hy_id)) {
  2419. $query->where('hyid', $job->company_hy_id);
  2420. } else {
  2421. $query->where('hyid', $job->job_industry);
  2422. }
  2423. })->first(['hyname']);
  2424. $job->hy_name = $hy_name->hyname ?? '';
  2425. }
  2426. // 取职位类别
  2427. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2428. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2429. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2430. $job->zw_name = $zw_name->zwname ?? '';
  2431. }
  2432. // 取具体职位
  2433. 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))) {
  2434. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2435. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2436. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2437. }
  2438. // 取工作经验
  2439. if (isset($job->experience) && !empty($job->experience)) {
  2440. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2441. $job->experience_name = $experience->ename ?? '';
  2442. }
  2443. // 取学历
  2444. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2445. $education = $job->educational ?? $job->school_education;
  2446. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2447. $job->education_name = $education->ename ?? '';
  2448. }
  2449. // 语言
  2450. if (isset($job->language) && !empty($job->language)) {
  2451. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2452. $job->language_name = $language->ename ?? '';
  2453. }
  2454. // 薪资
  2455. if (isset($job->salary) && !empty($job->salary)) {
  2456. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2457. $job->salary_name = $salary->ename ?? '';
  2458. }
  2459. // 职位性质
  2460. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2461. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2462. $job->job_nature_name = $job_nature->ename ?? '';
  2463. }
  2464. // 公司规模
  2465. if (isset($job->company_size) && !empty($job->company_size)) {
  2466. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2467. $job->company_size_name = $company_size->ename ?? '';
  2468. }
  2469. // 公司性质
  2470. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2471. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2472. $job->company_nature_name = $company_nature->nature_name ?? '';
  2473. }
  2474. // $job->pinyin = $pinyin;
  2475. return $job;
  2476. });
  2477. }
  2478. /**
  2479. * 获取书籍模块
  2480. * @param array $data
  2481. * @return array
  2482. * */
  2483. public function getWebsiteBook(array $data): array
  2484. {
  2485. $input['id'] = $data['id'];
  2486. $input['website_id'] = $data['website_id'];
  2487. // 将 JSON 字符串转换为 PHP 数组
  2488. $data = json_decode($input['id'], true);
  2489. // 使用 array_map 处理每个元素
  2490. $result = array_map(function ($item) use ($input) {
  2491. // 检查parent元素是否存在且不是undefined
  2492. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2493. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2494. $website = [
  2495. 'website_id' => $input['website_id'],
  2496. ];
  2497. // 查询栏目名称
  2498. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2499. if (empty($category)) {
  2500. $parent_alias = '';
  2501. $parent_pinyin = null;
  2502. $imgBooks = [];
  2503. $textBooks = [];
  2504. } else {
  2505. $parent_alias = $category->alias ?? '';
  2506. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2507. // 查找子分类ID数组
  2508. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2509. array_push($childCategoryIds, $parentCatId);
  2510. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2511. if ($parentImgNum != 0) {
  2512. // 查询图片新闻
  2513. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2514. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2515. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2516. })
  2517. ->where('book.status', 2)
  2518. ->where('book.img_url', '!=', '')
  2519. ->leftJoin('website_category', function ($join) use ($website) {
  2520. $join->on('book.cat_id', '=', 'website_category.category_id')
  2521. ->where('website_category.website_id', '=', $website['website_id']);
  2522. })
  2523. ->select(
  2524. 'book.id',
  2525. 'book.title',
  2526. 'book.img_url',
  2527. 'book.price',
  2528. 'book.market_price',
  2529. 'book.description',
  2530. 'book.cat_id',
  2531. 'book.description',
  2532. 'book.updated_at',
  2533. 'website_category.alias as category_name',
  2534. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2535. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2536. )
  2537. ->orderBy('updated_at', 'desc')
  2538. ->limit($parentImgNum)
  2539. ->get()->all();
  2540. // 查询文字新闻
  2541. }
  2542. if ($parentTextNum != 0) {
  2543. $textBooks = [];
  2544. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2545. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2546. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2547. })
  2548. ->where('book.status', 2)
  2549. ->leftJoin('website_category', function ($join) use ($website) {
  2550. $join->on('book.cat_id', '=', 'website_category.category_id')
  2551. ->where('website_category.website_id', '=', $website['website_id']);
  2552. })
  2553. ->select(
  2554. 'book.id',
  2555. 'book.title',
  2556. 'book.img_url',
  2557. 'book.price',
  2558. 'book.market_price',
  2559. 'book.description',
  2560. 'book.cat_id',
  2561. 'book.description',
  2562. 'book.updated_at',
  2563. 'website_category.alias as category_name',
  2564. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2565. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2566. )
  2567. ->orderBy('updated_at', 'desc')
  2568. ->limit($parentTextNum)
  2569. ->get()->all();
  2570. }
  2571. }
  2572. }
  2573. $resultItem = [
  2574. 'alias' => $parent_alias ?? '',
  2575. 'category_id' => $parentCatId ?? 0,
  2576. 'pinyin' => $parent_pinyin ?? null,
  2577. 'imgnum' => $imgBooks ?? [],
  2578. 'textnum' => $textBooks ?? [],
  2579. ];
  2580. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2581. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2582. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2583. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2584. ->get()->all();
  2585. if (!empty($childCategory)) {
  2586. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2587. // 查询子栏目名称
  2588. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2589. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2590. ->first();
  2591. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2592. $childImgArticles = [];
  2593. $childTextArticles = [];
  2594. $resultItem['child'] = [];
  2595. } else {
  2596. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2597. // 查询子栏目图片新闻
  2598. $childImgArticles = Book::where('cat_id', $childCatId)
  2599. ->where('status', 2)
  2600. ->where('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. DB::raw("'$child_pinyin' as pinyin")
  2616. )
  2617. ->orderBy('updated_at', 'desc')
  2618. ->limit($childImgNum)
  2619. ->get()->all();
  2620. // 查询子栏目文字新闻
  2621. $childTextArticles = Book::where('cat_id', $childCatId)
  2622. ->where('status', 2)
  2623. ->leftJoin('website_category', function ($join) use ($website) {
  2624. $join->on('book.cat_id', '=', 'website_category.category_id')
  2625. ->where('website_category.website_id', '=', $website['website_id']);
  2626. })
  2627. ->select(
  2628. 'book.id',
  2629. 'book.title',
  2630. 'book.img_url',
  2631. 'book.price',
  2632. 'book.market_price',
  2633. 'book.description',
  2634. 'book.cat_id',
  2635. 'book.description',
  2636. 'book.updated_at',
  2637. DB::raw("'$child_pinyin' as pinyin")
  2638. )
  2639. ->orderBy('updated_at', 'desc')
  2640. ->limit($childTextNum)
  2641. ->get()->all();
  2642. $resultItem['child'] = [
  2643. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2644. 'category_id' => $childCatId,
  2645. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2646. 'all_childcat' => $childCategory,
  2647. 'imgnum' => $childImgArticles,
  2648. 'textnum' => $childTextArticles,
  2649. ];
  2650. }
  2651. }
  2652. } else {
  2653. $resultItem['child'] = [];
  2654. }
  2655. return $resultItem;
  2656. }, $data);
  2657. return Result::success($result);
  2658. }
  2659. /**
  2660. * 获取书刊列表
  2661. * @param array $data
  2662. * @return array
  2663. * */
  2664. public function getWebsiteBookList(array $data): array
  2665. {
  2666. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2667. if (empty($web)) {
  2668. return Result::error("查询失败", 0);
  2669. }
  2670. $catid = $data['id'];
  2671. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2672. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2673. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2674. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2675. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2676. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2677. ->where('pid', $category['pid'])
  2678. ->select(
  2679. 'category_id',
  2680. 'alias',
  2681. 'aLIas_pinyin',
  2682. 'pid',
  2683. 'sort',
  2684. 'is_url',
  2685. 'web_url',
  2686. 'seo_title',
  2687. 'seo_keywords',
  2688. 'seo_description',
  2689. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2690. )
  2691. ->orderBy('sort')
  2692. ->get()->all();
  2693. if (empty($category)) {
  2694. return Result::error("查询失败", 0);
  2695. }
  2696. $query = Book::where('book.status', 2)
  2697. ->where('book.website_id', $data['website_id'])
  2698. ->where('book.cat_id', $catid)
  2699. ->select(
  2700. 'book.id',
  2701. 'book.title',
  2702. 'book.img_url',
  2703. 'book.description',
  2704. 'book.updated_at',
  2705. 'book.cat_id',
  2706. DB::raw("'$pinyin' as pinyin")
  2707. )
  2708. ->orderBy('book.updated_at', 'desc');
  2709. $count = $query->count();
  2710. $query = clone $query;
  2711. $Book = $query
  2712. ->limit($data['pageSize'])
  2713. ->offset(($data['page'] - 1) * $data['pageSize'])
  2714. ->get()->all();
  2715. $result = [
  2716. 'category' => $categorys,
  2717. 'books' => $Book,
  2718. 'count' => $count,
  2719. ];
  2720. // if(empty($result)){
  2721. // return Result::error("查询失败", 0);
  2722. // }
  2723. return Result::success($result);
  2724. }
  2725. /**
  2726. * 获取书刊详情
  2727. * @param array $data
  2728. * @return array
  2729. * */
  2730. public function getWebsiteBookInfo(array $data): array
  2731. {
  2732. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2733. if (empty($web)) {
  2734. return Result::error("查询失败", 0);
  2735. }
  2736. $book = Book::where('status', 2)
  2737. ->where('website_id', $data['website_id'])
  2738. ->where('id', $data['id'])
  2739. ->select(
  2740. 'book.*',
  2741. )
  2742. ->orderBy('updated_at', 'desc')
  2743. ->first();
  2744. if (empty($book)) {
  2745. return Result::error("查询失败", 0);
  2746. }
  2747. // 先查询当前分类的 pid
  2748. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2749. ->where('category_id', $book['cat_id'])
  2750. ->first(['pid', 'category_id']);
  2751. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2752. if (!empty($carpid)) {
  2753. if ($carpid->pid != 0) {
  2754. $pid = $carpid['pid'];
  2755. // $parent_pinyin = '';
  2756. } else {
  2757. $pid = $carpid['category_id'];
  2758. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2759. }
  2760. }
  2761. $categorys = $query->where('pid', $pid)
  2762. ->select(
  2763. 'category_id',
  2764. 'alias',
  2765. 'aLIas_pinyin',
  2766. 'pid',
  2767. 'sort',
  2768. 'is_url',
  2769. 'web_url',
  2770. 'category_arr_id as cat_arr_id',
  2771. )
  2772. ->orderBy('sort')
  2773. ->get();
  2774. $category = $this->processArticle($categorys, $data);
  2775. $result = [
  2776. 'category' => $category,
  2777. 'books' => $book,
  2778. ];
  2779. return Result::success($result);
  2780. }
  2781. /**
  2782. * 尝试
  2783. * @param array $data
  2784. * @return array
  2785. * */
  2786. public function test(array $data): array
  2787. {
  2788. $input['id'] = $data['id'];
  2789. $input['website_id'] = $data['website_id'];
  2790. // 将 JSON 字符串转换为 PHP 数组
  2791. $data = json_decode($input['id'], true);
  2792. $result = [];
  2793. $article = $data;
  2794. $result = array_map(function ($item) use ($input) {
  2795. $website = [
  2796. 'website_id' => $input['website_id'],
  2797. ];
  2798. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2799. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2800. $parent = [
  2801. 0 => $category['category_id'] ?? [],
  2802. 1 => $parentImgNum ?? [],
  2803. 2 => $parentTextNum ?? [],
  2804. ];
  2805. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2806. $child = [];
  2807. $resultItem = [
  2808. // 'alias' => $parent_alias ?? '',
  2809. 'category_id' => $parentCatId ?? 0,
  2810. 'pinyin' => $parentImgNum ?? null,
  2811. 'imgnum' => $parentTextNum ?? [],
  2812. // 'textnum' => $textArticles ?? [],
  2813. ];
  2814. return $parent;
  2815. }, $data);
  2816. return Result::success($result);
  2817. // });
  2818. }
  2819. /**
  2820. * 封装处理文章的路由问题
  2821. * */
  2822. function processArticle($article, $data)
  2823. {
  2824. return $article->map(function ($article) use ($data) {
  2825. $catid = $article->cat_arr_id ?? '';
  2826. $level = json_decode($catid, true);
  2827. $pinyin = '';
  2828. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2829. if (!empty($level) && is_array($level)) {
  2830. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2831. ->where('website_id', $data['website_id'])
  2832. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2833. ->get(['aLIas_pinyin'])
  2834. ->pluck('aLIas_pinyin')
  2835. ->implode('/');
  2836. } else {
  2837. $pinyin = '';
  2838. }
  2839. $article->pinyin = $pinyin;
  2840. return $article;
  2841. });
  2842. }
  2843. /**
  2844. * c端-获取招工招聘下拉选框
  2845. * @param array $data
  2846. * @return array
  2847. * */
  2848. public function getWebsiteJobSelect(array $data): array
  2849. {
  2850. $web = Website::where('id', $data['website_id'])->first();
  2851. if (empty($web)) {
  2852. return Result::error("该网站不存在", 0);
  2853. }
  2854. $hy = JobIndustry::get()->all();
  2855. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2856. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2857. $result = [
  2858. 'hy' => $hy,
  2859. 'zw' => $zw,
  2860. 'jtzw' => $jtzw,
  2861. ];
  2862. if (empty($result)) {
  2863. return Result::error("查询失败", 0);
  2864. }
  2865. return Result::success($result);
  2866. }
  2867. /**
  2868. * c端-获取招工招聘
  2869. * @param array $data
  2870. * @return array
  2871. * */
  2872. public function getWebsiteJob(array $data): array
  2873. {
  2874. $web = Website::where('id', $data['website_id'])->first();
  2875. if (empty($web)) {
  2876. return Result::error("该网站不存在", 0);
  2877. }
  2878. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2879. ->where('job_hunting.website_id', $data['website_id'])
  2880. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2881. $query->where(function ($q) use ($data) {
  2882. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2883. });
  2884. })
  2885. ->select(
  2886. 'job_hunting.id',
  2887. 'job_hunting.cat_arr_id',
  2888. 'job_hunting.job_name_get',
  2889. 'job_hunting.industry',
  2890. 'job_hunting.name',
  2891. 'job_hunting.sexy',
  2892. 'job_hunting.origin',
  2893. 'job_hunting.city_arr_id',
  2894. 'job_hunting.experience',
  2895. 'job_hunting.updated_at',
  2896. 'job_hunting.salary'
  2897. )
  2898. ->orderBy('updated_at', 'desc')
  2899. ->limit($data['job1_num'])
  2900. ->get();
  2901. $web['website_id'] = $data['website_id'];
  2902. if (empty($job_hunting)) {
  2903. $job_huntings = "未查询到相关简历信息";
  2904. } else {
  2905. $job_huntings = $this->processJob($job_hunting, $web);
  2906. }
  2907. // 0:待审核 1:已通过 2:已拒绝
  2908. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2909. ->where('job_recruiting.website_id', $data['website_id'])
  2910. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2911. $query->where(function ($q) use ($data) {
  2912. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2913. });
  2914. })
  2915. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2916. ->select(
  2917. 'job_recruiting.id',
  2918. 'job_recruiting.cat_arr_id',
  2919. 'job_recruiting.title',
  2920. 'job_recruiting.jtzw_id',
  2921. 'job_recruiting.hy_id',
  2922. 'job_recruiting.city_arr_id',
  2923. 'job_recruiting.due_data',
  2924. 'job_recruiting.updated_at',
  2925. 'job_recruiting.experience',
  2926. 'job_recruiting.educational',
  2927. 'job_recruiting.salary',
  2928. 'job_recruiting.zw_id',
  2929. 'job_company.business_name'
  2930. )
  2931. ->orderBy('updated_at', 'desc')
  2932. ->limit($data['job2_num'])
  2933. ->get();
  2934. if (empty($job_recruiting->toArray())) {
  2935. $job_recruitings = "未查询到相关职位信息";
  2936. } else {
  2937. $job_recruitings = $this->processJob($job_recruiting, $web);
  2938. }
  2939. $result = [
  2940. 'job_hunting' => $job_huntings,
  2941. 'job_recuiting' => $job_recruitings,
  2942. ];
  2943. return Result::success($result);
  2944. }
  2945. /**
  2946. * c端-获取招工招聘列表
  2947. * @param array $data
  2948. * @return array
  2949. * */
  2950. public function getWebsiteJobList(array $data): array
  2951. {
  2952. $recruit_where = [];
  2953. $hunt_where = [];
  2954. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2955. if (empty($web)) {
  2956. return Result::error("此网站不存在", 0);
  2957. }
  2958. $website_id['website_id'] = $data['website_id'];
  2959. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2960. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2961. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2962. }
  2963. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2964. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2965. }
  2966. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2967. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2968. }
  2969. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2970. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  2971. }
  2972. $query = JobRecruiting::where('job_recruiting.status', 1)
  2973. ->where('job_recruiting.website_id', $data['website_id'])
  2974. ->where($recruit_where)
  2975. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2976. $query->where(function ($q) use ($data) {
  2977. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2978. });
  2979. })
  2980. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2981. $query->where(function ($q) use ($data) {
  2982. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2983. });
  2984. })
  2985. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2986. ->select(
  2987. 'job_recruiting.id',
  2988. 'job_recruiting.hy_id',
  2989. 'job_recruiting.title',
  2990. 'job_recruiting.zw_id',
  2991. 'job_recruiting.educational',
  2992. 'job_recruiting.jtzw_id',
  2993. 'job_recruiting.city_arr_id',
  2994. 'job_recruiting.due_data',
  2995. 'job_recruiting.experience',
  2996. 'job_recruiting.cat_arr_id',
  2997. 'job_recruiting.updated_at',
  2998. 'job_company.business_name'
  2999. )
  3000. ->orderBy('job_recruiting.updated_at', 'desc');
  3001. $recruit_count = $query->count();
  3002. $query = clone $query;
  3003. $JobRecruiting = $query
  3004. ->offset(($data['page'] - 1) * $data['pageSize'])
  3005. ->limit($data['pageSize'])
  3006. ->get();
  3007. if (empty($JobRecruiting)) {
  3008. $JobRecruiting = "暂无相关职位信息";
  3009. } else {
  3010. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3011. }
  3012. }
  3013. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3014. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3015. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3016. }
  3017. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3018. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3019. }
  3020. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3021. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3022. }
  3023. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3024. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3025. }
  3026. $query = JobHunting::where('job_hunting.status', 2)
  3027. ->where('job_hunting.website_id', $data['website_id'])
  3028. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3029. ->where($hunt_where)
  3030. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3031. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3032. // })
  3033. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3034. $query->where(function ($q) use ($data) {
  3035. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3036. });
  3037. })
  3038. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3039. $query->where(function ($q) use ($data) {
  3040. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3041. });
  3042. })
  3043. ->select(
  3044. 'job_hunting.id',
  3045. 'job_hunting.sexy',
  3046. 'job_hunting.experience',
  3047. 'job_hunting.origin',
  3048. 'job_hunting.industry',
  3049. 'job_hunting.name',
  3050. 'job_hunting.job',
  3051. 'job_hunting.job_name_get',
  3052. 'job_hunting.city_arr_id',
  3053. 'job_hunting.cat_arr_id',
  3054. 'job_hunting.created_at',
  3055. 'job_hunting.updated_at',
  3056. 'job_position.zwname as job_name'
  3057. )
  3058. ->orderBy('job_hunting.updated_at', 'desc');
  3059. $hunt_count = $query->count();
  3060. $query = clone $query;
  3061. $JobHunting = $query
  3062. ->offset(($data['page'] - 1) * $data['pageSize'])
  3063. ->limit($data['pageSize'])
  3064. ->get();
  3065. if (empty($JobHunting)) {
  3066. $JobRecruiting = "暂无相关简历信息";
  3067. } else {
  3068. $JobHunting = $this->processJob($JobHunting, $website_id);
  3069. }
  3070. }
  3071. $result = [
  3072. 'JobRecruiting' => $JobRecruiting ?? [],
  3073. 'recruit_count' => $recruit_count ?? 0,
  3074. 'JobHunting' => $JobHunting ?? [],
  3075. 'hunt_count' => $hunt_count ?? 0,
  3076. ];
  3077. return Result::success($result);
  3078. }
  3079. /**
  3080. * c端-获取招工招聘详情
  3081. * @param array $data
  3082. * @return array
  3083. * */
  3084. public function getWebsiteJobInfo(array $data): array
  3085. {
  3086. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3087. if (empty($web)) {
  3088. return Result::error("该网站不存在", 0);
  3089. }
  3090. $webid = [
  3091. 'website_id' => $data['website_id'],
  3092. ];
  3093. // 职位相关信息
  3094. if ($data['type'] == 1) {
  3095. $query = JobRecruiting::where('status', 1)
  3096. ->where('website_id', $data['website_id'])
  3097. ->select('*');
  3098. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3099. $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();
  3100. if (!empty($company)) {
  3101. $result['company'] = $this->processJob($company, $webid);
  3102. }
  3103. $other_job = JobRecruiting::where('status', 1)
  3104. ->where('website_id', $data['website_id'])
  3105. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3106. ->where('id', '!=', $data['id'])
  3107. ->where('user_id', '=', $job[0]['user_id'])
  3108. ->limit($data['pageSize'])
  3109. ->get();
  3110. if (!empty($other_job)) {
  3111. $result['other_job'] = $this->processJob($other_job, $webid);
  3112. }
  3113. } else {
  3114. // 简历相关信息
  3115. $job = JobHunting::where('job_hunting.status', 2)
  3116. ->where('job_hunting.website_id', $data['website_id'])
  3117. ->where('job_hunting.id', $data['id'])
  3118. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3119. ->select('job_hunting.*', 'user_name')
  3120. ->get();
  3121. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3122. if (!empty($resume->toArray())) {
  3123. $result['resume'] = 1;
  3124. } else {
  3125. $result['resume'] = 0;
  3126. }
  3127. }
  3128. if (empty($job->toArray())) {
  3129. return Result::error("id参数错误", 0);
  3130. }
  3131. if (!empty($job[0]['job_experience'])) {
  3132. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3133. if (!empty($job_experience)) {
  3134. // $hy = [];
  3135. foreach ($job_experience as $key => $value) {
  3136. // $id = $value['id'];
  3137. $hy[$key] = $value['job_industry'];
  3138. $zw_id[$key] = $value['job_typename'];
  3139. $jtzw_id[$key] = $value['job_name'];
  3140. }
  3141. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3142. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3143. // 先将关联表转换为索引数组,提高查找效率
  3144. $hyLookup = [];
  3145. foreach ($hy_table as $item) {
  3146. $hyLookup[$item['hyid']] = $item['hyname'];
  3147. }
  3148. $zwLookup = [];
  3149. foreach ($zw_table as $item) {
  3150. $zwLookup[$item['zwid']] = $item['zwname'];
  3151. }
  3152. foreach ($job_experience as $key => &$value) {
  3153. // 处理行业名称
  3154. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3155. $value['hy_name'] = $hyLookup[$hy[$key]];
  3156. }
  3157. // 处理职位名称
  3158. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3159. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3160. }
  3161. // 处理具体职位名称
  3162. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3163. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3164. }
  3165. }
  3166. // 释放引用,防止意外修改后续代码
  3167. unset($value);
  3168. }
  3169. $result['job_experience'] = $job_experience ?? [];
  3170. }
  3171. if (!empty($job[0]['education_experience'])) {
  3172. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3173. if (!empty($education_experience)) {
  3174. foreach ($education_experience as $key => $value) {
  3175. // $id = $value['id'];
  3176. $education[$key] = $value['school_education'];
  3177. }
  3178. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3179. // // 先将关联表转换为索引数组,提高查找效率
  3180. $educationLookup = [];
  3181. foreach ($education_table as $item) {
  3182. $educationLookup[$item['evalue']] = $item['ename'];
  3183. }
  3184. foreach ($education_experience as $key => &$value) {
  3185. // 处理学历名称
  3186. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3187. $value['education_name'] = $educationLookup[$education[$key]];
  3188. }
  3189. }
  3190. }
  3191. $result['education_experience'] = $job_experience ?? [];
  3192. }
  3193. $result['job'] = $this->processJob($job, $webid);
  3194. // // 返现对应的栏目
  3195. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3196. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3197. ->whereIn('category_id', $catid)
  3198. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3199. ->orderBy('pid')->get()->all();
  3200. if (!empty($category)) {
  3201. $result['category'] = $category;
  3202. }
  3203. $result['job'] = $job;
  3204. $result['job_experience'] = $job_experience ?? [];
  3205. $result['education_experience'] = $education_experience ?? [];
  3206. if (empty($result)) {
  3207. return Result::error("参数错误", 0);
  3208. }
  3209. return Result::success($result);
  3210. }
  3211. /**
  3212. * c端-申请职位
  3213. * @param array $data
  3214. * @return array
  3215. * */
  3216. public function getWebsiteJobApply(array $data): array
  3217. {
  3218. // 首先验证网站是否存在
  3219. // return Result::success($data);
  3220. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3221. if (empty($web)) {
  3222. return Result::error("该网站不存在", 0);
  3223. }
  3224. // 验证用户是否存在且为个人会员/管理员
  3225. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3226. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3227. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3228. return Result::error("用户不存在", 0);
  3229. }
  3230. // 去除重复元素和空元素,并保持原始顺序
  3231. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3232. return !empty($value);
  3233. }));
  3234. // 验证职位是否存在 1:审核通过
  3235. $recruiting = JobRecruiting::where('status', 1)
  3236. ->where('website_id', $data['website_id'])
  3237. ->whereIn('id', $data['recruit_id'])
  3238. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3239. if (empty($recruiting)) {
  3240. return Result::error("该职位不存在", 0);
  3241. }
  3242. // 简历是否存在
  3243. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3244. if (empty($hunt_id)) {
  3245. return Result::error("该简历不存在", 0);
  3246. }
  3247. $data['hunt_id'] = $hunt_id['hunt_id'];
  3248. // // 验证是否已投递过该职位
  3249. $apply = JobApply::where('user_id', $data['user_id'])
  3250. ->where('hunt_id', $data['hunt_id'])
  3251. ->where('website_id', $data['website_id'])
  3252. ->whereIn('recruit_id', $data['recruit_id'])
  3253. ->get(['recruit_id']);
  3254. if (!empty($apply->toArray())) {
  3255. return Result::error("您已投递过该职位!");
  3256. }
  3257. $insertData = array_map(function ($recruiting) use ($data) {
  3258. return [
  3259. 'user_id' => $data['user_id'],
  3260. 'hunt_id' => $data['hunt_id'],
  3261. 'website_id' => $data['website_id'],
  3262. 'recruit_id' => $recruiting['recruit_id'],
  3263. 'receiver_id' => $recruiting['receiver_id'],
  3264. 'status' => 1,
  3265. ];
  3266. }, $recruiting);
  3267. // 批量插入数据
  3268. $result = JobApply::insert($insertData);
  3269. if (empty($result)) {
  3270. return Result::error("投递失败", 0);
  3271. }
  3272. return Result::success($result);
  3273. }
  3274. /**
  3275. * 招工招聘-沟通简历
  3276. * @param array $data
  3277. * @return array
  3278. * */
  3279. public function getWebsiteJobResume(array $data): array
  3280. {
  3281. // 首先验证网站是否存在
  3282. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3283. if (empty($web)) {
  3284. return Result::error("该网站不存在", 0);
  3285. }
  3286. // return Result::success($data);
  3287. // 验证用户是否存在且为企业会员/管理员
  3288. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3289. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3290. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3291. return Result::error("用户不存在", 0);
  3292. }
  3293. // 去除重复元素和空元素,并保持原始顺序
  3294. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3295. return !empty($value);
  3296. }));
  3297. // 验证简历是否存在
  3298. $hunting = JobHunting::where('status', 2)
  3299. ->where('website_id', $data['website_id'])
  3300. ->whereIn('id', $data['hunt_id'])
  3301. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3302. if (empty($hunting)) {
  3303. return Result::error("该简历不存在", 0);
  3304. }
  3305. // 验证是否已沟通过该简历
  3306. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3307. ->where('recruit_id', $data['recruit_id'])
  3308. ->where('website_id', $data['website_id'])
  3309. ->whereIn('hunt_id', $data['hunt_id'])
  3310. ->get(['hunt_id']);
  3311. if (!empty($remuse->toArray())) {
  3312. return Result::error("您已沟通过该简历!");
  3313. }
  3314. // 准备要插入的数据数组
  3315. $insertData = array_map(function ($hunting) use ($data) {
  3316. return [
  3317. 'user_id' => $data['user_id'],
  3318. 'recruit_id' => $data['recruit_id'],
  3319. 'website_id' => $data['website_id'],
  3320. 'hunt_id' => $hunting['hunt_id'],
  3321. 'receiver_id' => $hunting['receiver_id'],
  3322. 'status' => 1,
  3323. ];
  3324. }, $hunting);
  3325. // 批量插入数据
  3326. $result = JobRemuse::insert($insertData);
  3327. if (empty($result)) {
  3328. return Result::error("沟通失败", 0);
  3329. }
  3330. return Result::success($result);
  3331. }
  3332. /**
  3333. * 招工招聘 -我的职位(企业会员)
  3334. * @param array $data
  3335. * @return array
  3336. */
  3337. public function getWebsiteJobRecruiting(array $data): array
  3338. {
  3339. $web = Website::where('id', $data['website_id'])->first('id');
  3340. if (empty($web)) {
  3341. return Result::error("该网站不存在", 0);
  3342. }
  3343. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3344. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3345. return Result::error("用户暂无权限!", 0);
  3346. }
  3347. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3348. $result = JobRecruiting::where('website_id', $data['website_id'])
  3349. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3350. $query->where('user_id', $user['id']);
  3351. })
  3352. ->where('status', 1)
  3353. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3354. ->orderBy('updated_at', 'desc')
  3355. ->limit($data['pageSize'])
  3356. ->get();
  3357. if (empty($result)) {
  3358. return Result::error("暂无相关职位信息", 0);
  3359. }
  3360. return Result::success($result);
  3361. }
  3362. /**
  3363. * c端 - 验证路由
  3364. * @param array $data
  3365. * @return array
  3366. */
  3367. /**
  3368. * c端 - 验证路由
  3369. * @param array $data
  3370. * @return array
  3371. */
  3372. public function checkWebsiteRoute(array $data): array
  3373. {
  3374. // 测试001111111222
  3375. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3376. if (empty($web)) {
  3377. return Result::error("该网站不存在", 0);
  3378. } elseif ($web['status'] != 1) {
  3379. return Result::error("网站已经关闭", 0);
  3380. }
  3381. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3382. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3383. // 验证路由是否存在
  3384. if (empty($whiteRouterInfo)) {
  3385. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3386. }
  3387. if (!empty($whiteRouterInfo)) {
  3388. return Result::success($whiteRouterInfo->toArray());
  3389. }
  3390. }
  3391. // 验证栏目路由
  3392. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3393. ->where('aLIas_pinyin', $data['last_route'])
  3394. ->get()->all();
  3395. if (count($last_category) == 0) {
  3396. return Result::error("该栏目不存在", 0);
  3397. }
  3398. if (count($last_category) > 1) {
  3399. return Result::error("该子级栏目存在多个,路由验证失败!", 0);
  3400. }
  3401. if (count($last_category) == 1) {
  3402. $last_category = $last_category[0];
  3403. }
  3404. // return Result::success($last_category);
  3405. if (isset($data['id']) && !empty($data['id'])) {
  3406. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3407. switch ($last_category['type']) {
  3408. case 1:
  3409. // 文章
  3410. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3411. $article = Article::where('status', 1)
  3412. ->where('id', $data['id'])
  3413. ->where(function ($query) use ($data) {
  3414. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3415. ->orWhereNull("ignore_ids");
  3416. })
  3417. ->first(['cat_arr_id']);
  3418. if (empty($article)) {
  3419. return Result::error("该文章不存在", 0);
  3420. }
  3421. // return Result::success($article);
  3422. break;
  3423. case 2:
  3424. // 商品
  3425. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3426. $article = Good::where('website_id', $data['website_id'])
  3427. ->where('status', 2)
  3428. ->where('id', $data['id'])
  3429. ->first(['cat_arr_id']);
  3430. if (empty($article)) {
  3431. return Result::error("该商品不存在", 0);
  3432. }
  3433. break;
  3434. case 3:
  3435. // 书刊信息
  3436. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3437. $article = Book::where('website_id', $data['website_id'])
  3438. ->where('status', 2)
  3439. ->where('id', $data['id'])
  3440. ->first(['id', 'cat_arr_id']);
  3441. if (empty($article)) {
  3442. return Result::error("该书刊不存在", 0);
  3443. }
  3444. break;
  3445. case 4:
  3446. // 招聘
  3447. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3448. $article = JobRecruiting::where('website_id', $data['website_id'])
  3449. ->where('status', 1)
  3450. ->where('id', $data['id'])
  3451. ->first(['cat_arr_id']);
  3452. if (empty($article)) {
  3453. return Result::error("该招聘不存在", 0);
  3454. }
  3455. break;
  3456. case 5:
  3457. // 求职
  3458. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3459. $article = JobHunting::where('website_id', $data['website_id'])
  3460. ->where('status', 2)
  3461. ->where('id', $data['id'])
  3462. ->first(['cat_arr_id']);
  3463. if (empty($article)) {
  3464. return Result::error("该求职不存在", 0);
  3465. }
  3466. break;
  3467. case 6:
  3468. // 企业
  3469. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3470. $article = Company::
  3471. // where('website_id', $data['website_id'])
  3472. // ->
  3473. where('status', 1)
  3474. ->where('id', $data['id'])
  3475. ->first(['cat_arr_id']);
  3476. if (empty($article)) {
  3477. return Result::error("该企业不存在", 0);
  3478. }
  3479. break;
  3480. case 7:
  3481. // 项目
  3482. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3483. $article = Project::where('website_id', $data['website_id'])
  3484. ->where('status', 1)
  3485. ->where('id', $data['id'])
  3486. ->first(['cat_arr_id']);
  3487. if (empty($article)) {
  3488. return Result::error("该项目不存在", 0);
  3489. }
  3490. break;
  3491. default:
  3492. return Result::error("该数据不存在", 0);
  3493. break;
  3494. }
  3495. $catid = 0;
  3496. $catidArray = json_decode($article['cat_arr_id'], true);
  3497. $catid = !empty($catidArray) ? end($catidArray) : null;
  3498. // return Result::success($article['cat_arr_id']);
  3499. if (empty($catid)) {
  3500. return Result::error("该数据不存在", 0);
  3501. }
  3502. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3503. ->where('category_id', $catid)
  3504. ->select('path')
  3505. ->pluck('path');
  3506. } else {
  3507. if ($last_category['pid'] != 0) {
  3508. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3509. $catid = !empty($cat_arr) ? end($cat_arr) : null;
  3510. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3511. ->where('category_id', $catid)
  3512. ->where('path', $data['all_route'])
  3513. ->pluck('path');
  3514. } else {
  3515. $pinyin[0] = $last_category['aLIas_pinyin'];
  3516. }
  3517. }
  3518. // return Result::success($pinyin[0]);
  3519. if (empty($pinyin) || count($pinyin) > 1 || $pinyin[0] != $data['all_route']) {
  3520. return Result::error('非法路径!');
  3521. } else {
  3522. return Result::success($pinyin);
  3523. }
  3524. }
  3525. /**
  3526. * 招工招聘 - 获取推荐职位
  3527. * @param array $data
  3528. * @return array
  3529. */
  3530. public function getWebsiteLevelJob(array $data): array
  3531. {
  3532. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3533. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3534. ->where('job_recruiting.status', 1)
  3535. ->where('job_level', $data['job_level'])
  3536. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3537. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3538. ->orderBy('job_recruiting.updated_at', 'desc')
  3539. ->limit($data['pageSize'])
  3540. ->get();
  3541. $web = ['website_id' => $data['website_id']];
  3542. if (!empty($job)) {
  3543. $result = $this->processJob($job, $web);
  3544. }
  3545. if (empty($result)) {
  3546. return Result::error("暂无相关职位信息", 0);
  3547. }
  3548. return Result::success($result);
  3549. }
  3550. /**
  3551. * 验证导航名称是否重复
  3552. * @return void
  3553. */
  3554. //20250226 产品列表
  3555. public function getGoodList(array $data): array
  3556. {
  3557. var_dump($data, '---------1-2--');
  3558. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3559. unset($data['user_type_id']);
  3560. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3561. $where = [];
  3562. if ($type_id != '10000') {
  3563. $where = [
  3564. 'good.user_id' => $user_id,
  3565. ];
  3566. }
  3567. //类型
  3568. if (isset($data['type_id']) && $data['type_id']) {
  3569. $where['good.type_id'] = $data['type_id'];
  3570. }
  3571. //名称
  3572. if (isset($data['name']) && $data['name']) {
  3573. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3574. }
  3575. //status
  3576. if (isset($data['status']) && $data['status'] != '') {
  3577. $where['good.status'] = $data['status'];
  3578. }
  3579. //status1
  3580. // if (isset($data['status1']) && $data['status1'] == 1) {
  3581. // $status1 = 1;
  3582. // }
  3583. $where1 = [];
  3584. //website_id
  3585. // if (isset($data['website_id']) && $data['website_id']) {
  3586. // $where1 = [
  3587. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3588. // ];
  3589. // }
  3590. // website_name
  3591. if (isset($data['website_name']) && $data['website_name']) {
  3592. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3593. }
  3594. // catid
  3595. if (isset($data['category_name']) && $data['category_name']) {
  3596. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3597. }
  3598. // $result = Good::where($where)
  3599. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3600. var_dump($where, '---------1---');
  3601. $result = Good::where($where)
  3602. ->when(!empty($where1), function ($query) use ($where1) {
  3603. return $query->where($where1);
  3604. })
  3605. //status 1待审核2已审核3已拒绝
  3606. ->when(isset($data['status1']), function ($query) {
  3607. return $query->whereIn('good.status', [1, 3]);
  3608. })
  3609. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3610. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3611. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3612. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3613. ->orderBy("updated_at", "desc")
  3614. ->limit($data['page_size'])
  3615. ->offset(($data['page'] - 1) * $data['page_size'])
  3616. ->get();
  3617. $count = Good::where($where)
  3618. ->when(!empty($where1), function ($query) use ($where1) {
  3619. return $query->where($where1);
  3620. })
  3621. //status 1待审核2已审核3已拒绝
  3622. ->when(isset($data['status1']), function ($query) {
  3623. return $query->whereIn('good.status', [1, 3]);
  3624. })
  3625. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3626. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3627. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3628. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3629. ->orderBy("updated_at", "desc")->count();
  3630. $data = [
  3631. 'rows' => $result->toArray(),
  3632. 'count' => $count,
  3633. ];
  3634. if (empty($result)) {
  3635. return Result::error("此栏目暂无相关产品", 0);
  3636. }
  3637. return Result::success($data);
  3638. }
  3639. public function getGoodInfo(array $data): array
  3640. {
  3641. $result = Good::where('id', $data['id'])->first();
  3642. if (empty($result)) {
  3643. return Result::error("此产品不存在", 0);
  3644. }
  3645. return Result::success($result);
  3646. }
  3647. public function addGood(array $data): array
  3648. {
  3649. // unset($data['city_arr_id']);
  3650. // unset($data['cat_arr_id']);
  3651. $data['city_id'] = end($data['city_arr_id']);
  3652. $data['catid'] = end($data['cat_arr_id']);
  3653. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3654. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3655. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3656. unset($data['imgUrl']); //大小写
  3657. if (isset($data['price']) && $data['price'] == '') {
  3658. $data['price'] = 0;
  3659. }
  3660. if ($data['imgurl'] == '') {
  3661. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3662. preg_match_all($reg, $data['detail'], $matches);
  3663. if (isset($matches[1][0])) {
  3664. //截取varchar240
  3665. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3666. }
  3667. }
  3668. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3669. //提取标题+内容中的关键词
  3670. $data['keyword'] = $data['name'];
  3671. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3672. Jieba::init(); // 初始化 jieba-php
  3673. Finalseg::init();
  3674. $segList = Jieba::cut($data['keyword']);
  3675. $segList1 = array_slice($segList, 0, 8);
  3676. $data['keyword'] = implode(',', $segList1);
  3677. }
  3678. if ($data['description'] == '') {
  3679. //提取内容中的描述
  3680. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3681. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3682. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3683. }
  3684. if ($data['status'] == 1) {
  3685. $this->sendMessage([
  3686. 'talk_type' => 200,
  3687. 'title' => $data['name'],
  3688. 'content' => '提交了审核',
  3689. 'messageType' => 3,
  3690. ]);
  3691. }
  3692. $result = Good::insert($data);
  3693. if (empty($result)) {
  3694. return Result::error("添加失败", 0);
  3695. }
  3696. return Result::success($result);
  3697. }
  3698. public function updateGood(array $data): array
  3699. {
  3700. $data['city_id'] = end($data['city_arr_id']);
  3701. $data['catid'] = end($data['cat_arr_id']);
  3702. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3703. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3704. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3705. //设置东八区
  3706. date_default_timezone_set('Asia/Shanghai');
  3707. $data['updated_at'] = date('Y-m-d H:i:s');
  3708. if (isset($data['price']) && $data['price'] == '') {
  3709. $data['price'] = 0;
  3710. }
  3711. if ($data['imgurl'] == '') {
  3712. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3713. preg_match_all($reg, $data['detail'], $matches);
  3714. if (isset($matches[1][0])) {
  3715. //截取varchar240
  3716. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3717. }
  3718. }
  3719. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3720. //提取标题+内容中的关键词
  3721. $data['keyword'] = $data['name'];
  3722. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3723. Jieba::init(); // 初始化 jieba-php
  3724. Finalseg::init();
  3725. $segList = Jieba::cut($data['keyword']);
  3726. $segList1 = array_slice($segList, 0, 8);
  3727. $data['keyword'] = implode(',', $segList1);
  3728. }
  3729. if ($data['description'] == '') {
  3730. //提取内容中的描述
  3731. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3732. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3733. }
  3734. if ($data['status'] == 1) {
  3735. $this->sendMessage([
  3736. 'talk_type' => 200,
  3737. 'title' => $data['name'],
  3738. 'content' => '提交了审核',
  3739. 'messageType' => 3,
  3740. ]);
  3741. }
  3742. $result = Good::where('id', $data['id'])->update($data);
  3743. if (empty($result)) {
  3744. return Result::error("更新失败", 0);
  3745. }
  3746. return Result::success($result);
  3747. }
  3748. public function delGood(array $data): array
  3749. {
  3750. $result = Good::where('id', $data['id'])->delete();
  3751. if (empty($result)) {
  3752. return Result::error("删除失败", 0);
  3753. }
  3754. return Result::success($result);
  3755. }
  3756. //20250226 产品列表
  3757. //20250306 求职信息
  3758. public function getJobHuntingList(array $data): array
  3759. {
  3760. $where = [];
  3761. if (isset($data['username']) && !empty($data['username'])) {
  3762. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3763. }
  3764. //status 1待审核2已审核3已拒绝
  3765. if (isset($data['status']) && $data['status'] != '') {
  3766. $where = [
  3767. 'job_hunting.status' => $data['status'],
  3768. ];
  3769. }
  3770. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3771. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3772. unset($data['type_id']);
  3773. if ($type_id != '10000') {
  3774. $where[] = ['job_hunting.user_id', '=', $user_id];
  3775. }
  3776. $result = JobHunting::where($where)
  3777. ->when(!empty($data['status1']), function ($query) use ($data) {
  3778. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3779. })
  3780. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3781. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3782. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3783. ->orderBy("updated_at", "desc")
  3784. ->limit($data['page_size'])
  3785. ->offset(($data['page'] - 1) * $data['page_size'])
  3786. ->get();
  3787. if (empty($result)) {
  3788. return Result::error("查询失败", 0);
  3789. }
  3790. $count = JobHunting::where($where)
  3791. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3792. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3793. ->count();
  3794. $data = [
  3795. 'rows' => $result->toArray(),
  3796. 'count' => $count,
  3797. ];
  3798. return Result::success($data);
  3799. }
  3800. public function getJobHuntingApply(array $data): array
  3801. {
  3802. var_dump($data, '-----------------test--------1-');
  3803. $where = [];
  3804. if (isset($data['username']) && !empty($data['username'])) {
  3805. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3806. }
  3807. if (isset($data['salary']) && !empty($data['salary'])) {
  3808. $where[] = [
  3809. 'job_hunting.salary',
  3810. '=',
  3811. $data['salary'],
  3812. ];
  3813. }
  3814. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3815. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3816. unset($data['type_id']);
  3817. if ($type_id != '10000') {
  3818. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3819. }
  3820. var_dump($where, '-----------------test---------');
  3821. $result = jobApply::where($where)
  3822. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3823. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3824. // })
  3825. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3826. ->where('job_enum.egroup', '=', 'income')
  3827. ->where('job_hunting.status', 2) //已审核
  3828. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3829. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3830. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3831. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3832. //职位----是申请职位
  3833. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3834. ->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')
  3835. ->orderBy("job_hunting.updated_at", "desc")
  3836. ->limit($data['page_size'])
  3837. ->offset(($data['page'] - 1) * $data['page_size'])
  3838. ->get();
  3839. if (empty($result)) {
  3840. return Result::error("查询失败", 0);
  3841. }
  3842. $count = jobApply::where($where)
  3843. ->where('job_enum.egroup', '=', 'income')
  3844. ->where('job_hunting.status', 2) //已审核
  3845. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3846. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3847. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3848. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3849. //职位----是申请职位
  3850. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3851. ->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')
  3852. ->count();
  3853. $data = [
  3854. 'rows' => $result->toArray(),
  3855. 'count' => $count,
  3856. ];
  3857. return Result::success($data);
  3858. }
  3859. public function addJobHunting(array $data): array
  3860. {
  3861. date_default_timezone_set('Asia/Shanghai');
  3862. unset($data['company_name']);
  3863. unset($data['job_industry']);
  3864. unset($data['job_name']);
  3865. unset($data['department']);
  3866. unset($data['job_timeList']);
  3867. unset($data['job_content']);
  3868. unset($data['job_typename']); //不知道这是啥,
  3869. $data['created_at'] = date('Y-m-d H:i:s');
  3870. $data['updated_at'] = date('Y-m-d H:i:s');
  3871. //根据用户 user_id 只能添加一次
  3872. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3873. if (!empty($result)) {
  3874. return Result::error("您已添加过求职信息", 0);
  3875. }
  3876. var_dump($result, '-----------------test---------');
  3877. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3878. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3879. $cityArr = json_decode($data['city_arr_id'], true);
  3880. $data['city_id'] = end($cityArr);
  3881. } else {
  3882. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3883. $data['city_id'] = end($data['city_arr_id']);
  3884. }
  3885. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3886. $this->sendMessage([
  3887. 'talk_type' => 600,
  3888. 'title' => $data['name'],
  3889. 'content' => '提交了审核',
  3890. 'messageType' => 11,
  3891. ]);
  3892. }
  3893. $result = JobHunting::create($data);
  3894. if (empty($result)) {
  3895. return Result::error("添加失败", 0);
  3896. }
  3897. return Result::success($result);
  3898. }
  3899. public function delJobHunting(array $data): array
  3900. {
  3901. $result = JobHunting::where('id', $data['id'])->delete();
  3902. if (empty($result)) {
  3903. return Result::error("删除失败", 0);
  3904. }
  3905. return Result::success($result);
  3906. }
  3907. public function updateJobHunting(array $data): array
  3908. {
  3909. //设置东八区
  3910. date_default_timezone_set('Asia/Shanghai');
  3911. unset($data['company_name']);
  3912. unset($data['job_industry']);
  3913. unset($data['job_name']);
  3914. unset($data['department']);
  3915. unset($data['job_timeList']);
  3916. unset($data['job_content']);
  3917. unset($data['job_typename']); //不知道这是啥,
  3918. $data['created_at'] = date('Y-m-d H:i:s');
  3919. $data['updated_at'] = date('Y-m-d H:i:s');
  3920. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3921. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3922. $cityArr = json_decode($data['city_arr_id'], true);
  3923. $data['city_id'] = end($cityArr);
  3924. } else {
  3925. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3926. $data['city_id'] = end($data['city_arr_id']);
  3927. }
  3928. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3929. $this->sendMessage([
  3930. 'talk_type' => 600,
  3931. 'title' => $data['name'],
  3932. 'content' => '提交了审核',
  3933. 'messageType' => 11,
  3934. ]);
  3935. }
  3936. $result = JobHunting::where('id', $data['id'])->update($data);
  3937. if (empty($result)) {
  3938. return Result::error("更新失败", 0);
  3939. }
  3940. return Result::success($result);
  3941. }
  3942. public function getJobHuntingInfo(array $data): array
  3943. {
  3944. $result = JobHunting::where('id', $data['id'])->first();
  3945. if (empty($result)) {
  3946. return Result::error("查询失败", 0);
  3947. }
  3948. return Result::success($result);
  3949. }
  3950. public function getJobHuntingData(array $data): array
  3951. {
  3952. $jobEnum = JobEnum::get();
  3953. $jobIndustry = JobIndustry::get();
  3954. $jobNature = JobNature::get();
  3955. $jobPosition = JobPosition::get();
  3956. $data = [
  3957. 'jobEnum' => $jobEnum,
  3958. 'jobIndustry' => $jobIndustry,
  3959. 'jobNature' => $jobNature,
  3960. 'jobPosition' => $jobPosition,
  3961. ];
  3962. return Result::success($data);
  3963. }
  3964. public function delJobHuntingInfo(array $data): array
  3965. {
  3966. $result = JobHunting::where('id', $data['id'])->delete();
  3967. return Result::success();
  3968. }
  3969. //20250324 通知,公告,消息
  3970. public function delNotice(array $data): array
  3971. {
  3972. $result = Notice::where('id', $data['id'])->delete();
  3973. if ($result) {
  3974. return Result::success();
  3975. } else {
  3976. return Result::error("删除失败", 0);
  3977. }
  3978. }
  3979. public function getNoticeInfo(array $data): array
  3980. {
  3981. $result = Notice::where('id', $data['id'])->first();
  3982. // var_dump($result['re_user_ids'], '--------------------');
  3983. if (empty($result)) {
  3984. return Result::error("查询失败", 0);
  3985. }
  3986. return Result::success($result);
  3987. }
  3988. public function readNotice(array $data): array
  3989. {
  3990. $result = Notice::where('id', $data['id'])->first();
  3991. // var_dump($result['re_user_ids'], '--------------------');
  3992. if (empty($result)) {
  3993. return Result::error("查询失败", 0);
  3994. }
  3995. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  3996. $re_user_ids = json_decode($result['re_user_ids'], true);
  3997. var_dump($re_user_ids, '--------------1---test---------');
  3998. var_dump($data, '--------------1---test---------');
  3999. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4000. //如果已经存在,就不再添加
  4001. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4002. $read_id = json_decode($result['read_id'], true);
  4003. if (!is_array($read_id)) {
  4004. $read_id = [];
  4005. }
  4006. if (!in_array($data['user_id'], $read_id)) {
  4007. $read_id[] = $data['user_id'];
  4008. $result['read_id'] = json_encode($read_id);
  4009. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4010. }
  4011. } else {
  4012. //如果不存在,就添加
  4013. $result['read_id'] = json_encode([$data['user_id']]);
  4014. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4015. }
  4016. }
  4017. return Result::success($result);
  4018. }
  4019. public function addNotice(array $data): array
  4020. {
  4021. date_default_timezone_set('Asia/Shanghai');
  4022. $data['created_at'] = date('Y-m-d H:i:s');
  4023. $data['updated_at'] = date('Y-m-d H:i:s');
  4024. $user_id = UserInfo::
  4025. //city_id不是null
  4026. whereNotNull('city_id')
  4027. ->whereNotNull('department_id')
  4028. ->where(function ($query) use ($data) {
  4029. $query->where(function ($subQuery) use ($data) {
  4030. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4031. });
  4032. })
  4033. ->where(function ($query) use ($data) {
  4034. $query->where(function ($subQuery) use ($data) {
  4035. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4036. });
  4037. })
  4038. ->pluck('user_id')->toArray();
  4039. $user_id = array_unique($user_id);
  4040. $chat_ids = $user_id;
  4041. $user_id = json_encode($user_id);
  4042. $data['re_user_ids'] = $user_id;
  4043. $this->sendMessage([
  4044. 'talk_type' => 700,
  4045. 'title' => $data['title'],
  4046. 'content' => '提交了审核',
  4047. 'messageType' => 5,
  4048. ]);
  4049. $result = Notice::insertGetId($data);
  4050. if (empty($result)) {
  4051. return Result::error("添加失败", 0);
  4052. }
  4053. return Result::success($result);
  4054. }
  4055. public function updateNotice(array $data): array
  4056. {
  4057. date_default_timezone_set('Asia/Shanghai');
  4058. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4059. $user_id = UserInfo::
  4060. //city_id不是null
  4061. whereNotNull('city_id')
  4062. ->whereNotNull('department_id')
  4063. ->where(function ($query) use ($data) {
  4064. $query->where(function ($subQuery) use ($data) {
  4065. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4066. });
  4067. })
  4068. ->where(function ($query) use ($data) {
  4069. $query->where(function ($subQuery) use ($data) {
  4070. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4071. });
  4072. })
  4073. ->pluck('user_id')->toArray();
  4074. $user_id = array_unique($user_id);
  4075. $user_id = json_encode($user_id);
  4076. $data['re_user_ids'] = $user_id;
  4077. $data['updated_at'] = date('Y-m-d H:i:s');
  4078. $this->sendMessage([
  4079. 'talk_type' => 700,
  4080. 'title' => $data['title'],
  4081. 'content' => '提交了审核',
  4082. 'messageType' => 5,
  4083. ]);
  4084. $result = Notice::where('id', $data['id'])->update($data);
  4085. return Result::success($result);
  4086. }
  4087. public function getNoticeList(array $data): array
  4088. {
  4089. $where = [];
  4090. //title
  4091. if (isset($data['title']) && !empty($data['title'])) {
  4092. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4093. }
  4094. //level
  4095. if (isset($data['level']) && !empty($data['level'])) {
  4096. $where[] = ['notice.level', '=', $data['level']];
  4097. }
  4098. //status
  4099. if (isset($data['status']) && !empty($data['status'])) {
  4100. $where[] = ['notice.status', '=', $data['status']];
  4101. }
  4102. //type
  4103. if (isset($data['type']) && !empty($data['type'])) {
  4104. $where[] = ['notice.type', '=', $data['type']];
  4105. }
  4106. var_dump($data, '------------11111-2----test---------');
  4107. if ($data['type_id'] == 10000) {
  4108. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4109. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4110. })
  4111. ->where($where)
  4112. ->orderBy('updated_at', 'desc')
  4113. ->limit($data['page_size'])
  4114. ->offset(($data['page'] - 1) * $data['page_size'])
  4115. ->get();
  4116. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4117. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4118. })
  4119. ->where($where)
  4120. ->orderBy('updated_at', 'desc')
  4121. ->count();
  4122. } else {
  4123. $result = Notice::where($where)
  4124. // ->where('user_id', $data['user_id'])
  4125. ->Where(function ($query) use ($data) {
  4126. $query->Where(function ($q) use ($data) {
  4127. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4128. ->orWhere('notice.user_id', $data['user_id']);
  4129. });
  4130. })
  4131. ->when(!empty($data['status1']), function ($query) use ($data) {
  4132. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4133. })
  4134. ->orderBy('updated_at', 'desc')
  4135. ->limit($data['page_size'])
  4136. ->offset(($data['page'] - 1) * $data['page_size'])
  4137. ->get();
  4138. $total = Notice::where($where)
  4139. ->when(!empty($data['status1']), function ($query) use ($data) {
  4140. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4141. })
  4142. // ->where('user_id', $data['user_id'])
  4143. ->Where(function ($query) use ($data) {
  4144. $query->Where(function ($q) use ($data) {
  4145. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4146. ->orWhere('notice.user_id', $data['user_id']);
  4147. });
  4148. })
  4149. ->count();
  4150. }
  4151. if (empty($result)) {
  4152. return Result::error("查询失败", 0);
  4153. }
  4154. $data = [
  4155. 'rows' => $result,
  4156. 'count' => $total,
  4157. ];
  4158. return Result::success($data);
  4159. }
  4160. public function noticeList(array $data): array
  4161. {
  4162. $where = [];
  4163. //title
  4164. if (isset($data['title']) && !empty($data['title'])) {
  4165. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4166. }
  4167. //level
  4168. if (isset($data['level']) && !empty($data['level'])) {
  4169. $where[] = ['notice.level', '=', $data['level']];
  4170. }
  4171. //status
  4172. if (isset($data['status']) && !empty($data['status'])) {
  4173. $where[] = ['notice.status', '=', $data['status']];
  4174. }
  4175. //type
  4176. if (isset($data['type']) && !empty($data['type'])) {
  4177. $where[] = ['notice.type', '=', $data['type']];
  4178. }
  4179. var_dump($data, '------------11111-2----test---------');
  4180. if ($data['type_id'] == 10000) {
  4181. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4182. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4183. })
  4184. ->where($where)
  4185. ->orderBy('updated_at', 'desc')
  4186. ->limit($data['page_size'])
  4187. ->offset(($data['page'] - 1) * $data['page_size'])
  4188. ->get();
  4189. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4190. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4191. })
  4192. ->where($where)
  4193. ->orderBy('updated_at', 'desc')
  4194. ->count();
  4195. } else {
  4196. $result = Notice::where($where)
  4197. // ->where('user_id', $data['user_id'])
  4198. ->Where(function ($query) use ($data) {
  4199. $query->Where(function ($q) use ($data) {
  4200. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4201. ->orWhere('notice.user_id', $data['user_id']);
  4202. });
  4203. })
  4204. ->when(!empty($data['status1']), function ($query) use ($data) {
  4205. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4206. })
  4207. ->orderBy('updated_at', 'desc')
  4208. ->limit($data['page_size'])
  4209. ->offset(($data['page'] - 1) * $data['page_size'])
  4210. ->get();
  4211. $total = Notice::where($where)
  4212. ->when(!empty($data['status1']), function ($query) use ($data) {
  4213. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4214. })
  4215. // ->where('user_id', $data['user_id'])
  4216. ->Where(function ($query) use ($data) {
  4217. $query->Where(function ($q) use ($data) {
  4218. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4219. ->orWhere('notice.user_id', $data['user_id']);
  4220. });
  4221. })
  4222. ->count();
  4223. }
  4224. if (empty($result)) {
  4225. return Result::error("查询失败", 0);
  4226. }
  4227. $data = [
  4228. 'rows' => $result,
  4229. 'count' => $total,
  4230. ];
  4231. return Result::success($data);
  4232. }
  4233. public function getNoticeDetail(array $data): array
  4234. {
  4235. $result = Notice::where('id', $data['id'])->first();
  4236. if (empty($result)) {
  4237. return Result::error("查询失败", 0);
  4238. }
  4239. return Result::success($result);
  4240. }
  4241. public function deleteNotice(array $data): array
  4242. {
  4243. $notice = Notice::where('id', $data['id'])->first();
  4244. if (empty($notice)) {
  4245. return Result::error("删除失败", 0);
  4246. }
  4247. $chat_group_id = $notice->group_id;
  4248. if ($chat_group_id) {
  4249. //删除群聊
  4250. ChatGroups::where('id', $chat_group_id)->delete();
  4251. //删除群成员
  4252. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4253. //删除群聊记录
  4254. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4255. }
  4256. $result = Notice::where('id', $data['id'])->delete();
  4257. return Result::success($result);
  4258. }
  4259. public function complaintList(array $data): array
  4260. {
  4261. var_dump($data, '---------1---------');
  4262. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4263. unset($data['type_id']);
  4264. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4265. $where = [];
  4266. if ($type_id != 10000 && empty($data['deal_user'])) {
  4267. // $where['complaint.user_id'] = $user_id;
  4268. }
  4269. if (!empty($data['title'])) {
  4270. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4271. }
  4272. if (!empty($data['department_id'])) {
  4273. $where['complaint.department_id'] = $data['department_id'];
  4274. }
  4275. if (!empty($data['deal'])) {
  4276. $where['complaint.deal'] = $data['deal'];
  4277. }
  4278. if (!empty($data['status'])) {
  4279. $where['complaint.status'] = $data['status'];
  4280. }
  4281. var_dump(!empty($data['deal_user']), '----------1');
  4282. var_dump($where, '----------2');
  4283. $result = Complaint::where($where)
  4284. ->when(!empty($data['status1']), function ($query) use ($data) {
  4285. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4286. })
  4287. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4288. //json re_user_ids data[user_id]是不是在里面
  4289. $query->Where(function ($q) use ($data) {
  4290. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4291. ->where('complaint.status', 2);
  4292. });
  4293. })
  4294. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4295. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4296. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4297. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4298. ->orderBy('updated_at', 'desc')
  4299. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4300. //sql输出
  4301. if (empty($result)) {
  4302. return Result::error("暂无投诉信息", 0);
  4303. }
  4304. // 取出数据
  4305. $rows = $result->items();
  4306. $count = $result->total();
  4307. $responseData = [
  4308. 'rows' => $rows,
  4309. 'count' => $count,
  4310. ];
  4311. return Result::success($responseData);
  4312. }
  4313. public function getComplaintList(array $data): array
  4314. {
  4315. var_dump($data, '00000001000000000000');
  4316. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4317. unset($data['type_id']);
  4318. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4319. $where = [];
  4320. if ($type_id != 10000 && empty($data['deal_user'])) {
  4321. $where['complaint.user_id'] = $user_id;
  4322. }
  4323. if (!empty($data['title'])) {
  4324. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4325. }
  4326. if (!empty($data['department_id'])) {
  4327. $where['complaint.department_id'] = $data['department_id'];
  4328. }
  4329. if (!empty($data['deal'])) {
  4330. $where['complaint.deal'] = $data['deal'];
  4331. }
  4332. if (!empty($data['status'])) {
  4333. $where['complaint.status'] = $data['status'];
  4334. }
  4335. var_dump(!empty($data['deal_user']), '----------1');
  4336. var_dump($where, '----------2');
  4337. $result = Complaint::where($where)
  4338. ->when(!empty($data['status1']), function ($query) use ($data) {
  4339. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4340. })
  4341. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4342. // //json re_user_ids data[user_id]是不是在里面
  4343. // $query->Where(function ($q) use ($data) {
  4344. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4345. // ->where('complaint.status', 2);
  4346. // });
  4347. // })
  4348. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4349. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4350. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4351. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4352. ->orderBy('updated_at', 'desc')
  4353. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4354. //sql输出
  4355. if (empty($result)) {
  4356. return Result::error("暂无投诉信息", 0);
  4357. }
  4358. // 取出数据
  4359. $rows = $result->items();
  4360. $count = $result->total();
  4361. $responseData = [
  4362. 'rows' => $rows,
  4363. 'count' => $count,
  4364. ];
  4365. return Result::success($responseData);
  4366. }
  4367. public function getComplaintInfo(array $data): array
  4368. {
  4369. $result = Complaint::where('id', $data['id'])->first();
  4370. if (empty($result)) {
  4371. return Result::error("查询失败", 0);
  4372. }
  4373. return Result::success($result);
  4374. }
  4375. public function readComplaint(array $data): array
  4376. {
  4377. $result = Complaint::where('id', $data['id'])->first();
  4378. if (empty($result)) {
  4379. return Result::error("查询失败", 0);
  4380. }
  4381. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4382. $re_user_ids = json_decode($result['re_user_ids'], true);
  4383. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4384. //如果已经存在,就不再添加
  4385. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4386. $read_id = json_decode($result['read_id'], true);
  4387. if (!is_array($read_id)) {
  4388. $read_id = [];
  4389. }
  4390. if (!in_array($data['user_id'], $read_id)) {
  4391. $read_id[] = $data['user_id'];
  4392. $result['read_id'] = json_encode($read_id);
  4393. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4394. }
  4395. } else {
  4396. //如果不存在,就添加
  4397. $result['read_id'] = json_encode([$data['user_id']]);
  4398. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4399. }
  4400. }
  4401. return Result::success($result);
  4402. }
  4403. public function addComplaint(array $data): array
  4404. {
  4405. date_default_timezone_set('Asia/Shanghai');
  4406. $data['created_at'] = date('Y-m-d H:i:s');
  4407. $data['updated_at'] = date('Y-m-d H:i:s');
  4408. $this->sendMessage([
  4409. 'talk_type' => 800,
  4410. 'title' => $data['title'],
  4411. 'content' => '提交了审核',
  4412. 'messageType' => 6,
  4413. ]);
  4414. $result = Complaint::create($data);
  4415. return Result::success($result);
  4416. }
  4417. public function updateComplaint(array $data): array
  4418. {
  4419. date_default_timezone_set('Asia/Shanghai');
  4420. $data['updated_at'] = date('Y-m-d H:i:s');
  4421. $user_id = $data['user_id'] ?? 0;
  4422. $type_id = $data['type_id'] ?? 0;
  4423. unset($data['user_id']);
  4424. unset($data['type_id']);
  4425. $this->sendMessage([
  4426. 'talk_type' => 800,
  4427. 'title' => $data['title'],
  4428. 'content' => '提交了审核',
  4429. 'messageType' => 6,
  4430. ]);
  4431. $result = Complaint::where('id', $data['id'])->update($data);
  4432. return Result::success($result);
  4433. }
  4434. public function deleteComplaint(array $data): array
  4435. {
  4436. $result = Complaint::where('id', $data['id'])->delete();
  4437. return Result::success($result);
  4438. }
  4439. public function getComplainInfo(array $data): array
  4440. {
  4441. $result = Complaint::where('id', $data['id'])->first();
  4442. if (empty($result)) {
  4443. return Result::error("查询失败", 0);
  4444. }
  4445. return Result::success($result);
  4446. }
  4447. public function updateComplaintStatus(array $data): array
  4448. {
  4449. date_default_timezone_set('Asia/Shanghai');
  4450. $data['updated_at'] = date('Y-m-d H:i:s');
  4451. $user_id = $data['user_id'] ?? 0;
  4452. $type_id = $data['type_id'] ?? 0;
  4453. unset($data['user_id']);
  4454. unset($data['type_id']);
  4455. //处理, 写入处理人
  4456. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4457. $data['real_deal_user'] = $user_id;
  4458. }
  4459. //如果是deal 23,则判断是不是处理人
  4460. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4461. $complaintInof = Complaint::where('id', $data['id'])
  4462. ->where('real_deal_user', $user_id)
  4463. ->first();
  4464. if (empty($complaintInof)) {
  4465. return Result::error("处理人错误", 0);
  4466. }
  4467. }
  4468. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4469. if ($data['status'] == 1) {
  4470. $this->sendMessage([
  4471. 'talk_type' => 800,
  4472. 'title' => $complaintInfo['title'],
  4473. 'content' => '提交了审核',
  4474. 'messageType' => 6,
  4475. ]);
  4476. }
  4477. if ($data['status'] == 2 && !isset($data['deal'])) {
  4478. $this->sendMessage([
  4479. 'talk_type' => 801,
  4480. 'title' => $complaintInfo['title'],
  4481. 'content' => '审核通过',
  4482. 'messageType' => 6,
  4483. 'user_id' => $complaintInfo['user_id'],
  4484. ]);
  4485. $this->sendMessage([
  4486. 'talk_type' => 802,
  4487. 'title' => $complaintInfo['title'],
  4488. 'content' => '待处理',
  4489. 'messageType' => 6,
  4490. 'user_id' => $complaintInfo['re_user_ids'],
  4491. ]);
  4492. }
  4493. if ($data['status'] == 3 && !isset($data['deal'])) {
  4494. $this->sendMessage([
  4495. 'talk_type' => 801,
  4496. 'title' => $complaintInfo['title'],
  4497. 'content' => '审核拒绝',
  4498. 'messageType' => 6,
  4499. 'user_id' => $complaintInfo['user_id'],
  4500. ]);
  4501. }
  4502. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4503. $this->sendMessage([
  4504. 'talk_type' => 802,
  4505. 'title' => $complaintInfo['title'],
  4506. 'content' => '处理中',
  4507. 'messageType' => 6,
  4508. 'user_id' => $complaintInfo['re_user_ids'],
  4509. ]);
  4510. }
  4511. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4512. $this->sendMessage([
  4513. 'talk_type' => 802,
  4514. 'title' => $complaintInfo['title'],
  4515. 'content' => '不予处理',
  4516. 'messageType' => 6,
  4517. 'user_id' => $complaintInfo['re_user_ids'],
  4518. ]);
  4519. }
  4520. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4521. $this->sendMessage([
  4522. 'talk_type' => 802,
  4523. 'title' => $complaintInfo['title'],
  4524. 'content' => '已完结',
  4525. 'messageType' => 6,
  4526. 'user_id' => $complaintInfo['re_user_ids'],
  4527. ]);
  4528. }
  4529. $result = complaint::where('id', $data['id'])->update($data);
  4530. return Result::success($result);
  4531. }
  4532. public function updateGoodStatus(array $data): array
  4533. {
  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. $goodInfo = Good::where('id', $data['id'])->first();
  4539. if ($data['status'] == 2) {
  4540. $this->sendMessage([
  4541. 'talk_type' => 201,
  4542. 'title' => $goodInfo['name'],
  4543. 'content' => '审核通过',
  4544. 'messageType' => 3,
  4545. 'user_id' => $goodInfo['user_id'],
  4546. ]);
  4547. }
  4548. if ($data['status'] == 3) {
  4549. $this->sendMessage([
  4550. 'talk_type' => 201,
  4551. 'title' => $goodInfo['name'],
  4552. 'content' => '审核拒绝',
  4553. 'messageType' => 3,
  4554. 'user_id' => $goodInfo['user_id'],
  4555. ]);
  4556. }
  4557. if ($data['status'] == 1) {
  4558. $this->sendMessage([
  4559. 'talk_type' => 200,
  4560. 'title' => $goodInfo['name'],
  4561. 'content' => '提交了审核',
  4562. 'messageType' => 3,
  4563. ]);
  4564. }
  4565. $result = Good::where('id', $data['id'])->update($data);
  4566. return Result::success($result);
  4567. }
  4568. public function updateJobHuntingStatus(array $data): array
  4569. {
  4570. $user_id = $data['user_id'] ?? 0;
  4571. $type_id = $data['type_id'] ?? 0;
  4572. unset($data['user_id']);
  4573. unset($data['type_id']);
  4574. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4575. if ($data['status'] == 2) {
  4576. $this->sendMessage([
  4577. 'talk_type' => 601,
  4578. 'title' => $jogHuntingInfo['name'],
  4579. 'content' => '审核通过',
  4580. 'messageType' => 11,
  4581. 'user_id' => $jogHuntingInfo['user_id'],
  4582. ]);
  4583. }
  4584. if ($data['status'] == 3) {
  4585. $this->sendMessage([
  4586. 'talk_type' => 601,
  4587. 'title' => $jogHuntingInfo['name'],
  4588. 'content' => '审核拒绝',
  4589. 'messageType' => 11,
  4590. 'user_id' => $jogHuntingInfo['user_id'],
  4591. ]);
  4592. }
  4593. if ($data['status'] == 1) {
  4594. $this->sendMessage([
  4595. 'talk_type' => 600,
  4596. 'title' => $jogHuntingInfo['name'],
  4597. 'content' => '提交了审核',
  4598. 'messageType' => 11,
  4599. ]);
  4600. }
  4601. $result = JobHunting::where('id', $data['id'])->update($data);
  4602. return Result::success($result);
  4603. }
  4604. public function updateNoticeStatus(array $data): array
  4605. {
  4606. $user_id = $data['user_id'] ?? 0;
  4607. $type_id = $data['type_id'] ?? 0;
  4608. unset($data['user_id']);
  4609. unset($data['type_id']);
  4610. //查询公告
  4611. $notice = Notice::where('id', $data['id'])->first();
  4612. if (empty($notice)) {
  4613. return Result::error("公告不存在", 0);
  4614. }
  4615. //$chat_ids 去除掉$data['user_id']
  4616. $chat_ids = json_decode($notice['re_user_ids'], true);
  4617. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4618. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4619. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  4620. //chat_group
  4621. $group_id = PublicData::uuid();
  4622. $groupData = [
  4623. 'id' => $group_id,
  4624. 'creator_id' => $notice['user_id'],
  4625. 'group_name' => $notice['group_name'] ?? '',
  4626. 'profile' => $notice['profile'] ?? 0,
  4627. ];
  4628. var_dump($groupData, '-----------------groupData-------');
  4629. $groupResult = ChatGroups::insertGetId($groupData);
  4630. var_dump($groupResult, '-----------------groupid-------');
  4631. $groupMemberData = [
  4632. 'id' => PublicData::uuid(),
  4633. 'user_id' => $notice['user_id'],
  4634. 'group_id' => $group_id,
  4635. 'leader' => 2,
  4636. ];
  4637. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4638. //插入群成员表
  4639. $groupMemberDataUser = [];
  4640. $chatData = [];
  4641. foreach ($chat_ids as $key => $value) {
  4642. $groupMemberDataUser[] = [
  4643. 'id' => PublicData::uuid(),
  4644. 'user_id' => $value,
  4645. 'group_id' => $group_id,
  4646. 'leader' => 1,
  4647. ];
  4648. $chatData[] = [
  4649. 'user_id' => $value,
  4650. 'msg_type' => 1,
  4651. 'receiver_id' => $group_id,
  4652. 'content' => '通过通知创建群聊',
  4653. 'group_receiver_id' => $notice['user_id'],
  4654. 'action' => 'recieved',
  4655. 'created_at' => date('Y-m-d H:i:s'),
  4656. ];
  4657. }
  4658. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4659. ChatGroupsMember::insert($groupMemberDataUser);
  4660. //插入一条管理员聊天记录
  4661. $chatData[] = [
  4662. 'user_id' => $notice['user_id'],
  4663. 'msg_type' => 1,
  4664. 'receiver_id' => $group_id,
  4665. 'content' => '通过通知创建群聊',
  4666. 'group_receiver_id' => $notice['user_id'],
  4667. 'action' => 'said',
  4668. 'created_at' => date('Y-m-d H:i:s'),
  4669. ];
  4670. var_dump($chatData, '-----------------chatData-------');
  4671. $chatResult = ChatRecords::insert($chatData);
  4672. //处理imp
  4673. $group = [
  4674. 'type' => 1,
  4675. 'name' => $notice['group_name'] ?? '',
  4676. 'profile' => '',
  4677. 'avatar' => '',
  4678. 'creator_id' => $notice['user_id'],
  4679. ];
  4680. $groupResult = GroupImp::insertGetId($group);
  4681. var_dump($groupResult, '获取imp group_id');
  4682. $groupMember = [
  4683. 'user_id' => $notice['user_id'],
  4684. 'group_id' => $groupResult,
  4685. 'leader' => 1,
  4686. 'join_time' => Date('Y-m-d H:i:s')
  4687. ];
  4688. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  4689. $talk_session = [
  4690. 'user_id' => $notice['user_id'],
  4691. 'to_from_id' => $groupResult,
  4692. 'talk_mode' => 2,
  4693. 'created_at' => Date('Y-m-d H:i:s'),
  4694. 'updated_at' => Date('Y-m-d H:i:s'),
  4695. ];
  4696. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  4697. //被通知人员处理
  4698. foreach ($chat_ids as $key => $value) {
  4699. $groupMemberdata[] = [
  4700. 'user_id' => $value,
  4701. 'group_id' => $groupResult,
  4702. 'leader' => 3,
  4703. 'join_time' => Date('Y-m-d H:i:s')
  4704. ];
  4705. $talk_sessionData[] = [
  4706. 'user_id' => $value,
  4707. 'to_from_id' => $groupResult,
  4708. 'talk_mode' => 2,
  4709. 'created_at' => Date('Y-m-d H:i:s'),
  4710. 'updated_at' => Date('Y-m-d H:i:s'),
  4711. ];
  4712. }
  4713. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  4714. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  4715. $group_id = $groupResult;
  4716. //更新result的 group_id
  4717. $data['group_id'] = $group_id;
  4718. Notice::where(['id' => $data['id']])->update($data);
  4719. }
  4720. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  4721. //删除掉信息
  4722. GroupImp::where('id', $notice['group_id'])->delete();
  4723. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  4724. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  4725. foreach ($chat_ids as $key => $value) {
  4726. }
  4727. //聊天记录删除
  4728. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  4729. $data['group_id'] = null;
  4730. Notice::where(['id' => $data['id']])->update($data);
  4731. }
  4732. $result = Notice::where('id', $data['id'])->update($data);
  4733. $noticeInfo = Notice::where('id', $data['id'])->first();
  4734. if ($data['status'] == 2) {
  4735. $this->sendMessage([
  4736. 'talk_type' => 701,
  4737. 'title' => $noticeInfo['title'],
  4738. 'content' => '审核通过',
  4739. 'messageType' => 3,
  4740. 'user_id' => $noticeInfo['user_id'],
  4741. ]);
  4742. }
  4743. if ($data['status'] == 3) {
  4744. $this->sendMessage([
  4745. 'talk_type' => 701,
  4746. 'title' => $noticeInfo['title'],
  4747. 'content' => '审核拒绝',
  4748. 'messageType' => 3,
  4749. 'user_id' => $noticeInfo['user_id'],
  4750. ]);
  4751. }
  4752. if ($data['status'] == 1) {
  4753. $this->sendMessage([
  4754. 'talk_type' => 700,
  4755. 'title' => $noticeInfo['title'],
  4756. 'content' => '提交了审核',
  4757. 'messageType' => 3,
  4758. ]);
  4759. }
  4760. return Result::success($result);
  4761. }
  4762. public function getDUser(array $data): array
  4763. {
  4764. if (!empty($data['ids'])) {
  4765. $user = User::whereIn('id', $data['ids'])->getall();
  4766. if (empty($user)) {
  4767. return Result::error('无数据', 0);
  4768. }
  4769. return Result::success($user);
  4770. }
  4771. $where = [];
  4772. if (!empty($data['department_id'])) {
  4773. $where['department_id'] = $data['department_id'];
  4774. }
  4775. if (!empty($data['city_id'])) {
  4776. $where['city_id'] = $data['city_id'];
  4777. }
  4778. $result = User::where('type_id', 2)
  4779. ->where('status', 1)
  4780. ->where($where)
  4781. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4782. ->get();
  4783. if (empty($result)) {
  4784. return Result::error("查询失败", 0);
  4785. }
  4786. return Result::success($result);
  4787. }
  4788. /**
  4789. * 验证导航名称是否重复
  4790. * @return void
  4791. */
  4792. public function checkCategoryName(array $data): array
  4793. {
  4794. $result = Category::when($data, function ($query) use ($data) {
  4795. if (isset($data['name']) && $data['name']) {
  4796. $query->where("name", $data['name']);
  4797. }
  4798. if (isset($data['id']) && $data['id']) {
  4799. $query->where("id", "!=", $data['id']);
  4800. }
  4801. })->first();
  4802. if ($result) {
  4803. return Result::error("已存在");
  4804. } else {
  4805. return Result::success();
  4806. }
  4807. }
  4808. //20250226 产品列表
  4809. // 20250306 -------招聘--------fr
  4810. /*
  4811. * 招聘列表
  4812. * */
  4813. public function getJobRecruitingList(array $data): array
  4814. {
  4815. $where = [];
  4816. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4817. if ($data['checkout'] == 0) {
  4818. $job_status = [0, 2];
  4819. } else {
  4820. $job_status = [1];
  4821. }
  4822. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4823. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4824. }
  4825. $user = User::where('id', $data['user_id'])->first();
  4826. if (empty($user)) {
  4827. return Result::error("用户不存在", 0);
  4828. }
  4829. // 3:企业会员
  4830. if ($user['type_id'] == 3) {
  4831. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4832. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4833. }
  4834. // 如果 $where 为空,则不添加 where 条件
  4835. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4836. return $query->where($where);
  4837. })
  4838. ->whereIn('job_recruiting.status', $job_status)
  4839. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4840. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4841. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4842. ->orderBy("updated_at", "desc")
  4843. ->offset(($data['page'] - 1) * $data['page_size'])
  4844. ->limit($data['page_size'])
  4845. ->get()
  4846. ->all();
  4847. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4848. return $query->where($where);
  4849. })
  4850. ->whereIn('job_recruiting.status', $job_status)
  4851. ->count();
  4852. if (empty($result)) {
  4853. return Result::error("暂无招聘信息", 0);
  4854. }
  4855. return Result::success($result);
  4856. }
  4857. /*
  4858. * 招聘信息添加
  4859. * */
  4860. public function addJobRecruiting(array $data): array
  4861. {
  4862. // var_dump('添加招聘进入news------data',$data);
  4863. // return Result::success($data);
  4864. $user = User::where('user.id', $data['user_id'])
  4865. ->where('user.status', 1)
  4866. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4867. ->select(
  4868. 'user.type_id',
  4869. 'user.mobile',
  4870. 'user.email',
  4871. 'user_info.business_name',
  4872. 'user_info.company_hy_id',
  4873. 'user_info.company_nature',
  4874. 'user_info.company_size',
  4875. 'user_info.introduction',
  4876. 'user_info.real_name',
  4877. 'user_info.company_url',
  4878. 'user_info.address_arr_id',
  4879. 'user_info.address'
  4880. )
  4881. ->first();
  4882. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4883. return Result::error("用户不存在", 0);
  4884. }
  4885. $web = Website::where('id', $data['website_id'])->first();
  4886. if (empty($web)) {
  4887. return Result::error("网站不存在", 0);
  4888. }
  4889. // var_dump('添加招聘进入news---user---user',$user);
  4890. // return Result::success($user);
  4891. $data['action_id'] = $data['user_id'] ?? null;
  4892. $data['user_type'] = $user['type_id'] ?? null;
  4893. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  4894. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  4895. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  4896. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  4897. // 公司地址 管理员必填
  4898. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  4899. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  4900. // 管理员-企业相关信息
  4901. $company = [
  4902. // 'user_id' => $data['user_id']?? null,
  4903. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  4904. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  4905. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  4906. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  4907. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  4908. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  4909. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  4910. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  4911. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  4912. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  4913. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  4914. ];
  4915. //去掉相关企业信息
  4916. $job = array_diff_key($data, array_flip(array_keys($company)));
  4917. // var_dump('添加招聘进入news---job---user',$job);
  4918. Db::beginTransaction();
  4919. try {
  4920. // // 先添加职位相关信息
  4921. if ($user['type_id'] == 10000) {
  4922. $job['status'] = 1;
  4923. }
  4924. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  4925. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  4926. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  4927. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  4928. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  4929. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  4930. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  4931. // return Result::success($job);
  4932. $jobId = JobRecruiting::insertGetId($job);
  4933. if (empty($jobId)) {
  4934. Db::rollBack();
  4935. return Result::error("添加失败");
  4936. }
  4937. // 添加公司信息
  4938. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  4939. $company['job_id'] = $jobId;
  4940. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  4941. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  4942. if ($user['type_id'] == 10000) {
  4943. // 管理员添加企业信息
  4944. $companyId = JobCompany::insertGetId($company);
  4945. if (empty($companyId)) {
  4946. Db::rollBack();
  4947. return Result::error("添加失败");
  4948. }
  4949. } else {
  4950. // 企业会员添加企业信息
  4951. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  4952. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  4953. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  4954. $company['job_id'] = $jobId;
  4955. $companyId = JobCompany::insertGetId($company);
  4956. if (empty($companyId)) {
  4957. Db::rollBack();
  4958. return Result::error("添加失败");
  4959. }
  4960. }
  4961. Db::commit();
  4962. $result = [
  4963. 'job_id' => $jobId,
  4964. 'company_id' => $companyId,
  4965. ];
  4966. return Result::success($result);
  4967. } catch (\Exception $e) {
  4968. Db::rollBack();
  4969. return Result::error($e->getMessage(), 0);
  4970. }
  4971. // return Result::success($result);
  4972. }
  4973. /*
  4974. * 获取招聘信息详情
  4975. * */
  4976. public function getJobRecruitingInfo(array $data): array
  4977. {
  4978. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4979. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4980. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4981. ->select(
  4982. 'job_recruiting.*',
  4983. 'website.website_name as website_name',
  4984. 'job_company.business_name',
  4985. 'job_company.company_hy_id',
  4986. 'job_company.company_size',
  4987. 'job_company.company_nature',
  4988. 'job_company.introduction',
  4989. 'job_company.real_name',
  4990. 'job_company.mobile',
  4991. 'job_company.company_url',
  4992. 'job_company.address_arr_id',
  4993. 'job_company.address',
  4994. 'job_company.email'
  4995. )
  4996. ->first();
  4997. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4998. if (!empty($cityId)) {
  4999. if (isset($cityId[1]) && $cityId[1] != null) {
  5000. $city = District::where('id', $cityId[1])->first(['name']);
  5001. } else {
  5002. $city = District::where('id', $cityId[0])->first(['name']);
  5003. }
  5004. $result['city'] = $city['name'] ?? '';
  5005. }
  5006. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5007. if (is_array($addressId) && !empty($addressId)) {
  5008. $address = District::whereIn('id', $addressId)
  5009. ->orderBy('level', 'asc')
  5010. ->get(['name'])
  5011. ->pluck('name')
  5012. ->implode('');
  5013. // $job->address_name = $address ?? '';
  5014. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5015. }
  5016. if (empty($result)) {
  5017. return Result::error("招聘信息不存在", 0);
  5018. }
  5019. // return Result::success($job);
  5020. return Result::success($result);
  5021. }
  5022. /*
  5023. * 修改招聘信息
  5024. * */
  5025. public function upJobRecruiting(array $data): array
  5026. {
  5027. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5028. // return Result::success($job);
  5029. if (empty($job)) {
  5030. return Result::error("招聘信息不存在", 0);
  5031. }
  5032. $user = User::where('id', $data['user_id'])->first();
  5033. // return Result::success($user);
  5034. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5035. return Result::error("用户不存在", 0);
  5036. }
  5037. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5038. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5039. }
  5040. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5041. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5042. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5043. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5044. // 公司地址 管理员必填
  5045. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5046. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5047. // 管理员-企业相关信息
  5048. $company = [
  5049. // 'user_id' => $data['user_id']?? null,
  5050. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5051. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5052. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5053. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5054. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5055. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5056. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5057. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5058. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5059. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5060. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5061. ];
  5062. //去掉相关企业信息
  5063. $data = array_diff_key($data, array_flip(array_keys($company)));
  5064. $jobId = $data['id'];
  5065. $web = $data['website_id'];
  5066. $data['action_id'] = $data['user_id'];
  5067. unset($data['user_id']);
  5068. unset($data['user_type']);
  5069. unset($data['id']);
  5070. unset($data['website_id']);
  5071. // return Result::success($data);
  5072. Db::beginTransaction();
  5073. try {
  5074. // 管理员修改招聘信息
  5075. if ($user['type_id'] == 10000) {
  5076. $data['website_id'] = $web;
  5077. $company['website_id'] = $data['website_id'];
  5078. $data['status'] = 1;
  5079. } else {
  5080. $data['status'] = 0;
  5081. }
  5082. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5083. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5084. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5085. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5086. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5087. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5088. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5089. // return Result::success($job);
  5090. // Db::rollBack();
  5091. // return Result::success($company);
  5092. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5093. $this->sendMessage([
  5094. 'talk_type' => 500,
  5095. 'title' => $data['title'],
  5096. 'content' => '提交了审核',
  5097. 'messageType' => 10,
  5098. ]);
  5099. }
  5100. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5101. if (empty($result['job'])) {
  5102. Db::rollBack();
  5103. return Result::error("修改招聘信息失败");
  5104. }
  5105. // 管理员修改企业相关信息
  5106. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5107. if (empty($result['company'])) {
  5108. Db::rollBack();
  5109. return Result::error("修改企业相关信息失败");
  5110. }
  5111. Db::commit();
  5112. // return Result::success($result);
  5113. } catch (\Exception $e) {
  5114. Db::rollBack();
  5115. return Result::error($e->getMessage(), 0);
  5116. }
  5117. return Result::success($result);
  5118. }
  5119. /*
  5120. * 招聘信息删除
  5121. * */
  5122. public function delJobRecruiting(array $data): array
  5123. {
  5124. $user = User::where('id', $data['user_id'])->first();
  5125. if (empty($user)) {
  5126. return Result::error("用户不存在", 0);
  5127. }
  5128. $job = JobRecruiting::where('id', $data['id'])->first();
  5129. if (empty($job)) {
  5130. return Result::error("招聘信息不存在", 0);
  5131. }
  5132. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5133. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5134. }
  5135. Db::beginTransaction();
  5136. try {
  5137. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5138. if (empty($result['job'])) {
  5139. Db::rollBack();
  5140. return Result::error("删除招聘信息失败");
  5141. }
  5142. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5143. if (empty($result['company'])) {
  5144. Db::rollBack();
  5145. return Result::error("删除企业相关信息失败");
  5146. }
  5147. Db::commit();
  5148. } catch (\Exception $e) {
  5149. Db::rollBack();
  5150. return Result::error($e->getMessage(), 0);
  5151. }
  5152. return Result::success($result);
  5153. }
  5154. /*
  5155. * 获取公司信息
  5156. * */
  5157. public function getJobCompany(array $data): array
  5158. {
  5159. $user = User::where('user.id', $data['user_id'])
  5160. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5161. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5162. ->first();
  5163. // return Result::success($user);
  5164. if (empty($user)) {
  5165. return Result::error("用户不存在", 0);
  5166. }
  5167. if ($user['type_id'] == 3) {
  5168. $result = [
  5169. // 'id' => 0,
  5170. 'user_id' => $data['user_id'],
  5171. 'website_id' => $data['website_id'],
  5172. 'business_name' => $user['business_name'], // 企业名称
  5173. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5174. 'company_nature' => $user['company_nature'], // 公司性质
  5175. 'company_size' => $user['company_size'], // 公司规模
  5176. 'introduction' => $user['introduction'], // 公司简介
  5177. 'real_name' => $user['real_name'], // 企业联系人
  5178. 'mobile' => $user['mobile'], // 企业联系电话
  5179. 'company_url' => $user['company_url'], // 企业网址
  5180. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5181. 'address' => $user['address'], // 企业地址
  5182. 'email' => $user['email'], // 企业邮箱
  5183. ];
  5184. } else {
  5185. return Result::error("用户类型错误", 0);
  5186. }
  5187. if (empty($result)) {
  5188. return Result::error("公司信息不存在", 0);
  5189. }
  5190. return Result::success($result);
  5191. }
  5192. /*
  5193. * 修改公司信息
  5194. * */
  5195. public function upJobCompany(array $data): array
  5196. {
  5197. // return Result::success($data);
  5198. $user = User::where('user.id', $data['user_id'])
  5199. ->where('user.status', 1)
  5200. ->select('user.user_name', 'user.type_id')
  5201. ->first();
  5202. if (empty($user)) {
  5203. return Result::error("用户不存在", 0);
  5204. }
  5205. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5206. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5207. $company = [
  5208. 'business_name' => $data['business_name'], // 企业名称
  5209. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5210. 'company_nature' => $data['company_nature'], // 公司性质
  5211. 'company_size' => $data['company_size'], // 公司规模
  5212. 'introduction' => $data['introduction'], // 公司简介
  5213. // 'real_name' => $data['real_name'], // 企业联系人
  5214. 'company_url' => $data['company_url'], // 企业网址
  5215. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5216. 'address' => $data['address'], // 企业详细地址
  5217. // 'email' => $data['email'], // 企业邮箱
  5218. ];
  5219. if ($user['type_id'] == 3) {
  5220. Db::beginTransaction();
  5221. try {
  5222. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5223. 'business_name' => $data['business_name'], // 企业名称
  5224. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5225. 'company_nature' => $data['company_nature'], // 公司性质
  5226. 'company_size' => $data['company_size'], // 公司规模
  5227. 'introduction' => $data['introduction'], // 公司简介
  5228. // 'real_name' => $data['real_name'], // 企业联系人
  5229. 'company_url' => $data['company_url'], // 企业网址
  5230. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5231. 'address' => $data['address'], // 企业详细地址
  5232. ]);
  5233. if (empty($result['userinfo'])) {
  5234. Db::rollBack();
  5235. return Result::error('修改企业会员信息失败!');
  5236. }
  5237. $result['user'] = User::where('id', $data['user_id'])->update([
  5238. 'email' => $data['email'], // 企业邮箱
  5239. ]);
  5240. if (empty($result['user'])) {
  5241. Db::rollBack();
  5242. return Result::error('修改个人中心信息失败!');
  5243. }
  5244. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5245. if (!empty($job_company)) {
  5246. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5247. if (empty($result['job_company'])) {
  5248. Db::rollBack();
  5249. return Result::error('修改企业会员信息失败!');
  5250. }
  5251. }
  5252. Db::commit();
  5253. return Result::success($result);
  5254. } catch (\Exception $e) {
  5255. Db::rollBack();
  5256. return Result::error($e->getMessage(), 0);
  5257. }
  5258. } else {
  5259. return Result::error("用户类型错误", 0);
  5260. }
  5261. }
  5262. /*
  5263. * 获取省-市
  5264. * */
  5265. public function getJobRecruitingArea(array $data): array
  5266. {
  5267. if (isset($data['pid']) && $data['pid'] != null) {
  5268. $result = District::where('pid', $data['pid'])->get()->all();
  5269. } else {
  5270. $result = District::where('level', 1)->get()->all();
  5271. }
  5272. if (empty($result)) {
  5273. return Result::error("暂无此省市", 0);
  5274. }
  5275. return Result::success($result);
  5276. }
  5277. /*
  5278. * 获取行业分类
  5279. * */
  5280. public function getIndustry(array $data): array
  5281. {
  5282. $result = JobIndustry::get()->all();
  5283. if (empty($result)) {
  5284. return Result::error("暂无行业分类", 0);
  5285. }
  5286. return Result::success($result);
  5287. }
  5288. /*
  5289. * 获取职位
  5290. * */
  5291. public function getPositionList(array $data): array
  5292. {
  5293. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5294. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5295. } else {
  5296. $result = JobPosition::where('zwpid', 0)->get()->all();
  5297. }
  5298. if (empty($result)) {
  5299. return Result::error("暂无此职位", 0);
  5300. }
  5301. return Result::success($result);
  5302. }
  5303. /*
  5304. * 获取工作性质-菜单
  5305. * */
  5306. public function getJobNature(array $data): array
  5307. {
  5308. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5309. if (empty($result)) {
  5310. return Result::error("暂无工作性质", 0);
  5311. }
  5312. return Result::success($result);
  5313. }
  5314. /*
  5315. * 获取工作经验-菜单
  5316. * */
  5317. public function getExperience(array $data): array
  5318. {
  5319. $result = JobEnum::where('egroup', 'years')->get()->all();
  5320. if (empty($result)) {
  5321. return Result::error("暂无工作经验", 0);
  5322. }
  5323. return Result::success($result);
  5324. }
  5325. /*
  5326. * 获取学历-菜单
  5327. * */
  5328. public function getEducation(array $data): array
  5329. {
  5330. $result = JobEnum::where('egroup', 'education')->get()->all();
  5331. if (empty($result)) {
  5332. return Result::error("暂无学历", 0);
  5333. }
  5334. return Result::success($result);
  5335. }
  5336. /*
  5337. * 获取薪资-菜单
  5338. * */
  5339. public function getSalary(array $data): array
  5340. {
  5341. $result = JobEnum::where('egroup', 'income')->get()->all();
  5342. if (empty($result)) {
  5343. return Result::error("暂无薪资", 0);
  5344. }
  5345. return Result::success($result);
  5346. }
  5347. /*
  5348. * 获取语言-菜单
  5349. * */
  5350. public function getLanguage(array $data): array
  5351. {
  5352. $result = JobEnum::where('egroup', 'language')->get()->all();
  5353. if (empty($result)) {
  5354. return Result::error("暂无语言", 0);
  5355. }
  5356. return Result::success($result);
  5357. }
  5358. /*
  5359. * 获取掌握程度-菜单
  5360. * */
  5361. public function getLevel(array $data): array
  5362. {
  5363. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5364. if (empty($result)) {
  5365. return Result::error("暂无工作性质", 0);
  5366. }
  5367. return Result::success($result);
  5368. }
  5369. // 公司信息
  5370. /*
  5371. * 获取公司性质-菜单
  5372. * */
  5373. public function getCompanyNature(array $data): array
  5374. {
  5375. $result = JobNature::get()->all();
  5376. if (empty($result)) {
  5377. return Result::error("暂无公司性质", 0);
  5378. }
  5379. return Result::success($result);
  5380. }
  5381. /*
  5382. * 获取公司规模-菜单
  5383. * */
  5384. public function getCompanySize(array $data): array
  5385. {
  5386. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5387. if (empty($result)) {
  5388. return Result::error("暂无公司规模", 0);
  5389. }
  5390. return Result::success($result);
  5391. }
  5392. /*
  5393. * 招聘信息审核
  5394. * */
  5395. public function checkJobRecruiting(array $data): array
  5396. {
  5397. $user = User::where('id', $data['user_id'])->first();
  5398. if (empty($user)) {
  5399. return Result::error("用户不存在", 0);
  5400. }
  5401. $job = JobRecruiting::where('id', $data['id'])->first();
  5402. if (empty($job)) {
  5403. return Result::error("招聘信息不存在", 0);
  5404. }
  5405. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5406. if ($user['type_id'] != 10000) {
  5407. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5408. }
  5409. // 驳回原因
  5410. if ($data['status'] == 2) {
  5411. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5412. }
  5413. $data['action_id'] = $data['user_id'];
  5414. unset($data['user_id']);
  5415. if ($data['status'] == 1) {
  5416. $this->sendMessage([
  5417. 'talk_type' => 501,
  5418. 'title' => $job['title'],
  5419. 'content' => '审核通过',
  5420. 'messageType' => 10,
  5421. 'user_id' => $job['user_id'],
  5422. ]);
  5423. }
  5424. if ($data['status'] == 2) {
  5425. $this->sendMessage([
  5426. 'talk_type' => 501,
  5427. 'title' => $job['title'],
  5428. 'content' => '审核拒绝',
  5429. 'messageType' => 10,
  5430. 'user_id' => $job['user_id'],
  5431. ]);
  5432. }
  5433. if ($data['status'] == 0) {
  5434. $this->sendMessage([
  5435. 'talk_type' => 500,
  5436. 'title' => $job['title'],
  5437. 'content' => '提交了审核',
  5438. 'messageType' => 10,
  5439. ]);
  5440. }
  5441. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5442. if (empty($result)) {
  5443. return Result::error("审核失败", 0);
  5444. }
  5445. return Result::success($result);
  5446. }
  5447. public function myApplyList(array $data): array
  5448. {
  5449. var_dump($data, '------参数');
  5450. $user = User::where('id', $data['user_id'])->first();
  5451. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5452. return Result::error("用户不存在", 0);
  5453. }
  5454. // 1:个人会员 职场机会
  5455. if ($user['type_id'] == 1) {
  5456. $where['user_id'] = $user['id'];
  5457. }
  5458. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5459. $query->where('user_id', $user['id']);
  5460. })
  5461. ->pluck('recruit_id');
  5462. $where = [];
  5463. if (isset($data['salary']) && $data['salary'] != null) {
  5464. $where['job_recruiting.salary'] = $data['salary'];
  5465. }
  5466. if (isset($data['experience']) && $data['experience'] != null) {
  5467. $where['job_recruiting.experience'] = $data['experience'];
  5468. }
  5469. if (isset($data['business_name']) && $data['business_name'] != null) {
  5470. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5471. }
  5472. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5473. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5474. ->where($where);
  5475. // ->count();
  5476. $count = $query->count();
  5477. $query = clone $query;
  5478. $job = $query
  5479. ->leftJoin('job_enum as income_enum', function ($join) {
  5480. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5481. ->where('income_enum.egroup', 'income');
  5482. })
  5483. ->leftJoin('job_enum as years_enum', function ($join) {
  5484. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5485. ->where('years_enum.egroup', 'years');
  5486. })
  5487. // ->where($where)
  5488. ->orderBy('job_recruiting.updated_at', 'desc')
  5489. ->select(
  5490. 'job_recruiting.id',
  5491. 'job_recruiting.title',
  5492. 'job_company.business_name',
  5493. 'income_enum.evalue as salary_evalue',
  5494. 'income_enum.ename as salary_ename',
  5495. 'years_enum.evalue as experience_evalue',
  5496. 'years_enum.ename as experience_ename',
  5497. 'job_recruiting.updated_at'
  5498. )
  5499. ->offset(($data['page'] - 1) * $data['pageSize'])
  5500. ->limit($data['pageSize'])
  5501. ->get()
  5502. ->all();
  5503. if (empty($job)) {
  5504. return Result::error("暂无招聘信息", 0);
  5505. }
  5506. $result = [
  5507. 'row' => $job,
  5508. 'count' => $count,
  5509. ];
  5510. return Result::success($result);
  5511. }
  5512. public function readJobApply(array $data): array
  5513. {
  5514. $result = JobApply::where('id', $data['id'])->first();
  5515. if (empty($result)) {
  5516. return Result::error("查询失败", 0);
  5517. }
  5518. $result = JobApply::where('id', $data['id'])->update([
  5519. 'status' => 2,
  5520. ]);
  5521. return Result::success($result);
  5522. }
  5523. /*
  5524. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5525. * */
  5526. public function getRecruitingList(array $data): array
  5527. {
  5528. $user = User::where('id', $data['user_id'])->first();
  5529. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5530. return Result::error("用户不存在", 0);
  5531. }
  5532. // 1:个人会员 职场机会
  5533. if ($user['type_id'] == 1) {
  5534. $where['user_id'] = $user['id'];
  5535. }
  5536. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5537. $query->where('receiver_id', $user['id']);
  5538. })
  5539. ->pluck('recruit_id');
  5540. // return Result::success($recruitingId);
  5541. $where = [];
  5542. if (isset($data['salary']) && $data['salary'] != null) {
  5543. $where['job_recruiting.salary'] = $data['salary'];
  5544. }
  5545. if (isset($data['experience']) && $data['experience'] != null) {
  5546. $where['job_recruiting.experience'] = $data['experience'];
  5547. }
  5548. if (isset($data['business_name']) && $data['business_name'] != null) {
  5549. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5550. }
  5551. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5552. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5553. ->where($where);
  5554. // ->count();
  5555. $count = $query->count();
  5556. $query = clone $query;
  5557. $job = $query
  5558. ->leftJoin('job_enum as income_enum', function ($join) {
  5559. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5560. ->where('income_enum.egroup', 'income');
  5561. })
  5562. ->leftJoin('job_enum as years_enum', function ($join) {
  5563. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5564. ->where('years_enum.egroup', 'years');
  5565. })
  5566. // ->where($where)
  5567. ->orderBy('job_recruiting.updated_at', 'desc')
  5568. ->select(
  5569. 'job_recruiting.id',
  5570. 'job_recruiting.title',
  5571. 'job_company.business_name',
  5572. 'income_enum.evalue as salary_evalue',
  5573. 'income_enum.ename as salary_ename',
  5574. 'years_enum.evalue as experience_evalue',
  5575. 'years_enum.ename as experience_ename',
  5576. 'job_recruiting.updated_at'
  5577. )
  5578. ->offset(($data['page'] - 1) * $data['pageSize'])
  5579. ->limit($data['pageSize'])
  5580. ->get()
  5581. ->all();
  5582. if (empty($job)) {
  5583. return Result::error("暂无招聘信息", 0);
  5584. }
  5585. $result = [
  5586. 'row' => $job,
  5587. 'count' => $count,
  5588. ];
  5589. return Result::success($result);
  5590. }
  5591. /*
  5592. * 获取企业会员-招聘信息列表
  5593. * */
  5594. public function getRecruitingInfo(array $data): array
  5595. {
  5596. $user = User::where('id', $data['user_id'])->first();
  5597. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5598. return Result::error("用户不存在", 0);
  5599. }
  5600. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5601. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5602. ->select(
  5603. 'job_recruiting.*',
  5604. 'job_company.business_name',
  5605. 'job_company.company_hy_id',
  5606. 'job_company.company_size',
  5607. 'job_company.company_nature',
  5608. 'job_company.introduction',
  5609. 'job_company.real_name',
  5610. 'job_company.mobile',
  5611. 'job_company.company_url',
  5612. 'job_company.address_arr_id',
  5613. 'job_company.address',
  5614. 'job_company.email'
  5615. )
  5616. ->get();
  5617. if (empty($recruiting)) {
  5618. return Result::error("暂无招聘信息", 0);
  5619. }
  5620. return Result::success($recruiting);
  5621. }
  5622. /*
  5623. * 获取企业会员-我的沟通
  5624. * */
  5625. public function getJobResumeList(array $data): array
  5626. {
  5627. $user = User::where('id', $data['user_id'])->first();
  5628. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5629. return Result::error("用户不存在", 0);
  5630. }
  5631. $where = [];
  5632. if (isset($data['salary']) && $data['salary'] != null) {
  5633. $where['job_hunting.salary'] = $data['salary'];
  5634. }
  5635. if (isset($data['user_name']) && $data['user_name'] != null) {
  5636. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5637. }
  5638. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5639. $query->where('job_resume.user_id', $user['id']);
  5640. })
  5641. ->when(!empty($where), function ($query) use ($where) {
  5642. $query->where($where);
  5643. })
  5644. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5645. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5646. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5647. ->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');
  5648. $count = $job->count();
  5649. if ($count == 0) {
  5650. return Result::error("暂无沟通记录", 0);
  5651. }
  5652. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5653. ->offset(($data['page'] - 1) * $data['pageSize'])
  5654. ->limit($data['pageSize'])
  5655. ->get();
  5656. if (empty($jobs)) {
  5657. return Result::error("暂无沟通记录", 0);
  5658. }
  5659. $result['row'] = $this->processJob($jobs, '');
  5660. $result['count'] = $count;
  5661. return Result::success($result);
  5662. }
  5663. public function readJobResume(array $data): array
  5664. {
  5665. $result = JobResume::where('id', $data['id'])->first();
  5666. if (empty($result)) {
  5667. return Result::error("查询失败", 0);
  5668. }
  5669. $result = JobResume::where('id', $data['id'])->update([
  5670. 'status' => 2,
  5671. ]);
  5672. return Result::success($result);
  5673. }
  5674. // 20250306 招聘
  5675. //20250422 书刊音像
  5676. public function addBook(array $data): array
  5677. {
  5678. $user_id = $data['user_id'] ?? 0;
  5679. $type_id = $data['type_id'] ?? 0;
  5680. // $website_id = $data['website_id'] ?? 0;
  5681. // unset($data['user_id']);
  5682. unset($data['type_id']);
  5683. // unset($data['website_id']);
  5684. //处理数组
  5685. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5686. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5687. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5688. if ($data['img_url'] == '') {
  5689. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5690. preg_match_all($reg, $data['detail'], $matches);
  5691. if (isset($matches[1][0])) {
  5692. //截取varchar240
  5693. $data['img_url'] = substr($matches[1][0], 0, 240);
  5694. }
  5695. }
  5696. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5697. //提取标题+内容中的关键词
  5698. $data['keyword'] = $data['title'];
  5699. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5700. Jieba::init(); // 初始化 jieba-php
  5701. Finalseg::init();
  5702. $segList = Jieba::cut($data['keyword']);
  5703. $segList1 = array_slice($segList, 0, 8);
  5704. $data['keyword'] = implode(',', $segList1);
  5705. }
  5706. if ($data['description'] == '') {
  5707. //提取内容中的描述
  5708. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5709. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5710. }
  5711. var_dump($data, '--');
  5712. if ($data['status'] == 1) {
  5713. $this->sendMessage([
  5714. 'talk_type' => 400,
  5715. 'title' => $data['title'],
  5716. 'content' => '提交了审核',
  5717. 'messageType' => 7,
  5718. ]);
  5719. }
  5720. $result = Book::insertGetId($data);
  5721. if (empty($result)) {
  5722. return Result::error("添加失败", 0);
  5723. }
  5724. return Result::success($result);
  5725. }
  5726. public function getBookList(array $data): array
  5727. {
  5728. $where = [];
  5729. if (!empty($data["title"])) {
  5730. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5731. }
  5732. if (!empty($data['website_name'])) {
  5733. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5734. }
  5735. if (!empty($data['status'])) {
  5736. $where[] = ['book.status', '=', $data['status']];
  5737. }
  5738. $user_id = $data['user_id'];
  5739. $type_id = $data['type_id'];
  5740. // $type_id = 4;
  5741. var_dump($type_id, '------1--------');
  5742. if ($type_id != 10000) {
  5743. $where[] = ['book.user_id', '=', $user_id];
  5744. }
  5745. var_dump(!empty($data['status1']), '=-===1');
  5746. $result = Book::where($where)
  5747. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5748. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5749. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5750. ->when(isset($data['status1']), function ($query) use ($data) {
  5751. $query->whereIn('book.status', [1, 3]);
  5752. })
  5753. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5754. ->orderBy("updated_at", "desc")
  5755. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5756. if (empty($result)) {
  5757. return Result::error("暂无数据", 0);
  5758. }
  5759. // 取出数据
  5760. $rows = $result->items();
  5761. $count = $result->total();
  5762. $responseData = [
  5763. 'rows' => $rows,
  5764. 'count' => $count,
  5765. ];
  5766. return Result::success($responseData);
  5767. }
  5768. public function deleteBook(array $data): array
  5769. {
  5770. $result = Book::where('id', $data['id'])->delete();
  5771. if (empty($result)) {
  5772. return Result::error("删除失败", 0);
  5773. }
  5774. return Result::success($result);
  5775. }
  5776. public function updateBook(array $data): array
  5777. {
  5778. // $user_id = $data['user_id'] ?? 0;
  5779. $type_id = $data['type_id'] ?? 0;
  5780. // $website_id = $data['website_id'] ?? 0;
  5781. unset($data['user_id']);
  5782. unset($data['type_id']);
  5783. // unset($data['website_id']);
  5784. //处理数组
  5785. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5786. if ($data['img_url'] == '') {
  5787. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5788. preg_match_all($reg, $data['detail'], $matches);
  5789. if (isset($matches[1][0])) {
  5790. //截取varchar240
  5791. $data['img_url'] = substr($matches[1][0], 0, 240);
  5792. }
  5793. }
  5794. if ($data['keyword'] == '') {
  5795. //提取标题+内容中的关键词
  5796. $data['keyword'] = $data['title'];
  5797. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5798. Jieba::init(); // 初始化 jieba-php
  5799. Finalseg::init();
  5800. $segList = Jieba::cut($data['keyword']);
  5801. $segList1 = array_slice($segList, 0, 8);
  5802. $data['keyword'] = implode(',', $segList1);
  5803. }
  5804. if ($data['description'] == '') {
  5805. //提取内容中的描述
  5806. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5807. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5808. }
  5809. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5810. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5811. if ($data['status'] == 1) {
  5812. $this->sendMessage([
  5813. 'talk_type' => 400,
  5814. 'title' => $data['title'],
  5815. 'content' => '提交了审核',
  5816. 'messageType' => 7,
  5817. ]);
  5818. }
  5819. $result = Book::where("id", $data["id"])->update($data);
  5820. if (empty($result)) {
  5821. return Result::error("更新失败", 0);
  5822. }
  5823. return Result::success($result);
  5824. }
  5825. public function getBookInfo(array $data): array
  5826. {
  5827. $result = Book::where("id", $data["id"])->first();
  5828. if (empty($result)) {
  5829. return Result::error("获取失败", 0);
  5830. }
  5831. return Result::success($result);
  5832. }
  5833. public function updateBookStatus(array $data): array
  5834. {
  5835. //审核
  5836. unset($data['user_id']);
  5837. $bookInfo = Book::where("id", $data["id"])->first();
  5838. var_dump($bookInfo, '----');
  5839. if ($data['status'] == 2) {
  5840. $this->sendMessage([
  5841. 'talk_type' => 401,
  5842. 'title' => $bookInfo['title'],
  5843. 'content' => '审核通过',
  5844. 'messageType' => 7,
  5845. 'user_id' => $bookInfo['user_id'],
  5846. ]);
  5847. }
  5848. if ($data['status'] == 3) {
  5849. $this->sendMessage([
  5850. 'talk_type' => 401,
  5851. 'title' => $bookInfo['title'],
  5852. 'content' => '审核拒绝',
  5853. 'messageType' => 7,
  5854. 'user_id' => $bookInfo['user_id'],
  5855. ]);
  5856. }
  5857. if ($data['status'] == 1) {
  5858. $this->sendMessage([
  5859. 'talk_type' => 400,
  5860. 'title' => $bookInfo['title'],
  5861. 'content' => '提交了审核',
  5862. 'messageType' => 7,
  5863. // 'user_id'=>$bookInfo['user_id'],
  5864. ]);
  5865. }
  5866. $result = Book::where("id", $data["id"])->update($data);
  5867. if (empty($result)) {
  5868. return Result::error("更新失败", 0);
  5869. }
  5870. return Result::success($result);
  5871. }
  5872. //20250422 书刊音像
  5873. /**
  5874. * 贴身宝贝
  5875. * @param array $data
  5876. * @return array
  5877. */
  5878. public function getWebsiteTsbb(array $data): array
  5879. {
  5880. $month = $data['month'] ?? date('m');
  5881. $day = $data['day'] ?? date('d');
  5882. // 使用缓存键
  5883. $cacheKey = "tsbb_data_{$month}_{$day}";
  5884. // 尝试从缓存获取数据
  5885. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5886. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5887. if ($cachedData = $cache->get($cacheKey)) {
  5888. return Result::success(unserialize($cachedData));
  5889. }
  5890. //查询老黄历
  5891. try {
  5892. $date = date('Y-m-d');
  5893. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5894. // 使用 curl 替代 file_get_contents
  5895. $ch = curl_init();
  5896. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5897. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5898. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5899. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5900. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5901. 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');
  5902. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5903. 'Accept: application/json',
  5904. 'Content-Type: application/json',
  5905. 'Referer: https://www.36jxs.com/'
  5906. ]);
  5907. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5908. curl_setopt($ch, CURLOPT_ENCODING, '');
  5909. $almanacResponse = curl_exec($ch);
  5910. var_dump("====:", $almanacResponse);
  5911. if (curl_errno($ch)) {
  5912. var_dump('Curl error:', curl_error($ch));
  5913. throw new \Exception('Curl error: ' . curl_error($ch));
  5914. }
  5915. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5916. curl_close($ch);
  5917. if ($almanacResponse === false) {
  5918. throw new \Exception('Failed to fetch almanac data');
  5919. }
  5920. $almanacData = json_decode($almanacResponse, true);
  5921. if (json_last_error() !== JSON_ERROR_NONE) {
  5922. throw new \Exception('Failed to parse almanac data');
  5923. }
  5924. $almanacInfo = $almanacData['data'] ?? [];
  5925. } catch (\Exception $e) {
  5926. var_dump('Exception:', $e->getMessage());
  5927. $almanacInfo = [];
  5928. }
  5929. // 获取历史上的今天数据
  5930. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5931. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5932. ->orderBy('year', 'asc')
  5933. ->select("title", "id", "year", DB::raw('1 as type'))
  5934. ->limit(16)
  5935. ->get();
  5936. // 获取节日数据 - 从今天开始获取未来4条
  5937. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5938. ->orderBy('showtime', 'asc')
  5939. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5940. ->limit(16)
  5941. ->get();
  5942. //说文解字
  5943. $chartacterList = Character::orderBy('updated_at', 'desc')
  5944. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5945. ->limit(6)
  5946. ->get();
  5947. //谜语沙龙
  5948. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5949. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5950. ->limit(4)
  5951. ->get();
  5952. //成语欣赏
  5953. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5954. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5955. ->limit(32)
  5956. ->get();
  5957. //名联赏析
  5958. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5959. ->select("id", "first", "second", DB::raw('6 as type'))
  5960. ->limit(6)
  5961. ->get();
  5962. // 获取分类文章数据
  5963. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5964. ->pluck('category_id')
  5965. ->toArray();
  5966. $articlesList = [];
  5967. foreach ($categoryIds as $catid) {
  5968. // 先查有图片的
  5969. $withImg = DB::table('article')
  5970. ->where('status', 1)
  5971. ->where('catid', $catid)
  5972. ->whereNotNull('imgurl')
  5973. ->where('imgurl', '!=', '')
  5974. ->orderBy('updated_at', 'desc')
  5975. ->limit(6)
  5976. ->get();
  5977. $count = $withImg->count();
  5978. if ($count < 6) {
  5979. // 不足6条再查无图片的补足
  5980. $withoutImg = DB::table('article')
  5981. ->where('status', 1)
  5982. ->where('catid', $catid)
  5983. ->where(function ($q) {
  5984. $q->whereNull('imgurl')->orWhere('imgurl', '');
  5985. })
  5986. ->orderBy('updated_at', 'desc')
  5987. ->limit(6 - $count)
  5988. ->get();
  5989. $articles = $withImg->concat($withoutImg);
  5990. } else {
  5991. $articles = $withImg;
  5992. }
  5993. // 组装
  5994. $category = \App\Model\Category::find($catid);
  5995. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  5996. $articlesList[] = [
  5997. 'category_name' => $category ? $category->name : '',
  5998. 'catid' => $catid,
  5999. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6000. 'type' => 100,
  6001. 'list' => $articles->map(function ($item) {
  6002. return [
  6003. 'id' => $item->id,
  6004. 'title' => $item->title,
  6005. 'imgurl' => $item->imgurl,
  6006. 'created_at' => $item->created_at
  6007. ];
  6008. })->values()
  6009. ];
  6010. }
  6011. $result = [
  6012. 'almanac' => $almanacInfo,
  6013. 'historyTodayList' => [
  6014. 'category_name' => '历史上的今天',
  6015. 'list' => $historyTodayList,
  6016. 'type' => 1
  6017. ],
  6018. 'festivalList' => [
  6019. 'category_name' => '节日预告',
  6020. 'list' => $festivalList,
  6021. 'type' => 2
  6022. ],
  6023. 'chartacterList' => [
  6024. 'category_name' => '说文解字',
  6025. 'list' => $chartacterList,
  6026. 'type' => 3
  6027. ],
  6028. 'coupletList' => [
  6029. 'category_name' => '名联赏析',
  6030. 'list' => $coupletList,
  6031. 'type' => 6
  6032. ],
  6033. 'riddletList' => [
  6034. 'category_name' => '谜语沙龙',
  6035. 'list' => $riddletList,
  6036. 'type' => 4
  6037. ],
  6038. 'idiomList' => [
  6039. 'category_name' => '成语欣赏',
  6040. 'list' => $idiomList,
  6041. 'type' => 5
  6042. ],
  6043. 'articlesList' => $articlesList
  6044. ];
  6045. // 缓存结果,设置1小时过期
  6046. $cache->set($cacheKey, serialize($result), 3600);
  6047. return Result::success($result);
  6048. }
  6049. /**
  6050. * 获取资讯列表
  6051. */
  6052. public function getWebsiteTsbbList(array $data): array
  6053. {
  6054. $page = $data['page'] ?? 1;
  6055. $pageSize = $data['pageSize'] ?? 10;
  6056. // 如果没有传入月份和日期,则使用今天的日期
  6057. $month = $data['month'] ?? date('m');
  6058. $day = $data['day'] ?? date('d');
  6059. $total = 0;
  6060. $result = [];
  6061. $data['type'] = intval($data['type']);
  6062. var_dump("接收参数:", $data);
  6063. switch ($data['type']) {
  6064. case 1:
  6065. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6066. // 当前月份之后的数据
  6067. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6068. // 或者当前月份且日期大于等于当前日期的数据
  6069. ->orWhere(function ($q) use ($month, $day) {
  6070. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6071. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6072. });
  6073. })
  6074. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6075. $total = $query->count();
  6076. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6077. ->offset(($page - 1) * $pageSize)
  6078. ->limit($pageSize)
  6079. ->get();
  6080. break;
  6081. case 2:
  6082. $query = Festival::where(function ($q) use ($month, $day) {
  6083. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6084. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6085. ->orWhere(function ($q) use ($month, $day) {
  6086. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6087. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6088. });
  6089. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6090. $total = $query->count();
  6091. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6092. ->offset(($page - 1) * $pageSize)
  6093. ->limit($pageSize)
  6094. ->get();
  6095. break;
  6096. case 3:
  6097. $query = Character::orderBy("updated_at", "desc");
  6098. $total = $query->count();
  6099. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6100. ->offset(($page - 1) * $pageSize)
  6101. ->limit($pageSize)
  6102. ->get();
  6103. break;
  6104. case 4:
  6105. $query = Riddle::orderBy("updated_at", "desc");
  6106. $total = $query->count();
  6107. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6108. ->offset(($page - 1) * $pageSize)
  6109. ->limit($pageSize)
  6110. ->get();
  6111. break;
  6112. case 5:
  6113. $query = Idiom::orderBy("updated_at", "desc");
  6114. $total = $query->count();
  6115. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6116. ->offset(($page - 1) * $pageSize)
  6117. ->limit($pageSize)
  6118. ->get();
  6119. break;
  6120. case 6:
  6121. $query = Couplet::orderBy("updated_at", "desc");
  6122. $total = $query->count();
  6123. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6124. ->offset(($page - 1) * $pageSize)
  6125. ->limit($pageSize)
  6126. ->get();
  6127. break;
  6128. default:
  6129. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6130. $total = $query->count();
  6131. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6132. ->offset(($page - 1) * $pageSize)
  6133. ->limit($pageSize)
  6134. ->get();
  6135. }
  6136. return Result::success([
  6137. 'list' => $result,
  6138. 'total' => $total,
  6139. 'page' => (int)$page,
  6140. 'pageSize' => (int)$pageSize,
  6141. 'month' => $month,
  6142. 'day' => $day
  6143. ]);
  6144. }
  6145. /**
  6146. * 1:历史上的今天
  6147. * 2:节日
  6148. * 3:文章
  6149. *
  6150. * 资讯详情信息
  6151. */
  6152. public function getWebsiteTsbbDetail(array $data): array
  6153. {
  6154. $data['type'] = intval($data['type']);
  6155. switch ($data['type']) {
  6156. case 1:
  6157. $result = HistoryToday::where("id", $data['id'])->first();
  6158. break;
  6159. case 2:
  6160. $result = Festival::where("id", $data['id'])->first();
  6161. break;
  6162. case 3:
  6163. $result = Character::where("id", $data['id'])->first();
  6164. break;
  6165. case 4:
  6166. $result = Riddle::where("id", $data['id'])->first();
  6167. break;
  6168. case 5:
  6169. $result = Idiom::where("id", $data['id'])->first();
  6170. break;
  6171. case 6:
  6172. $result = Couplet::where("id", $data['id'])->first();
  6173. break;
  6174. default:
  6175. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6176. break;
  6177. }
  6178. return Result::success($result);
  6179. }
  6180. /**
  6181. * 农网导航首页数据
  6182. */
  6183. public function getWebsiteNwHomeList(array $data): array
  6184. {
  6185. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6186. ->pluck('category_id')
  6187. ->toArray();
  6188. // 使用子查询优化
  6189. $articlesList = DB::table('article')
  6190. ->select([
  6191. 'article.id',
  6192. 'article.title',
  6193. 'article.imgurl',
  6194. 'article.created_at',
  6195. 'category.name as category_name',
  6196. 'category.id as category_id',
  6197. 'website_category.aLIas_pinyin as pinyin',
  6198. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6199. DB::raw('100 as type')
  6200. ])
  6201. ->join('category', 'article.catid', '=', 'category.id')
  6202. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6203. ->leftJoin('website_category as parent_wc', function ($join) {
  6204. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6205. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6206. })
  6207. ->where('website_category.website_id', $data['website_id'])
  6208. ->where('article.status', 1)
  6209. ->whereIn('category.id', $categoryIds)
  6210. ->orderBy('article.created_at', 'desc')
  6211. ->get()
  6212. ->groupBy('category_id')
  6213. ->map(function ($group) {
  6214. // 确保第一条数据有图片
  6215. $firstWithImage = $group->first(function ($item) {
  6216. return !empty($item->imgurl);
  6217. });
  6218. if ($firstWithImage) {
  6219. // 如果有带图片的文章,将其放在第一位
  6220. $group = $group->filter(function ($item) use ($firstWithImage) {
  6221. return $item->id !== $firstWithImage->id;
  6222. })->prepend($firstWithImage);
  6223. }
  6224. return [
  6225. 'category_name' => $group->first()->category_name,
  6226. 'catid' => $group->first()->category_id,
  6227. 'pinyin' => $group->first()->pinyin,
  6228. 'parent_pinyin' => $group->first()->parent_pinyin,
  6229. 'list' => $group->take(4)->map(function ($item) {
  6230. return [
  6231. 'id' => $item->id,
  6232. 'title' => $item->title,
  6233. ];
  6234. })->values()
  6235. ];
  6236. })
  6237. ->values()
  6238. ->toArray();
  6239. return Result::success($articlesList);
  6240. }
  6241. /**
  6242. * 企业管理
  6243. * @param array $data
  6244. * @return array
  6245. */
  6246. public function getCompanyList(array $data): array
  6247. {
  6248. // return Result::success($data);
  6249. $where = [];
  6250. $user = User::where('id', $data['user_id'])->first();
  6251. if (empty($user)) {
  6252. return Result::error('用户不存在!');
  6253. }
  6254. if ($user['type_id'] != 10000) {
  6255. $where['user_id'] = $data['user_id'];
  6256. }
  6257. if (isset($data['title']) && !empty($data['title'])) {
  6258. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6259. }
  6260. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6261. array_push($where, ['website.id', $data['website_id']]);
  6262. }
  6263. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6264. if ($data['ischeck'] == 1) {
  6265. if (isset($data['status']) && $data['status'] != '') {
  6266. array_push($where, ['company.status', $data['status']]);
  6267. $query = Company::where($where);
  6268. } else {
  6269. $query = Company::whereIn('company.status', [0, 2]);
  6270. }
  6271. } else {
  6272. $query = Company::where('company.status', 1);
  6273. }
  6274. }
  6275. $result = $query->where($where)
  6276. ->leftJoin('website_category', function ($query) {
  6277. $query->on('website_category.category_id', '=', 'company.category_id')
  6278. ->on('website_category.website_id', '=', 'company.website_id');
  6279. })
  6280. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6281. ->select(
  6282. 'company.id',
  6283. 'company.title',
  6284. 'company.website_id',
  6285. 'company.category_id',
  6286. 'website.website_name',
  6287. 'website_category.alias as category_name',
  6288. 'company.status',
  6289. 'company.updated_at',
  6290. 'company.user_id'
  6291. )
  6292. ->orderBy('company.updated_at', 'desc')
  6293. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6294. if ($result->isEmpty()) {
  6295. return Result::error("暂无企业", 0);
  6296. }
  6297. return Result::success($result);
  6298. }
  6299. /**
  6300. * 添加企业
  6301. * @param array $data
  6302. * @return array
  6303. */
  6304. public function addCompany(array $data): array
  6305. {
  6306. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6307. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6308. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6309. $data['cat_arr_id'] = json_encode($car_arr_id);
  6310. } else {
  6311. $data['cat_arr_id'] = '';
  6312. }
  6313. if ($data['imgurl'] == '') {
  6314. //content中提取图片第一个图,正则提取
  6315. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6316. preg_match_all($reg, $data['content'], $matches);
  6317. if (isset($matches[1][0])) {
  6318. //截取varchar240
  6319. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6320. }
  6321. }
  6322. if ($data['keyword'] == '') {
  6323. //提取标题+内容中的关键词
  6324. $data['keyword'] = $data['title'];
  6325. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6326. Jieba::init(); // 初始化 jieba-php
  6327. Finalseg::init();
  6328. $segList = Jieba::cut($data['keyword']);
  6329. $segList1 = array_slice($segList, 0, 8);
  6330. $data['keyword'] = implode(',', $segList1);
  6331. }
  6332. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6333. //提取内容中的描述
  6334. $content = $data['content'];
  6335. // 去除 <style> 和 <script> 标签及其内容
  6336. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6337. // 去除所有 HTML 标签
  6338. $content = strip_tags($content);
  6339. // 去除 HTML 实体
  6340. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6341. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6342. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6343. // 去除多余空白
  6344. $content = preg_replace('/\s+/u', '', $content);
  6345. // 截取 100 个字符
  6346. $data['introduce'] = mb_substr($content, 0, 100);
  6347. }
  6348. $user = User::where('id', $data['user_id'])->first();
  6349. if (empty($user)) {
  6350. return Result::error('用户不存在!');
  6351. }
  6352. if ($user['type_id'] == 10000) {
  6353. $data['status'] = 1;
  6354. }
  6355. if (isset($data['level']) && $data['level'] != null) {
  6356. $data['level'] = intval($data['level']);
  6357. } else {
  6358. $data['level'] = null;
  6359. }
  6360. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6361. $this->sendMessage([
  6362. 'talk_type' => 900,
  6363. 'title' => $data['title'],
  6364. 'content' => '提交了审核',
  6365. 'messageType' => 8,
  6366. ]);
  6367. }
  6368. $result = Company::insertGetId($data);
  6369. if ($result) {
  6370. return Result::success($result);
  6371. } else {
  6372. return Result::error('添加失败');
  6373. }
  6374. }
  6375. /**
  6376. * 更新企业
  6377. * @param array $data
  6378. * @return array
  6379. */
  6380. public function upCompany(array $data): array
  6381. {
  6382. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6383. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6384. $data['cat_arr_id'] = json_encode($car_arr_id);
  6385. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6386. } else {
  6387. $data['cat_arr_id'] = '';
  6388. }
  6389. if ($data['imgurl'] == '') {
  6390. //content中提取图片第一个图,正则提取
  6391. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6392. preg_match_all($reg, $data['content'], $matches);
  6393. if (isset($matches[1][0])) {
  6394. //截取varchar
  6395. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6396. }
  6397. }
  6398. if ($data['keyword'] == '') {
  6399. //提取标题+内容中的关键词
  6400. $data['keyword'] = $data['title'];
  6401. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6402. Jieba::init(); // 初始化 jieba-php
  6403. Finalseg::init();
  6404. $segList = Jieba::cut($data['keyword']);
  6405. $segList1 = array_slice($segList, 0, 8);
  6406. $data['keyword'] = implode(',', $segList1);
  6407. }
  6408. if ($data['introduce'] == '') {
  6409. //提取内容中的描述
  6410. $content = $data['content'];
  6411. // 去除 <style> 和 <script> 标签及其内容
  6412. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6413. // 去除所有 HTML 标签
  6414. $content = strip_tags($content);
  6415. // 去除 HTML 实体
  6416. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6417. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6418. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6419. // 去除多余空白
  6420. $content = preg_replace('/\s+/u', '', $content);
  6421. // 截取 100 个字符
  6422. $data['introduce'] = mb_substr($content, 0, 100);
  6423. }
  6424. if (isset($data['level']) && $data['level'] != null) {
  6425. $data['level'] = intval($data['level']);
  6426. } else {
  6427. $data['level'] = null;
  6428. }
  6429. $user = User::where('id', $data['user_id'])->first();
  6430. if (empty($user)) {
  6431. return Result::error('用户不存在!');
  6432. }
  6433. if ($user['type_id'] == 10000) {
  6434. $data['status'] = 1;
  6435. } else {
  6436. $data['status'] = 0;
  6437. }
  6438. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6439. $this->sendMessage([
  6440. 'talk_type' => 900,
  6441. 'title' => $data['title'],
  6442. 'content' => '提交了审核',
  6443. 'messageType' => 8,
  6444. ]);
  6445. }
  6446. $result = Company::where('id', $data['id'])->update($data);
  6447. if ($result) {
  6448. return Result::success($result);
  6449. } else {
  6450. return Result::error('修改失败');
  6451. }
  6452. }
  6453. /**
  6454. * 删除企业
  6455. * @param array $data
  6456. * @return array
  6457. */
  6458. public function delCompany(array $data): array
  6459. {
  6460. $result = Company::where('id', $data['id'])->delete();
  6461. if ($result) {
  6462. return Result::success($result);
  6463. } else {
  6464. return Result::error('删除失败');
  6465. }
  6466. }
  6467. /**
  6468. * 审核企业
  6469. * @param array $data
  6470. * @return array
  6471. */
  6472. public function checkCompany(array $data): array
  6473. {
  6474. $user = User::where('id', $data['user_id'])->first();
  6475. if (empty($user)) {
  6476. return Result::error('用户不存在!');
  6477. }
  6478. $company = Company::where('id', $data['id'])->first();
  6479. if (empty($company)) {
  6480. return Result::error('企业不存在!');
  6481. }
  6482. // 状态:0:未审核 1:已审核 2:已拒绝
  6483. if ($data['status'] == 2 || $data['status'] == '2') {
  6484. $this->sendMessage([
  6485. 'talk_type' => 901,
  6486. 'title' => $company['title'],
  6487. 'content' => '审核拒绝',
  6488. 'messageType' => 8,
  6489. 'user_id' => $company['user_id'],
  6490. ]);
  6491. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6492. } else {
  6493. if ($data['status'] == 1) {
  6494. $this->sendMessage([
  6495. 'talk_type' => 901,
  6496. 'title' => $company['title'],
  6497. 'content' => '审核通过',
  6498. 'messageType' => 8,
  6499. 'user_id' => $company['user_id'],
  6500. ]);
  6501. } else if ($data['status'] == 0) {
  6502. $this->sendMessage([
  6503. 'talk_type' => 900,
  6504. 'title' => $company['title'],
  6505. 'content' => '提交了审核',
  6506. 'messageType' => 8,
  6507. ]);
  6508. }
  6509. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6510. }
  6511. if (empty($result)) {
  6512. return Result::error('审核失败!');
  6513. } else {
  6514. return Result::success($result);
  6515. }
  6516. }
  6517. /**
  6518. * 获取企业信息
  6519. * @param array $data
  6520. * @return array
  6521. */
  6522. public function getCompanyInfo(array $data): array
  6523. {
  6524. $result = Company::where('id', $data['id'])->first();
  6525. $city_arr = json_decode($result['city_arr_id']);
  6526. $result['city_name'] = District::whereIn('id', $city_arr)
  6527. ->pluck('name')
  6528. ->implode('-');
  6529. if (empty($result)) {
  6530. return Result::error('企业不存在!');
  6531. } else {
  6532. return Result::success($result);
  6533. }
  6534. }
  6535. /**
  6536. * @param array $data
  6537. * @return array
  6538. */
  6539. public function getWebsiteCompany(array $data): array
  6540. {
  6541. $categorys = json_decode($data['id'], true);
  6542. $category_arr = $this->processArticlePro($data['website_id']);
  6543. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6544. $catiall = $category_arr['catiall'];
  6545. $categoryIds = $category_arr['categoryIds'];
  6546. // return Result::success($category_arr);
  6547. foreach ($categorys as $key => $value) {
  6548. if (array_key_exists('level', $value)) {
  6549. $parts = explode(',', $value['level']);
  6550. $level = $parts[0] ?? null;
  6551. $imgnum = $parts[1] ?? null;
  6552. $textnum = $parts[2] ?? null;
  6553. if (!empty($textnum) && $textnum > 0) {
  6554. $text_num = Company::where('level', $level)
  6555. ->whereIn('category_id', $categoryIds)
  6556. ->where('status', 1)
  6557. ->select(
  6558. 'company.id',
  6559. 'company.title',
  6560. 'company.description',
  6561. 'company.updated_at',
  6562. 'company.category_id',
  6563. 'company.cat_arr_id'
  6564. )
  6565. ->orderBy('updated_at', 'desc')
  6566. ->limit($textnum)
  6567. ->get()->all();
  6568. }
  6569. if (!empty($imgnum) && $imgnum > 0) {
  6570. $img_num = Company::where('level', $level)
  6571. ->whereIn('category_id', $categoryIds)
  6572. ->where('status', 1)
  6573. ->where('imgurl', '!=', '')
  6574. ->whereNotNull('imgurl')
  6575. ->select(
  6576. 'company.id',
  6577. 'company.title',
  6578. 'company.description',
  6579. 'company.updated_at',
  6580. 'company.imgurl as imgs',
  6581. 'company.category_id',
  6582. 'company.cat_arr_id'
  6583. )
  6584. ->orderBy('updated_at', 'desc')
  6585. ->limit($imgnum)
  6586. ->get()->all();
  6587. }
  6588. }
  6589. if (array_key_exists('id', $value)) {
  6590. $parts = explode(',', $value['id']);
  6591. $category_id = $parts[0] ?? null;
  6592. $imgnum = $parts[1] ?? null;
  6593. $textnum = $parts[2] ?? null;
  6594. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6595. if (!empty($textnum) && $textnum > 0) {
  6596. $text_num = Company::whereIn('category_id', $category_arr)
  6597. // ->where('website_id', $data['website_id'])
  6598. ->where('status', 1)
  6599. ->select(
  6600. 'company.id',
  6601. 'company.title',
  6602. 'company.description',
  6603. 'company.updated_at',
  6604. 'company.category_id',
  6605. 'company.cat_arr_id'
  6606. )
  6607. ->orderBy('updated_at', 'desc')
  6608. ->limit($textnum)
  6609. ->get()->all();
  6610. }
  6611. if (!empty($imgnum) && $imgnum > 0) {
  6612. $img_num = Company::whereIn('category_id', $category_arr)
  6613. // ->where('website_id', $data['website_id'])
  6614. ->where('status', 1)
  6615. ->where('imgurl', '!=', '')
  6616. ->whereNotNull('imgurl')
  6617. ->select(
  6618. 'company.id',
  6619. 'company.title',
  6620. 'company.description',
  6621. 'company.updated_at',
  6622. 'company.imgurl as imgs',
  6623. 'company.category_id',
  6624. 'company.cat_arr_id'
  6625. )
  6626. ->orderBy('updated_at', 'desc')
  6627. ->limit($imgnum)
  6628. ->get()->all();
  6629. }
  6630. }
  6631. if (!empty($text_num)) {
  6632. foreach ($text_num as $k => $v) {
  6633. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6634. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6635. }
  6636. }
  6637. if (!empty($img_num)) {
  6638. foreach ($img_num as $k => $v) {
  6639. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6640. $imgurl = json_decode($v['imgs'], true);
  6641. if (!empty($imgurl)) {
  6642. $img_num[$k]->imgurl = $imgurl[0];
  6643. }
  6644. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6645. }
  6646. }
  6647. $company[$key]['img_num'] = $img_num ?? [];
  6648. $company[$key]['text_num'] = $text_num ?? [];
  6649. }
  6650. if (empty($company)) {
  6651. return Result::error("暂无相关企业信息", 0);
  6652. }
  6653. return Result::success($company);
  6654. }
  6655. /**
  6656. * @param array $data
  6657. * @return array
  6658. */
  6659. public function getWebsiteCompanyList(array $data): array
  6660. {
  6661. $where['website_id'] = $data['website_id'];
  6662. $where['status'] = 1;
  6663. $categoryIds = [];
  6664. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6665. $category_id = $data['category_id'];
  6666. }
  6667. $category_arr = $this->processArticlePro($data['website_id']);
  6668. $categoryIds = $category_arr['categoryIds'];
  6669. // return Result::success($cat_1st_arr);
  6670. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  6671. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  6672. })
  6673. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  6674. $query->whereIn('category_id', $categoryIds);
  6675. })
  6676. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  6677. $query->where('category_id', $category_id);
  6678. })
  6679. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6680. ->orderBy('updated_at', 'desc')
  6681. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6682. if (empty($company)) {
  6683. return Result::error("暂无相关公司信息", 0);
  6684. }
  6685. $result = [
  6686. 'count' => $company->total(),
  6687. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  6688. ];
  6689. return Result::success($result);
  6690. }
  6691. /**
  6692. * 获取项目列表
  6693. * @param array $data
  6694. * @return array
  6695. */
  6696. public function getProjectList(array $data): array
  6697. {
  6698. $where = [];
  6699. $user = User::where('id', $data['user_id'])->first();
  6700. if (empty($user)) {
  6701. return Result::error('用户不存在!');
  6702. }
  6703. if ($user->type_id != 10000) {
  6704. array_push($where, ['project.user_id', $data['user_id']]);
  6705. }
  6706. $query = Project::query();
  6707. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6708. array_push($where, ['project.website_id', $data['website_id']]);
  6709. }
  6710. if (isset($data['title']) && !empty($data['title'])) {
  6711. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6712. }
  6713. if ($data['status'] != 3) {
  6714. array_push($where, ['project.status', $data['status']]);
  6715. }
  6716. $query = Project::where($where)
  6717. ->when($data['status'] == 3, function ($query) {
  6718. $query->whereIn('project.status', [0, 2]);
  6719. });
  6720. $count = $query->clone()
  6721. ->count();
  6722. $rows = $query->clone()
  6723. ->leftJoin('website', 'project.website_id', 'website.id')
  6724. ->leftJoin('website_category', function ($join) {
  6725. $join->on('project.website_id', '=', 'website_category.website_id')
  6726. ->on('project.category_id', '=', 'website_category.category_id');
  6727. })
  6728. ->select(
  6729. 'project.id',
  6730. 'project.title',
  6731. 'project.updated_at',
  6732. 'project.status',
  6733. 'website.website_name',
  6734. 'website_category.alias as category_name',
  6735. 'project.website_id',
  6736. 'project.user_id'
  6737. )
  6738. ->orderBy('project.updated_at', 'desc')
  6739. ->offset(($data['page'] - 1) * $data['pageSize'])
  6740. ->limit($data['pageSize'])
  6741. ->get();
  6742. if ($rows->isEmpty()) {
  6743. return Result::error("暂无相关项目信息", 0);
  6744. }
  6745. $result = [
  6746. 'count' => $count,
  6747. 'rows' => $rows,
  6748. ];
  6749. return Result::success($result);
  6750. }
  6751. /**
  6752. * 添加项目
  6753. * @param array $data
  6754. * @return array
  6755. */
  6756. public function addProject(array $data): array
  6757. {
  6758. $user = User::where('id', $data['user_id'])->first();
  6759. if (empty($user)) {
  6760. return Result::error("暂无相关用户信息", 0);
  6761. }
  6762. if ($user->type_id == 10000) {
  6763. $data['status'] = 1;
  6764. } else {
  6765. $data['status'] = 0;
  6766. }
  6767. if ($data['keyword'] == '') {
  6768. //提取标题+内容中的关键词
  6769. $data['keyword'] = $data['title'];
  6770. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6771. Jieba::init(); // 初始化 jieba-php
  6772. Finalseg::init();
  6773. $segList = Jieba::cut($data['keyword']);
  6774. $segList1 = array_slice($segList, 0, 8);
  6775. $data['keyword'] = implode(',', $segList1);
  6776. }
  6777. if ($data['description'] == '') {
  6778. //提取内容中的描述
  6779. // var_dump(11111);
  6780. //提取内容中的描述
  6781. $content = $data['introduce'];
  6782. // 去除 <style> 和 <script> 标签及其内容
  6783. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6784. // 去除所有 HTML 标签
  6785. $content = strip_tags($content);
  6786. // 去除 HTML 实体
  6787. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6788. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6789. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6790. // 去除多余空白
  6791. $content = preg_replace('/\s+/u', '', $content);
  6792. // 截取 100 个字符
  6793. $data['description'] = mb_substr($content, 0, 100);
  6794. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6795. }
  6796. if ($data['status'] == 0) {
  6797. $this->sendMessage([
  6798. 'talk_type' => 1000,
  6799. 'title' => $data['title'],
  6800. 'content' => '提交了审核',
  6801. 'messageType' => 9,
  6802. ]);
  6803. }
  6804. $project = Project::insertGetId($data);
  6805. if (empty($project)) {
  6806. return Result::error("暂无相关项目信息", 0);
  6807. }
  6808. return Result::success($project);
  6809. }
  6810. /**
  6811. * 更新项目
  6812. * @param array $data
  6813. * @return array
  6814. */
  6815. public function upProject(array $data): array
  6816. {
  6817. $project = Project::where('id', $data['id'])->first();
  6818. if (empty($project)) {
  6819. return Result::error("暂无相关项目信息", 0);
  6820. }
  6821. $id = $data['id'];
  6822. unset($data['id']);
  6823. $user = User::where('id', $data['user_id'])->first();
  6824. if (empty($user)) {
  6825. return Result::error("暂无相关用户信息", 0);
  6826. }
  6827. if ($user->type_id == 10000) {
  6828. $data['status'] = 1;
  6829. } else {
  6830. $data['status'] = 0;
  6831. }
  6832. unset($data['user_id']);
  6833. if ($data['keyword'] == '') {
  6834. //提取标题+内容中的关键词
  6835. $data['keyword'] = $data['title'];
  6836. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6837. Jieba::init(); // 初始化 jieba-php
  6838. Finalseg::init();
  6839. $segList = Jieba::cut($data['keyword']);
  6840. $segList1 = array_slice($segList, 0, 8);
  6841. $data['keyword'] = implode(',', $segList1);
  6842. }
  6843. if ($data['description'] == '') {
  6844. //提取内容中的描述
  6845. // var_dump(11111);
  6846. //提取内容中的描述
  6847. $content = $data['introduce'];
  6848. // 去除 <style> 和 <script> 标签及其内容
  6849. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6850. // 去除所有 HTML 标签
  6851. $content = strip_tags($content);
  6852. // 去除 HTML 实体
  6853. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6854. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6855. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6856. // 去除多余空白
  6857. $content = preg_replace('/\s+/u', '', $content);
  6858. // 截取 100 个字符
  6859. $data['description'] = mb_substr($content, 0, 100);
  6860. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6861. }
  6862. if ($data['status'] == 0) {
  6863. $this->sendMessage([
  6864. 'talk_type' => 1000,
  6865. 'title' => $data['title'],
  6866. 'content' => '提交了审核',
  6867. 'messageType' => 9,
  6868. ]);
  6869. }
  6870. $result = Project::where('id', $id)->update($data);
  6871. if (empty($result)) {
  6872. return Result::error("更新失败", 0);
  6873. }
  6874. return Result::success($result);
  6875. }
  6876. /**
  6877. * 删除项目
  6878. * @param array $data
  6879. * @return array
  6880. */
  6881. public function delProject(array $data): array
  6882. {
  6883. $user = User::where('id', $data['user_id'])->first();
  6884. if (empty($user)) {
  6885. return Result::error("暂无相关用户信息", 0);
  6886. }
  6887. $project = Project::where('id', $data['id'])->first();
  6888. if (empty($project)) {
  6889. return Result::error("暂无相关项目信息", 0);
  6890. }
  6891. $result = Project::where('id', $data['id'])->delete();
  6892. if (empty($result)) {
  6893. return Result::error("删除失败", 0);
  6894. }
  6895. return Result::success($result);
  6896. }
  6897. /**
  6898. * 审核项目
  6899. * @param array $data
  6900. * @return array
  6901. */
  6902. public function checkProject(array $data): array
  6903. {
  6904. $user = User::where('id', $data['user_id'])->first();
  6905. if (empty($user)) {
  6906. return Result::error("暂无相关用户信息", 0);
  6907. }
  6908. // 0:未审核; 1:已审核; 2:已拒绝;
  6909. if ($user->type_id != 10000) {
  6910. if ($data['status'] == 1 || $data['status'] == 2) {
  6911. return Result::error("此用户权限不足", 0);
  6912. }
  6913. }
  6914. $project = Project::where('id', $data['id'])->first();
  6915. if (empty($project)) {
  6916. return Result::error("暂无相关项目信息", 0);
  6917. }
  6918. if ($data['status'] == 2) {
  6919. $this->sendMessage([
  6920. 'talk_type' => 1001,
  6921. 'title' => $project['title'],
  6922. 'content' => '审核拒绝',
  6923. 'messageType' => 9,
  6924. 'user_id' => $project['user_id'],
  6925. ]);
  6926. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  6927. } else {
  6928. if ($data['status'] == 1) {
  6929. $this->sendMessage([
  6930. 'talk_type' => 1001,
  6931. 'title' => $project['title'],
  6932. 'content' => '审核通过',
  6933. 'messageType' => 9,
  6934. 'user_id' => $project['user_id'],
  6935. ]);
  6936. } else if ($data['status'] == 0) {
  6937. $this->sendMessage([
  6938. 'talk_type' => 1000,
  6939. 'title' => $project['title'],
  6940. 'content' => '提交了审核',
  6941. 'messageType' => 9,
  6942. ]);
  6943. }
  6944. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  6945. }
  6946. if (empty($result)) {
  6947. return Result::error("审核失败", 0);
  6948. }
  6949. return Result::success($result);
  6950. }
  6951. /**
  6952. * 获取项目详情
  6953. * @param array $data
  6954. * @return array
  6955. */
  6956. public function getProjectInfo(array $data): array
  6957. {
  6958. $project = Project::where('id', $data['id'])->first();
  6959. if (empty($project)) {
  6960. return Result::error("暂无相关项目信息", 0);
  6961. }
  6962. return Result::success($project);
  6963. }
  6964. public function getWebsiteCompanyInfo(array $data): array
  6965. {
  6966. $company = Company::where('id', $data['id'])
  6967. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  6968. ->where('status', 1)
  6969. // ->where('website_id', $data['website_id'])
  6970. ->select('company.*', 'job_industry.hyname as hy_name')
  6971. ->first();
  6972. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  6973. switch ($company->jobnature_id) {
  6974. case null:
  6975. $company->jobnature_name = '';
  6976. break;
  6977. case 0:
  6978. $company->jobnature_name = '市场监督';
  6979. break;
  6980. case 1:
  6981. $company->jobnature_name = '信访纪检';
  6982. break;
  6983. case 2:
  6984. $company->jobnature_name = '公检法司';
  6985. break;
  6986. case 3:
  6987. $company->jobnature_name = '高关注机构';
  6988. break;
  6989. default:
  6990. $company->jobnature_name = '';
  6991. break;
  6992. }
  6993. $city_arr = $company->city_arr_id;
  6994. if (!empty($city_arr)) {
  6995. $city_arr = json_decode($city_arr, true);
  6996. $cityNames = District::whereIn('id', $city_arr)
  6997. ->pluck('name')
  6998. ->implode('-');
  6999. $company->city_name = $cityNames;
  7000. } else {
  7001. $company->city_name = '';
  7002. }
  7003. if (empty($company)) {
  7004. return Result::error("暂无相关公司信息", 0);
  7005. }
  7006. return Result::success($company);
  7007. }
  7008. public function getMSG(array $data): array
  7009. {
  7010. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7011. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7012. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7013. $result = [];
  7014. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7015. //最近的5篇已审的文章
  7016. $apply_articale = Article::where('status', 1)
  7017. ->where('admin_user_id', $user_id)
  7018. ->orderBy('updated_at', 'desc')
  7019. // ->limit(5)
  7020. ->get();
  7021. //获取5条用户的已审核商品
  7022. $good = Good::where('status', 2)
  7023. ->where('user_id', $user_id)
  7024. ->orderBy('updated_at', 'desc')
  7025. // ->limit(5)
  7026. ->get();
  7027. //获取5条用户待审核的公告
  7028. $notice = Notice::where('status', 2)
  7029. ->where('user_id', $user_id)
  7030. ->orderBy('updated_at', 'desc')
  7031. ->limit(5)->get();
  7032. //获取5条用户的待审核投诉
  7033. $complaint = Complaint::where('status', 2)
  7034. ->where('user_id', $user_id)
  7035. ->orderBy('updated_at', 'desc')
  7036. // ->limit(5)
  7037. ->get();
  7038. //获取5条用户的book
  7039. $book = Book::where('status', 2)
  7040. ->where('user_id', $user_id)
  7041. ->orderBy('updated_at', 'desc')
  7042. // ->limit(5)
  7043. ->get();
  7044. //获取5条用户的求职
  7045. //获取5条用户的求职 1
  7046. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7047. ->where('job_hunting.user_id', $user_id)
  7048. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7049. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7050. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7051. ->orderBy('updated_at', 'desc')
  7052. // ->limit(5)
  7053. ->get();
  7054. //获取5条用户的求职 2
  7055. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7056. ->where('job_recruiting.user_id', $user_id)
  7057. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7058. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7059. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7060. ->orderBy('updated_at', 'desc')
  7061. // ->limit(5)
  7062. ->get();
  7063. //人才库 1
  7064. $job_apply = JobApply::where('job_apply.status', 1)
  7065. ->where('job_apply.receiver_id', $user_id)
  7066. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7067. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7068. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7069. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7070. ->select('job_recruiting', 'job_recruiting.', '', '')
  7071. ->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')
  7072. ->orderBy('updated_at', 'desc')
  7073. // ->limit(5)
  7074. ->get();
  7075. // 职场机会 2
  7076. $job_resume = JobResume::where('job_resume.status', 1)
  7077. ->where('job_resume.receiver_id', $user_id)
  7078. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7079. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7080. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7081. ->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')
  7082. ->orderBy('updated_at', 'desc')
  7083. // ->limit(5)
  7084. ->get();
  7085. //获取5条用户待处理的投诉
  7086. $complaint_deal = Complaint::where('status', 2)
  7087. ->where('deal', 1)
  7088. ->whereJsonContains('re_user_ids', $user_id)
  7089. ->orderBy('updated_at', 'desc')
  7090. // ->limit(5)
  7091. ->get();
  7092. //获取 被通知者未读信息
  7093. $notice_unread = Notice::where('status', 2)
  7094. ->whereJsonContains('re_user_ids', $user_id)
  7095. //未读消息
  7096. ->where(function ($query) use ($user_id) {
  7097. $query->whereJsonDoesntContain('read_id', $user_id)
  7098. ->orWhereNull('read_id');
  7099. })
  7100. ->orderBy('updated_at', 'desc')
  7101. ->get();
  7102. $complaint_unread = Complaint::where('status', 2)
  7103. ->whereJsonContains('re_user_ids', $user_id)
  7104. //未读消息
  7105. ->where(function ($query) use ($user_id) {
  7106. $query->whereJsonDoesntContain('read_id', $user_id)
  7107. ->orWhereNull('read_id');
  7108. })
  7109. ->orderBy('updated_at', 'desc')
  7110. ->get();
  7111. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7112. $complany = Company::where('status', 1)
  7113. ->where('user_id', $user_id)
  7114. ->orderBy('updated_at', 'desc')
  7115. // ->limit(5)
  7116. ->get();
  7117. //获取5条单聊未读聊天消息
  7118. // $chat = ChatRecords::where('is_read', 0)
  7119. // ->where('user_id', $user_id)
  7120. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7121. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7122. // ->where('action', 'recieved')
  7123. // ->where('talk_type', 1)
  7124. // ->orderBy('created_at', 'desc')
  7125. // // ->limit(5)
  7126. // ->get();
  7127. //获取5条未读群聊信息
  7128. // $chat_group = ChatRecords::where('is_read', 0)
  7129. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7130. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7131. // ->where('user_id', $user_id)
  7132. // ->where('talk_type', 2)
  7133. // ->orderBy('created_at', 'desc')
  7134. // // ->limit(5)
  7135. // ->get();
  7136. //获取5条用户的待审核项目
  7137. $project = Project::where('status', 1)
  7138. ->where('user_id', $user_id)
  7139. ->orderBy('updated_at', 'desc')
  7140. // ->limit(5)
  7141. ->get();
  7142. // count($chat) + count($chat_group) +
  7143. $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)
  7144. + count($complany)
  7145. + count($project)
  7146. + count($notice_unread)
  7147. + count($complaint_unread)
  7148. // + count($chat) + count($chat_group)
  7149. ;
  7150. $result = [
  7151. 'apply_articale' => $apply_articale,
  7152. // 'chat' => $chat,
  7153. // 'chat_group' => $chat_group,
  7154. 'good' => $good,
  7155. 'notice' => $notice,
  7156. 'complaint' => $complaint,
  7157. 'book' => $book,
  7158. 'job_hunting' => $job_hunting,
  7159. 'job_recruiting' => $job_recruiting,
  7160. 'job_apply' => $job_apply,
  7161. 'job_resume' => $job_resume,
  7162. 'complaint_deal' => $complaint_deal,
  7163. 'complany' => $complany,
  7164. 'project' => $project,
  7165. 'notice_unread' => $notice_unread,
  7166. 'complaint_unread' => $complaint_unread,
  7167. 'count' => $count,
  7168. ];
  7169. } elseif ($type_id == 12) {
  7170. //最近的5篇已审的文章
  7171. $apply_articale = Article::where('status', 1)
  7172. ->where('admin_user_id', $user_id)
  7173. ->limit(5)->get();
  7174. //获取5条单聊未读聊天消息
  7175. $chat = ChatRecords::where('is_read', 0)
  7176. ->where('user_id', $user_id)
  7177. ->where('talk_type', 1)
  7178. ->orderBy('created_at', 'desc')
  7179. ->limit(5)->get();
  7180. //获取5条未读群聊信息
  7181. $chat_group = ChatRecords::where('is_read', 0)
  7182. ->where('user_id', $user_id)
  7183. ->where('talk_type', 2)
  7184. ->orderBy('created_at', 'desc')
  7185. ->limit(5)->get();
  7186. //获取5条用户的已审核商品
  7187. $good = Good::where('status', 2)
  7188. ->where('user_id', $user_id)
  7189. ->orderBy('updated_at', 'desc')
  7190. ->limit(5)->get();
  7191. //获取5条用户的book
  7192. $book = Book::where('status', 2)
  7193. ->where('user_id', $user_id)
  7194. ->orderBy('updated_at', 'desc')
  7195. ->limit(5)->get();
  7196. //获取5条用户的求职
  7197. //获取5条用户的求职 1
  7198. //count($chat) + count($chat_group)
  7199. $count = count($apply_articale) + count($good);
  7200. $result = [
  7201. 'apply_articale' => $apply_articale,
  7202. 'chat' => $chat,
  7203. 'chat_group' => $chat_group,
  7204. 'good' => $good,
  7205. 'book' => $book,
  7206. 'count' => $count,
  7207. ];
  7208. } elseif ($type_id == 13) {
  7209. //最近的5篇已审的文章
  7210. $apply_articale = Article::where('status', 1)
  7211. ->where('admin_user_id', $user_id)
  7212. ->limit(5)->get();
  7213. //获取5条单聊未读聊天消息
  7214. $chat = ChatRecords::where('is_read', 0)
  7215. ->where('user_id', $user_id)
  7216. ->where('talk_type', 1)
  7217. ->orderBy('created_at', 'desc')
  7218. ->limit(5)->get();
  7219. //获取5条未读群聊信息
  7220. $chat_group = ChatRecords::where('is_read', 0)
  7221. ->where('user_id', $user_id)
  7222. ->where('talk_type', 2)
  7223. ->orderBy('created_at', 'desc')
  7224. ->limit(5)->get();
  7225. //获取5条用户的已审核商品
  7226. $good = Good::where('status', 2)
  7227. ->where('user_id', $user_id)
  7228. ->orderBy('updated_at', 'desc')
  7229. ->limit(5)->get();
  7230. //count($chat) + count($chat_group) +
  7231. $count = count($apply_articale) + count($good);
  7232. $result = [
  7233. 'apply_articale' => $apply_articale,
  7234. 'chat' => $chat,
  7235. 'chat_group' => $chat_group,
  7236. 'good' => $good,
  7237. 'count' => $count,
  7238. ];
  7239. } elseif ($type_id == 14) {
  7240. //最近的5篇已审的文章
  7241. $apply_articale = Article::where('status', 1)
  7242. ->where('admin_user_id', $user_id)
  7243. // ->limit(5)
  7244. ->get();
  7245. //获取5条用户的已审核商品
  7246. $good = Good::where('status', 2)
  7247. ->where('user_id', $user_id)
  7248. ->orderBy('updated_at', 'desc')
  7249. // ->limit(5)
  7250. ->get();
  7251. $count = count($apply_articale) + count($good);
  7252. $result = [
  7253. 'apply_articale' => $apply_articale,
  7254. 'chat' => '',
  7255. 'chat_group' => '',
  7256. 'good' => $good,
  7257. 'count' => $count,
  7258. ];
  7259. } elseif ($type_id == 10000) {
  7260. //获取未审核的5篇文章
  7261. $apply_articale = Article::where('status', 0)
  7262. ->orderBy('updated_at', 'desc')
  7263. // ->limit(5)
  7264. ->get();
  7265. //获取5条单聊未读聊天消息
  7266. //获取5条单聊未读聊天消息
  7267. // $chat = ChatRecords::where('is_read', 0)
  7268. // ->where('user_id', $user_id)
  7269. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7270. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7271. // ->where('action', 'recieved')
  7272. // ->where('talk_type', 1)
  7273. // ->orderBy('created_at', 'desc')
  7274. // // ->limit(5)
  7275. // ->get();
  7276. // //获取5条未读群聊信息
  7277. // $chat_group = ChatRecords::where('is_read', 0)
  7278. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7279. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7280. // ->where('user_id', $user_id)
  7281. // ->where('talk_type', 2)
  7282. // ->orderBy('created_at', 'desc')
  7283. // // ->limit(5)
  7284. // ->get();
  7285. //获取5条用户的已审核商品
  7286. $good = Good::where('status', 1)
  7287. // ->where('user_id', $user_id)
  7288. ->orderBy('updated_at', 'desc')
  7289. // ->limit(5)
  7290. ->get();
  7291. //获取5条用户待审核的公告
  7292. $notice = Notice::where('status', 1)
  7293. ->orderBy('updated_at', 'desc')
  7294. // ->limit(5)
  7295. ->get();
  7296. //获取5条用户的待审核投诉
  7297. $complaint = Complaint::where('status', 1)
  7298. ->orderBy('updated_at', 'desc')
  7299. // ->limit(5)
  7300. ->get();
  7301. //获取5条用户的book
  7302. $book = Book::where('status', 1)
  7303. ->orderBy('updated_at', 'desc')
  7304. // ->limit(5)
  7305. ->get();
  7306. //获取5条用户的求职 1
  7307. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7308. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7309. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7310. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7311. ->orderBy('updated_at', 'desc')
  7312. // ->limit(5)
  7313. ->get();
  7314. //获取5条用户的求职 2
  7315. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7316. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7317. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7318. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7319. ->orderBy('updated_at', 'desc')
  7320. // ->limit(5)
  7321. ->get();
  7322. //人才库 1
  7323. $job_apply = JobApply::where('job_apply.status', 1)
  7324. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7325. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7326. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7327. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7328. ->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')
  7329. ->orderBy('updated_at', 'desc')
  7330. // ->limit(5)
  7331. ->get();
  7332. // 职场机会 2
  7333. $job_resume = JobResume::where('job_resume.status', 1)
  7334. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7335. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7336. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7337. ->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')
  7338. ->orderBy('updated_at', 'desc')
  7339. // ->limit(5)
  7340. ->get();
  7341. //待审核数据com pro
  7342. $complany = Company::where('status', 0)
  7343. ->orderBy('updated_at', 'desc')
  7344. // ->limit(5)
  7345. ->get();
  7346. $project = Project::where('status', 0)
  7347. ->orderBy('updated_at', 'desc')
  7348. // ->limit(5)
  7349. ->get();
  7350. $count =
  7351. // count($chat) +
  7352. // count($chat_group) +
  7353. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7354. // + count($job_apply)
  7355. // + count($job_resume)
  7356. + count($complany)
  7357. + count($project);
  7358. $result = [
  7359. 'apply_articale' => $apply_articale,
  7360. // 'chat' => $chat,
  7361. // 'chat_group' => $chat_group,
  7362. 'good' => $good,
  7363. 'notice' => $notice,
  7364. 'complaint' => $complaint,
  7365. 'book' => $book,
  7366. 'job_hunting' => $job_hunting,
  7367. 'job_recruiting' => $job_recruiting,
  7368. // 'job_apply' => $job_apply,
  7369. // 'job_resume' => $job_resume,
  7370. 'complany' => $complany,
  7371. 'project' => $project,
  7372. 'count' => $count,
  7373. ];
  7374. } elseif ($type_id == 20000) {
  7375. }
  7376. var_dump($type_id, '-----------------test---------');
  7377. return Result::success($result);
  7378. }
  7379. /**
  7380. * @param array $data
  7381. * @return array
  7382. */
  7383. public function getWebsiteProject(array $data): array
  7384. {
  7385. $categorys = json_decode($data['id'], true);
  7386. if (!empty($categorys)) {
  7387. $category_arr = $this->processArticlePro($data['website_id']);
  7388. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7389. $catiall = $category_arr['catiall'];
  7390. // return Result::success($catiall);
  7391. foreach ($categorys as $key => $val) {
  7392. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7393. $level = explode(',', $val['level'])[0];
  7394. $imgnum = explode(',', $val['level'])[1] ?? null;
  7395. $textnum = explode(',', $val['level'])[2] ?? null;
  7396. if ($level == 1) {
  7397. if (!empty($textnum) && $textnum > 0) {
  7398. $text_num = Project::where('level', $level)
  7399. ->where('website_id', $data['website_id'])
  7400. ->where('status', 1)
  7401. ->select(
  7402. 'project.id',
  7403. 'project.title',
  7404. 'project.description',
  7405. 'project.updated_at',
  7406. 'project.category_id',
  7407. 'project.cat_arr_id'
  7408. )
  7409. ->orderBy('updated_at', 'desc')
  7410. ->limit($textnum)
  7411. ->get()->all();
  7412. }
  7413. if (!empty($imgnum) && $imgnum > 0) {
  7414. $img_num = Project::where('level', $level)
  7415. ->where('website_id', $data['website_id'])
  7416. ->where('status', 1)
  7417. ->where('imgurl', '!=', '')
  7418. ->whereNotNull('imgurl')
  7419. ->select(
  7420. 'project.id',
  7421. 'project.title',
  7422. 'project.description',
  7423. 'project.updated_at',
  7424. 'project.imgurl as imgs',
  7425. 'project.category_id',
  7426. 'project.cat_arr_id'
  7427. )
  7428. ->orderBy('updated_at', 'desc')
  7429. ->limit($imgnum)
  7430. ->get()->all();
  7431. }
  7432. } else {
  7433. if (!empty($textnum) && $textnum > 0) {
  7434. $text_num = Project::where('website_id', $data['website_id'])
  7435. ->where('status', 1)
  7436. ->select(
  7437. 'project.id',
  7438. 'project.title',
  7439. 'project.description',
  7440. 'project.updated_at',
  7441. 'project.category_id',
  7442. 'project.cat_arr_id',
  7443. 'project.website_id',
  7444. 'project.updated_at',
  7445. 'project.created_at'
  7446. )
  7447. ->orderBy('updated_at', 'desc')
  7448. ->limit($textnum)
  7449. ->get()->all();
  7450. }
  7451. if (!empty($imgnum) && $imgnum > 0) {
  7452. $img_num = Project::where('website_id', $data['website_id'])
  7453. ->where('status', 1)
  7454. ->where('imgurl', '!=', '')
  7455. ->whereNotNull('imgurl')
  7456. ->select(
  7457. 'project.id',
  7458. 'project.title',
  7459. 'project.description',
  7460. 'project.updated_at',
  7461. 'project.imgurl as imgs',
  7462. 'project.category_id',
  7463. 'project.cat_arr_id'
  7464. )
  7465. ->orderBy('updated_at', 'desc')
  7466. ->limit($imgnum)
  7467. ->get()->all();
  7468. }
  7469. }
  7470. }
  7471. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7472. $category_ids = explode(',', $val['id'])[0];
  7473. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7474. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7475. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7476. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7477. $text_num = Project::whereIn('category_id', $category_arr)
  7478. ->where('website_id', $data['website_id'])
  7479. ->where('status', 1)
  7480. ->select(
  7481. 'project.id',
  7482. 'project.title',
  7483. 'project.description',
  7484. 'project.updated_at',
  7485. 'project.category_id',
  7486. 'project.cat_arr_id'
  7487. )
  7488. ->orderBy('updated_at', 'desc')
  7489. ->limit($cat_textnum)
  7490. ->get()->all();
  7491. }
  7492. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7493. $img_num = Project::whereIn('category_id', $category_arr)
  7494. ->where('website_id', $data['website_id'])
  7495. ->where('status', 1)
  7496. ->where('imgurl', '!=', '')
  7497. ->whereNotNull('imgurl')
  7498. ->select(
  7499. 'project.id',
  7500. 'project.title',
  7501. 'project.description',
  7502. 'project.updated_at',
  7503. 'project.imgurl as imgs',
  7504. 'project.category_id',
  7505. 'project.cat_arr_id'
  7506. )
  7507. ->orderBy('updated_at', 'desc')
  7508. ->limit($cat_imgnum)
  7509. ->get()->all();
  7510. }
  7511. }
  7512. if (!empty($img_num)) {
  7513. foreach ($img_num as $k => $v) {
  7514. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7515. $imgurl = json_decode($v['imgs'], true);
  7516. if (!empty($imgurl)) {
  7517. $img_num[$k]->imgurl = $imgurl[0];
  7518. }
  7519. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7520. }
  7521. }
  7522. if (!empty($text_num)) {
  7523. foreach ($text_num as $k => $v) {
  7524. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7525. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7526. }
  7527. }
  7528. $project[$key]['img_num'] = $img_num ?? [];
  7529. $project[$key]['text_num'] = $text_num ?? [];
  7530. }
  7531. }
  7532. if (empty($project)) {
  7533. return Result::error("暂无相关项目信息", 0);
  7534. }
  7535. return Result::success($project);
  7536. }
  7537. /**
  7538. * @param array $data
  7539. * @return array
  7540. */
  7541. public function getWebsiteProjectInfo(array $data): array
  7542. {
  7543. $project = Project::where('id', $data['id'])
  7544. ->where('status', 1)
  7545. ->where('website_id', $data['website_id'])
  7546. ->select('project.*')
  7547. ->first();
  7548. if (empty($project)) {
  7549. return Result::error("暂无相关项目信息", 0);
  7550. }
  7551. return Result::success($project);
  7552. }
  7553. /**
  7554. * @param array $data
  7555. * @return array
  7556. */
  7557. public function getWebsiteProjectList(array $data): array
  7558. {
  7559. $where = [];
  7560. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7561. $where['category_id'] = $data['category_id'];
  7562. }
  7563. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7564. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7565. }
  7566. $query = Project::where($where)
  7567. ->where('status', 1)
  7568. ->where('website_id', $data['website_id'])
  7569. ->select(
  7570. 'project.id',
  7571. 'project.title',
  7572. 'project.description',
  7573. 'project.imgurl as imgs',
  7574. 'project.category_id',
  7575. 'project.cat_arr_id'
  7576. )
  7577. ->orderBy('updated_at', 'desc');
  7578. $count = $query->count();
  7579. $project = $query->clone()
  7580. ->offset(($data['page'] - 1) * $data['pageSize'])
  7581. ->limit($data['pageSize'])
  7582. ->get()->all();
  7583. if (empty($project)) {
  7584. return Result::error("暂无相关项目信息", 0);
  7585. }
  7586. $categorys = $this->processArticlePro($data['website_id']);
  7587. $catiall = $categorys['catiall'];
  7588. foreach ($project as $key => $val) {
  7589. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7590. if (!empty($val['imgs'])) {
  7591. $imgurl = json_decode($val['imgs'], true);
  7592. if (!empty($imgurl)) {
  7593. $project[$key]->imgurl = $imgurl[0];
  7594. }
  7595. } else {
  7596. $project[$key]->imgurl = '';
  7597. }
  7598. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7599. }
  7600. $result = [
  7601. 'rows' => $project,
  7602. 'count' => $count,
  7603. ];
  7604. return Result::success($result);
  7605. }
  7606. /**
  7607. * @param array $data
  7608. * @return array
  7609. */
  7610. public function getWebsiteCategoryJob(array $data): array
  7611. {
  7612. $categorys = json_decode($data['id'], true);
  7613. if (!empty($categorys)) {
  7614. $category_arr = $this->processArticlePro($data['website_id']);
  7615. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7616. $catiall = $category_arr['catiall'];
  7617. foreach ($categorys as $key => $val) {
  7618. if (isset($val['id']) && !empty($val['id'])) {
  7619. $catid = explode(',', $val['id'])[0] ?? null;
  7620. $type = explode(',', $val['id'])[1] ?? null;
  7621. $textnum = explode(',', $val['id'])[2] ?? null;
  7622. }
  7623. // 4:招聘;5:求职;
  7624. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7625. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7626. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7627. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7628. ->where('job_recruiting.status', 1)
  7629. ->where('job_recruiting.website_id', $data['website_id'])
  7630. ->select(
  7631. 'job_recruiting.id',
  7632. 'job_recruiting.title',
  7633. 'job_company.business_name',
  7634. 'job_recruiting.updated_at',
  7635. 'job_recruiting.cat_arr_id'
  7636. )
  7637. ->orderBy('job_recruiting.updated_at', 'desc')
  7638. ->limit($textnum)
  7639. ->get()->all();
  7640. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7641. // 状态 审核状态,1待审核2已审核3已拒绝
  7642. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7643. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7644. ->where('job_hunting.status', 2)
  7645. ->where('job_hunting.website_id', $data['website_id'])
  7646. ->select(
  7647. 'job_hunting.id',
  7648. 'job_hunting.name',
  7649. 'job_hunting.cat_arr_id',
  7650. 'job_position.zwname as job_name',
  7651. 'job_hunting.updated_at'
  7652. )
  7653. ->orderBy('updated_at', 'desc')
  7654. ->limit($textnum)
  7655. ->get()->all();
  7656. } else {
  7657. $job = [];
  7658. }
  7659. // var_dump($catid.'222uuuuuuu'.$key);
  7660. if (!empty($job)) {
  7661. foreach ($job as $k => $value) {
  7662. if (isset($value->cat_arr_id)) {
  7663. $catArr = json_decode($value->cat_arr_id, true);
  7664. $catId = end($catArr);
  7665. } else {
  7666. continue;
  7667. }
  7668. if (isset($catiall[$catId])) {
  7669. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7670. }
  7671. }
  7672. }
  7673. // var_dump($catid.'xxxxx'.$key);
  7674. $result[$key] = $job ?? [];
  7675. }
  7676. }
  7677. if (empty($result)) {
  7678. return Result::error("暂无相关分类信息", 0);
  7679. }
  7680. return Result::success($result);
  7681. }
  7682. /**
  7683. * 发送消息
  7684. * @param array $messageData
  7685. * @return void
  7686. */
  7687. public function sendMessage($messageData)
  7688. {
  7689. $msg = [
  7690. 'talk_type' => $messageData['talk_type'],
  7691. 'title' => $messageData['title'],
  7692. 'content' => $messageData['content'],
  7693. 'messageType' => $messageData['messageType'],
  7694. 'user_id' => $messageData['user_id'] ?? '',
  7695. 'time' => microtime(),
  7696. ];
  7697. $message = new MqProducer($msg);
  7698. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7699. $producer->produce($message);
  7700. }
  7701. }