NewsService.php 218 KB

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