NewsService.php 265 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441
  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. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  64. class NewsService implements NewsServiceInterface
  65. {
  66. #[Inject]
  67. protected Redis $redis;
  68. /**
  69. * 获取导航池列表
  70. * @param array $data
  71. * @return array
  72. */
  73. public function getCategoryList(array $data): array
  74. {
  75. $search = $data['name'] ?? '';
  76. $page = (int)($data['page'] ?? 1);
  77. $perPage = (int)($data['pageSize'] ?? 10);
  78. // 1. 查出所有匹配的分类id
  79. if ($search) {
  80. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  81. if (empty($matchedIds)) {
  82. return Result::success(['rows' => [], 'total' => 0]);
  83. }
  84. // 2. 递归查所有父级,直到一级分类
  85. $idsStr = implode(',', $matchedIds);
  86. $sql = "
  87. WITH RECURSIVE parents AS (
  88. SELECT * FROM category WHERE id IN ($idsStr)
  89. UNION ALL
  90. SELECT c.* FROM category c
  91. INNER JOIN parents p ON c.id = p.pid
  92. )
  93. SELECT * FROM parents
  94. ";
  95. $parents = Db::select($sql);
  96. $parentIds = [];
  97. foreach ($parents as $row) {
  98. if ($row->pid == 0) {
  99. $parentIds[] = $row->id;
  100. }
  101. }
  102. $parentIds = array_unique($parentIds);
  103. } else {
  104. // 没有搜索,一级分类就是根
  105. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  106. }
  107. // 3. 一级分类分页
  108. $total = count($parentIds);
  109. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  110. if (empty($parentIds)) {
  111. return Result::success(['rows' => [], 'total' => $total]);
  112. }
  113. // 4. 递归查所有子孙
  114. $idsStr = implode(',', $parentIds);
  115. $sql = "
  116. WITH RECURSIVE subcategories AS (
  117. SELECT * FROM category WHERE id IN ($idsStr)
  118. UNION ALL
  119. SELECT c.* FROM category c
  120. INNER JOIN subcategories s ON c.pid = s.id
  121. )
  122. SELECT * FROM subcategories ORDER BY updated_at DESC
  123. ";
  124. $allCategories = Db::select($sql);
  125. // 5. 组装树结构
  126. $categoryMap = [];
  127. foreach ($allCategories as $cat) {
  128. $cat = (array)$cat;
  129. $cat['children'] = [];
  130. $categoryMap[$cat['id']] = $cat;
  131. }
  132. foreach ($categoryMap as $id => &$cat) {
  133. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  134. $categoryMap[$cat['pid']]['children'][] = &$cat;
  135. }
  136. }
  137. unset($cat);
  138. $categoryTree = [];
  139. foreach ($parentIds as $id) {
  140. if (isset($categoryMap[$id])) {
  141. $categoryTree[] = $categoryMap[$id];
  142. }
  143. }
  144. return Result::success([
  145. 'rows' => $categoryTree,
  146. 'total' => $total,
  147. ]);
  148. }
  149. private function findMatchedCategories($search)
  150. {
  151. if ($search) {
  152. return Category::where('name', 'like', "%{$search}%")
  153. ->orderBy('updated_at', 'desc')
  154. ->get();
  155. }
  156. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  157. ->get();
  158. }
  159. private function findAllParents($categories)
  160. {
  161. $allCategories = [];
  162. foreach ($categories as $category) {
  163. $parentId = $category->pid;
  164. while ($parentId > 0) {
  165. $parent = Category::find($parentId);
  166. if ($parent) {
  167. $allCategories[$parent->id] = $parent;
  168. $parentId = $parent->pid;
  169. } else {
  170. break;
  171. }
  172. }
  173. $allCategories[$category->id] = $category;
  174. }
  175. return array_values($allCategories);
  176. }
  177. private function buildCategoryTree($category, $allRequiredCategories)
  178. {
  179. $categoryData = $category->toArray();
  180. $children = [];
  181. foreach ($allRequiredCategories as $c) {
  182. if ($c->pid === $category->id) {
  183. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  184. }
  185. }
  186. if (!empty($children)) {
  187. $categoryData['children'] = $children;
  188. }
  189. return $categoryData;
  190. }
  191. public function myCategoryList(array $data): array
  192. {
  193. $sszq = $data['sszq'] ?? '';
  194. unset($data['sszq']);
  195. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  196. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  197. $where[] = [
  198. 'pid',
  199. '=',
  200. $data['pid'],
  201. ];
  202. if (isset($data['name'])) {
  203. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  204. }
  205. var_dump($where);
  206. //根据分类id,从category表中取出分类信息
  207. $result = Category::where($where)
  208. ->whereIn('category.id', $catorytids)
  209. ->select('category.*', 'category.id as category_id')->get();
  210. if (empty($result)) {
  211. return Result::error("没有栏目数据");
  212. }
  213. return Result::success($result);
  214. }
  215. /**
  216. * @param array $data
  217. * @return array
  218. */
  219. public function categoryList(array $data): array
  220. {
  221. $where[] = [
  222. 'pid',
  223. '=',
  224. $data['pid']
  225. ];
  226. if (isset($data['name'])) {
  227. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  228. }
  229. var_dump($where);
  230. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  231. if (empty($result)) {
  232. return Result::error("没有栏目数据");
  233. }
  234. return Result::success($result);
  235. }
  236. /**
  237. * @param array $data
  238. * @return array
  239. */
  240. public function addCategory(array $data): array
  241. {
  242. if (isset($data['id'])) {
  243. unset($data['id']);
  244. }
  245. $id = Category::insertGetId($data);
  246. if (empty($id)) {
  247. return Result::error("添加失败");
  248. }
  249. return Result::success(['id' => $id]);
  250. }
  251. /**
  252. * @param array $data
  253. * @return array
  254. */
  255. public function delCategory(array $data): array
  256. {
  257. Db::beginTransaction();
  258. try {
  259. $categoryList = Category::where(['pid' => $data['id']])->get();
  260. if ($categoryList->toArray()) {
  261. Db::rollBack();
  262. return Result::error("分类下面有子分类不能删除");
  263. }
  264. $articleList = Article::where(['catid' => $data['id']])->get();
  265. if ($articleList->toArray()) {
  266. Db::rollBack();
  267. return Result::error("分类下面有资讯不能删除");
  268. }
  269. $result = Category::where($data)->delete();
  270. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  271. if (!$result) {
  272. Db::rollBack();
  273. return Result::error("删除失败");
  274. }
  275. Db::commit();
  276. return Result::success($result);
  277. } catch (\Exception $e) {
  278. Db::rollBack();
  279. return Result::error("删除失败" . $e->getMessage());
  280. }
  281. }
  282. /**
  283. * @param array $data
  284. * @return array
  285. */
  286. public function updateCategory(array $data): array
  287. {
  288. $where = [
  289. 'id' => $data['id'],
  290. ];
  291. $result = Category::where($where)->update($data);
  292. if ($result) {
  293. return Result::success($result);
  294. } else {
  295. return Result::error("更新失败");
  296. }
  297. }
  298. /**
  299. * 获取导航池信息
  300. * @param array $data
  301. * @return array
  302. */
  303. public function getCategoryInfo(array $data): array
  304. {
  305. $where = [
  306. 'id' => $data['id'],
  307. ];
  308. $result = Category::where($where)->first();
  309. if ($result) {
  310. return Result::success($result);
  311. } else {
  312. return Result::error("更新失败");
  313. }
  314. }
  315. /**
  316. * @param array $data
  317. * @return array
  318. */
  319. public function getArticleList(array $data): array
  320. {
  321. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  322. $type_id = $data['type_id'];
  323. unset($data['type_id']);
  324. $user_id = $data['user_id'];
  325. unset($data['user_id']);
  326. $where = [];
  327. $status1 = [];
  328. if (isset($data['id']) && $data['id']) {
  329. array_push($where, ['article.id', '=', $data['id']]);
  330. }
  331. if (isset($data['title']) && $data['title']) {
  332. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  333. }
  334. if (isset($data['category_name']) && $data['category_name']) {
  335. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  336. }
  337. if (isset($data['author']) && $data['author']) {
  338. array_push($where, ['article.author', '=', $data['author']]);
  339. }
  340. if (isset($data['islink']) && $data['islink'] !== "") {
  341. array_push($where, ['article.islink', '=', $data['islink']]);
  342. }
  343. if (isset($data['status']) && $data['status'] !== "") {
  344. array_push($where, ['article.status', '=', $data['status']]);
  345. }
  346. if (isset($data['status1'])) {
  347. $status1 = json_decode(($data['status1']));
  348. }
  349. //不是管理员展示个人数据;
  350. if ($type_id != 10000) {
  351. $where[] = ['article.admin_user_id', '=', $user_id];
  352. }
  353. $rep = Article::where($where)
  354. ->whereNotIn('article.status', [404])
  355. ->when($status1, function ($query) use ($status1) {
  356. if (isset($status1) && $status1) {
  357. $query->whereIn('article.status', $status1);
  358. }
  359. })
  360. ->leftJoin('category', 'article.catid', 'category.id')
  361. ->leftJoin('website_category', function ($join) {
  362. $join->on('article.web_site_id', '=', 'website_category.website_id')
  363. ->on('article.catid', '=', 'website_category.category_id');
  364. })
  365. ->select("article.*", "category.name as category_name", "website_category.alias")
  366. ->orderBy("article.updated_at", "desc")
  367. ->limit($data['pageSize'])
  368. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  369. $count = Article::where($where)->whereNotIn('article.status', [404])
  370. ->when($status1, function ($query) use ($status1) {
  371. if (isset($status1) && $status1) {
  372. $query->whereIn('article.status', $status1);
  373. }
  374. })
  375. ->leftJoin('category', 'article.catid', 'category.id')->count();
  376. $data = [
  377. 'rows' => $rep->toArray(),
  378. 'count' => $count,
  379. ];
  380. if (empty($rep)) {
  381. return Result::error("没有信息数据");
  382. }
  383. return Result::success($data);
  384. }
  385. /**
  386. * @param array $data
  387. * @return array
  388. */
  389. public function addArticle(array $data): array
  390. {
  391. var_dump($data, '----------12-----------1');
  392. unset($data['user_type']);
  393. unset($data['nav_add_pool_id']);
  394. // unset($data['commend_id']);
  395. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  396. Db::beginTransaction();
  397. try {
  398. //处理投票
  399. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  400. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  401. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  402. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  403. unset($data['is_survey']);
  404. unset($data['survey_name']);
  405. unset($data['suvey_array']);
  406. // unset($data['website_id']);
  407. // unset($data['web_site_id']);
  408. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  409. if ($data['hits'] == '') {
  410. $data['hits'] = 0;
  411. }
  412. if ($data['is_original'] == '') {
  413. $data['is_original'] = 0;
  414. }
  415. if ($data['status'] == '') {
  416. $data['status'] = 0;
  417. }
  418. $articleData = $data;
  419. unset($articleData['content']);
  420. //自动处理缩略图、关键字、描述
  421. if ($articleData['imgurl'] == '') {
  422. //如果没有图,设置level=0
  423. $levelArr = json_decode($articleData['level'], true);
  424. var_dump($levelArr, '----------levelArr-----------1');
  425. //content中提取图片第一个图,正则提取
  426. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  427. preg_match_all($reg, $data['content'], $matches);
  428. if (isset($matches[1][0])) {
  429. //截取varchar240
  430. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  431. //如果有图,设置level=3
  432. if (!in_array(3, $levelArr)) {
  433. $levelArr[] = 3;
  434. }
  435. $articleData['level'] = json_encode($levelArr);
  436. } else {
  437. if (!in_array(0, $levelArr)) {
  438. $levelArr[] = 0;
  439. }
  440. $articleData['level'] = json_encode($levelArr);
  441. }
  442. }
  443. var_dump($articleData['level'], '----------$articleData[level]----------1');
  444. if ($articleData['keyword'] == '') {
  445. //提取标题+内容中的关键词
  446. $articleData['keyword'] = $data['title'];
  447. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  448. Jieba::init(); // 初始化 jieba-php
  449. Finalseg::init();
  450. $segList = Jieba::cut($articleData['keyword']);
  451. $segList1 = array_slice($segList, 0, 8);
  452. $articleData['keyword'] = implode(',', $segList1);
  453. }
  454. if ($articleData['introduce'] == '') {
  455. //提取内容中的描述
  456. $content = $data['content'];
  457. // 去除 <style> 和 <script> 标签及其内容
  458. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  459. // 去除所有 HTML 标签
  460. $content = strip_tags($content);
  461. // 去除 HTML 实体
  462. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  463. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  464. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  465. // 去除多余空白
  466. $content = preg_replace('/\s+/u', '', $content);
  467. // 截取 100 个字符
  468. $articleData['introduce'] = mb_substr($content, 0, 100);
  469. }
  470. if ($articleData['status'] == 0) {
  471. $this->sendMessage([
  472. 'talk_type' => 100,
  473. 'title' => $articleData['title'],
  474. 'content' => '提交了审核',
  475. 'messageType' => 2,
  476. ]);
  477. }
  478. $id = Article::insertGetId($articleData);
  479. $articleDataContent = [
  480. 'article_id' => $id,
  481. 'content' => $data['content'],
  482. ];
  483. ArticleData::insertGetId($articleDataContent);
  484. //处理投票
  485. if ($is_survey == 1) {
  486. //生成年月日时分秒+8位随机数
  487. $uuid = date('YmdHis') . rand(10000000, 99999999);
  488. var_dump($suvey_array, 'suvey_array________');
  489. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  490. var_dump($suveys_array, '---------------------1');
  491. var_dump($suvey_array, '---------------------2');
  492. $suvey_data = [];
  493. foreach ($suveys_array as $key => $value) {
  494. if ($value == '') {
  495. continue;
  496. }
  497. if (is_array($value)) {
  498. $suvey_data[] = [
  499. 'sur_id' => $uuid,
  500. 'art_id' => $id,
  501. 'website_id' => $website_id ?? 2,
  502. 'survey_name' => $survey_name,
  503. 'choice_name' => $value[1],
  504. 'is_other' => 1,
  505. 'other_id' => 0,
  506. 'results' => 0,
  507. ];
  508. } else {
  509. $suvey_data[] = [
  510. 'sur_id' => $uuid,
  511. 'art_id' => $id,
  512. 'website_id' => $website_id ?? 2,
  513. 'survey_name' => $survey_name,
  514. 'choice_name' => $value,
  515. 'is_other' => 0,
  516. 'other_id' => 0,
  517. 'results' => 0,
  518. ];
  519. }
  520. if (empty($suvey_data)) {
  521. throw new \Exception("投票数据为空");
  522. }
  523. }
  524. $result = ArticleSurvey::insert($suvey_data);
  525. if (!$result) {
  526. throw new \Exception("投票失败,ArticleSurvey插入失败");
  527. }
  528. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  529. if (!$result) {
  530. throw new \Exception("投票失败,更新主表失败");
  531. }
  532. }
  533. Db::commit();
  534. return Result::success(['id' => $id]);
  535. } catch (\Throwable $ex) {
  536. Db::rollBack();
  537. var_dump($ex->getMessage());
  538. return Result::error("创建失败", 0);
  539. }
  540. }
  541. /**
  542. * @param array $data
  543. * @return array
  544. */
  545. public function delArticle(array $data): array
  546. {
  547. $result = Article::where($data)->delete();
  548. //survey投票删除
  549. articleSurvey::where(['art_id' => $data['id']])->delete();
  550. if (!$result) {
  551. return Result::error("删除失败");
  552. }
  553. return Result::success($result);
  554. }
  555. /**
  556. * @param array $data
  557. * @return array
  558. */
  559. public function updateArticle(array $data): array
  560. {
  561. var_dump($data, '----------12-----------1');
  562. Db::beginTransaction();
  563. unset($data['user_type']);
  564. // unset($data['web_site_id']);
  565. unset($data['nav_add_pool_id']);
  566. try {
  567. //处理投票
  568. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  569. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  570. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  571. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  572. unset($data['is_survey']);
  573. unset($data['survey_name']);
  574. unset($data['suvey_array']);
  575. unset($data['website_id']);
  576. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  577. if ($data['hits'] == '') {
  578. $data['hits'] = 0;
  579. }
  580. if ($data['is_original'] == '') {
  581. $data['is_original'] = 0;
  582. }
  583. if ($data['status'] == '') {
  584. $data['status'] = 0;
  585. }
  586. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  587. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  588. $articleData = $data;
  589. unset($articleData['content']);
  590. unset($articleData['status_name']);
  591. unset($articleData['name']);
  592. unset($articleData['content']);
  593. unset($articleData['pid_arr']);
  594. unset($articleData['pid']);
  595. //自动处理缩略图、关键字、描述
  596. if ($articleData['imgurl'] == '') {
  597. //如果没有图,设置level=0
  598. $levelArr = json_decode($articleData['level'], true);
  599. var_dump($levelArr, '----------levelArr-----------1');
  600. //content中提取图片第一个图,正则提取
  601. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  602. preg_match_all($reg, $data['content'], $matches);
  603. if (isset($matches[1][0])) {
  604. //截取varchar240
  605. // 截取到第一个<
  606. $articleData['imgurl'] = $matches[1][0];
  607. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  608. $pos = strpos($articleData['imgurl'], '"');
  609. if ($pos !== false) {
  610. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  611. }
  612. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  613. //如果有图,设置level=3
  614. if (!in_array(3, $levelArr)) {
  615. $levelArr[] = 3;
  616. }
  617. $articleData['level'] = json_encode($levelArr);
  618. } else {
  619. if (!in_array(0, $levelArr)) {
  620. $levelArr[] = 0;
  621. }
  622. $articleData['level'] = json_encode($levelArr);
  623. }
  624. }
  625. var_dump($articleData['level'], '----------$articleData[level]----------1');
  626. if ($articleData['keyword'] == '') {
  627. //提取标题+内容中的关键词
  628. $articleData['keyword'] = $data['title'];
  629. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  630. Jieba::init(); // 初始化 jieba-php
  631. Finalseg::init();
  632. $segList = Jieba::cut($articleData['keyword']);
  633. $segList1 = array_slice($segList, 0, 8);
  634. $articleData['keyword'] = implode(',', $segList1);
  635. }
  636. if ($articleData['introduce'] == '') {
  637. //提取内容中的描述
  638. $content = $data['content'];
  639. // 去除 <style> 和 <script> 标签及其内容
  640. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  641. // 去除所有 HTML 标签
  642. $content = strip_tags($content);
  643. // 去除 HTML 实体
  644. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  645. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  646. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  647. // 去除多余空白
  648. $content = preg_replace('/\s+/u', '', $content);
  649. // 截取 100 个字符
  650. $articleData['introduce'] = mb_substr($content, 0, 100);
  651. }
  652. if ($articleData['status'] == 0) {
  653. $this->sendMessage([
  654. 'talk_type' => 100,
  655. 'title' => $articleData['title'],
  656. 'content' => '提交了审核',
  657. 'messageType' => 2,
  658. ]);
  659. }
  660. $id = Article::where(['id' => $data['id']])->update($articleData);
  661. $articleDataContent = [
  662. 'content' => $data['content'],
  663. ];
  664. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  665. //处理投票
  666. $id = $data['id'];
  667. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  668. var_dump($suvey_array, 'suvey_array________delete');
  669. //处理投票
  670. if ($is_survey == 1) {
  671. //生成年月日时分秒+8位随机数
  672. $uuid = date('YmdHis') . rand(10000000, 99999999);
  673. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  674. var_dump($suveys_array, '---------------------1');
  675. $suvey_data = [];
  676. if (is_array($suveys_array)) {
  677. foreach ($suveys_array as $key => $value) {
  678. if ($value == '') {
  679. continue;
  680. }
  681. if (is_array($value)) {
  682. $suvey_data[] = [
  683. 'sur_id' => $uuid,
  684. 'art_id' => $id,
  685. 'website_id' => $website_id ?? 2,
  686. 'survey_name' => $survey_name,
  687. 'choice_name' => $value[1],
  688. 'is_other' => 1,
  689. 'other_id' => 0,
  690. 'results' => 0,
  691. ];
  692. } else {
  693. $suvey_data[] = [
  694. 'sur_id' => $uuid,
  695. 'art_id' => $id,
  696. 'website_id' => $website_id ?? 2,
  697. 'survey_name' => $survey_name,
  698. 'choice_name' => $value,
  699. 'is_other' => 0,
  700. 'other_id' => 0,
  701. 'results' => 0,
  702. ];
  703. }
  704. if (empty($suvey_data)) {
  705. throw new \Exception("投票数据为空");
  706. }
  707. }
  708. }
  709. $result = ArticleSurvey::insert($suvey_data);
  710. if (!$result) {
  711. throw new \Exception("投票失败");
  712. }
  713. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  714. if (!$result) {
  715. throw new \Exception("投票失败");
  716. }
  717. } else {
  718. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  719. }
  720. Db::commit();
  721. return Result::success([]);
  722. } catch (\Throwable $ex) {
  723. Db::rollBack();
  724. var_dump($ex->getMessage());
  725. return Result::error("更新失败" . $ex->getMessage(), 0);
  726. }
  727. }
  728. /**
  729. * 更新资讯状态
  730. * @param array $data
  731. * @return array
  732. */
  733. public function upArticleStatus(array $data): array
  734. {
  735. $articleData = Article::where(['id' => $data['id']])->first();
  736. if ($data['status'] == 1) {
  737. $this->sendMessage([
  738. 'talk_type' => 101,
  739. 'title' => $articleData['title'],
  740. 'content' => '审核通过',
  741. 'messageType' => 2,
  742. 'user_id' => $articleData['admin_user_id'],
  743. ]);
  744. }
  745. if ($data['status'] == 2) {
  746. $this->sendMessage([
  747. 'talk_type' => 101,
  748. 'title' => $articleData['title'],
  749. 'content' => '审核拒绝',
  750. 'messageType' => 2,
  751. 'user_id' => $articleData['admin_user_id'],
  752. ]);
  753. }
  754. $result = Article::where(['id' => $data['id']])->update($data);
  755. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  756. //article_ignore 表插入数据 db操作
  757. //转成数组
  758. //删掉数据重新写入
  759. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  760. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  761. $insert_data = [];
  762. foreach ($website_ids as $key => $value) {
  763. $insert_data[] = [
  764. 'article_id' => $data['id'],
  765. 'website_id' => $value,
  766. ];
  767. }
  768. DB::table('article_ignore')->insert($insert_data);
  769. }
  770. if ($result) {
  771. return Result::success();
  772. } else {
  773. return Result::error("更新状态失败", 0);
  774. }
  775. }
  776. /**
  777. * 获取新闻详情
  778. * @param array $data
  779. * @return array
  780. */
  781. public function getArticleInfo(array $data): array
  782. {
  783. $where = [
  784. 'article.id' => $data['id'],
  785. // 'article.status' => 1,
  786. ];
  787. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  788. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  789. $info = $result;
  790. // var_dump($info, 'info');
  791. $info['survey_array'] = $articleSurvey;
  792. if ($result) {
  793. return Result::success($info);
  794. } else {
  795. return Result::error("查询失败", 0);
  796. }
  797. }
  798. /**
  799. * 获取头条新闻
  800. * @param array $data
  801. * @return array
  802. */
  803. public function getWebsiteArticlett(array $data): array
  804. {
  805. $website_id = $data['website_id'];
  806. $categorys = $this->processArticlePro($website_id);
  807. $catiall = $categorys['catiall'];
  808. $categoryIds = $categorys['categoryIds'];
  809. $where = [
  810. 'status' => 1
  811. ];
  812. $website_id = $data['website_id'];
  813. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  814. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  815. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  816. switch ($data['level']) {
  817. case 1:
  818. case 2:
  819. case 3:
  820. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  821. $query = Article::where($where)
  822. ->where('level', 'like', '%' . $data['level'] . '%')
  823. ->orderBy('updated_at', 'desc');
  824. break;
  825. case 4: //最新资讯
  826. $query = Article::where($where)->orderBy('updated_at', 'desc');
  827. break;
  828. case 5: //资讯推荐
  829. $query = Article::where($where)
  830. ->where('updated_at', '>', $month);
  831. break;
  832. case 7: //资讯分类
  833. if (isset($data['id']) && !empty($data['id'])) {
  834. $keyword = Article::where('id', $data['id'])->value('keyword');
  835. $keywordArray = explode(',', $keyword);
  836. $whereL7 = [];
  837. foreach ($keywordArray as $k => $v) {
  838. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  839. }
  840. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  841. break;
  842. } else {
  843. return Result::error("请输入资讯ID", 0);
  844. break;
  845. }
  846. default:
  847. break;
  848. }
  849. // $whereL7 = [];
  850. // if(isset($data['id']) && !empty($data['id'])){
  851. // $keyword = Article::where('id', $data['id'])->value('keyword');
  852. // $keywordArray = explode(',', $keyword);
  853. // foreach ($keywordArray as $k => $v) {
  854. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  855. // }
  856. // }
  857. // $query = Article::where($where)
  858. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  859. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  860. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  861. // }
  862. // if($data['level'] == 7){
  863. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  864. // }
  865. // if($data['level'] == 4){
  866. // $query = $query->inRandomOrder()
  867. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  868. // }
  869. // if($data['level'] == 5){
  870. // $query = $query->orderBy('updated_at','desc');
  871. // }
  872. // });
  873. if ($data['textnum'] > 0) {
  874. $query = clone $query;
  875. $result['text'] = $query
  876. ->whereIn('catid', $categoryIds)
  877. ->leftJoinSub(function ($query) use ($website_id) {
  878. $query->from('article_ignore')
  879. ->where('website_id', $website_id);
  880. }, 'article_ignore', function ($join) {
  881. $join->on('article_ignore.article_id', '=', 'article.id');
  882. })
  883. ->where(function ($query) use ($website_id) {
  884. $query->whereNull('article_ignore.article_id')
  885. ->orWhere('article_ignore.website_id', '!=', $website_id);
  886. })
  887. ->select(
  888. 'article.id',
  889. 'article.title',
  890. 'article.author',
  891. 'article.updated_at',
  892. 'article.introduce',
  893. 'article.islink',
  894. 'article.linkurl',
  895. 'article.copyfrom',
  896. 'article.cat_arr_id',
  897. 'article.catid',
  898. 'article.level'
  899. )
  900. ->offset($data['placeid'])
  901. ->limit($data['textnum'])
  902. ->get()->all();
  903. foreach ($result['text'] as $k => $v) {
  904. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  905. }
  906. }
  907. if ($data['imgnum'] > 0) {
  908. $query = clone $query;
  909. $result['img'] = $query
  910. ->whereIn('catid', $categoryIds)
  911. ->where('article.imgurl', '!=', '')
  912. ->select(
  913. 'article.id',
  914. 'article.title',
  915. 'article.imgurl',
  916. 'article.author',
  917. 'article.updated_at',
  918. 'article.introduce',
  919. 'article.islink',
  920. 'article.linkurl',
  921. 'article.copyfrom',
  922. 'article.cat_arr_id',
  923. 'article.catid',
  924. 'article.level'
  925. )
  926. ->offset($data['placeid'])
  927. ->limit($data['imgnum'])
  928. ->get()->all();
  929. foreach ($result['img'] as $k => $v) {
  930. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  931. }
  932. }
  933. if (empty($result)) {
  934. return Result::error("暂无相关资讯", 0);
  935. }
  936. return Result::success($result);
  937. }
  938. /**
  939. * 获取模块新闻
  940. * @param array $data
  941. * @return array
  942. */
  943. public function getWebsiteModelArticles(array $data): array
  944. {
  945. $catid = $data['catid'];
  946. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  947. $category = $category->toArray();
  948. if (!empty($category)) {
  949. $where = [
  950. 'status' => 1,
  951. 'catid' => $catid,
  952. ];
  953. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  954. // 1:文字新闻;2:轮播图;3:图文;
  955. // 级别:0:未分类
  956. // 3:推荐图片
  957. if ($data['level'] == 1) {
  958. $data['level'] = 0;
  959. }
  960. $result = Article::where($where)
  961. ->where(function ($query) use ($data) {
  962. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  963. ->orWhereNull("level")
  964. ->orWhereRaw("level = '[]'");
  965. })
  966. ->where(function ($query) use ($data) {
  967. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  968. ->orWhereNull("ignore_ids");
  969. })
  970. ->orderBy("updated_at", "desc")
  971. ->offset($placeid)
  972. ->limit($data['pagesize'])
  973. ->get();
  974. if (empty($result)) {
  975. return Result::error("此栏目暂无相关新闻", 0);
  976. }
  977. } else {
  978. return Result::error("此网站暂无此栏目", 0);
  979. }
  980. return Result::success($result);
  981. }
  982. /**
  983. *获取新闻列表
  984. * @param array $data
  985. * @return array
  986. */
  987. public function getWebsiteArticleList(array $data): array
  988. {
  989. // return Result::success($data);
  990. $where[] = ['status', '=', 1];
  991. $website_id = $data['website_id'];
  992. if (isset($data['catid']) && !empty($data['catid'])) {
  993. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  994. if (empty($category)) {
  995. return Result::error("此网站暂无此栏目", 0);
  996. }
  997. array_push($where, ['catid', '=', $data['catid']]);
  998. }
  999. // return Result::success($where);
  1000. $query = Article::where($where)
  1001. ->leftJoinSub(function ($query) use ($website_id) {
  1002. $query->from('article_ignore')
  1003. ->where('website_id', $website_id);
  1004. }, 'article_ignore', function ($join) {
  1005. $join->on('article_ignore.article_id', '=', 'article.id');
  1006. })
  1007. ->where(function ($query) use ($website_id) {
  1008. $query->whereNull('article_ignore.article_id')
  1009. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1010. })
  1011. ->select(
  1012. 'article.id',
  1013. 'article.title',
  1014. 'article.imgurl',
  1015. 'article.author',
  1016. 'article.updated_at',
  1017. 'article.introduce',
  1018. 'article.islink',
  1019. 'article.linkurl',
  1020. 'article.copyfrom',
  1021. 'article.cat_arr_id',
  1022. 'article.catid'
  1023. );
  1024. $count = $query->count();
  1025. $rep = $query->orderBy("updated_at", "desc")
  1026. ->offset(($data['page'] - 1) * $data['pageSize'])
  1027. ->limit($data['pageSize'])
  1028. ->get()->all();
  1029. $categorys = $this->processArticlePro($website_id);
  1030. $cat_1st_arr = $categorys['cat_1st_arr'];
  1031. $catiall = $categorys['catiall'];
  1032. // $web['website_id'] = $data['website_id'];
  1033. foreach ($rep as $k => $v) {
  1034. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1035. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1036. }
  1037. // $rep = $this->processArticles($rep,$web);
  1038. $data = [
  1039. 'rows' => $rep,
  1040. 'count' => $count,
  1041. ];
  1042. if (empty($rep)) {
  1043. return Result::error("没有信息数据");
  1044. }
  1045. return Result::success($data);
  1046. }
  1047. /**
  1048. * 前端-获取新闻详情
  1049. * @param array $data
  1050. * @return array
  1051. */
  1052. public function selectWebsiteArticleInfo(array $data): array
  1053. {
  1054. $where = [
  1055. 'article.id' => $data['id'],
  1056. 'article.status' => 1,
  1057. ];
  1058. $result = Article::where($where)
  1059. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1060. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1061. ->where(function ($query) use ($data) {
  1062. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1063. ->orWhereNull("ignore_ids");
  1064. })
  1065. ->select(
  1066. 'article.*',
  1067. 'article_data.content',
  1068. 'article_data.article_id',
  1069. 'article_extend.website_url',
  1070. 'article_extend.email',
  1071. 'article_extend.contacts',
  1072. 'article_extend.contacts_mobile',
  1073. 'article_extend.contacts_address',
  1074. 'article_extend.zip_code',
  1075. 'article_extend.enterprise_name'
  1076. )
  1077. ->first();
  1078. if (empty($result)) {
  1079. return Result::error("暂无此新闻!", 0);
  1080. }
  1081. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1082. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1083. ->where('website_category.website_id', $data['website_id'])
  1084. ->where(['website_category.category_id' => $result['catid']])
  1085. ->first();
  1086. if (empty($category)) {
  1087. return Result::error("查询失败", 0);
  1088. }
  1089. //手动推荐文章
  1090. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1091. $commendArticle = Article::whereIn('id', $commend_ids)
  1092. ->where('status', 1)
  1093. ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
  1094. ->orderBy('updated_at', 'desc')
  1095. ->limit(5)
  1096. ->get();
  1097. $result['category_id'] = $category['category_id'];
  1098. $result['cat_name'] = $category['alias'];
  1099. $result['website_name'] = $category['website_name'] ?? "";
  1100. $result['suffix'] = $category['suffix'] ?? "";
  1101. $result['commendArticle'] = $commendArticle;
  1102. return Result::success($result);
  1103. }
  1104. /**
  1105. * 前端-获取网站调查问卷
  1106. * @param array $data
  1107. * @return array
  1108. */
  1109. public function getWebsiteSurvey(array $data): array
  1110. {
  1111. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1112. $website = Website::where('id', $data['website_id'])->first();
  1113. if (empty($website)) {
  1114. return Result::error("暂无此网站", 0);
  1115. }
  1116. }
  1117. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1118. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1119. if (empty($article)) {
  1120. return Result::error("暂无此文章", 0);
  1121. }
  1122. // return Result::error($data,0);
  1123. $where['art_id'] = $data['art_id'];
  1124. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1125. } else {
  1126. $survey = Article::where(function ($query) {
  1127. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1128. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1129. })
  1130. ->where('status', 1)
  1131. ->where('is_survey', 1)
  1132. ->select('survey_id')
  1133. ->orderBy('updated_at', 'desc')
  1134. ->first();
  1135. if (empty($survey)) {
  1136. return Result::error("暂无调查问卷", 0);
  1137. }
  1138. $where['sur_id'] = $survey['survey_id'];
  1139. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1140. }
  1141. // return Result::success($where);
  1142. $result = ArticleSurvey::where($where)
  1143. ->where(function ($query) {
  1144. $query->where('is_other', 0)
  1145. ->orWhere(function ($subQuery) {
  1146. $subQuery->where('is_other', 1)
  1147. ->where('other_id', 0);
  1148. });
  1149. })
  1150. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1151. ->select('article_survey.*', 'article.survey_type')
  1152. ->get()->all();
  1153. if (empty($result)) {
  1154. return Result::error("此文章暂无调查问卷", 0);
  1155. }
  1156. return Result::success($result);
  1157. }
  1158. /**
  1159. * 前端-添加网站调查问卷选项
  1160. * @param array $data
  1161. * @return array
  1162. */
  1163. public function addWebsiteSurveyOption(array $data): array
  1164. {
  1165. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1166. $website = Website::where('id', $data['website_id'])->first();
  1167. if (empty($website)) {
  1168. return Result::error("暂无此网站", 0);
  1169. }
  1170. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1171. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1172. if (empty($survey)) {
  1173. return Result::error("此调查问卷不可添加选项", 0);
  1174. }
  1175. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1176. $choice = [
  1177. 'art_id' => $survey['art_id'],
  1178. 'website_id' => $data['website_id'],
  1179. 'survey_name' => $survey['survey_name'],
  1180. 'choice_name' => $data['choice_name'],
  1181. 'sur_id' => $survey['sur_id'],
  1182. 'is_other' => 1,
  1183. 'other_id' => $survey['id'],
  1184. ];
  1185. $result = ArticleSurvey::insertGetId($choice);
  1186. if (empty($result)) {
  1187. return Result::error("添加失败", 0);
  1188. }
  1189. return Result::success($result);
  1190. }
  1191. }
  1192. return Result::error("添加失败", 0);
  1193. }
  1194. return Result::error("添加失败", 0);
  1195. }
  1196. /**
  1197. * 前端-调查问卷投票
  1198. * @param array $data
  1199. * @return array
  1200. */
  1201. public function addWebsiteSurveyVote(array $data): array
  1202. {
  1203. // return Result::success($data);
  1204. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1205. $website = Website::where('id', $data['website_id'])->first();
  1206. if (empty($website)) {
  1207. return Result::error("暂无此网站", 0);
  1208. }
  1209. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1210. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1211. // return Result::success($survey);
  1212. if (empty($is_survey)) {
  1213. return Result::error("此调查问卷不存在", 0);
  1214. }
  1215. // return Result::success($survey);
  1216. // 调查问卷类型
  1217. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1218. //多选 若是json型则转化成数组类型
  1219. if (strpos($data['choice_id'], '[') === 0) {
  1220. $data['choice_id'] = json_decode($data['choice_id'], true);
  1221. } else {
  1222. // 单选 也转换成数组
  1223. $data['choice_id'] = [$data['choice_id']];
  1224. }
  1225. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1226. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1227. // ->where('website_id',$data['website_id'])
  1228. ->where('is_other', 1)
  1229. ->where('other_id', 0)
  1230. ->first();
  1231. if (!empty($other)) {
  1232. return Result::error("请选择已有的选项!", 0);
  1233. }
  1234. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1235. // ->where('website_id',$data['website_id'])
  1236. ->where('is_other', 1)
  1237. ->where('other_id', '!=', 0)
  1238. ->first();
  1239. // return Result::success($choice['other']);
  1240. $choice_id = $data['choice_id'];
  1241. if (!empty($choice['other'])) {
  1242. // array_push($data['choice_id'],$choice['other']['other_id']);
  1243. if (!empty($choice_id)) {
  1244. $key = array_search($choice['other']['id'], $choice_id);
  1245. if ($key !== false) {
  1246. unset($choice_id[$key]);
  1247. $choice_id = array_values($choice_id);
  1248. }
  1249. array_push($choice_id, $choice['other']['other_id']);
  1250. } else {
  1251. $choice_id[0] = $choice['other']['other_id'];
  1252. }
  1253. array_push($data['choice_id'], $choice['other']['other_id']);
  1254. }
  1255. // return Result::success($data);
  1256. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1257. // ->where('website_id',$data['website_id'])
  1258. ->increment('results', 1);
  1259. if (empty($choice)) {
  1260. return Result::error("请选择已有的选项!", 0);
  1261. }
  1262. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1263. // ->where('website_id',$data['website_id'])
  1264. ->where('other_id', 0)
  1265. ->get();
  1266. $survey['choice'] = $choice_id;
  1267. return Result::success($survey);
  1268. }
  1269. return Result::error("参数必填!");
  1270. }
  1271. return Result::error("此调查问卷不存在", 0);
  1272. }
  1273. return Result::error("参数必填!");
  1274. }
  1275. /**
  1276. * 后端-获取网站调查问卷列表
  1277. * @param array $data
  1278. * @return array
  1279. */
  1280. public function getSurveyList(array $data): array
  1281. {
  1282. $where = [];
  1283. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1284. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1285. }
  1286. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1287. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1288. }
  1289. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1290. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1291. }
  1292. // return Result::success($where);
  1293. if (!empty($where)) {
  1294. $query = Article::where($where)->where(function ($q) {
  1295. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1296. });
  1297. } else {
  1298. $query = Article::where(function ($q) {
  1299. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1300. });
  1301. }
  1302. $count = $query->count();
  1303. $survey = $query->orderByDesc('id')
  1304. ->limit($data['pageSize'])
  1305. ->offset(($data['page'] - 1) * $data['pageSize'])
  1306. ->get();
  1307. if (empty($survey->toArray())) {
  1308. return Result::error("暂无调查问卷!", 0);
  1309. }
  1310. $result = [
  1311. 'rows' => $survey,
  1312. 'count' => $count,
  1313. ];
  1314. return Result::success($result);
  1315. }
  1316. /**
  1317. * 后端-获取网站调查问卷详情
  1318. * @param array $data
  1319. * @return array
  1320. */
  1321. public function getSurveyInfo(array $data): array
  1322. {
  1323. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1324. $where = ['sur_id' => $data['sur_id']];
  1325. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1326. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1327. ->select('article_survey.*', 'article.survey_type')
  1328. ->get()->all();
  1329. if (empty($choose)) {
  1330. return Result::error("此调查问卷不存在", 0);
  1331. }
  1332. $resultsArray = array_column($choose, 'results');
  1333. $total = array_sum($resultsArray);
  1334. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1335. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1336. // $total = 0;
  1337. if (!empty($other)) {
  1338. $total = $total + $other['results'];
  1339. $other['choice_name'] = '(其他)';
  1340. if (!empty($others)) {
  1341. $other['hasChildren'] = true;
  1342. // array_push($other,['hasChildren','=',true]);
  1343. $other['children'] = $others;
  1344. $other_choices = [$other->toArray()];
  1345. $mer_choice = array_merge($choose, $other_choices);
  1346. $value_choice = array_values($mer_choice);
  1347. } else {
  1348. // return Result::error('1111');
  1349. $other_choices = [$other->toArray()];
  1350. $other_choices = array_merge($choose, $other_choices);
  1351. $value_choice = array_values($other_choices);
  1352. // return Result::success($result);
  1353. }
  1354. } else {
  1355. $value_choice = $choose;
  1356. }
  1357. $result = [
  1358. 'choose' => $value_choice,
  1359. 'total' => $total,
  1360. ];
  1361. }
  1362. return Result::success($result);
  1363. }
  1364. /**
  1365. * 前端-搜索新闻列表
  1366. * @param array $data
  1367. * @return array
  1368. */
  1369. public function selectWebsiteArticle(array $data): array
  1370. {
  1371. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1372. $website_id = $data['website_id'];
  1373. $categorys = $this->processArticlePro($website_id);
  1374. $catiall = $categorys['catiall'];
  1375. $query = Article::where('status', 1)
  1376. ->whereIn('catid', $category)
  1377. ->leftJoinSub(function ($query) use ($website_id) {
  1378. $query->from('article_ignore')
  1379. ->where('website_id', $website_id);
  1380. }, 'article_ignore', function ($join) {
  1381. $join->on('article_ignore.article_id', '=', 'article.id');
  1382. })
  1383. ->where(function ($query) use ($website_id) {
  1384. $query->whereNull('article_ignore.article_id')
  1385. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1386. });
  1387. // return Result::success($all_articles);
  1388. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1389. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1390. }
  1391. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1392. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1393. }
  1394. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1395. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1396. }
  1397. // 计算总数
  1398. $count = $query->count();
  1399. // 分页查询
  1400. $articles = $query
  1401. ->select(
  1402. 'article.id',
  1403. 'article.title',
  1404. 'article.imgurl',
  1405. 'article.author',
  1406. 'article.updated_at',
  1407. 'article.introduce',
  1408. 'article.islink',
  1409. 'article.linkurl',
  1410. 'article.copyfrom',
  1411. 'article.cat_arr_id',
  1412. 'article.catid',
  1413. 'article.department_arr_id',
  1414. 'article.city_arr_id',
  1415. )
  1416. ->orderBy("updated_at", "desc")
  1417. ->offset(($data['page'] - 1) * $data['pageSize'])
  1418. ->limit($data['pageSize'])
  1419. ->get();
  1420. foreach ($articles as $k => $v) {
  1421. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1422. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1423. }
  1424. if (empty($articles)) {
  1425. return Result::error("没有符合条件的资讯数据");
  1426. }
  1427. $result = [
  1428. 'rows' => $articles,
  1429. 'count' => $count,
  1430. ];
  1431. return Result::success($result);
  1432. }
  1433. /**
  1434. * 模块新闻加强版
  1435. * @param array $data
  1436. * @return array
  1437. */
  1438. public function getWebsiteCatidArticle(array $data): array
  1439. {
  1440. $where = [
  1441. 'website_category.category_id' => $data['catid'],
  1442. 'website_category.website_id' => $data['website_id'],
  1443. ];
  1444. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1445. $child_catnum = $data['child_catnum'] ?? 1;
  1446. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1447. $childCategoryIds = array_column($category['child'], 'category_id');
  1448. if (empty($childCategoryIds)) {
  1449. return Result::error("暂无子栏目", 0);
  1450. }
  1451. $imgArticles = [];
  1452. $textArticles = [];
  1453. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1454. // 初始化子分类图片新闻和文字新闻数组
  1455. // 查询所有子级栏目的图文新闻
  1456. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1457. ->where(function ($query) use ($data) {
  1458. $query->where(function ($subQuery) use ($data) {
  1459. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1460. })->orWhereNull("ignore_ids");
  1461. })
  1462. ->where('status', 1)
  1463. ->where('imgurl', '!=', '')
  1464. ->select('*')
  1465. ->orderBy('updated_at', 'desc')
  1466. ->limit($data['child_imgnum'])
  1467. ->get();
  1468. }
  1469. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1470. // 查询所有子级栏目的文字新闻
  1471. $textArticles = Article::where('catid', $childCategoryIds[0])
  1472. ->where('status', 1)
  1473. ->where(function ($query) use ($data) {
  1474. $query->where(function ($subQuery) use ($data) {
  1475. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1476. })->orWhereNull("ignore_ids");
  1477. })
  1478. ->select('*')
  1479. ->orderBy('updated_at', 'desc')
  1480. ->limit($data['child_textnum'])
  1481. ->get();
  1482. }
  1483. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1484. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1485. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1486. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1487. return $child;
  1488. }, $category['child']);
  1489. }
  1490. // }
  1491. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1492. $category['img'] = WebsiteCategory::where($where)
  1493. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1494. ->where('article.status', 1)
  1495. ->where('article.imgurl', '!=', '')
  1496. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1497. ->orderBy('article.updated_at', 'desc')
  1498. ->limit($data['img_num'])
  1499. ->get();
  1500. }
  1501. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1502. $category['text'] = WebsiteCategory::where($where)
  1503. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1504. ->where('article.status', 1)
  1505. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1506. ->orderBy('article.updated_at', 'desc')
  1507. ->limit($data['text_num'])
  1508. ->get();
  1509. }
  1510. // $category = $category->get();
  1511. if (empty($category)) {
  1512. return Result::error("查询失败", 0);
  1513. }
  1514. return Result::success($category);
  1515. }
  1516. /**
  1517. * 模块新闻加强plus版
  1518. * @param array $data
  1519. * @return array
  1520. */
  1521. public function getWebsiteAllArticle(array $data): array
  1522. {
  1523. $time1 = microtime(true);
  1524. $wetbsite_id = $data['website_id'] ?? 2;
  1525. $data = json_decode($data['id'], true);
  1526. $categorys = $this->processArticlePro($wetbsite_id);
  1527. $cat_1st_arr = $categorys['cat_1st_arr'];
  1528. $catiall = $categorys['catiall'];
  1529. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1530. $parent_category = array_column($data, 'parent');
  1531. $parent_cat = [];
  1532. $child_category = array_column($data, 'child');
  1533. if (!empty($parent_category)) {
  1534. foreach ($parent_category as $key => $value) {
  1535. $arr = array_map('intval', explode(',', $value));
  1536. $parent_cat[$key] = $arr[0] ?? 0;
  1537. $parent_category = $arr[0] ?? 0;
  1538. $article_imgnum = $arr[1] ?? 0;
  1539. $article_textnum = $arr[2] ?? 0;
  1540. if ($parent_category != 0) {
  1541. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1542. // return Result::success($category_arr);
  1543. if ($article_imgnum != 0) {
  1544. $img_article = Article::whereIn('catid', $category_arr)
  1545. ->where('status', 1)
  1546. ->where('imgurl', '!=', '')
  1547. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1548. $query->from('article_ignore')
  1549. ->where('website_id', $wetbsite_id);
  1550. }, 'article_ignore', function ($join) {
  1551. $join->on('article_ignore.article_id', '=', 'article.id');
  1552. })
  1553. ->where(function ($query) use ($wetbsite_id) {
  1554. $query->whereNull('article_ignore.article_id')
  1555. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1556. })
  1557. ->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')
  1558. ->orderBy('updated_at', 'desc')
  1559. ->limit($article_imgnum)
  1560. ->get()->all();
  1561. foreach ($img_article as $k => $v) {
  1562. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1563. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1564. }
  1565. } else {
  1566. $img_article = [];
  1567. }
  1568. if ($article_textnum != 0) {
  1569. $text_article = Article::whereIn('catid', $category_arr)
  1570. ->where('status', 1)
  1571. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1572. $query->from('article_ignore')
  1573. ->where('website_id', $wetbsite_id);
  1574. }, 'article_ignore', function ($join) {
  1575. $join->on('article_ignore.article_id', '=', 'article.id');
  1576. })
  1577. ->where(function ($query) use ($wetbsite_id) {
  1578. $query->whereNull('article_ignore.article_id')
  1579. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1580. })
  1581. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1582. ->orderBy('updated_at', 'desc')
  1583. ->limit($article_textnum)
  1584. ->get()->all();
  1585. foreach ($text_article as $k => $v) {
  1586. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1587. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1588. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1589. }
  1590. } else {
  1591. $text_article = [];
  1592. }
  1593. $catiall[$parent_category]['imgnum'] = $img_article;
  1594. $catiall[$parent_category]['textnum'] = $text_article;
  1595. $parent[$key] = $catiall[$parent_category];
  1596. } else {
  1597. $parent[$key] = '';
  1598. }
  1599. }
  1600. }
  1601. if (!empty($child_category)) {
  1602. foreach ($child_category as $key => $value) {
  1603. $arr = array_map('intval', explode(',', $value));
  1604. $parent_category = $parent_cat[$key];
  1605. $child_category = $arr[0] ?? 0;
  1606. $article_imgnum = $arr[1] ?? 0;
  1607. $article_textnum = $arr[2] ?? 0;
  1608. if ($child_category != 0) {
  1609. $all_childcat = $cat_1st_arr[$parent_category];
  1610. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1611. // 从 $websiteInfoIndexed 中获取对应的数据
  1612. $info = $websiteInfoIndexed[$v];
  1613. // 返回一个包含所需信息的数组
  1614. return [
  1615. 'alias' => $info->alias,
  1616. 'category_id' => $info->category_id,
  1617. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1618. 'pid' => $info->pid,
  1619. 'type' => $info->type,
  1620. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1621. 'pinyin' => $info->pinyin,
  1622. ];
  1623. }, $all_childcat);
  1624. if ($article_imgnum != 0) {
  1625. $img_article = Article::where('catid', $child_category)
  1626. ->where('status', 1)
  1627. ->where('imgurl', '!=', '')
  1628. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1629. $query->from('article_ignore')
  1630. ->where('website_id', $wetbsite_id);
  1631. }, 'article_ignore', function ($join) {
  1632. $join->on('article_ignore.article_id', '=', 'article.id');
  1633. })
  1634. ->where(function ($query) use ($wetbsite_id) {
  1635. $query->whereNull('article_ignore.article_id')
  1636. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1637. })
  1638. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1639. ->orderBy('updated_at', 'desc')
  1640. ->limit($article_imgnum)
  1641. ->get()->all();
  1642. foreach ($img_article as $k => $v) {
  1643. // var_dump($v);
  1644. // var_dump($k);
  1645. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1646. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1647. }
  1648. } else {
  1649. $img_article = [];
  1650. }
  1651. if ($article_textnum != 0) {
  1652. $text_article = Article::where('catid', $child_category)
  1653. ->where('status', 1)
  1654. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1655. $query->from('article_ignore')
  1656. ->where('website_id', $wetbsite_id);
  1657. }, 'article_ignore', function ($join) {
  1658. $join->on('article_ignore.article_id', '=', 'article.id');
  1659. })
  1660. ->where(function ($query) use ($wetbsite_id) {
  1661. $query->whereNull('article_ignore.article_id')
  1662. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1663. })
  1664. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1665. ->orderBy('updated_at', 'desc')
  1666. ->limit($article_textnum)
  1667. ->get()->all();
  1668. foreach ($text_article as $k => $v) {
  1669. // var_dump($v);
  1670. // var_dump($k);
  1671. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1672. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1673. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1674. }
  1675. } else {
  1676. $text_article = [];
  1677. }
  1678. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1679. $catiall[$child_category]['imgnum'] = $img_article;
  1680. $catiall[$child_category]['textnum'] = $text_article;
  1681. $child[$key] = $catiall[$child_category];
  1682. // var_dump($pids);
  1683. } else {
  1684. $child[$key] = '';
  1685. }
  1686. }
  1687. }
  1688. foreach ($parent as $key => $value) {
  1689. $result[$key] = $value;
  1690. if (!empty($child[$key])) {
  1691. // var_dump($child[$key]);
  1692. $result[$key]['child'] = $child[$key];
  1693. // $value[$key]['child'] = $child[$key];
  1694. } else {
  1695. $result[$key]['child'] = [
  1696. "alias" => null,
  1697. "category_id" => null,
  1698. "type" => null,
  1699. "pinyin" => null,
  1700. "all_childcat" => [],
  1701. "imgnum" => [],
  1702. "textnum" => []
  1703. ];
  1704. }
  1705. }
  1706. return Result::success($result);
  1707. }
  1708. /**
  1709. * 辅助方法:获取文章列表
  1710. */
  1711. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1712. {
  1713. sleep(1);
  1714. $query = Article::where('article.status', 1)
  1715. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1716. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1717. ->where(function ($query) use ($website) {
  1718. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1719. })
  1720. ->leftJoin('website_category', function ($join) use ($website) {
  1721. $join->on('article.catid', '=', 'website_category.category_id')
  1722. ->where('website_category.website_id', '=', $website['website_id']);
  1723. })
  1724. ->select(
  1725. 'article.id',
  1726. 'article.title',
  1727. 'article.imgurl',
  1728. 'article.author',
  1729. 'article.updated_at',
  1730. 'article.introduce',
  1731. 'article.islink',
  1732. 'article.linkurl',
  1733. 'article.copyfrom',
  1734. 'article.cat_arr_id',
  1735. 'article.catid',
  1736. 'website_category.alias as category_name'
  1737. )
  1738. ->orderBy('updated_at', 'desc')
  1739. ->limit($limit);
  1740. // 如果是图片文章,添加图片URL条件
  1741. if ($isImageArticle) {
  1742. $query->where('imgurl', '!=', '');
  1743. } else {
  1744. // 文字文章不需要imgurl字段
  1745. $query->addSelect('article.introduce');
  1746. }
  1747. $articles = $query->get();
  1748. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1749. }
  1750. /**
  1751. * 乡村网-获取特殊新闻模块
  1752. * @param array $data
  1753. * @return array
  1754. */
  1755. public function getWebsiteArticles(array $data): array
  1756. {
  1757. $website_id = $data['website_id'];
  1758. $catids = json_decode($data['id'], true);
  1759. $parent_category = array_column($catids, 'parent');
  1760. if (!empty($parent_category) && is_array($parent_category)) {
  1761. $categorys = $this->processArticlePro($website_id);
  1762. $catiall = $categorys['catiall'];
  1763. $cat_1st_arr = $categorys['cat_1st_arr'];
  1764. // return Result::success($categorys);
  1765. foreach ($parent_category as $key => $value) {
  1766. $arr = array_map('intval', explode(',', $value));
  1767. $parent_category = $arr[0] ?? 0;
  1768. $article_imgnum = $arr[1] ?? 0;
  1769. $article_textnum = $arr[2] ?? 0;
  1770. if ($parent_category != 0) {
  1771. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1772. // return Result::success($category_arr);
  1773. if ($article_imgnum != 0) {
  1774. $img_article = Article::whereIn('catid', $category_arr)
  1775. ->where('status', 1)
  1776. ->where('imgurl', '!=', '')
  1777. ->leftJoinSub(function ($query) use ($website_id) {
  1778. $query->from('article_ignore')
  1779. ->where('website_id', $website_id);
  1780. }, 'article_ignore', function ($join) {
  1781. $join->on('article_ignore.article_id', '=', 'article.id');
  1782. })
  1783. ->where(function ($query) use ($website_id) {
  1784. $query->whereNull('article_ignore.article_id')
  1785. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1786. })
  1787. ->select(
  1788. 'id',
  1789. 'title',
  1790. 'imgurl',
  1791. 'author',
  1792. 'updated_at',
  1793. 'introduce',
  1794. 'islink',
  1795. 'linkurl',
  1796. 'copyfrom',
  1797. 'cat_arr_id',
  1798. 'catid as category_id'
  1799. )
  1800. ->orderBy('updated_at', 'desc')
  1801. ->limit($article_imgnum)
  1802. ->get()->all();
  1803. foreach ($img_article as $k => $v) {
  1804. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1805. // return Result::success($v);
  1806. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1807. }
  1808. } else {
  1809. $img_article = [];
  1810. }
  1811. if ($article_textnum != 0) {
  1812. $text_article = Article::whereIn('catid', $category_arr)
  1813. ->where('status', 1)
  1814. ->leftJoinSub(function ($query) use ($website_id) {
  1815. $query->from('article_ignore')
  1816. ->where('website_id', $website_id);
  1817. }, 'article_ignore', function ($join) {
  1818. $join->on('article_ignore.article_id', '=', 'article.id');
  1819. })
  1820. ->where(function ($query) use ($website_id) {
  1821. $query->whereNull('article_ignore.article_id')
  1822. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1823. })
  1824. ->select(
  1825. 'id',
  1826. 'title',
  1827. 'author',
  1828. 'updated_at',
  1829. 'introduce',
  1830. 'islink',
  1831. 'linkurl',
  1832. 'copyfrom',
  1833. 'cat_arr_id',
  1834. 'catid as category_id'
  1835. )
  1836. ->orderBy('updated_at', 'desc')
  1837. ->limit($article_textnum)
  1838. ->get()->all();
  1839. foreach ($text_article as $k => $v) {
  1840. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1841. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1842. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1843. }
  1844. } else {
  1845. $text_article = [];
  1846. }
  1847. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  1848. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  1849. $parent[$key] = $catiall[$parent_category];
  1850. } else {
  1851. $parent[$key] = [];
  1852. }
  1853. }
  1854. }
  1855. return Result::success($parent);
  1856. }
  1857. // 封装处理商品的路由问题
  1858. function processGoods($goods, $data)
  1859. {
  1860. return $goods->map(function ($good) use ($data) {
  1861. $catid = $good->catid ?? 0;
  1862. // $pinyin = '';
  1863. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1864. if (!empty($category->pid) && $category->pid != 0) {
  1865. $level = json_decode($category->category_arr_id, true);
  1866. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1867. ->whereIn('category_id', $level)
  1868. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1869. ->get(['aLIas_pinyin'])
  1870. ->pluck('aLIas_pinyin')
  1871. ->implode('/');
  1872. } else {
  1873. $pinyin = $category->aLIas_pinyin ?? '';
  1874. }
  1875. if (isset($good->city_id) && !empty($good->city_id)) {
  1876. $city = District::where('id', $good->city_id)->first(['name']);
  1877. $good->city_name = $city->name ?? '';
  1878. }
  1879. // 解析imgurl JSON并取第一条数据
  1880. $imgUrls = json_decode($good->imgurl, true);
  1881. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1882. $good->pinyin = $pinyin;
  1883. return $good;
  1884. });
  1885. }
  1886. /**
  1887. * 获取商城首页-根据栏目id
  1888. * @param array $data
  1889. * @return array
  1890. * */
  1891. function getWebsiteCatidshop(array $data): array
  1892. {
  1893. $input['catid'] = $data['catid'];
  1894. $input['website_id'] = $data['website_id'];
  1895. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1896. $result = array_map(function ($item) use ($input) {
  1897. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1898. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1899. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1900. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1901. if (empty($category) || $category->type != 2) {
  1902. return Result::error("暂无此栏目", 0);
  1903. } else {
  1904. $website['website_id'] = $input['website_id'];
  1905. $goods = Good::where('good.status', 2)
  1906. ->where('good.website_id', $website['website_id'])
  1907. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1908. ->select(
  1909. 'good.id',
  1910. 'good.name',
  1911. 'good.imgurl',
  1912. 'good.description',
  1913. 'good.updated_at',
  1914. 'good.catid',
  1915. 'good.type_id',
  1916. 'good.price',
  1917. 'good.com',
  1918. 'good.level',
  1919. 'good.unit'
  1920. )
  1921. ->orderBy('updated_at', 'desc')
  1922. ->offset($goodStart)
  1923. ->limit($goodNum);
  1924. $all_goods = $goods->get();
  1925. $all_goods = $this->processGoods($all_goods, $website);
  1926. }
  1927. return $all_goods ?? [];
  1928. }
  1929. }, $data);
  1930. return Result::success($result);
  1931. }
  1932. /**
  1933. * 获取商品模块
  1934. * @param array $data
  1935. * @return array
  1936. * */
  1937. public function getWebsiteshop(array $data): array
  1938. {
  1939. $input['id'] = $data['id'];
  1940. $input['website_id'] = $data['website_id'];
  1941. $catid = $data['catid'];
  1942. $data = json_decode($input['id'] ?? '', true) ?? [];
  1943. $result['goods'] = array_map(function ($item) use ($input) {
  1944. // 检查parent元素是否存在且不是undefined
  1945. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  1946. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  1947. $website = $input['website_id'];
  1948. $query = Good::where('good.status', 2)
  1949. ->where('good.website_id', $website);
  1950. switch ($Levelid) {
  1951. case 1:
  1952. case 2:
  1953. case 3:
  1954. $goods = $query->where(function ($q) use ($Levelid) {
  1955. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  1956. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  1957. });
  1958. break;
  1959. case 4:
  1960. $goods = $query;
  1961. break;
  1962. case 5:
  1963. $goods = $query->where('type_id', 1);
  1964. break;
  1965. case 6:
  1966. $goods = $query->where('type_id', 2);
  1967. break;
  1968. default:
  1969. return [];
  1970. }
  1971. $all_goods = $goods
  1972. ->select(
  1973. 'good.id',
  1974. 'good.name',
  1975. 'good.imgurl',
  1976. 'good.description',
  1977. 'good.updated_at',
  1978. 'good.catid',
  1979. 'good.type_id',
  1980. 'good.price',
  1981. 'good.level',
  1982. 'good.website_id'
  1983. )
  1984. ->orderBy('updated_at', 'desc')
  1985. ->offset($goodStart)
  1986. ->limit($goodNum)
  1987. ->get();
  1988. $web['website_id'] = $website;
  1989. $all_goods = $this->processGoods($all_goods, $web);
  1990. }
  1991. return $all_goods;
  1992. }, $data);
  1993. $website = $input['website_id'];
  1994. $result['article'] = Article::where(function ($query) use ($website) {
  1995. $query->where(function ($subQuery) use ($website) {
  1996. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1997. })->orWhereNull("ignore_ids");
  1998. })
  1999. ->where('catid', $catid)
  2000. ->where('article.status', 1)
  2001. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2002. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2003. ->orderBy('article.updated_at', 'desc')
  2004. ->first();
  2005. return Result::success($result);
  2006. }
  2007. /**
  2008. * 获取商品分类
  2009. * @param array $data
  2010. * @return array
  2011. * */
  2012. public function getWebsiteshopCat(array $data): array
  2013. {
  2014. $website = $data['website_id'];
  2015. $category = WebsiteCategory::where('website_id', $website)
  2016. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2017. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2018. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2019. ->orderBy('sort')
  2020. ->get();
  2021. $cat = $category->map(function ($item) use ($website) {
  2022. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2023. $pid = $item->pid ?? 0;
  2024. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2025. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2026. ->where('website_id', $website)
  2027. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2028. ->get(['aLIas_pinyin'])
  2029. ->pluck('aLIas_pinyin')
  2030. ->implode('/');
  2031. } else {
  2032. $pinyin = $item->aLIas_pinyin ?? '';
  2033. }
  2034. $item->pinyin = $pinyin;
  2035. });
  2036. if (empty($category)) {
  2037. return Result::error("栏目查询失败", 0);
  2038. }
  2039. $cat_tree = Result::buildMenuTree($category);
  2040. $web['website_id'] = $website;
  2041. $goods = Good::where('website_id', $website)
  2042. ->where('status', 2)
  2043. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2044. ->latest('updated_at')
  2045. ->offset(($data['page'] - 1) * $data['pageSize'])
  2046. ->limit($data['pageSize'])
  2047. ->get();
  2048. if (!empty($goods)) {
  2049. if ($goods->count() > 1 && !empty($goods)) {
  2050. $goods = $this->processGoods($goods, $web);
  2051. }
  2052. } else {
  2053. $goods = [];
  2054. }
  2055. $result = [
  2056. 'category' => $cat_tree,
  2057. 'goods' => $goods,
  2058. ];
  2059. // $resul['goods'] = $goods;
  2060. if (empty($result)) {
  2061. return Result::error("查询失败", 0);
  2062. }
  2063. return Result::success($result);
  2064. }
  2065. /*
  2066. * 获取商品列表
  2067. * @param array $data
  2068. * @return array
  2069. * */
  2070. public function getWebsiteshopList(array $data): array
  2071. {
  2072. // return Result::success($data);
  2073. $where = [
  2074. 'status' => 2,
  2075. 'website_id' => $data['website_id'],
  2076. ];
  2077. if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2078. return Result::error("查询失败", 0);
  2079. }
  2080. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2081. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2082. $data['catid'] = $category->category_id ?? 0;
  2083. }
  2084. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2085. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2086. }
  2087. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2088. array_push($where, ['type_id', $data['type_id']]);
  2089. }
  2090. $query = Good::where($where)
  2091. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2092. $query->where(function ($q) use ($data) {
  2093. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2094. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2095. });
  2096. })
  2097. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2098. $query->where(function ($q) use ($data) {
  2099. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2100. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2101. });
  2102. })
  2103. ->select(
  2104. 'good.id',
  2105. 'good.name',
  2106. 'good.imgurl',
  2107. 'good.description',
  2108. 'good.updated_at',
  2109. 'good.com',
  2110. 'good.catid',
  2111. 'good.type_id',
  2112. 'good.website_id',
  2113. 'good.cat_arr_id',
  2114. 'good.created_at',
  2115. 'good.city_id'
  2116. )
  2117. ->latest('updated_at');
  2118. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2119. $result['count'] = $query->clone()->count();
  2120. $result['goods'] = $this->processGoods(
  2121. $query->clone()
  2122. ->offset(($data['page'] - 1) * $data['pageSize'])
  2123. ->limit($data['pageSize'])
  2124. ->get(),
  2125. $data
  2126. );
  2127. } else {
  2128. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2129. // 获取 type_id 为 1 的数据
  2130. $result['type1'] = $this->processGoods(
  2131. $query->clone()
  2132. ->where('type_id', 1)
  2133. ->offset(($data['page'] - 1) * $data['pageSize'])
  2134. ->limit($data['pageSize'])
  2135. ->get(),
  2136. $data
  2137. );
  2138. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2139. // 获取 type_id 为 2 的数据
  2140. $result['type2'] = $this->processGoods(
  2141. $query->clone()
  2142. ->where('type_id', 2)
  2143. ->offset(($data['page'] - 1) * $data['pageSize'])
  2144. ->limit($data['pageSize'])
  2145. ->get(),
  2146. $data
  2147. );
  2148. }
  2149. if (empty($result)) {
  2150. return Result::error("查询失败", 0);
  2151. }
  2152. return Result::success($result);
  2153. }
  2154. /**
  2155. * 获取商品详情
  2156. * @param array $data
  2157. * @return array
  2158. * */
  2159. public function getWebsiteshopInfo(array $data): array
  2160. {
  2161. $where = [
  2162. 'good.status' => 2,
  2163. 'good.website_id' => $data['website_id'],
  2164. 'good.id' => $data['id'],
  2165. ];
  2166. $goods = Good::where($where)
  2167. ->where('good.id', $data['id'])
  2168. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2169. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2170. ->first();
  2171. if (empty($goods)) {
  2172. return Result::error("查询失败", 0);
  2173. }
  2174. $goods->imgurl = json_decode($goods->imgurl, true);
  2175. return Result::success($goods);
  2176. }
  2177. /**
  2178. * plus pro 处理文章路由问题
  2179. */
  2180. function processArticlePro($website_id)
  2181. {
  2182. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2183. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2184. // 取出category_id 对应的aLIas_pinyin
  2185. $categoryIds = array_column($categorys, 'category_id');
  2186. $categoryPIds = array_column($categorys, 'pid');
  2187. $aliasPinyins = array_column($categorys, 'aLIas_pinyin');
  2188. $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2189. // return Result::success($categorys);
  2190. $catiall = [];
  2191. //一级所有子级的记录
  2192. $cat_1st_arr = [];
  2193. foreach ($categorys as $key => $value) {
  2194. $category_arr_id = json_decode($value->category_arr_id);
  2195. $pinyin_str = '';
  2196. // 算出一级 并且算出子级
  2197. if ($value->pid != 0) {
  2198. $cat_1st_arr[$value->pid][] = $value->category_id;
  2199. }
  2200. foreach ($category_arr_id as $k => $v) {
  2201. $pinyin_str .= $cat_arr[$v] . '/';
  2202. }
  2203. $pinyin_str = rtrim($pinyin_str, '/');
  2204. $catiall[$value->category_id]['alias'] = $value->alias;
  2205. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2206. $catiall[$value->category_id]['type'] = $value->type;
  2207. $catiall[$value->category_id]['pinyin'] = $pinyin_str;
  2208. $websiteInfoIndexed[$value->category_id]->pinyin = $pinyin_str;
  2209. }
  2210. return [
  2211. 'cat_1st_arr' => $cat_1st_arr,
  2212. 'catiall' => $catiall,
  2213. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2214. 'categoryIds' => $categoryIds,
  2215. ];
  2216. }
  2217. /**
  2218. * 封装处理文章的路由问题
  2219. * */
  2220. function processArticles($articles, $data)
  2221. {
  2222. // 检查 $articles 是否为数组或可迭代对象
  2223. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2224. return $articles->map(function ($article) use ($data) {
  2225. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2226. $catid = $article->cat_arr_id ?? '';
  2227. }
  2228. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2229. $catid = $article->category_arr_id ?? '';
  2230. }
  2231. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2232. $level = json_decode($catid, true);
  2233. if (!is_array($level)) {
  2234. return $article;
  2235. } else {
  2236. $level = array_map('intval', $level);
  2237. }
  2238. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2239. ->where($data)
  2240. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2241. ->pluck('aLIas_pinyin')
  2242. ->implode('/');
  2243. $article->pinyin = $pinyin ?? '';
  2244. return $article;
  2245. });
  2246. } else {
  2247. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2248. $catid = $articles->cat_arr_id ?? '';
  2249. $level = json_decode($catid, true);
  2250. if (!is_array($level)) {
  2251. return $articles;
  2252. } else {
  2253. $level = array_map('intval', $level);
  2254. }
  2255. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2256. ->where($data)
  2257. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2258. ->pluck('aLIas_pinyin')
  2259. ->implode('/');
  2260. $articles->pinyin = $pinyin ?? '';
  2261. return $articles;
  2262. }
  2263. }
  2264. // 封装处理由问题
  2265. function processJob($job, $data)
  2266. {
  2267. return $job->map(function ($job) use ($data) {
  2268. $category = $job->cat_arr_id ?? '';
  2269. $cityid = $job->city_arr_id ?? '';
  2270. $city = json_decode($cityid, true);
  2271. $pinyin = '';
  2272. $level = json_decode($category, true);
  2273. // 路由
  2274. if (!empty($level) && is_array($level)) {
  2275. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2276. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2277. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2278. ->get(['aLIas_pinyin'])
  2279. ->pluck('aLIas_pinyin')
  2280. ->implode('/');
  2281. if (empty($pinyin)) {
  2282. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2283. }
  2284. $job->pinyin = $pinyin;
  2285. }
  2286. // 取职位-城市 市??省
  2287. if (!empty($city) && is_array($city)) {
  2288. if (isset($city[1]) && !empty($city[1])) {
  2289. $city = District::where('id', $city[1])->first(['name']);
  2290. $job->city_name = $city->name ?? '';
  2291. } else if (isset($city[0]) && !empty($city[0])) {
  2292. $city = District::where('id', $city[0])->first(['name']);
  2293. $job->city_name = $city->name ?? '';
  2294. } else {
  2295. $job->city_name = '全国';
  2296. }
  2297. }
  2298. // 获取简历最后一级地区
  2299. if (isset($job->city_id) && !empty($job->city_id)) {
  2300. $city = District::where('id', $job->city_id)->first(['name']);
  2301. $job->hunt_cityname = $city->name ?? '';
  2302. }
  2303. // 组合详细地址
  2304. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2305. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2306. if (is_array($address_id) && !empty($address_id)) {
  2307. $address = District::whereIn('id', $address_id)
  2308. ->orderBy('level', 'asc')
  2309. ->get(['name'])
  2310. ->pluck('name')
  2311. ->implode('');
  2312. // $job->address_name = $address ?? '';
  2313. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2314. }
  2315. }
  2316. // 取行业
  2317. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2318. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2319. if (!empty($job->industry)) {
  2320. $query->where('hyid', $job->industry);
  2321. } else if (!empty($job->hy_id)) {
  2322. $query->where('hyid', $job->hy_id);
  2323. } else if (!empty($job->company_hy_id)) {
  2324. $query->where('hyid', $job->company_hy_id);
  2325. } else {
  2326. $query->where('hyid', $job->job_industry);
  2327. }
  2328. })->first(['hyname']);
  2329. $job->hy_name = $hy_name->hyname ?? '';
  2330. }
  2331. // 取职位类别
  2332. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2333. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2334. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2335. $job->zw_name = $zw_name->zwname ?? '';
  2336. }
  2337. // 取具体职位
  2338. 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))) {
  2339. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2340. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2341. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2342. }
  2343. // 取工作经验
  2344. if (isset($job->experience) && !empty($job->experience)) {
  2345. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2346. $job->experience_name = $experience->ename ?? '';
  2347. }
  2348. // 取学历
  2349. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2350. $education = $job->educational ?? $job->school_education;
  2351. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2352. $job->education_name = $education->ename ?? '';
  2353. }
  2354. // 语言
  2355. if (isset($job->language) && !empty($job->language)) {
  2356. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2357. $job->language_name = $language->ename ?? '';
  2358. }
  2359. // 薪资
  2360. if (isset($job->salary) && !empty($job->salary)) {
  2361. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2362. $job->salary_name = $salary->ename ?? '';
  2363. }
  2364. // 职位性质
  2365. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2366. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2367. $job->job_nature_name = $job_nature->ename ?? '';
  2368. }
  2369. // 公司规模
  2370. if (isset($job->company_size) && !empty($job->company_size)) {
  2371. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2372. $job->company_size_name = $company_size->ename ?? '';
  2373. }
  2374. // 公司性质
  2375. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2376. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2377. $job->company_nature_name = $company_nature->nature_name ?? '';
  2378. }
  2379. // $job->pinyin = $pinyin;
  2380. return $job;
  2381. });
  2382. }
  2383. /**
  2384. * 获取书籍模块
  2385. * @param array $data
  2386. * @return array
  2387. * */
  2388. public function getWebsiteBook(array $data): array
  2389. {
  2390. $input['id'] = $data['id'];
  2391. $input['website_id'] = $data['website_id'];
  2392. // 将 JSON 字符串转换为 PHP 数组
  2393. $data = json_decode($input['id'], true);
  2394. // 使用 array_map 处理每个元素
  2395. $result = array_map(function ($item) use ($input) {
  2396. // 检查parent元素是否存在且不是undefined
  2397. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2398. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2399. $website = [
  2400. 'website_id' => $input['website_id'],
  2401. ];
  2402. // 查询栏目名称
  2403. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2404. if (empty($category)) {
  2405. $parent_alias = '';
  2406. $parent_pinyin = null;
  2407. $imgBooks = [];
  2408. $textBooks = [];
  2409. } else {
  2410. $parent_alias = $category->alias ?? '';
  2411. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2412. // 查找子分类ID数组
  2413. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2414. array_push($childCategoryIds, $parentCatId);
  2415. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2416. if ($parentImgNum != 0) {
  2417. // 查询图片新闻
  2418. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2419. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2420. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2421. })
  2422. ->where('book.status', 2)
  2423. ->where('book.img_url', '!=', '')
  2424. ->leftJoin('website_category', function ($join) use ($website) {
  2425. $join->on('book.cat_id', '=', 'website_category.category_id')
  2426. ->where('website_category.website_id', '=', $website['website_id']);
  2427. })
  2428. ->select(
  2429. 'book.id',
  2430. 'book.title',
  2431. 'book.img_url',
  2432. 'book.price',
  2433. 'book.market_price',
  2434. 'book.description',
  2435. 'book.cat_id',
  2436. 'book.description',
  2437. 'book.updated_at',
  2438. 'website_category.alias as category_name',
  2439. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2440. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2441. )
  2442. ->orderBy('updated_at', 'desc')
  2443. ->limit($parentImgNum)
  2444. ->get()->all();
  2445. // 查询文字新闻
  2446. }
  2447. if ($parentTextNum != 0) {
  2448. $textBooks = [];
  2449. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2450. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2451. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2452. })
  2453. ->where('book.status', 2)
  2454. ->leftJoin('website_category', function ($join) use ($website) {
  2455. $join->on('book.cat_id', '=', 'website_category.category_id')
  2456. ->where('website_category.website_id', '=', $website['website_id']);
  2457. })
  2458. ->select(
  2459. 'book.id',
  2460. 'book.title',
  2461. 'book.img_url',
  2462. 'book.price',
  2463. 'book.market_price',
  2464. 'book.description',
  2465. 'book.cat_id',
  2466. 'book.description',
  2467. 'book.updated_at',
  2468. 'website_category.alias as category_name',
  2469. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2470. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2471. )
  2472. ->orderBy('updated_at', 'desc')
  2473. ->limit($parentTextNum)
  2474. ->get()->all();
  2475. }
  2476. }
  2477. }
  2478. $resultItem = [
  2479. 'alias' => $parent_alias ?? '',
  2480. 'category_id' => $parentCatId ?? 0,
  2481. 'pinyin' => $parent_pinyin ?? null,
  2482. 'imgnum' => $imgBooks ?? [],
  2483. 'textnum' => $textBooks ?? [],
  2484. ];
  2485. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2486. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2487. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2488. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2489. ->get()->all();
  2490. if (!empty($childCategory)) {
  2491. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2492. // 查询子栏目名称
  2493. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2494. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2495. ->first();
  2496. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2497. $childImgArticles = [];
  2498. $childTextArticles = [];
  2499. $resultItem['child'] = [];
  2500. } else {
  2501. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2502. // 查询子栏目图片新闻
  2503. $childImgArticles = Book::where('cat_id', $childCatId)
  2504. ->where('status', 2)
  2505. ->where('img_url', '!=', '')
  2506. ->leftJoin('website_category', function ($join) use ($website) {
  2507. $join->on('book.cat_id', '=', 'website_category.category_id')
  2508. ->where('website_category.website_id', '=', $website['website_id']);
  2509. })
  2510. ->select(
  2511. 'book.id',
  2512. 'book.title',
  2513. 'book.img_url',
  2514. 'book.price',
  2515. 'book.market_price',
  2516. 'book.description',
  2517. 'book.cat_id',
  2518. 'book.description',
  2519. 'book.updated_at',
  2520. DB::raw("'$child_pinyin' as pinyin")
  2521. )
  2522. ->orderBy('updated_at', 'desc')
  2523. ->limit($childImgNum)
  2524. ->get()->all();
  2525. // 查询子栏目文字新闻
  2526. $childTextArticles = Book::where('cat_id', $childCatId)
  2527. ->where('status', 2)
  2528. ->leftJoin('website_category', function ($join) use ($website) {
  2529. $join->on('book.cat_id', '=', 'website_category.category_id')
  2530. ->where('website_category.website_id', '=', $website['website_id']);
  2531. })
  2532. ->select(
  2533. 'book.id',
  2534. 'book.title',
  2535. 'book.img_url',
  2536. 'book.price',
  2537. 'book.market_price',
  2538. 'book.description',
  2539. 'book.cat_id',
  2540. 'book.description',
  2541. 'book.updated_at',
  2542. DB::raw("'$child_pinyin' as pinyin")
  2543. )
  2544. ->orderBy('updated_at', 'desc')
  2545. ->limit($childTextNum)
  2546. ->get()->all();
  2547. $resultItem['child'] = [
  2548. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2549. 'category_id' => $childCatId,
  2550. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2551. 'all_childcat' => $childCategory,
  2552. 'imgnum' => $childImgArticles,
  2553. 'textnum' => $childTextArticles,
  2554. ];
  2555. }
  2556. }
  2557. } else {
  2558. $resultItem['child'] = [];
  2559. }
  2560. return $resultItem;
  2561. }, $data);
  2562. return Result::success($result);
  2563. }
  2564. /**
  2565. * 获取书刊列表
  2566. * @param array $data
  2567. * @return array
  2568. * */
  2569. public function getWebsiteBookList(array $data): array
  2570. {
  2571. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2572. if (empty($web)) {
  2573. return Result::error("查询失败", 0);
  2574. }
  2575. $catid = $data['id'];
  2576. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2577. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2578. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2579. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2580. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2581. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2582. ->where('pid', $category['pid'])
  2583. ->select(
  2584. 'category_id',
  2585. 'alias',
  2586. 'aLIas_pinyin',
  2587. 'pid',
  2588. 'sort',
  2589. 'is_url',
  2590. 'web_url',
  2591. 'seo_title',
  2592. 'seo_keywords',
  2593. 'seo_description',
  2594. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2595. )
  2596. ->orderBy('sort')
  2597. ->get()->all();
  2598. if (empty($category)) {
  2599. return Result::error("查询失败", 0);
  2600. }
  2601. $query = Book::where('book.status', 2)
  2602. ->where('book.website_id', $data['website_id'])
  2603. ->where('book.cat_id', $catid)
  2604. ->select(
  2605. 'book.id',
  2606. 'book.title',
  2607. 'book.img_url',
  2608. 'book.description',
  2609. 'book.updated_at',
  2610. 'book.cat_id',
  2611. DB::raw("'$pinyin' as pinyin")
  2612. )
  2613. ->orderBy('book.updated_at', 'desc');
  2614. $count = $query->count();
  2615. $query = clone $query;
  2616. $Book = $query
  2617. ->limit($data['pageSize'])
  2618. ->offset(($data['page'] - 1) * $data['pageSize'])
  2619. ->get()->all();
  2620. $result = [
  2621. 'category' => $categorys,
  2622. 'books' => $Book,
  2623. 'count' => $count,
  2624. ];
  2625. // if(empty($result)){
  2626. // return Result::error("查询失败", 0);
  2627. // }
  2628. return Result::success($result);
  2629. }
  2630. /**
  2631. * 获取书刊详情
  2632. * @param array $data
  2633. * @return array
  2634. * */
  2635. public function getWebsiteBookInfo(array $data): array
  2636. {
  2637. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2638. if (empty($web)) {
  2639. return Result::error("查询失败", 0);
  2640. }
  2641. $book = Book::where('status', 2)
  2642. ->where('website_id', $data['website_id'])
  2643. ->where('id', $data['id'])
  2644. ->select(
  2645. 'book.*',
  2646. )
  2647. ->orderBy('updated_at', 'desc')
  2648. ->first();
  2649. if (empty($book)) {
  2650. return Result::error("查询失败", 0);
  2651. }
  2652. // 先查询当前分类的 pid
  2653. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2654. ->where('category_id', $book['cat_id'])
  2655. ->first(['pid', 'category_id']);
  2656. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2657. if (!empty($carpid)) {
  2658. if ($carpid->pid != 0) {
  2659. $pid = $carpid['pid'];
  2660. // $parent_pinyin = '';
  2661. } else {
  2662. $pid = $carpid['category_id'];
  2663. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2664. }
  2665. }
  2666. $categorys = $query->where('pid', $pid)
  2667. ->select(
  2668. 'category_id',
  2669. 'alias',
  2670. 'aLIas_pinyin',
  2671. 'pid',
  2672. 'sort',
  2673. 'is_url',
  2674. 'web_url',
  2675. 'category_arr_id as cat_arr_id',
  2676. )
  2677. ->orderBy('sort')
  2678. ->get();
  2679. $category = $this->processArticle($categorys, $data);
  2680. $result = [
  2681. 'category' => $category,
  2682. 'books' => $book,
  2683. ];
  2684. return Result::success($result);
  2685. }
  2686. /**
  2687. * 尝试
  2688. * @param array $data
  2689. * @return array
  2690. * */
  2691. public function test(array $data): array
  2692. {
  2693. $input['id'] = $data['id'];
  2694. $input['website_id'] = $data['website_id'];
  2695. // 将 JSON 字符串转换为 PHP 数组
  2696. $data = json_decode($input['id'], true);
  2697. $result = [];
  2698. $article = $data;
  2699. $result = array_map(function ($item) use ($input) {
  2700. $website = [
  2701. 'website_id' => $input['website_id'],
  2702. ];
  2703. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2704. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2705. $parent = [
  2706. 0 => $category['category_id'] ?? [],
  2707. 1 => $parentImgNum ?? [],
  2708. 2 => $parentTextNum ?? [],
  2709. ];
  2710. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2711. $child = [];
  2712. $resultItem = [
  2713. // 'alias' => $parent_alias ?? '',
  2714. 'category_id' => $parentCatId ?? 0,
  2715. 'pinyin' => $parentImgNum ?? null,
  2716. 'imgnum' => $parentTextNum ?? [],
  2717. // 'textnum' => $textArticles ?? [],
  2718. ];
  2719. return $parent;
  2720. }, $data);
  2721. return Result::success($result);
  2722. // });
  2723. }
  2724. /**
  2725. * 封装处理文章的路由问题
  2726. * */
  2727. function processArticle($article, $data)
  2728. {
  2729. return $article->map(function ($article) use ($data) {
  2730. $catid = $article->cat_arr_id ?? '';
  2731. $level = json_decode($catid, true);
  2732. $pinyin = '';
  2733. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2734. if (!empty($level) && is_array($level)) {
  2735. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2736. ->where('website_id', $data['website_id'])
  2737. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2738. ->get(['aLIas_pinyin'])
  2739. ->pluck('aLIas_pinyin')
  2740. ->implode('/');
  2741. } else {
  2742. $pinyin = '';
  2743. }
  2744. $article->pinyin = $pinyin;
  2745. return $article;
  2746. });
  2747. }
  2748. /**
  2749. * c端-获取招工招聘下拉选框
  2750. * @param array $data
  2751. * @return array
  2752. * */
  2753. public function getWebsiteJobSelect(array $data): array
  2754. {
  2755. $web = Website::where('id', $data['website_id'])->first();
  2756. if (empty($web)) {
  2757. return Result::error("该网站不存在", 0);
  2758. }
  2759. $hy = JobIndustry::get()->all();
  2760. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2761. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2762. $result = [
  2763. 'hy' => $hy,
  2764. 'zw' => $zw,
  2765. 'jtzw' => $jtzw,
  2766. ];
  2767. if (empty($result)) {
  2768. return Result::error("查询失败", 0);
  2769. }
  2770. return Result::success($result);
  2771. }
  2772. /**
  2773. * c端-获取招工招聘
  2774. * @param array $data
  2775. * @return array
  2776. * */
  2777. public function getWebsiteJob(array $data): array
  2778. {
  2779. $web = Website::where('id', $data['website_id'])->first();
  2780. if (empty($web)) {
  2781. return Result::error("该网站不存在", 0);
  2782. }
  2783. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2784. ->where('job_hunting.website_id', $data['website_id'])
  2785. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2786. $query->where(function ($q) use ($data) {
  2787. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2788. });
  2789. })
  2790. ->select(
  2791. 'job_hunting.id',
  2792. 'job_hunting.cat_arr_id',
  2793. 'job_hunting.job_name_get',
  2794. 'job_hunting.industry',
  2795. 'job_hunting.name',
  2796. 'job_hunting.sexy',
  2797. 'job_hunting.origin',
  2798. 'job_hunting.city_arr_id',
  2799. 'job_hunting.experience',
  2800. 'job_hunting.updated_at',
  2801. 'job_hunting.salary'
  2802. )
  2803. ->orderBy('updated_at', 'desc')
  2804. ->limit($data['job1_num'])
  2805. ->get();
  2806. $web['website_id'] = $data['website_id'];
  2807. if (empty($job_hunting)) {
  2808. $job_huntings = "未查询到相关简历信息";
  2809. } else {
  2810. $job_huntings = $this->processJob($job_hunting, $web);
  2811. }
  2812. // 0:待审核 1:已通过 2:已拒绝
  2813. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2814. ->where('job_recruiting.website_id', $data['website_id'])
  2815. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2816. $query->where(function ($q) use ($data) {
  2817. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2818. });
  2819. })
  2820. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2821. ->select(
  2822. 'job_recruiting.id',
  2823. 'job_recruiting.cat_arr_id',
  2824. 'job_recruiting.title',
  2825. 'job_recruiting.jtzw_id',
  2826. 'job_recruiting.hy_id',
  2827. 'job_recruiting.city_arr_id',
  2828. 'job_recruiting.due_data',
  2829. 'job_recruiting.updated_at',
  2830. 'job_recruiting.experience',
  2831. 'job_recruiting.educational',
  2832. 'job_recruiting.salary',
  2833. 'job_recruiting.zw_id',
  2834. 'job_company.business_name'
  2835. )
  2836. ->orderBy('updated_at', 'desc')
  2837. ->limit($data['job2_num'])
  2838. ->get();
  2839. if (empty($job_recruiting->toArray())) {
  2840. $job_recruitings = "未查询到相关职位信息";
  2841. } else {
  2842. $job_recruitings = $this->processJob($job_recruiting, $web);
  2843. }
  2844. $result = [
  2845. 'job_hunting' => $job_huntings,
  2846. 'job_recuiting' => $job_recruitings,
  2847. ];
  2848. return Result::success($result);
  2849. }
  2850. /**
  2851. * c端-获取招工招聘列表
  2852. * @param array $data
  2853. * @return array
  2854. * */
  2855. public function getWebsiteJobList(array $data): array
  2856. {
  2857. $recruit_where = [];
  2858. $hunt_where = [];
  2859. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2860. if (empty($web)) {
  2861. return Result::error("此网站不存在", 0);
  2862. }
  2863. $website_id['website_id'] = $data['website_id'];
  2864. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2865. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2866. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2867. }
  2868. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2869. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2870. }
  2871. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2872. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2873. }
  2874. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2875. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  2876. }
  2877. $query = JobRecruiting::where('job_recruiting.status', 1)
  2878. ->where('job_recruiting.website_id', $data['website_id'])
  2879. ->where($recruit_where)
  2880. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2881. $query->where(function ($q) use ($data) {
  2882. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2883. });
  2884. })
  2885. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2886. $query->where(function ($q) use ($data) {
  2887. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2888. });
  2889. })
  2890. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2891. ->select(
  2892. 'job_recruiting.id',
  2893. 'job_recruiting.hy_id',
  2894. 'job_recruiting.title',
  2895. 'job_recruiting.zw_id',
  2896. 'job_recruiting.educational',
  2897. 'job_recruiting.jtzw_id',
  2898. 'job_recruiting.city_arr_id',
  2899. 'job_recruiting.due_data',
  2900. 'job_recruiting.experience',
  2901. 'job_recruiting.cat_arr_id',
  2902. 'job_recruiting.updated_at',
  2903. 'job_company.business_name'
  2904. )
  2905. ->orderBy('job_recruiting.updated_at', 'desc');
  2906. $recruit_count = $query->count();
  2907. $query = clone $query;
  2908. $JobRecruiting = $query
  2909. ->offset(($data['page'] - 1) * $data['pageSize'])
  2910. ->limit($data['pageSize'])
  2911. ->get();
  2912. if (empty($JobRecruiting)) {
  2913. $JobRecruiting = "暂无相关职位信息";
  2914. } else {
  2915. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2916. }
  2917. }
  2918. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2919. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2920. array_push($hunt_where, ['job', $data['zw_id']]);
  2921. }
  2922. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2923. array_push($hunt_where, ['job_name_get', $data['jtzw_id']]);
  2924. }
  2925. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2926. array_push($hunt_where, ['industry', $data['hy_id']]);
  2927. }
  2928. $query = JobHunting::where('status', 2)
  2929. ->where('job_hunting.website_id', $data['website_id'])
  2930. ->where($hunt_where)
  2931. ->when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  2932. $query->where('job_position.zwname', 'like', '%' . $data['keyword'] . '%');
  2933. })
  2934. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2935. $query->where(function ($q) use ($data) {
  2936. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2937. });
  2938. })
  2939. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  2940. $query->where(function ($q) use ($data) {
  2941. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  2942. });
  2943. })
  2944. ->select('id', 'sexy', 'experience', 'origin', 'industry', 'name', 'job', 'job_name_get', 'city_arr_id', 'cat_arr_id', 'created_at', 'updated_at')
  2945. ->orderBy('updated_at', 'desc');
  2946. $hunt_count = $query->count();
  2947. $query = clone $query;
  2948. $JobHunting = $query
  2949. ->offset(($data['page'] - 1) * $data['pageSize'])
  2950. ->limit($data['pageSize'])
  2951. ->get();
  2952. if (empty($JobHunting)) {
  2953. $JobRecruiting = "暂无相关简历信息";
  2954. } else {
  2955. $JobHunting = $this->processJob($JobHunting, $website_id);
  2956. }
  2957. }
  2958. $result = [
  2959. 'JobRecruiting' => $JobRecruiting ?? [],
  2960. 'recruit_count' => $recruit_count ?? 0,
  2961. 'JobHunting' => $JobHunting ?? [],
  2962. 'hunt_count' => $hunt_count ?? 0,
  2963. ];
  2964. return Result::success($result);
  2965. }
  2966. /**
  2967. * c端-获取招工招聘详情
  2968. * @param array $data
  2969. * @return array
  2970. * */
  2971. public function getWebsiteJobInfo(array $data): array
  2972. {
  2973. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2974. if (empty($web)) {
  2975. return Result::error("该网站不存在", 0);
  2976. }
  2977. $webid = [
  2978. 'website_id' => $data['website_id'],
  2979. ];
  2980. // 职位相关信息
  2981. if ($data['type'] == 1) {
  2982. $query = JobRecruiting::where('status', 1)
  2983. ->where('website_id', $data['website_id'])
  2984. ->select('*');
  2985. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2986. $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();
  2987. if (!empty($company)) {
  2988. $result['company'] = $this->processJob($company, $webid);
  2989. }
  2990. $other_job = JobRecruiting::where('status', 1)
  2991. ->where('website_id', $data['website_id'])
  2992. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2993. ->where('id', '!=', $data['id'])
  2994. ->where('user_id', '=', $job[0]['user_id'])
  2995. ->limit($data['pageSize'])
  2996. ->get();
  2997. if (!empty($other_job)) {
  2998. $result['other_job'] = $this->processJob($other_job, $webid);
  2999. }
  3000. } else {
  3001. // 简历相关信息
  3002. $job = JobHunting::where('job_hunting.status', 2)
  3003. ->where('job_hunting.website_id', $data['website_id'])
  3004. ->where('job_hunting.id', $data['id'])
  3005. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3006. ->select('job_hunting.*', 'user_name')
  3007. ->get();
  3008. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3009. if (!empty($resume->toArray())) {
  3010. $result['resume'] = 1;
  3011. } else {
  3012. $result['resume'] = 0;
  3013. }
  3014. }
  3015. if (empty($job->toArray())) {
  3016. return Result::error("id参数错误", 0);
  3017. }
  3018. if (!empty($job[0]['job_experience'])) {
  3019. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3020. if (!empty($job_experience)) {
  3021. // $hy = [];
  3022. foreach ($job_experience as $key => $value) {
  3023. // $id = $value['id'];
  3024. $hy[$key] = $value['job_industry'];
  3025. $zw_id[$key] = $value['job_typename'];
  3026. $jtzw_id[$key] = $value['job_name'];
  3027. }
  3028. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3029. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3030. // 先将关联表转换为索引数组,提高查找效率
  3031. $hyLookup = [];
  3032. foreach ($hy_table as $item) {
  3033. $hyLookup[$item['hyid']] = $item['hyname'];
  3034. }
  3035. $zwLookup = [];
  3036. foreach ($zw_table as $item) {
  3037. $zwLookup[$item['zwid']] = $item['zwname'];
  3038. }
  3039. foreach ($job_experience as $key => &$value) {
  3040. // 处理行业名称
  3041. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3042. $value['hy_name'] = $hyLookup[$hy[$key]];
  3043. }
  3044. // 处理职位名称
  3045. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3046. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3047. }
  3048. // 处理具体职位名称
  3049. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3050. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3051. }
  3052. }
  3053. // 释放引用,防止意外修改后续代码
  3054. unset($value);
  3055. }
  3056. $result['job_experience'] = $job_experience ?? [];
  3057. }
  3058. if (!empty($job[0]['education_experience'])) {
  3059. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3060. if (!empty($education_experience)) {
  3061. foreach ($education_experience as $key => $value) {
  3062. // $id = $value['id'];
  3063. $education[$key] = $value['school_education'];
  3064. }
  3065. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3066. // // 先将关联表转换为索引数组,提高查找效率
  3067. $educationLookup = [];
  3068. foreach ($education_table as $item) {
  3069. $educationLookup[$item['evalue']] = $item['ename'];
  3070. }
  3071. foreach ($education_experience as $key => &$value) {
  3072. // 处理学历名称
  3073. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3074. $value['education_name'] = $educationLookup[$education[$key]];
  3075. }
  3076. }
  3077. }
  3078. $result['education_experience'] = $job_experience ?? [];
  3079. }
  3080. $result['job'] = $this->processJob($job, $webid);
  3081. // // 返现对应的栏目
  3082. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3083. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3084. ->whereIn('category_id', $catid)
  3085. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3086. ->orderBy('pid')->get()->all();
  3087. if (!empty($category)) {
  3088. $result['category'] = $category;
  3089. }
  3090. $result['job'] = $job;
  3091. $result['job_experience'] = $job_experience ?? [];
  3092. $result['education_experience'] = $education_experience ?? [];
  3093. if (empty($result)) {
  3094. return Result::error("参数错误", 0);
  3095. }
  3096. return Result::success($result);
  3097. }
  3098. /**
  3099. * c端-申请职位
  3100. * @param array $data
  3101. * @return array
  3102. * */
  3103. public function getWebsiteJobApply(array $data): array
  3104. {
  3105. // 首先验证网站是否存在
  3106. // return Result::success($data);
  3107. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3108. if (empty($web)) {
  3109. return Result::error("该网站不存在", 0);
  3110. }
  3111. // 验证用户是否存在且为个人会员/管理员
  3112. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3113. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3114. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3115. return Result::error("用户不存在", 0);
  3116. }
  3117. // 去除重复元素和空元素,并保持原始顺序
  3118. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3119. return !empty($value);
  3120. }));
  3121. // 验证职位是否存在 1:审核通过
  3122. $recruiting = JobRecruiting::where('status', 1)
  3123. ->where('website_id', $data['website_id'])
  3124. ->whereIn('id', $data['recruit_id'])
  3125. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3126. if (empty($recruiting)) {
  3127. return Result::error("该职位不存在", 0);
  3128. }
  3129. // 简历是否存在
  3130. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3131. if (empty($hunt_id)) {
  3132. return Result::error("该简历不存在", 0);
  3133. }
  3134. $data['hunt_id'] = $hunt_id['hunt_id'];
  3135. // // 验证是否已投递过该职位
  3136. $apply = JobApply::where('user_id', $data['user_id'])
  3137. ->where('hunt_id', $data['hunt_id'])
  3138. ->where('website_id', $data['website_id'])
  3139. ->whereIn('recruit_id', $data['recruit_id'])
  3140. ->get(['recruit_id']);
  3141. if (!empty($apply->toArray())) {
  3142. return Result::error("您已投递过该职位!");
  3143. }
  3144. $insertData = array_map(function ($recruiting) use ($data) {
  3145. return [
  3146. 'user_id' => $data['user_id'],
  3147. 'hunt_id' => $data['hunt_id'],
  3148. 'website_id' => $data['website_id'],
  3149. 'recruit_id' => $recruiting['recruit_id'],
  3150. 'receiver_id' => $recruiting['receiver_id'],
  3151. 'status' => 1,
  3152. ];
  3153. }, $recruiting);
  3154. // 批量插入数据
  3155. $result = JobApply::insert($insertData);
  3156. if (empty($result)) {
  3157. return Result::error("投递失败", 0);
  3158. }
  3159. return Result::success($result);
  3160. }
  3161. /**
  3162. * 招工招聘-沟通简历
  3163. * @param array $data
  3164. * @return array
  3165. * */
  3166. public function getWebsiteJobResume(array $data): array
  3167. {
  3168. // 首先验证网站是否存在
  3169. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3170. if (empty($web)) {
  3171. return Result::error("该网站不存在", 0);
  3172. }
  3173. // return Result::success($data);
  3174. // 验证用户是否存在且为企业会员/管理员
  3175. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3176. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3177. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3178. return Result::error("用户不存在", 0);
  3179. }
  3180. // 去除重复元素和空元素,并保持原始顺序
  3181. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3182. return !empty($value);
  3183. }));
  3184. // 验证简历是否存在
  3185. $hunting = JobHunting::where('status', 2)
  3186. ->where('website_id', $data['website_id'])
  3187. ->whereIn('id', $data['hunt_id'])
  3188. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3189. if (empty($hunting)) {
  3190. return Result::error("该简历不存在", 0);
  3191. }
  3192. // 验证是否已沟通过该简历
  3193. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3194. ->where('recruit_id', $data['recruit_id'])
  3195. ->where('website_id', $data['website_id'])
  3196. ->whereIn('hunt_id', $data['hunt_id'])
  3197. ->get(['hunt_id']);
  3198. if (!empty($remuse->toArray())) {
  3199. return Result::error("您已沟通过该简历!");
  3200. }
  3201. // 准备要插入的数据数组
  3202. $insertData = array_map(function ($hunting) use ($data) {
  3203. return [
  3204. 'user_id' => $data['user_id'],
  3205. 'recruit_id' => $data['recruit_id'],
  3206. 'website_id' => $data['website_id'],
  3207. 'hunt_id' => $hunting['hunt_id'],
  3208. 'receiver_id' => $hunting['receiver_id'],
  3209. 'status' => 1,
  3210. ];
  3211. }, $hunting);
  3212. // 批量插入数据
  3213. $result = JobRemuse::insert($insertData);
  3214. if (empty($result)) {
  3215. return Result::error("沟通失败", 0);
  3216. }
  3217. return Result::success($result);
  3218. }
  3219. /**
  3220. * 招工招聘 -我的职位(企业会员)
  3221. * @param array $data
  3222. * @return array
  3223. */
  3224. public function getWebsiteJobRecruiting(array $data): array
  3225. {
  3226. $web = Website::where('id', $data['website_id'])->first('id');
  3227. if (empty($web)) {
  3228. return Result::error("该网站不存在", 0);
  3229. }
  3230. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3231. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3232. return Result::error("用户暂无权限!", 0);
  3233. }
  3234. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3235. $result = JobRecruiting::where('website_id', $data['website_id'])
  3236. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3237. $query->where('user_id', $user['id']);
  3238. })
  3239. ->where('status', 1)
  3240. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3241. ->orderBy('updated_at', 'desc')
  3242. ->limit($data['pageSize'])
  3243. ->get();
  3244. if (empty($result)) {
  3245. return Result::error("暂无相关职位信息", 0);
  3246. }
  3247. return Result::success($result);
  3248. }
  3249. /**
  3250. * c端 - 验证路由
  3251. * @param array $data
  3252. * @return array
  3253. */
  3254. /**
  3255. * c端 - 验证路由
  3256. * @param array $data
  3257. * @return array
  3258. */
  3259. public function checkWebsiteRoute(array $data): array
  3260. {
  3261. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3262. if (empty($web)) {
  3263. return Result::error("该网站不存在", 0);
  3264. } elseif ($web['status'] != 1) {
  3265. return Result::error("网站已经关闭", 0);
  3266. }
  3267. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3268. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3269. if (!empty($whiteRouterInfo)) {
  3270. return Result::success($whiteRouterInfo->toArray());
  3271. }
  3272. }
  3273. // 验证栏目路由
  3274. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3275. ->where('aLIas_pinyin', $data['last_route'])
  3276. ->first();
  3277. if (empty($last_category)) {
  3278. return Result::error("该栏目不存在", 0);
  3279. }
  3280. if (isset($data['id']) && !empty($data['id'])) {
  3281. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3282. switch ($last_category['type']) {
  3283. case 1:
  3284. // 文章
  3285. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3286. $article = Article::where('status', 1)
  3287. ->where('id', $data['id'])
  3288. ->where(function ($query) use ($data) {
  3289. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3290. ->orWhereNull("ignore_ids");
  3291. })
  3292. ->first(['cat_arr_id']);
  3293. if (empty($article)) {
  3294. return Result::error("该文章不存在", 0);
  3295. }
  3296. // return Result::success($article);
  3297. break;
  3298. case 2:
  3299. // 商品
  3300. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3301. $article = Good::where('website_id', $data['website_id'])
  3302. ->where('status', 2)
  3303. ->where('id', $data['id'])
  3304. ->first(['cat_arr_id']);
  3305. if (empty($article)) {
  3306. return Result::error("该商品不存在", 0);
  3307. }
  3308. break;
  3309. case 3:
  3310. // 书刊信息
  3311. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3312. $article = Book::where('website_id', $data['website_id'])
  3313. ->where('status', 2)
  3314. ->where('id', $data['id'])
  3315. ->first(['id', 'cat_arr_id']);
  3316. if (empty($article)) {
  3317. return Result::error("该书刊不存在", 0);
  3318. }
  3319. break;
  3320. case 4:
  3321. // 招聘
  3322. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3323. $article = JobRecruiting::where('website_id', $data['website_id'])
  3324. ->where('status', 1)
  3325. ->where('id', $data['id'])
  3326. ->first(['cat_arr_id']);
  3327. if (empty($article)) {
  3328. return Result::error("该招聘不存在", 0);
  3329. }
  3330. break;
  3331. case 5:
  3332. // 求职
  3333. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3334. $article = JobHunting::where('website_id', $data['website_id'])
  3335. ->where('status', 2)
  3336. ->where('id', $data['id'])
  3337. ->first(['cat_arr_id']);
  3338. if (empty($article)) {
  3339. return Result::error("该求职不存在", 0);
  3340. }
  3341. break;
  3342. case 6:
  3343. // 企业
  3344. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3345. $article = Company::where('website_id', $data['website_id'])
  3346. ->where('status', 1)
  3347. ->where('id', $data['id'])
  3348. ->first(['cat_arr_id']);
  3349. if (empty($article)) {
  3350. return Result::error("该企业不存在", 0);
  3351. }
  3352. break;
  3353. case 7:
  3354. // 项目
  3355. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3356. $article = Project::where('website_id', $data['website_id'])
  3357. ->where('status', 1)
  3358. ->where('id', $data['id'])
  3359. ->first(['cat_arr_id']);
  3360. if (empty($article)) {
  3361. return Result::error("该项目不存在", 0);
  3362. }
  3363. break;
  3364. default:
  3365. return Result::error("该数据不存在", 0);
  3366. break;
  3367. }
  3368. $catid = json_decode($article['cat_arr_id'], true);
  3369. if (empty($catid)) {
  3370. return Result::error("该数据不存在", 0);
  3371. }
  3372. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3373. ->orderByRaw('FIELD(category_id, ' . implode(',', $catid) . ')')
  3374. ->whereIn('category_id', $catid)
  3375. ->pluck('aLIas_pinyin')
  3376. ->implode('/');
  3377. }
  3378. if ($last_category['pid'] != 0) {
  3379. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3380. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3381. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr) . ')')
  3382. ->whereIn('category_id', $cat_arr)
  3383. ->pluck('aLIas_pinyin')
  3384. ->implode('/');
  3385. } else {
  3386. $pinyin = $last_category['aLIas_pinyin'];
  3387. }
  3388. if (empty($pinyin) || $pinyin != $data['all_route']) {
  3389. return Result::error('非法路径!');
  3390. } else {
  3391. return Result::success($pinyin);
  3392. }
  3393. }
  3394. /**
  3395. * 招工招聘 - 获取推荐职位
  3396. * @param array $data
  3397. * @return array
  3398. */
  3399. public function getWebsiteLevelJob(array $data): array
  3400. {
  3401. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3402. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3403. ->where('job_recruiting.status', 1)
  3404. ->where('job_level', $data['job_level'])
  3405. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3406. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3407. ->orderBy('job_recruiting.updated_at', 'desc')
  3408. ->limit($data['pageSize'])
  3409. ->get();
  3410. $web = ['website_id' => $data['website_id']];
  3411. if (!empty($job)) {
  3412. $result = $this->processJob($job, $web);
  3413. }
  3414. if (empty($result)) {
  3415. return Result::error("暂无相关职位信息", 0);
  3416. }
  3417. return Result::success($result);
  3418. }
  3419. /**
  3420. * 验证导航名称是否重复
  3421. * @return void
  3422. */
  3423. //20250226 产品列表
  3424. public function getGoodList(array $data): array
  3425. {
  3426. var_dump($data, '---------1-2--');
  3427. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3428. unset($data['user_type_id']);
  3429. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3430. $where = [];
  3431. if ($type_id != '10000') {
  3432. $where = [
  3433. 'good.user_id' => $user_id,
  3434. ];
  3435. }
  3436. //类型
  3437. if (isset($data['type_id']) && $data['type_id']) {
  3438. $where['good.type_id'] = $data['type_id'];
  3439. }
  3440. //名称
  3441. if (isset($data['name']) && $data['name']) {
  3442. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3443. }
  3444. //status
  3445. if (isset($data['status']) && $data['status'] != '') {
  3446. $where['good.status'] = $data['status'];
  3447. }
  3448. //status1
  3449. // if (isset($data['status1']) && $data['status1'] == 1) {
  3450. // $status1 = 1;
  3451. // }
  3452. $where1 = [];
  3453. //website_id
  3454. // if (isset($data['website_id']) && $data['website_id']) {
  3455. // $where1 = [
  3456. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3457. // ];
  3458. // }
  3459. // website_name
  3460. if (isset($data['website_name']) && $data['website_name']) {
  3461. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3462. }
  3463. // catid
  3464. if (isset($data['category_name']) && $data['category_name']) {
  3465. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3466. }
  3467. // $result = Good::where($where)
  3468. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3469. var_dump($where, '---------1---');
  3470. $result = Good::where($where)
  3471. ->when(!empty($where1), function ($query) use ($where1) {
  3472. return $query->where($where1);
  3473. })
  3474. //status 1待审核2已审核3已拒绝
  3475. ->when(isset($data['status1']), function ($query) {
  3476. return $query->whereIn('good.status', [1, 3]);
  3477. })
  3478. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3479. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3480. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3481. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3482. ->orderBy("updated_at", "desc")
  3483. ->limit($data['page_size'])
  3484. ->offset(($data['page'] - 1) * $data['page_size'])
  3485. ->get();
  3486. $count = Good::where($where)
  3487. ->when(!empty($where1), function ($query) use ($where1) {
  3488. return $query->where($where1);
  3489. })
  3490. //status 1待审核2已审核3已拒绝
  3491. ->when(isset($data['status1']), function ($query) {
  3492. return $query->whereIn('good.status', [1, 3]);
  3493. })
  3494. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3495. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3496. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3497. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3498. ->orderBy("updated_at", "desc")->count();
  3499. $data = [
  3500. 'rows' => $result->toArray(),
  3501. 'count' => $count,
  3502. ];
  3503. if (empty($result)) {
  3504. return Result::error("此栏目暂无相关产品", 0);
  3505. }
  3506. return Result::success($data);
  3507. }
  3508. public function getGoodInfo(array $data): array
  3509. {
  3510. $result = Good::where('id', $data['id'])->first();
  3511. if (empty($result)) {
  3512. return Result::error("此产品不存在", 0);
  3513. }
  3514. return Result::success($result);
  3515. }
  3516. public function addGood(array $data): array
  3517. {
  3518. // unset($data['city_arr_id']);
  3519. // unset($data['cat_arr_id']);
  3520. $data['city_id'] = end($data['city_arr_id']);
  3521. $data['catid'] = end($data['cat_arr_id']);
  3522. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3523. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3524. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3525. unset($data['imgUrl']); //大小写
  3526. if (isset($data['price']) && $data['price'] == '') {
  3527. $data['price'] = 0;
  3528. }
  3529. if ($data['imgurl'] == '') {
  3530. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3531. preg_match_all($reg, $data['detail'], $matches);
  3532. if (isset($matches[1][0])) {
  3533. //截取varchar240
  3534. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3535. }
  3536. }
  3537. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3538. //提取标题+内容中的关键词
  3539. $data['keyword'] = $data['name'];
  3540. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3541. Jieba::init(); // 初始化 jieba-php
  3542. Finalseg::init();
  3543. $segList = Jieba::cut($data['keyword']);
  3544. $segList1 = array_slice($segList, 0, 8);
  3545. $data['keyword'] = implode(',', $segList1);
  3546. }
  3547. if ($data['description'] == '') {
  3548. //提取内容中的描述
  3549. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3550. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3551. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3552. }
  3553. if ($data['status'] == 1) {
  3554. $this->sendMessage([
  3555. 'talk_type' => 200,
  3556. 'title' => $data['name'],
  3557. 'content' => '提交了审核',
  3558. 'messageType' => 3,
  3559. ]);
  3560. }
  3561. $result = Good::insert($data);
  3562. if (empty($result)) {
  3563. return Result::error("添加失败", 0);
  3564. }
  3565. return Result::success($result);
  3566. }
  3567. public function updateGood(array $data): array
  3568. {
  3569. $data['city_id'] = end($data['city_arr_id']);
  3570. $data['catid'] = end($data['cat_arr_id']);
  3571. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3572. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3573. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3574. //设置东八区
  3575. date_default_timezone_set('Asia/Shanghai');
  3576. $data['updated_at'] = date('Y-m-d H:i:s');
  3577. if (isset($data['price']) && $data['price'] == '') {
  3578. $data['price'] = 0;
  3579. }
  3580. if ($data['imgurl'] == '') {
  3581. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3582. preg_match_all($reg, $data['detail'], $matches);
  3583. if (isset($matches[1][0])) {
  3584. //截取varchar240
  3585. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3586. }
  3587. }
  3588. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3589. //提取标题+内容中的关键词
  3590. $data['keyword'] = $data['name'];
  3591. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3592. Jieba::init(); // 初始化 jieba-php
  3593. Finalseg::init();
  3594. $segList = Jieba::cut($data['keyword']);
  3595. $segList1 = array_slice($segList, 0, 8);
  3596. $data['keyword'] = implode(',', $segList1);
  3597. }
  3598. if ($data['description'] == '') {
  3599. //提取内容中的描述
  3600. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3601. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3602. }
  3603. if ($data['status'] == 1) {
  3604. $this->sendMessage([
  3605. 'talk_type' => 200,
  3606. 'title' => $data['name'],
  3607. 'content' => '提交了审核',
  3608. 'messageType' => 3,
  3609. ]);
  3610. }
  3611. $result = Good::where('id', $data['id'])->update($data);
  3612. if (empty($result)) {
  3613. return Result::error("更新失败", 0);
  3614. }
  3615. return Result::success($result);
  3616. }
  3617. public function delGood(array $data): array
  3618. {
  3619. $result = Good::where('id', $data['id'])->delete();
  3620. if (empty($result)) {
  3621. return Result::error("删除失败", 0);
  3622. }
  3623. return Result::success($result);
  3624. }
  3625. //20250226 产品列表
  3626. //20250306 求职信息
  3627. public function getJobHuntingList(array $data): array
  3628. {
  3629. $where = [];
  3630. if (isset($data['username']) && !empty($data['username'])) {
  3631. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3632. }
  3633. //status 1待审核2已审核3已拒绝
  3634. if (isset($data['status']) && $data['status'] != '') {
  3635. $where = [
  3636. 'job_hunting.status' => $data['status'],
  3637. ];
  3638. }
  3639. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3640. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3641. unset($data['type_id']);
  3642. if ($type_id != '10000') {
  3643. $where[] = ['job_hunting.user_id', '=', $user_id];
  3644. }
  3645. $result = JobHunting::where($where)
  3646. ->when(!empty($data['status1']), function ($query) use ($data) {
  3647. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3648. })
  3649. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3650. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3651. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3652. ->orderBy("updated_at", "desc")
  3653. ->limit($data['page_size'])
  3654. ->offset(($data['page'] - 1) * $data['page_size'])
  3655. ->get();
  3656. if (empty($result)) {
  3657. return Result::error("查询失败", 0);
  3658. }
  3659. $count = JobHunting::where($where)
  3660. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3661. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3662. ->count();
  3663. $data = [
  3664. 'rows' => $result->toArray(),
  3665. 'count' => $count,
  3666. ];
  3667. return Result::success($data);
  3668. }
  3669. public function getJobHuntingApply(array $data): array
  3670. {
  3671. var_dump($data, '-----------------test--------1-');
  3672. $where = [];
  3673. if (isset($data['username']) && !empty($data['username'])) {
  3674. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3675. }
  3676. if (isset($data['salary']) && !empty($data['salary'])) {
  3677. $where[] = [
  3678. 'job_hunting.salary',
  3679. '=',
  3680. $data['salary'],
  3681. ];
  3682. }
  3683. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3684. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3685. unset($data['type_id']);
  3686. if ($type_id != '10000') {
  3687. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3688. }
  3689. var_dump($where, '-----------------test---------');
  3690. $result = jobApply::where($where)
  3691. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3692. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3693. // })
  3694. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3695. ->where('job_enum.egroup', '=', 'income')
  3696. ->where('job_hunting.status', 2) //已审核
  3697. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3698. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3699. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3700. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3701. //职位----是申请职位
  3702. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3703. ->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')
  3704. ->orderBy("job_hunting.updated_at", "desc")
  3705. ->limit($data['page_size'])
  3706. ->offset(($data['page'] - 1) * $data['page_size'])
  3707. ->get();
  3708. if (empty($result)) {
  3709. return Result::error("查询失败", 0);
  3710. }
  3711. $count = jobApply::where($where)
  3712. ->where('job_enum.egroup', '=', 'income')
  3713. ->where('job_hunting.status', 2) //已审核
  3714. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3715. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3716. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3717. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3718. //职位----是申请职位
  3719. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3720. ->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')
  3721. ->count();
  3722. $data = [
  3723. 'rows' => $result->toArray(),
  3724. 'count' => $count,
  3725. ];
  3726. return Result::success($data);
  3727. }
  3728. public function addJobHunting(array $data): array
  3729. {
  3730. date_default_timezone_set('Asia/Shanghai');
  3731. unset($data['company_name']);
  3732. unset($data['job_industry']);
  3733. unset($data['job_name']);
  3734. unset($data['department']);
  3735. unset($data['job_timeList']);
  3736. unset($data['job_content']);
  3737. unset($data['job_typename']); //不知道这是啥,
  3738. $data['created_at'] = date('Y-m-d H:i:s');
  3739. $data['updated_at'] = date('Y-m-d H:i:s');
  3740. //根据用户 user_id 只能添加一次
  3741. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3742. if (!empty($result)) {
  3743. return Result::error("您已添加过求职信息", 0);
  3744. }
  3745. var_dump($result, '-----------------test---------');
  3746. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3747. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3748. $cityArr = json_decode($data['city_arr_id'], true);
  3749. $data['city_id'] = end($cityArr);
  3750. } else {
  3751. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3752. $data['city_id'] = end($data['city_arr_id']);
  3753. }
  3754. if((isset($data['status']) && $data['status']==1) || !isset($data['status'])){
  3755. $this->sendMessage([
  3756. 'talk_type'=>600,
  3757. 'title'=>$data['title'],
  3758. 'content'=>'提交了审核',
  3759. 'messageType'=>11,
  3760. ]);
  3761. }
  3762. $result = JobHunting::create($data);
  3763. if (empty($result)) {
  3764. return Result::error("添加失败", 0);
  3765. }
  3766. return Result::success($result);
  3767. }
  3768. public function delJobHunting(array $data): array
  3769. {
  3770. $result = JobHunting::where('id', $data['id'])->delete();
  3771. if (empty($result)) {
  3772. return Result::error("删除失败", 0);
  3773. }
  3774. return Result::success($result);
  3775. }
  3776. public function updateJobHunting(array $data): array
  3777. {
  3778. //设置东八区
  3779. date_default_timezone_set('Asia/Shanghai');
  3780. unset($data['company_name']);
  3781. unset($data['job_industry']);
  3782. unset($data['job_name']);
  3783. unset($data['department']);
  3784. unset($data['job_timeList']);
  3785. unset($data['job_content']);
  3786. unset($data['job_typename']); //不知道这是啥,
  3787. $data['created_at'] = date('Y-m-d H:i:s');
  3788. $data['updated_at'] = date('Y-m-d H:i:s');
  3789. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3790. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3791. $cityArr = json_decode($data['city_arr_id'], true);
  3792. $data['city_id'] = end($cityArr);
  3793. } else {
  3794. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3795. $data['city_id'] = end($data['city_arr_id']);
  3796. }
  3797. if((isset($data['status']) && $data['status']==1) || !isset($data['status'])){
  3798. $this->sendMessage([
  3799. 'talk_type'=>600,
  3800. 'title'=>$data['title'],
  3801. 'content'=>'提交了审核',
  3802. 'messageType'=>11,
  3803. ]);
  3804. }
  3805. $result = JobHunting::where('id', $data['id'])->update($data);
  3806. if (empty($result)) {
  3807. return Result::error("更新失败", 0);
  3808. }
  3809. return Result::success($result);
  3810. }
  3811. public function getJobHuntingInfo(array $data): array
  3812. {
  3813. $result = JobHunting::where('id', $data['id'])->first();
  3814. if (empty($result)) {
  3815. return Result::error("查询失败", 0);
  3816. }
  3817. return Result::success($result);
  3818. }
  3819. public function getJobHuntingData(array $data): array
  3820. {
  3821. $jobEnum = JobEnum::get();
  3822. $jobIndustry = JobIndustry::get();
  3823. $jobNature = JobNature::get();
  3824. $jobPosition = JobPosition::get();
  3825. $data = [
  3826. 'jobEnum' => $jobEnum,
  3827. 'jobIndustry' => $jobIndustry,
  3828. 'jobNature' => $jobNature,
  3829. 'jobPosition' => $jobPosition,
  3830. ];
  3831. return Result::success($data);
  3832. }
  3833. public function delJobHuntingInfo(array $data): array
  3834. {
  3835. $result = JobHunting::where('id', $data['id'])->delete();
  3836. return Result::success();
  3837. }
  3838. //20250324 通知,公告,消息
  3839. public function delNotice(array $data): array
  3840. {
  3841. $result = Notice::where('id', $data['id'])->delete();
  3842. if ($result) {
  3843. return Result::success();
  3844. } else {
  3845. return Result::error("删除失败", 0);
  3846. }
  3847. }
  3848. public function getNoticeInfo(array $data): array
  3849. {
  3850. $result = Notice::where('id', $data['id'])->first();
  3851. // var_dump($result['re_user_ids'], '--------------------');
  3852. if (empty($result)) {
  3853. return Result::error("查询失败", 0);
  3854. }
  3855. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  3856. $re_user_ids = json_decode($result['re_user_ids'], true);
  3857. var_dump($re_user_ids, '--------------1---test---------');
  3858. var_dump($data, '--------------1---test---------');
  3859. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  3860. //如果已经存在,就不再添加
  3861. if (isset($result['read_id']) && !empty($result['read_id'])) {
  3862. $read_id = json_decode($result['read_id'], true);
  3863. if (!is_array($read_id)) {
  3864. $read_id = [];
  3865. }
  3866. if (!in_array($data['user_id'], $read_id)) {
  3867. $read_id[] = $data['user_id'];
  3868. $result['read_id'] = json_encode($read_id);
  3869. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  3870. }
  3871. } else {
  3872. //如果不存在,就添加
  3873. $result['read_id'] = json_encode([$data['user_id']]);
  3874. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  3875. }
  3876. }
  3877. return Result::success($result);
  3878. }
  3879. public function addNotice(array $data): array
  3880. {
  3881. date_default_timezone_set('Asia/Shanghai');
  3882. $data['created_at'] = date('Y-m-d H:i:s');
  3883. $data['updated_at'] = date('Y-m-d H:i:s');
  3884. $user_id = UserInfo::
  3885. //city_id不是null
  3886. whereNotNull('city_id')
  3887. ->whereNotNull('department_id')
  3888. ->where(function ($query) use ($data) {
  3889. $query->where(function ($subQuery) use ($data) {
  3890. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3891. });
  3892. })
  3893. ->where(function ($query) use ($data) {
  3894. $query->where(function ($subQuery) use ($data) {
  3895. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3896. });
  3897. })
  3898. ->pluck('user_id')->toArray();
  3899. $user_id = array_unique($user_id);
  3900. $chat_ids = $user_id;
  3901. $user_id = json_encode($user_id);
  3902. $data['re_user_ids'] = $user_id;
  3903. $this->sendMessage([
  3904. 'talk_type' => 700,
  3905. 'title' => $data['title'],
  3906. 'content' => '提交了审核',
  3907. 'messageType' => 5,
  3908. ]);
  3909. $result = Notice::insertGetId($data);
  3910. if (empty($result)) {
  3911. return Result::error("添加失败", 0);
  3912. }
  3913. return Result::success($result);
  3914. }
  3915. public function updateNotice(array $data): array
  3916. {
  3917. date_default_timezone_set('Asia/Shanghai');
  3918. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  3919. $user_id = UserInfo::
  3920. //city_id不是null
  3921. whereNotNull('city_id')
  3922. ->whereNotNull('department_id')
  3923. ->where(function ($query) use ($data) {
  3924. $query->where(function ($subQuery) use ($data) {
  3925. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3926. });
  3927. })
  3928. ->where(function ($query) use ($data) {
  3929. $query->where(function ($subQuery) use ($data) {
  3930. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3931. });
  3932. })
  3933. ->pluck('user_id')->toArray();
  3934. $user_id = array_unique($user_id);
  3935. $user_id = json_encode($user_id);
  3936. $data['re_user_ids'] = $user_id;
  3937. $data['updated_at'] = date('Y-m-d H:i:s');
  3938. $this->sendMessage([
  3939. 'talk_type' => 700,
  3940. 'title' => $data['title'],
  3941. 'content' => '提交了审核',
  3942. 'messageType' => 5,
  3943. ]);
  3944. $result = Notice::where('id', $data['id'])->update($data);
  3945. return Result::success($result);
  3946. }
  3947. public function getNoticeList(array $data): array
  3948. {
  3949. $where = [];
  3950. //title
  3951. if (isset($data['title']) && !empty($data['title'])) {
  3952. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  3953. }
  3954. //level
  3955. if (isset($data['level']) && !empty($data['level'])) {
  3956. $where[] = ['notice.level', '=', $data['level']];
  3957. }
  3958. //status
  3959. if (isset($data['status']) && !empty($data['status'])) {
  3960. $where[] = ['notice.status', '=', $data['status']];
  3961. }
  3962. //type
  3963. if (isset($data['type']) && !empty($data['type'])) {
  3964. $where[] = ['notice.type', '=', $data['type']];
  3965. }
  3966. var_dump($data, '------------11111-2----test---------');
  3967. if ($data['type_id'] == 10000) {
  3968. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3969. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3970. })
  3971. ->where($where)
  3972. ->orderBy('updated_at', 'desc')
  3973. ->limit($data['page_size'])
  3974. ->offset(($data['page'] - 1) * $data['page_size'])
  3975. ->get();
  3976. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3977. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3978. })
  3979. ->where($where)
  3980. ->orderBy('updated_at', 'desc')
  3981. ->count();
  3982. } else {
  3983. $result = Notice::where($where)
  3984. // ->where('user_id', $data['user_id'])
  3985. ->Where(function ($query) use ($data) {
  3986. $query->Where(function ($q) use ($data) {
  3987. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3988. ->orWhere('notice.user_id', $data['user_id']);
  3989. });
  3990. })
  3991. ->when(!empty($data['status1']), function ($query) use ($data) {
  3992. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3993. })
  3994. ->orderBy('updated_at', 'desc')
  3995. ->limit($data['page_size'])
  3996. ->offset(($data['page'] - 1) * $data['page_size'])
  3997. ->get();
  3998. $total = Notice::where($where)
  3999. ->when(!empty($data['status1']), function ($query) use ($data) {
  4000. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4001. })
  4002. // ->where('user_id', $data['user_id'])
  4003. ->Where(function ($query) use ($data) {
  4004. $query->Where(function ($q) use ($data) {
  4005. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4006. ->orWhere('notice.user_id', $data['user_id']);
  4007. });
  4008. })
  4009. ->count();
  4010. }
  4011. if (empty($result)) {
  4012. return Result::error("查询失败", 0);
  4013. }
  4014. $data = [
  4015. 'rows' => $result,
  4016. 'count' => $total,
  4017. ];
  4018. return Result::success($data);
  4019. }
  4020. public function getNoticeDetail(array $data): array
  4021. {
  4022. $result = Notice::where('id', $data['id'])->first();
  4023. if (empty($result)) {
  4024. return Result::error("查询失败", 0);
  4025. }
  4026. return Result::success($result);
  4027. }
  4028. public function deleteNotice(array $data): array
  4029. {
  4030. $notice = Notice::where('id', $data['id'])->first();
  4031. if (empty($notice)) {
  4032. return Result::error("删除失败", 0);
  4033. }
  4034. $chat_group_id = $notice->group_id;
  4035. if ($chat_group_id) {
  4036. //删除群聊
  4037. ChatGroups::where('id', $chat_group_id)->delete();
  4038. //删除群成员
  4039. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4040. //删除群聊记录
  4041. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4042. }
  4043. $result = Notice::where('id', $data['id'])->delete();
  4044. return Result::success($result);
  4045. }
  4046. public function getComplaintList(array $data): array
  4047. {
  4048. var_dump($data, '00000001000000000000');
  4049. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4050. unset($data['type_id']);
  4051. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4052. $where = [];
  4053. if ($type_id != 10000 && empty($data['deal_user'])) {
  4054. $where['complaint.user_id'] = $user_id;
  4055. }
  4056. if (!empty($data['title'])) {
  4057. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4058. }
  4059. if (!empty($data['department_id'])) {
  4060. $where['complaint.department_id'] = $data['department_id'];
  4061. }
  4062. if (!empty($data['deal'])) {
  4063. $where['complaint.deal'] = $data['deal'];
  4064. }
  4065. if (!empty($data['status'])) {
  4066. $where['complaint.status'] = $data['status'];
  4067. }
  4068. var_dump(!empty($data['deal_user']), '----------1');
  4069. var_dump($where, '----------2');
  4070. $result = Complaint::where($where)
  4071. ->when(!empty($data['status1']), function ($query) use ($data) {
  4072. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4073. })
  4074. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4075. //json re_user_ids data[user_id]是不是在里面
  4076. $query->Where(function ($q) use ($data) {
  4077. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4078. ->where('complaint.status', 2);
  4079. });
  4080. })
  4081. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4082. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4083. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4084. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4085. ->orderBy('updated_at', 'desc')
  4086. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4087. //sql输出
  4088. if (empty($result)) {
  4089. return Result::error("暂无投诉信息", 0);
  4090. }
  4091. // 取出数据
  4092. $rows = $result->items();
  4093. $count = $result->total();
  4094. $responseData = [
  4095. 'rows' => $rows,
  4096. 'count' => $count,
  4097. ];
  4098. return Result::success($responseData);
  4099. }
  4100. public function getComplaintInfo(array $data): array
  4101. {
  4102. $result = Complaint::where('id', $data['id'])->first();
  4103. if (empty($result)) {
  4104. return Result::error("查询失败", 0);
  4105. }
  4106. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4107. $re_user_ids = json_decode($result['re_user_ids'], true);
  4108. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4109. //如果已经存在,就不再添加
  4110. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4111. $read_id = json_decode($result['read_id'], true);
  4112. if (!is_array($read_id)) {
  4113. $read_id = [];
  4114. }
  4115. if (!in_array($data['user_id'], $read_id)) {
  4116. $read_id[] = $data['user_id'];
  4117. $result['read_id'] = json_encode($read_id);
  4118. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4119. }
  4120. } else {
  4121. //如果不存在,就添加
  4122. $result['read_id'] = json_encode([$data['user_id']]);
  4123. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4124. }
  4125. }
  4126. return Result::success($result);
  4127. }
  4128. public function addComplaint(array $data): array
  4129. {
  4130. date_default_timezone_set('Asia/Shanghai');
  4131. $data['created_at'] = date('Y-m-d H:i:s');
  4132. $data['updated_at'] = date('Y-m-d H:i:s');
  4133. $this->sendMessage([
  4134. 'talk_type' => 800,
  4135. 'title' => $data['title'],
  4136. 'content' => '提交了审核',
  4137. 'messageType' => 6,
  4138. ]);
  4139. $result = Complaint::create($data);
  4140. return Result::success($result);
  4141. }
  4142. public function updateComplaint(array $data): array
  4143. {
  4144. date_default_timezone_set('Asia/Shanghai');
  4145. $data['updated_at'] = date('Y-m-d H:i:s');
  4146. $user_id = $data['user_id'] ?? 0;
  4147. $type_id = $data['type_id'] ?? 0;
  4148. unset($data['user_id']);
  4149. unset($data['type_id']);
  4150. $this->sendMessage([
  4151. 'talk_type' => 800,
  4152. 'title' => $data['title'],
  4153. 'content' => '提交了审核',
  4154. 'messageType' => 6,
  4155. ]);
  4156. $result = Complaint::where('id', $data['id'])->update($data);
  4157. return Result::success($result);
  4158. }
  4159. public function deleteComplaint(array $data): array
  4160. {
  4161. $result = Complaint::where('id', $data['id'])->delete();
  4162. return Result::success($result);
  4163. }
  4164. public function getComplainInfo(array $data): array
  4165. {
  4166. $result = Complaint::where('id', $data['id'])->first();
  4167. if (empty($result)) {
  4168. return Result::error("查询失败", 0);
  4169. }
  4170. return Result::success($result);
  4171. }
  4172. public function updateComplaintStatus(array $data): array
  4173. {
  4174. date_default_timezone_set('Asia/Shanghai');
  4175. $data['updated_at'] = date('Y-m-d H:i:s');
  4176. $user_id = $data['user_id'] ?? 0;
  4177. $type_id = $data['type_id'] ?? 0;
  4178. unset($data['user_id']);
  4179. unset($data['type_id']);
  4180. //处理, 写入处理人
  4181. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4182. $data['real_deal_user'] = $user_id;
  4183. }
  4184. //如果是deal 23,则判断是不是处理人
  4185. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4186. $complaintInof = Complaint::where('id', $data['id'])
  4187. ->where('real_deal_user', $user_id)
  4188. ->first();
  4189. if (empty($complaintInof)) {
  4190. return Result::error("处理人错误", 0);
  4191. }
  4192. }
  4193. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4194. if ($data['status'] == 2 && !isset($data['deal'])) {
  4195. $this->sendMessage([
  4196. 'talk_type' => 801,
  4197. 'title' => $complaintInfo['title'],
  4198. 'content' => '审核通过',
  4199. 'messageType' => 6,
  4200. 'user_id' => $complaintInfo['user_id'],
  4201. ]);
  4202. $this->sendMessage([
  4203. 'talk_type' => 802,
  4204. 'title' => $complaintInfo['title'],
  4205. 'content' => '待处理',
  4206. 'messageType' => 6,
  4207. 'user_id' => $complaintInfo['re_user_ids'],
  4208. ]);
  4209. }
  4210. if ($data['status'] == 3 && !isset($data['deal'])) {
  4211. $this->sendMessage([
  4212. 'talk_type' => 801,
  4213. 'title' => $complaintInfo['title'],
  4214. 'content' => '审核拒绝',
  4215. 'messageType' => 6,
  4216. 'user_id' => $complaintInfo['user_id'],
  4217. ]);
  4218. }
  4219. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4220. $this->sendMessage([
  4221. 'talk_type' => 802,
  4222. 'title' => $complaintInfo['title'],
  4223. 'content' => '处理中',
  4224. 'messageType' => 6,
  4225. 'user_id' => $complaintInfo['re_user_ids'],
  4226. ]);
  4227. }
  4228. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4229. $this->sendMessage([
  4230. 'talk_type' => 802,
  4231. 'title' => $complaintInfo['title'],
  4232. 'content' => '不予处理',
  4233. 'messageType' => 6,
  4234. 'user_id' => $complaintInfo['re_user_ids'],
  4235. ]);
  4236. }
  4237. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4238. $this->sendMessage([
  4239. 'talk_type' => 802,
  4240. 'title' => $complaintInfo['title'],
  4241. 'content' => '已完结',
  4242. 'messageType' => 6,
  4243. 'user_id' => $complaintInfo['re_user_ids'],
  4244. ]);
  4245. }
  4246. $result = complaint::where('id', $data['id'])->update($data);
  4247. return Result::success($result);
  4248. }
  4249. public function updateGoodStatus(array $data): array
  4250. {
  4251. $user_id = $data['user_id'] ?? 0;
  4252. $type_id = $data['type_id'] ?? 0;
  4253. unset($data['user_id']);
  4254. unset($data['type_id']);
  4255. $goodInfo = Good::where('id', $data['id'])->first();
  4256. if ($data['status'] == 2) {
  4257. $this->sendMessage([
  4258. 'talk_type' => 201,
  4259. 'title' => $goodInfo['name'],
  4260. 'content' => '审核通过',
  4261. 'messageType' => 3,
  4262. 'user_id' => $goodInfo['user_id'],
  4263. ]);
  4264. }
  4265. if ($data['status'] == 3) {
  4266. $this->sendMessage([
  4267. 'talk_type' => 201,
  4268. 'title' => $goodInfo['name'],
  4269. 'content' => '审核拒绝',
  4270. 'messageType' => 3,
  4271. 'user_id' => $goodInfo['user_id'],
  4272. ]);
  4273. }
  4274. $result = Good::where('id', $data['id'])->update($data);
  4275. return Result::success($result);
  4276. }
  4277. public function updateJobHuntingStatus(array $data): array
  4278. {
  4279. $user_id = $data['user_id'] ?? 0;
  4280. $type_id = $data['type_id'] ?? 0;
  4281. unset($data['user_id']);
  4282. unset($data['type_id']);
  4283. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4284. if($data['status']==2){
  4285. $this->sendMessage([
  4286. 'talk_type'=>600,
  4287. 'title'=>$jogHuntingInfo['name'],
  4288. 'content'=>'审核通过',
  4289. 'messageType'=>11,
  4290. 'user_id'=>$jogHuntingInfo['user_id'],
  4291. ]);
  4292. }
  4293. if($data['status']==3){
  4294. $this->sendMessage([
  4295. 'talk_type'=>600,
  4296. 'title'=>$jogHuntingInfo['name'],
  4297. 'content'=>'审核拒绝',
  4298. 'messageType'=>11,
  4299. 'user_id'=>$jogHuntingInfo['user_id'],
  4300. ]);
  4301. }
  4302. $result = JobHunting::where('id', $data['id'])->update($data);
  4303. return Result::success($result);
  4304. }
  4305. public function updateNoticeStatus(array $data): array
  4306. {
  4307. $user_id = $data['user_id'] ?? 0;
  4308. $type_id = $data['type_id'] ?? 0;
  4309. unset($data['user_id']);
  4310. unset($data['type_id']);
  4311. //查询公告
  4312. $notice = Notice::where('id', $data['id'])->first();
  4313. if (empty($notice)) {
  4314. return Result::error("公告不存在", 0);
  4315. }
  4316. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4317. if ($data['status'] == 2 && $notice['is_group'] == 1 && $notice['status'] == 1 && empty($notice['group_id'])) {
  4318. //chat_group
  4319. $group_id = PublicData::uuid();
  4320. $groupData = [
  4321. 'id' => $group_id,
  4322. 'creator_id' => $notice['user_id'],
  4323. 'group_name' => $notice['group_name'] ?? '',
  4324. 'profile' => $notice['profile'] ?? 0,
  4325. ];
  4326. var_dump($groupData, '-----------------groupData-------');
  4327. $groupResult = ChatGroups::insertGetId($groupData);
  4328. var_dump($groupResult, '-----------------groupid-------');
  4329. $groupMemberData = [
  4330. 'id' => PublicData::uuid(),
  4331. 'user_id' => $notice['user_id'],
  4332. 'group_id' => $group_id,
  4333. 'leader' => 2,
  4334. ];
  4335. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4336. //$chat_ids 去除掉$data['user_id']
  4337. $chat_ids = json_decode($notice['re_user_ids'], true);
  4338. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4339. //插入群成员表
  4340. $groupMemberDataUser = [];
  4341. $chatData = [];
  4342. foreach ($chat_ids as $key => $value) {
  4343. $groupMemberDataUser[] = [
  4344. 'id' => PublicData::uuid(),
  4345. 'user_id' => $value,
  4346. 'group_id' => $group_id,
  4347. 'leader' => 1,
  4348. ];
  4349. $chatData[] = [
  4350. 'user_id' => $value,
  4351. 'msg_type' => 1,
  4352. 'receiver_id' => $group_id,
  4353. 'content' => '通过通知创建群聊',
  4354. 'group_receiver_id' => $notice['user_id'],
  4355. 'action' => 'recieved',
  4356. 'created_at' => date('Y-m-d H:i:s'),
  4357. ];
  4358. }
  4359. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4360. ChatGroupsMember::insert($groupMemberDataUser);
  4361. //插入一条管理员聊天记录
  4362. $chatData[] = [
  4363. 'user_id' => $notice['user_id'],
  4364. 'msg_type' => 1,
  4365. 'receiver_id' => $group_id,
  4366. 'content' => '通过通知创建群聊',
  4367. 'group_receiver_id' => $notice['user_id'],
  4368. 'action' => 'said',
  4369. 'created_at' => date('Y-m-d H:i:s'),
  4370. ];
  4371. var_dump($chatData, '-----------------chatData-------');
  4372. $chatResult = ChatRecords::insert($chatData);
  4373. //更新result的 group_id
  4374. $data['group_id'] = $group_id;
  4375. Notice::where(['id' => $data['id']])->update($data);
  4376. }
  4377. $result = Notice::where('id', $data['id'])->update($data);
  4378. $noticeInfo = Notice::where('id', $data['id'])->first();
  4379. if ($data['status'] == 2) {
  4380. $this->sendMessage([
  4381. 'talk_type' => 701,
  4382. 'title' => $noticeInfo['title'],
  4383. 'content' => '审核通过',
  4384. 'messageType' => 3,
  4385. 'user_id' => $noticeInfo['user_id'],
  4386. ]);
  4387. }
  4388. if ($data['status'] == 3) {
  4389. $this->sendMessage([
  4390. 'talk_type' => 701,
  4391. 'title' => $noticeInfo['title'],
  4392. 'content' => '审核拒绝',
  4393. 'messageType' => 3,
  4394. 'user_id' => $noticeInfo['user_id'],
  4395. ]);
  4396. }
  4397. return Result::success($result);
  4398. }
  4399. public function getDUser(array $data): array
  4400. {
  4401. if (!empty($data['ids'])) {
  4402. $user = User::whereIn('id', $data['ids'])->getall();
  4403. if (empty($user)) {
  4404. return Result::error('无数据', 0);
  4405. }
  4406. return Result::success($user);
  4407. }
  4408. $where = [];
  4409. if (!empty($data['department_id'])) {
  4410. $where['department_id'] = $data['department_id'];
  4411. }
  4412. if (!empty($data['city_id'])) {
  4413. $where['city_id'] = $data['city_id'];
  4414. }
  4415. $result = User::where('type_id', 2)
  4416. ->where('status', 1)
  4417. ->where($where)
  4418. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4419. ->get();
  4420. if (empty($result)) {
  4421. return Result::error("查询失败", 0);
  4422. }
  4423. return Result::success($result);
  4424. }
  4425. /**
  4426. * 验证导航名称是否重复
  4427. * @return void
  4428. */
  4429. public function checkCategoryName(array $data): array
  4430. {
  4431. $result = Category::when($data, function ($query) use ($data) {
  4432. if (isset($data['name']) && $data['name']) {
  4433. $query->where("name", $data['name']);
  4434. }
  4435. if (isset($data['id']) && $data['id']) {
  4436. $query->where("id", "!=", $data['id']);
  4437. }
  4438. })->first();
  4439. if ($result) {
  4440. return Result::error("已存在");
  4441. } else {
  4442. return Result::success();
  4443. }
  4444. }
  4445. //20250226 产品列表
  4446. // 20250306 -------招聘--------fr
  4447. /*
  4448. * 招聘列表
  4449. * */
  4450. public function getJobRecruitingList(array $data): array
  4451. {
  4452. $where = [];
  4453. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4454. if ($data['checkout'] == 0) {
  4455. $job_status = [0, 2];
  4456. } else {
  4457. $job_status = [1];
  4458. }
  4459. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4460. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4461. }
  4462. $user = User::where('id', $data['user_id'])->first();
  4463. if (empty($user)) {
  4464. return Result::error("用户不存在", 0);
  4465. }
  4466. // 3:企业会员
  4467. if ($user['type_id'] == 3) {
  4468. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4469. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4470. }
  4471. // 如果 $where 为空,则不添加 where 条件
  4472. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4473. return $query->where($where);
  4474. })
  4475. ->whereIn('job_recruiting.status', $job_status)
  4476. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4477. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4478. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4479. ->orderBy("updated_at", "desc")
  4480. ->offset(($data['page'] - 1) * $data['page_size'])
  4481. ->limit($data['page_size'])
  4482. ->get()
  4483. ->all();
  4484. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4485. return $query->where($where);
  4486. })
  4487. ->whereIn('job_recruiting.status', $job_status)
  4488. ->count();
  4489. if (empty($result)) {
  4490. return Result::error("暂无招聘信息", 0);
  4491. }
  4492. return Result::success($result);
  4493. }
  4494. /*
  4495. * 招聘信息添加
  4496. * */
  4497. public function addJobRecruiting(array $data): array
  4498. {
  4499. // return Result::success($data);
  4500. $user = User::where('user.id', $data['user_id'])
  4501. ->where('user.status', 1)
  4502. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4503. ->select(
  4504. 'user.type_id',
  4505. 'user.mobile',
  4506. 'user.email',
  4507. 'user_info.business_name',
  4508. 'user_info.company_hy_id',
  4509. 'user_info.company_nature',
  4510. 'user_info.company_size',
  4511. 'user_info.introduction',
  4512. 'user_info.real_name',
  4513. 'user_info.company_url',
  4514. 'user_info.address_arr_id',
  4515. 'user_info.address'
  4516. )
  4517. ->first();
  4518. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4519. return Result::error("用户不存在", 0);
  4520. }
  4521. $web = Website::where('id', $data['website_id'])->first();
  4522. if (empty($web)) {
  4523. return Result::error("网站不存在", 0);
  4524. }
  4525. // return Result::success($user);
  4526. $data['action_id'] = $data['user_id'];
  4527. $data['user_type'] = $user['type_id'];
  4528. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4529. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4530. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4531. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4532. // 公司地址 管理员必填
  4533. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4534. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4535. // 管理员-企业相关信息
  4536. $company = [
  4537. // 'user_id' => $data['user_id']?? null,
  4538. 'business_name' => $data['business_name'] ?? null,
  4539. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4540. 'company_size' => $data['company_size'] ?? null,
  4541. 'company_nature' => $data['company_nature'] ?? null,
  4542. 'introduction' => $data['introduction'] ?? null,
  4543. 'real_name' => $data['real_name'] ?? null,
  4544. 'mobile' => $data['mobile'] ?? null,
  4545. 'company_url' => $data['company_url'] ?? null,
  4546. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4547. 'address' => $data['address'] ?? null,
  4548. 'email' => $data['email'] ?? null,
  4549. ];
  4550. //去掉相关企业信息
  4551. $job = array_diff_key($data, array_flip(array_keys($company)));
  4552. Db::beginTransaction();
  4553. try {
  4554. // 先添加职位相关信息
  4555. if ($user['type_id'] == 10000) {
  4556. $job['status'] = 1;
  4557. }
  4558. if (empty($data['experience']) || $data['experience'] == '') {
  4559. $job['experience'] = null;
  4560. } else {
  4561. $job['experience'] = $data['experience'];
  4562. }
  4563. if((isset($data['status']) && $data['status']==0) || !isset($data['status'])){
  4564. $this->sendMessage([
  4565. 'talk_type'=>500,
  4566. 'title'=>$data['title'],
  4567. 'content'=>'提交了审核',
  4568. 'messageType'=>10,
  4569. ]);
  4570. }
  4571. $jobId = JobRecruiting::insertGetId($job);
  4572. if (empty($jobId)) {
  4573. Db::rollBack();
  4574. return Result::error("添加失败");
  4575. }
  4576. // 添加公司信息
  4577. $company['user_id'] = $data['user_id'] ?? null;
  4578. $company['job_id'] = $jobId;
  4579. $company['user_type'] = $user['type_id'] ?? null;
  4580. $company['website_id'] = $data['website_id'] ?? null;
  4581. if ($user['type_id'] == 10000) {
  4582. // 管理员添加企业信息
  4583. // return Result::success($company);
  4584. $companyId = JobCompany::insertGetId($company);
  4585. if (empty($companyId)) {
  4586. Db::rollBack();
  4587. return Result::error("添加失败");
  4588. }
  4589. } else {
  4590. // 企业会员添加企业信息
  4591. $company = [
  4592. 'user_id' => $data['user_id'] ?? null,
  4593. 'business_name' => $user['business_name'] ?? null,
  4594. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4595. 'company_size' => $user['company_size'] ?? null,
  4596. 'company_nature' => $user['company_nature'] ?? null,
  4597. 'introduction' => $user['introduction'] ?? null,
  4598. 'real_name' => $user['real_name'] ?? null,
  4599. 'mobile' => $user['mobile'] ?? null,
  4600. 'company_url' => $user['company_url'] ?? null,
  4601. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4602. 'address' => $user['address'] ?? null,
  4603. 'email' => $user['email'] ?? null,
  4604. 'website_id' => $data['website_id'] ?? null,
  4605. 'user_type' => $user['type_id'] ?? null,
  4606. 'job_id' => $jobId,
  4607. ];
  4608. $companyId = JobCompany::insertGetId($company);
  4609. if (empty($companyId)) {
  4610. Db::rollBack();
  4611. return Result::error("添加失败");
  4612. }
  4613. // return Result::success($company);
  4614. }
  4615. Db::commit();
  4616. } catch (\Exception $e) {
  4617. Db::rollBack();
  4618. return Result::error($e->getMessage(), 0);
  4619. }
  4620. $result = [
  4621. 'job_id' => $jobId,
  4622. 'company_id' => $companyId,
  4623. ];
  4624. if (empty($result)) {
  4625. return Result::error("添加失败", 0);
  4626. }
  4627. return Result::success($result);
  4628. }
  4629. /*
  4630. * 获取招聘信息详情
  4631. * */
  4632. public function getJobRecruitingInfo(array $data): array
  4633. {
  4634. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4635. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4636. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4637. ->select(
  4638. 'job_recruiting.*',
  4639. 'website.website_name as website_name',
  4640. 'job_company.business_name',
  4641. 'job_company.company_hy_id',
  4642. 'job_company.company_size',
  4643. 'job_company.company_nature',
  4644. 'job_company.introduction',
  4645. 'job_company.real_name',
  4646. 'job_company.mobile',
  4647. 'job_company.company_url',
  4648. 'job_company.address_arr_id',
  4649. 'job_company.address',
  4650. 'job_company.email'
  4651. )
  4652. ->first();
  4653. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4654. if (!empty($cityId)) {
  4655. if (isset($cityId[1]) && $cityId[1] != null) {
  4656. $city = District::where('id', $cityId[1])->first(['name']);
  4657. } else {
  4658. $city = District::where('id', $cityId[0])->first(['name']);
  4659. }
  4660. $result['city'] = $city['name'] ?? '';
  4661. }
  4662. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4663. if (is_array($addressId) && !empty($addressId)) {
  4664. $address = District::whereIn('id', $addressId)
  4665. ->orderBy('level', 'asc')
  4666. ->get(['name'])
  4667. ->pluck('name')
  4668. ->implode('');
  4669. // $job->address_name = $address ?? '';
  4670. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4671. }
  4672. if (empty($result)) {
  4673. return Result::error("招聘信息不存在", 0);
  4674. }
  4675. // return Result::success($job);
  4676. return Result::success($result);
  4677. }
  4678. /*
  4679. * 修改招聘信息
  4680. * */
  4681. public function upJobRecruiting(array $data): array
  4682. {
  4683. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4684. // return Result::success($job);
  4685. if (empty($job)) {
  4686. return Result::error("招聘信息不存在", 0);
  4687. }
  4688. $user = User::where('id', $data['user_id'])->first();
  4689. // return Result::success($user);
  4690. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4691. return Result::error("用户不存在", 0);
  4692. }
  4693. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4694. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4695. }
  4696. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4697. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4698. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4699. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4700. // 公司地址 管理员必填
  4701. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4702. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4703. // 管理员-企业相关信息
  4704. $company = [
  4705. 'business_name' => $data['business_name'] ?? null,
  4706. 'company_hy_id' => $data['hy_id'] ?? null,
  4707. 'company_size' => $data['company_size'] ?? null,
  4708. 'company_nature' => $data['company_nature'] ?? null,
  4709. 'introduction' => $data['introduction'] ?? null,
  4710. 'real_name' => $data['real_name'] ?? null,
  4711. 'mobile' => $data['mobile'] ?? null,
  4712. 'company_url' => $data['company_url'] ?? null,
  4713. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4714. 'address' => $data['address'] ?? null,
  4715. 'email' => $data['email'] ?? null,
  4716. ];
  4717. //去掉相关企业信息
  4718. $data = array_diff_key($data, array_flip(array_keys($company)));
  4719. $jobId = $data['id'];
  4720. $web = $data['website_id'];
  4721. $data['action_id'] = $data['user_id'];
  4722. unset($data['user_id']);
  4723. unset($data['user_type']);
  4724. unset($data['id']);
  4725. unset($data['website_id']);
  4726. // return Result::success($data);
  4727. Db::beginTransaction();
  4728. try {
  4729. // 管理员修改招聘信息
  4730. if ($user['type_id'] == 10000) {
  4731. $data['website_id'] = $web;
  4732. $company['website_id'] = $data['website_id'];
  4733. $data['status'] = 1;
  4734. } else {
  4735. $data['status'] = 0;
  4736. }
  4737. if (empty($data['experience']) || $data['experience'] == '') {
  4738. $job['experience'] = null;
  4739. } else {
  4740. $job['experience'] = $data['experience'];
  4741. }
  4742. // Db::rollBack();
  4743. // return Result::success($company);
  4744. if((isset($data['status']) && $data['status']==0) || !isset($data['status'])){
  4745. $this->sendMessage([
  4746. 'talk_type'=>500,
  4747. 'title'=>$data['title'],
  4748. 'content'=>'提交了审核',
  4749. 'messageType'=>10,
  4750. ]);
  4751. }
  4752. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4753. if (empty($result['job'])) {
  4754. Db::rollBack();
  4755. return Result::error("修改招聘信息失败");
  4756. }
  4757. // 管理员修改企业相关信息
  4758. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4759. if (empty($result['company'])) {
  4760. Db::rollBack();
  4761. return Result::error("修改企业相关信息失败");
  4762. }
  4763. Db::commit();
  4764. // return Result::success($result);
  4765. } catch (\Exception $e) {
  4766. Db::rollBack();
  4767. return Result::error($e->getMessage(), 0);
  4768. }
  4769. return Result::success($result);
  4770. }
  4771. /*
  4772. * 招聘信息删除
  4773. * */
  4774. public function delJobRecruiting(array $data): array
  4775. {
  4776. $user = User::where('id', $data['user_id'])->first();
  4777. if (empty($user)) {
  4778. return Result::error("用户不存在", 0);
  4779. }
  4780. $job = JobRecruiting::where('id', $data['id'])->first();
  4781. if (empty($job)) {
  4782. return Result::error("招聘信息不存在", 0);
  4783. }
  4784. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4785. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4786. }
  4787. Db::beginTransaction();
  4788. try {
  4789. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4790. if (empty($result['job'])) {
  4791. Db::rollBack();
  4792. return Result::error("删除招聘信息失败");
  4793. }
  4794. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4795. if (empty($result['company'])) {
  4796. Db::rollBack();
  4797. return Result::error("删除企业相关信息失败");
  4798. }
  4799. Db::commit();
  4800. } catch (\Exception $e) {
  4801. Db::rollBack();
  4802. return Result::error($e->getMessage(), 0);
  4803. }
  4804. return Result::success($result);
  4805. }
  4806. /*
  4807. * 获取公司信息
  4808. * */
  4809. public function getJobCompany(array $data): array
  4810. {
  4811. $user = User::where('user.id', $data['user_id'])
  4812. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4813. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4814. ->first();
  4815. // return Result::success($user);
  4816. if (empty($user)) {
  4817. return Result::error("用户不存在", 0);
  4818. }
  4819. if ($user['type_id'] == 3) {
  4820. $result = [
  4821. // 'id' => 0,
  4822. 'user_id' => $data['user_id'],
  4823. 'website_id' => $data['website_id'],
  4824. 'business_name' => $user['business_name'], // 企业名称
  4825. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4826. 'company_nature' => $user['company_nature'], // 公司性质
  4827. 'company_size' => $user['company_size'], // 公司规模
  4828. 'introduction' => $user['introduction'], // 公司简介
  4829. 'real_name' => $user['real_name'], // 企业联系人
  4830. 'mobile' => $user['mobile'], // 企业联系电话
  4831. 'company_url' => $user['company_url'], // 企业网址
  4832. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4833. 'address' => $user['address'], // 企业地址
  4834. 'email' => $user['email'], // 企业邮箱
  4835. ];
  4836. } else {
  4837. return Result::error("用户类型错误", 0);
  4838. }
  4839. if (empty($result)) {
  4840. return Result::error("公司信息不存在", 0);
  4841. }
  4842. return Result::success($result);
  4843. }
  4844. /*
  4845. * 修改公司信息
  4846. * */
  4847. public function upJobCompany(array $data): array
  4848. {
  4849. // return Result::success($data);
  4850. $user = User::where('user.id', $data['user_id'])
  4851. ->where('user.status', 1)
  4852. ->select('user.user_name', 'user.type_id')
  4853. ->first();
  4854. if (empty($user)) {
  4855. return Result::error("用户不存在", 0);
  4856. }
  4857. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4858. $company = [
  4859. 'business_name' => $data['business_name'], // 企业名称
  4860. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4861. 'company_nature' => $data['company_nature'], // 公司性质
  4862. 'company_size' => $data['company_size'], // 公司规模
  4863. 'introduction' => $data['introduction'], // 公司简介
  4864. // 'real_name' => $data['real_name'], // 企业联系人
  4865. 'company_url' => $data['company_url'], // 企业网址
  4866. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4867. 'address' => $data['address'], // 企业详细地址
  4868. ];
  4869. if ($user['type_id'] == 3) {
  4870. Db::beginTransaction();
  4871. try {
  4872. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  4873. 'business_name' => $data['business_name'], // 企业名称
  4874. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4875. 'company_nature' => $data['company_nature'], // 公司性质
  4876. 'company_size' => $data['company_size'], // 公司规模
  4877. 'introduction' => $data['introduction'], // 公司简介
  4878. // 'real_name' => $data['real_name'], // 企业联系人
  4879. 'company_url' => $data['company_url'], // 企业网址
  4880. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4881. 'address' => $data['address'], // 企业详细地址
  4882. ]);
  4883. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  4884. Db::commit();
  4885. } catch (\Exception $e) {
  4886. Db::rollBack();
  4887. return Result::error($e->getMessage(), 0);
  4888. }
  4889. } else {
  4890. return Result::error("用户类型错误", 0);
  4891. }
  4892. if (empty($result)) {
  4893. return Result::error("修改失败", 0);
  4894. }
  4895. return Result::success($result);
  4896. }
  4897. /*
  4898. * 获取省-市
  4899. * */
  4900. public function getJobRecruitingArea(array $data): array
  4901. {
  4902. if (isset($data['pid']) && $data['pid'] != null) {
  4903. $result = District::where('pid', $data['pid'])->get()->all();
  4904. } else {
  4905. $result = District::where('level', 1)->get()->all();
  4906. }
  4907. if (empty($result)) {
  4908. return Result::error("暂无此省市", 0);
  4909. }
  4910. return Result::success($result);
  4911. }
  4912. /*
  4913. * 获取行业分类
  4914. * */
  4915. public function getIndustry(array $data): array
  4916. {
  4917. $result = JobIndustry::get()->all();
  4918. if (empty($result)) {
  4919. return Result::error("暂无行业分类", 0);
  4920. }
  4921. return Result::success($result);
  4922. }
  4923. /*
  4924. * 获取职位
  4925. * */
  4926. public function getPositionList(array $data): array
  4927. {
  4928. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  4929. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  4930. } else {
  4931. $result = JobPosition::where('zwpid', 0)->get()->all();
  4932. }
  4933. if (empty($result)) {
  4934. return Result::error("暂无此职位", 0);
  4935. }
  4936. return Result::success($result);
  4937. }
  4938. /*
  4939. * 获取工作性质-菜单
  4940. * */
  4941. public function getJobNature(array $data): array
  4942. {
  4943. $result = JobEnum::where('egroup', 'nature')->get()->all();
  4944. if (empty($result)) {
  4945. return Result::error("暂无工作性质", 0);
  4946. }
  4947. return Result::success($result);
  4948. }
  4949. /*
  4950. * 获取工作经验-菜单
  4951. * */
  4952. public function getExperience(array $data): array
  4953. {
  4954. $result = JobEnum::where('egroup', 'years')->get()->all();
  4955. if (empty($result)) {
  4956. return Result::error("暂无工作经验", 0);
  4957. }
  4958. return Result::success($result);
  4959. }
  4960. /*
  4961. * 获取学历-菜单
  4962. * */
  4963. public function getEducation(array $data): array
  4964. {
  4965. $result = JobEnum::where('egroup', 'education')->get()->all();
  4966. if (empty($result)) {
  4967. return Result::error("暂无学历", 0);
  4968. }
  4969. return Result::success($result);
  4970. }
  4971. /*
  4972. * 获取薪资-菜单
  4973. * */
  4974. public function getSalary(array $data): array
  4975. {
  4976. $result = JobEnum::where('egroup', 'income')->get()->all();
  4977. if (empty($result)) {
  4978. return Result::error("暂无薪资", 0);
  4979. }
  4980. return Result::success($result);
  4981. }
  4982. /*
  4983. * 获取语言-菜单
  4984. * */
  4985. public function getLanguage(array $data): array
  4986. {
  4987. $result = JobEnum::where('egroup', 'language')->get()->all();
  4988. if (empty($result)) {
  4989. return Result::error("暂无语言", 0);
  4990. }
  4991. return Result::success($result);
  4992. }
  4993. /*
  4994. * 获取掌握程度-菜单
  4995. * */
  4996. public function getLevel(array $data): array
  4997. {
  4998. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  4999. if (empty($result)) {
  5000. return Result::error("暂无工作性质", 0);
  5001. }
  5002. return Result::success($result);
  5003. }
  5004. // 公司信息
  5005. /*
  5006. * 获取公司性质-菜单
  5007. * */
  5008. public function getCompanyNature(array $data): array
  5009. {
  5010. $result = JobNature::get()->all();
  5011. if (empty($result)) {
  5012. return Result::error("暂无公司性质", 0);
  5013. }
  5014. return Result::success($result);
  5015. }
  5016. /*
  5017. * 获取公司规模-菜单
  5018. * */
  5019. public function getCompanySize(array $data): array
  5020. {
  5021. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5022. if (empty($result)) {
  5023. return Result::error("暂无公司规模", 0);
  5024. }
  5025. return Result::success($result);
  5026. }
  5027. /*
  5028. * 招聘信息审核
  5029. * */
  5030. public function checkJobRecruiting(array $data): array
  5031. {
  5032. $user = User::where('id', $data['user_id'])->first();
  5033. if (empty($user)) {
  5034. return Result::error("用户不存在", 0);
  5035. }
  5036. $job = JobRecruiting::where('id', $data['id'])->first();
  5037. if (empty($job)) {
  5038. return Result::error("招聘信息不存在", 0);
  5039. }
  5040. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5041. if ($user['type_id'] != 10000) {
  5042. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5043. }
  5044. // 驳回原因
  5045. if ($data['status'] == 2) {
  5046. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5047. }
  5048. $data['action_id'] = $data['user_id'];
  5049. unset($data['user_id']);
  5050. if($data['status']==1){
  5051. $this->sendMessage([
  5052. 'talk_type'=>500,
  5053. 'title'=>$job['title'],
  5054. 'content'=>'审核通过',
  5055. 'messageType'=>10,
  5056. 'user_id'=>$job['user_id'],
  5057. ]);
  5058. }
  5059. if($data['status']==2){
  5060. $this->sendMessage([
  5061. 'talk_type'=>500,
  5062. 'title'=>$job['title'],
  5063. 'content'=>'审核拒绝',
  5064. 'messageType'=>10,
  5065. 'user_id'=>$job['user_id'],
  5066. ]);
  5067. }
  5068. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5069. if (empty($result)) {
  5070. return Result::error("审核失败", 0);
  5071. }
  5072. return Result::success($result);
  5073. }
  5074. public function myApplyList(array $data): array
  5075. {
  5076. var_dump($data, '------参数');
  5077. $user = User::where('id', $data['user_id'])->first();
  5078. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5079. return Result::error("用户不存在", 0);
  5080. }
  5081. // 1:个人会员 职场机会
  5082. if ($user['type_id'] == 1) {
  5083. $where['user_id'] = $user['id'];
  5084. }
  5085. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5086. $query->where('user_id', $user['id']);
  5087. })
  5088. ->pluck('recruit_id');
  5089. $where = [];
  5090. if (isset($data['salary']) && $data['salary'] != null) {
  5091. $where['job_recruiting.salary'] = $data['salary'];
  5092. }
  5093. if (isset($data['experience']) && $data['experience'] != null) {
  5094. $where['job_recruiting.experience'] = $data['experience'];
  5095. }
  5096. if (isset($data['business_name']) && $data['business_name'] != null) {
  5097. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5098. }
  5099. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5100. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5101. ->where($where);
  5102. // ->count();
  5103. $count = $query->count();
  5104. $query = clone $query;
  5105. $job = $query
  5106. ->leftJoin('job_enum as income_enum', function ($join) {
  5107. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5108. ->where('income_enum.egroup', 'income');
  5109. })
  5110. ->leftJoin('job_enum as years_enum', function ($join) {
  5111. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5112. ->where('years_enum.egroup', 'years');
  5113. })
  5114. // ->where($where)
  5115. ->orderBy('job_recruiting.updated_at', 'desc')
  5116. ->select(
  5117. 'job_recruiting.id',
  5118. 'job_recruiting.title',
  5119. 'job_company.business_name',
  5120. 'income_enum.evalue as salary_evalue',
  5121. 'income_enum.ename as salary_ename',
  5122. 'years_enum.evalue as experience_evalue',
  5123. 'years_enum.ename as experience_ename',
  5124. 'job_recruiting.updated_at'
  5125. )
  5126. ->offset(($data['page'] - 1) * $data['pageSize'])
  5127. ->limit($data['pageSize'])
  5128. ->get()
  5129. ->all();
  5130. if (empty($job)) {
  5131. return Result::error("暂无招聘信息", 0);
  5132. }
  5133. $result = [
  5134. 'row' => $job,
  5135. 'count' => $count,
  5136. ];
  5137. return Result::success($result);
  5138. }
  5139. /*
  5140. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5141. * */
  5142. public function getRecruitingList(array $data): array
  5143. {
  5144. $user = User::where('id', $data['user_id'])->first();
  5145. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5146. return Result::error("用户不存在", 0);
  5147. }
  5148. // 1:个人会员 职场机会
  5149. if ($user['type_id'] == 1) {
  5150. $where['user_id'] = $user['id'];
  5151. }
  5152. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5153. $query->where('receiver_id', $user['id']);
  5154. })
  5155. ->pluck('recruit_id');
  5156. // return Result::success($recruitingId);
  5157. $where = [];
  5158. if (isset($data['salary']) && $data['salary'] != null) {
  5159. $where['job_recruiting.salary'] = $data['salary'];
  5160. }
  5161. if (isset($data['experience']) && $data['experience'] != null) {
  5162. $where['job_recruiting.experience'] = $data['experience'];
  5163. }
  5164. if (isset($data['business_name']) && $data['business_name'] != null) {
  5165. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5166. }
  5167. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5168. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5169. ->where($where);
  5170. // ->count();
  5171. $count = $query->count();
  5172. $query = clone $query;
  5173. $job = $query
  5174. ->leftJoin('job_enum as income_enum', function ($join) {
  5175. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5176. ->where('income_enum.egroup', 'income');
  5177. })
  5178. ->leftJoin('job_enum as years_enum', function ($join) {
  5179. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5180. ->where('years_enum.egroup', 'years');
  5181. })
  5182. // ->where($where)
  5183. ->orderBy('job_recruiting.updated_at', 'desc')
  5184. ->select(
  5185. 'job_recruiting.id',
  5186. 'job_recruiting.title',
  5187. 'job_company.business_name',
  5188. 'income_enum.evalue as salary_evalue',
  5189. 'income_enum.ename as salary_ename',
  5190. 'years_enum.evalue as experience_evalue',
  5191. 'years_enum.ename as experience_ename',
  5192. 'job_recruiting.updated_at'
  5193. )
  5194. ->offset(($data['page'] - 1) * $data['pageSize'])
  5195. ->limit($data['pageSize'])
  5196. ->get()
  5197. ->all();
  5198. if (empty($job)) {
  5199. return Result::error("暂无招聘信息", 0);
  5200. }
  5201. $result = [
  5202. 'row' => $job,
  5203. 'count' => $count,
  5204. ];
  5205. return Result::success($result);
  5206. }
  5207. /*
  5208. * 获取企业会员-招聘信息列表
  5209. * */
  5210. public function getRecruitingInfo(array $data): array
  5211. {
  5212. $user = User::where('id', $data['user_id'])->first();
  5213. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5214. return Result::error("用户不存在", 0);
  5215. }
  5216. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5217. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5218. ->select(
  5219. 'job_recruiting.*',
  5220. 'job_company.business_name',
  5221. 'job_company.company_hy_id',
  5222. 'job_company.company_size',
  5223. 'job_company.company_nature',
  5224. 'job_company.introduction',
  5225. 'job_company.real_name',
  5226. 'job_company.mobile',
  5227. 'job_company.company_url',
  5228. 'job_company.address_arr_id',
  5229. 'job_company.address',
  5230. 'job_company.email'
  5231. )
  5232. ->get();
  5233. if (empty($recruiting)) {
  5234. return Result::error("暂无招聘信息", 0);
  5235. }
  5236. return Result::success($recruiting);
  5237. }
  5238. /*
  5239. * 获取企业会员-我的沟通
  5240. * */
  5241. public function getJobResumeList(array $data): array
  5242. {
  5243. $user = User::where('id', $data['user_id'])->first();
  5244. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5245. return Result::error("用户不存在", 0);
  5246. }
  5247. $where = [];
  5248. if (isset($data['salary']) && $data['salary'] != null) {
  5249. $where['job_hunting.salary'] = $data['salary'];
  5250. }
  5251. if (isset($data['user_name']) && $data['user_name'] != null) {
  5252. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5253. }
  5254. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5255. $query->where('job_resume.user_id', $user['id']);
  5256. })
  5257. ->when(!empty($where), function ($query) use ($where) {
  5258. $query->where($where);
  5259. })
  5260. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5261. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5262. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5263. ->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');
  5264. $count = $job->count();
  5265. if ($count == 0) {
  5266. return Result::error("暂无沟通记录", 0);
  5267. }
  5268. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5269. ->offset(($data['page'] - 1) * $data['pageSize'])
  5270. ->limit($data['pageSize'])
  5271. ->get();
  5272. if (empty($jobs)) {
  5273. return Result::error("暂无沟通记录", 0);
  5274. }
  5275. $result['row'] = $this->processJob($jobs, '');
  5276. $result['count'] = $count;
  5277. return Result::success($result);
  5278. }
  5279. // 20250306 招聘
  5280. //20250422 书刊音像
  5281. public function addBook(array $data): array
  5282. {
  5283. $user_id = $data['user_id'] ?? 0;
  5284. $type_id = $data['type_id'] ?? 0;
  5285. // $website_id = $data['website_id'] ?? 0;
  5286. // unset($data['user_id']);
  5287. unset($data['type_id']);
  5288. // unset($data['website_id']);
  5289. //处理数组
  5290. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5291. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5292. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5293. if ($data['img_url'] == '') {
  5294. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5295. preg_match_all($reg, $data['detail'], $matches);
  5296. if (isset($matches[1][0])) {
  5297. //截取varchar240
  5298. $data['img_url'] = substr($matches[1][0], 0, 240);
  5299. }
  5300. }
  5301. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5302. //提取标题+内容中的关键词
  5303. $data['keyword'] = $data['title'];
  5304. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5305. Jieba::init(); // 初始化 jieba-php
  5306. Finalseg::init();
  5307. $segList = Jieba::cut($data['keyword']);
  5308. $segList1 = array_slice($segList, 0, 8);
  5309. $data['keyword'] = implode(',', $segList1);
  5310. }
  5311. if ($data['description'] == '') {
  5312. //提取内容中的描述
  5313. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5314. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5315. }
  5316. var_dump($data, '--');
  5317. if($data['status']==1){
  5318. $this->sendMessage([
  5319. 'talk_type'=>400,
  5320. 'title'=>$data['title'],
  5321. 'content'=>'提交了审核',
  5322. 'messageType'=>7,
  5323. ]);
  5324. }
  5325. $result = Book::insertGetId($data);
  5326. if (empty($result)) {
  5327. return Result::error("添加失败", 0);
  5328. }
  5329. return Result::success($result);
  5330. }
  5331. public function getBookList(array $data): array
  5332. {
  5333. $where = [];
  5334. if (!empty($data["title"])) {
  5335. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5336. }
  5337. if (!empty($data['website_name'])) {
  5338. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5339. }
  5340. if (!empty($data['status'])) {
  5341. $where[] = ['book.status', '=', $data['status']];
  5342. }
  5343. $user_id = $data['user_id'];
  5344. $type_id = $data['type_id'];
  5345. // $type_id = 4;
  5346. var_dump($type_id, '------1--------');
  5347. if ($type_id != 10000) {
  5348. $where[] = ['book.user_id', '=', $user_id];
  5349. }
  5350. var_dump(!empty($data['status1']), '=-===1');
  5351. $result = Book::where($where)
  5352. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5353. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5354. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5355. ->when(isset($data['status1']), function ($query) use ($data) {
  5356. $query->whereIn('book.status', [1, 3]);
  5357. })
  5358. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5359. ->orderBy("updated_at", "desc")
  5360. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5361. if (empty($result)) {
  5362. return Result::error("暂无数据", 0);
  5363. }
  5364. // 取出数据
  5365. $rows = $result->items();
  5366. $count = $result->total();
  5367. $responseData = [
  5368. 'rows' => $rows,
  5369. 'count' => $count,
  5370. ];
  5371. return Result::success($responseData);
  5372. }
  5373. public function deleteBook(array $data): array
  5374. {
  5375. $result = Book::where('id', $data['id'])->delete();
  5376. if (empty($result)) {
  5377. return Result::error("删除失败", 0);
  5378. }
  5379. return Result::success($result);
  5380. }
  5381. public function updateBook(array $data): array
  5382. {
  5383. // $user_id = $data['user_id'] ?? 0;
  5384. $type_id = $data['type_id'] ?? 0;
  5385. // $website_id = $data['website_id'] ?? 0;
  5386. unset($data['user_id']);
  5387. unset($data['type_id']);
  5388. // unset($data['website_id']);
  5389. //处理数组
  5390. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5391. if ($data['img_url'] == '') {
  5392. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5393. preg_match_all($reg, $data['detail'], $matches);
  5394. if (isset($matches[1][0])) {
  5395. //截取varchar240
  5396. $data['img_url'] = substr($matches[1][0], 0, 240);
  5397. }
  5398. }
  5399. if ($data['keyword'] == '') {
  5400. //提取标题+内容中的关键词
  5401. $data['keyword'] = $data['title'];
  5402. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5403. Jieba::init(); // 初始化 jieba-php
  5404. Finalseg::init();
  5405. $segList = Jieba::cut($data['keyword']);
  5406. $segList1 = array_slice($segList, 0, 8);
  5407. $data['keyword'] = implode(',', $segList1);
  5408. }
  5409. if ($data['description'] == '') {
  5410. //提取内容中的描述
  5411. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5412. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5413. }
  5414. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5415. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5416. if($data['status']==1){
  5417. $this->sendMessage([
  5418. 'talk_type'=>400,
  5419. 'title'=>$data['title'],
  5420. 'content'=>'提交了审核',
  5421. 'messageType'=>7,
  5422. ]);
  5423. }
  5424. $result = Book::where("id", $data["id"])->update($data);
  5425. if (empty($result)) {
  5426. return Result::error("更新失败", 0);
  5427. }
  5428. return Result::success($result);
  5429. }
  5430. public function getBookInfo(array $data): array
  5431. {
  5432. $result = Book::where("id", $data["id"])->first();
  5433. if (empty($result)) {
  5434. return Result::error("获取失败", 0);
  5435. }
  5436. return Result::success($result);
  5437. }
  5438. public function updateBookStatus(array $data): array
  5439. {
  5440. //审核
  5441. unset($data['user_id']);
  5442. $bookInfo = Book::where("id", $data["id"])->first();
  5443. if($bookInfo['status']==2){
  5444. $this->sendMessage([
  5445. 'talk_type'=>400,
  5446. 'title'=>$bookInfo['title'],
  5447. 'content'=>'审核通过',
  5448. 'messageType'=>7,
  5449. 'user_id'=>$bookInfo['user_id'],
  5450. ]);
  5451. }
  5452. if($bookInfo['status']==3){
  5453. $this->sendMessage([
  5454. 'talk_type'=>400,
  5455. 'title'=>$bookInfo['title'],
  5456. 'content'=>'审核拒绝',
  5457. 'messageType'=>7,
  5458. 'user_id'=>$bookInfo['user_id'],
  5459. ]);
  5460. }
  5461. $result = Book::where("id", $data["id"])->update($data);
  5462. if (empty($result)) {
  5463. return Result::error("更新失败", 0);
  5464. }
  5465. return Result::success($result);
  5466. }
  5467. //20250422 书刊音像
  5468. /**
  5469. * 贴身宝贝
  5470. * @param array $data
  5471. * @return array
  5472. */
  5473. public function getWebsiteTsbb(array $data): array
  5474. {
  5475. $month = $data['month'] ?? date('m');
  5476. $day = $data['day'] ?? date('d');
  5477. // 使用缓存键
  5478. $cacheKey = "tsbb_data_{$month}_{$day}";
  5479. // 尝试从缓存获取数据
  5480. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5481. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5482. if ($cachedData = $cache->get($cacheKey)) {
  5483. return Result::success(unserialize($cachedData));
  5484. }
  5485. //查询老黄历
  5486. try {
  5487. $date = date('Y-m-d');
  5488. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5489. // 使用 curl 替代 file_get_contents
  5490. $ch = curl_init();
  5491. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5492. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5493. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5494. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5495. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5496. 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');
  5497. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5498. 'Accept: application/json',
  5499. 'Content-Type: application/json',
  5500. 'Referer: https://www.36jxs.com/'
  5501. ]);
  5502. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5503. curl_setopt($ch, CURLOPT_ENCODING, '');
  5504. $almanacResponse = curl_exec($ch);
  5505. var_dump("====:", $almanacResponse);
  5506. if (curl_errno($ch)) {
  5507. var_dump('Curl error:', curl_error($ch));
  5508. throw new \Exception('Curl error: ' . curl_error($ch));
  5509. }
  5510. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5511. curl_close($ch);
  5512. if ($almanacResponse === false) {
  5513. throw new \Exception('Failed to fetch almanac data');
  5514. }
  5515. $almanacData = json_decode($almanacResponse, true);
  5516. if (json_last_error() !== JSON_ERROR_NONE) {
  5517. throw new \Exception('Failed to parse almanac data');
  5518. }
  5519. $almanacInfo = $almanacData['data'] ?? [];
  5520. } catch (\Exception $e) {
  5521. var_dump('Exception:', $e->getMessage());
  5522. $almanacInfo = [];
  5523. }
  5524. // 获取历史上的今天数据
  5525. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5526. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5527. ->orderBy('year', 'asc')
  5528. ->select("title", "id", "year", DB::raw('1 as type'))
  5529. ->limit(16)
  5530. ->get();
  5531. // 获取节日数据 - 从今天开始获取未来4条
  5532. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5533. ->orderBy('showtime', 'asc')
  5534. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5535. ->limit(16)
  5536. ->get();
  5537. //说文解字
  5538. $chartacterList = Character::orderBy('updated_at', 'desc')
  5539. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5540. ->limit(6)
  5541. ->get();
  5542. //谜语沙龙
  5543. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5544. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5545. ->limit(4)
  5546. ->get();
  5547. //成语欣赏
  5548. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5549. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5550. ->limit(32)
  5551. ->get();
  5552. //名联赏析
  5553. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5554. ->select("id", "first", "second", DB::raw('6 as type'))
  5555. ->limit(6)
  5556. ->get();
  5557. // 获取分类文章数据
  5558. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5559. ->pluck('category_id')
  5560. ->toArray();
  5561. $articlesList = [];
  5562. foreach ($categoryIds as $catid) {
  5563. // 先查有图片的
  5564. $withImg = DB::table('article')
  5565. ->where('status', 1)
  5566. ->where('catid', $catid)
  5567. ->whereNotNull('imgurl')
  5568. ->where('imgurl', '!=', '')
  5569. ->orderBy('updated_at', 'desc')
  5570. ->limit(6)
  5571. ->get();
  5572. $count = $withImg->count();
  5573. if ($count < 6) {
  5574. // 不足6条再查无图片的补足
  5575. $withoutImg = DB::table('article')
  5576. ->where('status', 1)
  5577. ->where('catid', $catid)
  5578. ->where(function ($q) {
  5579. $q->whereNull('imgurl')->orWhere('imgurl', '');
  5580. })
  5581. ->orderBy('updated_at', 'desc')
  5582. ->limit(6 - $count)
  5583. ->get();
  5584. $articles = $withImg->concat($withoutImg);
  5585. } else {
  5586. $articles = $withImg;
  5587. }
  5588. // 组装
  5589. $category = \App\Model\Category::find($catid);
  5590. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  5591. $articlesList[] = [
  5592. 'category_name' => $category ? $category->name : '',
  5593. 'catid' => $catid,
  5594. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  5595. 'type' => 100,
  5596. 'list' => $articles->map(function ($item) {
  5597. return [
  5598. 'id' => $item->id,
  5599. 'title' => $item->title,
  5600. 'imgurl' => $item->imgurl,
  5601. 'created_at' => $item->created_at
  5602. ];
  5603. })->values()
  5604. ];
  5605. }
  5606. $result = [
  5607. 'almanac' => $almanacInfo,
  5608. 'historyTodayList' => [
  5609. 'category_name' => '历史上的今天',
  5610. 'list' => $historyTodayList,
  5611. 'type' => 1
  5612. ],
  5613. 'festivalList' => [
  5614. 'category_name' => '节日预告',
  5615. 'list' => $festivalList,
  5616. 'type' => 2
  5617. ],
  5618. 'chartacterList' => [
  5619. 'category_name' => '说文解字',
  5620. 'list' => $chartacterList,
  5621. 'type' => 3
  5622. ],
  5623. 'coupletList' => [
  5624. 'category_name' => '名联赏析',
  5625. 'list' => $coupletList,
  5626. 'type' => 6
  5627. ],
  5628. 'riddletList' => [
  5629. 'category_name' => '谜语沙龙',
  5630. 'list' => $riddletList,
  5631. 'type' => 4
  5632. ],
  5633. 'idiomList' => [
  5634. 'category_name' => '成语欣赏',
  5635. 'list' => $idiomList,
  5636. 'type' => 5
  5637. ],
  5638. 'articlesList' => $articlesList
  5639. ];
  5640. // 缓存结果,设置1小时过期
  5641. $cache->set($cacheKey, serialize($result), 3600);
  5642. return Result::success($result);
  5643. }
  5644. /**
  5645. * 获取资讯列表
  5646. */
  5647. public function getWebsiteTsbbList(array $data): array
  5648. {
  5649. $page = $data['page'] ?? 1;
  5650. $pageSize = $data['pageSize'] ?? 10;
  5651. // 如果没有传入月份和日期,则使用今天的日期
  5652. $month = $data['month'] ?? date('m');
  5653. $day = $data['day'] ?? date('d');
  5654. $total = 0;
  5655. $result = [];
  5656. $data['type'] = intval($data['type']);
  5657. var_dump("接收参数:", $data);
  5658. switch ($data['type']) {
  5659. case 1:
  5660. $query = HistoryToday::where(function ($q) use ($month, $day) {
  5661. // 当前月份之后的数据
  5662. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  5663. // 或者当前月份且日期大于等于当前日期的数据
  5664. ->orWhere(function ($q) use ($month, $day) {
  5665. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5666. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  5667. });
  5668. })
  5669. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  5670. $total = $query->count();
  5671. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  5672. ->offset(($page - 1) * $pageSize)
  5673. ->limit($pageSize)
  5674. ->get();
  5675. break;
  5676. case 2:
  5677. $query = Festival::where(function ($q) use ($month, $day) {
  5678. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  5679. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  5680. ->orWhere(function ($q) use ($month, $day) {
  5681. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  5682. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  5683. });
  5684. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  5685. $total = $query->count();
  5686. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  5687. ->offset(($page - 1) * $pageSize)
  5688. ->limit($pageSize)
  5689. ->get();
  5690. break;
  5691. case 3:
  5692. $query = Character::orderBy("updated_at", "desc");
  5693. $total = $query->count();
  5694. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  5695. ->offset(($page - 1) * $pageSize)
  5696. ->limit($pageSize)
  5697. ->get();
  5698. break;
  5699. case 4:
  5700. $query = Riddle::orderBy("updated_at", "desc");
  5701. $total = $query->count();
  5702. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  5703. ->offset(($page - 1) * $pageSize)
  5704. ->limit($pageSize)
  5705. ->get();
  5706. break;
  5707. case 5:
  5708. $query = Idiom::orderBy("updated_at", "desc");
  5709. $total = $query->count();
  5710. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  5711. ->offset(($page - 1) * $pageSize)
  5712. ->limit($pageSize)
  5713. ->get();
  5714. break;
  5715. case 6:
  5716. $query = Couplet::orderBy("updated_at", "desc");
  5717. $total = $query->count();
  5718. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  5719. ->offset(($page - 1) * $pageSize)
  5720. ->limit($pageSize)
  5721. ->get();
  5722. break;
  5723. default:
  5724. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  5725. $total = $query->count();
  5726. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  5727. ->offset(($page - 1) * $pageSize)
  5728. ->limit($pageSize)
  5729. ->get();
  5730. }
  5731. return Result::success([
  5732. 'list' => $result,
  5733. 'total' => $total,
  5734. 'page' => (int)$page,
  5735. 'pageSize' => (int)$pageSize,
  5736. 'month' => $month,
  5737. 'day' => $day
  5738. ]);
  5739. }
  5740. /**
  5741. * 1:历史上的今天
  5742. * 2:节日
  5743. * 3:文章
  5744. *
  5745. * 资讯详情信息
  5746. */
  5747. public function getWebsiteTsbbDetail(array $data): array
  5748. {
  5749. $data['type'] = intval($data['type']);
  5750. switch ($data['type']) {
  5751. case 1:
  5752. $result = HistoryToday::where("id", $data['id'])->first();
  5753. break;
  5754. case 2:
  5755. $result = Festival::where("id", $data['id'])->first();
  5756. break;
  5757. case 3:
  5758. $result = Character::where("id", $data['id'])->first();
  5759. break;
  5760. case 4:
  5761. $result = Riddle::where("id", $data['id'])->first();
  5762. break;
  5763. case 5:
  5764. $result = Idiom::where("id", $data['id'])->first();
  5765. break;
  5766. case 6:
  5767. $result = Couplet::where("id", $data['id'])->first();
  5768. break;
  5769. default:
  5770. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  5771. break;
  5772. }
  5773. return Result::success($result);
  5774. }
  5775. /**
  5776. * 农网导航首页数据
  5777. */
  5778. public function getWebsiteNwHomeList(array $data): array
  5779. {
  5780. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  5781. ->pluck('category_id')
  5782. ->toArray();
  5783. // 使用子查询优化
  5784. $articlesList = DB::table('article')
  5785. ->select([
  5786. 'article.id',
  5787. 'article.title',
  5788. 'article.imgurl',
  5789. 'article.created_at',
  5790. 'category.name as category_name',
  5791. 'category.id as category_id',
  5792. 'website_category.aLIas_pinyin as pinyin',
  5793. 'parent_wc.aLIas_pinyin as parent_pinyin',
  5794. DB::raw('100 as type')
  5795. ])
  5796. ->join('category', 'article.catid', '=', 'category.id')
  5797. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5798. ->leftJoin('website_category as parent_wc', function ($join) {
  5799. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  5800. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  5801. })
  5802. ->where('website_category.website_id', $data['website_id'])
  5803. ->where('article.status', 1)
  5804. ->whereIn('category.id', $categoryIds)
  5805. ->orderBy('article.created_at', 'desc')
  5806. ->get()
  5807. ->groupBy('category_id')
  5808. ->map(function ($group) {
  5809. // 确保第一条数据有图片
  5810. $firstWithImage = $group->first(function ($item) {
  5811. return !empty($item->imgurl);
  5812. });
  5813. if ($firstWithImage) {
  5814. // 如果有带图片的文章,将其放在第一位
  5815. $group = $group->filter(function ($item) use ($firstWithImage) {
  5816. return $item->id !== $firstWithImage->id;
  5817. })->prepend($firstWithImage);
  5818. }
  5819. return [
  5820. 'category_name' => $group->first()->category_name,
  5821. 'catid' => $group->first()->category_id,
  5822. 'pinyin' => $group->first()->pinyin,
  5823. 'parent_pinyin' => $group->first()->parent_pinyin,
  5824. 'list' => $group->take(4)->map(function ($item) {
  5825. return [
  5826. 'id' => $item->id,
  5827. 'title' => $item->title,
  5828. ];
  5829. })->values()
  5830. ];
  5831. })
  5832. ->values()
  5833. ->toArray();
  5834. return Result::success($articlesList);
  5835. }
  5836. /**
  5837. * 企业管理
  5838. * @param array $data
  5839. * @return array
  5840. */
  5841. public function getCompanyList(array $data): array
  5842. {
  5843. // return Result::success($data);
  5844. $where = [];
  5845. $user = User::where('id', $data['user_id'])->first();
  5846. if (empty($user)) {
  5847. return Result::error('用户不存在!');
  5848. }
  5849. if ($user['type_id'] != 10000) {
  5850. $where['user_id'] = $data['user_id'];
  5851. }
  5852. if (isset($data['title']) && !empty($data['title'])) {
  5853. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  5854. }
  5855. if (isset($data['website_id']) && !empty($data['website_id'])) {
  5856. array_push($where, ['website.id', $data['website_id']]);
  5857. }
  5858. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  5859. if ($data['ischeck'] == 1) {
  5860. if (isset($data['status']) && $data['status'] != '') {
  5861. array_push($where, ['company.status', $data['status']]);
  5862. $query = Company::where($where);
  5863. } else {
  5864. $query = Company::whereIn('company.status', [0, 2]);
  5865. }
  5866. } else {
  5867. $query = Company::where('company.status', 1);
  5868. }
  5869. }
  5870. $result = $query->where($where)
  5871. ->leftJoin('website_category', function ($query) {
  5872. $query->on('website_category.category_id', '=', 'company.category_id')
  5873. ->on('website_category.website_id', '=', 'company.website_id');
  5874. })
  5875. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  5876. ->select(
  5877. 'company.id',
  5878. 'company.title',
  5879. 'company.website_id',
  5880. 'company.category_id',
  5881. 'website.website_name',
  5882. 'website_category.alias as category_name',
  5883. 'company.status',
  5884. 'company.updated_at',
  5885. )
  5886. ->orderBy('company.updated_at', 'desc')
  5887. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  5888. if ($result->isEmpty()) {
  5889. return Result::error("暂无企业", 0);
  5890. }
  5891. return Result::success($result);
  5892. }
  5893. /**
  5894. * 添加企业
  5895. * @param array $data
  5896. * @return array
  5897. */
  5898. public function addCompany(array $data): array
  5899. {
  5900. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  5901. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5902. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  5903. $data['cat_arr_id'] = json_encode($car_arr_id);
  5904. } else {
  5905. $data['cat_arr_id'] = '';
  5906. }
  5907. if ($data['imgurl'] == '') {
  5908. //content中提取图片第一个图,正则提取
  5909. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5910. preg_match_all($reg, $data['content'], $matches);
  5911. if (isset($matches[1][0])) {
  5912. //截取varchar240
  5913. $data['imgurl'] = substr($matches[1][0], 0, 240);
  5914. }
  5915. }
  5916. if ($data['keyword'] == '') {
  5917. //提取标题+内容中的关键词
  5918. $data['keyword'] = $data['title'];
  5919. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5920. Jieba::init(); // 初始化 jieba-php
  5921. Finalseg::init();
  5922. $segList = Jieba::cut($data['keyword']);
  5923. $segList1 = array_slice($segList, 0, 8);
  5924. $data['keyword'] = implode(',', $segList1);
  5925. }
  5926. if ($data['introduce'] == '' || empty($data['introduce'])) {
  5927. //提取内容中的描述
  5928. $content = $data['content'];
  5929. // 去除 <style> 和 <script> 标签及其内容
  5930. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5931. // 去除所有 HTML 标签
  5932. $content = strip_tags($content);
  5933. // 去除 HTML 实体
  5934. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5935. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5936. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5937. // 去除多余空白
  5938. $content = preg_replace('/\s+/u', '', $content);
  5939. // 截取 100 个字符
  5940. $data['introduce'] = mb_substr($content, 0, 100);
  5941. }
  5942. $user = User::where('id', $data['user_id'])->first();
  5943. if (empty($user)) {
  5944. return Result::error('用户不存在!');
  5945. }
  5946. if ($user['type_id'] == 10000) {
  5947. $data['status'] = 1;
  5948. }
  5949. if (isset($data['level']) && $data['level'] != null) {
  5950. $data['level'] = intval($data['level']);
  5951. } else {
  5952. $data['level'] = null;
  5953. }
  5954. if((isset($data['status']) && $data['status']==0) || !isset($data['status'])){
  5955. $this->sendMessage([
  5956. 'talk_type'=>900,
  5957. 'title'=>$data['title'],
  5958. 'content'=>'提交了审核',
  5959. 'messageType'=>8,
  5960. ]);
  5961. }
  5962. $result = Company::insertGetId($data);
  5963. if ($result) {
  5964. return Result::success($result);
  5965. } else {
  5966. return Result::error('添加失败');
  5967. }
  5968. }
  5969. /**
  5970. * 更新企业
  5971. * @param array $data
  5972. * @return array
  5973. */
  5974. public function upCompany(array $data): array
  5975. {
  5976. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5977. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  5978. $data['cat_arr_id'] = json_encode($car_arr_id);
  5979. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  5980. } else {
  5981. $data['cat_arr_id'] = '';
  5982. }
  5983. if ($data['imgurl'] == '') {
  5984. //content中提取图片第一个图,正则提取
  5985. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5986. preg_match_all($reg, $data['content'], $matches);
  5987. if (isset($matches[1][0])) {
  5988. //截取varchar
  5989. $data['imgurl'] = substr($matches[1][0], 0, 240);
  5990. }
  5991. }
  5992. if ($data['keyword'] == '') {
  5993. //提取标题+内容中的关键词
  5994. $data['keyword'] = $data['title'];
  5995. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5996. Jieba::init(); // 初始化 jieba-php
  5997. Finalseg::init();
  5998. $segList = Jieba::cut($data['keyword']);
  5999. $segList1 = array_slice($segList, 0, 8);
  6000. $data['keyword'] = implode(',', $segList1);
  6001. }
  6002. if ($data['introduce'] == '') {
  6003. //提取内容中的描述
  6004. $content = $data['content'];
  6005. // 去除 <style> 和 <script> 标签及其内容
  6006. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6007. // 去除所有 HTML 标签
  6008. $content = strip_tags($content);
  6009. // 去除 HTML 实体
  6010. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6011. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6012. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6013. // 去除多余空白
  6014. $content = preg_replace('/\s+/u', '', $content);
  6015. // 截取 100 个字符
  6016. $data['introduce'] = mb_substr($content, 0, 100);
  6017. }
  6018. if (isset($data['level']) && $data['level'] != null) {
  6019. $data['level'] = intval($data['level']);
  6020. } else {
  6021. $data['level'] = null;
  6022. }
  6023. $user = User::where('id', $data['user_id'])->first();
  6024. if (empty($user)) {
  6025. return Result::error('用户不存在!');
  6026. }
  6027. if ($user['type_id'] == 10000) {
  6028. $data['status'] = 1;
  6029. } else {
  6030. $data['status'] = 0;
  6031. }
  6032. if((isset($data['status']) && $data['status']==0) || !isset($data['status'])){
  6033. $this->sendMessage([
  6034. 'talk_type'=>900,
  6035. 'title'=>$data['title'],
  6036. 'content'=>'提交了审核',
  6037. 'messageType'=>8,
  6038. ]);
  6039. }
  6040. $result = Company::where('id', $data['id'])->update($data);
  6041. if ($result) {
  6042. return Result::success($result);
  6043. } else {
  6044. return Result::error('修改失败');
  6045. }
  6046. }
  6047. /**
  6048. * 删除企业
  6049. * @param array $data
  6050. * @return array
  6051. */
  6052. public function delCompany(array $data): array
  6053. {
  6054. $result = Company::where('id', $data['id'])->delete();
  6055. if ($result) {
  6056. return Result::success($result);
  6057. } else {
  6058. return Result::error('删除失败');
  6059. }
  6060. }
  6061. /**
  6062. * 审核企业
  6063. * @param array $data
  6064. * @return array
  6065. */
  6066. public function checkCompany(array $data): array
  6067. {
  6068. $user = User::where('id', $data['user_id'])->first();
  6069. if (empty($user)) {
  6070. return Result::error('用户不存在!');
  6071. }
  6072. $company = Company::where('id', $data['id'])->first();
  6073. if (empty($company)) {
  6074. return Result::error('企业不存在!');
  6075. }
  6076. // 状态:0:未审核 1:已审核 2:已拒绝
  6077. if ($data['status'] == 2 || $data['status'] == '2') {
  6078. $this->sendMessage([
  6079. 'talk_type'=>901,
  6080. 'title'=>$company['title'],
  6081. 'content'=>'审核拒绝',
  6082. 'messageType'=>8,
  6083. 'user_id'=>$company['user_id'],
  6084. ]);
  6085. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6086. } else {
  6087. $this->sendMessage([
  6088. 'talk_type'=>901,
  6089. 'title'=>$company['title'],
  6090. 'content'=>'审核通过',
  6091. 'messageType'=>8,
  6092. 'user_id'=>$company['user_id'],
  6093. ]);
  6094. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6095. }
  6096. if (empty($result)) {
  6097. return Result::error('审核失败!');
  6098. } else {
  6099. return Result::success($result);
  6100. }
  6101. }
  6102. /**
  6103. * 获取企业信息
  6104. * @param array $data
  6105. * @return array
  6106. */
  6107. public function getCompanyInfo(array $data): array
  6108. {
  6109. $result = Company::where('id', $data['id'])->first();
  6110. if (empty($result)) {
  6111. return Result::error('企业不存在!');
  6112. } else {
  6113. return Result::success($result);
  6114. }
  6115. }
  6116. /**
  6117. * @param array $data
  6118. * @return array
  6119. */
  6120. public function getWebsiteCompany(array $data): array
  6121. {
  6122. $categorys = json_decode($data['id'], true);
  6123. $category_arr = $this->processArticlePro($data['website_id']);
  6124. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6125. $catiall = $category_arr['catiall'];
  6126. foreach ($categorys as $key => $value) {
  6127. if (array_key_exists('level', $value)) {
  6128. $parts = explode(',', $value['level']);
  6129. $level = $parts[0] ?? null;
  6130. $imgnum = $parts[1] ?? null;
  6131. $textnum = $parts[2] ?? null;
  6132. if (!empty($textnum) && $textnum > 0) {
  6133. $text_num = Company::where('level', $level)
  6134. ->where('website_id', $data['website_id'])
  6135. ->where('status', 1)
  6136. ->select(
  6137. 'company.id',
  6138. 'company.title',
  6139. 'company.description',
  6140. 'company.updated_at',
  6141. 'company.category_id',
  6142. 'company.cat_arr_id'
  6143. )
  6144. ->orderBy('updated_at', 'desc')
  6145. ->limit($textnum)
  6146. ->get()->all();
  6147. }
  6148. if (!empty($imgnum) && $imgnum > 0) {
  6149. $img_num = Company::where('level', $level)
  6150. ->where('website_id', $data['website_id'])
  6151. ->where('status', 1)
  6152. ->where('imgurl', '!=', '')
  6153. ->whereNotNull('imgurl')
  6154. ->select(
  6155. 'company.id',
  6156. 'company.title',
  6157. 'company.description',
  6158. 'company.updated_at',
  6159. 'company.imgurl as imgs',
  6160. 'company.category_id',
  6161. 'company.cat_arr_id'
  6162. )
  6163. ->orderBy('updated_at', 'desc')
  6164. ->limit($imgnum)
  6165. ->get()->all();
  6166. }
  6167. }
  6168. if (array_key_exists('id', $value)) {
  6169. $parts = explode(',', $value['id']);
  6170. $category_id = $parts[0] ?? null;
  6171. $imgnum = $parts[1] ?? null;
  6172. $textnum = $parts[2] ?? null;
  6173. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6174. if (!empty($textnum) && $textnum > 0) {
  6175. $text_num = Company::whereIn('category_id', $category_arr)
  6176. ->where('website_id', $data['website_id'])
  6177. ->where('status', 1)
  6178. ->select(
  6179. 'company.id',
  6180. 'company.title',
  6181. 'company.description',
  6182. 'company.updated_at',
  6183. 'company.category_id',
  6184. 'company.cat_arr_id'
  6185. )
  6186. ->orderBy('updated_at', 'desc')
  6187. ->limit($textnum)
  6188. ->get()->all();
  6189. }
  6190. if (!empty($imgnum) && $imgnum > 0) {
  6191. $img_num = Company::whereIn('category_id', $category_arr)
  6192. ->where('website_id', $data['website_id'])
  6193. ->where('status', 1)
  6194. ->where('imgurl', '!=', '')
  6195. ->whereNotNull('imgurl')
  6196. ->select(
  6197. 'company.id',
  6198. 'company.title',
  6199. 'company.description',
  6200. 'company.updated_at',
  6201. 'company.imgurl as imgs',
  6202. 'company.category_id',
  6203. 'company.cat_arr_id'
  6204. )
  6205. ->orderBy('updated_at', 'desc')
  6206. ->limit($imgnum)
  6207. ->get()->all();
  6208. }
  6209. }
  6210. if (!empty($text_num)) {
  6211. foreach ($text_num as $k => $v) {
  6212. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6213. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6214. }
  6215. }
  6216. if (!empty($img_num)) {
  6217. foreach ($img_num as $k => $v) {
  6218. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6219. $imgurl = json_decode($v['imgs'], true);
  6220. if (!empty($imgurl)) {
  6221. $img_num[$k]->imgurl = $imgurl[0];
  6222. }
  6223. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6224. }
  6225. }
  6226. $company[$key]['img_num'] = $img_num ?? [];
  6227. $company[$key]['text_num'] = $text_num ?? [];
  6228. }
  6229. if (empty($company)) {
  6230. return Result::error("暂无相关企业信息", 0);
  6231. }
  6232. return Result::success($company);
  6233. }
  6234. /**
  6235. * @param array $data
  6236. * @return array
  6237. */
  6238. public function getWebsiteCompanyList(array $data): array
  6239. {
  6240. $where['website_id'] = $data['website_id'];
  6241. $where['status'] = 1;
  6242. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6243. $where['category_id'] = $data['category_id'];
  6244. }
  6245. if (isset($data['keyword']) && !empty($data['keyword'])) {
  6246. array_push($where, ['title', 'like', '%' . $data['keyword'] . '%']);
  6247. }
  6248. $query = Company::where($where);
  6249. $company = $this->processArticle(
  6250. $query->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6251. ->orderBy('updated_at', 'desc')
  6252. ->offset(($data['page'] - 1) * $data['pageSize'])
  6253. ->limit($data['pageSize'])
  6254. ->get(),
  6255. $data
  6256. );
  6257. if (empty($company)) {
  6258. return Result::error("暂无相关公司信息", 0);
  6259. }
  6260. $result = [
  6261. 'count' => $query->clone()->count(),
  6262. 'data' => $company,
  6263. ];
  6264. return Result::success($result);
  6265. }
  6266. /**
  6267. * 获取项目列表
  6268. * @param array $data
  6269. * @return array
  6270. */
  6271. public function getProjectList(array $data): array
  6272. {
  6273. $where = [];
  6274. $user = User::where('id', $data['user_id'])->first();
  6275. if (empty($user)) {
  6276. return Result::error('用户不存在!');
  6277. }
  6278. if ($user->type_id != 10000) {
  6279. array_push($where, ['project.user_id', $data['user_id']]);
  6280. }
  6281. $query = Project::query();
  6282. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6283. array_push($where, ['project.website_id', $data['website_id']]);
  6284. }
  6285. if (isset($data['title']) && !empty($data['title'])) {
  6286. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6287. }
  6288. if ($data['status'] != 3) {
  6289. array_push($where, ['project.status', $data['status']]);
  6290. }
  6291. $query = Project::where($where)
  6292. ->when($data['status'] == 3, function ($query) {
  6293. $query->whereIn('project.status', [0, 2]);
  6294. });
  6295. $count = $query->clone()
  6296. ->count();
  6297. $rows = $query->clone()
  6298. ->leftJoin('website', 'project.website_id', 'website.id')
  6299. ->leftJoin('website_category', function ($join) {
  6300. $join->on('project.website_id', '=', 'website_category.website_id')
  6301. ->on('project.category_id', '=', 'website_category.category_id');
  6302. })
  6303. ->select(
  6304. 'project.id',
  6305. 'project.title',
  6306. 'project.updated_at',
  6307. 'project.status',
  6308. 'website.website_name',
  6309. 'website_category.alias as category_name'
  6310. )
  6311. ->orderBy('project.updated_at', 'desc')
  6312. ->offset(($data['page'] - 1) * $data['pageSize'])
  6313. ->limit($data['pageSize'])
  6314. ->get();
  6315. if ($rows->isEmpty()) {
  6316. return Result::error("暂无相关项目信息", 0);
  6317. }
  6318. $result = [
  6319. 'count' => $count,
  6320. 'rows' => $rows,
  6321. ];
  6322. return Result::success($result);
  6323. }
  6324. /**
  6325. * 添加项目
  6326. * @param array $data
  6327. * @return array
  6328. */
  6329. public function addProject(array $data): array
  6330. {
  6331. $user = User::where('id', $data['user_id'])->first();
  6332. if (empty($user)) {
  6333. return Result::error("暂无相关用户信息", 0);
  6334. }
  6335. if ($user->type_id == 10000) {
  6336. $data['status'] = 1;
  6337. } else {
  6338. $data['status'] = 0;
  6339. }
  6340. if ($data['keyword'] == '') {
  6341. //提取标题+内容中的关键词
  6342. $data['keyword'] = $data['title'];
  6343. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6344. Jieba::init(); // 初始化 jieba-php
  6345. Finalseg::init();
  6346. $segList = Jieba::cut($data['keyword']);
  6347. $segList1 = array_slice($segList, 0, 8);
  6348. $data['keyword'] = implode(',', $segList1);
  6349. }
  6350. if ($data['description'] == '') {
  6351. //提取内容中的描述
  6352. // var_dump(11111);
  6353. //提取内容中的描述
  6354. $content = $data['introduce'];
  6355. // 去除 <style> 和 <script> 标签及其内容
  6356. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6357. // 去除所有 HTML 标签
  6358. $content = strip_tags($content);
  6359. // 去除 HTML 实体
  6360. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6361. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6362. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6363. // 去除多余空白
  6364. $content = preg_replace('/\s+/u', '', $content);
  6365. // 截取 100 个字符
  6366. $data['description'] = mb_substr($content, 0, 100);
  6367. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6368. }
  6369. if($data['status']==0){
  6370. $this->sendMessage([
  6371. 'talk_type'=>1000,
  6372. 'title'=>$data['title'],
  6373. 'content'=>'提交了审核',
  6374. 'messageType'=>9,
  6375. ]);
  6376. }
  6377. $project = Project::insertGetId($data);
  6378. if (empty($project)) {
  6379. return Result::error("暂无相关项目信息", 0);
  6380. }
  6381. return Result::success($project);
  6382. }
  6383. /**
  6384. * 更新项目
  6385. * @param array $data
  6386. * @return array
  6387. */
  6388. public function upProject(array $data): array
  6389. {
  6390. $project = Project::where('id', $data['id'])->first();
  6391. if (empty($project)) {
  6392. return Result::error("暂无相关项目信息", 0);
  6393. }
  6394. $id = $data['id'];
  6395. unset($data['id']);
  6396. $user = User::where('id', $data['user_id'])->first();
  6397. if (empty($user)) {
  6398. return Result::error("暂无相关用户信息", 0);
  6399. }
  6400. if ($user->type_id == 10000) {
  6401. $data['status'] = 1;
  6402. } else {
  6403. $data['status'] = 0;
  6404. }
  6405. unset($data['user_id']);
  6406. if ($data['keyword'] == '') {
  6407. //提取标题+内容中的关键词
  6408. $data['keyword'] = $data['title'];
  6409. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6410. Jieba::init(); // 初始化 jieba-php
  6411. Finalseg::init();
  6412. $segList = Jieba::cut($data['keyword']);
  6413. $segList1 = array_slice($segList, 0, 8);
  6414. $data['keyword'] = implode(',', $segList1);
  6415. }
  6416. if ($data['description'] == '') {
  6417. //提取内容中的描述
  6418. // var_dump(11111);
  6419. //提取内容中的描述
  6420. $content = $data['introduce'];
  6421. // 去除 <style> 和 <script> 标签及其内容
  6422. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6423. // 去除所有 HTML 标签
  6424. $content = strip_tags($content);
  6425. // 去除 HTML 实体
  6426. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6427. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6428. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6429. // 去除多余空白
  6430. $content = preg_replace('/\s+/u', '', $content);
  6431. // 截取 100 个字符
  6432. $data['description'] = mb_substr($content, 0, 100);
  6433. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6434. }
  6435. if($data['status']==0){
  6436. $this->sendMessage([
  6437. 'talk_type'=>1000,
  6438. 'title'=>$data['title'],
  6439. 'content'=>'提交了审核',
  6440. 'messageType'=>9,
  6441. ]);
  6442. }
  6443. $result = Project::where('id', $id)->update($data);
  6444. if (empty($result)) {
  6445. return Result::error("更新失败", 0);
  6446. }
  6447. return Result::success($result);
  6448. }
  6449. /**
  6450. * 删除项目
  6451. * @param array $data
  6452. * @return array
  6453. */
  6454. public function delProject(array $data): array
  6455. {
  6456. $user = User::where('id', $data['user_id'])->first();
  6457. if (empty($user)) {
  6458. return Result::error("暂无相关用户信息", 0);
  6459. }
  6460. $project = Project::where('id', $data['id'])->first();
  6461. if (empty($project)) {
  6462. return Result::error("暂无相关项目信息", 0);
  6463. }
  6464. $result = Project::where('id', $data['id'])->delete();
  6465. if (empty($result)) {
  6466. return Result::error("删除失败", 0);
  6467. }
  6468. return Result::success($result);
  6469. }
  6470. /**
  6471. * 审核项目
  6472. * @param array $data
  6473. * @return array
  6474. */
  6475. public function checkProject(array $data): array
  6476. {
  6477. $user = User::where('id', $data['user_id'])->first();
  6478. if (empty($user)) {
  6479. return Result::error("暂无相关用户信息", 0);
  6480. }
  6481. // 0:未审核; 1:已审核; 2:已拒绝;
  6482. if ($user->type_id != 10000) {
  6483. if ($data['status'] == 1 || $data['status'] == 2) {
  6484. return Result::error("此用户权限不足", 0);
  6485. }
  6486. }
  6487. $project = Project::where('id', $data['id'])->first();
  6488. if (empty($project)) {
  6489. return Result::error("暂无相关项目信息", 0);
  6490. }
  6491. if ($data['status'] == 2) {
  6492. $this->sendMessage([
  6493. 'talk_type'=>1001,
  6494. 'title'=>$project['title'],
  6495. 'content'=>'审核拒绝',
  6496. 'messageType'=>9,
  6497. 'user_id'=>$project['user_id'],
  6498. ]);
  6499. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  6500. } else {
  6501. $this->sendMessage([
  6502. 'talk_type'=>1001,
  6503. 'title'=>$project['title'],
  6504. 'content'=>'审核通过',
  6505. 'messageType'=>9,
  6506. 'user_id'=>$project['user_id'],
  6507. ]);
  6508. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  6509. }
  6510. if (empty($result)) {
  6511. return Result::error("审核失败", 0);
  6512. }
  6513. return Result::success($result);
  6514. }
  6515. /**
  6516. * 获取项目详情
  6517. * @param array $data
  6518. * @return array
  6519. */
  6520. public function getProjectInfo(array $data): array
  6521. {
  6522. $project = Project::where('id', $data['id'])->first();
  6523. if (empty($project)) {
  6524. return Result::error("暂无相关项目信息", 0);
  6525. }
  6526. return Result::success($project);
  6527. }
  6528. public function getWebsiteCompanyInfo(array $data): array
  6529. {
  6530. $company = Company::where('id', $data['id'])
  6531. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  6532. ->where('status', 1)
  6533. ->where('website_id', $data['website_id'])
  6534. ->select('company.*', 'job_industry.hyname as hy_name')
  6535. ->first();
  6536. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  6537. switch ($company->jobnature_id) {
  6538. case null:
  6539. $company->jobnature_name = '';
  6540. break;
  6541. case 0:
  6542. $company->jobnature_name = '市场监督';
  6543. break;
  6544. case 1:
  6545. $company->jobnature_name = '信访纪检';
  6546. break;
  6547. case 2:
  6548. $company->jobnature_name = '公检法司';
  6549. break;
  6550. case 3:
  6551. $company->jobnature_name = '高关注机构';
  6552. break;
  6553. default:
  6554. $company->jobnature_name = '';
  6555. break;
  6556. }
  6557. $city_arr = $company->city_arr_id;
  6558. if (!empty($city_arr)) {
  6559. $city_arr = json_decode($city_arr, true);
  6560. $cityNames = District::whereIn('id', $city_arr)
  6561. ->pluck('name')
  6562. ->implode('-');
  6563. $company->city_name = $cityNames;
  6564. } else {
  6565. $company->city_name = '';
  6566. }
  6567. if (empty($company)) {
  6568. return Result::error("暂无相关公司信息", 0);
  6569. }
  6570. return Result::success($company);
  6571. }
  6572. public function getMSG(array $data): array
  6573. {
  6574. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  6575. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  6576. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  6577. $result = [];
  6578. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  6579. //最近的5篇已审的文章
  6580. $apply_articale = Article::where('status', 1)
  6581. ->where('admin_user_id', $user_id)
  6582. ->orderBy('updated_at', 'desc')
  6583. // ->limit(5)
  6584. ->get();
  6585. //获取5条用户的已审核商品
  6586. $good = Good::where('status', 2)
  6587. ->where('user_id', $user_id)
  6588. ->orderBy('updated_at', 'desc')
  6589. // ->limit(5)
  6590. ->get();
  6591. //获取5条用户待审核的公告
  6592. $notice = Notice::where('status', 2)
  6593. ->where('user_id', $user_id)
  6594. ->orderBy('updated_at', 'desc')
  6595. ->limit(5)->get();
  6596. //获取5条用户的待审核投诉
  6597. $complaint = Complaint::where('status', 2)
  6598. ->where('user_id', $user_id)
  6599. ->orderBy('updated_at', 'desc')
  6600. // ->limit(5)
  6601. ->get();
  6602. //获取5条用户的book
  6603. $book = Book::where('status', 2)
  6604. ->where('user_id', $user_id)
  6605. ->orderBy('updated_at', 'desc')
  6606. // ->limit(5)
  6607. ->get();
  6608. //获取5条用户的求职
  6609. //获取5条用户的求职 1
  6610. $job_hunting = JobHunting::where('job_hunting.status', 1)
  6611. ->where('job_hunting.user_id', $user_id)
  6612. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  6613. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  6614. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6615. ->orderBy('updated_at', 'desc')
  6616. // ->limit(5)
  6617. ->get();
  6618. //获取5条用户的求职 2
  6619. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  6620. ->where('job_recruiting.user_id', $user_id)
  6621. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  6622. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  6623. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6624. ->orderBy('updated_at', 'desc')
  6625. // ->limit(5)
  6626. ->get();
  6627. //人才库 1
  6628. $job_apply = JobApply::where('job_apply.status', 1)
  6629. ->where('job_apply.receiver_id', $user_id)
  6630. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  6631. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  6632. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  6633. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  6634. ->select('job_recruiting', 'job_recruiting.', '', '')
  6635. ->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')
  6636. ->orderBy('updated_at', 'desc')
  6637. // ->limit(5)
  6638. ->get();
  6639. // 职场机会 2
  6640. $job_resume = JobResume::where('job_resume.status', 1)
  6641. ->where('job_resume.receiver_id', $user_id)
  6642. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  6643. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  6644. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  6645. ->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')
  6646. ->orderBy('updated_at', 'desc')
  6647. // ->limit(5)
  6648. ->get();
  6649. //获取5条用户待处理的投诉
  6650. $complaint_deal = Complaint::where('status', 2)
  6651. ->where('deal', 1)
  6652. ->whereJsonContains('re_user_ids', $user_id)
  6653. ->orderBy('updated_at', 'desc')
  6654. // ->limit(5)
  6655. ->get();
  6656. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  6657. $complany = Company::where('status', 1)
  6658. ->where('user_id', $user_id)
  6659. ->orderBy('updated_at', 'desc')
  6660. // ->limit(5)
  6661. ->get();
  6662. //获取5条单聊未读聊天消息
  6663. // $chat = ChatRecords::where('is_read', 0)
  6664. // ->where('user_id', $user_id)
  6665. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  6666. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  6667. // ->where('action', 'recieved')
  6668. // ->where('talk_type', 1)
  6669. // ->orderBy('created_at', 'desc')
  6670. // // ->limit(5)
  6671. // ->get();
  6672. //获取5条未读群聊信息
  6673. // $chat_group = ChatRecords::where('is_read', 0)
  6674. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  6675. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  6676. // ->where('user_id', $user_id)
  6677. // ->where('talk_type', 2)
  6678. // ->orderBy('created_at', 'desc')
  6679. // // ->limit(5)
  6680. // ->get();
  6681. //获取5条用户的待审核项目
  6682. $project = Project::where('status', 1)
  6683. ->where('user_id', $user_id)
  6684. ->orderBy('updated_at', 'desc')
  6685. // ->limit(5)
  6686. ->get();
  6687. // count($chat) + count($chat_group) +
  6688. $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)
  6689. + count($complany)
  6690. + count($project)
  6691. // + count($chat) + count($chat_group)
  6692. ;
  6693. $result = [
  6694. 'apply_articale' => $apply_articale,
  6695. // 'chat' => $chat,
  6696. // 'chat_group' => $chat_group,
  6697. 'good' => $good,
  6698. 'notice' => $notice,
  6699. 'complaint' => $complaint,
  6700. 'book' => $book,
  6701. 'job_hunting' => $job_hunting,
  6702. 'job_recruiting' => $job_recruiting,
  6703. 'job_apply' => $job_apply,
  6704. 'job_resume' => $job_resume,
  6705. 'complaint_deal' => $complaint_deal,
  6706. 'complany' => $complany,
  6707. 'project' => $project,
  6708. 'count' => $count,
  6709. ];
  6710. } elseif ($type_id == 12) {
  6711. //最近的5篇已审的文章
  6712. $apply_articale = Article::where('status', 1)
  6713. ->where('admin_user_id', $user_id)
  6714. ->limit(5)->get();
  6715. //获取5条单聊未读聊天消息
  6716. $chat = ChatRecords::where('is_read', 0)
  6717. ->where('user_id', $user_id)
  6718. ->where('talk_type', 1)
  6719. ->orderBy('created_at', 'desc')
  6720. ->limit(5)->get();
  6721. //获取5条未读群聊信息
  6722. $chat_group = ChatRecords::where('is_read', 0)
  6723. ->where('user_id', $user_id)
  6724. ->where('talk_type', 2)
  6725. ->orderBy('created_at', 'desc')
  6726. ->limit(5)->get();
  6727. //获取5条用户的已审核商品
  6728. $good = Good::where('status', 2)
  6729. ->where('user_id', $user_id)
  6730. ->orderBy('updated_at', 'desc')
  6731. ->limit(5)->get();
  6732. //获取5条用户的book
  6733. $book = Book::where('status', 2)
  6734. ->where('user_id', $user_id)
  6735. ->orderBy('updated_at', 'desc')
  6736. ->limit(5)->get();
  6737. //获取5条用户的求职
  6738. //获取5条用户的求职 1
  6739. //count($chat) + count($chat_group)
  6740. $count = count($apply_articale) + count($good);
  6741. $result = [
  6742. 'apply_articale' => $apply_articale,
  6743. 'chat' => $chat,
  6744. 'chat_group' => $chat_group,
  6745. 'good' => $good,
  6746. 'book' => $book,
  6747. 'count' => $count,
  6748. ];
  6749. } elseif ($type_id == 13) {
  6750. //最近的5篇已审的文章
  6751. $apply_articale = Article::where('status', 1)
  6752. ->where('admin_user_id', $user_id)
  6753. ->limit(5)->get();
  6754. //获取5条单聊未读聊天消息
  6755. $chat = ChatRecords::where('is_read', 0)
  6756. ->where('user_id', $user_id)
  6757. ->where('talk_type', 1)
  6758. ->orderBy('created_at', 'desc')
  6759. ->limit(5)->get();
  6760. //获取5条未读群聊信息
  6761. $chat_group = ChatRecords::where('is_read', 0)
  6762. ->where('user_id', $user_id)
  6763. ->where('talk_type', 2)
  6764. ->orderBy('created_at', 'desc')
  6765. ->limit(5)->get();
  6766. //获取5条用户的已审核商品
  6767. $good = Good::where('status', 2)
  6768. ->where('user_id', $user_id)
  6769. ->orderBy('updated_at', 'desc')
  6770. ->limit(5)->get();
  6771. //count($chat) + count($chat_group) +
  6772. $count = count($apply_articale) + count($good);
  6773. $result = [
  6774. 'apply_articale' => $apply_articale,
  6775. 'chat' => $chat,
  6776. 'chat_group' => $chat_group,
  6777. 'good' => $good,
  6778. 'count' => $count,
  6779. ];
  6780. } elseif ($type_id == 14) {
  6781. //最近的5篇已审的文章
  6782. $apply_articale = Article::where('status', 1)
  6783. ->where('admin_user_id', $user_id)
  6784. // ->limit(5)
  6785. ->get();
  6786. //获取5条用户的已审核商品
  6787. $good = Good::where('status', 2)
  6788. ->where('user_id', $user_id)
  6789. ->orderBy('updated_at', 'desc')
  6790. // ->limit(5)
  6791. ->get();
  6792. $count = count($apply_articale) + count($good);
  6793. $result = [
  6794. 'apply_articale' => $apply_articale,
  6795. 'chat' => '',
  6796. 'chat_group' => '',
  6797. 'good' => $good,
  6798. 'count' => $count,
  6799. ];
  6800. } elseif ($type_id == 10000) {
  6801. //获取未审核的5篇文章
  6802. $apply_articale = Article::where('status', 0)
  6803. ->orderBy('updated_at', 'desc')
  6804. // ->limit(5)
  6805. ->get();
  6806. //获取5条单聊未读聊天消息
  6807. //获取5条单聊未读聊天消息
  6808. // $chat = ChatRecords::where('is_read', 0)
  6809. // ->where('user_id', $user_id)
  6810. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  6811. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  6812. // ->where('action', 'recieved')
  6813. // ->where('talk_type', 1)
  6814. // ->orderBy('created_at', 'desc')
  6815. // // ->limit(5)
  6816. // ->get();
  6817. // //获取5条未读群聊信息
  6818. // $chat_group = ChatRecords::where('is_read', 0)
  6819. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  6820. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  6821. // ->where('user_id', $user_id)
  6822. // ->where('talk_type', 2)
  6823. // ->orderBy('created_at', 'desc')
  6824. // // ->limit(5)
  6825. // ->get();
  6826. //获取5条用户的已审核商品
  6827. $good = Good::where('status', 1)
  6828. // ->where('user_id', $user_id)
  6829. ->orderBy('updated_at', 'desc')
  6830. // ->limit(5)
  6831. ->get();
  6832. //获取5条用户待审核的公告
  6833. $notice = Notice::where('status', 1)
  6834. ->orderBy('updated_at', 'desc')
  6835. // ->limit(5)
  6836. ->get();
  6837. //获取5条用户的待审核投诉
  6838. $complaint = Complaint::where('status', 1)
  6839. ->orderBy('updated_at', 'desc')
  6840. // ->limit(5)
  6841. ->get();
  6842. //获取5条用户的book
  6843. $book = Book::where('status', 1)
  6844. ->orderBy('updated_at', 'desc')
  6845. // ->limit(5)
  6846. ->get();
  6847. //获取5条用户的求职 1
  6848. $job_hunting = JobHunting::where('job_hunting.status', 1)
  6849. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  6850. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  6851. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6852. ->orderBy('updated_at', 'desc')
  6853. // ->limit(5)
  6854. ->get();
  6855. //获取5条用户的求职 2
  6856. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  6857. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  6858. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  6859. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6860. ->orderBy('updated_at', 'desc')
  6861. // ->limit(5)
  6862. ->get();
  6863. //人才库 1
  6864. $job_apply = JobApply::where('job_apply.status', 1)
  6865. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  6866. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  6867. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  6868. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  6869. ->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')
  6870. ->orderBy('updated_at', 'desc')
  6871. // ->limit(5)
  6872. ->get();
  6873. // 职场机会 2
  6874. $job_resume = JobResume::where('job_resume.status', 1)
  6875. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  6876. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  6877. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  6878. ->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')
  6879. ->orderBy('updated_at', 'desc')
  6880. // ->limit(5)
  6881. ->get();
  6882. //待审核数据com pro
  6883. $complany = Company::where('status', 0)
  6884. ->orderBy('updated_at', 'desc')
  6885. // ->limit(5)
  6886. ->get();
  6887. $project = Project::where('status', 0)
  6888. ->orderBy('updated_at', 'desc')
  6889. // ->limit(5)
  6890. ->get();
  6891. $count =
  6892. // count($chat) +
  6893. // count($chat_group) +
  6894. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  6895. + count($job_apply)
  6896. + count($job_resume)
  6897. + count($complany)
  6898. + count($project);
  6899. $result = [
  6900. 'apply_articale' => $apply_articale,
  6901. // 'chat' => $chat,
  6902. // 'chat_group' => $chat_group,
  6903. 'good' => $good,
  6904. 'notice' => $notice,
  6905. 'complaint' => $complaint,
  6906. 'book' => $book,
  6907. 'job_hunting' => $job_hunting,
  6908. 'job_recruiting' => $job_recruiting,
  6909. 'job_apply' => $job_apply,
  6910. 'job_resume' => $job_resume,
  6911. 'complany' => $complany,
  6912. 'project' => $project,
  6913. 'count' => $count,
  6914. ];
  6915. } elseif ($type_id == 20000) {
  6916. }
  6917. var_dump($type_id, '-----------------test---------');
  6918. return Result::success($result);
  6919. }
  6920. /**
  6921. * @param array $data
  6922. * @return array
  6923. */
  6924. public function getWebsiteProject(array $data): array
  6925. {
  6926. $categorys = json_decode($data['id'], true);
  6927. if (!empty($categorys)) {
  6928. $category_arr = $this->processArticlePro($data['website_id']);
  6929. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6930. $catiall = $category_arr['catiall'];
  6931. // return Result::success($catiall);
  6932. foreach ($categorys as $key => $val) {
  6933. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  6934. $level = explode(',', $val['level'])[0];
  6935. $imgnum = explode(',', $val['level'])[1] ?? null;
  6936. $textnum = explode(',', $val['level'])[2] ?? null;
  6937. if ($level == 1) {
  6938. if (!empty($textnum) && $textnum > 0) {
  6939. $text_num = Project::where('level', $level)
  6940. ->where('website_id', $data['website_id'])
  6941. ->where('status', 1)
  6942. ->select(
  6943. 'project.id',
  6944. 'project.title',
  6945. 'project.description',
  6946. 'project.updated_at',
  6947. 'project.category_id',
  6948. 'project.cat_arr_id'
  6949. )
  6950. ->orderBy('updated_at', 'desc')
  6951. ->limit($textnum)
  6952. ->get()->all();
  6953. }
  6954. if (!empty($imgnum) && $imgnum > 0) {
  6955. $img_num = Project::where('level', $level)
  6956. ->where('website_id', $data['website_id'])
  6957. ->where('status', 1)
  6958. ->where('imgurl', '!=', '')
  6959. ->whereNotNull('imgurl')
  6960. ->select(
  6961. 'project.id',
  6962. 'project.title',
  6963. 'project.description',
  6964. 'project.updated_at',
  6965. 'project.imgurl as imgs',
  6966. 'project.category_id',
  6967. 'project.cat_arr_id'
  6968. )
  6969. ->orderBy('updated_at', 'desc')
  6970. ->limit($imgnum)
  6971. ->get()->all();
  6972. }
  6973. } else {
  6974. if (!empty($textnum) && $textnum > 0) {
  6975. $text_num = Project::where('website_id', $data['website_id'])
  6976. ->where('status', 1)
  6977. ->select(
  6978. 'project.id',
  6979. 'project.title',
  6980. 'project.description',
  6981. 'project.updated_at',
  6982. 'project.category_id',
  6983. 'project.cat_arr_id',
  6984. 'project.website_id',
  6985. 'project.updated_at',
  6986. 'project.created_at'
  6987. )
  6988. ->orderBy('updated_at', 'desc')
  6989. ->limit($textnum)
  6990. ->get()->all();
  6991. }
  6992. if (!empty($imgnum) && $imgnum > 0) {
  6993. $img_num = Project::where('website_id', $data['website_id'])
  6994. ->where('status', 1)
  6995. ->where('imgurl', '!=', '')
  6996. ->whereNotNull('imgurl')
  6997. ->select(
  6998. 'project.id',
  6999. 'project.title',
  7000. 'project.description',
  7001. 'project.updated_at',
  7002. 'project.imgurl as imgs',
  7003. 'project.category_id',
  7004. 'project.cat_arr_id'
  7005. )
  7006. ->orderBy('updated_at', 'desc')
  7007. ->limit($imgnum)
  7008. ->get()->all();
  7009. }
  7010. }
  7011. }
  7012. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7013. $category_ids = explode(',', $val['id'])[0];
  7014. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7015. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7016. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7017. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7018. $text_num = Project::whereIn('category_id', $category_arr)
  7019. ->where('website_id', $data['website_id'])
  7020. ->where('status', 1)
  7021. ->select(
  7022. 'project.id',
  7023. 'project.title',
  7024. 'project.description',
  7025. 'project.updated_at',
  7026. 'project.category_id',
  7027. 'project.cat_arr_id'
  7028. )
  7029. ->orderBy('updated_at', 'desc')
  7030. ->limit($cat_textnum)
  7031. ->get()->all();
  7032. }
  7033. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7034. $img_num = Project::whereIn('category_id', $category_arr)
  7035. ->where('website_id', $data['website_id'])
  7036. ->where('status', 1)
  7037. ->where('imgurl', '!=', '')
  7038. ->whereNotNull('imgurl')
  7039. ->select(
  7040. 'project.id',
  7041. 'project.title',
  7042. 'project.description',
  7043. 'project.updated_at',
  7044. 'project.imgurl as imgs',
  7045. 'project.category_id',
  7046. 'project.cat_arr_id'
  7047. )
  7048. ->orderBy('updated_at', 'desc')
  7049. ->limit($cat_imgnum)
  7050. ->get()->all();
  7051. }
  7052. }
  7053. if (!empty($img_num)) {
  7054. foreach ($img_num as $k => $v) {
  7055. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7056. $imgurl = json_decode($v['imgs'], true);
  7057. if (!empty($imgurl)) {
  7058. $img_num[$k]->imgurl = $imgurl[0];
  7059. }
  7060. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7061. }
  7062. }
  7063. if (!empty($text_num)) {
  7064. foreach ($text_num as $k => $v) {
  7065. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7066. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7067. }
  7068. }
  7069. $project[$key]['img_num'] = $img_num ?? [];
  7070. $project[$key]['text_num'] = $text_num ?? [];
  7071. }
  7072. }
  7073. if (empty($project)) {
  7074. return Result::error("暂无相关项目信息", 0);
  7075. }
  7076. return Result::success($project);
  7077. }
  7078. /**
  7079. * @param array $data
  7080. * @return array
  7081. */
  7082. public function getWebsiteProjectInfo(array $data): array
  7083. {
  7084. $project = Project::where('id', $data['id'])
  7085. ->where('status', 1)
  7086. ->where('website_id', $data['website_id'])
  7087. ->select('project.*')
  7088. ->first();
  7089. if (empty($project)) {
  7090. return Result::error("暂无相关项目信息", 0);
  7091. }
  7092. return Result::success($project);
  7093. }
  7094. /**
  7095. * @param array $data
  7096. * @return array
  7097. */
  7098. public function getWebsiteProjectList(array $data): array
  7099. {
  7100. $where = [];
  7101. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7102. $where['category_id'] = $data['category_id'];
  7103. }
  7104. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7105. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7106. }
  7107. $query = Project::where($where)
  7108. ->where('status', 1)
  7109. ->where('website_id', $data['website_id'])
  7110. ->select(
  7111. 'project.id',
  7112. 'project.title',
  7113. 'project.description',
  7114. 'project.imgurl as imgs',
  7115. 'project.category_id',
  7116. 'project.cat_arr_id'
  7117. )
  7118. ->orderBy('updated_at', 'desc');
  7119. $count = $query->count();
  7120. $project = $query->clone()
  7121. ->offset(($data['page'] - 1) * $data['pageSize'])
  7122. ->limit($data['pageSize'])
  7123. ->get()->all();
  7124. if (empty($project)) {
  7125. return Result::error("暂无相关项目信息", 0);
  7126. }
  7127. $categorys = $this->processArticlePro($data['website_id']);
  7128. $catiall = $categorys['catiall'];
  7129. foreach ($project as $key => $val) {
  7130. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7131. if (!empty($val['imgs'])) {
  7132. $imgurl = json_decode($val['imgs'], true);
  7133. if (!empty($imgurl)) {
  7134. $project[$key]->imgurl = $imgurl[0];
  7135. }
  7136. } else {
  7137. $project[$key]->imgurl = '';
  7138. }
  7139. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7140. }
  7141. $result = [
  7142. 'rows' => $project,
  7143. 'count' => $count,
  7144. ];
  7145. return Result::success($result);
  7146. }
  7147. /**
  7148. * @param array $data
  7149. * @return array
  7150. */
  7151. public function getWebsiteCategoryJob(array $data): array
  7152. {
  7153. $categorys = json_decode($data['id'], true);
  7154. if (!empty($categorys)) {
  7155. $category_arr = $this->processArticlePro($data['website_id']);
  7156. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7157. $catiall = $category_arr['catiall'];
  7158. foreach ($categorys as $key => $val) {
  7159. if (isset($val['id']) && !empty($val['id'])) {
  7160. $catid = explode(',', $val['id'])[0] ?? null;
  7161. $type = explode(',', $val['id'])[1] ?? null;
  7162. $textnum = explode(',', $val['id'])[2] ?? null;
  7163. }
  7164. // 4:招聘;5:求职;
  7165. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7166. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7167. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7168. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7169. ->where('job_recruiting.status', 1)
  7170. ->where('job_recruiting.website_id', $data['website_id'])
  7171. ->select(
  7172. 'job_recruiting.id',
  7173. 'job_recruiting.title',
  7174. 'job_company.business_name',
  7175. 'job_recruiting.updated_at',
  7176. 'job_recruiting.cat_arr_id'
  7177. )
  7178. ->orderBy('job_recruiting.updated_at', 'desc')
  7179. ->limit($textnum)
  7180. ->get()->all();
  7181. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7182. // 状态 审核状态,1待审核2已审核3已拒绝
  7183. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7184. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7185. ->where('job_hunting.status', 2)
  7186. ->where('job_hunting.website_id', $data['website_id'])
  7187. ->select(
  7188. 'job_hunting.id',
  7189. 'job_hunting.name',
  7190. 'job_hunting.cat_arr_id',
  7191. 'job_position.zwname as job_name',
  7192. 'job_hunting.updated_at'
  7193. )
  7194. ->orderBy('updated_at', 'desc')
  7195. ->limit($textnum)
  7196. ->get()->all();
  7197. } else {
  7198. $job = [];
  7199. }
  7200. // var_dump($catid.'222uuuuuuu'.$key);
  7201. if (!empty($job)) {
  7202. foreach ($job as $k => $value) {
  7203. if (isset($value->cat_arr_id)) {
  7204. $catArr = json_decode($value->cat_arr_id, true);
  7205. $catId = end($catArr);
  7206. } else {
  7207. continue;
  7208. }
  7209. if (isset($catiall[$catId])) {
  7210. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7211. }
  7212. }
  7213. }
  7214. // var_dump($catid.'xxxxx'.$key);
  7215. $result[$key] = $job ?? [];
  7216. }
  7217. }
  7218. if (empty($result)) {
  7219. return Result::error("暂无相关分类信息", 0);
  7220. }
  7221. return Result::success($result);
  7222. }
  7223. /**
  7224. * 发送消息
  7225. * @param array $messageData
  7226. * @return void
  7227. */
  7228. public function sendMessage($messageData)
  7229. {
  7230. $msg = [
  7231. 'talk_type' => $messageData['talk_type'],
  7232. 'title' => $messageData['title'],
  7233. 'content' => $messageData['content'],
  7234. 'messageType' => $messageData['messageType'],
  7235. 'user_id' => $messageData['user_id'] ?? '',
  7236. ];
  7237. $message = new MqProducer($msg);
  7238. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7239. $producer->produce($message);
  7240. }
  7241. }