NewsService.php 282 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  65. class NewsService implements NewsServiceInterface
  66. {
  67. #[Inject]
  68. protected Redis $redis;
  69. /**
  70. * 获取导航池列表
  71. * @param array $data
  72. * @return array
  73. */
  74. public function getCategoryList(array $data): array
  75. {
  76. $search = $data['name'] ?? '';
  77. $page = (int)($data['page'] ?? 1);
  78. $perPage = (int)($data['pageSize'] ?? 10);
  79. // 1. 查出所有匹配的分类id
  80. if ($search) {
  81. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  82. if (empty($matchedIds)) {
  83. return Result::success(['rows' => [], 'total' => 0]);
  84. }
  85. // 2. 递归查所有父级,直到一级分类
  86. $idsStr = implode(',', $matchedIds);
  87. $sql = "
  88. WITH RECURSIVE parents AS (
  89. SELECT * FROM category WHERE id IN ($idsStr)
  90. UNION ALL
  91. SELECT c.* FROM category c
  92. INNER JOIN parents p ON c.id = p.pid
  93. )
  94. SELECT * FROM parents
  95. ";
  96. $parents = Db::select($sql);
  97. $parentIds = [];
  98. foreach ($parents as $row) {
  99. if ($row->pid == 0) {
  100. $parentIds[] = $row->id;
  101. }
  102. }
  103. $parentIds = array_unique($parentIds);
  104. } else {
  105. // 没有搜索,一级分类就是根
  106. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  107. }
  108. // 3. 一级分类分页
  109. $total = count($parentIds);
  110. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  111. if (empty($parentIds)) {
  112. return Result::success(['rows' => [], 'total' => $total]);
  113. }
  114. // 4. 递归查所有子孙
  115. $idsStr = implode(',', $parentIds);
  116. $sql = "
  117. WITH RECURSIVE subcategories AS (
  118. SELECT * FROM category WHERE id IN ($idsStr)
  119. UNION ALL
  120. SELECT c.* FROM category c
  121. INNER JOIN subcategories s ON c.pid = s.id
  122. )
  123. SELECT * FROM subcategories ORDER BY updated_at DESC
  124. ";
  125. $allCategories = Db::select($sql);
  126. // 5. 组装树结构
  127. $categoryMap = [];
  128. foreach ($allCategories as $cat) {
  129. $cat = (array)$cat;
  130. $cat['children'] = [];
  131. $categoryMap[$cat['id']] = $cat;
  132. }
  133. foreach ($categoryMap as $id => &$cat) {
  134. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  135. $categoryMap[$cat['pid']]['children'][] = &$cat;
  136. }
  137. }
  138. unset($cat);
  139. $categoryTree = [];
  140. foreach ($parentIds as $id) {
  141. if (isset($categoryMap[$id])) {
  142. $categoryTree[] = $categoryMap[$id];
  143. }
  144. }
  145. return Result::success([
  146. 'rows' => $categoryTree,
  147. 'total' => $total,
  148. ]);
  149. }
  150. private function findMatchedCategories($search)
  151. {
  152. if ($search) {
  153. return Category::where('name', 'like', "%{$search}%")
  154. ->orderBy('updated_at', 'desc')
  155. ->get();
  156. }
  157. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  158. ->get();
  159. }
  160. private function findAllParents($categories)
  161. {
  162. $allCategories = [];
  163. foreach ($categories as $category) {
  164. $parentId = $category->pid;
  165. while ($parentId > 0) {
  166. $parent = Category::find($parentId);
  167. if ($parent) {
  168. $allCategories[$parent->id] = $parent;
  169. $parentId = $parent->pid;
  170. } else {
  171. break;
  172. }
  173. }
  174. $allCategories[$category->id] = $category;
  175. }
  176. return array_values($allCategories);
  177. }
  178. private function buildCategoryTree($category, $allRequiredCategories)
  179. {
  180. $categoryData = $category->toArray();
  181. $children = [];
  182. foreach ($allRequiredCategories as $c) {
  183. if ($c->pid === $category->id) {
  184. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  185. }
  186. }
  187. if (!empty($children)) {
  188. $categoryData['children'] = $children;
  189. }
  190. return $categoryData;
  191. }
  192. public function myCategoryList(array $data): array
  193. {
  194. $sszq = $data['sszq'] ?? '';
  195. unset($data['sszq']);
  196. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  197. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  198. $where[] = [
  199. 'pid',
  200. '=',
  201. $data['pid'],
  202. ];
  203. if (isset($data['name'])) {
  204. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  205. }
  206. var_dump($where);
  207. //根据分类id,从category表中取出分类信息
  208. $result = Category::where($where)
  209. ->whereIn('category.id', $catorytids)
  210. ->select('category.*', 'category.id as category_id')->get();
  211. if (empty($result)) {
  212. return Result::error("没有栏目数据");
  213. }
  214. return Result::success($result);
  215. }
  216. /**
  217. * @param array $data
  218. * @return array
  219. */
  220. public function categoryList(array $data): array
  221. {
  222. $where[] = [
  223. 'pid',
  224. '=',
  225. $data['pid']
  226. ];
  227. if (isset($data['name'])) {
  228. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  229. }
  230. var_dump($where);
  231. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  232. if (empty($result)) {
  233. return Result::error("没有栏目数据");
  234. }
  235. return Result::success($result);
  236. }
  237. /**
  238. * @param array $data
  239. * @return array
  240. */
  241. public function addCategory(array $data): array
  242. {
  243. if (isset($data['id'])) {
  244. unset($data['id']);
  245. }
  246. $id = Category::insertGetId($data);
  247. if (empty($id)) {
  248. return Result::error("添加失败");
  249. }
  250. return Result::success(['id' => $id]);
  251. }
  252. /**
  253. * @param array $data
  254. * @return array
  255. */
  256. public function delCategory(array $data): array
  257. {
  258. Db::beginTransaction();
  259. try {
  260. $categoryList = Category::where(['pid' => $data['id']])->get();
  261. if ($categoryList->toArray()) {
  262. Db::rollBack();
  263. return Result::error("分类下面有子分类不能删除");
  264. }
  265. $articleList = Article::where(['catid' => $data['id']])->get();
  266. if ($articleList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有资讯不能删除");
  269. }
  270. $result = Category::where($data)->delete();
  271. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  272. if (!$result) {
  273. Db::rollBack();
  274. return Result::error("删除失败");
  275. }
  276. Db::commit();
  277. return Result::success($result);
  278. } catch (\Exception $e) {
  279. Db::rollBack();
  280. return Result::error("删除失败" . $e->getMessage());
  281. }
  282. }
  283. /**
  284. * @param array $data
  285. * @return array
  286. */
  287. public function updateCategory(array $data): array
  288. {
  289. $where = [
  290. 'id' => $data['id'],
  291. ];
  292. $result = Category::where($where)->update($data);
  293. if ($result) {
  294. return Result::success($result);
  295. } else {
  296. return Result::error("更新失败");
  297. }
  298. }
  299. /**
  300. * 获取导航池信息
  301. * @param array $data
  302. * @return array
  303. */
  304. public function getCategoryInfo(array $data): array
  305. {
  306. $where = [
  307. 'id' => $data['id'],
  308. ];
  309. $result = Category::where($where)->first();
  310. if ($result) {
  311. return Result::success($result);
  312. } else {
  313. return Result::error("更新失败");
  314. }
  315. }
  316. public function getArticleCommend(array $data): array
  317. {
  318. $where = [
  319. 'website_id' => $data['website_id'],
  320. ];
  321. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  322. var_dump($ids);
  323. if (empty($ids)) {
  324. return Result::error("没有推荐数据");
  325. }
  326. //id
  327. $whereArticle = [];
  328. if (isset($data['id'])) {
  329. $whereArticle['id'] = $data['id'];
  330. }
  331. //title like
  332. if (isset($data['title'])) {
  333. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  334. }
  335. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  336. ->where($whereArticle)
  337. ->orderBy('id', 'desc')
  338. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  339. if ($article) {
  340. $data = [
  341. 'rows' => $article->items(),
  342. 'count' => $article->total(),
  343. ];
  344. return Result::success($data);
  345. } else {
  346. return Result::error("获取失败失败");
  347. }
  348. }
  349. /**
  350. * @param array $data
  351. * @return array
  352. */
  353. public function getArticleList(array $data): array
  354. {
  355. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  356. $type_id = $data['type_id'];
  357. unset($data['type_id']);
  358. $user_id = $data['user_id'];
  359. unset($data['user_id']);
  360. $where = [];
  361. $status1 = [];
  362. if (isset($data['id']) && $data['id']) {
  363. array_push($where, ['article.id', '=', $data['id']]);
  364. }
  365. if (isset($data['title']) && $data['title']) {
  366. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  367. }
  368. if (isset($data['category_name']) && $data['category_name']) {
  369. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  370. }
  371. if (isset($data['catid']) && $data['catid']) {
  372. array_push($where, ['article.catid', '=', $data['catid']]);
  373. }
  374. if (isset($data['author']) && $data['author']) {
  375. array_push($where, ['article.author', '=', $data['author']]);
  376. }
  377. if (isset($data['islink']) && $data['islink'] !== "") {
  378. array_push($where, ['article.islink', '=', $data['islink']]);
  379. }
  380. if (isset($data['status']) && $data['status'] !== "") {
  381. array_push($where, ['article.status', '=', $data['status']]);
  382. }
  383. if (isset($data['status1'])) {
  384. $status1 = json_decode(($data['status1']));
  385. }
  386. //不是管理员展示个人数据;
  387. if ($type_id != 10000) {
  388. $where[] = ['article.admin_user_id', '=', $user_id];
  389. }
  390. $rep = Article::where($where)
  391. ->whereNotIn('article.status', [404])
  392. ->when($status1, function ($query) use ($status1) {
  393. if (isset($status1) && $status1) {
  394. $query->whereIn('article.status', $status1);
  395. }
  396. })
  397. ->leftJoin('category', 'article.catid', 'category.id')
  398. ->leftJoin('website_category', function ($join) {
  399. $join->on('article.web_site_id', '=', 'website_category.website_id')
  400. ->on('article.catid', '=', 'website_category.category_id');
  401. })
  402. ->select("article.*", "category.name as category_name", "website_category.alias")
  403. ->orderBy("article.updated_at", "desc")
  404. ->limit($data['pageSize'])
  405. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  406. $count = Article::where($where)->whereNotIn('article.status', [404])
  407. ->when($status1, function ($query) use ($status1) {
  408. if (isset($status1) && $status1) {
  409. $query->whereIn('article.status', $status1);
  410. }
  411. })
  412. ->leftJoin('category', 'article.catid', 'category.id')->count();
  413. $data = [
  414. 'rows' => $rep->toArray(),
  415. 'count' => $count,
  416. ];
  417. if (empty($rep)) {
  418. return Result::error("没有信息数据");
  419. }
  420. return Result::success($data);
  421. }
  422. /**
  423. * @param array $data
  424. * @return array
  425. */
  426. public function addArticle(array $data): array
  427. {
  428. var_dump($data, '----------12-----------1');
  429. unset($data['user_type']);
  430. unset($data['nav_add_pool_id']);
  431. // unset($data['commend_id']);
  432. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  433. Db::beginTransaction();
  434. try {
  435. //处理投票
  436. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  437. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  438. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  439. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  440. unset($data['is_survey']);
  441. unset($data['survey_name']);
  442. unset($data['suvey_array']);
  443. // unset($data['website_id']);
  444. // unset($data['web_site_id']);
  445. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  446. if ($data['hits'] == '') {
  447. $data['hits'] = 0;
  448. }
  449. if ($data['is_original'] == '') {
  450. $data['is_original'] = 0;
  451. }
  452. if ($data['status'] == '') {
  453. $data['status'] = 0;
  454. }
  455. $articleData = $data;
  456. unset($articleData['content']);
  457. //自动处理缩略图、关键字、描述
  458. if ($articleData['imgurl'] == '') {
  459. //如果没有图,设置level=0
  460. $levelArr = json_decode($articleData['level'], true);
  461. var_dump($levelArr, '----------levelArr-----------1');
  462. //content中提取图片第一个图,正则提取
  463. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  464. preg_match_all($reg, $data['content'], $matches);
  465. if (isset($matches[1][0])) {
  466. //截取varchar240
  467. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  468. //如果有图,设置level=3
  469. if (!in_array(3, $levelArr)) {
  470. $levelArr[] = 3;
  471. }
  472. $articleData['level'] = json_encode($levelArr);
  473. } else {
  474. if (!in_array(0, $levelArr)) {
  475. $levelArr[] = 0;
  476. }
  477. $articleData['level'] = json_encode($levelArr);
  478. }
  479. }
  480. var_dump($articleData['level'], '----------$articleData[level]----------1');
  481. if ($articleData['keyword'] == '') {
  482. //提取标题+内容中的关键词
  483. $articleData['keyword'] = $data['title'];
  484. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  485. Jieba::init(); // 初始化 jieba-php
  486. Finalseg::init();
  487. $segList = Jieba::cut($articleData['keyword']);
  488. $segList1 = array_slice($segList, 0, 8);
  489. $articleData['keyword'] = implode(',', $segList1);
  490. }
  491. if ($articleData['introduce'] == '') {
  492. //提取内容中的描述
  493. $content = $data['content'];
  494. // 去除 <style> 和 <script> 标签及其内容
  495. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  496. // 去除所有 HTML 标签
  497. $content = strip_tags($content);
  498. // 去除 HTML 实体
  499. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  500. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  501. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  502. // 去除多余空白
  503. $content = preg_replace('/\s+/u', '', $content);
  504. // 截取 100 个字符
  505. $articleData['introduce'] = mb_substr($content, 0, 100);
  506. }
  507. if ($articleData['status'] == 0) {
  508. $this->sendMessage([
  509. 'talk_type' => 100,
  510. 'title' => $articleData['title'],
  511. 'content' => '提交了审核',
  512. 'messageType' => 2,
  513. ]);
  514. }
  515. $id = Article::insertGetId($articleData);
  516. $articleDataContent = [
  517. 'article_id' => $id,
  518. 'content' => $data['content'],
  519. ];
  520. ArticleData::insertGetId($articleDataContent);
  521. //处理投票
  522. if ($is_survey == 1) {
  523. //生成年月日时分秒+8位随机数
  524. $uuid = date('YmdHis') . rand(10000000, 99999999);
  525. var_dump($suvey_array, 'suvey_array________');
  526. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  527. var_dump($suveys_array, '---------------------1');
  528. var_dump($suvey_array, '---------------------2');
  529. $suvey_data = [];
  530. foreach ($suveys_array as $key => $value) {
  531. if ($value == '') {
  532. continue;
  533. }
  534. if (is_array($value)) {
  535. $suvey_data[] = [
  536. 'sur_id' => $uuid,
  537. 'art_id' => $id,
  538. 'website_id' => $website_id ?? 2,
  539. 'survey_name' => $survey_name,
  540. 'choice_name' => $value[1],
  541. 'is_other' => 1,
  542. 'other_id' => 0,
  543. 'results' => 0,
  544. ];
  545. } else {
  546. $suvey_data[] = [
  547. 'sur_id' => $uuid,
  548. 'art_id' => $id,
  549. 'website_id' => $website_id ?? 2,
  550. 'survey_name' => $survey_name,
  551. 'choice_name' => $value,
  552. 'is_other' => 0,
  553. 'other_id' => 0,
  554. 'results' => 0,
  555. ];
  556. }
  557. if (empty($suvey_data)) {
  558. throw new \Exception("投票数据为空");
  559. }
  560. }
  561. $result = ArticleSurvey::insert($suvey_data);
  562. if (!$result) {
  563. throw new \Exception("投票失败,ArticleSurvey插入失败");
  564. }
  565. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  566. if (!$result) {
  567. throw new \Exception("投票失败,更新主表失败");
  568. }
  569. }
  570. Db::commit();
  571. return Result::success(['id' => $id]);
  572. } catch (\Throwable $ex) {
  573. Db::rollBack();
  574. var_dump($ex->getMessage());
  575. return Result::error("创建失败", 0);
  576. }
  577. }
  578. /**
  579. * @param array $data
  580. * @return array
  581. */
  582. public function delArticle(array $data): array
  583. {
  584. $result = Article::where($data)->delete();
  585. //survey投票删除
  586. articleSurvey::where(['art_id' => $data['id']])->delete();
  587. if (!$result) {
  588. return Result::error("删除失败");
  589. }
  590. return Result::success($result);
  591. }
  592. /**
  593. * @param array $data
  594. * @return array
  595. */
  596. public function updateArticle(array $data): array
  597. {
  598. var_dump($data, '----------12-----------1');
  599. Db::beginTransaction();
  600. unset($data['user_type']);
  601. // unset($data['web_site_id']);
  602. unset($data['nav_add_pool_id']);
  603. try {
  604. //处理投票
  605. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  606. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  607. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  608. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  609. unset($data['is_survey']);
  610. unset($data['survey_name']);
  611. unset($data['suvey_array']);
  612. unset($data['website_id']);
  613. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  614. if ($data['hits'] == '') {
  615. $data['hits'] = 0;
  616. }
  617. if ($data['is_original'] == '') {
  618. $data['is_original'] = 0;
  619. }
  620. if ($data['status'] == '') {
  621. $data['status'] = 0;
  622. }
  623. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  624. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  625. $articleData = $data;
  626. unset($articleData['content']);
  627. unset($articleData['status_name']);
  628. unset($articleData['name']);
  629. unset($articleData['content']);
  630. unset($articleData['pid_arr']);
  631. unset($articleData['pid']);
  632. //自动处理缩略图、关键字、描述
  633. if ($articleData['imgurl'] == '') {
  634. //如果没有图,设置level=0
  635. $levelArr = json_decode($articleData['level'], true);
  636. var_dump($levelArr, '----------levelArr-----------1');
  637. //content中提取图片第一个图,正则提取
  638. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  639. preg_match_all($reg, $data['content'], $matches);
  640. if (isset($matches[1][0])) {
  641. //截取varchar240
  642. // 截取到第一个<
  643. $articleData['imgurl'] = $matches[1][0];
  644. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  645. $pos = strpos($articleData['imgurl'], '"');
  646. if ($pos !== false) {
  647. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  648. }
  649. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  650. //如果有图,设置level=3
  651. if (!in_array(3, $levelArr)) {
  652. $levelArr[] = 3;
  653. }
  654. $articleData['level'] = json_encode($levelArr);
  655. } else {
  656. if (!in_array(0, $levelArr)) {
  657. $levelArr[] = 0;
  658. }
  659. $articleData['level'] = json_encode($levelArr);
  660. }
  661. }
  662. var_dump($articleData['level'], '----------$articleData[level]----------1');
  663. if ($articleData['keyword'] == '') {
  664. //提取标题+内容中的关键词
  665. $articleData['keyword'] = $data['title'];
  666. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  667. Jieba::init(); // 初始化 jieba-php
  668. Finalseg::init();
  669. $segList = Jieba::cut($articleData['keyword']);
  670. $segList1 = array_slice($segList, 0, 8);
  671. $articleData['keyword'] = implode(',', $segList1);
  672. }
  673. if ($articleData['introduce'] == '') {
  674. //提取内容中的描述
  675. $content = $data['content'];
  676. // 去除 <style> 和 <script> 标签及其内容
  677. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  678. // 去除所有 HTML 标签
  679. $content = strip_tags($content);
  680. // 去除 HTML 实体
  681. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  682. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  683. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  684. // 去除多余空白
  685. $content = preg_replace('/\s+/u', '', $content);
  686. // 截取 100 个字符
  687. $articleData['introduce'] = mb_substr($content, 0, 100);
  688. }
  689. if ($articleData['status'] == 0) {
  690. $this->sendMessage([
  691. 'talk_type' => 100,
  692. 'title' => $articleData['title'],
  693. 'content' => '提交了审核',
  694. 'messageType' => 2,
  695. ]);
  696. }
  697. $id = Article::where(['id' => $data['id']])->update($articleData);
  698. $articleDataContent = [
  699. 'content' => $data['content'],
  700. ];
  701. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  702. //处理投票
  703. $id = $data['id'];
  704. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  705. var_dump($suvey_array, 'suvey_array________delete');
  706. //处理投票
  707. if ($is_survey == 1) {
  708. //生成年月日时分秒+8位随机数
  709. $uuid = date('YmdHis') . rand(10000000, 99999999);
  710. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  711. var_dump($suveys_array, '---------------------1');
  712. $suvey_data = [];
  713. if (is_array($suveys_array)) {
  714. foreach ($suveys_array as $key => $value) {
  715. if ($value == '') {
  716. continue;
  717. }
  718. if (is_array($value)) {
  719. $suvey_data[] = [
  720. 'sur_id' => $uuid,
  721. 'art_id' => $id,
  722. 'website_id' => $website_id ?? 2,
  723. 'survey_name' => $survey_name,
  724. 'choice_name' => $value[1],
  725. 'is_other' => 1,
  726. 'other_id' => 0,
  727. 'results' => 0,
  728. ];
  729. } else {
  730. $suvey_data[] = [
  731. 'sur_id' => $uuid,
  732. 'art_id' => $id,
  733. 'website_id' => $website_id ?? 2,
  734. 'survey_name' => $survey_name,
  735. 'choice_name' => $value,
  736. 'is_other' => 0,
  737. 'other_id' => 0,
  738. 'results' => 0,
  739. ];
  740. }
  741. if (empty($suvey_data)) {
  742. throw new \Exception("投票数据为空");
  743. }
  744. }
  745. }
  746. $result = ArticleSurvey::insert($suvey_data);
  747. if (!$result) {
  748. throw new \Exception("投票失败");
  749. }
  750. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  751. if (!$result) {
  752. throw new \Exception("投票失败");
  753. }
  754. } else {
  755. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  756. }
  757. Db::commit();
  758. return Result::success([]);
  759. } catch (\Throwable $ex) {
  760. Db::rollBack();
  761. var_dump($ex->getMessage());
  762. return Result::error("更新失败" . $ex->getMessage(), 0);
  763. }
  764. }
  765. /**
  766. * 更新资讯状态
  767. * @param array $data
  768. * @return array
  769. */
  770. public function upArticleStatus(array $data): array
  771. {
  772. $articleData = Article::where(['id' => $data['id']])->first();
  773. if ($data['status'] == 1) {
  774. $this->sendMessage([
  775. 'talk_type' => 101,
  776. 'title' => $articleData['title'],
  777. 'content' => '审核通过',
  778. 'messageType' => 2,
  779. 'user_id' => $articleData['admin_user_id'],
  780. ]);
  781. }
  782. if ($data['status'] == 2) {
  783. $this->sendMessage([
  784. 'talk_type' => 101,
  785. 'title' => $articleData['title'],
  786. 'content' => '审核拒绝',
  787. 'messageType' => 2,
  788. 'user_id' => $articleData['admin_user_id'],
  789. ]);
  790. }
  791. if ($data['status'] == 0) {
  792. $this->sendMessage([
  793. 'talk_type' => 100,
  794. 'title' => $articleData['title'],
  795. 'content' => '提交了审核',
  796. 'messageType' => 2,
  797. ]);
  798. }
  799. $result = Article::where(['id' => $data['id']])->update($data);
  800. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  801. //article_ignore 表插入数据 db操作
  802. //转成数组
  803. //删掉数据重新写入
  804. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  805. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  806. $insert_data = [];
  807. foreach ($website_ids as $key => $value) {
  808. $insert_data[] = [
  809. 'article_id' => $data['id'],
  810. 'website_id' => $value,
  811. ];
  812. }
  813. DB::table('article_ignore')->insert($insert_data);
  814. }
  815. if ($result) {
  816. return Result::success();
  817. } else {
  818. return Result::error("更新状态失败", 0);
  819. }
  820. }
  821. /**
  822. * 获取新闻详情
  823. * @param array $data
  824. * @return array
  825. */
  826. public function getArticleInfo(array $data): array
  827. {
  828. $where = [
  829. 'article.id' => $data['id'],
  830. // 'article.status' => 1,
  831. ];
  832. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  833. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  834. $info = $result;
  835. // var_dump($info, 'info');
  836. $info['survey_array'] = $articleSurvey;
  837. if ($result) {
  838. return Result::success($info);
  839. } else {
  840. return Result::error("查询失败", 0);
  841. }
  842. }
  843. /**
  844. * 获取头条新闻
  845. * @param array $data
  846. * @return array
  847. */
  848. public function getWebsiteArticlett(array $data): array
  849. {
  850. $website_id = $data['website_id'];
  851. $categorys = $this->processArticlePro($website_id);
  852. $catiall = $categorys['catiall'];
  853. $categoryIds = $categorys['categoryIds'];
  854. $where = [
  855. 'status' => 1
  856. ];
  857. $website_id = $data['website_id'];
  858. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  859. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  860. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  861. switch ($data['level']) {
  862. case 1:
  863. case 2:
  864. case 3:
  865. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  866. $query = Article::where($where)
  867. ->where('level', 'like', '%' . $data['level'] . '%')
  868. ->orderBy('updated_at', 'desc');
  869. break;
  870. case 4: //最新资讯
  871. $query = Article::where($where)->orderBy('updated_at', 'desc');
  872. break;
  873. case 5: //资讯推荐
  874. $query = Article::where($where)
  875. ->where('updated_at', '>', $month);
  876. break;
  877. case 7: //资讯分类
  878. if (isset($data['id']) && !empty($data['id'])) {
  879. $keyword = Article::where('id', $data['id'])->value('keyword');
  880. $keywordArray = explode(',', $keyword);
  881. $whereL7 = [];
  882. foreach ($keywordArray as $k => $v) {
  883. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  884. }
  885. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  886. break;
  887. } else {
  888. return Result::error("请输入资讯ID", 0);
  889. break;
  890. }
  891. default:
  892. break;
  893. }
  894. // $whereL7 = [];
  895. // if(isset($data['id']) && !empty($data['id'])){
  896. // $keyword = Article::where('id', $data['id'])->value('keyword');
  897. // $keywordArray = explode(',', $keyword);
  898. // foreach ($keywordArray as $k => $v) {
  899. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  900. // }
  901. // }
  902. // $query = Article::where($where)
  903. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  904. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  905. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  906. // }
  907. // if($data['level'] == 7){
  908. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  909. // }
  910. // if($data['level'] == 4){
  911. // $query = $query->inRandomOrder()
  912. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  913. // }
  914. // if($data['level'] == 5){
  915. // $query = $query->orderBy('updated_at','desc');
  916. // }
  917. // });
  918. if ($data['textnum'] > 0) {
  919. $query = clone $query;
  920. $result['text'] = $query
  921. ->whereIn('catid', $categoryIds)
  922. ->leftJoinSub(function ($query) use ($website_id) {
  923. $query->from('article_ignore')
  924. ->where('website_id', $website_id);
  925. }, 'article_ignore', function ($join) {
  926. $join->on('article_ignore.article_id', '=', 'article.id');
  927. })
  928. ->where(function ($query) use ($website_id) {
  929. $query->whereNull('article_ignore.article_id')
  930. ->orWhere('article_ignore.website_id', '!=', $website_id);
  931. })
  932. ->select(
  933. 'article.id',
  934. 'article.title',
  935. 'article.author',
  936. 'article.updated_at',
  937. 'article.introduce',
  938. 'article.islink',
  939. 'article.linkurl',
  940. 'article.copyfrom',
  941. 'article.cat_arr_id',
  942. 'article.catid',
  943. 'article.level'
  944. )
  945. ->offset($data['placeid'])
  946. ->limit($data['textnum'])
  947. ->get()->all();
  948. foreach ($result['text'] as $k => $v) {
  949. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  950. }
  951. }
  952. if ($data['imgnum'] > 0) {
  953. $query = clone $query;
  954. $result['img'] = $query
  955. ->whereIn('catid', $categoryIds)
  956. ->where('article.imgurl', '!=', '')
  957. ->select(
  958. 'article.id',
  959. 'article.title',
  960. 'article.imgurl',
  961. 'article.author',
  962. 'article.updated_at',
  963. 'article.introduce',
  964. 'article.islink',
  965. 'article.linkurl',
  966. 'article.copyfrom',
  967. 'article.cat_arr_id',
  968. 'article.catid',
  969. 'article.level'
  970. )
  971. ->offset($data['placeid'])
  972. ->limit($data['imgnum'])
  973. ->get()->all();
  974. foreach ($result['img'] as $k => $v) {
  975. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  976. }
  977. }
  978. if (empty($result)) {
  979. return Result::error("暂无相关资讯", 0);
  980. }
  981. return Result::success($result);
  982. }
  983. /**
  984. * 获取模块新闻
  985. * @param array $data
  986. * @return array
  987. */
  988. public function getWebsiteModelArticles(array $data): array
  989. {
  990. $catid = $data['catid'];
  991. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  992. $category = $category->toArray();
  993. if (!empty($category)) {
  994. $where = [
  995. 'status' => 1,
  996. 'catid' => $catid,
  997. ];
  998. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  999. // 1:文字新闻;2:轮播图;3:图文;
  1000. // 级别:0:未分类
  1001. // 3:推荐图片
  1002. if ($data['level'] == 1) {
  1003. $data['level'] = 0;
  1004. }
  1005. $result = Article::where($where)
  1006. ->where(function ($query) use ($data) {
  1007. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1008. ->orWhereNull("level")
  1009. ->orWhereRaw("level = '[]'");
  1010. })
  1011. ->where(function ($query) use ($data) {
  1012. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1013. ->orWhereNull("ignore_ids");
  1014. })
  1015. ->orderBy("updated_at", "desc")
  1016. ->offset($placeid)
  1017. ->limit($data['pagesize'])
  1018. ->get();
  1019. if (empty($result)) {
  1020. return Result::error("此栏目暂无相关新闻", 0);
  1021. }
  1022. } else {
  1023. return Result::error("此网站暂无此栏目", 0);
  1024. }
  1025. return Result::success($result);
  1026. }
  1027. /**
  1028. *获取新闻列表
  1029. * @param array $data
  1030. * @return array
  1031. */
  1032. public function getWebsiteArticleList(array $data): array
  1033. {
  1034. // return Result::success($data);
  1035. $where[] = ['status', '=', 1];
  1036. $website_id = $data['website_id'];
  1037. if (isset($data['catid']) && !empty($data['catid'])) {
  1038. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1039. if (empty($category)) {
  1040. return Result::error("此网站暂无此栏目", 0);
  1041. }
  1042. array_push($where, ['catid', '=', $data['catid']]);
  1043. }
  1044. // return Result::success($where);
  1045. $query = Article::where($where)
  1046. ->leftJoinSub(function ($query) use ($website_id) {
  1047. $query->from('article_ignore')
  1048. ->where('website_id', $website_id);
  1049. }, 'article_ignore', function ($join) {
  1050. $join->on('article_ignore.article_id', '=', 'article.id');
  1051. })
  1052. ->where(function ($query) use ($website_id) {
  1053. $query->whereNull('article_ignore.article_id')
  1054. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1055. })
  1056. ->select(
  1057. 'article.id',
  1058. 'article.title',
  1059. 'article.imgurl',
  1060. 'article.author',
  1061. 'article.updated_at',
  1062. 'article.introduce',
  1063. 'article.islink',
  1064. 'article.linkurl',
  1065. 'article.copyfrom',
  1066. 'article.cat_arr_id',
  1067. 'article.catid'
  1068. );
  1069. $count = $query->count();
  1070. $rep = $query->orderBy("updated_at", "desc")
  1071. ->offset(($data['page'] - 1) * $data['pageSize'])
  1072. ->limit($data['pageSize'])
  1073. ->get()->all();
  1074. $categorys = $this->processArticlePro($website_id);
  1075. $cat_1st_arr = $categorys['cat_1st_arr'];
  1076. $catiall = $categorys['catiall'];
  1077. // $web['website_id'] = $data['website_id'];
  1078. foreach ($rep as $k => $v) {
  1079. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1080. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1081. }
  1082. // $rep = $this->processArticles($rep,$web);
  1083. $data = [
  1084. 'rows' => $rep,
  1085. 'count' => $count,
  1086. ];
  1087. if (empty($rep)) {
  1088. return Result::error("没有信息数据");
  1089. }
  1090. return Result::success($data);
  1091. }
  1092. /**
  1093. * 前端-获取新闻详情
  1094. * @param array $data
  1095. * @return array
  1096. */
  1097. public function selectWebsiteArticleInfo(array $data): array
  1098. {
  1099. $where = [
  1100. 'article.id' => $data['id'],
  1101. 'article.status' => 1,
  1102. ];
  1103. $result = Article::where($where)
  1104. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1105. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1106. ->where(function ($query) use ($data) {
  1107. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1108. ->orWhereNull("ignore_ids");
  1109. })
  1110. ->select(
  1111. 'article.*',
  1112. 'article_data.content',
  1113. 'article_data.article_id',
  1114. 'article_extend.website_url',
  1115. 'article_extend.email',
  1116. 'article_extend.contacts',
  1117. 'article_extend.contacts_mobile',
  1118. 'article_extend.contacts_address',
  1119. 'article_extend.zip_code',
  1120. 'article_extend.enterprise_name'
  1121. )
  1122. ->first();
  1123. if (empty($result)) {
  1124. return Result::error("暂无此新闻!", 0);
  1125. }
  1126. if (!empty($result['publiced_at'])) {
  1127. $result['updated_at'] = $result['publiced_at'];
  1128. }
  1129. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1130. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1131. ->where('website_category.website_id', $data['website_id'])
  1132. ->where(['website_category.category_id' => $result['catid']])
  1133. ->first();
  1134. if (empty($category)) {
  1135. return Result::error("查询失败", 0);
  1136. }
  1137. //手动推荐文章
  1138. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1139. if (empty($commend_ids)) {
  1140. $commendArticle = [];
  1141. } else {
  1142. //去除不存在的文章ID
  1143. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1144. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1145. ->where('article.status', 1)
  1146. ->where('website_category.website_id', $data['website_id'])
  1147. ->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')
  1148. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1149. // ->orderBy('article.updated_at', 'desc')
  1150. ->limit(5)
  1151. ->get();
  1152. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1153. foreach ($commendArticle as $k => $v) {
  1154. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1155. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1156. $cat_arr_id = array_unique($cat_arr_id);
  1157. // 从website_category取出alias_pinyin
  1158. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1159. ->whereIn('category_id', $cat_arr_id)
  1160. ->pluck('alias_pinyin', 'category_id')
  1161. ->toArray();
  1162. // 将cat_arr_id的json转成路径/隔开
  1163. $path_parts = [];
  1164. foreach ($cat_arr_id as $cat_id) {
  1165. if (isset($cat_arr[$cat_id])) {
  1166. $path_parts[] = $cat_arr[$cat_id];
  1167. }
  1168. }
  1169. $v->alias_pinyin = implode('/', $path_parts);
  1170. } else {
  1171. $v->alias_pinyin = '';
  1172. }
  1173. }
  1174. }
  1175. $result['category_id'] = $category['category_id'];
  1176. $result['cat_name'] = $category['alias'];
  1177. $result['website_name'] = $category['website_name'] ?? "";
  1178. $result['suffix'] = $category['suffix'] ?? "";
  1179. $result['commendArticle'] = $commendArticle;
  1180. $result['commend_ids'] = $commend_ids;
  1181. return Result::success($result);
  1182. }
  1183. /**
  1184. * 前端-获取网站调查问卷
  1185. * @param array $data
  1186. * @return array
  1187. */
  1188. public function getWebsiteSurvey(array $data): array
  1189. {
  1190. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1191. $website = Website::where('id', $data['website_id'])->first();
  1192. if (empty($website)) {
  1193. return Result::error("暂无此网站", 0);
  1194. }
  1195. }
  1196. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1197. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1198. if (empty($article)) {
  1199. return Result::error("暂无此文章", 0);
  1200. }
  1201. // return Result::error($data,0);
  1202. $where['art_id'] = $data['art_id'];
  1203. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1204. } else {
  1205. $survey = Article::where(function ($query) {
  1206. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1207. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1208. })
  1209. ->where('status', 1)
  1210. ->where('is_survey', 1)
  1211. ->select('survey_id')
  1212. ->orderBy('updated_at', 'desc')
  1213. ->first();
  1214. if (empty($survey)) {
  1215. return Result::error("暂无调查问卷", 0);
  1216. }
  1217. $where['sur_id'] = $survey['survey_id'];
  1218. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1219. }
  1220. // return Result::success($where);
  1221. $result = ArticleSurvey::where($where)
  1222. ->where(function ($query) {
  1223. $query->where('is_other', 0)
  1224. ->orWhere(function ($subQuery) {
  1225. $subQuery->where('is_other', 1)
  1226. ->where('other_id', 0);
  1227. });
  1228. })
  1229. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1230. ->select('article_survey.*', 'article.survey_type')
  1231. ->get()->all();
  1232. if (empty($result)) {
  1233. return Result::error("此文章暂无调查问卷", 0);
  1234. }
  1235. return Result::success($result);
  1236. }
  1237. /**
  1238. * 前端-添加网站调查问卷选项
  1239. * @param array $data
  1240. * @return array
  1241. */
  1242. public function addWebsiteSurveyOption(array $data): array
  1243. {
  1244. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1245. $website = Website::where('id', $data['website_id'])->first();
  1246. if (empty($website)) {
  1247. return Result::error("暂无此网站", 0);
  1248. }
  1249. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1250. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1251. if (empty($survey)) {
  1252. return Result::error("此调查问卷不可添加选项", 0);
  1253. }
  1254. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1255. $choice = [
  1256. 'art_id' => $survey['art_id'],
  1257. 'website_id' => $data['website_id'],
  1258. 'survey_name' => $survey['survey_name'],
  1259. 'choice_name' => $data['choice_name'],
  1260. 'sur_id' => $survey['sur_id'],
  1261. 'is_other' => 1,
  1262. 'other_id' => $survey['id'],
  1263. ];
  1264. $result = ArticleSurvey::insertGetId($choice);
  1265. if (empty($result)) {
  1266. return Result::error("添加失败", 0);
  1267. }
  1268. return Result::success($result);
  1269. }
  1270. }
  1271. return Result::error("添加失败", 0);
  1272. }
  1273. return Result::error("添加失败", 0);
  1274. }
  1275. /**
  1276. * 前端-调查问卷投票
  1277. * @param array $data
  1278. * @return array
  1279. */
  1280. public function addWebsiteSurveyVote(array $data): array
  1281. {
  1282. // return Result::success($data);
  1283. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1284. $website = Website::where('id', $data['website_id'])->first();
  1285. if (empty($website)) {
  1286. return Result::error("暂无此网站", 0);
  1287. }
  1288. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1289. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1290. // return Result::success($survey);
  1291. if (empty($is_survey)) {
  1292. return Result::error("此调查问卷不存在", 0);
  1293. }
  1294. // return Result::success($survey);
  1295. // 调查问卷类型
  1296. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1297. //多选 若是json型则转化成数组类型
  1298. if (strpos($data['choice_id'], '[') === 0) {
  1299. $data['choice_id'] = json_decode($data['choice_id'], true);
  1300. } else {
  1301. // 单选 也转换成数组
  1302. $data['choice_id'] = [$data['choice_id']];
  1303. }
  1304. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1305. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1306. // ->where('website_id',$data['website_id'])
  1307. ->where('is_other', 1)
  1308. ->where('other_id', 0)
  1309. ->first();
  1310. if (!empty($other)) {
  1311. return Result::error("请选择已有的选项!", 0);
  1312. }
  1313. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1314. // ->where('website_id',$data['website_id'])
  1315. ->where('is_other', 1)
  1316. ->where('other_id', '!=', 0)
  1317. ->first();
  1318. // return Result::success($choice['other']);
  1319. $choice_id = $data['choice_id'];
  1320. if (!empty($choice['other'])) {
  1321. // array_push($data['choice_id'],$choice['other']['other_id']);
  1322. if (!empty($choice_id)) {
  1323. $key = array_search($choice['other']['id'], $choice_id);
  1324. if ($key !== false) {
  1325. unset($choice_id[$key]);
  1326. $choice_id = array_values($choice_id);
  1327. }
  1328. array_push($choice_id, $choice['other']['other_id']);
  1329. } else {
  1330. $choice_id[0] = $choice['other']['other_id'];
  1331. }
  1332. array_push($data['choice_id'], $choice['other']['other_id']);
  1333. }
  1334. // return Result::success($data);
  1335. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1336. // ->where('website_id',$data['website_id'])
  1337. ->increment('results', 1);
  1338. if (empty($choice)) {
  1339. return Result::error("请选择已有的选项!", 0);
  1340. }
  1341. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1342. // ->where('website_id',$data['website_id'])
  1343. ->where('other_id', 0)
  1344. ->get();
  1345. $survey['choice'] = $choice_id;
  1346. return Result::success($survey);
  1347. }
  1348. return Result::error("参数必填!");
  1349. }
  1350. return Result::error("此调查问卷不存在", 0);
  1351. }
  1352. return Result::error("参数必填!");
  1353. }
  1354. /**
  1355. * 后端-获取网站调查问卷列表
  1356. * @param array $data
  1357. * @return array
  1358. */
  1359. public function getSurveyList(array $data): array
  1360. {
  1361. $where = [];
  1362. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1363. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1364. }
  1365. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1366. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1367. }
  1368. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1369. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1370. }
  1371. // return Result::success($where);
  1372. if (!empty($where)) {
  1373. $query = Article::where($where)->where(function ($q) {
  1374. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1375. });
  1376. } else {
  1377. $query = Article::where(function ($q) {
  1378. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1379. });
  1380. }
  1381. $count = $query->count();
  1382. $survey = $query->orderByDesc('id')
  1383. ->limit($data['pageSize'])
  1384. ->offset(($data['page'] - 1) * $data['pageSize'])
  1385. ->get();
  1386. if (empty($survey->toArray())) {
  1387. return Result::error("暂无调查问卷!", 0);
  1388. }
  1389. $result = [
  1390. 'rows' => $survey,
  1391. 'count' => $count,
  1392. ];
  1393. return Result::success($result);
  1394. }
  1395. /**
  1396. * 后端-获取网站调查问卷详情
  1397. * @param array $data
  1398. * @return array
  1399. */
  1400. public function getSurveyInfo(array $data): array
  1401. {
  1402. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1403. $where = ['sur_id' => $data['sur_id']];
  1404. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1405. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1406. ->select('article_survey.*', 'article.survey_type')
  1407. ->get()->all();
  1408. if (empty($choose)) {
  1409. return Result::error("此调查问卷不存在", 0);
  1410. }
  1411. $resultsArray = array_column($choose, 'results');
  1412. $total = array_sum($resultsArray);
  1413. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1414. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1415. // $total = 0;
  1416. if (!empty($other)) {
  1417. $total = $total + $other['results'];
  1418. $other['choice_name'] = '(其他)';
  1419. if (!empty($others)) {
  1420. $other['hasChildren'] = true;
  1421. // array_push($other,['hasChildren','=',true]);
  1422. $other['children'] = $others;
  1423. $other_choices = [$other->toArray()];
  1424. $mer_choice = array_merge($choose, $other_choices);
  1425. $value_choice = array_values($mer_choice);
  1426. } else {
  1427. // return Result::error('1111');
  1428. $other_choices = [$other->toArray()];
  1429. $other_choices = array_merge($choose, $other_choices);
  1430. $value_choice = array_values($other_choices);
  1431. // return Result::success($result);
  1432. }
  1433. } else {
  1434. $value_choice = $choose;
  1435. }
  1436. $result = [
  1437. 'choose' => $value_choice,
  1438. 'total' => $total,
  1439. ];
  1440. }
  1441. return Result::success($result);
  1442. }
  1443. /**
  1444. * 前端-搜索新闻列表
  1445. * @param array $data
  1446. * @return array
  1447. */
  1448. public function selectWebsiteArticle(array $data): array
  1449. {
  1450. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1451. $website_id = $data['website_id'];
  1452. $categorys = $this->processArticlePro($website_id);
  1453. $catiall = $categorys['catiall'];
  1454. $query = Article::where('status', 1)
  1455. ->whereIn('catid', $category)
  1456. ->leftJoinSub(function ($query) use ($website_id) {
  1457. $query->from('article_ignore')
  1458. ->where('website_id', $website_id);
  1459. }, 'article_ignore', function ($join) {
  1460. $join->on('article_ignore.article_id', '=', 'article.id');
  1461. })
  1462. ->where(function ($query) use ($website_id) {
  1463. $query->whereNull('article_ignore.article_id')
  1464. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1465. });
  1466. // return Result::success($all_articles);
  1467. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1468. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1469. }
  1470. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1471. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1472. }
  1473. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1474. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1475. }
  1476. // 计算总数
  1477. $count = $query->count();
  1478. // 分页查询
  1479. $articles = $query
  1480. ->select(
  1481. 'article.id',
  1482. 'article.title',
  1483. 'article.imgurl',
  1484. 'article.author',
  1485. 'article.updated_at',
  1486. 'article.introduce',
  1487. 'article.islink',
  1488. 'article.linkurl',
  1489. 'article.copyfrom',
  1490. 'article.cat_arr_id',
  1491. 'article.catid',
  1492. 'article.department_arr_id',
  1493. 'article.city_arr_id',
  1494. )
  1495. ->orderBy("updated_at", "desc")
  1496. ->offset(($data['page'] - 1) * $data['pageSize'])
  1497. ->limit($data['pageSize'])
  1498. ->get();
  1499. foreach ($articles as $k => $v) {
  1500. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1501. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1502. }
  1503. if (empty($articles)) {
  1504. return Result::error("没有符合条件的资讯数据");
  1505. }
  1506. $result = [
  1507. 'rows' => $articles,
  1508. 'count' => $count,
  1509. ];
  1510. return Result::success($result);
  1511. }
  1512. /**
  1513. * 模块新闻加强版
  1514. * @param array $data
  1515. * @return array
  1516. */
  1517. public function getWebsiteCatidArticle(array $data): array
  1518. {
  1519. $where = [
  1520. 'website_category.category_id' => $data['catid'],
  1521. 'website_category.website_id' => $data['website_id'],
  1522. ];
  1523. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1524. $child_catnum = $data['child_catnum'] ?? 1;
  1525. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1526. $childCategoryIds = array_column($category['child'], 'category_id');
  1527. if (empty($childCategoryIds)) {
  1528. return Result::error("暂无子栏目", 0);
  1529. }
  1530. $imgArticles = [];
  1531. $textArticles = [];
  1532. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1533. // 初始化子分类图片新闻和文字新闻数组
  1534. // 查询所有子级栏目的图文新闻
  1535. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1536. ->where(function ($query) use ($data) {
  1537. $query->where(function ($subQuery) use ($data) {
  1538. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1539. })->orWhereNull("ignore_ids");
  1540. })
  1541. ->where('status', 1)
  1542. ->where('imgurl', '!=', '')
  1543. ->select('*')
  1544. ->orderBy('updated_at', 'desc')
  1545. ->limit($data['child_imgnum'])
  1546. ->get();
  1547. }
  1548. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1549. // 查询所有子级栏目的文字新闻
  1550. $textArticles = Article::where('catid', $childCategoryIds[0])
  1551. ->where('status', 1)
  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. ->select('*')
  1558. ->orderBy('updated_at', 'desc')
  1559. ->limit($data['child_textnum'])
  1560. ->get();
  1561. }
  1562. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1563. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1564. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1565. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1566. return $child;
  1567. }, $category['child']);
  1568. }
  1569. // }
  1570. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1571. $category['img'] = WebsiteCategory::where($where)
  1572. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1573. ->where('article.status', 1)
  1574. ->where('article.imgurl', '!=', '')
  1575. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1576. ->orderBy('article.updated_at', 'desc')
  1577. ->limit($data['img_num'])
  1578. ->get();
  1579. }
  1580. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1581. $category['text'] = WebsiteCategory::where($where)
  1582. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1583. ->where('article.status', 1)
  1584. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1585. ->orderBy('article.updated_at', 'desc')
  1586. ->limit($data['text_num'])
  1587. ->get();
  1588. }
  1589. // $category = $category->get();
  1590. if (empty($category)) {
  1591. return Result::error("查询失败", 0);
  1592. }
  1593. return Result::success($category);
  1594. }
  1595. /**
  1596. * 模块新闻加强plus版
  1597. * @param array $data
  1598. * @return array
  1599. */
  1600. public function getWebsiteAllArticle(array $data): array
  1601. {
  1602. $time1 = microtime(true);
  1603. $wetbsite_id = $data['website_id'] ?? 2;
  1604. $data = json_decode($data['id'], true);
  1605. $categorys = $this->processArticlePro($wetbsite_id);
  1606. $cat_1st_arr = $categorys['cat_1st_arr'];
  1607. $catiall = $categorys['catiall'];
  1608. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1609. $parent_category = array_column($data, 'parent');
  1610. $parent_cat = [];
  1611. $child_category = array_column($data, 'child');
  1612. if (!empty($parent_category)) {
  1613. foreach ($parent_category as $key => $value) {
  1614. $arr = array_map('intval', explode(',', $value));
  1615. $parent_cat[$key] = $arr[0] ?? 0;
  1616. $parent_category = $arr[0] ?? 0;
  1617. $article_imgnum = $arr[1] ?? 0;
  1618. $article_textnum = $arr[2] ?? 0;
  1619. if ($parent_category != 0) {
  1620. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1621. // return Result::success($category_arr);
  1622. if ($article_imgnum != 0) {
  1623. $img_article = Article::whereIn('catid', $category_arr)
  1624. ->where('status', 1)
  1625. ->where('imgurl', '!=', '')
  1626. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1627. $query->from('article_ignore')
  1628. ->where('website_id', $wetbsite_id);
  1629. }, 'article_ignore', function ($join) {
  1630. $join->on('article_ignore.article_id', '=', 'article.id');
  1631. })
  1632. ->where(function ($query) use ($wetbsite_id) {
  1633. $query->whereNull('article_ignore.article_id')
  1634. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1635. })
  1636. ->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')
  1637. ->orderBy('updated_at', 'desc')
  1638. ->limit($article_imgnum)
  1639. ->get()->all();
  1640. foreach ($img_article as $k => $v) {
  1641. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1642. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1643. }
  1644. } else {
  1645. $img_article = [];
  1646. }
  1647. if ($article_textnum != 0) {
  1648. $text_article = Article::whereIn('catid', $category_arr)
  1649. ->where('status', 1)
  1650. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1651. $query->from('article_ignore')
  1652. ->where('website_id', $wetbsite_id);
  1653. }, 'article_ignore', function ($join) {
  1654. $join->on('article_ignore.article_id', '=', 'article.id');
  1655. })
  1656. ->where(function ($query) use ($wetbsite_id) {
  1657. $query->whereNull('article_ignore.article_id')
  1658. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1659. })
  1660. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1661. ->orderBy('updated_at', 'desc')
  1662. ->limit($article_textnum)
  1663. ->get()->all();
  1664. foreach ($text_article as $k => $v) {
  1665. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1666. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1667. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1668. }
  1669. } else {
  1670. $text_article = [];
  1671. }
  1672. $catiall[$parent_category]['imgnum'] = $img_article;
  1673. $catiall[$parent_category]['textnum'] = $text_article;
  1674. $parent[$key] = $catiall[$parent_category];
  1675. } else {
  1676. $parent[$key] = '';
  1677. }
  1678. }
  1679. }
  1680. if (!empty($child_category)) {
  1681. foreach ($child_category as $key => $value) {
  1682. $arr = array_map('intval', explode(',', $value));
  1683. $parent_category = $parent_cat[$key];
  1684. $child_category = $arr[0] ?? 0;
  1685. $article_imgnum = $arr[1] ?? 0;
  1686. $article_textnum = $arr[2] ?? 0;
  1687. if ($child_category != 0) {
  1688. $all_childcat = $cat_1st_arr[$parent_category];
  1689. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1690. // 从 $websiteInfoIndexed 中获取对应的数据
  1691. $info = $websiteInfoIndexed[$v];
  1692. // 返回一个包含所需信息的数组
  1693. return [
  1694. 'alias' => $info->alias,
  1695. 'category_id' => $info->category_id,
  1696. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1697. 'pid' => $info->pid,
  1698. 'type' => $info->type,
  1699. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1700. 'pinyin' => $info->pinyin,
  1701. ];
  1702. }, $all_childcat);
  1703. if ($article_imgnum != 0) {
  1704. $img_article = Article::where('catid', $child_category)
  1705. ->where('status', 1)
  1706. ->where('imgurl', '!=', '')
  1707. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1708. $query->from('article_ignore')
  1709. ->where('website_id', $wetbsite_id);
  1710. }, 'article_ignore', function ($join) {
  1711. $join->on('article_ignore.article_id', '=', 'article.id');
  1712. })
  1713. ->where(function ($query) use ($wetbsite_id) {
  1714. $query->whereNull('article_ignore.article_id')
  1715. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1716. })
  1717. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1718. ->orderBy('updated_at', 'desc')
  1719. ->limit($article_imgnum)
  1720. ->get()->all();
  1721. foreach ($img_article as $k => $v) {
  1722. // var_dump($v);
  1723. // var_dump($k);
  1724. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1725. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1726. }
  1727. } else {
  1728. $img_article = [];
  1729. }
  1730. if ($article_textnum != 0) {
  1731. $text_article = Article::where('catid', $child_category)
  1732. ->where('status', 1)
  1733. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1734. $query->from('article_ignore')
  1735. ->where('website_id', $wetbsite_id);
  1736. }, 'article_ignore', function ($join) {
  1737. $join->on('article_ignore.article_id', '=', 'article.id');
  1738. })
  1739. ->where(function ($query) use ($wetbsite_id) {
  1740. $query->whereNull('article_ignore.article_id')
  1741. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1742. })
  1743. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1744. ->orderBy('updated_at', 'desc')
  1745. ->limit($article_textnum)
  1746. ->get()->all();
  1747. foreach ($text_article as $k => $v) {
  1748. // var_dump($v);
  1749. // var_dump($k);
  1750. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1751. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1752. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1753. }
  1754. } else {
  1755. $text_article = [];
  1756. }
  1757. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1758. $catiall[$child_category]['imgnum'] = $img_article;
  1759. $catiall[$child_category]['textnum'] = $text_article;
  1760. $child[$key] = $catiall[$child_category];
  1761. // var_dump($pids);
  1762. } else {
  1763. $child[$key] = '';
  1764. }
  1765. }
  1766. }
  1767. foreach ($parent as $key => $value) {
  1768. $result[$key] = $value;
  1769. if (!empty($child[$key])) {
  1770. // var_dump($child[$key]);
  1771. $result[$key]['child'] = $child[$key];
  1772. // $value[$key]['child'] = $child[$key];
  1773. } else {
  1774. $result[$key]['child'] = [
  1775. "alias" => null,
  1776. "category_id" => null,
  1777. "type" => null,
  1778. "pinyin" => null,
  1779. "all_childcat" => [],
  1780. "imgnum" => [],
  1781. "textnum" => []
  1782. ];
  1783. }
  1784. }
  1785. return Result::success($result);
  1786. }
  1787. /**
  1788. * 辅助方法:获取文章列表
  1789. */
  1790. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1791. {
  1792. sleep(1);
  1793. $query = Article::where('article.status', 1)
  1794. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1795. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1796. ->where(function ($query) use ($website) {
  1797. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1798. })
  1799. ->leftJoin('website_category', function ($join) use ($website) {
  1800. $join->on('article.catid', '=', 'website_category.category_id')
  1801. ->where('website_category.website_id', '=', $website['website_id']);
  1802. })
  1803. ->select(
  1804. 'article.id',
  1805. 'article.title',
  1806. 'article.imgurl',
  1807. 'article.author',
  1808. 'article.updated_at',
  1809. 'article.introduce',
  1810. 'article.islink',
  1811. 'article.linkurl',
  1812. 'article.copyfrom',
  1813. 'article.cat_arr_id',
  1814. 'article.catid',
  1815. 'website_category.alias as category_name'
  1816. )
  1817. ->orderBy('updated_at', 'desc')
  1818. ->limit($limit);
  1819. // 如果是图片文章,添加图片URL条件
  1820. if ($isImageArticle) {
  1821. $query->where('imgurl', '!=', '');
  1822. } else {
  1823. // 文字文章不需要imgurl字段
  1824. $query->addSelect('article.introduce');
  1825. }
  1826. $articles = $query->get();
  1827. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1828. }
  1829. /**
  1830. * 乡村网-获取特殊新闻模块
  1831. * @param array $data
  1832. * @return array
  1833. */
  1834. public function getWebsiteArticles(array $data): array
  1835. {
  1836. $website_id = $data['website_id'];
  1837. $catids = json_decode($data['id'], true);
  1838. $parent_category = array_column($catids, 'parent');
  1839. if (!empty($parent_category) && is_array($parent_category)) {
  1840. $categorys = $this->processArticlePro($website_id);
  1841. $catiall = $categorys['catiall'];
  1842. $cat_1st_arr = $categorys['cat_1st_arr'];
  1843. // return Result::success($categorys);
  1844. foreach ($parent_category as $key => $value) {
  1845. $arr = array_map('intval', explode(',', $value));
  1846. $parent_category = $arr[0] ?? 0;
  1847. $article_imgnum = $arr[1] ?? 0;
  1848. $article_textnum = $arr[2] ?? 0;
  1849. if ($parent_category != 0) {
  1850. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1851. // return Result::success($category_arr);
  1852. if ($article_imgnum != 0) {
  1853. $img_article = Article::whereIn('catid', $category_arr)
  1854. ->where('status', 1)
  1855. ->where('imgurl', '!=', '')
  1856. ->leftJoinSub(function ($query) use ($website_id) {
  1857. $query->from('article_ignore')
  1858. ->where('website_id', $website_id);
  1859. }, 'article_ignore', function ($join) {
  1860. $join->on('article_ignore.article_id', '=', 'article.id');
  1861. })
  1862. ->where(function ($query) use ($website_id) {
  1863. $query->whereNull('article_ignore.article_id')
  1864. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1865. })
  1866. ->select(
  1867. 'id',
  1868. 'title',
  1869. 'imgurl',
  1870. 'author',
  1871. 'updated_at',
  1872. 'introduce',
  1873. 'islink',
  1874. 'linkurl',
  1875. 'copyfrom',
  1876. 'cat_arr_id',
  1877. 'catid as category_id'
  1878. )
  1879. ->orderBy('updated_at', 'desc')
  1880. ->limit($article_imgnum)
  1881. ->get()->all();
  1882. foreach ($img_article as $k => $v) {
  1883. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1884. // return Result::success($v);
  1885. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1886. }
  1887. } else {
  1888. $img_article = [];
  1889. }
  1890. if ($article_textnum != 0) {
  1891. $text_article = Article::whereIn('catid', $category_arr)
  1892. ->where('status', 1)
  1893. ->leftJoinSub(function ($query) use ($website_id) {
  1894. $query->from('article_ignore')
  1895. ->where('website_id', $website_id);
  1896. }, 'article_ignore', function ($join) {
  1897. $join->on('article_ignore.article_id', '=', 'article.id');
  1898. })
  1899. ->where(function ($query) use ($website_id) {
  1900. $query->whereNull('article_ignore.article_id')
  1901. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1902. })
  1903. ->select(
  1904. 'id',
  1905. 'title',
  1906. 'author',
  1907. 'updated_at',
  1908. 'introduce',
  1909. 'islink',
  1910. 'linkurl',
  1911. 'copyfrom',
  1912. 'cat_arr_id',
  1913. 'catid as category_id'
  1914. )
  1915. ->orderBy('updated_at', 'desc')
  1916. ->limit($article_textnum)
  1917. ->get()->all();
  1918. foreach ($text_article as $k => $v) {
  1919. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1920. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1921. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1922. }
  1923. } else {
  1924. $text_article = [];
  1925. }
  1926. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  1927. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  1928. $parent[$key] = $catiall[$parent_category];
  1929. } else {
  1930. $parent[$key] = [];
  1931. }
  1932. }
  1933. }
  1934. return Result::success($parent);
  1935. }
  1936. // 封装处理商品的路由问题
  1937. function processGoods($goods, $data)
  1938. {
  1939. return $goods->map(function ($good) use ($data) {
  1940. $catid = $good->catid ?? 0;
  1941. // $pinyin = '';
  1942. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1943. if (!empty($category->pid) && $category->pid != 0) {
  1944. $level = json_decode($category->category_arr_id, true);
  1945. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1946. ->whereIn('category_id', $level)
  1947. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1948. ->get(['aLIas_pinyin'])
  1949. ->pluck('aLIas_pinyin')
  1950. ->implode('/');
  1951. } else {
  1952. $pinyin = $category->aLIas_pinyin ?? '';
  1953. }
  1954. if (isset($good->city_id) && !empty($good->city_id)) {
  1955. $city = District::where('id', $good->city_id)->first(['name']);
  1956. $good->city_name = $city->name ?? '';
  1957. }
  1958. // 解析imgurl JSON并取第一条数据
  1959. $imgUrls = json_decode($good->imgurl, true);
  1960. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1961. $good->pinyin = $pinyin;
  1962. return $good;
  1963. });
  1964. }
  1965. /**
  1966. * 获取商城首页-根据栏目id
  1967. * @param array $data
  1968. * @return array
  1969. * */
  1970. function getWebsiteCatidshop(array $data): array
  1971. {
  1972. $input['catid'] = $data['catid'];
  1973. $input['website_id'] = $data['website_id'];
  1974. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1975. $result = array_map(function ($item) use ($input) {
  1976. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1977. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1978. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1979. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1980. if (empty($category) || $category->type != 2) {
  1981. return Result::error("暂无此栏目", 0);
  1982. } else {
  1983. $website['website_id'] = $input['website_id'];
  1984. $goods = Good::where('good.status', 2)
  1985. ->where('good.website_id', $website['website_id'])
  1986. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1987. ->select(
  1988. 'good.id',
  1989. 'good.name',
  1990. 'good.imgurl',
  1991. 'good.description',
  1992. 'good.updated_at',
  1993. 'good.catid',
  1994. 'good.type_id',
  1995. 'good.price',
  1996. 'good.com',
  1997. 'good.level',
  1998. 'good.unit'
  1999. )
  2000. ->orderBy('updated_at', 'desc')
  2001. ->offset($goodStart)
  2002. ->limit($goodNum);
  2003. $all_goods = $goods->get();
  2004. $all_goods = $this->processGoods($all_goods, $website);
  2005. }
  2006. return $all_goods ?? [];
  2007. }
  2008. }, $data);
  2009. return Result::success($result);
  2010. }
  2011. /**
  2012. * 获取商品模块
  2013. * @param array $data
  2014. * @return array
  2015. * */
  2016. public function getWebsiteshop(array $data): array
  2017. {
  2018. $input['id'] = $data['id'];
  2019. $input['website_id'] = $data['website_id'];
  2020. $catid = $data['catid'];
  2021. $data = json_decode($input['id'] ?? '', true) ?? [];
  2022. $result['goods'] = array_map(function ($item) use ($input) {
  2023. // 检查parent元素是否存在且不是undefined
  2024. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2025. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2026. $website = $input['website_id'];
  2027. $query = Good::where('good.status', 2)
  2028. ->where('good.website_id', $website);
  2029. switch ($Levelid) {
  2030. case 1:
  2031. case 2:
  2032. case 3:
  2033. $goods = $query->where(function ($q) use ($Levelid) {
  2034. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2035. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2036. });
  2037. break;
  2038. case 4:
  2039. $goods = $query;
  2040. break;
  2041. case 5:
  2042. $goods = $query->where('type_id', 1);
  2043. break;
  2044. case 6:
  2045. $goods = $query->where('type_id', 2);
  2046. break;
  2047. default:
  2048. return [];
  2049. }
  2050. $all_goods = $goods
  2051. ->select(
  2052. 'good.id',
  2053. 'good.name',
  2054. 'good.imgurl',
  2055. 'good.description',
  2056. 'good.updated_at',
  2057. 'good.catid',
  2058. 'good.type_id',
  2059. 'good.price',
  2060. 'good.level',
  2061. 'good.website_id'
  2062. )
  2063. ->orderBy('updated_at', 'desc')
  2064. ->offset($goodStart)
  2065. ->limit($goodNum)
  2066. ->get();
  2067. $web['website_id'] = $website;
  2068. $all_goods = $this->processGoods($all_goods, $web);
  2069. }
  2070. return $all_goods;
  2071. }, $data);
  2072. $website = $input['website_id'];
  2073. $result['article'] = Article::where(function ($query) use ($website) {
  2074. $query->where(function ($subQuery) use ($website) {
  2075. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2076. })->orWhereNull("ignore_ids");
  2077. })
  2078. ->where('catid', $catid)
  2079. ->where('article.status', 1)
  2080. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2081. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2082. ->orderBy('article.updated_at', 'desc')
  2083. ->first();
  2084. return Result::success($result);
  2085. }
  2086. /**
  2087. * 获取商品分类
  2088. * @param array $data
  2089. * @return array
  2090. * */
  2091. public function getWebsiteshopCat(array $data): array
  2092. {
  2093. $website = $data['website_id'];
  2094. $category = WebsiteCategory::where('website_id', $website)
  2095. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2096. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2097. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2098. ->orderBy('sort')
  2099. ->get();
  2100. $cat = $category->map(function ($item) use ($website) {
  2101. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2102. $pid = $item->pid ?? 0;
  2103. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2104. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2105. ->where('website_id', $website)
  2106. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2107. ->get(['aLIas_pinyin'])
  2108. ->pluck('aLIas_pinyin')
  2109. ->implode('/');
  2110. } else {
  2111. $pinyin = $item->aLIas_pinyin ?? '';
  2112. }
  2113. $item->pinyin = $pinyin;
  2114. });
  2115. if (empty($category)) {
  2116. return Result::error("栏目查询失败", 0);
  2117. }
  2118. $cat_tree = Result::buildMenuTree($category);
  2119. $web['website_id'] = $website;
  2120. $goods = Good::where('website_id', $website)
  2121. ->where('status', 2)
  2122. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2123. ->latest('updated_at')
  2124. ->offset(($data['page'] - 1) * $data['pageSize'])
  2125. ->limit($data['pageSize'])
  2126. ->get();
  2127. if (!empty($goods)) {
  2128. if ($goods->count() > 1 && !empty($goods)) {
  2129. $goods = $this->processGoods($goods, $web);
  2130. }
  2131. } else {
  2132. $goods = [];
  2133. }
  2134. $result = [
  2135. 'category' => $cat_tree,
  2136. 'goods' => $goods,
  2137. ];
  2138. // $resul['goods'] = $goods;
  2139. if (empty($result)) {
  2140. return Result::error("查询失败", 0);
  2141. }
  2142. return Result::success($result);
  2143. }
  2144. /*
  2145. * 获取商品列表
  2146. * @param array $data
  2147. * @return array
  2148. * */
  2149. public function getWebsiteshopList(array $data): array
  2150. {
  2151. // return Result::success($data);
  2152. $where = [
  2153. 'status' => 2,
  2154. 'website_id' => $data['website_id'],
  2155. ];
  2156. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2157. // return Result::error("查询失败", 0);
  2158. // }
  2159. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2160. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2161. $data['catid'] = $category->category_id ?? 0;
  2162. }
  2163. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2164. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2165. }
  2166. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2167. array_push($where, ['type_id', $data['type_id']]);
  2168. }
  2169. $query = Good::where($where)
  2170. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2171. $query->where(function ($q) use ($data) {
  2172. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2173. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2174. });
  2175. })
  2176. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2177. $query->where(function ($q) use ($data) {
  2178. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2179. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2180. });
  2181. })
  2182. ->select(
  2183. 'good.id',
  2184. 'good.name',
  2185. 'good.imgurl',
  2186. 'good.description',
  2187. 'good.updated_at',
  2188. 'good.com',
  2189. 'good.catid',
  2190. 'good.type_id',
  2191. 'good.website_id',
  2192. 'good.cat_arr_id',
  2193. 'good.created_at',
  2194. 'good.city_id'
  2195. )
  2196. ->latest('updated_at');
  2197. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2198. $result['count'] = $query->clone()->count();
  2199. $result['goods'] = $this->processGoods(
  2200. $query->clone()
  2201. ->offset(($data['page'] - 1) * $data['pageSize'])
  2202. ->limit($data['pageSize'])
  2203. ->get(),
  2204. $data
  2205. );
  2206. } else {
  2207. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2208. // 获取 type_id 为 1 的数据
  2209. $result['type1'] = $this->processGoods(
  2210. $query->clone()
  2211. ->where('type_id', 1)
  2212. ->offset(($data['page'] - 1) * $data['pageSize'])
  2213. ->limit($data['pageSize'])
  2214. ->get(),
  2215. $data
  2216. );
  2217. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2218. // 获取 type_id 为 2 的数据
  2219. $result['type2'] = $this->processGoods(
  2220. $query->clone()
  2221. ->where('type_id', 2)
  2222. ->offset(($data['page'] - 1) * $data['pageSize'])
  2223. ->limit($data['pageSize'])
  2224. ->get(),
  2225. $data
  2226. );
  2227. }
  2228. if (empty($result)) {
  2229. return Result::error("查询失败", 0);
  2230. }
  2231. return Result::success($result);
  2232. }
  2233. /**
  2234. * 获取商品详情
  2235. * @param array $data
  2236. * @return array
  2237. * */
  2238. public function getWebsiteshopInfo(array $data): array
  2239. {
  2240. $where = [
  2241. 'good.status' => 2,
  2242. 'good.website_id' => $data['website_id'],
  2243. 'good.id' => $data['id'],
  2244. ];
  2245. $goods = Good::where($where)
  2246. ->where('good.id', $data['id'])
  2247. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2248. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2249. ->first();
  2250. if (empty($goods)) {
  2251. return Result::error("查询失败", 0);
  2252. }
  2253. $goods->imgurl = json_decode($goods->imgurl, true);
  2254. return Result::success($goods);
  2255. }
  2256. /**
  2257. * plus pro 处理文章路由问题
  2258. */
  2259. function processArticlePro($website_id)
  2260. {
  2261. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2262. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2263. // 取出category_id 对应的aLIas_pinyin
  2264. $categoryIds = array_column($categorys, 'category_id');
  2265. $categoryPIds = array_column($categorys, 'pid');
  2266. $aliasPinyins = array_column($categorys, 'aLIas_pinyin');
  2267. $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2268. // return Result::success($categorys);
  2269. $catiall = [];
  2270. //一级所有子级的记录
  2271. $cat_1st_arr = [];
  2272. foreach ($categorys as $key => $value) {
  2273. $category_arr_id = json_decode($value->category_arr_id);
  2274. $pinyin_str = '';
  2275. // 算出一级 并且算出子级
  2276. if ($value->pid != 0) {
  2277. $cat_1st_arr[$value->pid][] = $value->category_id;
  2278. }
  2279. foreach ($category_arr_id as $k => $v) {
  2280. $pinyin_str .= $cat_arr[$v] . '/';
  2281. }
  2282. $pinyin_str = rtrim($pinyin_str, '/');
  2283. $catiall[$value->category_id]['alias'] = $value->alias;
  2284. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2285. $catiall[$value->category_id]['type'] = $value->type;
  2286. $catiall[$value->category_id]['pinyin'] = $pinyin_str;
  2287. $websiteInfoIndexed[$value->category_id]->pinyin = $pinyin_str;
  2288. }
  2289. return [
  2290. 'cat_1st_arr' => $cat_1st_arr,
  2291. 'catiall' => $catiall,
  2292. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2293. 'categoryIds' => $categoryIds,
  2294. ];
  2295. }
  2296. /**
  2297. * 封装处理文章的路由问题
  2298. * */
  2299. function processArticles($articles, $data)
  2300. {
  2301. // 检查 $articles 是否为数组或可迭代对象
  2302. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2303. return $articles->map(function ($article) use ($data) {
  2304. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2305. $catid = $article->cat_arr_id ?? '';
  2306. }
  2307. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2308. $catid = $article->category_arr_id ?? '';
  2309. }
  2310. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2311. $level = json_decode($catid, true);
  2312. if (!is_array($level)) {
  2313. return $article;
  2314. } else {
  2315. $level = array_map('intval', $level);
  2316. }
  2317. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2318. ->where($data)
  2319. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2320. ->pluck('aLIas_pinyin')
  2321. ->implode('/');
  2322. $article->pinyin = $pinyin ?? '';
  2323. return $article;
  2324. });
  2325. } else {
  2326. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2327. $catid = $articles->cat_arr_id ?? '';
  2328. $level = json_decode($catid, true);
  2329. if (!is_array($level)) {
  2330. return $articles;
  2331. } else {
  2332. $level = array_map('intval', $level);
  2333. }
  2334. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2335. ->where($data)
  2336. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2337. ->pluck('aLIas_pinyin')
  2338. ->implode('/');
  2339. $articles->pinyin = $pinyin ?? '';
  2340. return $articles;
  2341. }
  2342. }
  2343. // 封装处理由问题
  2344. function processJob($job, $data)
  2345. {
  2346. return $job->map(function ($job) use ($data) {
  2347. $category = $job->cat_arr_id ?? '';
  2348. $cityid = $job->city_arr_id ?? '';
  2349. $city = json_decode($cityid, true);
  2350. $pinyin = '';
  2351. $level = json_decode($category, true);
  2352. // 路由
  2353. if (!empty($level) && is_array($level)) {
  2354. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2355. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2356. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2357. ->get(['aLIas_pinyin'])
  2358. ->pluck('aLIas_pinyin')
  2359. ->implode('/');
  2360. if (empty($pinyin)) {
  2361. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2362. }
  2363. $job->pinyin = $pinyin;
  2364. }
  2365. // 取职位-城市 市??省
  2366. if (!empty($city) && is_array($city)) {
  2367. if (isset($city[1]) && !empty($city[1])) {
  2368. $city = District::where('id', $city[1])->first(['name']);
  2369. $job->city_name = $city->name ?? '';
  2370. } else if (isset($city[0]) && !empty($city[0])) {
  2371. $city = District::where('id', $city[0])->first(['name']);
  2372. $job->city_name = $city->name ?? '';
  2373. } else {
  2374. $job->city_name = '全国';
  2375. }
  2376. }
  2377. // 获取简历最后一级地区
  2378. if (isset($job->city_id) && !empty($job->city_id)) {
  2379. $city = District::where('id', $job->city_id)->first(['name']);
  2380. $job->hunt_cityname = $city->name ?? '';
  2381. }
  2382. // 组合详细地址
  2383. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2384. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2385. if (is_array($address_id) && !empty($address_id)) {
  2386. $address = District::whereIn('id', $address_id)
  2387. ->orderBy('level', 'asc')
  2388. ->get(['name'])
  2389. ->pluck('name')
  2390. ->implode('');
  2391. // $job->address_name = $address ?? '';
  2392. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2393. }
  2394. }
  2395. // 取行业
  2396. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2397. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2398. if (!empty($job->industry)) {
  2399. $query->where('hyid', $job->industry);
  2400. } else if (!empty($job->hy_id)) {
  2401. $query->where('hyid', $job->hy_id);
  2402. } else if (!empty($job->company_hy_id)) {
  2403. $query->where('hyid', $job->company_hy_id);
  2404. } else {
  2405. $query->where('hyid', $job->job_industry);
  2406. }
  2407. })->first(['hyname']);
  2408. $job->hy_name = $hy_name->hyname ?? '';
  2409. }
  2410. // 取职位类别
  2411. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2412. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2413. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2414. $job->zw_name = $zw_name->zwname ?? '';
  2415. }
  2416. // 取具体职位
  2417. 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))) {
  2418. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2419. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2420. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2421. }
  2422. // 取工作经验
  2423. if (isset($job->experience) && !empty($job->experience)) {
  2424. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2425. $job->experience_name = $experience->ename ?? '';
  2426. }
  2427. // 取学历
  2428. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2429. $education = $job->educational ?? $job->school_education;
  2430. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2431. $job->education_name = $education->ename ?? '';
  2432. }
  2433. // 语言
  2434. if (isset($job->language) && !empty($job->language)) {
  2435. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2436. $job->language_name = $language->ename ?? '';
  2437. }
  2438. // 薪资
  2439. if (isset($job->salary) && !empty($job->salary)) {
  2440. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2441. $job->salary_name = $salary->ename ?? '';
  2442. }
  2443. // 职位性质
  2444. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2445. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2446. $job->job_nature_name = $job_nature->ename ?? '';
  2447. }
  2448. // 公司规模
  2449. if (isset($job->company_size) && !empty($job->company_size)) {
  2450. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2451. $job->company_size_name = $company_size->ename ?? '';
  2452. }
  2453. // 公司性质
  2454. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2455. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2456. $job->company_nature_name = $company_nature->nature_name ?? '';
  2457. }
  2458. // $job->pinyin = $pinyin;
  2459. return $job;
  2460. });
  2461. }
  2462. /**
  2463. * 获取书籍模块
  2464. * @param array $data
  2465. * @return array
  2466. * */
  2467. public function getWebsiteBook(array $data): array
  2468. {
  2469. $input['id'] = $data['id'];
  2470. $input['website_id'] = $data['website_id'];
  2471. // 将 JSON 字符串转换为 PHP 数组
  2472. $data = json_decode($input['id'], true);
  2473. // 使用 array_map 处理每个元素
  2474. $result = array_map(function ($item) use ($input) {
  2475. // 检查parent元素是否存在且不是undefined
  2476. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2477. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2478. $website = [
  2479. 'website_id' => $input['website_id'],
  2480. ];
  2481. // 查询栏目名称
  2482. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2483. if (empty($category)) {
  2484. $parent_alias = '';
  2485. $parent_pinyin = null;
  2486. $imgBooks = [];
  2487. $textBooks = [];
  2488. } else {
  2489. $parent_alias = $category->alias ?? '';
  2490. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2491. // 查找子分类ID数组
  2492. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2493. array_push($childCategoryIds, $parentCatId);
  2494. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2495. if ($parentImgNum != 0) {
  2496. // 查询图片新闻
  2497. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2498. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2499. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2500. })
  2501. ->where('book.status', 2)
  2502. ->where('book.img_url', '!=', '')
  2503. ->leftJoin('website_category', function ($join) use ($website) {
  2504. $join->on('book.cat_id', '=', 'website_category.category_id')
  2505. ->where('website_category.website_id', '=', $website['website_id']);
  2506. })
  2507. ->select(
  2508. 'book.id',
  2509. 'book.title',
  2510. 'book.img_url',
  2511. 'book.price',
  2512. 'book.market_price',
  2513. 'book.description',
  2514. 'book.cat_id',
  2515. 'book.description',
  2516. 'book.updated_at',
  2517. 'website_category.alias as category_name',
  2518. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2519. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2520. )
  2521. ->orderBy('updated_at', 'desc')
  2522. ->limit($parentImgNum)
  2523. ->get()->all();
  2524. // 查询文字新闻
  2525. }
  2526. if ($parentTextNum != 0) {
  2527. $textBooks = [];
  2528. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2529. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2530. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2531. })
  2532. ->where('book.status', 2)
  2533. ->leftJoin('website_category', function ($join) use ($website) {
  2534. $join->on('book.cat_id', '=', 'website_category.category_id')
  2535. ->where('website_category.website_id', '=', $website['website_id']);
  2536. })
  2537. ->select(
  2538. 'book.id',
  2539. 'book.title',
  2540. 'book.img_url',
  2541. 'book.price',
  2542. 'book.market_price',
  2543. 'book.description',
  2544. 'book.cat_id',
  2545. 'book.description',
  2546. 'book.updated_at',
  2547. 'website_category.alias as category_name',
  2548. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2549. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2550. )
  2551. ->orderBy('updated_at', 'desc')
  2552. ->limit($parentTextNum)
  2553. ->get()->all();
  2554. }
  2555. }
  2556. }
  2557. $resultItem = [
  2558. 'alias' => $parent_alias ?? '',
  2559. 'category_id' => $parentCatId ?? 0,
  2560. 'pinyin' => $parent_pinyin ?? null,
  2561. 'imgnum' => $imgBooks ?? [],
  2562. 'textnum' => $textBooks ?? [],
  2563. ];
  2564. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2565. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2566. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2567. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2568. ->get()->all();
  2569. if (!empty($childCategory)) {
  2570. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2571. // 查询子栏目名称
  2572. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2573. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2574. ->first();
  2575. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2576. $childImgArticles = [];
  2577. $childTextArticles = [];
  2578. $resultItem['child'] = [];
  2579. } else {
  2580. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2581. // 查询子栏目图片新闻
  2582. $childImgArticles = Book::where('cat_id', $childCatId)
  2583. ->where('status', 2)
  2584. ->where('img_url', '!=', '')
  2585. ->leftJoin('website_category', function ($join) use ($website) {
  2586. $join->on('book.cat_id', '=', 'website_category.category_id')
  2587. ->where('website_category.website_id', '=', $website['website_id']);
  2588. })
  2589. ->select(
  2590. 'book.id',
  2591. 'book.title',
  2592. 'book.img_url',
  2593. 'book.price',
  2594. 'book.market_price',
  2595. 'book.description',
  2596. 'book.cat_id',
  2597. 'book.description',
  2598. 'book.updated_at',
  2599. DB::raw("'$child_pinyin' as pinyin")
  2600. )
  2601. ->orderBy('updated_at', 'desc')
  2602. ->limit($childImgNum)
  2603. ->get()->all();
  2604. // 查询子栏目文字新闻
  2605. $childTextArticles = Book::where('cat_id', $childCatId)
  2606. ->where('status', 2)
  2607. ->leftJoin('website_category', function ($join) use ($website) {
  2608. $join->on('book.cat_id', '=', 'website_category.category_id')
  2609. ->where('website_category.website_id', '=', $website['website_id']);
  2610. })
  2611. ->select(
  2612. 'book.id',
  2613. 'book.title',
  2614. 'book.img_url',
  2615. 'book.price',
  2616. 'book.market_price',
  2617. 'book.description',
  2618. 'book.cat_id',
  2619. 'book.description',
  2620. 'book.updated_at',
  2621. DB::raw("'$child_pinyin' as pinyin")
  2622. )
  2623. ->orderBy('updated_at', 'desc')
  2624. ->limit($childTextNum)
  2625. ->get()->all();
  2626. $resultItem['child'] = [
  2627. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2628. 'category_id' => $childCatId,
  2629. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2630. 'all_childcat' => $childCategory,
  2631. 'imgnum' => $childImgArticles,
  2632. 'textnum' => $childTextArticles,
  2633. ];
  2634. }
  2635. }
  2636. } else {
  2637. $resultItem['child'] = [];
  2638. }
  2639. return $resultItem;
  2640. }, $data);
  2641. return Result::success($result);
  2642. }
  2643. /**
  2644. * 获取书刊列表
  2645. * @param array $data
  2646. * @return array
  2647. * */
  2648. public function getWebsiteBookList(array $data): array
  2649. {
  2650. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2651. if (empty($web)) {
  2652. return Result::error("查询失败", 0);
  2653. }
  2654. $catid = $data['id'];
  2655. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2656. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2657. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2658. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2659. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2660. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2661. ->where('pid', $category['pid'])
  2662. ->select(
  2663. 'category_id',
  2664. 'alias',
  2665. 'aLIas_pinyin',
  2666. 'pid',
  2667. 'sort',
  2668. 'is_url',
  2669. 'web_url',
  2670. 'seo_title',
  2671. 'seo_keywords',
  2672. 'seo_description',
  2673. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2674. )
  2675. ->orderBy('sort')
  2676. ->get()->all();
  2677. if (empty($category)) {
  2678. return Result::error("查询失败", 0);
  2679. }
  2680. $query = Book::where('book.status', 2)
  2681. ->where('book.website_id', $data['website_id'])
  2682. ->where('book.cat_id', $catid)
  2683. ->select(
  2684. 'book.id',
  2685. 'book.title',
  2686. 'book.img_url',
  2687. 'book.description',
  2688. 'book.updated_at',
  2689. 'book.cat_id',
  2690. DB::raw("'$pinyin' as pinyin")
  2691. )
  2692. ->orderBy('book.updated_at', 'desc');
  2693. $count = $query->count();
  2694. $query = clone $query;
  2695. $Book = $query
  2696. ->limit($data['pageSize'])
  2697. ->offset(($data['page'] - 1) * $data['pageSize'])
  2698. ->get()->all();
  2699. $result = [
  2700. 'category' => $categorys,
  2701. 'books' => $Book,
  2702. 'count' => $count,
  2703. ];
  2704. // if(empty($result)){
  2705. // return Result::error("查询失败", 0);
  2706. // }
  2707. return Result::success($result);
  2708. }
  2709. /**
  2710. * 获取书刊详情
  2711. * @param array $data
  2712. * @return array
  2713. * */
  2714. public function getWebsiteBookInfo(array $data): array
  2715. {
  2716. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2717. if (empty($web)) {
  2718. return Result::error("查询失败", 0);
  2719. }
  2720. $book = Book::where('status', 2)
  2721. ->where('website_id', $data['website_id'])
  2722. ->where('id', $data['id'])
  2723. ->select(
  2724. 'book.*',
  2725. )
  2726. ->orderBy('updated_at', 'desc')
  2727. ->first();
  2728. if (empty($book)) {
  2729. return Result::error("查询失败", 0);
  2730. }
  2731. // 先查询当前分类的 pid
  2732. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2733. ->where('category_id', $book['cat_id'])
  2734. ->first(['pid', 'category_id']);
  2735. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2736. if (!empty($carpid)) {
  2737. if ($carpid->pid != 0) {
  2738. $pid = $carpid['pid'];
  2739. // $parent_pinyin = '';
  2740. } else {
  2741. $pid = $carpid['category_id'];
  2742. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2743. }
  2744. }
  2745. $categorys = $query->where('pid', $pid)
  2746. ->select(
  2747. 'category_id',
  2748. 'alias',
  2749. 'aLIas_pinyin',
  2750. 'pid',
  2751. 'sort',
  2752. 'is_url',
  2753. 'web_url',
  2754. 'category_arr_id as cat_arr_id',
  2755. )
  2756. ->orderBy('sort')
  2757. ->get();
  2758. $category = $this->processArticle($categorys, $data);
  2759. $result = [
  2760. 'category' => $category,
  2761. 'books' => $book,
  2762. ];
  2763. return Result::success($result);
  2764. }
  2765. /**
  2766. * 尝试
  2767. * @param array $data
  2768. * @return array
  2769. * */
  2770. public function test(array $data): array
  2771. {
  2772. $input['id'] = $data['id'];
  2773. $input['website_id'] = $data['website_id'];
  2774. // 将 JSON 字符串转换为 PHP 数组
  2775. $data = json_decode($input['id'], true);
  2776. $result = [];
  2777. $article = $data;
  2778. $result = array_map(function ($item) use ($input) {
  2779. $website = [
  2780. 'website_id' => $input['website_id'],
  2781. ];
  2782. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2783. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2784. $parent = [
  2785. 0 => $category['category_id'] ?? [],
  2786. 1 => $parentImgNum ?? [],
  2787. 2 => $parentTextNum ?? [],
  2788. ];
  2789. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2790. $child = [];
  2791. $resultItem = [
  2792. // 'alias' => $parent_alias ?? '',
  2793. 'category_id' => $parentCatId ?? 0,
  2794. 'pinyin' => $parentImgNum ?? null,
  2795. 'imgnum' => $parentTextNum ?? [],
  2796. // 'textnum' => $textArticles ?? [],
  2797. ];
  2798. return $parent;
  2799. }, $data);
  2800. return Result::success($result);
  2801. // });
  2802. }
  2803. /**
  2804. * 封装处理文章的路由问题
  2805. * */
  2806. function processArticle($article, $data)
  2807. {
  2808. return $article->map(function ($article) use ($data) {
  2809. $catid = $article->cat_arr_id ?? '';
  2810. $level = json_decode($catid, true);
  2811. $pinyin = '';
  2812. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2813. if (!empty($level) && is_array($level)) {
  2814. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2815. ->where('website_id', $data['website_id'])
  2816. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2817. ->get(['aLIas_pinyin'])
  2818. ->pluck('aLIas_pinyin')
  2819. ->implode('/');
  2820. } else {
  2821. $pinyin = '';
  2822. }
  2823. $article->pinyin = $pinyin;
  2824. return $article;
  2825. });
  2826. }
  2827. /**
  2828. * c端-获取招工招聘下拉选框
  2829. * @param array $data
  2830. * @return array
  2831. * */
  2832. public function getWebsiteJobSelect(array $data): array
  2833. {
  2834. $web = Website::where('id', $data['website_id'])->first();
  2835. if (empty($web)) {
  2836. return Result::error("该网站不存在", 0);
  2837. }
  2838. $hy = JobIndustry::get()->all();
  2839. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2840. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2841. $result = [
  2842. 'hy' => $hy,
  2843. 'zw' => $zw,
  2844. 'jtzw' => $jtzw,
  2845. ];
  2846. if (empty($result)) {
  2847. return Result::error("查询失败", 0);
  2848. }
  2849. return Result::success($result);
  2850. }
  2851. /**
  2852. * c端-获取招工招聘
  2853. * @param array $data
  2854. * @return array
  2855. * */
  2856. public function getWebsiteJob(array $data): array
  2857. {
  2858. $web = Website::where('id', $data['website_id'])->first();
  2859. if (empty($web)) {
  2860. return Result::error("该网站不存在", 0);
  2861. }
  2862. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2863. ->where('job_hunting.website_id', $data['website_id'])
  2864. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2865. $query->where(function ($q) use ($data) {
  2866. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2867. });
  2868. })
  2869. ->select(
  2870. 'job_hunting.id',
  2871. 'job_hunting.cat_arr_id',
  2872. 'job_hunting.job_name_get',
  2873. 'job_hunting.industry',
  2874. 'job_hunting.name',
  2875. 'job_hunting.sexy',
  2876. 'job_hunting.origin',
  2877. 'job_hunting.city_arr_id',
  2878. 'job_hunting.experience',
  2879. 'job_hunting.updated_at',
  2880. 'job_hunting.salary'
  2881. )
  2882. ->orderBy('updated_at', 'desc')
  2883. ->limit($data['job1_num'])
  2884. ->get();
  2885. $web['website_id'] = $data['website_id'];
  2886. if (empty($job_hunting)) {
  2887. $job_huntings = "未查询到相关简历信息";
  2888. } else {
  2889. $job_huntings = $this->processJob($job_hunting, $web);
  2890. }
  2891. // 0:待审核 1:已通过 2:已拒绝
  2892. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2893. ->where('job_recruiting.website_id', $data['website_id'])
  2894. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2895. $query->where(function ($q) use ($data) {
  2896. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2897. });
  2898. })
  2899. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2900. ->select(
  2901. 'job_recruiting.id',
  2902. 'job_recruiting.cat_arr_id',
  2903. 'job_recruiting.title',
  2904. 'job_recruiting.jtzw_id',
  2905. 'job_recruiting.hy_id',
  2906. 'job_recruiting.city_arr_id',
  2907. 'job_recruiting.due_data',
  2908. 'job_recruiting.updated_at',
  2909. 'job_recruiting.experience',
  2910. 'job_recruiting.educational',
  2911. 'job_recruiting.salary',
  2912. 'job_recruiting.zw_id',
  2913. 'job_company.business_name'
  2914. )
  2915. ->orderBy('updated_at', 'desc')
  2916. ->limit($data['job2_num'])
  2917. ->get();
  2918. if (empty($job_recruiting->toArray())) {
  2919. $job_recruitings = "未查询到相关职位信息";
  2920. } else {
  2921. $job_recruitings = $this->processJob($job_recruiting, $web);
  2922. }
  2923. $result = [
  2924. 'job_hunting' => $job_huntings,
  2925. 'job_recuiting' => $job_recruitings,
  2926. ];
  2927. return Result::success($result);
  2928. }
  2929. /**
  2930. * c端-获取招工招聘列表
  2931. * @param array $data
  2932. * @return array
  2933. * */
  2934. public function getWebsiteJobList(array $data): array
  2935. {
  2936. $recruit_where = [];
  2937. $hunt_where = [];
  2938. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2939. if (empty($web)) {
  2940. return Result::error("此网站不存在", 0);
  2941. }
  2942. $website_id['website_id'] = $data['website_id'];
  2943. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2944. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2945. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2946. }
  2947. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2948. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2949. }
  2950. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2951. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2952. }
  2953. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2954. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  2955. }
  2956. $query = JobRecruiting::where('job_recruiting.status', 1)
  2957. ->where('job_recruiting.website_id', $data['website_id'])
  2958. ->where($recruit_where)
  2959. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2960. $query->where(function ($q) use ($data) {
  2961. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2962. });
  2963. })
  2964. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2965. $query->where(function ($q) use ($data) {
  2966. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2967. });
  2968. })
  2969. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2970. ->select(
  2971. 'job_recruiting.id',
  2972. 'job_recruiting.hy_id',
  2973. 'job_recruiting.title',
  2974. 'job_recruiting.zw_id',
  2975. 'job_recruiting.educational',
  2976. 'job_recruiting.jtzw_id',
  2977. 'job_recruiting.city_arr_id',
  2978. 'job_recruiting.due_data',
  2979. 'job_recruiting.experience',
  2980. 'job_recruiting.cat_arr_id',
  2981. 'job_recruiting.updated_at',
  2982. 'job_company.business_name'
  2983. )
  2984. ->orderBy('job_recruiting.updated_at', 'desc');
  2985. $recruit_count = $query->count();
  2986. $query = clone $query;
  2987. $JobRecruiting = $query
  2988. ->offset(($data['page'] - 1) * $data['pageSize'])
  2989. ->limit($data['pageSize'])
  2990. ->get();
  2991. if (empty($JobRecruiting)) {
  2992. $JobRecruiting = "暂无相关职位信息";
  2993. } else {
  2994. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2995. }
  2996. }
  2997. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2998. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2999. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3000. }
  3001. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3002. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3003. }
  3004. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3005. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3006. }
  3007. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3008. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3009. }
  3010. $query = JobHunting::where('job_hunting.status', 2)
  3011. ->where('job_hunting.website_id', $data['website_id'])
  3012. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3013. ->where($hunt_where)
  3014. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3015. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3016. // })
  3017. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3018. $query->where(function ($q) use ($data) {
  3019. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3020. });
  3021. })
  3022. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3023. $query->where(function ($q) use ($data) {
  3024. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3025. });
  3026. })
  3027. ->select(
  3028. 'job_hunting.id',
  3029. 'job_hunting.sexy',
  3030. 'job_hunting.experience',
  3031. 'job_hunting.origin',
  3032. 'job_hunting.industry',
  3033. 'job_hunting.name',
  3034. 'job_hunting.job',
  3035. 'job_hunting.job_name_get',
  3036. 'job_hunting.city_arr_id',
  3037. 'job_hunting.cat_arr_id',
  3038. 'job_hunting.created_at',
  3039. 'job_hunting.updated_at',
  3040. 'job_position.zwname as job_name'
  3041. )
  3042. ->orderBy('job_hunting.updated_at', 'desc');
  3043. $hunt_count = $query->count();
  3044. $query = clone $query;
  3045. $JobHunting = $query
  3046. ->offset(($data['page'] - 1) * $data['pageSize'])
  3047. ->limit($data['pageSize'])
  3048. ->get();
  3049. if (empty($JobHunting)) {
  3050. $JobRecruiting = "暂无相关简历信息";
  3051. } else {
  3052. $JobHunting = $this->processJob($JobHunting, $website_id);
  3053. }
  3054. }
  3055. $result = [
  3056. 'JobRecruiting' => $JobRecruiting ?? [],
  3057. 'recruit_count' => $recruit_count ?? 0,
  3058. 'JobHunting' => $JobHunting ?? [],
  3059. 'hunt_count' => $hunt_count ?? 0,
  3060. ];
  3061. return Result::success($result);
  3062. }
  3063. /**
  3064. * c端-获取招工招聘详情
  3065. * @param array $data
  3066. * @return array
  3067. * */
  3068. public function getWebsiteJobInfo(array $data): array
  3069. {
  3070. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3071. if (empty($web)) {
  3072. return Result::error("该网站不存在", 0);
  3073. }
  3074. $webid = [
  3075. 'website_id' => $data['website_id'],
  3076. ];
  3077. // 职位相关信息
  3078. if ($data['type'] == 1) {
  3079. $query = JobRecruiting::where('status', 1)
  3080. ->where('website_id', $data['website_id'])
  3081. ->select('*');
  3082. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3083. $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();
  3084. if (!empty($company)) {
  3085. $result['company'] = $this->processJob($company, $webid);
  3086. }
  3087. $other_job = JobRecruiting::where('status', 1)
  3088. ->where('website_id', $data['website_id'])
  3089. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3090. ->where('id', '!=', $data['id'])
  3091. ->where('user_id', '=', $job[0]['user_id'])
  3092. ->limit($data['pageSize'])
  3093. ->get();
  3094. if (!empty($other_job)) {
  3095. $result['other_job'] = $this->processJob($other_job, $webid);
  3096. }
  3097. } else {
  3098. // 简历相关信息
  3099. $job = JobHunting::where('job_hunting.status', 2)
  3100. ->where('job_hunting.website_id', $data['website_id'])
  3101. ->where('job_hunting.id', $data['id'])
  3102. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3103. ->select('job_hunting.*', 'user_name')
  3104. ->get();
  3105. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3106. if (!empty($resume->toArray())) {
  3107. $result['resume'] = 1;
  3108. } else {
  3109. $result['resume'] = 0;
  3110. }
  3111. }
  3112. if (empty($job->toArray())) {
  3113. return Result::error("id参数错误", 0);
  3114. }
  3115. if (!empty($job[0]['job_experience'])) {
  3116. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3117. if (!empty($job_experience)) {
  3118. // $hy = [];
  3119. foreach ($job_experience as $key => $value) {
  3120. // $id = $value['id'];
  3121. $hy[$key] = $value['job_industry'];
  3122. $zw_id[$key] = $value['job_typename'];
  3123. $jtzw_id[$key] = $value['job_name'];
  3124. }
  3125. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3126. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3127. // 先将关联表转换为索引数组,提高查找效率
  3128. $hyLookup = [];
  3129. foreach ($hy_table as $item) {
  3130. $hyLookup[$item['hyid']] = $item['hyname'];
  3131. }
  3132. $zwLookup = [];
  3133. foreach ($zw_table as $item) {
  3134. $zwLookup[$item['zwid']] = $item['zwname'];
  3135. }
  3136. foreach ($job_experience as $key => &$value) {
  3137. // 处理行业名称
  3138. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3139. $value['hy_name'] = $hyLookup[$hy[$key]];
  3140. }
  3141. // 处理职位名称
  3142. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3143. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3144. }
  3145. // 处理具体职位名称
  3146. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3147. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3148. }
  3149. }
  3150. // 释放引用,防止意外修改后续代码
  3151. unset($value);
  3152. }
  3153. $result['job_experience'] = $job_experience ?? [];
  3154. }
  3155. if (!empty($job[0]['education_experience'])) {
  3156. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3157. if (!empty($education_experience)) {
  3158. foreach ($education_experience as $key => $value) {
  3159. // $id = $value['id'];
  3160. $education[$key] = $value['school_education'];
  3161. }
  3162. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3163. // // 先将关联表转换为索引数组,提高查找效率
  3164. $educationLookup = [];
  3165. foreach ($education_table as $item) {
  3166. $educationLookup[$item['evalue']] = $item['ename'];
  3167. }
  3168. foreach ($education_experience as $key => &$value) {
  3169. // 处理学历名称
  3170. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3171. $value['education_name'] = $educationLookup[$education[$key]];
  3172. }
  3173. }
  3174. }
  3175. $result['education_experience'] = $job_experience ?? [];
  3176. }
  3177. $result['job'] = $this->processJob($job, $webid);
  3178. // // 返现对应的栏目
  3179. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3180. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3181. ->whereIn('category_id', $catid)
  3182. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3183. ->orderBy('pid')->get()->all();
  3184. if (!empty($category)) {
  3185. $result['category'] = $category;
  3186. }
  3187. $result['job'] = $job;
  3188. $result['job_experience'] = $job_experience ?? [];
  3189. $result['education_experience'] = $education_experience ?? [];
  3190. if (empty($result)) {
  3191. return Result::error("参数错误", 0);
  3192. }
  3193. return Result::success($result);
  3194. }
  3195. /**
  3196. * c端-申请职位
  3197. * @param array $data
  3198. * @return array
  3199. * */
  3200. public function getWebsiteJobApply(array $data): array
  3201. {
  3202. // 首先验证网站是否存在
  3203. // return Result::success($data);
  3204. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3205. if (empty($web)) {
  3206. return Result::error("该网站不存在", 0);
  3207. }
  3208. // 验证用户是否存在且为个人会员/管理员
  3209. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3210. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3211. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3212. return Result::error("用户不存在", 0);
  3213. }
  3214. // 去除重复元素和空元素,并保持原始顺序
  3215. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3216. return !empty($value);
  3217. }));
  3218. // 验证职位是否存在 1:审核通过
  3219. $recruiting = JobRecruiting::where('status', 1)
  3220. ->where('website_id', $data['website_id'])
  3221. ->whereIn('id', $data['recruit_id'])
  3222. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3223. if (empty($recruiting)) {
  3224. return Result::error("该职位不存在", 0);
  3225. }
  3226. // 简历是否存在
  3227. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3228. if (empty($hunt_id)) {
  3229. return Result::error("该简历不存在", 0);
  3230. }
  3231. $data['hunt_id'] = $hunt_id['hunt_id'];
  3232. // // 验证是否已投递过该职位
  3233. $apply = JobApply::where('user_id', $data['user_id'])
  3234. ->where('hunt_id', $data['hunt_id'])
  3235. ->where('website_id', $data['website_id'])
  3236. ->whereIn('recruit_id', $data['recruit_id'])
  3237. ->get(['recruit_id']);
  3238. if (!empty($apply->toArray())) {
  3239. return Result::error("您已投递过该职位!");
  3240. }
  3241. $insertData = array_map(function ($recruiting) use ($data) {
  3242. return [
  3243. 'user_id' => $data['user_id'],
  3244. 'hunt_id' => $data['hunt_id'],
  3245. 'website_id' => $data['website_id'],
  3246. 'recruit_id' => $recruiting['recruit_id'],
  3247. 'receiver_id' => $recruiting['receiver_id'],
  3248. 'status' => 1,
  3249. ];
  3250. }, $recruiting);
  3251. // 批量插入数据
  3252. $result = JobApply::insert($insertData);
  3253. if (empty($result)) {
  3254. return Result::error("投递失败", 0);
  3255. }
  3256. return Result::success($result);
  3257. }
  3258. /**
  3259. * 招工招聘-沟通简历
  3260. * @param array $data
  3261. * @return array
  3262. * */
  3263. public function getWebsiteJobResume(array $data): array
  3264. {
  3265. // 首先验证网站是否存在
  3266. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3267. if (empty($web)) {
  3268. return Result::error("该网站不存在", 0);
  3269. }
  3270. // return Result::success($data);
  3271. // 验证用户是否存在且为企业会员/管理员
  3272. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3273. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3274. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3275. return Result::error("用户不存在", 0);
  3276. }
  3277. // 去除重复元素和空元素,并保持原始顺序
  3278. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3279. return !empty($value);
  3280. }));
  3281. // 验证简历是否存在
  3282. $hunting = JobHunting::where('status', 2)
  3283. ->where('website_id', $data['website_id'])
  3284. ->whereIn('id', $data['hunt_id'])
  3285. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3286. if (empty($hunting)) {
  3287. return Result::error("该简历不存在", 0);
  3288. }
  3289. // 验证是否已沟通过该简历
  3290. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3291. ->where('recruit_id', $data['recruit_id'])
  3292. ->where('website_id', $data['website_id'])
  3293. ->whereIn('hunt_id', $data['hunt_id'])
  3294. ->get(['hunt_id']);
  3295. if (!empty($remuse->toArray())) {
  3296. return Result::error("您已沟通过该简历!");
  3297. }
  3298. // 准备要插入的数据数组
  3299. $insertData = array_map(function ($hunting) use ($data) {
  3300. return [
  3301. 'user_id' => $data['user_id'],
  3302. 'recruit_id' => $data['recruit_id'],
  3303. 'website_id' => $data['website_id'],
  3304. 'hunt_id' => $hunting['hunt_id'],
  3305. 'receiver_id' => $hunting['receiver_id'],
  3306. 'status' => 1,
  3307. ];
  3308. }, $hunting);
  3309. // 批量插入数据
  3310. $result = JobRemuse::insert($insertData);
  3311. if (empty($result)) {
  3312. return Result::error("沟通失败", 0);
  3313. }
  3314. return Result::success($result);
  3315. }
  3316. /**
  3317. * 招工招聘 -我的职位(企业会员)
  3318. * @param array $data
  3319. * @return array
  3320. */
  3321. public function getWebsiteJobRecruiting(array $data): array
  3322. {
  3323. $web = Website::where('id', $data['website_id'])->first('id');
  3324. if (empty($web)) {
  3325. return Result::error("该网站不存在", 0);
  3326. }
  3327. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3328. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3329. return Result::error("用户暂无权限!", 0);
  3330. }
  3331. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3332. $result = JobRecruiting::where('website_id', $data['website_id'])
  3333. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3334. $query->where('user_id', $user['id']);
  3335. })
  3336. ->where('status', 1)
  3337. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3338. ->orderBy('updated_at', 'desc')
  3339. ->limit($data['pageSize'])
  3340. ->get();
  3341. if (empty($result)) {
  3342. return Result::error("暂无相关职位信息", 0);
  3343. }
  3344. return Result::success($result);
  3345. }
  3346. /**
  3347. * c端 - 验证路由
  3348. * @param array $data
  3349. * @return array
  3350. */
  3351. /**
  3352. * c端 - 验证路由
  3353. * @param array $data
  3354. * @return array
  3355. */
  3356. public function checkWebsiteRoute(array $data): array
  3357. {
  3358. // 测试001111111222
  3359. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3360. if (empty($web)) {
  3361. return Result::error("该网站不存在", 0);
  3362. } elseif ($web['status'] != 1) {
  3363. return Result::error("网站已经关闭", 0);
  3364. }
  3365. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3366. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3367. // 验证路由是否存在
  3368. if (empty($whiteRouterInfo)) {
  3369. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3370. }
  3371. if (!empty($whiteRouterInfo)) {
  3372. return Result::success($whiteRouterInfo->toArray());
  3373. }
  3374. }
  3375. // 验证栏目路由
  3376. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3377. ->where('aLIas_pinyin', $data['last_route'])
  3378. ->get()->all();
  3379. if (count($last_category) == 0) {
  3380. return Result::error("该栏目不存在", 0);
  3381. }
  3382. if (count($last_category) > 1) {
  3383. return Result::error("该子级栏目存在多个,路由验证失败!", 0);
  3384. }
  3385. if (count($last_category) == 1) {
  3386. $last_category = $last_category[0];
  3387. }
  3388. // return Result::success($last_category);
  3389. if (isset($data['id']) && !empty($data['id'])) {
  3390. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3391. switch ($last_category['type']) {
  3392. case 1:
  3393. // 文章
  3394. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3395. $article = Article::where('status', 1)
  3396. ->where('id', $data['id'])
  3397. ->where(function ($query) use ($data) {
  3398. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3399. ->orWhereNull("ignore_ids");
  3400. })
  3401. ->first(['cat_arr_id']);
  3402. if (empty($article)) {
  3403. return Result::error("该文章不存在", 0);
  3404. }
  3405. // return Result::success($article);
  3406. break;
  3407. case 2:
  3408. // 商品
  3409. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3410. $article = Good::where('website_id', $data['website_id'])
  3411. ->where('status', 2)
  3412. ->where('id', $data['id'])
  3413. ->first(['cat_arr_id']);
  3414. if (empty($article)) {
  3415. return Result::error("该商品不存在", 0);
  3416. }
  3417. break;
  3418. case 3:
  3419. // 书刊信息
  3420. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3421. $article = Book::where('website_id', $data['website_id'])
  3422. ->where('status', 2)
  3423. ->where('id', $data['id'])
  3424. ->first(['id', 'cat_arr_id']);
  3425. if (empty($article)) {
  3426. return Result::error("该书刊不存在", 0);
  3427. }
  3428. break;
  3429. case 4:
  3430. // 招聘
  3431. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3432. $article = JobRecruiting::where('website_id', $data['website_id'])
  3433. ->where('status', 1)
  3434. ->where('id', $data['id'])
  3435. ->first(['cat_arr_id']);
  3436. if (empty($article)) {
  3437. return Result::error("该招聘不存在", 0);
  3438. }
  3439. break;
  3440. case 5:
  3441. // 求职
  3442. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3443. $article = JobHunting::where('website_id', $data['website_id'])
  3444. ->where('status', 2)
  3445. ->where('id', $data['id'])
  3446. ->first(['cat_arr_id']);
  3447. if (empty($article)) {
  3448. return Result::error("该求职不存在", 0);
  3449. }
  3450. break;
  3451. case 6:
  3452. // 企业
  3453. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3454. $article = Company::
  3455. // where('website_id', $data['website_id'])
  3456. // ->
  3457. where('status', 1)
  3458. ->where('id', $data['id'])
  3459. ->first(['cat_arr_id']);
  3460. if (empty($article)) {
  3461. return Result::error("该企业不存在", 0);
  3462. }
  3463. break;
  3464. case 7:
  3465. // 项目
  3466. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3467. $article = Project::where('website_id', $data['website_id'])
  3468. ->where('status', 1)
  3469. ->where('id', $data['id'])
  3470. ->first(['cat_arr_id']);
  3471. if (empty($article)) {
  3472. return Result::error("该项目不存在", 0);
  3473. }
  3474. break;
  3475. default:
  3476. return Result::error("该数据不存在", 0);
  3477. break;
  3478. }
  3479. $catid = 0;
  3480. $catidArray = json_decode($article['cat_arr_id'], true);
  3481. $catid = !empty($catidArray) ? end($catidArray) : null;
  3482. // return Result::success($article['cat_arr_id']);
  3483. if (empty($catid)) {
  3484. return Result::error("该数据不存在", 0);
  3485. }
  3486. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3487. ->where('category_id', $catid)
  3488. ->select('path')
  3489. ->pluck('path');
  3490. } else {
  3491. if ($last_category['pid'] != 0) {
  3492. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3493. $catid = !empty($cat_arr) ? end($cat_arr) : null;
  3494. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3495. ->where('category_id', $catid)
  3496. ->where('path', $data['all_route'])
  3497. ->pluck('path');
  3498. } else {
  3499. $pinyin[0] = $last_category['aLIas_pinyin'];
  3500. }
  3501. }
  3502. // return Result::success($pinyin[0]);
  3503. if (empty($pinyin) || count($pinyin) > 1 || $pinyin[0] != $data['all_route']) {
  3504. return Result::error('非法路径!');
  3505. } else {
  3506. return Result::success($pinyin);
  3507. }
  3508. }
  3509. /**
  3510. * 招工招聘 - 获取推荐职位
  3511. * @param array $data
  3512. * @return array
  3513. */
  3514. public function getWebsiteLevelJob(array $data): array
  3515. {
  3516. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3517. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3518. ->where('job_recruiting.status', 1)
  3519. ->where('job_level', $data['job_level'])
  3520. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3521. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3522. ->orderBy('job_recruiting.updated_at', 'desc')
  3523. ->limit($data['pageSize'])
  3524. ->get();
  3525. $web = ['website_id' => $data['website_id']];
  3526. if (!empty($job)) {
  3527. $result = $this->processJob($job, $web);
  3528. }
  3529. if (empty($result)) {
  3530. return Result::error("暂无相关职位信息", 0);
  3531. }
  3532. return Result::success($result);
  3533. }
  3534. /**
  3535. * 验证导航名称是否重复
  3536. * @return void
  3537. */
  3538. //20250226 产品列表
  3539. public function getGoodList(array $data): array
  3540. {
  3541. var_dump($data, '---------1-2--');
  3542. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3543. unset($data['user_type_id']);
  3544. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3545. $where = [];
  3546. if ($type_id != '10000') {
  3547. $where = [
  3548. 'good.user_id' => $user_id,
  3549. ];
  3550. }
  3551. //类型
  3552. if (isset($data['type_id']) && $data['type_id']) {
  3553. $where['good.type_id'] = $data['type_id'];
  3554. }
  3555. //名称
  3556. if (isset($data['name']) && $data['name']) {
  3557. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3558. }
  3559. //status
  3560. if (isset($data['status']) && $data['status'] != '') {
  3561. $where['good.status'] = $data['status'];
  3562. }
  3563. //status1
  3564. // if (isset($data['status1']) && $data['status1'] == 1) {
  3565. // $status1 = 1;
  3566. // }
  3567. $where1 = [];
  3568. //website_id
  3569. // if (isset($data['website_id']) && $data['website_id']) {
  3570. // $where1 = [
  3571. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3572. // ];
  3573. // }
  3574. // website_name
  3575. if (isset($data['website_name']) && $data['website_name']) {
  3576. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3577. }
  3578. // catid
  3579. if (isset($data['category_name']) && $data['category_name']) {
  3580. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3581. }
  3582. // $result = Good::where($where)
  3583. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3584. var_dump($where, '---------1---');
  3585. $result = Good::where($where)
  3586. ->when(!empty($where1), function ($query) use ($where1) {
  3587. return $query->where($where1);
  3588. })
  3589. //status 1待审核2已审核3已拒绝
  3590. ->when(isset($data['status1']), function ($query) {
  3591. return $query->whereIn('good.status', [1, 3]);
  3592. })
  3593. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3594. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3595. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3596. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3597. ->orderBy("updated_at", "desc")
  3598. ->limit($data['page_size'])
  3599. ->offset(($data['page'] - 1) * $data['page_size'])
  3600. ->get();
  3601. $count = 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")->count();
  3614. $data = [
  3615. 'rows' => $result->toArray(),
  3616. 'count' => $count,
  3617. ];
  3618. if (empty($result)) {
  3619. return Result::error("此栏目暂无相关产品", 0);
  3620. }
  3621. return Result::success($data);
  3622. }
  3623. public function getGoodInfo(array $data): array
  3624. {
  3625. $result = Good::where('id', $data['id'])->first();
  3626. if (empty($result)) {
  3627. return Result::error("此产品不存在", 0);
  3628. }
  3629. return Result::success($result);
  3630. }
  3631. public function addGood(array $data): array
  3632. {
  3633. // unset($data['city_arr_id']);
  3634. // unset($data['cat_arr_id']);
  3635. $data['city_id'] = end($data['city_arr_id']);
  3636. $data['catid'] = end($data['cat_arr_id']);
  3637. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3638. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3639. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3640. unset($data['imgUrl']); //大小写
  3641. if (isset($data['price']) && $data['price'] == '') {
  3642. $data['price'] = 0;
  3643. }
  3644. if ($data['imgurl'] == '') {
  3645. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3646. preg_match_all($reg, $data['detail'], $matches);
  3647. if (isset($matches[1][0])) {
  3648. //截取varchar240
  3649. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3650. }
  3651. }
  3652. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3653. //提取标题+内容中的关键词
  3654. $data['keyword'] = $data['name'];
  3655. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3656. Jieba::init(); // 初始化 jieba-php
  3657. Finalseg::init();
  3658. $segList = Jieba::cut($data['keyword']);
  3659. $segList1 = array_slice($segList, 0, 8);
  3660. $data['keyword'] = implode(',', $segList1);
  3661. }
  3662. if ($data['description'] == '') {
  3663. //提取内容中的描述
  3664. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3665. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3666. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3667. }
  3668. if ($data['status'] == 1) {
  3669. $this->sendMessage([
  3670. 'talk_type' => 200,
  3671. 'title' => $data['name'],
  3672. 'content' => '提交了审核',
  3673. 'messageType' => 3,
  3674. ]);
  3675. }
  3676. $result = Good::insert($data);
  3677. if (empty($result)) {
  3678. return Result::error("添加失败", 0);
  3679. }
  3680. return Result::success($result);
  3681. }
  3682. public function updateGood(array $data): array
  3683. {
  3684. $data['city_id'] = end($data['city_arr_id']);
  3685. $data['catid'] = end($data['cat_arr_id']);
  3686. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3687. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3688. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3689. //设置东八区
  3690. date_default_timezone_set('Asia/Shanghai');
  3691. $data['updated_at'] = date('Y-m-d H:i:s');
  3692. if (isset($data['price']) && $data['price'] == '') {
  3693. $data['price'] = 0;
  3694. }
  3695. if ($data['imgurl'] == '') {
  3696. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3697. preg_match_all($reg, $data['detail'], $matches);
  3698. if (isset($matches[1][0])) {
  3699. //截取varchar240
  3700. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3701. }
  3702. }
  3703. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3704. //提取标题+内容中的关键词
  3705. $data['keyword'] = $data['name'];
  3706. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3707. Jieba::init(); // 初始化 jieba-php
  3708. Finalseg::init();
  3709. $segList = Jieba::cut($data['keyword']);
  3710. $segList1 = array_slice($segList, 0, 8);
  3711. $data['keyword'] = implode(',', $segList1);
  3712. }
  3713. if ($data['description'] == '') {
  3714. //提取内容中的描述
  3715. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3716. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3717. }
  3718. if ($data['status'] == 1) {
  3719. $this->sendMessage([
  3720. 'talk_type' => 200,
  3721. 'title' => $data['name'],
  3722. 'content' => '提交了审核',
  3723. 'messageType' => 3,
  3724. ]);
  3725. }
  3726. $result = Good::where('id', $data['id'])->update($data);
  3727. if (empty($result)) {
  3728. return Result::error("更新失败", 0);
  3729. }
  3730. return Result::success($result);
  3731. }
  3732. public function delGood(array $data): array
  3733. {
  3734. $result = Good::where('id', $data['id'])->delete();
  3735. if (empty($result)) {
  3736. return Result::error("删除失败", 0);
  3737. }
  3738. return Result::success($result);
  3739. }
  3740. //20250226 产品列表
  3741. //20250306 求职信息
  3742. public function getJobHuntingList(array $data): array
  3743. {
  3744. $where = [];
  3745. if (isset($data['username']) && !empty($data['username'])) {
  3746. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3747. }
  3748. //status 1待审核2已审核3已拒绝
  3749. if (isset($data['status']) && $data['status'] != '') {
  3750. $where = [
  3751. 'job_hunting.status' => $data['status'],
  3752. ];
  3753. }
  3754. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3755. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3756. unset($data['type_id']);
  3757. if ($type_id != '10000') {
  3758. $where[] = ['job_hunting.user_id', '=', $user_id];
  3759. }
  3760. $result = JobHunting::where($where)
  3761. ->when(!empty($data['status1']), function ($query) use ($data) {
  3762. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3763. })
  3764. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3765. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3766. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3767. ->orderBy("updated_at", "desc")
  3768. ->limit($data['page_size'])
  3769. ->offset(($data['page'] - 1) * $data['page_size'])
  3770. ->get();
  3771. if (empty($result)) {
  3772. return Result::error("查询失败", 0);
  3773. }
  3774. $count = JobHunting::where($where)
  3775. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3776. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3777. ->count();
  3778. $data = [
  3779. 'rows' => $result->toArray(),
  3780. 'count' => $count,
  3781. ];
  3782. return Result::success($data);
  3783. }
  3784. public function getJobHuntingApply(array $data): array
  3785. {
  3786. var_dump($data, '-----------------test--------1-');
  3787. $where = [];
  3788. if (isset($data['username']) && !empty($data['username'])) {
  3789. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3790. }
  3791. if (isset($data['salary']) && !empty($data['salary'])) {
  3792. $where[] = [
  3793. 'job_hunting.salary',
  3794. '=',
  3795. $data['salary'],
  3796. ];
  3797. }
  3798. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3799. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3800. unset($data['type_id']);
  3801. if ($type_id != '10000') {
  3802. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3803. }
  3804. var_dump($where, '-----------------test---------');
  3805. $result = jobApply::where($where)
  3806. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3807. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3808. // })
  3809. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3810. ->where('job_enum.egroup', '=', 'income')
  3811. ->where('job_hunting.status', 2) //已审核
  3812. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3813. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3814. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3815. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3816. //职位----是申请职位
  3817. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3818. ->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')
  3819. ->orderBy("job_hunting.updated_at", "desc")
  3820. ->limit($data['page_size'])
  3821. ->offset(($data['page'] - 1) * $data['page_size'])
  3822. ->get();
  3823. if (empty($result)) {
  3824. return Result::error("查询失败", 0);
  3825. }
  3826. $count = jobApply::where($where)
  3827. ->where('job_enum.egroup', '=', 'income')
  3828. ->where('job_hunting.status', 2) //已审核
  3829. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3830. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3831. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3832. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3833. //职位----是申请职位
  3834. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3835. ->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')
  3836. ->count();
  3837. $data = [
  3838. 'rows' => $result->toArray(),
  3839. 'count' => $count,
  3840. ];
  3841. return Result::success($data);
  3842. }
  3843. public function addJobHunting(array $data): array
  3844. {
  3845. date_default_timezone_set('Asia/Shanghai');
  3846. unset($data['company_name']);
  3847. unset($data['job_industry']);
  3848. unset($data['job_name']);
  3849. unset($data['department']);
  3850. unset($data['job_timeList']);
  3851. unset($data['job_content']);
  3852. unset($data['job_typename']); //不知道这是啥,
  3853. $data['created_at'] = date('Y-m-d H:i:s');
  3854. $data['updated_at'] = date('Y-m-d H:i:s');
  3855. //根据用户 user_id 只能添加一次
  3856. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3857. if (!empty($result)) {
  3858. return Result::error("您已添加过求职信息", 0);
  3859. }
  3860. var_dump($result, '-----------------test---------');
  3861. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3862. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3863. $cityArr = json_decode($data['city_arr_id'], true);
  3864. $data['city_id'] = end($cityArr);
  3865. } else {
  3866. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3867. $data['city_id'] = end($data['city_arr_id']);
  3868. }
  3869. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3870. $this->sendMessage([
  3871. 'talk_type' => 600,
  3872. 'title' => $data['name'],
  3873. 'content' => '提交了审核',
  3874. 'messageType' => 11,
  3875. ]);
  3876. }
  3877. $result = JobHunting::create($data);
  3878. if (empty($result)) {
  3879. return Result::error("添加失败", 0);
  3880. }
  3881. return Result::success($result);
  3882. }
  3883. public function delJobHunting(array $data): array
  3884. {
  3885. $result = JobHunting::where('id', $data['id'])->delete();
  3886. if (empty($result)) {
  3887. return Result::error("删除失败", 0);
  3888. }
  3889. return Result::success($result);
  3890. }
  3891. public function updateJobHunting(array $data): array
  3892. {
  3893. //设置东八区
  3894. date_default_timezone_set('Asia/Shanghai');
  3895. unset($data['company_name']);
  3896. unset($data['job_industry']);
  3897. unset($data['job_name']);
  3898. unset($data['department']);
  3899. unset($data['job_timeList']);
  3900. unset($data['job_content']);
  3901. unset($data['job_typename']); //不知道这是啥,
  3902. $data['created_at'] = date('Y-m-d H:i:s');
  3903. $data['updated_at'] = date('Y-m-d H:i:s');
  3904. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3905. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3906. $cityArr = json_decode($data['city_arr_id'], true);
  3907. $data['city_id'] = end($cityArr);
  3908. } else {
  3909. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3910. $data['city_id'] = end($data['city_arr_id']);
  3911. }
  3912. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3913. $this->sendMessage([
  3914. 'talk_type' => 600,
  3915. 'title' => $data['name'],
  3916. 'content' => '提交了审核',
  3917. 'messageType' => 11,
  3918. ]);
  3919. }
  3920. $result = JobHunting::where('id', $data['id'])->update($data);
  3921. if (empty($result)) {
  3922. return Result::error("更新失败", 0);
  3923. }
  3924. return Result::success($result);
  3925. }
  3926. public function getJobHuntingInfo(array $data): array
  3927. {
  3928. $result = JobHunting::where('id', $data['id'])->first();
  3929. if (empty($result)) {
  3930. return Result::error("查询失败", 0);
  3931. }
  3932. return Result::success($result);
  3933. }
  3934. public function getJobHuntingData(array $data): array
  3935. {
  3936. $jobEnum = JobEnum::get();
  3937. $jobIndustry = JobIndustry::get();
  3938. $jobNature = JobNature::get();
  3939. $jobPosition = JobPosition::get();
  3940. $data = [
  3941. 'jobEnum' => $jobEnum,
  3942. 'jobIndustry' => $jobIndustry,
  3943. 'jobNature' => $jobNature,
  3944. 'jobPosition' => $jobPosition,
  3945. ];
  3946. return Result::success($data);
  3947. }
  3948. public function delJobHuntingInfo(array $data): array
  3949. {
  3950. $result = JobHunting::where('id', $data['id'])->delete();
  3951. return Result::success();
  3952. }
  3953. //20250324 通知,公告,消息
  3954. public function delNotice(array $data): array
  3955. {
  3956. $result = Notice::where('id', $data['id'])->delete();
  3957. if ($result) {
  3958. return Result::success();
  3959. } else {
  3960. return Result::error("删除失败", 0);
  3961. }
  3962. }
  3963. public function getNoticeInfo(array $data): array
  3964. {
  3965. $result = Notice::where('id', $data['id'])->first();
  3966. // var_dump($result['re_user_ids'], '--------------------');
  3967. if (empty($result)) {
  3968. return Result::error("查询失败", 0);
  3969. }
  3970. return Result::success($result);
  3971. }
  3972. public function readNotice(array $data): array
  3973. {
  3974. $result = Notice::where('id', $data['id'])->first();
  3975. // var_dump($result['re_user_ids'], '--------------------');
  3976. if (empty($result)) {
  3977. return Result::error("查询失败", 0);
  3978. }
  3979. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  3980. $re_user_ids = json_decode($result['re_user_ids'], true);
  3981. var_dump($re_user_ids, '--------------1---test---------');
  3982. var_dump($data, '--------------1---test---------');
  3983. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  3984. //如果已经存在,就不再添加
  3985. if (isset($result['read_id']) && !empty($result['read_id'])) {
  3986. $read_id = json_decode($result['read_id'], true);
  3987. if (!is_array($read_id)) {
  3988. $read_id = [];
  3989. }
  3990. if (!in_array($data['user_id'], $read_id)) {
  3991. $read_id[] = $data['user_id'];
  3992. $result['read_id'] = json_encode($read_id);
  3993. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  3994. }
  3995. } else {
  3996. //如果不存在,就添加
  3997. $result['read_id'] = json_encode([$data['user_id']]);
  3998. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  3999. }
  4000. }
  4001. return Result::success($result);
  4002. }
  4003. public function addNotice(array $data): array
  4004. {
  4005. date_default_timezone_set('Asia/Shanghai');
  4006. $data['created_at'] = date('Y-m-d H:i:s');
  4007. $data['updated_at'] = date('Y-m-d H:i:s');
  4008. $user_id = UserInfo::
  4009. //city_id不是null
  4010. whereNotNull('city_id')
  4011. ->whereNotNull('department_id')
  4012. ->where(function ($query) use ($data) {
  4013. $query->where(function ($subQuery) use ($data) {
  4014. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4015. });
  4016. })
  4017. ->where(function ($query) use ($data) {
  4018. $query->where(function ($subQuery) use ($data) {
  4019. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4020. });
  4021. })
  4022. ->pluck('user_id')->toArray();
  4023. $user_id = array_unique($user_id);
  4024. $chat_ids = $user_id;
  4025. $user_id = json_encode($user_id);
  4026. $data['re_user_ids'] = $user_id;
  4027. $this->sendMessage([
  4028. 'talk_type' => 700,
  4029. 'title' => $data['title'],
  4030. 'content' => '提交了审核',
  4031. 'messageType' => 5,
  4032. ]);
  4033. $result = Notice::insertGetId($data);
  4034. if (empty($result)) {
  4035. return Result::error("添加失败", 0);
  4036. }
  4037. return Result::success($result);
  4038. }
  4039. public function updateNotice(array $data): array
  4040. {
  4041. date_default_timezone_set('Asia/Shanghai');
  4042. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4043. $user_id = UserInfo::
  4044. //city_id不是null
  4045. whereNotNull('city_id')
  4046. ->whereNotNull('department_id')
  4047. ->where(function ($query) use ($data) {
  4048. $query->where(function ($subQuery) use ($data) {
  4049. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4050. });
  4051. })
  4052. ->where(function ($query) use ($data) {
  4053. $query->where(function ($subQuery) use ($data) {
  4054. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4055. });
  4056. })
  4057. ->pluck('user_id')->toArray();
  4058. $user_id = array_unique($user_id);
  4059. $user_id = json_encode($user_id);
  4060. $data['re_user_ids'] = $user_id;
  4061. $data['updated_at'] = date('Y-m-d H:i:s');
  4062. $this->sendMessage([
  4063. 'talk_type' => 700,
  4064. 'title' => $data['title'],
  4065. 'content' => '提交了审核',
  4066. 'messageType' => 5,
  4067. ]);
  4068. $result = Notice::where('id', $data['id'])->update($data);
  4069. return Result::success($result);
  4070. }
  4071. public function getNoticeList(array $data): array
  4072. {
  4073. $where = [];
  4074. //title
  4075. if (isset($data['title']) && !empty($data['title'])) {
  4076. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4077. }
  4078. //level
  4079. if (isset($data['level']) && !empty($data['level'])) {
  4080. $where[] = ['notice.level', '=', $data['level']];
  4081. }
  4082. //status
  4083. if (isset($data['status']) && !empty($data['status'])) {
  4084. $where[] = ['notice.status', '=', $data['status']];
  4085. }
  4086. //type
  4087. if (isset($data['type']) && !empty($data['type'])) {
  4088. $where[] = ['notice.type', '=', $data['type']];
  4089. }
  4090. var_dump($data, '------------11111-2----test---------');
  4091. if ($data['type_id'] == 10000) {
  4092. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4093. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4094. })
  4095. ->where($where)
  4096. ->orderBy('updated_at', 'desc')
  4097. ->limit($data['page_size'])
  4098. ->offset(($data['page'] - 1) * $data['page_size'])
  4099. ->get();
  4100. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4101. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4102. })
  4103. ->where($where)
  4104. ->orderBy('updated_at', 'desc')
  4105. ->count();
  4106. } else {
  4107. $result = Notice::where($where)
  4108. // ->where('user_id', $data['user_id'])
  4109. ->Where(function ($query) use ($data) {
  4110. $query->Where(function ($q) use ($data) {
  4111. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4112. ->orWhere('notice.user_id', $data['user_id']);
  4113. });
  4114. })
  4115. ->when(!empty($data['status1']), function ($query) use ($data) {
  4116. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4117. })
  4118. ->orderBy('updated_at', 'desc')
  4119. ->limit($data['page_size'])
  4120. ->offset(($data['page'] - 1) * $data['page_size'])
  4121. ->get();
  4122. $total = Notice::where($where)
  4123. ->when(!empty($data['status1']), function ($query) use ($data) {
  4124. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4125. })
  4126. // ->where('user_id', $data['user_id'])
  4127. ->Where(function ($query) use ($data) {
  4128. $query->Where(function ($q) use ($data) {
  4129. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4130. ->orWhere('notice.user_id', $data['user_id']);
  4131. });
  4132. })
  4133. ->count();
  4134. }
  4135. if (empty($result)) {
  4136. return Result::error("查询失败", 0);
  4137. }
  4138. $data = [
  4139. 'rows' => $result,
  4140. 'count' => $total,
  4141. ];
  4142. return Result::success($data);
  4143. }
  4144. public function noticeList(array $data): array
  4145. {
  4146. $where = [];
  4147. //title
  4148. if (isset($data['title']) && !empty($data['title'])) {
  4149. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4150. }
  4151. //level
  4152. if (isset($data['level']) && !empty($data['level'])) {
  4153. $where[] = ['notice.level', '=', $data['level']];
  4154. }
  4155. //status
  4156. if (isset($data['status']) && !empty($data['status'])) {
  4157. $where[] = ['notice.status', '=', $data['status']];
  4158. }
  4159. //type
  4160. if (isset($data['type']) && !empty($data['type'])) {
  4161. $where[] = ['notice.type', '=', $data['type']];
  4162. }
  4163. var_dump($data, '------------11111-2----test---------');
  4164. if ($data['type_id'] == 10000) {
  4165. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4166. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4167. })
  4168. ->where($where)
  4169. ->orderBy('updated_at', 'desc')
  4170. ->limit($data['page_size'])
  4171. ->offset(($data['page'] - 1) * $data['page_size'])
  4172. ->get();
  4173. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4174. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4175. })
  4176. ->where($where)
  4177. ->orderBy('updated_at', 'desc')
  4178. ->count();
  4179. } else {
  4180. $result = Notice::where($where)
  4181. // ->where('user_id', $data['user_id'])
  4182. ->Where(function ($query) use ($data) {
  4183. $query->Where(function ($q) use ($data) {
  4184. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4185. ->orWhere('notice.user_id', $data['user_id']);
  4186. });
  4187. })
  4188. ->when(!empty($data['status1']), function ($query) use ($data) {
  4189. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4190. })
  4191. ->orderBy('updated_at', 'desc')
  4192. ->limit($data['page_size'])
  4193. ->offset(($data['page'] - 1) * $data['page_size'])
  4194. ->get();
  4195. $total = Notice::where($where)
  4196. ->when(!empty($data['status1']), function ($query) use ($data) {
  4197. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4198. })
  4199. // ->where('user_id', $data['user_id'])
  4200. ->Where(function ($query) use ($data) {
  4201. $query->Where(function ($q) use ($data) {
  4202. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4203. ->orWhere('notice.user_id', $data['user_id']);
  4204. });
  4205. })
  4206. ->count();
  4207. }
  4208. if (empty($result)) {
  4209. return Result::error("查询失败", 0);
  4210. }
  4211. $data = [
  4212. 'rows' => $result,
  4213. 'count' => $total,
  4214. ];
  4215. return Result::success($data);
  4216. }
  4217. public function getNoticeDetail(array $data): array
  4218. {
  4219. $result = Notice::where('id', $data['id'])->first();
  4220. if (empty($result)) {
  4221. return Result::error("查询失败", 0);
  4222. }
  4223. return Result::success($result);
  4224. }
  4225. public function deleteNotice(array $data): array
  4226. {
  4227. $notice = Notice::where('id', $data['id'])->first();
  4228. if (empty($notice)) {
  4229. return Result::error("删除失败", 0);
  4230. }
  4231. $chat_group_id = $notice->group_id;
  4232. if ($chat_group_id) {
  4233. //删除群聊
  4234. ChatGroups::where('id', $chat_group_id)->delete();
  4235. //删除群成员
  4236. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4237. //删除群聊记录
  4238. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4239. }
  4240. $result = Notice::where('id', $data['id'])->delete();
  4241. return Result::success($result);
  4242. }
  4243. public function complaintList(array $data): array
  4244. {
  4245. var_dump($data, '---------1---------');
  4246. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4247. unset($data['type_id']);
  4248. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4249. $where = [];
  4250. if ($type_id != 10000 && empty($data['deal_user'])) {
  4251. // $where['complaint.user_id'] = $user_id;
  4252. }
  4253. if (!empty($data['title'])) {
  4254. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4255. }
  4256. if (!empty($data['department_id'])) {
  4257. $where['complaint.department_id'] = $data['department_id'];
  4258. }
  4259. if (!empty($data['deal'])) {
  4260. $where['complaint.deal'] = $data['deal'];
  4261. }
  4262. if (!empty($data['status'])) {
  4263. $where['complaint.status'] = $data['status'];
  4264. }
  4265. var_dump(!empty($data['deal_user']), '----------1');
  4266. var_dump($where, '----------2');
  4267. $result = Complaint::where($where)
  4268. ->when(!empty($data['status1']), function ($query) use ($data) {
  4269. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4270. })
  4271. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4272. //json re_user_ids data[user_id]是不是在里面
  4273. $query->Where(function ($q) use ($data) {
  4274. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4275. ->where('complaint.status', 2);
  4276. });
  4277. })
  4278. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4279. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4280. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4281. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4282. ->orderBy('updated_at', 'desc')
  4283. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4284. //sql输出
  4285. if (empty($result)) {
  4286. return Result::error("暂无投诉信息", 0);
  4287. }
  4288. // 取出数据
  4289. $rows = $result->items();
  4290. $count = $result->total();
  4291. $responseData = [
  4292. 'rows' => $rows,
  4293. 'count' => $count,
  4294. ];
  4295. return Result::success($responseData);
  4296. }
  4297. public function getComplaintList(array $data): array
  4298. {
  4299. var_dump($data, '00000001000000000000');
  4300. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4301. unset($data['type_id']);
  4302. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4303. $where = [];
  4304. if ($type_id != 10000 && empty($data['deal_user'])) {
  4305. $where['complaint.user_id'] = $user_id;
  4306. }
  4307. if (!empty($data['title'])) {
  4308. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4309. }
  4310. if (!empty($data['department_id'])) {
  4311. $where['complaint.department_id'] = $data['department_id'];
  4312. }
  4313. if (!empty($data['deal'])) {
  4314. $where['complaint.deal'] = $data['deal'];
  4315. }
  4316. if (!empty($data['status'])) {
  4317. $where['complaint.status'] = $data['status'];
  4318. }
  4319. var_dump(!empty($data['deal_user']), '----------1');
  4320. var_dump($where, '----------2');
  4321. $result = Complaint::where($where)
  4322. ->when(!empty($data['status1']), function ($query) use ($data) {
  4323. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4324. })
  4325. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4326. // //json re_user_ids data[user_id]是不是在里面
  4327. // $query->Where(function ($q) use ($data) {
  4328. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4329. // ->where('complaint.status', 2);
  4330. // });
  4331. // })
  4332. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4333. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4334. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4335. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4336. ->orderBy('updated_at', 'desc')
  4337. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4338. //sql输出
  4339. if (empty($result)) {
  4340. return Result::error("暂无投诉信息", 0);
  4341. }
  4342. // 取出数据
  4343. $rows = $result->items();
  4344. $count = $result->total();
  4345. $responseData = [
  4346. 'rows' => $rows,
  4347. 'count' => $count,
  4348. ];
  4349. return Result::success($responseData);
  4350. }
  4351. public function getComplaintInfo(array $data): array
  4352. {
  4353. $result = Complaint::where('id', $data['id'])->first();
  4354. if (empty($result)) {
  4355. return Result::error("查询失败", 0);
  4356. }
  4357. return Result::success($result);
  4358. }
  4359. public function readComplaint(array $data): array
  4360. {
  4361. $result = Complaint::where('id', $data['id'])->first();
  4362. if (empty($result)) {
  4363. return Result::error("查询失败", 0);
  4364. }
  4365. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4366. $re_user_ids = json_decode($result['re_user_ids'], true);
  4367. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4368. //如果已经存在,就不再添加
  4369. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4370. $read_id = json_decode($result['read_id'], true);
  4371. if (!is_array($read_id)) {
  4372. $read_id = [];
  4373. }
  4374. if (!in_array($data['user_id'], $read_id)) {
  4375. $read_id[] = $data['user_id'];
  4376. $result['read_id'] = json_encode($read_id);
  4377. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4378. }
  4379. } else {
  4380. //如果不存在,就添加
  4381. $result['read_id'] = json_encode([$data['user_id']]);
  4382. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4383. }
  4384. }
  4385. return Result::success($result);
  4386. }
  4387. public function addComplaint(array $data): array
  4388. {
  4389. date_default_timezone_set('Asia/Shanghai');
  4390. $data['created_at'] = date('Y-m-d H:i:s');
  4391. $data['updated_at'] = date('Y-m-d H:i:s');
  4392. $this->sendMessage([
  4393. 'talk_type' => 800,
  4394. 'title' => $data['title'],
  4395. 'content' => '提交了审核',
  4396. 'messageType' => 6,
  4397. ]);
  4398. $result = Complaint::create($data);
  4399. return Result::success($result);
  4400. }
  4401. public function updateComplaint(array $data): array
  4402. {
  4403. date_default_timezone_set('Asia/Shanghai');
  4404. $data['updated_at'] = date('Y-m-d H:i:s');
  4405. $user_id = $data['user_id'] ?? 0;
  4406. $type_id = $data['type_id'] ?? 0;
  4407. unset($data['user_id']);
  4408. unset($data['type_id']);
  4409. $this->sendMessage([
  4410. 'talk_type' => 800,
  4411. 'title' => $data['title'],
  4412. 'content' => '提交了审核',
  4413. 'messageType' => 6,
  4414. ]);
  4415. $result = Complaint::where('id', $data['id'])->update($data);
  4416. return Result::success($result);
  4417. }
  4418. public function deleteComplaint(array $data): array
  4419. {
  4420. $result = Complaint::where('id', $data['id'])->delete();
  4421. return Result::success($result);
  4422. }
  4423. public function getComplainInfo(array $data): array
  4424. {
  4425. $result = Complaint::where('id', $data['id'])->first();
  4426. if (empty($result)) {
  4427. return Result::error("查询失败", 0);
  4428. }
  4429. return Result::success($result);
  4430. }
  4431. public function updateComplaintStatus(array $data): array
  4432. {
  4433. date_default_timezone_set('Asia/Shanghai');
  4434. $data['updated_at'] = date('Y-m-d H:i:s');
  4435. $user_id = $data['user_id'] ?? 0;
  4436. $type_id = $data['type_id'] ?? 0;
  4437. unset($data['user_id']);
  4438. unset($data['type_id']);
  4439. //处理, 写入处理人
  4440. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4441. $data['real_deal_user'] = $user_id;
  4442. }
  4443. //如果是deal 23,则判断是不是处理人
  4444. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4445. $complaintInof = Complaint::where('id', $data['id'])
  4446. ->where('real_deal_user', $user_id)
  4447. ->first();
  4448. if (empty($complaintInof)) {
  4449. return Result::error("处理人错误", 0);
  4450. }
  4451. }
  4452. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4453. if ($data['status'] == 1) {
  4454. $this->sendMessage([
  4455. 'talk_type' => 800,
  4456. 'title' => $complaintInfo['title'],
  4457. 'content' => '提交了审核',
  4458. 'messageType' => 6,
  4459. ]);
  4460. }
  4461. if ($data['status'] == 2 && !isset($data['deal'])) {
  4462. $this->sendMessage([
  4463. 'talk_type' => 801,
  4464. 'title' => $complaintInfo['title'],
  4465. 'content' => '审核通过',
  4466. 'messageType' => 6,
  4467. 'user_id' => $complaintInfo['user_id'],
  4468. ]);
  4469. $this->sendMessage([
  4470. 'talk_type' => 802,
  4471. 'title' => $complaintInfo['title'],
  4472. 'content' => '待处理',
  4473. 'messageType' => 6,
  4474. 'user_id' => $complaintInfo['re_user_ids'],
  4475. ]);
  4476. }
  4477. if ($data['status'] == 3 && !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. }
  4486. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4487. $this->sendMessage([
  4488. 'talk_type' => 802,
  4489. 'title' => $complaintInfo['title'],
  4490. 'content' => '处理中',
  4491. 'messageType' => 6,
  4492. 'user_id' => $complaintInfo['re_user_ids'],
  4493. ]);
  4494. }
  4495. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4496. $this->sendMessage([
  4497. 'talk_type' => 802,
  4498. 'title' => $complaintInfo['title'],
  4499. 'content' => '不予处理',
  4500. 'messageType' => 6,
  4501. 'user_id' => $complaintInfo['re_user_ids'],
  4502. ]);
  4503. }
  4504. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4505. $this->sendMessage([
  4506. 'talk_type' => 802,
  4507. 'title' => $complaintInfo['title'],
  4508. 'content' => '已完结',
  4509. 'messageType' => 6,
  4510. 'user_id' => $complaintInfo['re_user_ids'],
  4511. ]);
  4512. }
  4513. $result = complaint::where('id', $data['id'])->update($data);
  4514. return Result::success($result);
  4515. }
  4516. public function updateGoodStatus(array $data): array
  4517. {
  4518. $user_id = $data['user_id'] ?? 0;
  4519. $type_id = $data['type_id'] ?? 0;
  4520. unset($data['user_id']);
  4521. unset($data['type_id']);
  4522. $goodInfo = Good::where('id', $data['id'])->first();
  4523. if ($data['status'] == 2) {
  4524. $this->sendMessage([
  4525. 'talk_type' => 201,
  4526. 'title' => $goodInfo['name'],
  4527. 'content' => '审核通过',
  4528. 'messageType' => 3,
  4529. 'user_id' => $goodInfo['user_id'],
  4530. ]);
  4531. }
  4532. if ($data['status'] == 3) {
  4533. $this->sendMessage([
  4534. 'talk_type' => 201,
  4535. 'title' => $goodInfo['name'],
  4536. 'content' => '审核拒绝',
  4537. 'messageType' => 3,
  4538. 'user_id' => $goodInfo['user_id'],
  4539. ]);
  4540. }
  4541. if ($data['status'] == 1) {
  4542. $this->sendMessage([
  4543. 'talk_type' => 200,
  4544. 'title' => $goodInfo['name'],
  4545. 'content' => '提交了审核',
  4546. 'messageType' => 3,
  4547. ]);
  4548. }
  4549. $result = Good::where('id', $data['id'])->update($data);
  4550. return Result::success($result);
  4551. }
  4552. public function updateJobHuntingStatus(array $data): array
  4553. {
  4554. $user_id = $data['user_id'] ?? 0;
  4555. $type_id = $data['type_id'] ?? 0;
  4556. unset($data['user_id']);
  4557. unset($data['type_id']);
  4558. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4559. if ($data['status'] == 2) {
  4560. $this->sendMessage([
  4561. 'talk_type' => 601,
  4562. 'title' => $jogHuntingInfo['name'],
  4563. 'content' => '审核通过',
  4564. 'messageType' => 11,
  4565. 'user_id' => $jogHuntingInfo['user_id'],
  4566. ]);
  4567. }
  4568. if ($data['status'] == 3) {
  4569. $this->sendMessage([
  4570. 'talk_type' => 601,
  4571. 'title' => $jogHuntingInfo['name'],
  4572. 'content' => '审核拒绝',
  4573. 'messageType' => 11,
  4574. 'user_id' => $jogHuntingInfo['user_id'],
  4575. ]);
  4576. }
  4577. if ($data['status'] == 1) {
  4578. $this->sendMessage([
  4579. 'talk_type' => 600,
  4580. 'title' => $jogHuntingInfo['name'],
  4581. 'content' => '提交了审核',
  4582. 'messageType' => 11,
  4583. ]);
  4584. }
  4585. $result = JobHunting::where('id', $data['id'])->update($data);
  4586. return Result::success($result);
  4587. }
  4588. public function updateNoticeStatus(array $data): array
  4589. {
  4590. $user_id = $data['user_id'] ?? 0;
  4591. $type_id = $data['type_id'] ?? 0;
  4592. unset($data['user_id']);
  4593. unset($data['type_id']);
  4594. //查询公告
  4595. $notice = Notice::where('id', $data['id'])->first();
  4596. if (empty($notice)) {
  4597. return Result::error("公告不存在", 0);
  4598. }
  4599. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4600. if ($data['status'] == 2 && $notice['is_group'] == 1 && $notice['status'] == 1 && empty($notice['group_id'])) {
  4601. //chat_group
  4602. $group_id = PublicData::uuid();
  4603. $groupData = [
  4604. 'id' => $group_id,
  4605. 'creator_id' => $notice['user_id'],
  4606. 'group_name' => $notice['group_name'] ?? '',
  4607. 'profile' => $notice['profile'] ?? 0,
  4608. ];
  4609. var_dump($groupData, '-----------------groupData-------');
  4610. $groupResult = ChatGroups::insertGetId($groupData);
  4611. var_dump($groupResult, '-----------------groupid-------');
  4612. $groupMemberData = [
  4613. 'id' => PublicData::uuid(),
  4614. 'user_id' => $notice['user_id'],
  4615. 'group_id' => $group_id,
  4616. 'leader' => 2,
  4617. ];
  4618. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4619. //$chat_ids 去除掉$data['user_id']
  4620. $chat_ids = json_decode($notice['re_user_ids'], true);
  4621. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4622. //插入群成员表
  4623. $groupMemberDataUser = [];
  4624. $chatData = [];
  4625. foreach ($chat_ids as $key => $value) {
  4626. $groupMemberDataUser[] = [
  4627. 'id' => PublicData::uuid(),
  4628. 'user_id' => $value,
  4629. 'group_id' => $group_id,
  4630. 'leader' => 1,
  4631. ];
  4632. $chatData[] = [
  4633. 'user_id' => $value,
  4634. 'msg_type' => 1,
  4635. 'receiver_id' => $group_id,
  4636. 'content' => '通过通知创建群聊',
  4637. 'group_receiver_id' => $notice['user_id'],
  4638. 'action' => 'recieved',
  4639. 'created_at' => date('Y-m-d H:i:s'),
  4640. ];
  4641. }
  4642. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4643. ChatGroupsMember::insert($groupMemberDataUser);
  4644. //插入一条管理员聊天记录
  4645. $chatData[] = [
  4646. 'user_id' => $notice['user_id'],
  4647. 'msg_type' => 1,
  4648. 'receiver_id' => $group_id,
  4649. 'content' => '通过通知创建群聊',
  4650. 'group_receiver_id' => $notice['user_id'],
  4651. 'action' => 'said',
  4652. 'created_at' => date('Y-m-d H:i:s'),
  4653. ];
  4654. var_dump($chatData, '-----------------chatData-------');
  4655. $chatResult = ChatRecords::insert($chatData);
  4656. //更新result的 group_id
  4657. $data['group_id'] = $group_id;
  4658. Notice::where(['id' => $data['id']])->update($data);
  4659. }
  4660. $result = Notice::where('id', $data['id'])->update($data);
  4661. $noticeInfo = Notice::where('id', $data['id'])->first();
  4662. if ($data['status'] == 2) {
  4663. $this->sendMessage([
  4664. 'talk_type' => 701,
  4665. 'title' => $noticeInfo['title'],
  4666. 'content' => '审核通过',
  4667. 'messageType' => 3,
  4668. 'user_id' => $noticeInfo['user_id'],
  4669. ]);
  4670. }
  4671. if ($data['status'] == 3) {
  4672. $this->sendMessage([
  4673. 'talk_type' => 701,
  4674. 'title' => $noticeInfo['title'],
  4675. 'content' => '审核拒绝',
  4676. 'messageType' => 3,
  4677. 'user_id' => $noticeInfo['user_id'],
  4678. ]);
  4679. }
  4680. if ($data['status'] == 1) {
  4681. $this->sendMessage([
  4682. 'talk_type' => 700,
  4683. 'title' => $noticeInfo['title'],
  4684. 'content' => '提交了审核',
  4685. 'messageType' => 3,
  4686. ]);
  4687. }
  4688. return Result::success($result);
  4689. }
  4690. public function getDUser(array $data): array
  4691. {
  4692. if (!empty($data['ids'])) {
  4693. $user = User::whereIn('id', $data['ids'])->getall();
  4694. if (empty($user)) {
  4695. return Result::error('无数据', 0);
  4696. }
  4697. return Result::success($user);
  4698. }
  4699. $where = [];
  4700. if (!empty($data['department_id'])) {
  4701. $where['department_id'] = $data['department_id'];
  4702. }
  4703. if (!empty($data['city_id'])) {
  4704. $where['city_id'] = $data['city_id'];
  4705. }
  4706. $result = User::where('type_id', 2)
  4707. ->where('status', 1)
  4708. ->where($where)
  4709. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4710. ->get();
  4711. if (empty($result)) {
  4712. return Result::error("查询失败", 0);
  4713. }
  4714. return Result::success($result);
  4715. }
  4716. /**
  4717. * 验证导航名称是否重复
  4718. * @return void
  4719. */
  4720. public function checkCategoryName(array $data): array
  4721. {
  4722. $result = Category::when($data, function ($query) use ($data) {
  4723. if (isset($data['name']) && $data['name']) {
  4724. $query->where("name", $data['name']);
  4725. }
  4726. if (isset($data['id']) && $data['id']) {
  4727. $query->where("id", "!=", $data['id']);
  4728. }
  4729. })->first();
  4730. if ($result) {
  4731. return Result::error("已存在");
  4732. } else {
  4733. return Result::success();
  4734. }
  4735. }
  4736. //20250226 产品列表
  4737. // 20250306 -------招聘--------fr
  4738. /*
  4739. * 招聘列表
  4740. * */
  4741. public function getJobRecruitingList(array $data): array
  4742. {
  4743. $where = [];
  4744. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4745. if ($data['checkout'] == 0) {
  4746. $job_status = [0, 2];
  4747. } else {
  4748. $job_status = [1];
  4749. }
  4750. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4751. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4752. }
  4753. $user = User::where('id', $data['user_id'])->first();
  4754. if (empty($user)) {
  4755. return Result::error("用户不存在", 0);
  4756. }
  4757. // 3:企业会员
  4758. if ($user['type_id'] == 3) {
  4759. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4760. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4761. }
  4762. // 如果 $where 为空,则不添加 where 条件
  4763. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4764. return $query->where($where);
  4765. })
  4766. ->whereIn('job_recruiting.status', $job_status)
  4767. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4768. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4769. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4770. ->orderBy("updated_at", "desc")
  4771. ->offset(($data['page'] - 1) * $data['page_size'])
  4772. ->limit($data['page_size'])
  4773. ->get()
  4774. ->all();
  4775. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4776. return $query->where($where);
  4777. })
  4778. ->whereIn('job_recruiting.status', $job_status)
  4779. ->count();
  4780. if (empty($result)) {
  4781. return Result::error("暂无招聘信息", 0);
  4782. }
  4783. return Result::success($result);
  4784. }
  4785. /*
  4786. * 招聘信息添加
  4787. * */
  4788. public function addJobRecruiting(array $data): array
  4789. {
  4790. // var_dump('添加招聘进入news------data',$data);
  4791. // return Result::success($data);
  4792. $user = User::where('user.id', $data['user_id'])
  4793. ->where('user.status', 1)
  4794. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4795. ->select(
  4796. 'user.type_id',
  4797. 'user.mobile',
  4798. 'user.email',
  4799. 'user_info.business_name',
  4800. 'user_info.company_hy_id',
  4801. 'user_info.company_nature',
  4802. 'user_info.company_size',
  4803. 'user_info.introduction',
  4804. 'user_info.real_name',
  4805. 'user_info.company_url',
  4806. 'user_info.address_arr_id',
  4807. 'user_info.address'
  4808. )
  4809. ->first();
  4810. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4811. return Result::error("用户不存在", 0);
  4812. }
  4813. $web = Website::where('id', $data['website_id'])->first();
  4814. if (empty($web)) {
  4815. return Result::error("网站不存在", 0);
  4816. }
  4817. // var_dump('添加招聘进入news---user---user',$user);
  4818. // return Result::success($user);
  4819. $data['action_id'] = $data['user_id'] ?? null;
  4820. $data['user_type'] = $user['type_id'] ?? null;
  4821. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  4822. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  4823. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  4824. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  4825. // 公司地址 管理员必填
  4826. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  4827. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  4828. // 管理员-企业相关信息
  4829. $company = [
  4830. // 'user_id' => $data['user_id']?? null,
  4831. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  4832. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  4833. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  4834. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  4835. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  4836. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  4837. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  4838. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  4839. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  4840. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  4841. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  4842. ];
  4843. //去掉相关企业信息
  4844. $job = array_diff_key($data, array_flip(array_keys($company)));
  4845. // var_dump('添加招聘进入news---job---user',$job);
  4846. Db::beginTransaction();
  4847. try {
  4848. // // 先添加职位相关信息
  4849. if ($user['type_id'] == 10000) {
  4850. $job['status'] = 1;
  4851. }
  4852. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  4853. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  4854. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  4855. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  4856. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  4857. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  4858. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  4859. // return Result::success($job);
  4860. $jobId = JobRecruiting::insertGetId($job);
  4861. if (empty($jobId)) {
  4862. Db::rollBack();
  4863. return Result::error("添加失败");
  4864. }
  4865. // 添加公司信息
  4866. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  4867. $company['job_id'] = $jobId;
  4868. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  4869. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  4870. if ($user['type_id'] == 10000) {
  4871. // 管理员添加企业信息
  4872. $companyId = JobCompany::insertGetId($company);
  4873. if (empty($companyId)) {
  4874. Db::rollBack();
  4875. return Result::error("添加失败");
  4876. }
  4877. } else {
  4878. // 企业会员添加企业信息
  4879. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  4880. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  4881. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  4882. $company['job_id'] = $jobId;
  4883. $companyId = JobCompany::insertGetId($company);
  4884. if (empty($companyId)) {
  4885. Db::rollBack();
  4886. return Result::error("添加失败");
  4887. }
  4888. }
  4889. Db::commit();
  4890. $result = [
  4891. 'job_id' => $jobId,
  4892. 'company_id' => $companyId,
  4893. ];
  4894. return Result::success($result);
  4895. } catch (\Exception $e) {
  4896. Db::rollBack();
  4897. return Result::error($e->getMessage(), 0);
  4898. }
  4899. // return Result::success($result);
  4900. }
  4901. /*
  4902. * 获取招聘信息详情
  4903. * */
  4904. public function getJobRecruitingInfo(array $data): array
  4905. {
  4906. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4907. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4908. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4909. ->select(
  4910. 'job_recruiting.*',
  4911. 'website.website_name as website_name',
  4912. 'job_company.business_name',
  4913. 'job_company.company_hy_id',
  4914. 'job_company.company_size',
  4915. 'job_company.company_nature',
  4916. 'job_company.introduction',
  4917. 'job_company.real_name',
  4918. 'job_company.mobile',
  4919. 'job_company.company_url',
  4920. 'job_company.address_arr_id',
  4921. 'job_company.address',
  4922. 'job_company.email'
  4923. )
  4924. ->first();
  4925. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4926. if (!empty($cityId)) {
  4927. if (isset($cityId[1]) && $cityId[1] != null) {
  4928. $city = District::where('id', $cityId[1])->first(['name']);
  4929. } else {
  4930. $city = District::where('id', $cityId[0])->first(['name']);
  4931. }
  4932. $result['city'] = $city['name'] ?? '';
  4933. }
  4934. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4935. if (is_array($addressId) && !empty($addressId)) {
  4936. $address = District::whereIn('id', $addressId)
  4937. ->orderBy('level', 'asc')
  4938. ->get(['name'])
  4939. ->pluck('name')
  4940. ->implode('');
  4941. // $job->address_name = $address ?? '';
  4942. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4943. }
  4944. if (empty($result)) {
  4945. return Result::error("招聘信息不存在", 0);
  4946. }
  4947. // return Result::success($job);
  4948. return Result::success($result);
  4949. }
  4950. /*
  4951. * 修改招聘信息
  4952. * */
  4953. public function upJobRecruiting(array $data): array
  4954. {
  4955. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4956. // return Result::success($job);
  4957. if (empty($job)) {
  4958. return Result::error("招聘信息不存在", 0);
  4959. }
  4960. $user = User::where('id', $data['user_id'])->first();
  4961. // return Result::success($user);
  4962. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4963. return Result::error("用户不存在", 0);
  4964. }
  4965. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4966. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4967. }
  4968. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4969. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4970. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4971. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4972. // 公司地址 管理员必填
  4973. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4974. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4975. // 管理员-企业相关信息
  4976. $company = [
  4977. // 'user_id' => $data['user_id']?? null,
  4978. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  4979. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  4980. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  4981. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  4982. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  4983. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  4984. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  4985. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  4986. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  4987. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  4988. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  4989. ];
  4990. //去掉相关企业信息
  4991. $data = array_diff_key($data, array_flip(array_keys($company)));
  4992. $jobId = $data['id'];
  4993. $web = $data['website_id'];
  4994. $data['action_id'] = $data['user_id'];
  4995. unset($data['user_id']);
  4996. unset($data['user_type']);
  4997. unset($data['id']);
  4998. unset($data['website_id']);
  4999. // return Result::success($data);
  5000. Db::beginTransaction();
  5001. try {
  5002. // 管理员修改招聘信息
  5003. if ($user['type_id'] == 10000) {
  5004. $data['website_id'] = $web;
  5005. $company['website_id'] = $data['website_id'];
  5006. $data['status'] = 1;
  5007. } else {
  5008. $data['status'] = 0;
  5009. }
  5010. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5011. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5012. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5013. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5014. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5015. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5016. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5017. // return Result::success($job);
  5018. // Db::rollBack();
  5019. // return Result::success($company);
  5020. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5021. $this->sendMessage([
  5022. 'talk_type' => 500,
  5023. 'title' => $data['title'],
  5024. 'content' => '提交了审核',
  5025. 'messageType' => 10,
  5026. ]);
  5027. }
  5028. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5029. if (empty($result['job'])) {
  5030. Db::rollBack();
  5031. return Result::error("修改招聘信息失败");
  5032. }
  5033. // 管理员修改企业相关信息
  5034. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5035. if (empty($result['company'])) {
  5036. Db::rollBack();
  5037. return Result::error("修改企业相关信息失败");
  5038. }
  5039. Db::commit();
  5040. // return Result::success($result);
  5041. } catch (\Exception $e) {
  5042. Db::rollBack();
  5043. return Result::error($e->getMessage(), 0);
  5044. }
  5045. return Result::success($result);
  5046. }
  5047. /*
  5048. * 招聘信息删除
  5049. * */
  5050. public function delJobRecruiting(array $data): array
  5051. {
  5052. $user = User::where('id', $data['user_id'])->first();
  5053. if (empty($user)) {
  5054. return Result::error("用户不存在", 0);
  5055. }
  5056. $job = JobRecruiting::where('id', $data['id'])->first();
  5057. if (empty($job)) {
  5058. return Result::error("招聘信息不存在", 0);
  5059. }
  5060. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5061. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5062. }
  5063. Db::beginTransaction();
  5064. try {
  5065. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5066. if (empty($result['job'])) {
  5067. Db::rollBack();
  5068. return Result::error("删除招聘信息失败");
  5069. }
  5070. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5071. if (empty($result['company'])) {
  5072. Db::rollBack();
  5073. return Result::error("删除企业相关信息失败");
  5074. }
  5075. Db::commit();
  5076. } catch (\Exception $e) {
  5077. Db::rollBack();
  5078. return Result::error($e->getMessage(), 0);
  5079. }
  5080. return Result::success($result);
  5081. }
  5082. /*
  5083. * 获取公司信息
  5084. * */
  5085. public function getJobCompany(array $data): array
  5086. {
  5087. $user = User::where('user.id', $data['user_id'])
  5088. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5089. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5090. ->first();
  5091. // return Result::success($user);
  5092. if (empty($user)) {
  5093. return Result::error("用户不存在", 0);
  5094. }
  5095. if ($user['type_id'] == 3) {
  5096. $result = [
  5097. // 'id' => 0,
  5098. 'user_id' => $data['user_id'],
  5099. 'website_id' => $data['website_id'],
  5100. 'business_name' => $user['business_name'], // 企业名称
  5101. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5102. 'company_nature' => $user['company_nature'], // 公司性质
  5103. 'company_size' => $user['company_size'], // 公司规模
  5104. 'introduction' => $user['introduction'], // 公司简介
  5105. 'real_name' => $user['real_name'], // 企业联系人
  5106. 'mobile' => $user['mobile'], // 企业联系电话
  5107. 'company_url' => $user['company_url'], // 企业网址
  5108. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5109. 'address' => $user['address'], // 企业地址
  5110. 'email' => $user['email'], // 企业邮箱
  5111. ];
  5112. } else {
  5113. return Result::error("用户类型错误", 0);
  5114. }
  5115. if (empty($result)) {
  5116. return Result::error("公司信息不存在", 0);
  5117. }
  5118. return Result::success($result);
  5119. }
  5120. /*
  5121. * 修改公司信息
  5122. * */
  5123. public function upJobCompany(array $data): array
  5124. {
  5125. // return Result::success($data);
  5126. $user = User::where('user.id', $data['user_id'])
  5127. ->where('user.status', 1)
  5128. ->select('user.user_name', 'user.type_id')
  5129. ->first();
  5130. if (empty($user)) {
  5131. return Result::error("用户不存在", 0);
  5132. }
  5133. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5134. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5135. $company = [
  5136. 'business_name' => $data['business_name'], // 企业名称
  5137. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5138. 'company_nature' => $data['company_nature'], // 公司性质
  5139. 'company_size' => $data['company_size'], // 公司规模
  5140. 'introduction' => $data['introduction'], // 公司简介
  5141. // 'real_name' => $data['real_name'], // 企业联系人
  5142. 'company_url' => $data['company_url'], // 企业网址
  5143. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5144. 'address' => $data['address'], // 企业详细地址
  5145. // 'email' => $data['email'], // 企业邮箱
  5146. ];
  5147. if ($user['type_id'] == 3) {
  5148. Db::beginTransaction();
  5149. try {
  5150. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5151. 'business_name' => $data['business_name'], // 企业名称
  5152. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5153. 'company_nature' => $data['company_nature'], // 公司性质
  5154. 'company_size' => $data['company_size'], // 公司规模
  5155. 'introduction' => $data['introduction'], // 公司简介
  5156. // 'real_name' => $data['real_name'], // 企业联系人
  5157. 'company_url' => $data['company_url'], // 企业网址
  5158. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5159. 'address' => $data['address'], // 企业详细地址
  5160. ]);
  5161. if (empty($result['userinfo'])) {
  5162. Db::rollBack();
  5163. return Result::error('修改企业会员信息失败!');
  5164. }
  5165. $result['user'] = User::where('id', $data['user_id'])->update([
  5166. 'email' => $data['email'], // 企业邮箱
  5167. ]);
  5168. if (empty($result['user'])) {
  5169. Db::rollBack();
  5170. return Result::error('修改个人中心信息失败!');
  5171. }
  5172. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5173. if (!empty($job_company)) {
  5174. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5175. if (empty($result['job_company'])) {
  5176. Db::rollBack();
  5177. return Result::error('修改企业会员信息失败!');
  5178. }
  5179. }
  5180. Db::commit();
  5181. return Result::success($result);
  5182. } catch (\Exception $e) {
  5183. Db::rollBack();
  5184. return Result::error($e->getMessage(), 0);
  5185. }
  5186. } else {
  5187. return Result::error("用户类型错误", 0);
  5188. }
  5189. }
  5190. /*
  5191. * 获取省-市
  5192. * */
  5193. public function getJobRecruitingArea(array $data): array
  5194. {
  5195. if (isset($data['pid']) && $data['pid'] != null) {
  5196. $result = District::where('pid', $data['pid'])->get()->all();
  5197. } else {
  5198. $result = District::where('level', 1)->get()->all();
  5199. }
  5200. if (empty($result)) {
  5201. return Result::error("暂无此省市", 0);
  5202. }
  5203. return Result::success($result);
  5204. }
  5205. /*
  5206. * 获取行业分类
  5207. * */
  5208. public function getIndustry(array $data): array
  5209. {
  5210. $result = JobIndustry::get()->all();
  5211. if (empty($result)) {
  5212. return Result::error("暂无行业分类", 0);
  5213. }
  5214. return Result::success($result);
  5215. }
  5216. /*
  5217. * 获取职位
  5218. * */
  5219. public function getPositionList(array $data): array
  5220. {
  5221. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5222. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5223. } else {
  5224. $result = JobPosition::where('zwpid', 0)->get()->all();
  5225. }
  5226. if (empty($result)) {
  5227. return Result::error("暂无此职位", 0);
  5228. }
  5229. return Result::success($result);
  5230. }
  5231. /*
  5232. * 获取工作性质-菜单
  5233. * */
  5234. public function getJobNature(array $data): array
  5235. {
  5236. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5237. if (empty($result)) {
  5238. return Result::error("暂无工作性质", 0);
  5239. }
  5240. return Result::success($result);
  5241. }
  5242. /*
  5243. * 获取工作经验-菜单
  5244. * */
  5245. public function getExperience(array $data): array
  5246. {
  5247. $result = JobEnum::where('egroup', 'years')->get()->all();
  5248. if (empty($result)) {
  5249. return Result::error("暂无工作经验", 0);
  5250. }
  5251. return Result::success($result);
  5252. }
  5253. /*
  5254. * 获取学历-菜单
  5255. * */
  5256. public function getEducation(array $data): array
  5257. {
  5258. $result = JobEnum::where('egroup', 'education')->get()->all();
  5259. if (empty($result)) {
  5260. return Result::error("暂无学历", 0);
  5261. }
  5262. return Result::success($result);
  5263. }
  5264. /*
  5265. * 获取薪资-菜单
  5266. * */
  5267. public function getSalary(array $data): array
  5268. {
  5269. $result = JobEnum::where('egroup', 'income')->get()->all();
  5270. if (empty($result)) {
  5271. return Result::error("暂无薪资", 0);
  5272. }
  5273. return Result::success($result);
  5274. }
  5275. /*
  5276. * 获取语言-菜单
  5277. * */
  5278. public function getLanguage(array $data): array
  5279. {
  5280. $result = JobEnum::where('egroup', 'language')->get()->all();
  5281. if (empty($result)) {
  5282. return Result::error("暂无语言", 0);
  5283. }
  5284. return Result::success($result);
  5285. }
  5286. /*
  5287. * 获取掌握程度-菜单
  5288. * */
  5289. public function getLevel(array $data): array
  5290. {
  5291. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5292. if (empty($result)) {
  5293. return Result::error("暂无工作性质", 0);
  5294. }
  5295. return Result::success($result);
  5296. }
  5297. // 公司信息
  5298. /*
  5299. * 获取公司性质-菜单
  5300. * */
  5301. public function getCompanyNature(array $data): array
  5302. {
  5303. $result = JobNature::get()->all();
  5304. if (empty($result)) {
  5305. return Result::error("暂无公司性质", 0);
  5306. }
  5307. return Result::success($result);
  5308. }
  5309. /*
  5310. * 获取公司规模-菜单
  5311. * */
  5312. public function getCompanySize(array $data): array
  5313. {
  5314. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5315. if (empty($result)) {
  5316. return Result::error("暂无公司规模", 0);
  5317. }
  5318. return Result::success($result);
  5319. }
  5320. /*
  5321. * 招聘信息审核
  5322. * */
  5323. public function checkJobRecruiting(array $data): array
  5324. {
  5325. $user = User::where('id', $data['user_id'])->first();
  5326. if (empty($user)) {
  5327. return Result::error("用户不存在", 0);
  5328. }
  5329. $job = JobRecruiting::where('id', $data['id'])->first();
  5330. if (empty($job)) {
  5331. return Result::error("招聘信息不存在", 0);
  5332. }
  5333. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5334. if ($user['type_id'] != 10000) {
  5335. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5336. }
  5337. // 驳回原因
  5338. if ($data['status'] == 2) {
  5339. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5340. }
  5341. $data['action_id'] = $data['user_id'];
  5342. unset($data['user_id']);
  5343. if ($data['status'] == 1) {
  5344. $this->sendMessage([
  5345. 'talk_type' => 501,
  5346. 'title' => $job['title'],
  5347. 'content' => '审核通过',
  5348. 'messageType' => 10,
  5349. 'user_id' => $job['user_id'],
  5350. ]);
  5351. }
  5352. if ($data['status'] == 2) {
  5353. $this->sendMessage([
  5354. 'talk_type' => 501,
  5355. 'title' => $job['title'],
  5356. 'content' => '审核拒绝',
  5357. 'messageType' => 10,
  5358. 'user_id' => $job['user_id'],
  5359. ]);
  5360. }
  5361. if ($data['status'] == 0) {
  5362. $this->sendMessage([
  5363. 'talk_type' => 500,
  5364. 'title' => $job['title'],
  5365. 'content' => '提交了审核',
  5366. 'messageType' => 10,
  5367. ]);
  5368. }
  5369. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5370. if (empty($result)) {
  5371. return Result::error("审核失败", 0);
  5372. }
  5373. return Result::success($result);
  5374. }
  5375. public function myApplyList(array $data): array
  5376. {
  5377. var_dump($data, '------参数');
  5378. $user = User::where('id', $data['user_id'])->first();
  5379. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5380. return Result::error("用户不存在", 0);
  5381. }
  5382. // 1:个人会员 职场机会
  5383. if ($user['type_id'] == 1) {
  5384. $where['user_id'] = $user['id'];
  5385. }
  5386. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5387. $query->where('user_id', $user['id']);
  5388. })
  5389. ->pluck('recruit_id');
  5390. $where = [];
  5391. if (isset($data['salary']) && $data['salary'] != null) {
  5392. $where['job_recruiting.salary'] = $data['salary'];
  5393. }
  5394. if (isset($data['experience']) && $data['experience'] != null) {
  5395. $where['job_recruiting.experience'] = $data['experience'];
  5396. }
  5397. if (isset($data['business_name']) && $data['business_name'] != null) {
  5398. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5399. }
  5400. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5401. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5402. ->where($where);
  5403. // ->count();
  5404. $count = $query->count();
  5405. $query = clone $query;
  5406. $job = $query
  5407. ->leftJoin('job_enum as income_enum', function ($join) {
  5408. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5409. ->where('income_enum.egroup', 'income');
  5410. })
  5411. ->leftJoin('job_enum as years_enum', function ($join) {
  5412. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5413. ->where('years_enum.egroup', 'years');
  5414. })
  5415. // ->where($where)
  5416. ->orderBy('job_recruiting.updated_at', 'desc')
  5417. ->select(
  5418. 'job_recruiting.id',
  5419. 'job_recruiting.title',
  5420. 'job_company.business_name',
  5421. 'income_enum.evalue as salary_evalue',
  5422. 'income_enum.ename as salary_ename',
  5423. 'years_enum.evalue as experience_evalue',
  5424. 'years_enum.ename as experience_ename',
  5425. 'job_recruiting.updated_at'
  5426. )
  5427. ->offset(($data['page'] - 1) * $data['pageSize'])
  5428. ->limit($data['pageSize'])
  5429. ->get()
  5430. ->all();
  5431. if (empty($job)) {
  5432. return Result::error("暂无招聘信息", 0);
  5433. }
  5434. $result = [
  5435. 'row' => $job,
  5436. 'count' => $count,
  5437. ];
  5438. return Result::success($result);
  5439. }
  5440. public function readJobApply(array $data): array
  5441. {
  5442. $result = JobApply::where('id', $data['id'])->first();
  5443. if (empty($result)) {
  5444. return Result::error("查询失败", 0);
  5445. }
  5446. $result = JobApply::where('id', $data['id'])->update([
  5447. 'status' => 2,
  5448. ]);
  5449. return Result::success($result);
  5450. }
  5451. /*
  5452. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5453. * */
  5454. public function getRecruitingList(array $data): array
  5455. {
  5456. $user = User::where('id', $data['user_id'])->first();
  5457. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5458. return Result::error("用户不存在", 0);
  5459. }
  5460. // 1:个人会员 职场机会
  5461. if ($user['type_id'] == 1) {
  5462. $where['user_id'] = $user['id'];
  5463. }
  5464. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5465. $query->where('receiver_id', $user['id']);
  5466. })
  5467. ->pluck('recruit_id');
  5468. // return Result::success($recruitingId);
  5469. $where = [];
  5470. if (isset($data['salary']) && $data['salary'] != null) {
  5471. $where['job_recruiting.salary'] = $data['salary'];
  5472. }
  5473. if (isset($data['experience']) && $data['experience'] != null) {
  5474. $where['job_recruiting.experience'] = $data['experience'];
  5475. }
  5476. if (isset($data['business_name']) && $data['business_name'] != null) {
  5477. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5478. }
  5479. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5480. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5481. ->where($where);
  5482. // ->count();
  5483. $count = $query->count();
  5484. $query = clone $query;
  5485. $job = $query
  5486. ->leftJoin('job_enum as income_enum', function ($join) {
  5487. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5488. ->where('income_enum.egroup', 'income');
  5489. })
  5490. ->leftJoin('job_enum as years_enum', function ($join) {
  5491. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5492. ->where('years_enum.egroup', 'years');
  5493. })
  5494. // ->where($where)
  5495. ->orderBy('job_recruiting.updated_at', 'desc')
  5496. ->select(
  5497. 'job_recruiting.id',
  5498. 'job_recruiting.title',
  5499. 'job_company.business_name',
  5500. 'income_enum.evalue as salary_evalue',
  5501. 'income_enum.ename as salary_ename',
  5502. 'years_enum.evalue as experience_evalue',
  5503. 'years_enum.ename as experience_ename',
  5504. 'job_recruiting.updated_at'
  5505. )
  5506. ->offset(($data['page'] - 1) * $data['pageSize'])
  5507. ->limit($data['pageSize'])
  5508. ->get()
  5509. ->all();
  5510. if (empty($job)) {
  5511. return Result::error("暂无招聘信息", 0);
  5512. }
  5513. $result = [
  5514. 'row' => $job,
  5515. 'count' => $count,
  5516. ];
  5517. return Result::success($result);
  5518. }
  5519. /*
  5520. * 获取企业会员-招聘信息列表
  5521. * */
  5522. public function getRecruitingInfo(array $data): array
  5523. {
  5524. $user = User::where('id', $data['user_id'])->first();
  5525. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5526. return Result::error("用户不存在", 0);
  5527. }
  5528. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5529. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5530. ->select(
  5531. 'job_recruiting.*',
  5532. 'job_company.business_name',
  5533. 'job_company.company_hy_id',
  5534. 'job_company.company_size',
  5535. 'job_company.company_nature',
  5536. 'job_company.introduction',
  5537. 'job_company.real_name',
  5538. 'job_company.mobile',
  5539. 'job_company.company_url',
  5540. 'job_company.address_arr_id',
  5541. 'job_company.address',
  5542. 'job_company.email'
  5543. )
  5544. ->get();
  5545. if (empty($recruiting)) {
  5546. return Result::error("暂无招聘信息", 0);
  5547. }
  5548. return Result::success($recruiting);
  5549. }
  5550. /*
  5551. * 获取企业会员-我的沟通
  5552. * */
  5553. public function getJobResumeList(array $data): array
  5554. {
  5555. $user = User::where('id', $data['user_id'])->first();
  5556. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5557. return Result::error("用户不存在", 0);
  5558. }
  5559. $where = [];
  5560. if (isset($data['salary']) && $data['salary'] != null) {
  5561. $where['job_hunting.salary'] = $data['salary'];
  5562. }
  5563. if (isset($data['user_name']) && $data['user_name'] != null) {
  5564. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5565. }
  5566. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5567. $query->where('job_resume.user_id', $user['id']);
  5568. })
  5569. ->when(!empty($where), function ($query) use ($where) {
  5570. $query->where($where);
  5571. })
  5572. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5573. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5574. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5575. ->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');
  5576. $count = $job->count();
  5577. if ($count == 0) {
  5578. return Result::error("暂无沟通记录", 0);
  5579. }
  5580. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5581. ->offset(($data['page'] - 1) * $data['pageSize'])
  5582. ->limit($data['pageSize'])
  5583. ->get();
  5584. if (empty($jobs)) {
  5585. return Result::error("暂无沟通记录", 0);
  5586. }
  5587. $result['row'] = $this->processJob($jobs, '');
  5588. $result['count'] = $count;
  5589. return Result::success($result);
  5590. }
  5591. public function readJobResume(array $data): array
  5592. {
  5593. $result = JobResume::where('id', $data['id'])->first();
  5594. if (empty($result)) {
  5595. return Result::error("查询失败", 0);
  5596. }
  5597. $result = JobResume::where('id', $data['id'])->update([
  5598. 'status' => 2,
  5599. ]);
  5600. return Result::success($result);
  5601. }
  5602. // 20250306 招聘
  5603. //20250422 书刊音像
  5604. public function addBook(array $data): array
  5605. {
  5606. $user_id = $data['user_id'] ?? 0;
  5607. $type_id = $data['type_id'] ?? 0;
  5608. // $website_id = $data['website_id'] ?? 0;
  5609. // unset($data['user_id']);
  5610. unset($data['type_id']);
  5611. // unset($data['website_id']);
  5612. //处理数组
  5613. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5614. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5615. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5616. if ($data['img_url'] == '') {
  5617. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5618. preg_match_all($reg, $data['detail'], $matches);
  5619. if (isset($matches[1][0])) {
  5620. //截取varchar240
  5621. $data['img_url'] = substr($matches[1][0], 0, 240);
  5622. }
  5623. }
  5624. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5625. //提取标题+内容中的关键词
  5626. $data['keyword'] = $data['title'];
  5627. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5628. Jieba::init(); // 初始化 jieba-php
  5629. Finalseg::init();
  5630. $segList = Jieba::cut($data['keyword']);
  5631. $segList1 = array_slice($segList, 0, 8);
  5632. $data['keyword'] = implode(',', $segList1);
  5633. }
  5634. if ($data['description'] == '') {
  5635. //提取内容中的描述
  5636. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5637. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5638. }
  5639. var_dump($data, '--');
  5640. if ($data['status'] == 1) {
  5641. $this->sendMessage([
  5642. 'talk_type' => 400,
  5643. 'title' => $data['title'],
  5644. 'content' => '提交了审核',
  5645. 'messageType' => 7,
  5646. ]);
  5647. }
  5648. $result = Book::insertGetId($data);
  5649. if (empty($result)) {
  5650. return Result::error("添加失败", 0);
  5651. }
  5652. return Result::success($result);
  5653. }
  5654. public function getBookList(array $data): array
  5655. {
  5656. $where = [];
  5657. if (!empty($data["title"])) {
  5658. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5659. }
  5660. if (!empty($data['website_name'])) {
  5661. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5662. }
  5663. if (!empty($data['status'])) {
  5664. $where[] = ['book.status', '=', $data['status']];
  5665. }
  5666. $user_id = $data['user_id'];
  5667. $type_id = $data['type_id'];
  5668. // $type_id = 4;
  5669. var_dump($type_id, '------1--------');
  5670. if ($type_id != 10000) {
  5671. $where[] = ['book.user_id', '=', $user_id];
  5672. }
  5673. var_dump(!empty($data['status1']), '=-===1');
  5674. $result = Book::where($where)
  5675. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5676. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5677. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5678. ->when(isset($data['status1']), function ($query) use ($data) {
  5679. $query->whereIn('book.status', [1, 3]);
  5680. })
  5681. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5682. ->orderBy("updated_at", "desc")
  5683. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5684. if (empty($result)) {
  5685. return Result::error("暂无数据", 0);
  5686. }
  5687. // 取出数据
  5688. $rows = $result->items();
  5689. $count = $result->total();
  5690. $responseData = [
  5691. 'rows' => $rows,
  5692. 'count' => $count,
  5693. ];
  5694. return Result::success($responseData);
  5695. }
  5696. public function deleteBook(array $data): array
  5697. {
  5698. $result = Book::where('id', $data['id'])->delete();
  5699. if (empty($result)) {
  5700. return Result::error("删除失败", 0);
  5701. }
  5702. return Result::success($result);
  5703. }
  5704. public function updateBook(array $data): array
  5705. {
  5706. // $user_id = $data['user_id'] ?? 0;
  5707. $type_id = $data['type_id'] ?? 0;
  5708. // $website_id = $data['website_id'] ?? 0;
  5709. unset($data['user_id']);
  5710. unset($data['type_id']);
  5711. // unset($data['website_id']);
  5712. //处理数组
  5713. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5714. if ($data['img_url'] == '') {
  5715. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5716. preg_match_all($reg, $data['detail'], $matches);
  5717. if (isset($matches[1][0])) {
  5718. //截取varchar240
  5719. $data['img_url'] = substr($matches[1][0], 0, 240);
  5720. }
  5721. }
  5722. if ($data['keyword'] == '') {
  5723. //提取标题+内容中的关键词
  5724. $data['keyword'] = $data['title'];
  5725. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5726. Jieba::init(); // 初始化 jieba-php
  5727. Finalseg::init();
  5728. $segList = Jieba::cut($data['keyword']);
  5729. $segList1 = array_slice($segList, 0, 8);
  5730. $data['keyword'] = implode(',', $segList1);
  5731. }
  5732. if ($data['description'] == '') {
  5733. //提取内容中的描述
  5734. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5735. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5736. }
  5737. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5738. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5739. if ($data['status'] == 1) {
  5740. $this->sendMessage([
  5741. 'talk_type' => 400,
  5742. 'title' => $data['title'],
  5743. 'content' => '提交了审核',
  5744. 'messageType' => 7,
  5745. ]);
  5746. }
  5747. $result = Book::where("id", $data["id"])->update($data);
  5748. if (empty($result)) {
  5749. return Result::error("更新失败", 0);
  5750. }
  5751. return Result::success($result);
  5752. }
  5753. public function getBookInfo(array $data): array
  5754. {
  5755. $result = Book::where("id", $data["id"])->first();
  5756. if (empty($result)) {
  5757. return Result::error("获取失败", 0);
  5758. }
  5759. return Result::success($result);
  5760. }
  5761. public function updateBookStatus(array $data): array
  5762. {
  5763. //审核
  5764. unset($data['user_id']);
  5765. $bookInfo = Book::where("id", $data["id"])->first();
  5766. var_dump($bookInfo, '----');
  5767. if ($data['status'] == 2) {
  5768. $this->sendMessage([
  5769. 'talk_type' => 401,
  5770. 'title' => $bookInfo['title'],
  5771. 'content' => '审核通过',
  5772. 'messageType' => 7,
  5773. 'user_id' => $bookInfo['user_id'],
  5774. ]);
  5775. }
  5776. if ($data['status'] == 3) {
  5777. $this->sendMessage([
  5778. 'talk_type' => 401,
  5779. 'title' => $bookInfo['title'],
  5780. 'content' => '审核拒绝',
  5781. 'messageType' => 7,
  5782. 'user_id' => $bookInfo['user_id'],
  5783. ]);
  5784. }
  5785. if ($data['status'] == 1) {
  5786. $this->sendMessage([
  5787. 'talk_type' => 400,
  5788. 'title' => $bookInfo['title'],
  5789. 'content' => '提交了审核',
  5790. 'messageType' => 7,
  5791. // 'user_id'=>$bookInfo['user_id'],
  5792. ]);
  5793. }
  5794. $result = Book::where("id", $data["id"])->update($data);
  5795. if (empty($result)) {
  5796. return Result::error("更新失败", 0);
  5797. }
  5798. return Result::success($result);
  5799. }
  5800. //20250422 书刊音像
  5801. /**
  5802. * 贴身宝贝
  5803. * @param array $data
  5804. * @return array
  5805. */
  5806. public function getWebsiteTsbb(array $data): array
  5807. {
  5808. $month = $data['month'] ?? date('m');
  5809. $day = $data['day'] ?? date('d');
  5810. // 使用缓存键
  5811. $cacheKey = "tsbb_data_{$month}_{$day}";
  5812. // 尝试从缓存获取数据
  5813. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5814. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5815. if ($cachedData = $cache->get($cacheKey)) {
  5816. return Result::success(unserialize($cachedData));
  5817. }
  5818. //查询老黄历
  5819. try {
  5820. $date = date('Y-m-d');
  5821. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5822. // 使用 curl 替代 file_get_contents
  5823. $ch = curl_init();
  5824. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5825. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5826. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5827. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5828. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5829. 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');
  5830. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5831. 'Accept: application/json',
  5832. 'Content-Type: application/json',
  5833. 'Referer: https://www.36jxs.com/'
  5834. ]);
  5835. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5836. curl_setopt($ch, CURLOPT_ENCODING, '');
  5837. $almanacResponse = curl_exec($ch);
  5838. var_dump("====:", $almanacResponse);
  5839. if (curl_errno($ch)) {
  5840. var_dump('Curl error:', curl_error($ch));
  5841. throw new \Exception('Curl error: ' . curl_error($ch));
  5842. }
  5843. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5844. curl_close($ch);
  5845. if ($almanacResponse === false) {
  5846. throw new \Exception('Failed to fetch almanac data');
  5847. }
  5848. $almanacData = json_decode($almanacResponse, true);
  5849. if (json_last_error() !== JSON_ERROR_NONE) {
  5850. throw new \Exception('Failed to parse almanac data');
  5851. }
  5852. $almanacInfo = $almanacData['data'] ?? [];
  5853. } catch (\Exception $e) {
  5854. var_dump('Exception:', $e->getMessage());
  5855. $almanacInfo = [];
  5856. }
  5857. // 获取历史上的今天数据
  5858. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5859. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5860. ->orderBy('year', 'asc')
  5861. ->select("title", "id", "year", DB::raw('1 as type'))
  5862. ->limit(16)
  5863. ->get();
  5864. // 获取节日数据 - 从今天开始获取未来4条
  5865. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5866. ->orderBy('showtime', 'asc')
  5867. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5868. ->limit(16)
  5869. ->get();
  5870. //说文解字
  5871. $chartacterList = Character::orderBy('updated_at', 'desc')
  5872. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5873. ->limit(6)
  5874. ->get();
  5875. //谜语沙龙
  5876. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5877. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5878. ->limit(4)
  5879. ->get();
  5880. //成语欣赏
  5881. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5882. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5883. ->limit(32)
  5884. ->get();
  5885. //名联赏析
  5886. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5887. ->select("id", "first", "second", DB::raw('6 as type'))
  5888. ->limit(6)
  5889. ->get();
  5890. // 获取分类文章数据
  5891. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5892. ->pluck('category_id')
  5893. ->toArray();
  5894. $articlesList = [];
  5895. foreach ($categoryIds as $catid) {
  5896. // 先查有图片的
  5897. $withImg = DB::table('article')
  5898. ->where('status', 1)
  5899. ->where('catid', $catid)
  5900. ->whereNotNull('imgurl')
  5901. ->where('imgurl', '!=', '')
  5902. ->orderBy('updated_at', 'desc')
  5903. ->limit(6)
  5904. ->get();
  5905. $count = $withImg->count();
  5906. if ($count < 6) {
  5907. // 不足6条再查无图片的补足
  5908. $withoutImg = DB::table('article')
  5909. ->where('status', 1)
  5910. ->where('catid', $catid)
  5911. ->where(function ($q) {
  5912. $q->whereNull('imgurl')->orWhere('imgurl', '');
  5913. })
  5914. ->orderBy('updated_at', 'desc')
  5915. ->limit(6 - $count)
  5916. ->get();
  5917. $articles = $withImg->concat($withoutImg);
  5918. } else {
  5919. $articles = $withImg;
  5920. }
  5921. // 组装
  5922. $category = \App\Model\Category::find($catid);
  5923. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  5924. $articlesList[] = [
  5925. 'category_name' => $category ? $category->name : '',
  5926. 'catid' => $catid,
  5927. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  5928. 'type' => 100,
  5929. 'list' => $articles->map(function ($item) {
  5930. return [
  5931. 'id' => $item->id,
  5932. 'title' => $item->title,
  5933. 'imgurl' => $item->imgurl,
  5934. 'created_at' => $item->created_at
  5935. ];
  5936. })->values()
  5937. ];
  5938. }
  5939. $result = [
  5940. 'almanac' => $almanacInfo,
  5941. 'historyTodayList' => [
  5942. 'category_name' => '历史上的今天',
  5943. 'list' => $historyTodayList,
  5944. 'type' => 1
  5945. ],
  5946. 'festivalList' => [
  5947. 'category_name' => '节日预告',
  5948. 'list' => $festivalList,
  5949. 'type' => 2
  5950. ],
  5951. 'chartacterList' => [
  5952. 'category_name' => '说文解字',
  5953. 'list' => $chartacterList,
  5954. 'type' => 3
  5955. ],
  5956. 'coupletList' => [
  5957. 'category_name' => '名联赏析',
  5958. 'list' => $coupletList,
  5959. 'type' => 6
  5960. ],
  5961. 'riddletList' => [
  5962. 'category_name' => '谜语沙龙',
  5963. 'list' => $riddletList,
  5964. 'type' => 4
  5965. ],
  5966. 'idiomList' => [
  5967. 'category_name' => '成语欣赏',
  5968. 'list' => $idiomList,
  5969. 'type' => 5
  5970. ],
  5971. 'articlesList' => $articlesList
  5972. ];
  5973. // 缓存结果,设置1小时过期
  5974. $cache->set($cacheKey, serialize($result), 3600);
  5975. return Result::success($result);
  5976. }
  5977. /**
  5978. * 获取资讯列表
  5979. */
  5980. public function getWebsiteTsbbList(array $data): array
  5981. {
  5982. $page = $data['page'] ?? 1;
  5983. $pageSize = $data['pageSize'] ?? 10;
  5984. // 如果没有传入月份和日期,则使用今天的日期
  5985. $month = $data['month'] ?? date('m');
  5986. $day = $data['day'] ?? date('d');
  5987. $total = 0;
  5988. $result = [];
  5989. $data['type'] = intval($data['type']);
  5990. var_dump("接收参数:", $data);
  5991. switch ($data['type']) {
  5992. case 1:
  5993. $query = HistoryToday::where(function ($q) use ($month, $day) {
  5994. // 当前月份之后的数据
  5995. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  5996. // 或者当前月份且日期大于等于当前日期的数据
  5997. ->orWhere(function ($q) use ($month, $day) {
  5998. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5999. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6000. });
  6001. })
  6002. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6003. $total = $query->count();
  6004. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6005. ->offset(($page - 1) * $pageSize)
  6006. ->limit($pageSize)
  6007. ->get();
  6008. break;
  6009. case 2:
  6010. $query = Festival::where(function ($q) use ($month, $day) {
  6011. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6012. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6013. ->orWhere(function ($q) use ($month, $day) {
  6014. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6015. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6016. });
  6017. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6018. $total = $query->count();
  6019. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6020. ->offset(($page - 1) * $pageSize)
  6021. ->limit($pageSize)
  6022. ->get();
  6023. break;
  6024. case 3:
  6025. $query = Character::orderBy("updated_at", "desc");
  6026. $total = $query->count();
  6027. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6028. ->offset(($page - 1) * $pageSize)
  6029. ->limit($pageSize)
  6030. ->get();
  6031. break;
  6032. case 4:
  6033. $query = Riddle::orderBy("updated_at", "desc");
  6034. $total = $query->count();
  6035. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6036. ->offset(($page - 1) * $pageSize)
  6037. ->limit($pageSize)
  6038. ->get();
  6039. break;
  6040. case 5:
  6041. $query = Idiom::orderBy("updated_at", "desc");
  6042. $total = $query->count();
  6043. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6044. ->offset(($page - 1) * $pageSize)
  6045. ->limit($pageSize)
  6046. ->get();
  6047. break;
  6048. case 6:
  6049. $query = Couplet::orderBy("updated_at", "desc");
  6050. $total = $query->count();
  6051. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6052. ->offset(($page - 1) * $pageSize)
  6053. ->limit($pageSize)
  6054. ->get();
  6055. break;
  6056. default:
  6057. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6058. $total = $query->count();
  6059. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6060. ->offset(($page - 1) * $pageSize)
  6061. ->limit($pageSize)
  6062. ->get();
  6063. }
  6064. return Result::success([
  6065. 'list' => $result,
  6066. 'total' => $total,
  6067. 'page' => (int)$page,
  6068. 'pageSize' => (int)$pageSize,
  6069. 'month' => $month,
  6070. 'day' => $day
  6071. ]);
  6072. }
  6073. /**
  6074. * 1:历史上的今天
  6075. * 2:节日
  6076. * 3:文章
  6077. *
  6078. * 资讯详情信息
  6079. */
  6080. public function getWebsiteTsbbDetail(array $data): array
  6081. {
  6082. $data['type'] = intval($data['type']);
  6083. switch ($data['type']) {
  6084. case 1:
  6085. $result = HistoryToday::where("id", $data['id'])->first();
  6086. break;
  6087. case 2:
  6088. $result = Festival::where("id", $data['id'])->first();
  6089. break;
  6090. case 3:
  6091. $result = Character::where("id", $data['id'])->first();
  6092. break;
  6093. case 4:
  6094. $result = Riddle::where("id", $data['id'])->first();
  6095. break;
  6096. case 5:
  6097. $result = Idiom::where("id", $data['id'])->first();
  6098. break;
  6099. case 6:
  6100. $result = Couplet::where("id", $data['id'])->first();
  6101. break;
  6102. default:
  6103. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6104. break;
  6105. }
  6106. return Result::success($result);
  6107. }
  6108. /**
  6109. * 农网导航首页数据
  6110. */
  6111. public function getWebsiteNwHomeList(array $data): array
  6112. {
  6113. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6114. ->pluck('category_id')
  6115. ->toArray();
  6116. // 使用子查询优化
  6117. $articlesList = DB::table('article')
  6118. ->select([
  6119. 'article.id',
  6120. 'article.title',
  6121. 'article.imgurl',
  6122. 'article.created_at',
  6123. 'category.name as category_name',
  6124. 'category.id as category_id',
  6125. 'website_category.aLIas_pinyin as pinyin',
  6126. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6127. DB::raw('100 as type')
  6128. ])
  6129. ->join('category', 'article.catid', '=', 'category.id')
  6130. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6131. ->leftJoin('website_category as parent_wc', function ($join) {
  6132. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6133. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6134. })
  6135. ->where('website_category.website_id', $data['website_id'])
  6136. ->where('article.status', 1)
  6137. ->whereIn('category.id', $categoryIds)
  6138. ->orderBy('article.created_at', 'desc')
  6139. ->get()
  6140. ->groupBy('category_id')
  6141. ->map(function ($group) {
  6142. // 确保第一条数据有图片
  6143. $firstWithImage = $group->first(function ($item) {
  6144. return !empty($item->imgurl);
  6145. });
  6146. if ($firstWithImage) {
  6147. // 如果有带图片的文章,将其放在第一位
  6148. $group = $group->filter(function ($item) use ($firstWithImage) {
  6149. return $item->id !== $firstWithImage->id;
  6150. })->prepend($firstWithImage);
  6151. }
  6152. return [
  6153. 'category_name' => $group->first()->category_name,
  6154. 'catid' => $group->first()->category_id,
  6155. 'pinyin' => $group->first()->pinyin,
  6156. 'parent_pinyin' => $group->first()->parent_pinyin,
  6157. 'list' => $group->take(4)->map(function ($item) {
  6158. return [
  6159. 'id' => $item->id,
  6160. 'title' => $item->title,
  6161. ];
  6162. })->values()
  6163. ];
  6164. })
  6165. ->values()
  6166. ->toArray();
  6167. return Result::success($articlesList);
  6168. }
  6169. /**
  6170. * 企业管理
  6171. * @param array $data
  6172. * @return array
  6173. */
  6174. public function getCompanyList(array $data): array
  6175. {
  6176. // return Result::success($data);
  6177. $where = [];
  6178. $user = User::where('id', $data['user_id'])->first();
  6179. if (empty($user)) {
  6180. return Result::error('用户不存在!');
  6181. }
  6182. if ($user['type_id'] != 10000) {
  6183. $where['user_id'] = $data['user_id'];
  6184. }
  6185. if (isset($data['title']) && !empty($data['title'])) {
  6186. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6187. }
  6188. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6189. array_push($where, ['website.id', $data['website_id']]);
  6190. }
  6191. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6192. if ($data['ischeck'] == 1) {
  6193. if (isset($data['status']) && $data['status'] != '') {
  6194. array_push($where, ['company.status', $data['status']]);
  6195. $query = Company::where($where);
  6196. } else {
  6197. $query = Company::whereIn('company.status', [0, 2]);
  6198. }
  6199. } else {
  6200. $query = Company::where('company.status', 1);
  6201. }
  6202. }
  6203. $result = $query->where($where)
  6204. ->leftJoin('website_category', function ($query) {
  6205. $query->on('website_category.category_id', '=', 'company.category_id')
  6206. ->on('website_category.website_id', '=', 'company.website_id');
  6207. })
  6208. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6209. ->select(
  6210. 'company.id',
  6211. 'company.title',
  6212. 'company.website_id',
  6213. 'company.category_id',
  6214. 'website.website_name',
  6215. 'website_category.alias as category_name',
  6216. 'company.status',
  6217. 'company.updated_at',
  6218. 'company.user_id'
  6219. )
  6220. ->orderBy('company.updated_at', 'desc')
  6221. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6222. if ($result->isEmpty()) {
  6223. return Result::error("暂无企业", 0);
  6224. }
  6225. return Result::success($result);
  6226. }
  6227. /**
  6228. * 添加企业
  6229. * @param array $data
  6230. * @return array
  6231. */
  6232. public function addCompany(array $data): array
  6233. {
  6234. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6235. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6236. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6237. $data['cat_arr_id'] = json_encode($car_arr_id);
  6238. } else {
  6239. $data['cat_arr_id'] = '';
  6240. }
  6241. if ($data['imgurl'] == '') {
  6242. //content中提取图片第一个图,正则提取
  6243. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6244. preg_match_all($reg, $data['content'], $matches);
  6245. if (isset($matches[1][0])) {
  6246. //截取varchar240
  6247. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6248. }
  6249. }
  6250. if ($data['keyword'] == '') {
  6251. //提取标题+内容中的关键词
  6252. $data['keyword'] = $data['title'];
  6253. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6254. Jieba::init(); // 初始化 jieba-php
  6255. Finalseg::init();
  6256. $segList = Jieba::cut($data['keyword']);
  6257. $segList1 = array_slice($segList, 0, 8);
  6258. $data['keyword'] = implode(',', $segList1);
  6259. }
  6260. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6261. //提取内容中的描述
  6262. $content = $data['content'];
  6263. // 去除 <style> 和 <script> 标签及其内容
  6264. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6265. // 去除所有 HTML 标签
  6266. $content = strip_tags($content);
  6267. // 去除 HTML 实体
  6268. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6269. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6270. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6271. // 去除多余空白
  6272. $content = preg_replace('/\s+/u', '', $content);
  6273. // 截取 100 个字符
  6274. $data['introduce'] = mb_substr($content, 0, 100);
  6275. }
  6276. $user = User::where('id', $data['user_id'])->first();
  6277. if (empty($user)) {
  6278. return Result::error('用户不存在!');
  6279. }
  6280. if ($user['type_id'] == 10000) {
  6281. $data['status'] = 1;
  6282. }
  6283. if (isset($data['level']) && $data['level'] != null) {
  6284. $data['level'] = intval($data['level']);
  6285. } else {
  6286. $data['level'] = null;
  6287. }
  6288. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6289. $this->sendMessage([
  6290. 'talk_type' => 900,
  6291. 'title' => $data['title'],
  6292. 'content' => '提交了审核',
  6293. 'messageType' => 8,
  6294. ]);
  6295. }
  6296. $result = Company::insertGetId($data);
  6297. if ($result) {
  6298. return Result::success($result);
  6299. } else {
  6300. return Result::error('添加失败');
  6301. }
  6302. }
  6303. /**
  6304. * 更新企业
  6305. * @param array $data
  6306. * @return array
  6307. */
  6308. public function upCompany(array $data): array
  6309. {
  6310. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6311. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6312. $data['cat_arr_id'] = json_encode($car_arr_id);
  6313. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6314. } else {
  6315. $data['cat_arr_id'] = '';
  6316. }
  6317. if ($data['imgurl'] == '') {
  6318. //content中提取图片第一个图,正则提取
  6319. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6320. preg_match_all($reg, $data['content'], $matches);
  6321. if (isset($matches[1][0])) {
  6322. //截取varchar
  6323. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6324. }
  6325. }
  6326. if ($data['keyword'] == '') {
  6327. //提取标题+内容中的关键词
  6328. $data['keyword'] = $data['title'];
  6329. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6330. Jieba::init(); // 初始化 jieba-php
  6331. Finalseg::init();
  6332. $segList = Jieba::cut($data['keyword']);
  6333. $segList1 = array_slice($segList, 0, 8);
  6334. $data['keyword'] = implode(',', $segList1);
  6335. }
  6336. if ($data['introduce'] == '') {
  6337. //提取内容中的描述
  6338. $content = $data['content'];
  6339. // 去除 <style> 和 <script> 标签及其内容
  6340. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6341. // 去除所有 HTML 标签
  6342. $content = strip_tags($content);
  6343. // 去除 HTML 实体
  6344. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6345. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6346. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6347. // 去除多余空白
  6348. $content = preg_replace('/\s+/u', '', $content);
  6349. // 截取 100 个字符
  6350. $data['introduce'] = mb_substr($content, 0, 100);
  6351. }
  6352. if (isset($data['level']) && $data['level'] != null) {
  6353. $data['level'] = intval($data['level']);
  6354. } else {
  6355. $data['level'] = null;
  6356. }
  6357. $user = User::where('id', $data['user_id'])->first();
  6358. if (empty($user)) {
  6359. return Result::error('用户不存在!');
  6360. }
  6361. if ($user['type_id'] == 10000) {
  6362. $data['status'] = 1;
  6363. } else {
  6364. $data['status'] = 0;
  6365. }
  6366. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6367. $this->sendMessage([
  6368. 'talk_type' => 900,
  6369. 'title' => $data['title'],
  6370. 'content' => '提交了审核',
  6371. 'messageType' => 8,
  6372. ]);
  6373. }
  6374. $result = Company::where('id', $data['id'])->update($data);
  6375. if ($result) {
  6376. return Result::success($result);
  6377. } else {
  6378. return Result::error('修改失败');
  6379. }
  6380. }
  6381. /**
  6382. * 删除企业
  6383. * @param array $data
  6384. * @return array
  6385. */
  6386. public function delCompany(array $data): array
  6387. {
  6388. $result = Company::where('id', $data['id'])->delete();
  6389. if ($result) {
  6390. return Result::success($result);
  6391. } else {
  6392. return Result::error('删除失败');
  6393. }
  6394. }
  6395. /**
  6396. * 审核企业
  6397. * @param array $data
  6398. * @return array
  6399. */
  6400. public function checkCompany(array $data): array
  6401. {
  6402. $user = User::where('id', $data['user_id'])->first();
  6403. if (empty($user)) {
  6404. return Result::error('用户不存在!');
  6405. }
  6406. $company = Company::where('id', $data['id'])->first();
  6407. if (empty($company)) {
  6408. return Result::error('企业不存在!');
  6409. }
  6410. // 状态:0:未审核 1:已审核 2:已拒绝
  6411. if ($data['status'] == 2 || $data['status'] == '2') {
  6412. $this->sendMessage([
  6413. 'talk_type' => 901,
  6414. 'title' => $company['title'],
  6415. 'content' => '审核拒绝',
  6416. 'messageType' => 8,
  6417. 'user_id' => $company['user_id'],
  6418. ]);
  6419. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6420. } else {
  6421. if ($data['status'] == 1) {
  6422. $this->sendMessage([
  6423. 'talk_type' => 901,
  6424. 'title' => $company['title'],
  6425. 'content' => '审核通过',
  6426. 'messageType' => 8,
  6427. 'user_id' => $company['user_id'],
  6428. ]);
  6429. } else if ($data['status'] == 0) {
  6430. $this->sendMessage([
  6431. 'talk_type' => 900,
  6432. 'title' => $company['title'],
  6433. 'content' => '提交了审核',
  6434. 'messageType' => 8,
  6435. ]);
  6436. }
  6437. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6438. }
  6439. if (empty($result)) {
  6440. return Result::error('审核失败!');
  6441. } else {
  6442. return Result::success($result);
  6443. }
  6444. }
  6445. /**
  6446. * 获取企业信息
  6447. * @param array $data
  6448. * @return array
  6449. */
  6450. public function getCompanyInfo(array $data): array
  6451. {
  6452. $result = Company::where('id', $data['id'])->first();
  6453. $city_arr = json_decode($result['city_arr_id']);
  6454. $result['city_name'] = District::whereIn('id', $city_arr)
  6455. ->pluck('name')
  6456. ->implode('-');
  6457. if (empty($result)) {
  6458. return Result::error('企业不存在!');
  6459. } else {
  6460. return Result::success($result);
  6461. }
  6462. }
  6463. /**
  6464. * @param array $data
  6465. * @return array
  6466. */
  6467. public function getWebsiteCompany(array $data): array
  6468. {
  6469. $categorys = json_decode($data['id'], true);
  6470. $category_arr = $this->processArticlePro($data['website_id']);
  6471. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6472. $catiall = $category_arr['catiall'];
  6473. $categoryIds = $category_arr['categoryIds'];
  6474. // return Result::success($category_arr);
  6475. foreach ($categorys as $key => $value) {
  6476. if (array_key_exists('level', $value)) {
  6477. $parts = explode(',', $value['level']);
  6478. $level = $parts[0] ?? null;
  6479. $imgnum = $parts[1] ?? null;
  6480. $textnum = $parts[2] ?? null;
  6481. if (!empty($textnum) && $textnum > 0) {
  6482. $text_num = Company::where('level', $level)
  6483. ->whereIn('category_id', $categoryIds)
  6484. ->where('status', 1)
  6485. ->select(
  6486. 'company.id',
  6487. 'company.title',
  6488. 'company.description',
  6489. 'company.updated_at',
  6490. 'company.category_id',
  6491. 'company.cat_arr_id'
  6492. )
  6493. ->orderBy('updated_at', 'desc')
  6494. ->limit($textnum)
  6495. ->get()->all();
  6496. }
  6497. if (!empty($imgnum) && $imgnum > 0) {
  6498. $img_num = Company::where('level', $level)
  6499. ->whereIn('category_id', $categoryIds)
  6500. ->where('status', 1)
  6501. ->where('imgurl', '!=', '')
  6502. ->whereNotNull('imgurl')
  6503. ->select(
  6504. 'company.id',
  6505. 'company.title',
  6506. 'company.description',
  6507. 'company.updated_at',
  6508. 'company.imgurl as imgs',
  6509. 'company.category_id',
  6510. 'company.cat_arr_id'
  6511. )
  6512. ->orderBy('updated_at', 'desc')
  6513. ->limit($imgnum)
  6514. ->get()->all();
  6515. }
  6516. }
  6517. if (array_key_exists('id', $value)) {
  6518. $parts = explode(',', $value['id']);
  6519. $category_id = $parts[0] ?? null;
  6520. $imgnum = $parts[1] ?? null;
  6521. $textnum = $parts[2] ?? null;
  6522. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6523. if (!empty($textnum) && $textnum > 0) {
  6524. $text_num = Company::whereIn('category_id', $category_arr)
  6525. // ->where('website_id', $data['website_id'])
  6526. ->where('status', 1)
  6527. ->select(
  6528. 'company.id',
  6529. 'company.title',
  6530. 'company.description',
  6531. 'company.updated_at',
  6532. 'company.category_id',
  6533. 'company.cat_arr_id'
  6534. )
  6535. ->orderBy('updated_at', 'desc')
  6536. ->limit($textnum)
  6537. ->get()->all();
  6538. }
  6539. if (!empty($imgnum) && $imgnum > 0) {
  6540. $img_num = Company::whereIn('category_id', $category_arr)
  6541. // ->where('website_id', $data['website_id'])
  6542. ->where('status', 1)
  6543. ->where('imgurl', '!=', '')
  6544. ->whereNotNull('imgurl')
  6545. ->select(
  6546. 'company.id',
  6547. 'company.title',
  6548. 'company.description',
  6549. 'company.updated_at',
  6550. 'company.imgurl as imgs',
  6551. 'company.category_id',
  6552. 'company.cat_arr_id'
  6553. )
  6554. ->orderBy('updated_at', 'desc')
  6555. ->limit($imgnum)
  6556. ->get()->all();
  6557. }
  6558. }
  6559. if (!empty($text_num)) {
  6560. foreach ($text_num as $k => $v) {
  6561. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6562. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6563. }
  6564. }
  6565. if (!empty($img_num)) {
  6566. foreach ($img_num as $k => $v) {
  6567. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6568. $imgurl = json_decode($v['imgs'], true);
  6569. if (!empty($imgurl)) {
  6570. $img_num[$k]->imgurl = $imgurl[0];
  6571. }
  6572. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6573. }
  6574. }
  6575. $company[$key]['img_num'] = $img_num ?? [];
  6576. $company[$key]['text_num'] = $text_num ?? [];
  6577. }
  6578. if (empty($company)) {
  6579. return Result::error("暂无相关企业信息", 0);
  6580. }
  6581. return Result::success($company);
  6582. }
  6583. /**
  6584. * @param array $data
  6585. * @return array
  6586. */
  6587. public function getWebsiteCompanyList(array $data): array
  6588. {
  6589. $where['website_id'] = $data['website_id'];
  6590. $where['status'] = 1;
  6591. $categoryIds = [];
  6592. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6593. $category_id = $data['category_id'];
  6594. }
  6595. $category_arr = $this->processArticlePro($data['website_id']);
  6596. $categoryIds = $category_arr['categoryIds'];
  6597. // return Result::success($cat_1st_arr);
  6598. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  6599. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  6600. })
  6601. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  6602. $query->whereIn('category_id', $categoryIds);
  6603. })
  6604. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  6605. $query->where('category_id', $category_id);
  6606. })
  6607. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6608. ->orderBy('updated_at', 'desc')
  6609. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6610. if (empty($company)) {
  6611. return Result::error("暂无相关公司信息", 0);
  6612. }
  6613. $result = [
  6614. 'count' => $company->total(),
  6615. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  6616. ];
  6617. return Result::success($result);
  6618. }
  6619. /**
  6620. * 获取项目列表
  6621. * @param array $data
  6622. * @return array
  6623. */
  6624. public function getProjectList(array $data): array
  6625. {
  6626. $where = [];
  6627. $user = User::where('id', $data['user_id'])->first();
  6628. if (empty($user)) {
  6629. return Result::error('用户不存在!');
  6630. }
  6631. if ($user->type_id != 10000) {
  6632. array_push($where, ['project.user_id', $data['user_id']]);
  6633. }
  6634. $query = Project::query();
  6635. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6636. array_push($where, ['project.website_id', $data['website_id']]);
  6637. }
  6638. if (isset($data['title']) && !empty($data['title'])) {
  6639. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6640. }
  6641. if ($data['status'] != 3) {
  6642. array_push($where, ['project.status', $data['status']]);
  6643. }
  6644. $query = Project::where($where)
  6645. ->when($data['status'] == 3, function ($query) {
  6646. $query->whereIn('project.status', [0, 2]);
  6647. });
  6648. $count = $query->clone()
  6649. ->count();
  6650. $rows = $query->clone()
  6651. ->leftJoin('website', 'project.website_id', 'website.id')
  6652. ->leftJoin('website_category', function ($join) {
  6653. $join->on('project.website_id', '=', 'website_category.website_id')
  6654. ->on('project.category_id', '=', 'website_category.category_id');
  6655. })
  6656. ->select(
  6657. 'project.id',
  6658. 'project.title',
  6659. 'project.updated_at',
  6660. 'project.status',
  6661. 'website.website_name',
  6662. 'website_category.alias as category_name',
  6663. 'project.website_id',
  6664. 'project.user_id'
  6665. )
  6666. ->orderBy('project.updated_at', 'desc')
  6667. ->offset(($data['page'] - 1) * $data['pageSize'])
  6668. ->limit($data['pageSize'])
  6669. ->get();
  6670. if ($rows->isEmpty()) {
  6671. return Result::error("暂无相关项目信息", 0);
  6672. }
  6673. $result = [
  6674. 'count' => $count,
  6675. 'rows' => $rows,
  6676. ];
  6677. return Result::success($result);
  6678. }
  6679. /**
  6680. * 添加项目
  6681. * @param array $data
  6682. * @return array
  6683. */
  6684. public function addProject(array $data): array
  6685. {
  6686. $user = User::where('id', $data['user_id'])->first();
  6687. if (empty($user)) {
  6688. return Result::error("暂无相关用户信息", 0);
  6689. }
  6690. if ($user->type_id == 10000) {
  6691. $data['status'] = 1;
  6692. } else {
  6693. $data['status'] = 0;
  6694. }
  6695. if ($data['keyword'] == '') {
  6696. //提取标题+内容中的关键词
  6697. $data['keyword'] = $data['title'];
  6698. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6699. Jieba::init(); // 初始化 jieba-php
  6700. Finalseg::init();
  6701. $segList = Jieba::cut($data['keyword']);
  6702. $segList1 = array_slice($segList, 0, 8);
  6703. $data['keyword'] = implode(',', $segList1);
  6704. }
  6705. if ($data['description'] == '') {
  6706. //提取内容中的描述
  6707. // var_dump(11111);
  6708. //提取内容中的描述
  6709. $content = $data['introduce'];
  6710. // 去除 <style> 和 <script> 标签及其内容
  6711. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6712. // 去除所有 HTML 标签
  6713. $content = strip_tags($content);
  6714. // 去除 HTML 实体
  6715. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6716. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6717. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6718. // 去除多余空白
  6719. $content = preg_replace('/\s+/u', '', $content);
  6720. // 截取 100 个字符
  6721. $data['description'] = mb_substr($content, 0, 100);
  6722. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6723. }
  6724. if ($data['status'] == 0) {
  6725. $this->sendMessage([
  6726. 'talk_type' => 1000,
  6727. 'title' => $data['title'],
  6728. 'content' => '提交了审核',
  6729. 'messageType' => 9,
  6730. ]);
  6731. }
  6732. $project = Project::insertGetId($data);
  6733. if (empty($project)) {
  6734. return Result::error("暂无相关项目信息", 0);
  6735. }
  6736. return Result::success($project);
  6737. }
  6738. /**
  6739. * 更新项目
  6740. * @param array $data
  6741. * @return array
  6742. */
  6743. public function upProject(array $data): array
  6744. {
  6745. $project = Project::where('id', $data['id'])->first();
  6746. if (empty($project)) {
  6747. return Result::error("暂无相关项目信息", 0);
  6748. }
  6749. $id = $data['id'];
  6750. unset($data['id']);
  6751. $user = User::where('id', $data['user_id'])->first();
  6752. if (empty($user)) {
  6753. return Result::error("暂无相关用户信息", 0);
  6754. }
  6755. if ($user->type_id == 10000) {
  6756. $data['status'] = 1;
  6757. } else {
  6758. $data['status'] = 0;
  6759. }
  6760. unset($data['user_id']);
  6761. if ($data['keyword'] == '') {
  6762. //提取标题+内容中的关键词
  6763. $data['keyword'] = $data['title'];
  6764. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6765. Jieba::init(); // 初始化 jieba-php
  6766. Finalseg::init();
  6767. $segList = Jieba::cut($data['keyword']);
  6768. $segList1 = array_slice($segList, 0, 8);
  6769. $data['keyword'] = implode(',', $segList1);
  6770. }
  6771. if ($data['description'] == '') {
  6772. //提取内容中的描述
  6773. // var_dump(11111);
  6774. //提取内容中的描述
  6775. $content = $data['introduce'];
  6776. // 去除 <style> 和 <script> 标签及其内容
  6777. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6778. // 去除所有 HTML 标签
  6779. $content = strip_tags($content);
  6780. // 去除 HTML 实体
  6781. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6782. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6783. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6784. // 去除多余空白
  6785. $content = preg_replace('/\s+/u', '', $content);
  6786. // 截取 100 个字符
  6787. $data['description'] = mb_substr($content, 0, 100);
  6788. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6789. }
  6790. if ($data['status'] == 0) {
  6791. $this->sendMessage([
  6792. 'talk_type' => 1000,
  6793. 'title' => $data['title'],
  6794. 'content' => '提交了审核',
  6795. 'messageType' => 9,
  6796. ]);
  6797. }
  6798. $result = Project::where('id', $id)->update($data);
  6799. if (empty($result)) {
  6800. return Result::error("更新失败", 0);
  6801. }
  6802. return Result::success($result);
  6803. }
  6804. /**
  6805. * 删除项目
  6806. * @param array $data
  6807. * @return array
  6808. */
  6809. public function delProject(array $data): array
  6810. {
  6811. $user = User::where('id', $data['user_id'])->first();
  6812. if (empty($user)) {
  6813. return Result::error("暂无相关用户信息", 0);
  6814. }
  6815. $project = Project::where('id', $data['id'])->first();
  6816. if (empty($project)) {
  6817. return Result::error("暂无相关项目信息", 0);
  6818. }
  6819. $result = Project::where('id', $data['id'])->delete();
  6820. if (empty($result)) {
  6821. return Result::error("删除失败", 0);
  6822. }
  6823. return Result::success($result);
  6824. }
  6825. /**
  6826. * 审核项目
  6827. * @param array $data
  6828. * @return array
  6829. */
  6830. public function checkProject(array $data): array
  6831. {
  6832. $user = User::where('id', $data['user_id'])->first();
  6833. if (empty($user)) {
  6834. return Result::error("暂无相关用户信息", 0);
  6835. }
  6836. // 0:未审核; 1:已审核; 2:已拒绝;
  6837. if ($user->type_id != 10000) {
  6838. if ($data['status'] == 1 || $data['status'] == 2) {
  6839. return Result::error("此用户权限不足", 0);
  6840. }
  6841. }
  6842. $project = Project::where('id', $data['id'])->first();
  6843. if (empty($project)) {
  6844. return Result::error("暂无相关项目信息", 0);
  6845. }
  6846. if ($data['status'] == 2) {
  6847. $this->sendMessage([
  6848. 'talk_type' => 1001,
  6849. 'title' => $project['title'],
  6850. 'content' => '审核拒绝',
  6851. 'messageType' => 9,
  6852. 'user_id' => $project['user_id'],
  6853. ]);
  6854. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  6855. } else {
  6856. if ($data['status'] == 1) {
  6857. $this->sendMessage([
  6858. 'talk_type' => 1001,
  6859. 'title' => $project['title'],
  6860. 'content' => '审核通过',
  6861. 'messageType' => 9,
  6862. 'user_id' => $project['user_id'],
  6863. ]);
  6864. } else if ($data['status'] == 0) {
  6865. $this->sendMessage([
  6866. 'talk_type' => 1000,
  6867. 'title' => $project['title'],
  6868. 'content' => '提交了审核',
  6869. 'messageType' => 9,
  6870. ]);
  6871. }
  6872. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  6873. }
  6874. if (empty($result)) {
  6875. return Result::error("审核失败", 0);
  6876. }
  6877. return Result::success($result);
  6878. }
  6879. /**
  6880. * 获取项目详情
  6881. * @param array $data
  6882. * @return array
  6883. */
  6884. public function getProjectInfo(array $data): array
  6885. {
  6886. $project = Project::where('id', $data['id'])->first();
  6887. if (empty($project)) {
  6888. return Result::error("暂无相关项目信息", 0);
  6889. }
  6890. return Result::success($project);
  6891. }
  6892. public function getWebsiteCompanyInfo(array $data): array
  6893. {
  6894. $company = Company::where('id', $data['id'])
  6895. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  6896. ->where('status', 1)
  6897. // ->where('website_id', $data['website_id'])
  6898. ->select('company.*', 'job_industry.hyname as hy_name')
  6899. ->first();
  6900. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  6901. switch ($company->jobnature_id) {
  6902. case null:
  6903. $company->jobnature_name = '';
  6904. break;
  6905. case 0:
  6906. $company->jobnature_name = '市场监督';
  6907. break;
  6908. case 1:
  6909. $company->jobnature_name = '信访纪检';
  6910. break;
  6911. case 2:
  6912. $company->jobnature_name = '公检法司';
  6913. break;
  6914. case 3:
  6915. $company->jobnature_name = '高关注机构';
  6916. break;
  6917. default:
  6918. $company->jobnature_name = '';
  6919. break;
  6920. }
  6921. $city_arr = $company->city_arr_id;
  6922. if (!empty($city_arr)) {
  6923. $city_arr = json_decode($city_arr, true);
  6924. $cityNames = District::whereIn('id', $city_arr)
  6925. ->pluck('name')
  6926. ->implode('-');
  6927. $company->city_name = $cityNames;
  6928. } else {
  6929. $company->city_name = '';
  6930. }
  6931. if (empty($company)) {
  6932. return Result::error("暂无相关公司信息", 0);
  6933. }
  6934. return Result::success($company);
  6935. }
  6936. public function getMSG(array $data): array
  6937. {
  6938. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  6939. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  6940. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  6941. $result = [];
  6942. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  6943. //最近的5篇已审的文章
  6944. $apply_articale = Article::where('status', 1)
  6945. ->where('admin_user_id', $user_id)
  6946. ->orderBy('updated_at', 'desc')
  6947. // ->limit(5)
  6948. ->get();
  6949. //获取5条用户的已审核商品
  6950. $good = Good::where('status', 2)
  6951. ->where('user_id', $user_id)
  6952. ->orderBy('updated_at', 'desc')
  6953. // ->limit(5)
  6954. ->get();
  6955. //获取5条用户待审核的公告
  6956. $notice = Notice::where('status', 2)
  6957. ->where('user_id', $user_id)
  6958. ->orderBy('updated_at', 'desc')
  6959. ->limit(5)->get();
  6960. //获取5条用户的待审核投诉
  6961. $complaint = Complaint::where('status', 2)
  6962. ->where('user_id', $user_id)
  6963. ->orderBy('updated_at', 'desc')
  6964. // ->limit(5)
  6965. ->get();
  6966. //获取5条用户的book
  6967. $book = Book::where('status', 2)
  6968. ->where('user_id', $user_id)
  6969. ->orderBy('updated_at', 'desc')
  6970. // ->limit(5)
  6971. ->get();
  6972. //获取5条用户的求职
  6973. //获取5条用户的求职 1
  6974. $job_hunting = JobHunting::where('job_hunting.status', 2)
  6975. ->where('job_hunting.user_id', $user_id)
  6976. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  6977. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  6978. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6979. ->orderBy('updated_at', 'desc')
  6980. // ->limit(5)
  6981. ->get();
  6982. //获取5条用户的求职 2
  6983. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  6984. ->where('job_recruiting.user_id', $user_id)
  6985. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  6986. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  6987. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6988. ->orderBy('updated_at', 'desc')
  6989. // ->limit(5)
  6990. ->get();
  6991. //人才库 1
  6992. $job_apply = JobApply::where('job_apply.status', 1)
  6993. ->where('job_apply.receiver_id', $user_id)
  6994. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  6995. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  6996. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  6997. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  6998. ->select('job_recruiting', 'job_recruiting.', '', '')
  6999. ->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')
  7000. ->orderBy('updated_at', 'desc')
  7001. // ->limit(5)
  7002. ->get();
  7003. // 职场机会 2
  7004. $job_resume = JobResume::where('job_resume.status', 1)
  7005. ->where('job_resume.receiver_id', $user_id)
  7006. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7007. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7008. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7009. ->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')
  7010. ->orderBy('updated_at', 'desc')
  7011. // ->limit(5)
  7012. ->get();
  7013. //获取5条用户待处理的投诉
  7014. $complaint_deal = Complaint::where('status', 2)
  7015. ->where('deal', 1)
  7016. ->whereJsonContains('re_user_ids', $user_id)
  7017. ->orderBy('updated_at', 'desc')
  7018. // ->limit(5)
  7019. ->get();
  7020. //获取 被通知者未读信息
  7021. $notice_unread = Notice::where('status', 2)
  7022. ->whereJsonContains('re_user_ids', $user_id)
  7023. //未读消息
  7024. ->where(function ($query) use ($user_id) {
  7025. $query->whereJsonDoesntContain('read_id', $user_id)
  7026. ->orWhereNull('read_id');
  7027. })
  7028. ->orderBy('updated_at', 'desc')
  7029. ->get();
  7030. $complaint_unread = Complaint::where('status', 2)
  7031. ->whereJsonContains('re_user_ids', $user_id)
  7032. //未读消息
  7033. ->where(function ($query) use ($user_id) {
  7034. $query->whereJsonDoesntContain('read_id', $user_id)
  7035. ->orWhereNull('read_id');
  7036. })
  7037. ->orderBy('updated_at', 'desc')
  7038. ->get();
  7039. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7040. $complany = Company::where('status', 1)
  7041. ->where('user_id', $user_id)
  7042. ->orderBy('updated_at', 'desc')
  7043. // ->limit(5)
  7044. ->get();
  7045. //获取5条单聊未读聊天消息
  7046. // $chat = ChatRecords::where('is_read', 0)
  7047. // ->where('user_id', $user_id)
  7048. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7049. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7050. // ->where('action', 'recieved')
  7051. // ->where('talk_type', 1)
  7052. // ->orderBy('created_at', 'desc')
  7053. // // ->limit(5)
  7054. // ->get();
  7055. //获取5条未读群聊信息
  7056. // $chat_group = ChatRecords::where('is_read', 0)
  7057. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7058. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7059. // ->where('user_id', $user_id)
  7060. // ->where('talk_type', 2)
  7061. // ->orderBy('created_at', 'desc')
  7062. // // ->limit(5)
  7063. // ->get();
  7064. //获取5条用户的待审核项目
  7065. $project = Project::where('status', 1)
  7066. ->where('user_id', $user_id)
  7067. ->orderBy('updated_at', 'desc')
  7068. // ->limit(5)
  7069. ->get();
  7070. // count($chat) + count($chat_group) +
  7071. $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)
  7072. + count($complany)
  7073. + count($project)
  7074. + count($notice_unread)
  7075. + count($complaint_unread)
  7076. // + count($chat) + count($chat_group)
  7077. ;
  7078. $result = [
  7079. 'apply_articale' => $apply_articale,
  7080. // 'chat' => $chat,
  7081. // 'chat_group' => $chat_group,
  7082. 'good' => $good,
  7083. 'notice' => $notice,
  7084. 'complaint' => $complaint,
  7085. 'book' => $book,
  7086. 'job_hunting' => $job_hunting,
  7087. 'job_recruiting' => $job_recruiting,
  7088. 'job_apply' => $job_apply,
  7089. 'job_resume' => $job_resume,
  7090. 'complaint_deal' => $complaint_deal,
  7091. 'complany' => $complany,
  7092. 'project' => $project,
  7093. 'notice_unread' => $notice_unread,
  7094. 'complaint_unread' => $complaint_unread,
  7095. 'count' => $count,
  7096. ];
  7097. } elseif ($type_id == 12) {
  7098. //最近的5篇已审的文章
  7099. $apply_articale = Article::where('status', 1)
  7100. ->where('admin_user_id', $user_id)
  7101. ->limit(5)->get();
  7102. //获取5条单聊未读聊天消息
  7103. $chat = ChatRecords::where('is_read', 0)
  7104. ->where('user_id', $user_id)
  7105. ->where('talk_type', 1)
  7106. ->orderBy('created_at', 'desc')
  7107. ->limit(5)->get();
  7108. //获取5条未读群聊信息
  7109. $chat_group = ChatRecords::where('is_read', 0)
  7110. ->where('user_id', $user_id)
  7111. ->where('talk_type', 2)
  7112. ->orderBy('created_at', 'desc')
  7113. ->limit(5)->get();
  7114. //获取5条用户的已审核商品
  7115. $good = Good::where('status', 2)
  7116. ->where('user_id', $user_id)
  7117. ->orderBy('updated_at', 'desc')
  7118. ->limit(5)->get();
  7119. //获取5条用户的book
  7120. $book = Book::where('status', 2)
  7121. ->where('user_id', $user_id)
  7122. ->orderBy('updated_at', 'desc')
  7123. ->limit(5)->get();
  7124. //获取5条用户的求职
  7125. //获取5条用户的求职 1
  7126. //count($chat) + count($chat_group)
  7127. $count = count($apply_articale) + count($good);
  7128. $result = [
  7129. 'apply_articale' => $apply_articale,
  7130. 'chat' => $chat,
  7131. 'chat_group' => $chat_group,
  7132. 'good' => $good,
  7133. 'book' => $book,
  7134. 'count' => $count,
  7135. ];
  7136. } elseif ($type_id == 13) {
  7137. //最近的5篇已审的文章
  7138. $apply_articale = Article::where('status', 1)
  7139. ->where('admin_user_id', $user_id)
  7140. ->limit(5)->get();
  7141. //获取5条单聊未读聊天消息
  7142. $chat = ChatRecords::where('is_read', 0)
  7143. ->where('user_id', $user_id)
  7144. ->where('talk_type', 1)
  7145. ->orderBy('created_at', 'desc')
  7146. ->limit(5)->get();
  7147. //获取5条未读群聊信息
  7148. $chat_group = ChatRecords::where('is_read', 0)
  7149. ->where('user_id', $user_id)
  7150. ->where('talk_type', 2)
  7151. ->orderBy('created_at', 'desc')
  7152. ->limit(5)->get();
  7153. //获取5条用户的已审核商品
  7154. $good = Good::where('status', 2)
  7155. ->where('user_id', $user_id)
  7156. ->orderBy('updated_at', 'desc')
  7157. ->limit(5)->get();
  7158. //count($chat) + count($chat_group) +
  7159. $count = count($apply_articale) + count($good);
  7160. $result = [
  7161. 'apply_articale' => $apply_articale,
  7162. 'chat' => $chat,
  7163. 'chat_group' => $chat_group,
  7164. 'good' => $good,
  7165. 'count' => $count,
  7166. ];
  7167. } elseif ($type_id == 14) {
  7168. //最近的5篇已审的文章
  7169. $apply_articale = Article::where('status', 1)
  7170. ->where('admin_user_id', $user_id)
  7171. // ->limit(5)
  7172. ->get();
  7173. //获取5条用户的已审核商品
  7174. $good = Good::where('status', 2)
  7175. ->where('user_id', $user_id)
  7176. ->orderBy('updated_at', 'desc')
  7177. // ->limit(5)
  7178. ->get();
  7179. $count = count($apply_articale) + count($good);
  7180. $result = [
  7181. 'apply_articale' => $apply_articale,
  7182. 'chat' => '',
  7183. 'chat_group' => '',
  7184. 'good' => $good,
  7185. 'count' => $count,
  7186. ];
  7187. } elseif ($type_id == 10000) {
  7188. //获取未审核的5篇文章
  7189. $apply_articale = Article::where('status', 0)
  7190. ->orderBy('updated_at', 'desc')
  7191. // ->limit(5)
  7192. ->get();
  7193. //获取5条单聊未读聊天消息
  7194. //获取5条单聊未读聊天消息
  7195. // $chat = ChatRecords::where('is_read', 0)
  7196. // ->where('user_id', $user_id)
  7197. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7198. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7199. // ->where('action', 'recieved')
  7200. // ->where('talk_type', 1)
  7201. // ->orderBy('created_at', 'desc')
  7202. // // ->limit(5)
  7203. // ->get();
  7204. // //获取5条未读群聊信息
  7205. // $chat_group = ChatRecords::where('is_read', 0)
  7206. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7207. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7208. // ->where('user_id', $user_id)
  7209. // ->where('talk_type', 2)
  7210. // ->orderBy('created_at', 'desc')
  7211. // // ->limit(5)
  7212. // ->get();
  7213. //获取5条用户的已审核商品
  7214. $good = Good::where('status', 1)
  7215. // ->where('user_id', $user_id)
  7216. ->orderBy('updated_at', 'desc')
  7217. // ->limit(5)
  7218. ->get();
  7219. //获取5条用户待审核的公告
  7220. $notice = Notice::where('status', 1)
  7221. ->orderBy('updated_at', 'desc')
  7222. // ->limit(5)
  7223. ->get();
  7224. //获取5条用户的待审核投诉
  7225. $complaint = Complaint::where('status', 1)
  7226. ->orderBy('updated_at', 'desc')
  7227. // ->limit(5)
  7228. ->get();
  7229. //获取5条用户的book
  7230. $book = Book::where('status', 1)
  7231. ->orderBy('updated_at', 'desc')
  7232. // ->limit(5)
  7233. ->get();
  7234. //获取5条用户的求职 1
  7235. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7236. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7237. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7238. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7239. ->orderBy('updated_at', 'desc')
  7240. // ->limit(5)
  7241. ->get();
  7242. //获取5条用户的求职 2
  7243. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7244. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7245. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7246. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7247. ->orderBy('updated_at', 'desc')
  7248. // ->limit(5)
  7249. ->get();
  7250. //人才库 1
  7251. $job_apply = JobApply::where('job_apply.status', 1)
  7252. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7253. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7254. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7255. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7256. ->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')
  7257. ->orderBy('updated_at', 'desc')
  7258. // ->limit(5)
  7259. ->get();
  7260. // 职场机会 2
  7261. $job_resume = JobResume::where('job_resume.status', 1)
  7262. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7263. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7264. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7265. ->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')
  7266. ->orderBy('updated_at', 'desc')
  7267. // ->limit(5)
  7268. ->get();
  7269. //待审核数据com pro
  7270. $complany = Company::where('status', 0)
  7271. ->orderBy('updated_at', 'desc')
  7272. // ->limit(5)
  7273. ->get();
  7274. $project = Project::where('status', 0)
  7275. ->orderBy('updated_at', 'desc')
  7276. // ->limit(5)
  7277. ->get();
  7278. $count =
  7279. // count($chat) +
  7280. // count($chat_group) +
  7281. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7282. // + count($job_apply)
  7283. // + count($job_resume)
  7284. + count($complany)
  7285. + count($project);
  7286. $result = [
  7287. 'apply_articale' => $apply_articale,
  7288. // 'chat' => $chat,
  7289. // 'chat_group' => $chat_group,
  7290. 'good' => $good,
  7291. 'notice' => $notice,
  7292. 'complaint' => $complaint,
  7293. 'book' => $book,
  7294. 'job_hunting' => $job_hunting,
  7295. 'job_recruiting' => $job_recruiting,
  7296. 'job_apply' => $job_apply,
  7297. 'job_resume' => $job_resume,
  7298. 'complany' => $complany,
  7299. 'project' => $project,
  7300. 'count' => $count,
  7301. ];
  7302. } elseif ($type_id == 20000) {
  7303. }
  7304. var_dump($type_id, '-----------------test---------');
  7305. return Result::success($result);
  7306. }
  7307. /**
  7308. * @param array $data
  7309. * @return array
  7310. */
  7311. public function getWebsiteProject(array $data): array
  7312. {
  7313. $categorys = json_decode($data['id'], true);
  7314. if (!empty($categorys)) {
  7315. $category_arr = $this->processArticlePro($data['website_id']);
  7316. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7317. $catiall = $category_arr['catiall'];
  7318. // return Result::success($catiall);
  7319. foreach ($categorys as $key => $val) {
  7320. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7321. $level = explode(',', $val['level'])[0];
  7322. $imgnum = explode(',', $val['level'])[1] ?? null;
  7323. $textnum = explode(',', $val['level'])[2] ?? null;
  7324. if ($level == 1) {
  7325. if (!empty($textnum) && $textnum > 0) {
  7326. $text_num = Project::where('level', $level)
  7327. ->where('website_id', $data['website_id'])
  7328. ->where('status', 1)
  7329. ->select(
  7330. 'project.id',
  7331. 'project.title',
  7332. 'project.description',
  7333. 'project.updated_at',
  7334. 'project.category_id',
  7335. 'project.cat_arr_id'
  7336. )
  7337. ->orderBy('updated_at', 'desc')
  7338. ->limit($textnum)
  7339. ->get()->all();
  7340. }
  7341. if (!empty($imgnum) && $imgnum > 0) {
  7342. $img_num = Project::where('level', $level)
  7343. ->where('website_id', $data['website_id'])
  7344. ->where('status', 1)
  7345. ->where('imgurl', '!=', '')
  7346. ->whereNotNull('imgurl')
  7347. ->select(
  7348. 'project.id',
  7349. 'project.title',
  7350. 'project.description',
  7351. 'project.updated_at',
  7352. 'project.imgurl as imgs',
  7353. 'project.category_id',
  7354. 'project.cat_arr_id'
  7355. )
  7356. ->orderBy('updated_at', 'desc')
  7357. ->limit($imgnum)
  7358. ->get()->all();
  7359. }
  7360. } else {
  7361. if (!empty($textnum) && $textnum > 0) {
  7362. $text_num = Project::where('website_id', $data['website_id'])
  7363. ->where('status', 1)
  7364. ->select(
  7365. 'project.id',
  7366. 'project.title',
  7367. 'project.description',
  7368. 'project.updated_at',
  7369. 'project.category_id',
  7370. 'project.cat_arr_id',
  7371. 'project.website_id',
  7372. 'project.updated_at',
  7373. 'project.created_at'
  7374. )
  7375. ->orderBy('updated_at', 'desc')
  7376. ->limit($textnum)
  7377. ->get()->all();
  7378. }
  7379. if (!empty($imgnum) && $imgnum > 0) {
  7380. $img_num = Project::where('website_id', $data['website_id'])
  7381. ->where('status', 1)
  7382. ->where('imgurl', '!=', '')
  7383. ->whereNotNull('imgurl')
  7384. ->select(
  7385. 'project.id',
  7386. 'project.title',
  7387. 'project.description',
  7388. 'project.updated_at',
  7389. 'project.imgurl as imgs',
  7390. 'project.category_id',
  7391. 'project.cat_arr_id'
  7392. )
  7393. ->orderBy('updated_at', 'desc')
  7394. ->limit($imgnum)
  7395. ->get()->all();
  7396. }
  7397. }
  7398. }
  7399. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7400. $category_ids = explode(',', $val['id'])[0];
  7401. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7402. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7403. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7404. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7405. $text_num = Project::whereIn('category_id', $category_arr)
  7406. ->where('website_id', $data['website_id'])
  7407. ->where('status', 1)
  7408. ->select(
  7409. 'project.id',
  7410. 'project.title',
  7411. 'project.description',
  7412. 'project.updated_at',
  7413. 'project.category_id',
  7414. 'project.cat_arr_id'
  7415. )
  7416. ->orderBy('updated_at', 'desc')
  7417. ->limit($cat_textnum)
  7418. ->get()->all();
  7419. }
  7420. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7421. $img_num = Project::whereIn('category_id', $category_arr)
  7422. ->where('website_id', $data['website_id'])
  7423. ->where('status', 1)
  7424. ->where('imgurl', '!=', '')
  7425. ->whereNotNull('imgurl')
  7426. ->select(
  7427. 'project.id',
  7428. 'project.title',
  7429. 'project.description',
  7430. 'project.updated_at',
  7431. 'project.imgurl as imgs',
  7432. 'project.category_id',
  7433. 'project.cat_arr_id'
  7434. )
  7435. ->orderBy('updated_at', 'desc')
  7436. ->limit($cat_imgnum)
  7437. ->get()->all();
  7438. }
  7439. }
  7440. if (!empty($img_num)) {
  7441. foreach ($img_num as $k => $v) {
  7442. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7443. $imgurl = json_decode($v['imgs'], true);
  7444. if (!empty($imgurl)) {
  7445. $img_num[$k]->imgurl = $imgurl[0];
  7446. }
  7447. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7448. }
  7449. }
  7450. if (!empty($text_num)) {
  7451. foreach ($text_num as $k => $v) {
  7452. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7453. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7454. }
  7455. }
  7456. $project[$key]['img_num'] = $img_num ?? [];
  7457. $project[$key]['text_num'] = $text_num ?? [];
  7458. }
  7459. }
  7460. if (empty($project)) {
  7461. return Result::error("暂无相关项目信息", 0);
  7462. }
  7463. return Result::success($project);
  7464. }
  7465. /**
  7466. * @param array $data
  7467. * @return array
  7468. */
  7469. public function getWebsiteProjectInfo(array $data): array
  7470. {
  7471. $project = Project::where('id', $data['id'])
  7472. ->where('status', 1)
  7473. ->where('website_id', $data['website_id'])
  7474. ->select('project.*')
  7475. ->first();
  7476. if (empty($project)) {
  7477. return Result::error("暂无相关项目信息", 0);
  7478. }
  7479. return Result::success($project);
  7480. }
  7481. /**
  7482. * @param array $data
  7483. * @return array
  7484. */
  7485. public function getWebsiteProjectList(array $data): array
  7486. {
  7487. $where = [];
  7488. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7489. $where['category_id'] = $data['category_id'];
  7490. }
  7491. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7492. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7493. }
  7494. $query = Project::where($where)
  7495. ->where('status', 1)
  7496. ->where('website_id', $data['website_id'])
  7497. ->select(
  7498. 'project.id',
  7499. 'project.title',
  7500. 'project.description',
  7501. 'project.imgurl as imgs',
  7502. 'project.category_id',
  7503. 'project.cat_arr_id'
  7504. )
  7505. ->orderBy('updated_at', 'desc');
  7506. $count = $query->count();
  7507. $project = $query->clone()
  7508. ->offset(($data['page'] - 1) * $data['pageSize'])
  7509. ->limit($data['pageSize'])
  7510. ->get()->all();
  7511. if (empty($project)) {
  7512. return Result::error("暂无相关项目信息", 0);
  7513. }
  7514. $categorys = $this->processArticlePro($data['website_id']);
  7515. $catiall = $categorys['catiall'];
  7516. foreach ($project as $key => $val) {
  7517. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7518. if (!empty($val['imgs'])) {
  7519. $imgurl = json_decode($val['imgs'], true);
  7520. if (!empty($imgurl)) {
  7521. $project[$key]->imgurl = $imgurl[0];
  7522. }
  7523. } else {
  7524. $project[$key]->imgurl = '';
  7525. }
  7526. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7527. }
  7528. $result = [
  7529. 'rows' => $project,
  7530. 'count' => $count,
  7531. ];
  7532. return Result::success($result);
  7533. }
  7534. /**
  7535. * @param array $data
  7536. * @return array
  7537. */
  7538. public function getWebsiteCategoryJob(array $data): array
  7539. {
  7540. $categorys = json_decode($data['id'], true);
  7541. if (!empty($categorys)) {
  7542. $category_arr = $this->processArticlePro($data['website_id']);
  7543. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7544. $catiall = $category_arr['catiall'];
  7545. foreach ($categorys as $key => $val) {
  7546. if (isset($val['id']) && !empty($val['id'])) {
  7547. $catid = explode(',', $val['id'])[0] ?? null;
  7548. $type = explode(',', $val['id'])[1] ?? null;
  7549. $textnum = explode(',', $val['id'])[2] ?? null;
  7550. }
  7551. // 4:招聘;5:求职;
  7552. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7553. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7554. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7555. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7556. ->where('job_recruiting.status', 1)
  7557. ->where('job_recruiting.website_id', $data['website_id'])
  7558. ->select(
  7559. 'job_recruiting.id',
  7560. 'job_recruiting.title',
  7561. 'job_company.business_name',
  7562. 'job_recruiting.updated_at',
  7563. 'job_recruiting.cat_arr_id'
  7564. )
  7565. ->orderBy('job_recruiting.updated_at', 'desc')
  7566. ->limit($textnum)
  7567. ->get()->all();
  7568. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7569. // 状态 审核状态,1待审核2已审核3已拒绝
  7570. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7571. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7572. ->where('job_hunting.status', 2)
  7573. ->where('job_hunting.website_id', $data['website_id'])
  7574. ->select(
  7575. 'job_hunting.id',
  7576. 'job_hunting.name',
  7577. 'job_hunting.cat_arr_id',
  7578. 'job_position.zwname as job_name',
  7579. 'job_hunting.updated_at'
  7580. )
  7581. ->orderBy('updated_at', 'desc')
  7582. ->limit($textnum)
  7583. ->get()->all();
  7584. } else {
  7585. $job = [];
  7586. }
  7587. // var_dump($catid.'222uuuuuuu'.$key);
  7588. if (!empty($job)) {
  7589. foreach ($job as $k => $value) {
  7590. if (isset($value->cat_arr_id)) {
  7591. $catArr = json_decode($value->cat_arr_id, true);
  7592. $catId = end($catArr);
  7593. } else {
  7594. continue;
  7595. }
  7596. if (isset($catiall[$catId])) {
  7597. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7598. }
  7599. }
  7600. }
  7601. // var_dump($catid.'xxxxx'.$key);
  7602. $result[$key] = $job ?? [];
  7603. }
  7604. }
  7605. if (empty($result)) {
  7606. return Result::error("暂无相关分类信息", 0);
  7607. }
  7608. return Result::success($result);
  7609. }
  7610. /**
  7611. * 发送消息
  7612. * @param array $messageData
  7613. * @return void
  7614. */
  7615. public function sendMessage($messageData)
  7616. {
  7617. $msg = [
  7618. 'talk_type' => $messageData['talk_type'],
  7619. 'title' => $messageData['title'],
  7620. 'content' => $messageData['content'],
  7621. 'messageType' => $messageData['messageType'],
  7622. 'user_id' => $messageData['user_id'] ?? '',
  7623. 'time' => microtime(),
  7624. ];
  7625. $message = new MqProducer($msg);
  7626. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7627. $producer->produce($message);
  7628. }
  7629. }