NewsService.php 210 KB

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