NewsService.php 208 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764
  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. public function getWebsiteAllArticle(array $data): array
  1404. {
  1405. // $redisKey = 'website_cache';
  1406. // $this->redis->hSet($redisKey, $data['website_id'], json_encode($data));
  1407. // $result = $this->redis->sadd($redisKey);
  1408. // 使用缓存键
  1409. // $cacheKey = $data['website_id'];
  1410. // // 尝试从缓存获取数据
  1411. $container = \Hyperf\Context\ApplicationContext::getContainer();
  1412. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  1413. // 修正传入的字符串,将单引号替换为双引号
  1414. $input['id'] = $data['id'];
  1415. $input['website_id'] = $data['website_id'];
  1416. // 将 JSON 字符串转换为 PHP 数组
  1417. $items = json_decode($input['id'], true);
  1418. if (!is_array($items)) {
  1419. return Result::error("无效的JSON格式", 0);
  1420. }
  1421. $website = [
  1422. 'website_id' => $input['website_id'],
  1423. ];
  1424. foreach ($items as $key => $item) {
  1425. if (isset($item['parent']) && $item['parent'] !== "") {
  1426. $parentParams = explode(',', $item['parent']);
  1427. if (isset($parentParams) && $parentParams[0] !== "") {
  1428. $parentCatId[$key] = $parentParams[0];
  1429. }
  1430. } else {
  1431. return Result::error("缺少必需参数错误", 0);
  1432. }
  1433. }
  1434. $pid = WebsiteCategory::whereIn('category_id', $parentCatId)->where($website)->pluck('pid')->toArray();
  1435. // return Result::success($pid);
  1436. if (!empty($pid)) {
  1437. $pid = array_values(array_unique($pid));
  1438. if (count($pid) == 1) {
  1439. $cacheKey = $data['website_id'] . ',' . $pid[0];
  1440. } else {
  1441. return Result::error("参数传递错误", 0);
  1442. }
  1443. }
  1444. // return Result::success($cacheKey);
  1445. if ($cachedData = $cache->get($cacheKey)) {
  1446. return Result::success(unserialize($cachedData));
  1447. }
  1448. try {
  1449. // 提前缓存常用查询结果,减少重复查询
  1450. $categoryCache = [];
  1451. $childCategoryCache = [];
  1452. // 使用 array_map 处理每个元素
  1453. $result = array_map(function ($item) use ($website, &$categoryCache, &$childCategoryCache) {
  1454. $resultItem = [
  1455. 'alias' => null,
  1456. 'category_id' => null,
  1457. 'pinyin' => null,
  1458. 'imgnum' => [],
  1459. 'textnum' => [],
  1460. 'child' => []
  1461. ];
  1462. // 处理父级栏目
  1463. if (isset($item['parent']) && $item['parent'] !== 'undefined' && $item['parent'] !== "") {
  1464. $parentParams = explode(',', $item['parent']);
  1465. if (count($parentParams) !== 3) {
  1466. return Result::error("父级栏目:缺少必需参数错误", 0);
  1467. }
  1468. list($parentCatId, $parentImgNum, $parentTextNum) = $parentParams;
  1469. $cacheKey = "parent_{$parentCatId}_{$website['website_id']}";
  1470. if (!isset($categoryCache[$cacheKey])) {
  1471. // 查询栏目名称
  1472. $categoryCache[$cacheKey] = WebsiteCategory::where('category_id', $parentCatId)
  1473. ->where($website)
  1474. ->first(['alias', 'category_id', 'aLIas_pinyin', 'type']);
  1475. }
  1476. $category = $categoryCache[$cacheKey];
  1477. if (!empty($category)) {
  1478. $resultItem['alias'] = $category->alias;
  1479. $resultItem['category_id'] = $category->category_id;
  1480. $resultItem['pinyin'] = $category->aLIas_pinyin;
  1481. // 查询图片新闻
  1482. if (!empty($parentImgNum)) {
  1483. $resultItem['imgnum'] = $this->fetchArticles($parentCatId, $website, (int)$parentImgNum, true);
  1484. }
  1485. // 查询文字新闻
  1486. if (!empty($parentTextNum)) {
  1487. $resultItem['textnum'] = $this->fetchArticles($parentCatId, $website, (int)$parentTextNum, false);
  1488. }
  1489. }
  1490. }
  1491. // 处理子级栏目
  1492. if (isset($item['child']) && $item['child'] !== 'undefined' && $item['child'] !== "") {
  1493. $childParams = explode(',', $item['child']);
  1494. if (count($childParams) !== 3) {
  1495. return Result::error("子级栏目:缺少必需参数错误", 0);
  1496. }
  1497. list($childCatId, $childImgNum, $childTextNum) = $childParams;
  1498. $cacheKey = "child_{$childCatId}_{$website['website_id']}";
  1499. if (!isset($childCategoryCache[$cacheKey])) {
  1500. // 查询子栏目信息
  1501. $childCategoryCache[$cacheKey] = WebsiteCategory::where($website)
  1502. ->where("category_id", $childCatId)
  1503. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($childCatId) . "') = 1")
  1504. ->first(['alias', 'category_id', 'aLIas_pinyin', 'pid', 'category_arr_id as cat_arr_id']);
  1505. }
  1506. $childCategory = $childCategoryCache[$cacheKey];
  1507. if (!empty($childCategory)) {
  1508. $childCategory = $this->processArticles($childCategory, $website);
  1509. // 查询此层级的所有子栏目
  1510. $allChildCategories = WebsiteCategory::where($website)
  1511. ->where("pid", $childCategory['pid'])
  1512. ->get(['alias', 'category_id', 'aLIas_pinyin', 'pid', 'category_arr_id as cat_arr_id']);
  1513. $allChildCategories = $this->processArticles($allChildCategories, $website);
  1514. $childResult = [
  1515. 'alias' => $childCategory->alias,
  1516. 'category_id' => $childCategory->category_id,
  1517. 'pinyin' => $childCategory->aLIas_pinyin,
  1518. 'all_childcat' => $allChildCategories,
  1519. 'imgnum' => [],
  1520. 'textnum' => []
  1521. ];
  1522. // 查询子栏目图片新闻
  1523. if (!empty($childImgNum)) {
  1524. $childResult['imgnum'] = $this->fetchArticles($childCatId, $website, (int)$childImgNum, true);
  1525. }
  1526. // 查询子栏目文字新闻
  1527. if (!empty($childTextNum)) {
  1528. $childResult['textnum'] = $this->fetchArticles($childCatId, $website, (int)$childTextNum, false);
  1529. }
  1530. $resultItem['child'] = $childResult;
  1531. }
  1532. }
  1533. return $resultItem;
  1534. }, $items);
  1535. $cache->set($cacheKey, serialize($result), 86400);
  1536. return Result::success($result);
  1537. } catch (\Exception $e) {
  1538. // 记录错误日志
  1539. return Result::error("获取网站文章失败: " . $e->getMessage());
  1540. }
  1541. }
  1542. /**
  1543. * 辅助方法:获取文章列表
  1544. */
  1545. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1546. {
  1547. sleep(1);
  1548. $query = Article::where('article.status', 1)
  1549. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1550. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1551. ->where(function ($query) use ($website) {
  1552. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1553. })
  1554. ->leftJoin('website_category', function ($join) use ($website) {
  1555. $join->on('article.catid', '=', 'website_category.category_id')
  1556. ->where('website_category.website_id', '=', $website['website_id']);
  1557. })
  1558. ->select(
  1559. 'article.id',
  1560. 'article.title',
  1561. 'article.imgurl',
  1562. 'article.author',
  1563. 'article.updated_at',
  1564. 'article.introduce',
  1565. 'article.islink',
  1566. 'article.linkurl',
  1567. 'article.copyfrom',
  1568. 'article.cat_arr_id',
  1569. 'article.catid',
  1570. 'website_category.alias as category_name'
  1571. )
  1572. ->orderBy('updated_at', 'desc')
  1573. ->limit($limit);
  1574. // 如果是图片文章,添加图片URL条件
  1575. if ($isImageArticle) {
  1576. $query->where('imgurl', '!=', '');
  1577. } else {
  1578. // 文字文章不需要imgurl字段
  1579. $query->addSelect('article.introduce');
  1580. }
  1581. $articles = $query->get();
  1582. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1583. }
  1584. /**
  1585. * 乡村网-获取特殊新闻模块
  1586. * @param array $data
  1587. * @return array
  1588. */
  1589. public function getWebsiteArticles(array $data): array
  1590. {
  1591. $input['id'] = $data['id'];
  1592. $input['website_id'] = $data['website_id'];
  1593. $data = json_decode($input['id'], true);
  1594. // 使用 array_map 处理每个元素
  1595. $result = array_map(function ($item) use ($input) {
  1596. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1597. $website = [
  1598. 'website_id' => $input['website_id']
  1599. ];
  1600. // 查询栏目名称
  1601. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1602. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1603. if (empty($category)) {
  1604. $imgArticles = [];
  1605. $textArticles = [];
  1606. // return Result::error("暂无此栏目",0);
  1607. } else {
  1608. $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1609. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin . '/' : null;
  1610. // return Result::success($website);
  1611. // 查询图片新闻
  1612. // 合并查询条件
  1613. $baseQuery = Article::where(function ($query) use ($website) {
  1614. $query->where(function ($subQuery) use ($website) {
  1615. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1616. })->orWhereNull("ignore_ids");
  1617. })
  1618. ->where('article.status', 1)
  1619. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1620. ->where('website_category.website_id', $website['website_id']);
  1621. // 查询文字新闻
  1622. $textArticles = clone $baseQuery;
  1623. $textArticles = $textArticles->whereIn('catid', $child_category)
  1624. ->select(
  1625. 'article.id',
  1626. 'article.title',
  1627. // 'article.imgurl',
  1628. 'article.author',
  1629. 'article.updated_at',
  1630. 'article.introduce',
  1631. 'article.islink',
  1632. 'article.linkurl',
  1633. 'article.copyfrom',
  1634. 'website_category.category_id',
  1635. 'website_category.alias',
  1636. 'website_category.aLIas_pinyin'
  1637. )
  1638. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1639. ->orderBy('article.updated_at', 'desc')
  1640. ->limit($parentTextNum)
  1641. ->get()
  1642. ->all();
  1643. if (empty($textArticles)) {
  1644. $textArticles = clone $baseQuery;
  1645. $textArticles = $textArticles->where('catid', $parentCatId)
  1646. ->select(
  1647. 'article.id',
  1648. 'article.title',
  1649. // 'article.imgurl',
  1650. 'article.author',
  1651. 'article.updated_at',
  1652. 'article.introduce',
  1653. 'article.islink',
  1654. 'article.linkurl',
  1655. 'article.copyfrom',
  1656. 'website_category.category_id',
  1657. 'website_category.alias',
  1658. 'website_category.aLIas_pinyin'
  1659. )
  1660. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1661. ->orderBy('article.updated_at', 'desc')
  1662. ->limit($parentTextNum)
  1663. ->get()
  1664. ->all();
  1665. }
  1666. // 查询图片新闻
  1667. $imgArticles = clone $baseQuery;
  1668. $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid', $child_category)
  1669. ->select(
  1670. 'article.id',
  1671. 'article.title',
  1672. 'article.imgurl',
  1673. 'article.author',
  1674. 'article.updated_at',
  1675. 'article.introduce',
  1676. 'article.islink',
  1677. 'article.linkurl',
  1678. 'article.copyfrom',
  1679. 'website_category.category_id',
  1680. 'website_category.alias',
  1681. 'website_category.aLIas_pinyin'
  1682. )
  1683. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1684. ->orderBy('article.updated_at', 'desc')
  1685. ->limit($parentImgNum)
  1686. ->get()
  1687. ->all();
  1688. if (empty($imgArticles)) {
  1689. $imgArticles = clone $baseQuery;
  1690. $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid', $parentCatId)
  1691. ->select(
  1692. 'article.id',
  1693. 'article.title',
  1694. 'article.imgurl',
  1695. 'article.author',
  1696. 'article.updated_at',
  1697. 'article.introduce',
  1698. 'article.islink',
  1699. 'article.linkurl',
  1700. 'article.copyfrom',
  1701. 'website_category.category_id',
  1702. 'website_category.alias',
  1703. 'website_category.aLIas_pinyin'
  1704. )
  1705. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1706. ->orderBy('article.updated_at', 'desc')
  1707. ->limit($parentImgNum)
  1708. ->get()
  1709. ->all();
  1710. }
  1711. }
  1712. $resultItem = [
  1713. 'alias' => $category ? $category->alias : null,
  1714. 'category_id' => $parentCatId,
  1715. 'pinyin' => $pinyin ? $pinyin : null,
  1716. 'imgnum' => $imgArticles ?? [],
  1717. 'textnum' => $textArticles ?? [],
  1718. ];
  1719. return $resultItem;
  1720. }, $data);
  1721. return Result::success($result);
  1722. }
  1723. // 封装处理商品的路由问题
  1724. function processGoods($goods, $data)
  1725. {
  1726. return $goods->map(function ($good) use ($data) {
  1727. $catid = $good->catid ?? 0;
  1728. // $pinyin = '';
  1729. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1730. if (!empty($category->pid) && $category->pid != 0) {
  1731. $level = json_decode($category->category_arr_id);
  1732. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1733. ->whereIn('category_id', $level)
  1734. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1735. ->get(['aLIas_pinyin'])
  1736. ->pluck('aLIas_pinyin')
  1737. ->implode('/');
  1738. } else {
  1739. $pinyin = $category->aLIas_pinyin ?? '';
  1740. }
  1741. if (isset($good->city_id) && !empty($good->city_id)) {
  1742. $city = District::where('id', $good->city_id)->first(['name']);
  1743. $good->city_name = $city->name ?? '';
  1744. }
  1745. // 解析imgurl JSON并取第一条数据
  1746. $imgUrls = json_decode($good->imgurl, true);
  1747. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1748. $good->pinyin = $pinyin;
  1749. return $good;
  1750. });
  1751. }
  1752. /**
  1753. * 获取商城首页-根据栏目id
  1754. * @param array $data
  1755. * @return array
  1756. * */
  1757. function getWebsiteCatidshop(array $data): array
  1758. {
  1759. $input['catid'] = $data['catid'];
  1760. $input['website_id'] = $data['website_id'];
  1761. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1762. $result = array_map(function ($item) use ($input) {
  1763. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1764. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1765. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1766. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1767. if (empty($category) || $category->type != 2) {
  1768. return Result::error("暂无此栏目", 0);
  1769. } else {
  1770. $website['website_id'] = $input['website_id'];
  1771. $goods = Good::where('good.status', 2)
  1772. ->where('good.website_id', $website['website_id'])
  1773. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1774. ->select(
  1775. 'good.id',
  1776. 'good.name',
  1777. 'good.imgurl',
  1778. 'good.description',
  1779. 'good.updated_at',
  1780. 'good.catid',
  1781. 'good.type_id',
  1782. 'good.price',
  1783. 'good.com',
  1784. 'good.level',
  1785. 'good.unit'
  1786. )
  1787. ->orderBy('updated_at', 'desc')
  1788. ->offset($goodStart)
  1789. ->limit($goodNum);
  1790. $all_goods = $goods->get();
  1791. $all_goods = $this->processGoods($all_goods, $website);
  1792. }
  1793. return $all_goods ?? [];
  1794. }
  1795. }, $data);
  1796. return Result::success($result);
  1797. }
  1798. /**
  1799. * 获取商品模块
  1800. * @param array $data
  1801. * @return array
  1802. * */
  1803. public function getWebsiteshop(array $data): array
  1804. {
  1805. $input['id'] = $data['id'];
  1806. $input['website_id'] = $data['website_id'];
  1807. $catid = $data['catid'];
  1808. $data = json_decode($input['id'] ?? '', true) ?? [];
  1809. $result['goods'] = array_map(function ($item) use ($input) {
  1810. // 检查parent元素是否存在且不是undefined
  1811. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  1812. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  1813. $website = $input['website_id'];
  1814. $query = Good::where('good.status', 2)
  1815. ->where('good.website_id', $website);
  1816. switch ($Levelid) {
  1817. case 1:
  1818. case 2:
  1819. case 3:
  1820. $goods = $query->where(function ($q) use ($Levelid) {
  1821. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  1822. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  1823. });
  1824. break;
  1825. case 4:
  1826. $goods = $query;
  1827. break;
  1828. case 5:
  1829. $goods = $query->where('type_id', 1);
  1830. break;
  1831. case 6:
  1832. $goods = $query->where('type_id', 2);
  1833. break;
  1834. default:
  1835. return [];
  1836. }
  1837. $all_goods = $goods
  1838. ->select(
  1839. 'good.id',
  1840. 'good.name',
  1841. 'good.imgurl',
  1842. 'good.description',
  1843. 'good.updated_at',
  1844. 'good.catid',
  1845. 'good.type_id',
  1846. 'good.price',
  1847. 'good.level',
  1848. 'good.website_id'
  1849. )
  1850. ->orderBy('updated_at', 'desc')
  1851. ->offset($goodStart)
  1852. ->limit($goodNum)
  1853. ->get();
  1854. $web['website_id'] = $website;
  1855. $all_goods = $this->processGoods($all_goods, $web);
  1856. }
  1857. return $all_goods;
  1858. }, $data);
  1859. $website = $input['website_id'];
  1860. $result['article'] = Article::where(function ($query) use ($website) {
  1861. $query->where(function ($subQuery) use ($website) {
  1862. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1863. })->orWhereNull("ignore_ids");
  1864. })
  1865. ->where('catid', $catid)
  1866. ->where('article.status', 1)
  1867. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  1868. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  1869. ->orderBy('article.updated_at', 'desc')
  1870. ->first();
  1871. return Result::success($result);
  1872. }
  1873. /**
  1874. * 获取商品分类
  1875. * @param array $data
  1876. * @return array
  1877. * */
  1878. public function getWebsiteshopCat(array $data): array
  1879. {
  1880. $website = $data['website_id'];
  1881. $category = WebsiteCategory::where('website_id', $website)
  1882. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  1883. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  1884. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  1885. ->orderBy('sort')
  1886. ->get();
  1887. $cat = $category->map(function ($item) use ($website) {
  1888. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  1889. $pid = $item->pid ?? 0;
  1890. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  1891. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  1892. ->where('website_id', $website)
  1893. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  1894. ->get(['aLIas_pinyin'])
  1895. ->pluck('aLIas_pinyin')
  1896. ->implode('/');
  1897. } else {
  1898. $pinyin = $item->aLIas_pinyin ?? '';
  1899. }
  1900. $item->pinyin = $pinyin;
  1901. });
  1902. if (empty($category)) {
  1903. return Result::error("栏目查询失败", 0);
  1904. }
  1905. $cat_tree = Result::buildMenuTree($category);
  1906. $web['website_id'] = $website;
  1907. $goods = Good::where('website_id', $website)
  1908. ->where('status', 2)
  1909. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  1910. ->latest('updated_at')
  1911. ->offset(($data['page'] - 1) * $data['pageSize'])
  1912. ->limit($data['pageSize'])
  1913. ->get();
  1914. if (!empty($goods)) {
  1915. if ($goods->count() > 1 && !empty($goods)) {
  1916. $goods = $this->processGoods($goods, $web);
  1917. }
  1918. } else {
  1919. $goods = [];
  1920. }
  1921. $result = [
  1922. 'category' => $cat_tree,
  1923. 'goods' => $goods,
  1924. ];
  1925. // $resul['goods'] = $goods;
  1926. if (empty($result)) {
  1927. return Result::error("查询失败", 0);
  1928. }
  1929. return Result::success($result);
  1930. }
  1931. /*
  1932. * 获取商品列表
  1933. * @param array $data
  1934. * @return array
  1935. * */
  1936. public function getWebsiteshopList(array $data): array
  1937. {
  1938. // return Result::success($data);
  1939. $where = [
  1940. 'status' => 2,
  1941. 'website_id' => $data['website_id'],
  1942. ];
  1943. if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  1944. return Result::error("查询失败", 0);
  1945. }
  1946. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  1947. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  1948. $data['catid'] = $category->category_id ?? 0;
  1949. }
  1950. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1951. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  1952. }
  1953. if (isset($data['type_id']) && !empty($data['type_id'])) {
  1954. array_push($where, ['type_id', $data['type_id']]);
  1955. }
  1956. $query = Good::where($where)
  1957. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  1958. $query->where(function ($q) use ($data) {
  1959. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  1960. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  1961. });
  1962. })
  1963. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  1964. $query->where(function ($q) use ($data) {
  1965. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  1966. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  1967. });
  1968. })
  1969. ->select(
  1970. 'good.id',
  1971. 'good.name',
  1972. 'good.imgurl',
  1973. 'good.description',
  1974. 'good.updated_at',
  1975. 'good.com',
  1976. 'good.catid',
  1977. 'good.type_id',
  1978. 'good.website_id',
  1979. 'good.cat_arr_id',
  1980. 'good.created_at',
  1981. 'good.city_id'
  1982. )
  1983. ->latest('updated_at');
  1984. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  1985. // 获取 type_id 为 1 的数据
  1986. $result['type1'] = $this->processGoods(
  1987. $query->clone()
  1988. ->where('type_id', 1)
  1989. ->offset(($data['page'] - 1) * $data['pageSize'])
  1990. ->limit($data['pageSize'])
  1991. ->get(),
  1992. $data
  1993. );
  1994. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  1995. // 获取 type_id 为 2 的数据
  1996. $result['type2'] = $this->processGoods(
  1997. $query->clone()
  1998. ->where('type_id', 2)
  1999. ->offset(($data['page'] - 1) * $data['pageSize'])
  2000. ->limit($data['pageSize'])
  2001. ->get(),
  2002. $data
  2003. );
  2004. if (empty($result)) {
  2005. return Result::error("查询失败", 0);
  2006. }
  2007. return Result::success($result);
  2008. }
  2009. /**
  2010. * 获取商品详情
  2011. * @param array $data
  2012. * @return array
  2013. * */
  2014. public function getWebsiteshopInfo(array $data): array
  2015. {
  2016. $where = [
  2017. 'good.status' => 2,
  2018. 'good.website_id' => $data['website_id'],
  2019. 'good.id' => $data['id'],
  2020. ];
  2021. $goods = Good::where($where)
  2022. ->where('good.id', $data['id'])
  2023. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2024. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2025. ->first();
  2026. if (empty($goods)) {
  2027. return Result::error("查询失败", 0);
  2028. }
  2029. $goods->imgurl = json_decode($goods->imgurl, true);
  2030. return Result::success($goods);
  2031. }
  2032. /**
  2033. * 封装处理文章的路由问题
  2034. * */
  2035. function processArticles($articles, $data)
  2036. {
  2037. // 检查 $articles 是否为数组或可迭代对象
  2038. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2039. return $articles->map(function ($article) use ($data) {
  2040. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2041. $catid = $article->cat_arr_id ?? '';
  2042. }
  2043. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2044. $catid = $article->category_arr_id ?? '';
  2045. }
  2046. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2047. $level = json_decode($catid, true);
  2048. if (!is_array($level)) {
  2049. return $article;
  2050. } else {
  2051. $level = array_map('intval', $level);
  2052. }
  2053. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2054. ->where($data)
  2055. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2056. ->pluck('aLIas_pinyin')
  2057. ->implode('/');
  2058. $article->pinyin = $pinyin ?? '';
  2059. return $article;
  2060. });
  2061. } else {
  2062. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2063. $catid = $articles->cat_arr_id ?? '';
  2064. $level = json_decode($catid, true);
  2065. if (!is_array($level)) {
  2066. return $articles;
  2067. } else {
  2068. $level = array_map('intval', $level);
  2069. }
  2070. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2071. ->where($data)
  2072. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2073. ->pluck('aLIas_pinyin')
  2074. ->implode('/');
  2075. $articles->pinyin = $pinyin ?? '';
  2076. return $articles;
  2077. }
  2078. }
  2079. // 封装处理由问题
  2080. function processJob($job, $data)
  2081. {
  2082. return $job->map(function ($job) use ($data) {
  2083. $category = $job->cat_arr_id ?? '';
  2084. $cityid = $job->city_arr_id ?? '';
  2085. $city = json_decode($cityid, true);
  2086. $pinyin = '';
  2087. $level = json_decode($category, true);
  2088. // 路由
  2089. if (!empty($level) && is_array($level)) {
  2090. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2091. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2092. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2093. ->get(['aLIas_pinyin'])
  2094. ->pluck('aLIas_pinyin')
  2095. ->implode('/');
  2096. if (empty($pinyin)) {
  2097. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2098. }
  2099. $job->pinyin = $pinyin;
  2100. }
  2101. // 取职位-城市 市??省
  2102. if (!empty($city) && is_array($city)) {
  2103. if (isset($city[1]) && !empty($city[1])) {
  2104. $city = District::where('id', $city[1])->first(['name']);
  2105. $job->city_name = $city->name ?? '';
  2106. } else if (isset($city[0]) && !empty($city[0])) {
  2107. $city = District::where('id', $city[0])->first(['name']);
  2108. $job->city_name = $city->name ?? '';
  2109. } else {
  2110. $job->city_name = '全国';
  2111. }
  2112. }
  2113. // 获取简历最后一级地区
  2114. if (isset($job->city_id) && !empty($job->city_id)) {
  2115. $city = District::where('id', $job->city_id)->first(['name']);
  2116. $job->hunt_cityname = $city->name ?? '';
  2117. }
  2118. // 组合详细地址
  2119. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2120. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2121. if (is_array($address_id) && !empty($address_id)) {
  2122. $address = District::whereIn('id', $address_id)
  2123. ->orderBy('level', 'asc')
  2124. ->get(['name'])
  2125. ->pluck('name')
  2126. ->implode('');
  2127. // $job->address_name = $address ?? '';
  2128. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2129. }
  2130. }
  2131. // 取行业
  2132. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2133. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2134. if (!empty($job->industry)) {
  2135. $query->where('hyid', $job->industry);
  2136. } else if (!empty($job->hy_id)) {
  2137. $query->where('hyid', $job->hy_id);
  2138. } else if (!empty($job->company_hy_id)) {
  2139. $query->where('hyid', $job->company_hy_id);
  2140. } else {
  2141. $query->where('hyid', $job->job_industry);
  2142. }
  2143. })->first(['hyname']);
  2144. $job->hy_name = $hy_name->hyname ?? '';
  2145. }
  2146. // 取职位类别
  2147. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2148. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2149. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2150. $job->zw_name = $zw_name->zwname ?? '';
  2151. }
  2152. // 取具体职位
  2153. 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))) {
  2154. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2155. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2156. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2157. }
  2158. // 取工作经验
  2159. if (isset($job->experience) && !empty($job->experience)) {
  2160. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2161. $job->experience_name = $experience->ename ?? '';
  2162. }
  2163. // 取学历
  2164. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2165. $education = $job->educational ?? $job->school_education;
  2166. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2167. $job->education_name = $education->ename ?? '';
  2168. }
  2169. // 语言
  2170. if (isset($job->language) && !empty($job->language)) {
  2171. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2172. $job->language_name = $language->ename ?? '';
  2173. }
  2174. // 薪资
  2175. if (isset($job->salary) && !empty($job->salary)) {
  2176. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2177. $job->salary_name = $salary->ename ?? '';
  2178. }
  2179. // 职位性质
  2180. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2181. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2182. $job->job_nature_name = $job_nature->ename ?? '';
  2183. }
  2184. // 公司规模
  2185. if (isset($job->company_size) && !empty($job->company_size)) {
  2186. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2187. $job->company_size_name = $company_size->ename ?? '';
  2188. }
  2189. // 公司性质
  2190. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2191. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2192. $job->company_nature_name = $company_nature->nature_name ?? '';
  2193. }
  2194. // $job->pinyin = $pinyin;
  2195. return $job;
  2196. });
  2197. }
  2198. /**
  2199. * 获取书籍模块
  2200. * @param array $data
  2201. * @return array
  2202. * */
  2203. public function getWebsiteBook(array $data): array
  2204. {
  2205. $input['id'] = $data['id'];
  2206. $input['website_id'] = $data['website_id'];
  2207. // 将 JSON 字符串转换为 PHP 数组
  2208. $data = json_decode($input['id'], true);
  2209. // 使用 array_map 处理每个元素
  2210. $result = array_map(function ($item) use ($input) {
  2211. // 检查parent元素是否存在且不是undefined
  2212. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2213. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2214. $website = [
  2215. 'website_id' => $input['website_id'],
  2216. ];
  2217. // 查询栏目名称
  2218. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2219. if (empty($category)) {
  2220. $parent_alias = '';
  2221. $parent_pinyin = null;
  2222. $imgBooks = [];
  2223. $textBooks = [];
  2224. } else {
  2225. $parent_alias = $category->alias ?? '';
  2226. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2227. // 查找子分类ID数组
  2228. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2229. array_push($childCategoryIds, $parentCatId);
  2230. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2231. if ($parentImgNum != 0) {
  2232. // 查询图片新闻
  2233. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2234. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2235. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2236. })
  2237. ->where('book.status', 2)
  2238. ->where('book.img_url', '!=', '')
  2239. ->leftJoin('website_category', function ($join) use ($website) {
  2240. $join->on('book.cat_id', '=', 'website_category.category_id')
  2241. ->where('website_category.website_id', '=', $website['website_id']);
  2242. })
  2243. ->select(
  2244. 'book.id',
  2245. 'book.title',
  2246. 'book.img_url',
  2247. 'book.price',
  2248. 'book.market_price',
  2249. 'book.description',
  2250. 'book.cat_id',
  2251. 'book.description',
  2252. 'book.updated_at',
  2253. 'website_category.alias as category_name',
  2254. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2255. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2256. )
  2257. ->orderBy('updated_at', 'desc')
  2258. ->limit($parentImgNum)
  2259. ->get()->all();
  2260. // 查询文字新闻
  2261. }
  2262. if ($parentTextNum != 0) {
  2263. $textBooks = [];
  2264. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2265. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2266. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2267. })
  2268. ->where('book.status', 2)
  2269. ->leftJoin('website_category', function ($join) use ($website) {
  2270. $join->on('book.cat_id', '=', 'website_category.category_id')
  2271. ->where('website_category.website_id', '=', $website['website_id']);
  2272. })
  2273. ->select(
  2274. 'book.id',
  2275. 'book.title',
  2276. 'book.img_url',
  2277. 'book.price',
  2278. 'book.market_price',
  2279. 'book.description',
  2280. 'book.cat_id',
  2281. 'book.description',
  2282. 'book.updated_at',
  2283. 'website_category.alias as category_name',
  2284. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2285. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2286. )
  2287. ->orderBy('updated_at', 'desc')
  2288. ->limit($parentTextNum)
  2289. ->get()->all();
  2290. }
  2291. }
  2292. }
  2293. $resultItem = [
  2294. 'alias' => $parent_alias ?? '',
  2295. 'category_id' => $parentCatId ?? 0,
  2296. 'pinyin' => $parent_pinyin ?? null,
  2297. 'imgnum' => $imgBooks ?? [],
  2298. 'textnum' => $textBooks ?? [],
  2299. ];
  2300. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2301. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2302. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2303. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2304. ->get()->all();
  2305. if (!empty($childCategory)) {
  2306. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2307. // 查询子栏目名称
  2308. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2309. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2310. ->first();
  2311. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2312. $childImgArticles = [];
  2313. $childTextArticles = [];
  2314. $resultItem['child'] = [];
  2315. } else {
  2316. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2317. // 查询子栏目图片新闻
  2318. $childImgArticles = Book::where('cat_id', $childCatId)
  2319. ->where('status', 2)
  2320. ->where('img_url', '!=', '')
  2321. ->leftJoin('website_category', function ($join) use ($website) {
  2322. $join->on('book.cat_id', '=', 'website_category.category_id')
  2323. ->where('website_category.website_id', '=', $website['website_id']);
  2324. })
  2325. ->select(
  2326. 'book.id',
  2327. 'book.title',
  2328. 'book.img_url',
  2329. 'book.price',
  2330. 'book.market_price',
  2331. 'book.description',
  2332. 'book.cat_id',
  2333. 'book.description',
  2334. 'book.updated_at',
  2335. DB::raw("'$child_pinyin' as pinyin")
  2336. )
  2337. ->orderBy('updated_at', 'desc')
  2338. ->limit($childImgNum)
  2339. ->get()->all();
  2340. // 查询子栏目文字新闻
  2341. $childTextArticles = Book::where('cat_id', $childCatId)
  2342. ->where('status', 2)
  2343. ->leftJoin('website_category', function ($join) use ($website) {
  2344. $join->on('book.cat_id', '=', 'website_category.category_id')
  2345. ->where('website_category.website_id', '=', $website['website_id']);
  2346. })
  2347. ->select(
  2348. 'book.id',
  2349. 'book.title',
  2350. 'book.img_url',
  2351. 'book.price',
  2352. 'book.market_price',
  2353. 'book.description',
  2354. 'book.cat_id',
  2355. 'book.description',
  2356. 'book.updated_at',
  2357. DB::raw("'$child_pinyin' as pinyin")
  2358. )
  2359. ->orderBy('updated_at', 'desc')
  2360. ->limit($childTextNum)
  2361. ->get()->all();
  2362. $resultItem['child'] = [
  2363. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2364. 'category_id' => $childCatId,
  2365. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2366. 'all_childcat' => $childCategory,
  2367. 'imgnum' => $childImgArticles,
  2368. 'textnum' => $childTextArticles,
  2369. ];
  2370. }
  2371. }
  2372. } else {
  2373. $resultItem['child'] = [];
  2374. }
  2375. return $resultItem;
  2376. }, $data);
  2377. return Result::success($result);
  2378. }
  2379. /**
  2380. * 获取书刊列表
  2381. * @param array $data
  2382. * @return array
  2383. * */
  2384. public function getWebsiteBookList(array $data): array
  2385. {
  2386. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2387. if (empty($web)) {
  2388. return Result::error("查询失败", 0);
  2389. }
  2390. $catid = $data['id'];
  2391. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2392. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2393. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2394. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2395. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2396. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2397. ->where('pid', $category['pid'])
  2398. ->select(
  2399. 'category_id',
  2400. 'alias',
  2401. 'aLIas_pinyin',
  2402. 'pid',
  2403. 'sort',
  2404. 'is_url',
  2405. 'web_url',
  2406. 'seo_title',
  2407. 'seo_keywords',
  2408. 'seo_description',
  2409. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2410. )
  2411. ->orderBy('sort')
  2412. ->get()->all();
  2413. if (empty($category)) {
  2414. return Result::error("查询失败", 0);
  2415. }
  2416. $query = Book::where('book.status', 2)
  2417. ->where('book.website_id', $data['website_id'])
  2418. ->where('book.cat_id', $catid)
  2419. ->select(
  2420. 'book.id',
  2421. 'book.title',
  2422. 'book.img_url',
  2423. 'book.description',
  2424. 'book.updated_at',
  2425. 'book.cat_id',
  2426. DB::raw("'$pinyin' as pinyin")
  2427. )
  2428. ->orderBy('book.updated_at', 'desc');
  2429. $count = $query->count();
  2430. $query = clone $query;
  2431. $Book = $query
  2432. ->limit($data['pageSize'])
  2433. ->offset(($data['page'] - 1) * $data['pageSize'])
  2434. ->get()->all();
  2435. $result = [
  2436. 'category' => $categorys,
  2437. 'books' => $Book,
  2438. 'count' => $count,
  2439. ];
  2440. // if(empty($result)){
  2441. // return Result::error("查询失败", 0);
  2442. // }
  2443. return Result::success($result);
  2444. }
  2445. /**
  2446. * 获取书刊详情
  2447. * @param array $data
  2448. * @return array
  2449. * */
  2450. public function getWebsiteBookInfo(array $data): array
  2451. {
  2452. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2453. if (empty($web)) {
  2454. return Result::error("查询失败", 0);
  2455. }
  2456. $book = Book::where('status', 2)
  2457. ->where('website_id', $data['website_id'])
  2458. ->where('id', $data['id'])
  2459. ->select(
  2460. 'book.*',
  2461. )
  2462. ->orderBy('updated_at', 'desc')
  2463. ->first();
  2464. if (empty($book)) {
  2465. return Result::error("查询失败", 0);
  2466. }
  2467. // 先查询当前分类的 pid
  2468. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2469. ->where('category_id', $book['cat_id'])
  2470. ->first(['pid', 'category_id']);
  2471. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2472. if (!empty($carpid)) {
  2473. if ($carpid->pid != 0) {
  2474. $pid = $carpid['pid'];
  2475. // $parent_pinyin = '';
  2476. } else {
  2477. $pid = $carpid['category_id'];
  2478. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2479. }
  2480. }
  2481. $categorys = $query->where('pid', $pid)
  2482. ->select(
  2483. 'category_id',
  2484. 'alias',
  2485. 'aLIas_pinyin',
  2486. 'pid',
  2487. 'sort',
  2488. 'is_url',
  2489. 'web_url',
  2490. 'category_arr_id as cat_arr_id',
  2491. )
  2492. ->orderBy('sort')
  2493. ->get();
  2494. $category = $this->processArticle($categorys, $data);
  2495. $result = [
  2496. 'category' => $category,
  2497. 'books' => $book,
  2498. ];
  2499. return Result::success($result);
  2500. }
  2501. /**
  2502. * 尝试
  2503. * @param array $data
  2504. * @return array
  2505. * */
  2506. public function test(array $data): array
  2507. {
  2508. $input['id'] = $data['id'];
  2509. $input['website_id'] = $data['website_id'];
  2510. // 将 JSON 字符串转换为 PHP 数组
  2511. $data = json_decode($input['id'], true);
  2512. $result = [];
  2513. $article = $data;
  2514. $result = array_map(function ($item) use ($input) {
  2515. $website = [
  2516. 'website_id' => $input['website_id'],
  2517. ];
  2518. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2519. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2520. $parent = [
  2521. 0 => $category['category_id'] ?? [],
  2522. 1 => $parentImgNum ?? [],
  2523. 2 => $parentTextNum ?? [],
  2524. ];
  2525. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2526. $child = [];
  2527. $resultItem = [
  2528. // 'alias' => $parent_alias ?? '',
  2529. 'category_id' => $parentCatId ?? 0,
  2530. 'pinyin' => $parentImgNum ?? null,
  2531. 'imgnum' => $parentTextNum ?? [],
  2532. // 'textnum' => $textArticles ?? [],
  2533. ];
  2534. return $parent;
  2535. }, $data);
  2536. return Result::success($result);
  2537. // });
  2538. }
  2539. /**
  2540. * 封装处理文章的路由问题
  2541. * */
  2542. function processArticle($article, $data)
  2543. {
  2544. return $article->map(function ($article) use ($data) {
  2545. $catid = $article->cat_arr_id ?? '';
  2546. $level = json_decode($catid, true);
  2547. $pinyin = '';
  2548. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2549. if (!empty($level) && is_array($level)) {
  2550. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2551. ->where('website_id', $data['website_id'])
  2552. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2553. ->get(['aLIas_pinyin'])
  2554. ->pluck('aLIas_pinyin')
  2555. ->implode('/');
  2556. } else {
  2557. $pinyin = '';
  2558. }
  2559. $article->pinyin = $pinyin;
  2560. return $article;
  2561. });
  2562. }
  2563. /**
  2564. * c端-获取招工招聘下拉选框
  2565. * @param array $data
  2566. * @return array
  2567. * */
  2568. public function getWebsiteJobSelect(array $data): array
  2569. {
  2570. $web = Website::where('id', $data['website_id'])->first();
  2571. if (empty($web)) {
  2572. return Result::error("该网站不存在", 0);
  2573. }
  2574. $hy = JobIndustry::get()->all();
  2575. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2576. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2577. $result = [
  2578. 'hy' => $hy,
  2579. 'zw' => $zw,
  2580. 'jtzw' => $jtzw,
  2581. ];
  2582. if (empty($result)) {
  2583. return Result::error("查询失败", 0);
  2584. }
  2585. return Result::success($result);
  2586. }
  2587. /**
  2588. * c端-获取招工招聘
  2589. * @param array $data
  2590. * @return array
  2591. * */
  2592. public function getWebsiteJob(array $data): array
  2593. {
  2594. $web = Website::where('id', $data['website_id'])->first();
  2595. if (empty($web)) {
  2596. return Result::error("该网站不存在", 0);
  2597. }
  2598. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2599. ->where('job_hunting.website_id', $data['website_id'])
  2600. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2601. $query->where(function ($q) use ($data) {
  2602. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2603. });
  2604. })
  2605. ->select(
  2606. 'job_hunting.id',
  2607. 'job_hunting.cat_arr_id',
  2608. 'job_hunting.job_name_get',
  2609. 'job_hunting.industry',
  2610. 'job_hunting.name',
  2611. 'job_hunting.sexy',
  2612. 'job_hunting.origin',
  2613. 'job_hunting.city_arr_id',
  2614. 'job_hunting.experience',
  2615. 'job_hunting.updated_at',
  2616. 'job_hunting.salary'
  2617. )
  2618. ->orderBy('updated_at', 'desc')
  2619. ->limit($data['job1_num'])
  2620. ->get();
  2621. $web['website_id'] = $data['website_id'];
  2622. if (empty($job_hunting)) {
  2623. $job_huntings = "未查询到相关简历信息";
  2624. } else {
  2625. $job_huntings = $this->processJob($job_hunting, $web);
  2626. }
  2627. // 0:待审核 1:已通过 2:已拒绝
  2628. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2629. ->where('job_recruiting.website_id', $data['website_id'])
  2630. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2631. $query->where(function ($q) use ($data) {
  2632. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2633. });
  2634. })
  2635. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2636. ->select(
  2637. 'job_recruiting.id',
  2638. 'job_recruiting.cat_arr_id',
  2639. 'job_recruiting.title',
  2640. 'job_recruiting.jtzw_id',
  2641. 'job_recruiting.hy_id',
  2642. 'job_recruiting.city_arr_id',
  2643. 'job_recruiting.due_data',
  2644. 'job_recruiting.updated_at',
  2645. 'job_recruiting.experience',
  2646. 'job_recruiting.educational',
  2647. 'job_recruiting.salary',
  2648. 'job_recruiting.zw_id',
  2649. 'job_company.business_name'
  2650. )
  2651. ->orderBy('updated_at', 'desc')
  2652. ->limit($data['job2_num'])
  2653. ->get();
  2654. if (empty($job_recruiting->toArray())) {
  2655. $job_recruitings = "未查询到相关职位信息";
  2656. } else {
  2657. $job_recruitings = $this->processJob($job_recruiting, $web);
  2658. }
  2659. $result = [
  2660. 'job_hunting' => $job_huntings,
  2661. 'job_recuiting' => $job_recruitings,
  2662. ];
  2663. return Result::success($result);
  2664. }
  2665. /**
  2666. * c端-获取招工招聘列表
  2667. * @param array $data
  2668. * @return array
  2669. * */
  2670. public function getWebsiteJobList(array $data): array
  2671. {
  2672. $recruit_where = [];
  2673. $hunt_where = [];
  2674. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2675. if (empty($web)) {
  2676. return Result::error("此网站不存在", 0);
  2677. }
  2678. $website_id['website_id'] = $data['website_id'];
  2679. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2680. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2681. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2682. }
  2683. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2684. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2685. }
  2686. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2687. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2688. }
  2689. $query = JobRecruiting::where('job_recruiting.status', 1)
  2690. ->where('job_recruiting.website_id', $data['website_id'])
  2691. ->where($recruit_where)
  2692. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2693. $query->where(function ($q) use ($data) {
  2694. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2695. });
  2696. })
  2697. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2698. $query->where(function ($q) use ($data) {
  2699. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2700. });
  2701. })
  2702. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2703. ->select(
  2704. 'job_recruiting.id',
  2705. 'job_recruiting.hy_id',
  2706. 'job_recruiting.title',
  2707. 'job_recruiting.zw_id',
  2708. 'job_recruiting.educational',
  2709. 'job_recruiting.jtzw_id',
  2710. 'job_recruiting.city_arr_id',
  2711. 'job_recruiting.due_data',
  2712. 'job_recruiting.experience',
  2713. 'job_recruiting.cat_arr_id',
  2714. 'job_recruiting.updated_at',
  2715. 'job_company.business_name'
  2716. )
  2717. ->orderBy('updated_at', 'desc');
  2718. $recruit_count = $query->count();
  2719. $query = clone $query;
  2720. $JobRecruiting = $query
  2721. ->offset(($data['page'] - 1) * $data['pageSize'])
  2722. ->limit($data['pageSize'])
  2723. ->get();
  2724. if (empty($JobRecruiting)) {
  2725. $JobRecruiting = "暂无相关职位信息";
  2726. } else {
  2727. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2728. }
  2729. }
  2730. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2731. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2732. array_push($hunt_where, ['job', $data['zw_id']]);
  2733. }
  2734. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2735. array_push($hunt_where, ['job_name_get', $data['jtzw_id']]);
  2736. }
  2737. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2738. array_push($hunt_where, ['industry', $data['hy_id']]);
  2739. }
  2740. $query = JobHunting::where('status', 2)
  2741. ->where('job_hunting.website_id', $data['website_id'])
  2742. ->where($hunt_where)
  2743. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2744. $query->where(function ($q) use ($data) {
  2745. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2746. });
  2747. })
  2748. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  2749. $query->where(function ($q) use ($data) {
  2750. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  2751. });
  2752. })
  2753. ->select('id', 'sexy', 'experience', 'origin', 'industry', 'name', 'job', 'job_name_get', 'city_arr_id', 'cat_arr_id', 'created_at', 'updated_at')
  2754. ->orderBy('updated_at', 'desc');
  2755. $hunt_count = $query->count();
  2756. $query = clone $query;
  2757. $JobHunting = $query
  2758. ->offset(($data['page'] - 1) * $data['pageSize'])
  2759. ->limit($data['pageSize'])
  2760. ->get();
  2761. if (empty($JobHunting)) {
  2762. $JobRecruiting = "暂无相关简历信息";
  2763. } else {
  2764. $JobHunting = $this->processJob($JobHunting, $website_id);
  2765. }
  2766. }
  2767. $result = [
  2768. 'JobRecruiting' => $JobRecruiting ?? [],
  2769. 'recruit_count' => $recruit_count ?? 0,
  2770. 'JobHunting' => $JobHunting ?? [],
  2771. 'hunt_count' => $hunt_count ?? 0,
  2772. ];
  2773. return Result::success($result);
  2774. }
  2775. /**
  2776. * c端-获取招工招聘详情
  2777. * @param array $data
  2778. * @return array
  2779. * */
  2780. public function getWebsiteJobInfo(array $data): array
  2781. {
  2782. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2783. if (empty($web)) {
  2784. return Result::error("该网站不存在", 0);
  2785. }
  2786. $webid = [
  2787. 'website_id' => $data['website_id'],
  2788. ];
  2789. // 职位相关信息
  2790. if ($data['type'] == 1) {
  2791. $query = JobRecruiting::where('status', 1)
  2792. ->where('website_id', $data['website_id'])
  2793. ->select('*');
  2794. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2795. $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();
  2796. if (!empty($company)) {
  2797. $result['company'] = $this->processJob($company, $webid);
  2798. }
  2799. $other_job = JobRecruiting::where('status', 1)
  2800. ->where('website_id', $data['website_id'])
  2801. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2802. ->where('id', '!=', $data['id'])
  2803. ->where('user_id', '=', $job[0]['user_id'])
  2804. ->limit($data['pageSize'])
  2805. ->get();
  2806. if (!empty($other_job)) {
  2807. $result['other_job'] = $this->processJob($other_job, $webid);
  2808. }
  2809. } else {
  2810. // 简历相关信息
  2811. $job = JobHunting::where('job_hunting.status', 2)
  2812. ->where('job_hunting.website_id', $data['website_id'])
  2813. ->where('job_hunting.id', $data['id'])
  2814. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2815. ->select('job_hunting.*', 'user_name')
  2816. ->get();
  2817. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  2818. if (!empty($resume->toArray())) {
  2819. $result['resume'] = 1;
  2820. } else {
  2821. $result['resume'] = 0;
  2822. }
  2823. }
  2824. if (empty($job->toArray())) {
  2825. return Result::error("id参数错误", 0);
  2826. }
  2827. if (!empty($job[0]['job_experience'])) {
  2828. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  2829. if (!empty($job_experience)) {
  2830. // $hy = [];
  2831. foreach ($job_experience as $key => $value) {
  2832. // $id = $value['id'];
  2833. $hy[$key] = $value['job_industry'];
  2834. $zw_id[$key] = $value['job_typename'];
  2835. $jtzw_id[$key] = $value['job_name'];
  2836. }
  2837. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  2838. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  2839. // 先将关联表转换为索引数组,提高查找效率
  2840. $hyLookup = [];
  2841. foreach ($hy_table as $item) {
  2842. $hyLookup[$item['hyid']] = $item['hyname'];
  2843. }
  2844. $zwLookup = [];
  2845. foreach ($zw_table as $item) {
  2846. $zwLookup[$item['zwid']] = $item['zwname'];
  2847. }
  2848. foreach ($job_experience as $key => &$value) {
  2849. // 处理行业名称
  2850. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  2851. $value['hy_name'] = $hyLookup[$hy[$key]];
  2852. }
  2853. // 处理职位名称
  2854. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  2855. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  2856. }
  2857. // 处理具体职位名称
  2858. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  2859. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  2860. }
  2861. }
  2862. // 释放引用,防止意外修改后续代码
  2863. unset($value);
  2864. }
  2865. $result['job_experience'] = $job_experience ?? [];
  2866. }
  2867. if (!empty($job[0]['education_experience'])) {
  2868. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  2869. if (!empty($education_experience)) {
  2870. foreach ($education_experience as $key => $value) {
  2871. // $id = $value['id'];
  2872. $education[$key] = $value['school_education'];
  2873. }
  2874. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  2875. // // 先将关联表转换为索引数组,提高查找效率
  2876. $educationLookup = [];
  2877. foreach ($education_table as $item) {
  2878. $educationLookup[$item['evalue']] = $item['ename'];
  2879. }
  2880. foreach ($education_experience as $key => &$value) {
  2881. // 处理学历名称
  2882. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  2883. $value['education_name'] = $educationLookup[$education[$key]];
  2884. }
  2885. }
  2886. }
  2887. $result['education_experience'] = $job_experience ?? [];
  2888. }
  2889. $result['job'] = $this->processJob($job, $webid);
  2890. // // 返现对应的栏目
  2891. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  2892. $category = WebsiteCategory::where('website_id', $data['website_id'])
  2893. ->whereIn('category_id', $catid)
  2894. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  2895. ->orderBy('pid')->get()->all();
  2896. if (!empty($category)) {
  2897. $result['category'] = $category;
  2898. }
  2899. $result['job'] = $job;
  2900. $result['job_experience'] = $job_experience ?? [];
  2901. $result['education_experience'] = $education_experience ?? [];
  2902. if (empty($result)) {
  2903. return Result::error("参数错误", 0);
  2904. }
  2905. return Result::success($result);
  2906. }
  2907. /**
  2908. * c端-申请职位
  2909. * @param array $data
  2910. * @return array
  2911. * */
  2912. public function getWebsiteJobApply(array $data): array
  2913. {
  2914. // 首先验证网站是否存在
  2915. // return Result::success($data);
  2916. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2917. if (empty($web)) {
  2918. return Result::error("该网站不存在", 0);
  2919. }
  2920. // 验证用户是否存在且为个人会员/管理员
  2921. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2922. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2923. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  2924. return Result::error("用户不存在", 0);
  2925. }
  2926. // 去除重复元素和空元素,并保持原始顺序
  2927. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  2928. return !empty($value);
  2929. }));
  2930. // 验证职位是否存在 1:审核通过
  2931. $recruiting = JobRecruiting::where('status', 1)
  2932. ->where('website_id', $data['website_id'])
  2933. ->whereIn('id', $data['recruit_id'])
  2934. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  2935. if (empty($recruiting)) {
  2936. return Result::error("该职位不存在", 0);
  2937. }
  2938. // 简历是否存在
  2939. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  2940. if (empty($hunt_id)) {
  2941. return Result::error("该简历不存在", 0);
  2942. }
  2943. $data['hunt_id'] = $hunt_id['hunt_id'];
  2944. // // 验证是否已投递过该职位
  2945. $apply = JobApply::where('user_id', $data['user_id'])
  2946. ->where('hunt_id', $data['hunt_id'])
  2947. ->where('website_id', $data['website_id'])
  2948. ->whereIn('recruit_id', $data['recruit_id'])
  2949. ->get(['recruit_id']);
  2950. if (!empty($apply->toArray())) {
  2951. return Result::error("您已投递过该职位!");
  2952. }
  2953. $insertData = array_map(function ($recruiting) use ($data) {
  2954. return [
  2955. 'user_id' => $data['user_id'],
  2956. 'hunt_id' => $data['hunt_id'],
  2957. 'website_id' => $data['website_id'],
  2958. 'recruit_id' => $recruiting['recruit_id'],
  2959. 'receiver_id' => $recruiting['receiver_id'],
  2960. 'status' => 1,
  2961. ];
  2962. }, $recruiting);
  2963. // 批量插入数据
  2964. $result = JobApply::insert($insertData);
  2965. if (empty($result)) {
  2966. return Result::error("投递失败", 0);
  2967. }
  2968. return Result::success($result);
  2969. }
  2970. /**
  2971. * 招工招聘-沟通简历
  2972. * @param array $data
  2973. * @return array
  2974. * */
  2975. public function getWebsiteJobResume(array $data): array
  2976. {
  2977. // 首先验证网站是否存在
  2978. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2979. if (empty($web)) {
  2980. return Result::error("该网站不存在", 0);
  2981. }
  2982. // return Result::success($data);
  2983. // 验证用户是否存在且为企业会员/管理员
  2984. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2985. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2986. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2987. return Result::error("用户不存在", 0);
  2988. }
  2989. // 去除重复元素和空元素,并保持原始顺序
  2990. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  2991. return !empty($value);
  2992. }));
  2993. // 验证简历是否存在
  2994. $hunting = JobHunting::where('status', 2)
  2995. ->where('website_id', $data['website_id'])
  2996. ->whereIn('id', $data['hunt_id'])
  2997. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  2998. if (empty($hunting)) {
  2999. return Result::error("该简历不存在", 0);
  3000. }
  3001. // 验证是否已沟通过该简历
  3002. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3003. ->where('recruit_id', $data['recruit_id'])
  3004. ->where('website_id', $data['website_id'])
  3005. ->whereIn('hunt_id', $data['hunt_id'])
  3006. ->get(['hunt_id']);
  3007. if (!empty($remuse->toArray())) {
  3008. return Result::error("您已沟通过该简历!");
  3009. }
  3010. // 准备要插入的数据数组
  3011. $insertData = array_map(function ($hunting) use ($data) {
  3012. return [
  3013. 'user_id' => $data['user_id'],
  3014. 'recruit_id' => $data['recruit_id'],
  3015. 'website_id' => $data['website_id'],
  3016. 'hunt_id' => $hunting['hunt_id'],
  3017. 'receiver_id' => $hunting['receiver_id'],
  3018. 'status' => 1,
  3019. ];
  3020. }, $hunting);
  3021. // 批量插入数据
  3022. $result = JobRemuse::insert($insertData);
  3023. if (empty($result)) {
  3024. return Result::error("沟通失败", 0);
  3025. }
  3026. return Result::success($result);
  3027. }
  3028. /**
  3029. * 招工招聘 -我的职位(企业会员)
  3030. * @param array $data
  3031. * @return array
  3032. */
  3033. public function getWebsiteJobRecruiting(array $data): array
  3034. {
  3035. $web = Website::where('id', $data['website_id'])->first('id');
  3036. if (empty($web)) {
  3037. return Result::error("该网站不存在", 0);
  3038. }
  3039. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3040. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3041. return Result::error("用户暂无权限!", 0);
  3042. }
  3043. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3044. $result = JobRecruiting::where('website_id', $data['website_id'])
  3045. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3046. $query->where('user_id', $user['id']);
  3047. })
  3048. ->where('status', 1)
  3049. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3050. ->orderBy('updated_at', 'desc')
  3051. ->limit($data['pageSize'])
  3052. ->get();
  3053. if (empty($result)) {
  3054. return Result::error("暂无相关职位信息", 0);
  3055. }
  3056. return Result::success($result);
  3057. }
  3058. /**
  3059. * c端 - 验证路由
  3060. * @param array $data
  3061. * @return array
  3062. */
  3063. /**
  3064. * c端 - 验证路由
  3065. * @param array $data
  3066. * @return array
  3067. */
  3068. public function checkWebsiteRoute(array $data): array
  3069. {
  3070. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3071. if (empty($web)) {
  3072. return Result::error("该网站不存在", 0);
  3073. }
  3074. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3075. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3076. if (empty($whiteRouterInfo)) {
  3077. return Result::error("非法路径地址", 0);
  3078. } else {
  3079. return Result::success($whiteRouterInfo->toArray());
  3080. }
  3081. } else {
  3082. // 验证栏目路由
  3083. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3084. ->where('aLIas_pinyin', $data['last_route'])
  3085. ->first();
  3086. if (empty($last_category)) {
  3087. return Result::error("该栏目不存在", 0);
  3088. }
  3089. if (isset($data['id']) && !empty($data['id'])) {
  3090. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3091. switch ($last_category['type']) {
  3092. case 1:
  3093. // 文章
  3094. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3095. $article = Article::where('status', 1)
  3096. ->where('id', $data['id'])
  3097. ->where(function ($query) use ($data) {
  3098. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3099. ->orWhereNull("ignore_ids");
  3100. })
  3101. ->first(['cat_arr_id']);
  3102. if (empty($article)) {
  3103. return Result::error("该文章不存在", 0);
  3104. }
  3105. // return Result::success($article);
  3106. break;
  3107. case 2:
  3108. // 商品
  3109. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3110. $article = Good::where('website_id', $data['website_id'])
  3111. ->where('status', 2)
  3112. ->where('id', $data['id'])
  3113. ->first(['cat_arr_id']);
  3114. if (empty($article)) {
  3115. return Result::error("该商品不存在", 0);
  3116. }
  3117. break;
  3118. case 3:
  3119. // 书刊信息
  3120. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3121. $article = Book::where('website_id', $data['website_id'])
  3122. ->where('status', 2)
  3123. ->where('id', $data['id'])
  3124. ->first(['id', 'cat_arr_id']);
  3125. if (empty($article)) {
  3126. return Result::error("该书刊不存在", 0);
  3127. }
  3128. break;
  3129. case 4:
  3130. // 招聘
  3131. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核;(只有企业会员需要审核)',
  3132. $article = JobRecruiting::where('website_id', $data['website_id'])
  3133. ->where('status', 1)
  3134. ->where('id', $data['id'])
  3135. ->first(['cat_arr_id']);
  3136. if (empty($article)) {
  3137. return Result::error("该招聘不存在", 0);
  3138. }
  3139. break;
  3140. case 5:
  3141. // 求职
  3142. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3143. $article = JobHunting::where('website_id', $data['website_id'])
  3144. ->where('status', 2)
  3145. ->where('id', $data['id'])
  3146. ->first(['cat_arr_id']);
  3147. if (empty($article)) {
  3148. return Result::error("该求职不存在", 0);
  3149. }
  3150. break;
  3151. case 6:
  3152. // 招工招聘
  3153. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3154. $article = JobRecruiting::where('website_id', $data['website_id'])
  3155. ->where('status', 1)
  3156. ->where('id', $data['id'])
  3157. ->first(['cat_arr_id']);
  3158. if (empty($article)) {
  3159. $article = JobHunting::where('website_id', $data['website_id'])
  3160. ->where('status', 2)
  3161. ->where('id', $data['id'])
  3162. ->first(['cat_arr_id']);
  3163. }
  3164. if (empty($article)) {
  3165. return Result::error("该招工招聘不存在", 0);
  3166. }
  3167. break;
  3168. default:
  3169. return Result::error("该数据不存在", 0);
  3170. break;
  3171. }
  3172. $catid = json_decode($article['cat_arr_id'], true);
  3173. if (empty($catid)) {
  3174. return Result::error("该数据不存在", 0);
  3175. }
  3176. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3177. ->orderByRaw('FIELD(category_id, ' . implode(',', $catid) . ')')
  3178. ->whereIn('category_id', $catid)
  3179. ->pluck('aLIas_pinyin')
  3180. ->implode('/');
  3181. }
  3182. if ($last_category['pid'] != 0) {
  3183. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3184. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3185. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr) . ')')
  3186. ->whereIn('category_id', $cat_arr)
  3187. ->pluck('aLIas_pinyin')
  3188. ->implode('/');
  3189. } else {
  3190. $pinyin = $last_category['aLIas_pinyin'];
  3191. }
  3192. if (empty($pinyin) || $pinyin != $data['all_route']) {
  3193. return Result::error('非法路径!');
  3194. } else {
  3195. return Result::success($pinyin);
  3196. }
  3197. }
  3198. }
  3199. /**
  3200. * 招工招聘 - 获取推荐职位
  3201. * @param array $data
  3202. * @return array
  3203. */
  3204. public function getWebsiteLevelJob(array $data): array
  3205. {
  3206. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3207. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3208. ->where('job_recruiting.status', 1)
  3209. ->where('job_level', $data['job_level'])
  3210. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3211. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3212. ->orderBy('job_recruiting.updated_at', 'desc')
  3213. ->limit($data['pageSize'])
  3214. ->get();
  3215. $web = ['website_id' => $data['website_id']];
  3216. if (!empty($job)) {
  3217. $result = $this->processJob($job, $web);
  3218. }
  3219. if (empty($result)) {
  3220. return Result::error("暂无相关职位信息", 0);
  3221. }
  3222. return Result::success($result);
  3223. }
  3224. /**
  3225. * 验证导航名称是否重复
  3226. * @return void
  3227. */
  3228. //20250226 产品列表
  3229. public function getGoodList(array $data): array
  3230. {
  3231. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3232. unset($data['type_id']);
  3233. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3234. $where = [];
  3235. if ($type_id != '10000') {
  3236. $where = [
  3237. 'good.user_id' => $user_id,
  3238. ];
  3239. }
  3240. //类型
  3241. if (isset($data['type_id']) && $data['type_id']) {
  3242. $where = [
  3243. 'type_id' => $data['type_id'],
  3244. ];
  3245. }
  3246. //名称
  3247. if (isset($data['name']) && $data['name']) {
  3248. $where = [
  3249. 'good.name' => $data['name'],
  3250. ];
  3251. }
  3252. //status
  3253. if (isset($data['status']) && $data['status'] != '') {
  3254. $where = [
  3255. 'good.status' => $data['status'],
  3256. ];
  3257. }
  3258. //status1
  3259. // if (isset($data['status1']) && $data['status1'] == 1) {
  3260. // $status1 = 1;
  3261. // }
  3262. $where1 = [];
  3263. //website_id
  3264. // if (isset($data['website_id']) && $data['website_id']) {
  3265. // $where1 = [
  3266. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3267. // ];
  3268. // }
  3269. // website_name
  3270. if (isset($data['website_name']) && $data['website_name']) {
  3271. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3272. }
  3273. // catid
  3274. if (isset($data['category_name']) && $data['category_name']) {
  3275. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3276. }
  3277. // $result = Good::where($where)
  3278. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3279. $result = Good::where($where)
  3280. ->when(!empty($where1), function ($query) use ($where1) {
  3281. return $query->where($where1);
  3282. })
  3283. //status 1待审核2已审核3已拒绝
  3284. ->when(isset($data['status1']), function ($query) {
  3285. return $query->whereIn('good.status', [1, 3]);
  3286. })
  3287. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3288. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3289. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3290. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3291. ->orderBy("updated_at", "desc")
  3292. ->limit($data['page_size'])
  3293. ->offset(($data['page'] - 1) * $data['page_size'])
  3294. ->get();
  3295. $count = Good::where($where)
  3296. ->when(!empty($where1), function ($query) use ($where1) {
  3297. return $query->where($where1);
  3298. })
  3299. //status 1待审核2已审核3已拒绝
  3300. ->when(isset($data['status1']), function ($query) {
  3301. return $query->whereIn('good.status', [1, 3]);
  3302. })
  3303. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3304. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3305. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3306. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3307. ->orderBy("updated_at", "desc")->count();
  3308. $data = [
  3309. 'rows' => $result->toArray(),
  3310. 'count' => $count,
  3311. ];
  3312. if (empty($result)) {
  3313. return Result::error("此栏目暂无相关产品", 0);
  3314. }
  3315. return Result::success($data);
  3316. }
  3317. public function getGoodInfo(array $data): array
  3318. {
  3319. $result = Good::where('id', $data['id'])->first();
  3320. if (empty($result)) {
  3321. return Result::error("此产品不存在", 0);
  3322. }
  3323. return Result::success($result);
  3324. }
  3325. public function addGood(array $data): array
  3326. {
  3327. // unset($data['city_arr_id']);
  3328. // unset($data['cat_arr_id']);
  3329. $data['city_id'] = end($data['city_arr_id']);
  3330. $data['catid'] = end($data['cat_arr_id']);
  3331. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3332. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3333. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3334. unset($data['imgUrl']);
  3335. if (isset($data['price']) && $data['price'] == '') {
  3336. $data['price'] = 0;
  3337. }
  3338. $result = Good::insert($data);
  3339. if (empty($result)) {
  3340. return Result::error("添加失败", 0);
  3341. }
  3342. return Result::success($result);
  3343. }
  3344. public function updateGood(array $data): array
  3345. {
  3346. $data['city_id'] = end($data['city_arr_id']);
  3347. $data['catid'] = end($data['cat_arr_id']);
  3348. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3349. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3350. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3351. //设置东八区
  3352. date_default_timezone_set('Asia/Shanghai');
  3353. $data['updated_at'] = date('Y-m-d H:i:s');
  3354. if (isset($data['price']) && $data['price'] == '') {
  3355. $data['price'] = 0;
  3356. }
  3357. $result = Good::where('id', $data['id'])->update($data);
  3358. if (empty($result)) {
  3359. return Result::error("更新失败", 0);
  3360. }
  3361. return Result::success($result);
  3362. }
  3363. public function delGood(array $data): array
  3364. {
  3365. $result = Good::where('id', $data['id'])->delete();
  3366. if (empty($result)) {
  3367. return Result::error("删除失败", 0);
  3368. }
  3369. return Result::success($result);
  3370. }
  3371. //20250226 产品列表
  3372. //20250306 求职信息
  3373. public function getJobHuntingList(array $data): array
  3374. {
  3375. $where = [];
  3376. if (isset($data['username']) && !empty($data['username'])) {
  3377. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3378. }
  3379. //status 1待审核2已审核3已拒绝
  3380. if (isset($data['status']) && $data['status'] != '') {
  3381. $where = [
  3382. 'job_hunting.status' => $data['status'],
  3383. ];
  3384. }
  3385. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3386. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3387. unset($data['type_id']);
  3388. if ($type_id != '10000') {
  3389. $where[] = ['job_hunting.user_id', '=', $user_id];
  3390. }
  3391. $result = JobHunting::where($where)
  3392. ->when(!empty($data['status1']), function ($query) use ($data) {
  3393. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3394. })
  3395. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3396. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3397. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3398. ->orderBy("updated_at", "desc")
  3399. ->limit($data['page_size'])
  3400. ->offset(($data['page'] - 1) * $data['page_size'])
  3401. ->get();
  3402. if (empty($result)) {
  3403. return Result::error("查询失败", 0);
  3404. }
  3405. $count = JobHunting::where($where)
  3406. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3407. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3408. ->count();
  3409. $data = [
  3410. 'rows' => $result->toArray(),
  3411. 'count' => $count,
  3412. ];
  3413. return Result::success($data);
  3414. }
  3415. public function getJobHuntingApply(array $data): array
  3416. {
  3417. var_dump($data, '-----------------test--------1-');
  3418. $where = [];
  3419. if (isset($data['username']) && !empty($data['username'])) {
  3420. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3421. }
  3422. if (isset($data['salary']) && !empty($data['salary'])) {
  3423. $where[] = [
  3424. 'job_hunting.salary',
  3425. '=',
  3426. $data['salary'],
  3427. ];
  3428. }
  3429. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3430. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3431. unset($data['type_id']);
  3432. if ($type_id != '10000') {
  3433. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3434. }
  3435. var_dump($where, '-----------------test---------');
  3436. $result = jobApply::where($where)
  3437. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3438. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3439. // })
  3440. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3441. ->where('job_enum.egroup', '=', 'income')
  3442. ->where('job_hunting.status', 2) //已审核
  3443. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3444. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3445. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3446. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3447. //职位----是申请职位
  3448. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3449. ->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')
  3450. ->orderBy("job_hunting.updated_at", "desc")
  3451. ->limit($data['page_size'])
  3452. ->offset(($data['page'] - 1) * $data['page_size'])
  3453. ->get();
  3454. if (empty($result)) {
  3455. return Result::error("查询失败", 0);
  3456. }
  3457. $count = jobApply::where($where)
  3458. ->where('job_enum.egroup', '=', 'income')
  3459. ->where('job_hunting.status', 2) //已审核
  3460. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3461. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3462. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3463. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3464. //职位----是申请职位
  3465. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3466. ->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')
  3467. ->count();
  3468. $data = [
  3469. 'rows' => $result->toArray(),
  3470. 'count' => $count,
  3471. ];
  3472. return Result::success($data);
  3473. }
  3474. public function addJobHunting(array $data): array
  3475. {
  3476. date_default_timezone_set('Asia/Shanghai');
  3477. unset($data['company_name']);
  3478. unset($data['job_industry']);
  3479. unset($data['job_name']);
  3480. unset($data['department']);
  3481. unset($data['job_timeList']);
  3482. unset($data['job_content']);
  3483. unset($data['job_typename']); //不知道这是啥,
  3484. $data['created_at'] = date('Y-m-d H:i:s');
  3485. $data['updated_at'] = date('Y-m-d H:i:s');
  3486. //根据用户 user_id 只能添加一次
  3487. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3488. if (!empty($result)) {
  3489. return Result::error("您已添加过求职信息", 0);
  3490. }
  3491. var_dump($result, '-----------------test---------');
  3492. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3493. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3494. $cityArr = json_decode($data['city_arr_id'], true);
  3495. $data['city_id'] = end($cityArr);
  3496. } else {
  3497. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3498. $data['city_id'] = end($data['city_arr_id']);
  3499. }
  3500. $result = JobHunting::create($data);
  3501. if (empty($result)) {
  3502. return Result::error("添加失败", 0);
  3503. }
  3504. return Result::success($result);
  3505. }
  3506. public function delJobHunting(array $data): array
  3507. {
  3508. $result = JobHunting::where('id', $data['id'])->delete();
  3509. if (empty($result)) {
  3510. return Result::error("删除失败", 0);
  3511. }
  3512. return Result::success($result);
  3513. }
  3514. public function updateJobHunting(array $data): array
  3515. {
  3516. //设置东八区
  3517. date_default_timezone_set('Asia/Shanghai');
  3518. unset($data['company_name']);
  3519. unset($data['job_industry']);
  3520. unset($data['job_name']);
  3521. unset($data['department']);
  3522. unset($data['job_timeList']);
  3523. unset($data['job_content']);
  3524. unset($data['job_typename']); //不知道这是啥,
  3525. $data['created_at'] = date('Y-m-d H:i:s');
  3526. $data['updated_at'] = date('Y-m-d H:i:s');
  3527. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3528. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3529. $cityArr = json_decode($data['city_arr_id'], true);
  3530. $data['city_id'] = end($cityArr);
  3531. } else {
  3532. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3533. $data['city_id'] = end($data['city_arr_id']);
  3534. }
  3535. $result = JobHunting::where('id', $data['id'])->update($data);
  3536. if (empty($result)) {
  3537. return Result::error("更新失败", 0);
  3538. }
  3539. return Result::success($result);
  3540. }
  3541. public function getJobHuntingInfo(array $data): array
  3542. {
  3543. $result = JobHunting::where('id', $data['id'])->first();
  3544. if (empty($result)) {
  3545. return Result::error("查询失败", 0);
  3546. }
  3547. return Result::success($result);
  3548. }
  3549. public function getJobHuntingData(array $data): array
  3550. {
  3551. $jobEnum = JobEnum::get();
  3552. $jobIndustry = JobIndustry::get();
  3553. $jobNature = JobNature::get();
  3554. $jobPosition = JobPosition::get();
  3555. $data = [
  3556. 'jobEnum' => $jobEnum,
  3557. 'jobIndustry' => $jobIndustry,
  3558. 'jobNature' => $jobNature,
  3559. 'jobPosition' => $jobPosition,
  3560. ];
  3561. return Result::success($data);
  3562. }
  3563. public function delJobHuntingInfo(array $data): array
  3564. {
  3565. $result = JobHunting::where('id', $data['id'])->delete();
  3566. return Result::success();
  3567. }
  3568. //20250324 通知,公告,消息
  3569. public function delNotice(array $data): array
  3570. {
  3571. $result = Notice::where('id', $data['id'])->delete();
  3572. if ($result) {
  3573. return Result::success();
  3574. } else {
  3575. return Result::error("删除失败", 0);
  3576. }
  3577. }
  3578. public function getNoticeInfo(array $data): array
  3579. {
  3580. $result = Notice::where('id', $data['id'])->first();
  3581. if (empty($result)) {
  3582. return Result::error("查询失败", 0);
  3583. }
  3584. return Result::success($result);
  3585. }
  3586. public function addNotice(array $data): array
  3587. {
  3588. date_default_timezone_set('Asia/Shanghai');
  3589. $data['created_at'] = date('Y-m-d H:i:s');
  3590. $data['updated_at'] = date('Y-m-d H:i:s');
  3591. $user_id = UserInfo::
  3592. //city_id不是null
  3593. whereNotNull('city_id')
  3594. ->whereNotNull('department_id')
  3595. ->where(function ($query) use ($data) {
  3596. $query->where(function ($subQuery) use ($data) {
  3597. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3598. });
  3599. })
  3600. ->where(function ($query) use ($data) {
  3601. $query->where(function ($subQuery) use ($data) {
  3602. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3603. });
  3604. })
  3605. ->pluck('user_id')->toArray();
  3606. $user_id = array_unique($user_id);
  3607. $chat_ids = $user_id;
  3608. $user_id = json_encode($user_id);
  3609. $data['re_user_ids'] = $user_id;
  3610. $result = Notice::insertGetId($data);
  3611. if ($result && $data['is_group'] == 1) {
  3612. //chat_group
  3613. $group_id = PublicData::uuid();
  3614. $groupData = [
  3615. 'id' => $group_id,
  3616. 'creator_id' => $data['user_id'],
  3617. 'group_name' => $data['group_name'] ?? '',
  3618. 'profile' => $data['profile'] ?? 0,
  3619. ];
  3620. var_dump($groupData, '-----------------groupData-------');
  3621. $groupResult = ChatGroups::insertGetId($groupData);
  3622. var_dump($groupResult, '-----------------groupid-------');
  3623. $groupMemberData = [
  3624. 'id' => PublicData::uuid(),
  3625. 'user_id' => $data['user_id'],
  3626. 'group_id' => $group_id,
  3627. 'leader' => 2,
  3628. ];
  3629. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  3630. //$chat_ids 去除掉$data['user_id']
  3631. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  3632. //插入群成员表
  3633. $groupMemberDataUser = [];
  3634. $chatData = [];
  3635. foreach ($chat_ids as $key => $value) {
  3636. $groupMemberDataUser[] = [
  3637. 'id' => PublicData::uuid(),
  3638. 'user_id' => $value,
  3639. 'group_id' => $group_id,
  3640. 'leader' => 1,
  3641. ];
  3642. $chatData[] = [
  3643. 'user_id' => $value,
  3644. 'msg_type' => 1,
  3645. 'receiver_id' => $group_id,
  3646. 'content' => '通过通知创建群聊',
  3647. 'group_receiver_id' => $data['user_id'],
  3648. 'action' => 'recieved',
  3649. 'created_at' => date('Y-m-d H:i:s'),
  3650. ];
  3651. }
  3652. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  3653. ChatGroupsMember::insert($groupMemberDataUser);
  3654. //插入一条管理员聊天记录
  3655. $chatData[] = [
  3656. 'user_id' => $data['user_id'],
  3657. 'msg_type' => 1,
  3658. 'receiver_id' => $group_id,
  3659. 'content' => '通过通知创建群聊',
  3660. 'group_receiver_id' => $data['user_id'],
  3661. 'action' => 'said',
  3662. 'created_at' => date('Y-m-d H:i:s'),
  3663. ];
  3664. var_dump($chatData, '-----------------chatData-------');
  3665. $chatResult = ChatRecords::insert($chatData);
  3666. //更新result的 group_id
  3667. $data['group_id'] = $group_id;
  3668. Notice::where(['id' => $result])->update($data);
  3669. }
  3670. if (empty($result)) {
  3671. return Result::error("添加失败", 0);
  3672. }
  3673. return Result::success($result);
  3674. }
  3675. public function updateNotice(array $data): array
  3676. {
  3677. date_default_timezone_set('Asia/Shanghai');
  3678. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  3679. $user_id = UserInfo::
  3680. //city_id不是null
  3681. whereNotNull('city_id')
  3682. ->whereNotNull('department_id')
  3683. ->where(function ($query) use ($data) {
  3684. $query->where(function ($subQuery) use ($data) {
  3685. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3686. });
  3687. })
  3688. ->where(function ($query) use ($data) {
  3689. $query->where(function ($subQuery) use ($data) {
  3690. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3691. });
  3692. })
  3693. ->pluck('user_id')->toArray();
  3694. $user_id = array_unique($user_id);
  3695. $user_id = json_encode($user_id);
  3696. $data['re_user_ids'] = $user_id;
  3697. $data['updated_at'] = date('Y-m-d H:i:s');
  3698. $result = Notice::where('id', $data['id'])->update($data);
  3699. return Result::success($result);
  3700. }
  3701. public function getNoticeList(array $data): array
  3702. {
  3703. $where = [];
  3704. //title
  3705. if (isset($data['title']) && !empty($data['title'])) {
  3706. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  3707. }
  3708. //level
  3709. if (isset($data['level']) && !empty($data['level'])) {
  3710. $where[] = ['notice.level', '=', $data['level']];
  3711. }
  3712. //status
  3713. if (isset($data['status']) && !empty($data['status'])) {
  3714. $where[] = ['notice.status', '=', $data['status']];
  3715. }
  3716. var_dump($data, '------------11111-2----test---------');
  3717. if ($data['type_id'] == 10000) {
  3718. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3719. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3720. })
  3721. ->where($where)
  3722. ->orderBy('updated_at', 'desc')
  3723. ->limit($data['page_size'])
  3724. ->offset(($data['page'] - 1) * $data['page_size'])
  3725. ->get();
  3726. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3727. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3728. })
  3729. ->where($where)
  3730. ->orderBy('updated_at', 'desc')
  3731. ->count();
  3732. } else {
  3733. $result = Notice::where($where)
  3734. // ->where('user_id', $data['user_id'])
  3735. ->Where(function ($query) use ($data) {
  3736. $query->Where(function ($q) use ($data) {
  3737. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3738. ->orWhere('notice.user_id', $data['user_id']);
  3739. });
  3740. })
  3741. ->when(!empty($data['status1']), function ($query) use ($data) {
  3742. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3743. })
  3744. ->orderBy('updated_at', 'desc')
  3745. ->limit($data['page_size'])
  3746. ->offset(($data['page'] - 1) * $data['page_size'])
  3747. ->get();
  3748. $total = Notice::where($where)
  3749. ->when(!empty($data['status1']), function ($query) use ($data) {
  3750. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3751. })
  3752. // ->where('user_id', $data['user_id'])
  3753. ->Where(function ($query) use ($data) {
  3754. $query->Where(function ($q) use ($data) {
  3755. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3756. ->orWhere('notice.user_id', $data['user_id']);
  3757. });
  3758. })
  3759. ->count();
  3760. }
  3761. if (empty($result)) {
  3762. return Result::error("查询失败", 0);
  3763. }
  3764. $data = [
  3765. 'rows' => $result,
  3766. 'count' => $total,
  3767. ];
  3768. return Result::success($data);
  3769. }
  3770. public function getNoticeDetail(array $data): array
  3771. {
  3772. $result = Notice::where('id', $data['id'])->first();
  3773. if (empty($result)) {
  3774. return Result::error("查询失败", 0);
  3775. }
  3776. return Result::success($result);
  3777. }
  3778. public function deleteNotice(array $data): array
  3779. {
  3780. $notice = Notice::where('id', $data['id'])->first();
  3781. if (empty($notice)) {
  3782. return Result::error("删除失败", 0);
  3783. }
  3784. $chat_group_id = $notice->group_id;
  3785. if ($chat_group_id) {
  3786. //删除群聊
  3787. ChatGroups::where('id', $chat_group_id)->delete();
  3788. //删除群成员
  3789. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  3790. //删除群聊记录
  3791. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  3792. }
  3793. $result = Notice::where('id', $data['id'])->delete();
  3794. return Result::success($result);
  3795. }
  3796. public function getMSG(array $data): array
  3797. {
  3798. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  3799. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3800. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  3801. $result = [];
  3802. if ($type_id == 1) {
  3803. //最近的5篇已审的文章
  3804. $apply_articale = Article::where('status', 1)
  3805. ->where('admin_user_id', $user_id)
  3806. ->orderBy('updated_at', 'desc')
  3807. ->limit(5)->get();
  3808. //获取5条单聊未读聊天消息
  3809. $chat = ChatRecords::where('is_read', 0)
  3810. ->where('user_id', $user_id)
  3811. ->where('talk_type', 1)
  3812. ->orderBy('created_at', 'desc')
  3813. ->limit(5)->get();
  3814. //获取5条未读群聊信息
  3815. $chat_group = ChatRecords::where('is_read', 0)
  3816. ->where('user_id', $user_id)
  3817. ->where('talk_type', 2)
  3818. ->orderBy('created_at', 'desc')
  3819. ->limit(5)->get();
  3820. //获取5条用户的已审核商品
  3821. $good = Good::where('status', 2)
  3822. ->where('user_id', $user_id)
  3823. ->orderBy('updated_at', 'desc')
  3824. ->limit(5)->get();
  3825. //获取5条用户待审核的公告
  3826. $notice = Notice::where('status', 2)
  3827. ->where('user_id', $user_id)
  3828. ->orderBy('updated_at', 'desc')
  3829. ->limit(5)->get();
  3830. //获取5条用户的待审核投诉
  3831. $complaint = Complaint::where('status', 2)
  3832. ->where('user_id', $user_id)
  3833. ->orderBy('updated_at', 'desc')
  3834. ->limit(5)->get();
  3835. //获取5条用户的book
  3836. $book = Book::where('status', 2)
  3837. ->where('user_id', $user_id)
  3838. ->orderBy('updated_at', 'desc')
  3839. ->limit(5)->get();
  3840. //获取5条用户的求职
  3841. //获取5条用户的求职 1
  3842. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3843. ->where('job_hunting.user_id', $user_id)
  3844. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3845. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3846. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3847. ->orderBy('updated_at', 'desc')
  3848. ->limit(5)->get();
  3849. //获取5条用户的求职 2
  3850. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3851. ->where('job_recruiting.user_id', $user_id)
  3852. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3853. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3854. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3855. ->orderBy('updated_at', 'desc')
  3856. ->limit(5)->get();
  3857. //人才库 1
  3858. $job_apply = JobApply::where('job_apply.status', 1)
  3859. ->where('job_apply.receiver_id', $user_id)
  3860. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3861. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3862. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3863. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3864. ->select('job_recruiting', 'job_recruiting.', '', '')
  3865. ->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')
  3866. ->orderBy('updated_at', 'desc')
  3867. ->limit(5)->get();
  3868. // 职场机会 2
  3869. $job_resume = JobResume::where('job_resume.status', 1)
  3870. ->where('job_resume.receiver_id', $user_id)
  3871. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3872. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3873. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3874. ->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')
  3875. ->orderBy('updated_at', 'desc')
  3876. ->limit(5)->get();
  3877. // count($chat) + count($chat_group) +
  3878. $count = count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  3879. $result = [
  3880. 'apply_articale' => $apply_articale,
  3881. 'chat' => $chat,
  3882. 'chat_group' => $chat_group,
  3883. 'good' => $good,
  3884. 'notice' => $notice,
  3885. 'complaint' => $complaint,
  3886. 'book' => $book,
  3887. 'job_hunting' => $job_hunting,
  3888. 'job_recruiting' => $job_recruiting,
  3889. 'job_apply' => $job_apply,
  3890. 'job_resume' => $job_resume,
  3891. 'count' => $count,
  3892. ];
  3893. } elseif ($type_id == 2) {
  3894. //最近的5篇已审的文章
  3895. $apply_articale = Article::where('status', 1)
  3896. ->where('admin_user_id', $user_id)
  3897. ->limit(5)->get();
  3898. //获取5条单聊未读聊天消息
  3899. $chat = ChatRecords::where('is_read', 0)
  3900. ->where('user_id', $user_id)
  3901. ->where('talk_type', 1)
  3902. ->orderBy('created_at', 'desc')
  3903. ->limit(5)->get();
  3904. //获取5条未读群聊信息
  3905. $chat_group = ChatRecords::where('is_read', 0)
  3906. ->where('user_id', $user_id)
  3907. ->where('talk_type', 2)
  3908. ->orderBy('created_at', 'desc')
  3909. ->limit(5)->get();
  3910. //获取5条用户的已审核商品
  3911. $good = Good::where('status', 2)
  3912. ->where('user_id', $user_id)
  3913. ->orderBy('updated_at', 'desc')
  3914. ->limit(5)->get();
  3915. //count($chat) + count($chat_group)
  3916. $count = count($apply_articale) + count($good);
  3917. $result = [
  3918. 'apply_articale' => $apply_articale,
  3919. 'chat' => $chat,
  3920. 'chat_group' => $chat_group,
  3921. 'good' => $good,
  3922. 'count' => $count,
  3923. ];
  3924. } elseif ($type_id == 3) {
  3925. //最近的5篇已审的文章
  3926. $apply_articale = Article::where('status', 1)
  3927. ->where('admin_user_id', $user_id)
  3928. ->limit(5)->get();
  3929. //获取5条单聊未读聊天消息
  3930. $chat = ChatRecords::where('is_read', 0)
  3931. ->where('user_id', $user_id)
  3932. ->where('talk_type', 1)
  3933. ->orderBy('created_at', 'desc')
  3934. ->limit(5)->get();
  3935. //获取5条未读群聊信息
  3936. $chat_group = ChatRecords::where('is_read', 0)
  3937. ->where('user_id', $user_id)
  3938. ->where('talk_type', 2)
  3939. ->orderBy('created_at', 'desc')
  3940. ->limit(5)->get();
  3941. //获取5条用户的已审核商品
  3942. $good = Good::where('status', 2)
  3943. ->where('user_id', $user_id)
  3944. ->orderBy('updated_at', 'desc')
  3945. ->limit(5)->get();
  3946. //count($chat) + count($chat_group) +
  3947. $count = count($apply_articale) + count($good);
  3948. $result = [
  3949. 'apply_articale' => $apply_articale,
  3950. 'chat' => $chat,
  3951. 'chat_group' => $chat_group,
  3952. 'good' => $good,
  3953. 'count' => $count,
  3954. ];
  3955. } elseif ($type_id == 4) {
  3956. //最近的5篇已审的文章
  3957. $apply_articale = Article::where('status', 1)
  3958. ->where('admin_user_id', $user_id)
  3959. ->limit(5)->get();
  3960. //获取5条用户的已审核商品
  3961. $good = Good::where('status', 2)
  3962. ->where('user_id', $user_id)
  3963. ->orderBy('updated_at', 'desc')
  3964. ->limit(5)->get();
  3965. $count = count($apply_articale) + count($good);
  3966. $result = [
  3967. 'apply_articale' => $apply_articale,
  3968. 'chat' => '',
  3969. 'chat_group' => '',
  3970. 'good' => $good,
  3971. 'count' => $count,
  3972. ];
  3973. } elseif ($type_id == 10000) {
  3974. //获取未审核的5篇文章
  3975. $apply_articale = Article::where('status', 0)
  3976. ->orderBy('updated_at', 'desc')
  3977. ->limit(5)->get();
  3978. //获取5条单聊未读聊天消息
  3979. $chat = ChatRecords::where('is_read', 0)
  3980. ->where('user_id', $user_id)
  3981. ->where('talk_type', 1)
  3982. ->orderBy('created_at', 'desc')
  3983. ->limit(5)->get();
  3984. //获取5条未读群聊信息
  3985. $chat_group = ChatRecords::where('is_read', 0)
  3986. ->where('user_id', $user_id)
  3987. ->where('talk_type', 2)
  3988. ->orderBy('created_at', 'desc')
  3989. ->limit(5)->get();
  3990. //获取5条用户的已审核商品
  3991. $good = Good::where('status', 1)
  3992. // ->where('user_id', $user_id)
  3993. ->orderBy('updated_at', 'desc')
  3994. ->limit(5)->get();
  3995. //获取5条用户待审核的公告
  3996. $notice = Notice::where('status', 1)
  3997. ->orderBy('updated_at', 'desc')
  3998. ->limit(5)->get();
  3999. //获取5条用户的待审核投诉
  4000. $complaint = Complaint::where('status', 1)
  4001. ->orderBy('updated_at', 'desc')
  4002. ->limit(5)->get();
  4003. //获取5条用户的book
  4004. $book = Book::where('status', 1)
  4005. ->orderBy('updated_at', 'desc')
  4006. ->limit(5)->get();
  4007. //获取5条用户的求职 1
  4008. $job_hunting = JobHunting::where('job_hunting.status', 1)
  4009. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4010. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  4011. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  4012. ->orderBy('updated_at', 'desc')
  4013. ->limit(5)->get();
  4014. //获取5条用户的求职 2
  4015. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  4016. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4017. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4018. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  4019. ->orderBy('updated_at', 'desc')
  4020. ->limit(5)->get();
  4021. //人才库 1
  4022. $job_apply = JobApply::where('job_apply.status', 1)
  4023. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  4024. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  4025. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  4026. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  4027. ->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')
  4028. ->orderBy('updated_at', 'desc')
  4029. ->limit(5)->get();
  4030. // 职场机会 2
  4031. $job_resume = JobResume::where('job_resume.status', 1)
  4032. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  4033. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  4034. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  4035. ->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')
  4036. ->orderBy('updated_at', 'desc')
  4037. ->limit(5)->get();
  4038. $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);
  4039. $result = [
  4040. 'apply_articale' => $apply_articale,
  4041. 'chat' => $chat,
  4042. 'chat_group' => $chat_group,
  4043. 'good' => $good,
  4044. 'notice' => $notice,
  4045. 'complaint' => $complaint,
  4046. 'book' => $book,
  4047. 'job_hunting' => $job_hunting,
  4048. 'job_recruiting' => $job_recruiting,
  4049. 'job_apply' => $job_apply,
  4050. 'job_resume' => $job_resume,
  4051. 'count' => $count,
  4052. ];
  4053. } elseif ($type_id == 20000) {
  4054. }
  4055. var_dump($type_id, '-----------------test---------');
  4056. return Result::success($result);
  4057. }
  4058. public function getComplaintList(array $data): array
  4059. {
  4060. var_dump($data, '00000001000000000000');
  4061. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4062. unset($data['type_id']);
  4063. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4064. $where = [];
  4065. if ($type_id != 10000 && empty($data['deal_user'])) {
  4066. $where['complaint.user_id'] = $user_id;
  4067. }
  4068. if (!empty($data['title'])) {
  4069. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4070. }
  4071. if (!empty($data['department_id'])) {
  4072. $where['complaint.department_id'] = $data['department_id'];
  4073. }
  4074. if (!empty($data['deal'])) {
  4075. $where['complaint.deal'] = $data['deal'];
  4076. }
  4077. if (!empty($data['status'])) {
  4078. $where['complaint.status'] = $data['status'];
  4079. }
  4080. var_dump(!empty($data['deal_user']), '----------1');
  4081. var_dump($where, '----------2');
  4082. $result = Complaint::where($where)
  4083. ->when(!empty($data['status1']), function ($query) use ($data) {
  4084. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4085. })
  4086. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4087. //json re_user_ids data[user_id]是不是在里面
  4088. $query->Where(function ($q) use ($data) {
  4089. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4090. ->where('complaint.status', 2);
  4091. });
  4092. })
  4093. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4094. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4095. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4096. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4097. ->orderBy('updated_at', 'desc')
  4098. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4099. //sql输出
  4100. if (empty($result)) {
  4101. return Result::error("暂无投诉信息", 0);
  4102. }
  4103. // 取出数据
  4104. $rows = $result->items();
  4105. $count = $result->total();
  4106. $responseData = [
  4107. 'rows' => $rows,
  4108. 'count' => $count,
  4109. ];
  4110. return Result::success($responseData);
  4111. }
  4112. public function getComplaintInfo(array $data): array
  4113. {
  4114. $result = Complaint::where('id', $data['id'])->first();
  4115. if (empty($result)) {
  4116. return Result::error("查询失败", 0);
  4117. }
  4118. return Result::success($result);
  4119. }
  4120. public function addComplaint(array $data): array
  4121. {
  4122. date_default_timezone_set('Asia/Shanghai');
  4123. $data['created_at'] = date('Y-m-d H:i:s');
  4124. $data['updated_at'] = date('Y-m-d H:i:s');
  4125. $result = Complaint::create($data);
  4126. return Result::success($result);
  4127. }
  4128. public function updateComplaint(array $data): array
  4129. {
  4130. date_default_timezone_set('Asia/Shanghai');
  4131. $data['updated_at'] = date('Y-m-d H:i:s');
  4132. $user_id = $data['user_id'] ?? 0;
  4133. $type_id = $data['type_id'] ?? 0;
  4134. unset($data['user_id']);
  4135. unset($data['type_id']);
  4136. $result = Complaint::where('id', $data['id'])->update($data);
  4137. return Result::success($result);
  4138. }
  4139. public function deleteComplaint(array $data): array
  4140. {
  4141. $result = Complaint::where('id', $data['id'])->delete();
  4142. return Result::success($result);
  4143. }
  4144. public function getComplainInfo(array $data): array
  4145. {
  4146. $result = Complaint::where('id', $data['id'])->first();
  4147. if (empty($result)) {
  4148. return Result::error("查询失败", 0);
  4149. }
  4150. return Result::success($result);
  4151. }
  4152. public function updateComplaintStatus(array $data): array
  4153. {
  4154. date_default_timezone_set('Asia/Shanghai');
  4155. $data['updated_at'] = date('Y-m-d H:i:s');
  4156. $user_id = $data['user_id'] ?? 0;
  4157. $type_id = $data['type_id'] ?? 0;
  4158. unset($data['user_id']);
  4159. unset($data['type_id']);
  4160. //处理, 写入处理人
  4161. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4162. $data['real_deal_user'] = $user_id;
  4163. }
  4164. //如果是deal 23,则判断是不是处理人
  4165. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4166. $complaintInof = Complaint::where('id', $data['id'])
  4167. ->where('real_deal_user', $user_id)
  4168. ->first();
  4169. if (empty($complaintInof)) {
  4170. return Result::error("处理人错误", 0);
  4171. }
  4172. }
  4173. $result = complaint::where('id', $data['id'])->update($data);
  4174. return Result::success($result);
  4175. }
  4176. public function updateGoodStatus(array $data): array
  4177. {
  4178. $user_id = $data['user_id'] ?? 0;
  4179. $type_id = $data['type_id'] ?? 0;
  4180. unset($data['user_id']);
  4181. unset($data['type_id']);
  4182. $result = Good::where('id', $data['id'])->update($data);
  4183. return Result::success($result);
  4184. }
  4185. public function updateJobHuntingStatus(array $data): array
  4186. {
  4187. $user_id = $data['user_id'] ?? 0;
  4188. $type_id = $data['type_id'] ?? 0;
  4189. unset($data['user_id']);
  4190. unset($data['type_id']);
  4191. $result = JobHunting::where('id', $data['id'])->update($data);
  4192. return Result::success($result);
  4193. }
  4194. public function updateNoticeStatus(array $data): array
  4195. {
  4196. $user_id = $data['user_id'] ?? 0;
  4197. $type_id = $data['type_id'] ?? 0;
  4198. unset($data['user_id']);
  4199. unset($data['type_id']);
  4200. $result = Notice::where('id', $data['id'])->update($data);
  4201. return Result::success($result);
  4202. }
  4203. public function getDUser(array $data): array
  4204. {
  4205. if (!empty($data['ids'])) {
  4206. $user = User::whereIn('id', $data['ids'])->getall();
  4207. if (empty($user)) {
  4208. return Result::error('无数据', 0);
  4209. }
  4210. return Result::success($user);
  4211. }
  4212. $where = [];
  4213. if (!empty($data['department_id'])) {
  4214. $where['department_id'] = $data['department_id'];
  4215. }
  4216. if (!empty($data['city_id'])) {
  4217. $where['city_id'] = $data['city_id'];
  4218. }
  4219. $result = User::where('type_id', 2)
  4220. ->where('status', 1)
  4221. ->where($where)
  4222. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4223. ->get();
  4224. if (empty($result)) {
  4225. return Result::error("查询失败", 0);
  4226. }
  4227. return Result::success($result);
  4228. }
  4229. /**
  4230. * 验证导航名称是否重复
  4231. * @return void
  4232. */
  4233. public function checkCategoryName(array $data): array
  4234. {
  4235. $result = Category::when($data, function ($query) use ($data) {
  4236. if (isset($data['name']) && $data['name']) {
  4237. $query->where("name", $data['name']);
  4238. }
  4239. if (isset($data['id']) && $data['id']) {
  4240. $query->where("id", "!=", $data['id']);
  4241. }
  4242. })->first();
  4243. if ($result) {
  4244. return Result::error("已存在");
  4245. } else {
  4246. return Result::success();
  4247. }
  4248. }
  4249. //20250226 产品列表
  4250. // 20250306 -------招聘--------fr
  4251. /*
  4252. * 招聘列表
  4253. * */
  4254. public function getJobRecruitingList(array $data): array
  4255. {
  4256. $where = [];
  4257. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4258. if ($data['checkout'] == 0) {
  4259. $job_status = [0, 2];
  4260. } else {
  4261. $job_status = [1];
  4262. }
  4263. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4264. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4265. }
  4266. $user = User::where('id', $data['user_id'])->first();
  4267. if (empty($user)) {
  4268. return Result::error("用户不存在", 0);
  4269. }
  4270. // 3:企业会员
  4271. if ($user['type_id'] == 3) {
  4272. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4273. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4274. }
  4275. // 如果 $where 为空,则不添加 where 条件
  4276. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4277. return $query->where($where);
  4278. })
  4279. ->whereIn('job_recruiting.status', $job_status)
  4280. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4281. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4282. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4283. ->orderBy("updated_at", "desc")
  4284. ->offset(($data['page'] - 1) * $data['page_size'])
  4285. ->limit($data['page_size'])
  4286. ->get()
  4287. ->all();
  4288. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4289. return $query->where($where);
  4290. })
  4291. ->whereIn('job_recruiting.status', $job_status)
  4292. ->count();
  4293. if (empty($result)) {
  4294. return Result::error("暂无招聘信息", 0);
  4295. }
  4296. return Result::success($result);
  4297. }
  4298. /*
  4299. * 招聘信息添加
  4300. * */
  4301. public function addJobRecruiting(array $data): array
  4302. {
  4303. // return Result::success($data);
  4304. $user = User::where('user.id', $data['user_id'])
  4305. ->where('user.status', 1)
  4306. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4307. ->select(
  4308. 'user.type_id',
  4309. 'user.mobile',
  4310. 'user.email',
  4311. 'user_info.business_name',
  4312. 'user_info.company_hy_id',
  4313. 'user_info.company_nature',
  4314. 'user_info.company_size',
  4315. 'user_info.introduction',
  4316. 'user_info.real_name',
  4317. 'user_info.company_url',
  4318. 'user_info.address_arr_id',
  4319. 'user_info.address'
  4320. )
  4321. ->first();
  4322. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4323. return Result::error("用户不存在", 0);
  4324. }
  4325. $web = Website::where('id', $data['website_id'])->first();
  4326. if (empty($web)) {
  4327. return Result::error("网站不存在", 0);
  4328. }
  4329. // return Result::success($user);
  4330. $data['action_id'] = $data['user_id'];
  4331. $data['user_type'] = $user['type_id'];
  4332. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4333. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4334. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4335. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4336. // 公司地址 管理员必填
  4337. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4338. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4339. // 管理员-企业相关信息
  4340. $company = [
  4341. // 'user_id' => $data['user_id']?? null,
  4342. 'business_name' => $data['business_name'] ?? null,
  4343. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4344. 'company_size' => $data['company_size'] ?? null,
  4345. 'company_nature' => $data['company_nature'] ?? null,
  4346. 'introduction' => $data['introduction'] ?? null,
  4347. 'real_name' => $data['real_name'] ?? null,
  4348. 'mobile' => $data['mobile'] ?? null,
  4349. 'company_url' => $data['company_url'] ?? null,
  4350. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4351. 'address' => $data['address'] ?? null,
  4352. 'email' => $data['email'] ?? null,
  4353. ];
  4354. //去掉相关企业信息
  4355. $job = array_diff_key($data, array_flip(array_keys($company)));
  4356. Db::beginTransaction();
  4357. try {
  4358. // 先添加职位相关信息
  4359. if ($user['type_id'] == 10000) {
  4360. $job['status'] = 1;
  4361. }
  4362. if (empty($data['experience']) || $data['experience'] == '') {
  4363. $job['experience'] = null;
  4364. } else {
  4365. $job['experience'] = $data['experience'];
  4366. }
  4367. $jobId = JobRecruiting::insertGetId($job);
  4368. if (empty($jobId)) {
  4369. Db::rollBack();
  4370. return Result::error("添加失败");
  4371. }
  4372. // 添加公司信息
  4373. $company['user_id'] = $data['user_id'] ?? null;
  4374. $company['job_id'] = $jobId;
  4375. $company['user_type'] = $user['type_id'] ?? null;
  4376. $company['website_id'] = $data['website_id'] ?? null;
  4377. if ($user['type_id'] == 10000) {
  4378. // 管理员添加企业信息
  4379. // return Result::success($company);
  4380. $companyId = JobCompany::insertGetId($company);
  4381. if (empty($companyId)) {
  4382. Db::rollBack();
  4383. return Result::error("添加失败");
  4384. }
  4385. } else {
  4386. // 企业会员添加企业信息
  4387. $company = [
  4388. 'user_id' => $data['user_id'] ?? null,
  4389. 'business_name' => $user['business_name'] ?? null,
  4390. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4391. 'company_size' => $user['company_size'] ?? null,
  4392. 'company_nature' => $user['company_nature'] ?? null,
  4393. 'introduction' => $user['introduction'] ?? null,
  4394. 'real_name' => $user['real_name'] ?? null,
  4395. 'mobile' => $user['mobile'] ?? null,
  4396. 'company_url' => $user['company_url'] ?? null,
  4397. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4398. 'address' => $user['address'] ?? null,
  4399. 'email' => $user['email'] ?? null,
  4400. 'website_id' => $data['website_id'] ?? null,
  4401. 'user_type' => $user['type_id'] ?? null,
  4402. 'job_id' => $jobId,
  4403. ];
  4404. $companyId = JobCompany::insertGetId($company);
  4405. if (empty($companyId)) {
  4406. Db::rollBack();
  4407. return Result::error("添加失败");
  4408. }
  4409. // return Result::success($company);
  4410. }
  4411. Db::commit();
  4412. } catch (\Exception $e) {
  4413. Db::rollBack();
  4414. return Result::error($e->getMessage(), 0);
  4415. }
  4416. $result = [
  4417. 'job_id' => $jobId,
  4418. 'company_id' => $companyId,
  4419. ];
  4420. if (empty($result)) {
  4421. return Result::error("添加失败", 0);
  4422. }
  4423. return Result::success($result);
  4424. }
  4425. /*
  4426. * 获取招聘信息详情
  4427. * */
  4428. public function getJobRecruitingInfo(array $data): array
  4429. {
  4430. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4431. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4432. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4433. ->select(
  4434. 'job_recruiting.*',
  4435. 'website.website_name as website_name',
  4436. 'job_company.business_name',
  4437. 'job_company.company_hy_id',
  4438. 'job_company.company_size',
  4439. 'job_company.company_nature',
  4440. 'job_company.introduction',
  4441. 'job_company.real_name',
  4442. 'job_company.mobile',
  4443. 'job_company.company_url',
  4444. 'job_company.address_arr_id',
  4445. 'job_company.address',
  4446. 'job_company.email'
  4447. )
  4448. ->first();
  4449. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4450. if (!empty($cityId)) {
  4451. if (isset($cityId[1]) && $cityId[1] != null) {
  4452. $city = District::where('id', $cityId[1])->first(['name']);
  4453. } else {
  4454. $city = District::where('id', $cityId[0])->first(['name']);
  4455. }
  4456. $result['city'] = $city['name'] ?? '';
  4457. }
  4458. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4459. if (is_array($addressId) && !empty($addressId)) {
  4460. $address = District::whereIn('id', $addressId)
  4461. ->orderBy('level', 'asc')
  4462. ->get(['name'])
  4463. ->pluck('name')
  4464. ->implode('');
  4465. // $job->address_name = $address ?? '';
  4466. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4467. }
  4468. if (empty($result)) {
  4469. return Result::error("招聘信息不存在", 0);
  4470. }
  4471. // return Result::success($job);
  4472. return Result::success($result);
  4473. }
  4474. /*
  4475. * 修改招聘信息
  4476. * */
  4477. public function upJobRecruiting(array $data): array
  4478. {
  4479. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4480. // return Result::success($job);
  4481. if (empty($job)) {
  4482. return Result::error("招聘信息不存在", 0);
  4483. }
  4484. $user = User::where('id', $data['user_id'])->first();
  4485. // return Result::success($user);
  4486. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4487. return Result::error("用户不存在", 0);
  4488. }
  4489. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4490. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4491. }
  4492. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4493. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4494. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4495. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4496. // 公司地址 管理员必填
  4497. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4498. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4499. // 管理员-企业相关信息
  4500. $company = [
  4501. 'business_name' => $data['business_name'] ?? null,
  4502. 'company_hy_id' => $data['hy_id'] ?? null,
  4503. 'company_size' => $data['company_size'] ?? null,
  4504. 'company_nature' => $data['company_nature'] ?? null,
  4505. 'introduction' => $data['introduction'] ?? null,
  4506. 'real_name' => $data['real_name'] ?? null,
  4507. 'mobile' => $data['mobile'] ?? null,
  4508. 'company_url' => $data['company_url'] ?? null,
  4509. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4510. 'address' => $data['address'] ?? null,
  4511. 'email' => $data['email'] ?? null,
  4512. ];
  4513. //去掉相关企业信息
  4514. $data = array_diff_key($data, array_flip(array_keys($company)));
  4515. $jobId = $data['id'];
  4516. $web = $data['website_id'];
  4517. $data['action_id'] = $data['user_id'];
  4518. unset($data['user_id']);
  4519. unset($data['user_type']);
  4520. unset($data['id']);
  4521. unset($data['website_id']);
  4522. // return Result::success($data);
  4523. Db::beginTransaction();
  4524. try {
  4525. // 管理员修改招聘信息
  4526. if ($user['type_id'] == 10000) {
  4527. $data['website_id'] = $web;
  4528. $company['website_id'] = $data['website_id'];
  4529. $data['status'] = 1;
  4530. } else {
  4531. $data['status'] = 0;
  4532. }
  4533. if (empty($data['experience']) || $data['experience'] == '') {
  4534. $job['experience'] = null;
  4535. } else {
  4536. $job['experience'] = $data['experience'];
  4537. }
  4538. // Db::rollBack();
  4539. // return Result::success($company);
  4540. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4541. if (empty($result['job'])) {
  4542. Db::rollBack();
  4543. return Result::error("修改招聘信息失败");
  4544. }
  4545. // 管理员修改企业相关信息
  4546. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4547. if (empty($result['company'])) {
  4548. Db::rollBack();
  4549. return Result::error("修改企业相关信息失败");
  4550. }
  4551. Db::commit();
  4552. // return Result::success($result);
  4553. } catch (\Exception $e) {
  4554. Db::rollBack();
  4555. return Result::error($e->getMessage(), 0);
  4556. }
  4557. return Result::success($result);
  4558. }
  4559. /*
  4560. * 招聘信息删除
  4561. * */
  4562. public function delJobRecruiting(array $data): array
  4563. {
  4564. $user = User::where('id', $data['user_id'])->first();
  4565. if (empty($user)) {
  4566. return Result::error("用户不存在", 0);
  4567. }
  4568. $job = JobRecruiting::where('id', $data['id'])->first();
  4569. if (empty($job)) {
  4570. return Result::error("招聘信息不存在", 0);
  4571. }
  4572. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4573. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4574. }
  4575. Db::beginTransaction();
  4576. try {
  4577. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4578. if (empty($result['job'])) {
  4579. Db::rollBack();
  4580. return Result::error("删除招聘信息失败");
  4581. }
  4582. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4583. if (empty($result['company'])) {
  4584. Db::rollBack();
  4585. return Result::error("删除企业相关信息失败");
  4586. }
  4587. Db::commit();
  4588. } catch (\Exception $e) {
  4589. Db::rollBack();
  4590. return Result::error($e->getMessage(), 0);
  4591. }
  4592. return Result::success($result);
  4593. }
  4594. /*
  4595. * 获取公司信息
  4596. * */
  4597. public function getJobCompany(array $data): array
  4598. {
  4599. $user = User::where('user.id', $data['user_id'])
  4600. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4601. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4602. ->first();
  4603. // return Result::success($user);
  4604. if (empty($user)) {
  4605. return Result::error("用户不存在", 0);
  4606. }
  4607. if ($user['type_id'] == 3) {
  4608. $result = [
  4609. // 'id' => 0,
  4610. 'user_id' => $data['user_id'],
  4611. 'website_id' => $data['website_id'],
  4612. 'business_name' => $user['business_name'], // 企业名称
  4613. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4614. 'company_nature' => $user['company_nature'], // 公司性质
  4615. 'company_size' => $user['company_size'], // 公司规模
  4616. 'introduction' => $user['introduction'], // 公司简介
  4617. 'real_name' => $user['real_name'], // 企业联系人
  4618. 'mobile' => $user['mobile'], // 企业联系电话
  4619. 'company_url' => $user['company_url'], // 企业网址
  4620. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4621. 'address' => $user['address'], // 企业地址
  4622. 'email' => $user['email'], // 企业邮箱
  4623. ];
  4624. } else {
  4625. return Result::error("用户类型错误", 0);
  4626. }
  4627. if (empty($result)) {
  4628. return Result::error("公司信息不存在", 0);
  4629. }
  4630. return Result::success($result);
  4631. }
  4632. /*
  4633. * 修改公司信息
  4634. * */
  4635. public function upJobCompany(array $data): array
  4636. {
  4637. // return Result::success($data);
  4638. $user = User::where('user.id', $data['user_id'])
  4639. ->where('user.status', 1)
  4640. ->select('user.user_name', 'user.type_id')
  4641. ->first();
  4642. if (empty($user)) {
  4643. return Result::error("用户不存在", 0);
  4644. }
  4645. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4646. $company = [
  4647. 'business_name' => $data['business_name'], // 企业名称
  4648. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4649. 'company_nature' => $data['company_nature'], // 公司性质
  4650. 'company_size' => $data['company_size'], // 公司规模
  4651. 'introduction' => $data['introduction'], // 公司简介
  4652. // 'real_name' => $data['real_name'], // 企业联系人
  4653. 'company_url' => $data['company_url'], // 企业网址
  4654. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4655. 'address' => $data['address'], // 企业详细地址
  4656. ];
  4657. if ($user['type_id'] == 3) {
  4658. Db::beginTransaction();
  4659. try {
  4660. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  4661. 'business_name' => $data['business_name'], // 企业名称
  4662. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4663. 'company_nature' => $data['company_nature'], // 公司性质
  4664. 'company_size' => $data['company_size'], // 公司规模
  4665. 'introduction' => $data['introduction'], // 公司简介
  4666. // 'real_name' => $data['real_name'], // 企业联系人
  4667. 'company_url' => $data['company_url'], // 企业网址
  4668. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4669. 'address' => $data['address'], // 企业详细地址
  4670. ]);
  4671. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  4672. Db::commit();
  4673. } catch (\Exception $e) {
  4674. Db::rollBack();
  4675. return Result::error($e->getMessage(), 0);
  4676. }
  4677. } else {
  4678. return Result::error("用户类型错误", 0);
  4679. }
  4680. if (empty($result)) {
  4681. return Result::error("修改失败", 0);
  4682. }
  4683. return Result::success($result);
  4684. }
  4685. /*
  4686. * 获取省-市
  4687. * */
  4688. public function getJobRecruitingArea(array $data): array
  4689. {
  4690. if (isset($data['pid']) && $data['pid'] != null) {
  4691. $result = District::where('pid', $data['pid'])->get()->all();
  4692. } else {
  4693. $result = District::where('level', 1)->get()->all();
  4694. }
  4695. if (empty($result)) {
  4696. return Result::error("暂无此省市", 0);
  4697. }
  4698. return Result::success($result);
  4699. }
  4700. /*
  4701. * 获取行业分类
  4702. * */
  4703. public function getIndustry(array $data): array
  4704. {
  4705. $result = JobIndustry::get()->all();
  4706. if (empty($result)) {
  4707. return Result::error("暂无行业分类", 0);
  4708. }
  4709. return Result::success($result);
  4710. }
  4711. /*
  4712. * 获取职位
  4713. * */
  4714. public function getPositionList(array $data): array
  4715. {
  4716. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  4717. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  4718. } else {
  4719. $result = JobPosition::where('zwpid', 0)->get()->all();
  4720. }
  4721. if (empty($result)) {
  4722. return Result::error("暂无此职位", 0);
  4723. }
  4724. return Result::success($result);
  4725. }
  4726. /*
  4727. * 获取工作性质-菜单
  4728. * */
  4729. public function getJobNature(array $data): array
  4730. {
  4731. $result = JobEnum::where('egroup', 'nature')->get()->all();
  4732. if (empty($result)) {
  4733. return Result::error("暂无工作性质", 0);
  4734. }
  4735. return Result::success($result);
  4736. }
  4737. /*
  4738. * 获取工作经验-菜单
  4739. * */
  4740. public function getExperience(array $data): array
  4741. {
  4742. $result = JobEnum::where('egroup', 'years')->get()->all();
  4743. if (empty($result)) {
  4744. return Result::error("暂无工作经验", 0);
  4745. }
  4746. return Result::success($result);
  4747. }
  4748. /*
  4749. * 获取学历-菜单
  4750. * */
  4751. public function getEducation(array $data): array
  4752. {
  4753. $result = JobEnum::where('egroup', 'education')->get()->all();
  4754. if (empty($result)) {
  4755. return Result::error("暂无学历", 0);
  4756. }
  4757. return Result::success($result);
  4758. }
  4759. /*
  4760. * 获取薪资-菜单
  4761. * */
  4762. public function getSalary(array $data): array
  4763. {
  4764. $result = JobEnum::where('egroup', 'income')->get()->all();
  4765. if (empty($result)) {
  4766. return Result::error("暂无薪资", 0);
  4767. }
  4768. return Result::success($result);
  4769. }
  4770. /*
  4771. * 获取语言-菜单
  4772. * */
  4773. public function getLanguage(array $data): array
  4774. {
  4775. $result = JobEnum::where('egroup', 'language')->get()->all();
  4776. if (empty($result)) {
  4777. return Result::error("暂无语言", 0);
  4778. }
  4779. return Result::success($result);
  4780. }
  4781. /*
  4782. * 获取掌握程度-菜单
  4783. * */
  4784. public function getLevel(array $data): array
  4785. {
  4786. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  4787. if (empty($result)) {
  4788. return Result::error("暂无工作性质", 0);
  4789. }
  4790. return Result::success($result);
  4791. }
  4792. // 公司信息
  4793. /*
  4794. * 获取公司性质-菜单
  4795. * */
  4796. public function getCompanyNature(array $data): array
  4797. {
  4798. $result = JobNature::get()->all();
  4799. if (empty($result)) {
  4800. return Result::error("暂无公司性质", 0);
  4801. }
  4802. return Result::success($result);
  4803. }
  4804. /*
  4805. * 获取公司规模-菜单
  4806. * */
  4807. public function getCompanySize(array $data): array
  4808. {
  4809. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  4810. if (empty($result)) {
  4811. return Result::error("暂无公司规模", 0);
  4812. }
  4813. return Result::success($result);
  4814. }
  4815. /*
  4816. * 招聘信息审核
  4817. * */
  4818. public function checkJobRecruiting(array $data): array
  4819. {
  4820. $user = User::where('id', $data['user_id'])->first();
  4821. if (empty($user)) {
  4822. return Result::error("用户不存在", 0);
  4823. }
  4824. $job = JobRecruiting::where('id', $data['id'])->first();
  4825. if (empty($job)) {
  4826. return Result::error("招聘信息不存在", 0);
  4827. }
  4828. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  4829. if ($user['type_id'] != 10000) {
  4830. return Result::error("用户暂无权限审核此招聘信息!", 0);
  4831. }
  4832. // 驳回原因
  4833. if ($data['status'] == 2) {
  4834. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  4835. }
  4836. $data['action_id'] = $data['user_id'];
  4837. unset($data['user_id']);
  4838. $result = JobRecruiting::where('id', $data['id'])->update($data);
  4839. if (empty($result)) {
  4840. return Result::error("审核失败", 0);
  4841. }
  4842. return Result::success($result);
  4843. }
  4844. public function myApplyList(array $data): array
  4845. {
  4846. var_dump($data, '------参数');
  4847. $user = User::where('id', $data['user_id'])->first();
  4848. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4849. return Result::error("用户不存在", 0);
  4850. }
  4851. // 1:个人会员 职场机会
  4852. if ($user['type_id'] == 1) {
  4853. $where['user_id'] = $user['id'];
  4854. }
  4855. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  4856. $query->where('user_id', $user['id']);
  4857. })
  4858. ->pluck('recruit_id');
  4859. $where = [];
  4860. if (isset($data['salary']) && $data['salary'] != null) {
  4861. $where['job_recruiting.salary'] = $data['salary'];
  4862. }
  4863. if (isset($data['experience']) && $data['experience'] != null) {
  4864. $where['job_recruiting.experience'] = $data['experience'];
  4865. }
  4866. if (isset($data['business_name']) && $data['business_name'] != null) {
  4867. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4868. }
  4869. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4870. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4871. ->where($where);
  4872. // ->count();
  4873. $count = $query->count();
  4874. $query = clone $query;
  4875. $job = $query
  4876. ->leftJoin('job_enum as income_enum', function ($join) {
  4877. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4878. ->where('income_enum.egroup', 'income');
  4879. })
  4880. ->leftJoin('job_enum as years_enum', function ($join) {
  4881. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4882. ->where('years_enum.egroup', 'years');
  4883. })
  4884. // ->where($where)
  4885. ->orderBy('job_recruiting.updated_at', 'desc')
  4886. ->select(
  4887. 'job_recruiting.id',
  4888. 'job_recruiting.title',
  4889. 'job_company.business_name',
  4890. 'income_enum.evalue as salary_evalue',
  4891. 'income_enum.ename as salary_ename',
  4892. 'years_enum.evalue as experience_evalue',
  4893. 'years_enum.ename as experience_ename',
  4894. 'job_recruiting.updated_at'
  4895. )
  4896. ->offset(($data['page'] - 1) * $data['pageSize'])
  4897. ->limit($data['pageSize'])
  4898. ->get()
  4899. ->all();
  4900. if (empty($job)) {
  4901. return Result::error("暂无招聘信息", 0);
  4902. }
  4903. $result = [
  4904. 'row' => $job,
  4905. 'count' => $count,
  4906. ];
  4907. return Result::success($result);
  4908. }
  4909. /*
  4910. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  4911. * */
  4912. public function getRecruitingList(array $data): array
  4913. {
  4914. $user = User::where('id', $data['user_id'])->first();
  4915. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4916. return Result::error("用户不存在", 0);
  4917. }
  4918. // 1:个人会员 职场机会
  4919. if ($user['type_id'] == 1) {
  4920. $where['user_id'] = $user['id'];
  4921. }
  4922. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  4923. $query->where('receiver_id', $user['id']);
  4924. })
  4925. ->pluck('recruit_id');
  4926. // return Result::success($recruitingId);
  4927. $where = [];
  4928. if (isset($data['salary']) && $data['salary'] != null) {
  4929. $where['job_recruiting.salary'] = $data['salary'];
  4930. }
  4931. if (isset($data['experience']) && $data['experience'] != null) {
  4932. $where['job_recruiting.experience'] = $data['experience'];
  4933. }
  4934. if (isset($data['business_name']) && $data['business_name'] != null) {
  4935. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4936. }
  4937. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4938. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4939. ->where($where);
  4940. // ->count();
  4941. $count = $query->count();
  4942. $query = clone $query;
  4943. $job = $query
  4944. ->leftJoin('job_enum as income_enum', function ($join) {
  4945. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4946. ->where('income_enum.egroup', 'income');
  4947. })
  4948. ->leftJoin('job_enum as years_enum', function ($join) {
  4949. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4950. ->where('years_enum.egroup', 'years');
  4951. })
  4952. // ->where($where)
  4953. ->orderBy('job_recruiting.updated_at', 'desc')
  4954. ->select(
  4955. 'job_recruiting.id',
  4956. 'job_recruiting.title',
  4957. 'job_company.business_name',
  4958. 'income_enum.evalue as salary_evalue',
  4959. 'income_enum.ename as salary_ename',
  4960. 'years_enum.evalue as experience_evalue',
  4961. 'years_enum.ename as experience_ename',
  4962. 'job_recruiting.updated_at'
  4963. )
  4964. ->offset(($data['page'] - 1) * $data['pageSize'])
  4965. ->limit($data['pageSize'])
  4966. ->get()
  4967. ->all();
  4968. if (empty($job)) {
  4969. return Result::error("暂无招聘信息", 0);
  4970. }
  4971. $result = [
  4972. 'row' => $job,
  4973. 'count' => $count,
  4974. ];
  4975. return Result::success($result);
  4976. }
  4977. /*
  4978. * 获取企业会员-招聘信息列表
  4979. * */
  4980. public function getRecruitingInfo(array $data): array
  4981. {
  4982. $user = User::where('id', $data['user_id'])->first();
  4983. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4984. return Result::error("用户不存在", 0);
  4985. }
  4986. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  4987. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4988. ->select(
  4989. 'job_recruiting.*',
  4990. 'job_company.business_name',
  4991. 'job_company.company_hy_id',
  4992. 'job_company.company_size',
  4993. 'job_company.company_nature',
  4994. 'job_company.introduction',
  4995. 'job_company.real_name',
  4996. 'job_company.mobile',
  4997. 'job_company.company_url',
  4998. 'job_company.address_arr_id',
  4999. 'job_company.address',
  5000. 'job_company.email'
  5001. )
  5002. ->get();
  5003. if (empty($recruiting)) {
  5004. return Result::error("暂无招聘信息", 0);
  5005. }
  5006. return Result::success($recruiting);
  5007. }
  5008. /*
  5009. * 获取企业会员-我的沟通
  5010. * */
  5011. public function getJobResumeList(array $data): array
  5012. {
  5013. $user = User::where('id', $data['user_id'])->first();
  5014. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5015. return Result::error("用户不存在", 0);
  5016. }
  5017. $where = [];
  5018. if (isset($data['salary']) && $data['salary'] != null) {
  5019. $where['job_hunting.salary'] = $data['salary'];
  5020. }
  5021. if (isset($data['user_name']) && $data['user_name'] != null) {
  5022. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5023. }
  5024. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5025. $query->where('job_resume.user_id', $user['id']);
  5026. })
  5027. ->when(!empty($where), function ($query) use ($where) {
  5028. $query->where($where);
  5029. })
  5030. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5031. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5032. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5033. ->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');
  5034. $count = $job->count();
  5035. if ($count == 0) {
  5036. return Result::error("暂无沟通记录", 0);
  5037. }
  5038. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5039. ->offset(($data['page'] - 1) * $data['pageSize'])
  5040. ->limit($data['pageSize'])
  5041. ->get();
  5042. if (empty($jobs)) {
  5043. return Result::error("暂无沟通记录", 0);
  5044. }
  5045. $result['row'] = $this->processJob($jobs, '');
  5046. $result['count'] = $count;
  5047. return Result::success($result);
  5048. }
  5049. // 20250306 招聘
  5050. //20250422 书刊音像
  5051. public function addBook(array $data): array
  5052. {
  5053. // $user_id = $data['user_id'] ?? 0;
  5054. $type_id = $data['type_id'] ?? 0;
  5055. // $website_id = $data['website_id'] ?? 0;
  5056. // unset($data['user_id']);
  5057. unset($data['type_id']);
  5058. // unset($data['website_id']);
  5059. //处理数组
  5060. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5061. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5062. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5063. if ($data['img_url'] == '') {
  5064. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5065. preg_match_all($reg, $data['detail'], $matches);
  5066. if (isset($matches[1][0])) {
  5067. //截取varchar240
  5068. $data['img_url'] = substr($matches[1][0], 0, 240);
  5069. }
  5070. }
  5071. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5072. //提取标题+内容中的关键词
  5073. $data['keyword'] = $data['title'];
  5074. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5075. Jieba::init(); // 初始化 jieba-php
  5076. Finalseg::init();
  5077. $segList = Jieba::cut($data['keyword']);
  5078. $segList1 = array_slice($segList, 0, 8);
  5079. $data['keyword'] = implode(',', $segList1);
  5080. }
  5081. if ($data['description'] == '') {
  5082. //提取内容中的描述
  5083. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  5084. }
  5085. var_dump($data, '--');
  5086. $result = Book::insertGetId($data);
  5087. if (empty($result)) {
  5088. return Result::error("添加失败", 0);
  5089. }
  5090. return Result::success($result);
  5091. }
  5092. public function getBookList(array $data): array
  5093. {
  5094. $where = [];
  5095. if (!empty($data["title"])) {
  5096. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5097. }
  5098. if (!empty($data['website_name'])) {
  5099. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5100. }
  5101. if (!empty($data['status'])) {
  5102. $where[] = ['book.status', '=', $data['status']];
  5103. }
  5104. $user_id = $data['user_id'];
  5105. $type_id = $data['type_id'];
  5106. // $type_id = 4;
  5107. var_dump($type_id, '------1--------');
  5108. if ($type_id != 10000) {
  5109. $where[] = ['book.user_id', '=', $user_id];
  5110. }
  5111. var_dump(!empty($data['status1']), '=-===1');
  5112. $result = Book::where($where)
  5113. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5114. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5115. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5116. ->when(isset($data['status1']), function ($query) use ($data) {
  5117. $query->whereIn('book.status', [1, 3]);
  5118. })
  5119. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5120. ->orderBy("updated_at", "desc")
  5121. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5122. if (empty($result)) {
  5123. return Result::error("暂无数据", 0);
  5124. }
  5125. // 取出数据
  5126. $rows = $result->items();
  5127. $count = $result->total();
  5128. $responseData = [
  5129. 'rows' => $rows,
  5130. 'count' => $count,
  5131. ];
  5132. return Result::success($responseData);
  5133. }
  5134. public function deleteBook(array $data): array
  5135. {
  5136. $result = Book::where('id', $data['id'])->delete();
  5137. if (empty($result)) {
  5138. return Result::error("删除失败", 0);
  5139. }
  5140. return Result::success($result);
  5141. }
  5142. public function updateBook(array $data): array
  5143. {
  5144. // $user_id = $data['user_id'] ?? 0;
  5145. $type_id = $data['type_id'] ?? 0;
  5146. // $website_id = $data['website_id'] ?? 0;
  5147. unset($data['user_id']);
  5148. unset($data['type_id']);
  5149. // unset($data['website_id']);
  5150. //处理数组
  5151. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5152. if ($data['img_url'] == '') {
  5153. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5154. preg_match_all($reg, $data['detail'], $matches);
  5155. if (isset($matches[1][0])) {
  5156. //截取varchar240
  5157. $data['img_url'] = substr($matches[1][0], 0, 240);
  5158. }
  5159. }
  5160. if ($data['keyword'] == '') {
  5161. //提取标题+内容中的关键词
  5162. $data['keyword'] = $data['title'];
  5163. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5164. Jieba::init(); // 初始化 jieba-php
  5165. Finalseg::init();
  5166. $segList = Jieba::cut($data['keyword']);
  5167. $segList1 = array_slice($segList, 0, 8);
  5168. $data['keyword'] = implode(',', $segList1);
  5169. }
  5170. if ($data['description'] == '') {
  5171. //提取内容中的描述
  5172. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  5173. }
  5174. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5175. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5176. $result = Book::where("id", $data["id"])->update($data);
  5177. if (empty($result)) {
  5178. return Result::error("更新失败", 0);
  5179. }
  5180. return Result::success($result);
  5181. }
  5182. public function getBookInfo(array $data): array
  5183. {
  5184. $result = Book::where("id", $data["id"])->first();
  5185. if (empty($result)) {
  5186. return Result::error("获取失败", 0);
  5187. }
  5188. return Result::success($result);
  5189. }
  5190. public function updateBookStatus(array $data): array
  5191. {
  5192. //审核
  5193. unset($data['user_id']);
  5194. $result = Book::where("id", $data["id"])->update($data);
  5195. if (empty($result)) {
  5196. return Result::error("更新失败", 0);
  5197. }
  5198. return Result::success($result);
  5199. }
  5200. //20250422 书刊音像
  5201. /**
  5202. * 贴身宝贝
  5203. * @param array $data
  5204. * @return array
  5205. */
  5206. public function getWebsiteTsbb(array $data): array
  5207. {
  5208. $month = $data['month'] ?? date('m');
  5209. $day = $data['day'] ?? date('d');
  5210. // 使用缓存键
  5211. $cacheKey = "tsbb_data_{$month}_{$day}";
  5212. // 尝试从缓存获取数据
  5213. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5214. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5215. if ($cachedData = $cache->get($cacheKey)) {
  5216. return Result::success(unserialize($cachedData));
  5217. }
  5218. //查询老黄历
  5219. try {
  5220. $date = date('Y-m-d');
  5221. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5222. // 使用 curl 替代 file_get_contents
  5223. $ch = curl_init();
  5224. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5225. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5226. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5227. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5228. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5229. 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');
  5230. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5231. 'Accept: application/json',
  5232. 'Content-Type: application/json',
  5233. 'Referer: https://www.36jxs.com/'
  5234. ]);
  5235. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5236. curl_setopt($ch, CURLOPT_ENCODING, '');
  5237. $almanacResponse = curl_exec($ch);
  5238. var_dump("====:", $almanacResponse);
  5239. if (curl_errno($ch)) {
  5240. var_dump('Curl error:', curl_error($ch));
  5241. throw new \Exception('Curl error: ' . curl_error($ch));
  5242. }
  5243. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5244. curl_close($ch);
  5245. if ($almanacResponse === false) {
  5246. throw new \Exception('Failed to fetch almanac data');
  5247. }
  5248. $almanacData = json_decode($almanacResponse, true);
  5249. if (json_last_error() !== JSON_ERROR_NONE) {
  5250. throw new \Exception('Failed to parse almanac data');
  5251. }
  5252. $almanacInfo = $almanacData['data'] ?? [];
  5253. } catch (\Exception $e) {
  5254. var_dump('Exception:', $e->getMessage());
  5255. $almanacInfo = [];
  5256. }
  5257. // 获取历史上的今天数据
  5258. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5259. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5260. ->orderBy('year', 'asc')
  5261. ->select("title", "id", "year", DB::raw('1 as type'))
  5262. ->limit(16)
  5263. ->get();
  5264. // 获取节日数据 - 从今天开始获取未来4条
  5265. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5266. ->orderBy('showtime', 'asc')
  5267. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5268. ->limit(16)
  5269. ->get();
  5270. //说文解字
  5271. $chartacterList = Character::orderBy('updated_at', 'desc')
  5272. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5273. ->limit(6)
  5274. ->get();
  5275. //谜语沙龙
  5276. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5277. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5278. ->limit(4)
  5279. ->get();
  5280. //成语欣赏
  5281. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5282. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5283. ->limit(32)
  5284. ->get();
  5285. //名联赏析
  5286. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5287. ->select("id", "first", "second", DB::raw('6 as type'))
  5288. ->limit(6)
  5289. ->get();
  5290. // 获取分类文章数据
  5291. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5292. ->pluck('category_id')
  5293. ->toArray();
  5294. // $categoryIds = [627, 628, 629, 630, 631, 632, 633, 634, 635, 636];
  5295. // 使用子查询优化
  5296. $articlesList = DB::table('article')
  5297. ->select([
  5298. 'article.id',
  5299. 'article.title',
  5300. 'article.imgurl',
  5301. 'article.created_at',
  5302. 'category.name as category_name',
  5303. 'category.id as category_id',
  5304. 'website_category.aLIas_pinyin as pinyin',
  5305. DB::raw('100 as type')
  5306. ])
  5307. ->join('category', 'article.catid', '=', 'category.id')
  5308. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5309. ->where('website_category.website_id', $data['website_id'])
  5310. ->where('article.status', 1)
  5311. ->whereIn('category.id', $categoryIds)
  5312. // ->whereRaw('article.created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)')
  5313. ->orderBy('article.created_at', 'desc')
  5314. ->get()
  5315. ->groupBy('category_id')
  5316. ->map(function ($group) {
  5317. // 确保第一条数据有图片
  5318. $firstWithImage = $group->first(function ($item) {
  5319. return !empty($item->imgurl);
  5320. });
  5321. if ($firstWithImage) {
  5322. // 如果有带图片的文章,将其放在第一位
  5323. $group = $group->filter(function ($item) use ($firstWithImage) {
  5324. return $item->id !== $firstWithImage->id;
  5325. })->prepend($firstWithImage);
  5326. }
  5327. return [
  5328. 'category_name' => $group->first()->category_name,
  5329. 'catid' => $group->first()->category_id,
  5330. 'pinyin' => $group->first()->pinyin,
  5331. 'type' => 100,
  5332. 'list' => $group->take(6)->map(function ($item) {
  5333. return [
  5334. 'id' => $item->id,
  5335. 'title' => $item->title,
  5336. 'imgurl' => $item->imgurl,
  5337. 'created_at' => $item->created_at
  5338. ];
  5339. })->values()
  5340. ];
  5341. })
  5342. ->values()
  5343. ->toArray();
  5344. $result = [
  5345. 'almanac' => $almanacInfo,
  5346. 'historyTodayList' => [
  5347. 'category_name' => '历史上的今天',
  5348. 'list' => $historyTodayList,
  5349. 'type' => 1
  5350. ],
  5351. 'festivalList' => [
  5352. 'category_name' => '节日预告',
  5353. 'list' => $festivalList,
  5354. 'type' => 2
  5355. ],
  5356. 'chartacterList' => [
  5357. 'category_name' => '说文解字',
  5358. 'list' => $chartacterList,
  5359. 'type' => 3
  5360. ],
  5361. 'coupletList' => [
  5362. 'category_name' => '名联赏析',
  5363. 'list' => $coupletList,
  5364. 'type' => 6
  5365. ],
  5366. 'riddletList' => [
  5367. 'category_name' => '谜语沙龙',
  5368. 'list' => $riddletList,
  5369. 'type' => 4
  5370. ],
  5371. 'idiomList' => [
  5372. 'category_name' => '成语欣赏',
  5373. 'list' => $idiomList,
  5374. 'type' => 5
  5375. ],
  5376. 'articlesList' => $articlesList
  5377. ];
  5378. // 缓存结果,设置1小时过期
  5379. $cache->set($cacheKey, serialize($result), 3600);
  5380. return Result::success($result);
  5381. }
  5382. /**
  5383. * 获取资讯列表
  5384. */
  5385. public function getWebsiteTsbbList(array $data): array
  5386. {
  5387. $page = $data['page'] ?? 1;
  5388. $pageSize = $data['pageSize'] ?? 10;
  5389. // 如果没有传入月份和日期,则使用今天的日期
  5390. $month = $data['month'] ?? date('m');
  5391. $day = $data['day'] ?? date('d');
  5392. $total = 0;
  5393. $result = [];
  5394. $data['type'] = intval($data['type']);
  5395. var_dump("接收参数:", $data);
  5396. switch ($data['type']) {
  5397. case 1:
  5398. $query = HistoryToday::where(function ($q) use ($month, $day) {
  5399. // 当前月份之后的数据
  5400. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  5401. // 或者当前月份且日期大于等于当前日期的数据
  5402. ->orWhere(function ($q) use ($month, $day) {
  5403. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5404. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  5405. });
  5406. })
  5407. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  5408. $total = $query->count();
  5409. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  5410. ->offset(($page - 1) * $pageSize)
  5411. ->limit($pageSize)
  5412. ->get();
  5413. break;
  5414. case 2:
  5415. $query = Festival::where(function ($q) use ($month, $day) {
  5416. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  5417. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  5418. ->orWhere(function ($q) use ($month, $day) {
  5419. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  5420. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  5421. });
  5422. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  5423. $total = $query->count();
  5424. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  5425. ->offset(($page - 1) * $pageSize)
  5426. ->limit($pageSize)
  5427. ->get();
  5428. break;
  5429. case 3:
  5430. $query = Character::orderBy("updated_at", "desc");
  5431. $total = $query->count();
  5432. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  5433. ->offset(($page - 1) * $pageSize)
  5434. ->limit($pageSize)
  5435. ->get();
  5436. break;
  5437. case 4:
  5438. $query = Riddle::orderBy("updated_at", "desc");
  5439. $total = $query->count();
  5440. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  5441. ->offset(($page - 1) * $pageSize)
  5442. ->limit($pageSize)
  5443. ->get();
  5444. break;
  5445. case 5:
  5446. $query = Idiom::orderBy("updated_at", "desc");
  5447. $total = $query->count();
  5448. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  5449. ->offset(($page - 1) * $pageSize)
  5450. ->limit($pageSize)
  5451. ->get();
  5452. break;
  5453. case 6:
  5454. $query = Couplet::orderBy("updated_at", "desc");
  5455. $total = $query->count();
  5456. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  5457. ->offset(($page - 1) * $pageSize)
  5458. ->limit($pageSize)
  5459. ->get();
  5460. break;
  5461. default:
  5462. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  5463. $total = $query->count();
  5464. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  5465. ->offset(($page - 1) * $pageSize)
  5466. ->limit($pageSize)
  5467. ->get();
  5468. }
  5469. return Result::success([
  5470. 'list' => $result,
  5471. 'total' => $total,
  5472. 'page' => (int)$page,
  5473. 'pageSize' => (int)$pageSize,
  5474. 'month' => $month,
  5475. 'day' => $day
  5476. ]);
  5477. }
  5478. /**
  5479. * 1:历史上的今天
  5480. * 2:节日
  5481. * 3:文章
  5482. *
  5483. * 资讯详情信息
  5484. */
  5485. public function getWebsiteTsbbDetail(array $data): array
  5486. {
  5487. $data['type'] = intval($data['type']);
  5488. switch ($data['type']) {
  5489. case 1:
  5490. $result = HistoryToday::where("id", $data['id'])->first();
  5491. break;
  5492. case 2:
  5493. $result = Festival::where("id", $data['id'])->first();
  5494. break;
  5495. case 3:
  5496. $result = Character::where("id", $data['id'])->first();
  5497. break;
  5498. case 4:
  5499. $result = Riddle::where("id", $data['id'])->first();
  5500. break;
  5501. case 5:
  5502. $result = Idiom::where("id", $data['id'])->first();
  5503. break;
  5504. case 6:
  5505. $result = Couplet::where("id", $data['id'])->first();
  5506. break;
  5507. default:
  5508. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  5509. break;
  5510. }
  5511. return Result::success($result);
  5512. }
  5513. /**
  5514. * 农网导航首页数据
  5515. */
  5516. public function getWebsiteNwHomeList(array $data): array{
  5517. $categoryIds = WebsiteCategory::where(['website_id'=> $data['website_id']])->where("pid","!=",0)
  5518. ->pluck('category_id')
  5519. ->toArray();
  5520. // 使用子查询优化
  5521. $articlesList = DB::table('article')
  5522. ->select([
  5523. 'article.id',
  5524. 'article.title',
  5525. 'article.imgurl',
  5526. 'article.created_at',
  5527. 'category.name as category_name',
  5528. 'category.id as category_id',
  5529. 'website_category.aLIas_pinyin as pinyin',
  5530. 'parent_wc.aLIas_pinyin as parent_pinyin',
  5531. DB::raw('100 as type')
  5532. ])
  5533. ->join('category', 'article.catid', '=', 'category.id')
  5534. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5535. ->leftJoin('website_category as parent_wc', function($join) {
  5536. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  5537. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  5538. })
  5539. ->where('website_category.website_id', $data['website_id'])
  5540. ->where('article.status', 1)
  5541. ->whereIn('category.id', $categoryIds)
  5542. ->orderBy('article.created_at', 'desc')
  5543. ->get()
  5544. ->groupBy('category_id')
  5545. ->map(function ($group) {
  5546. // 确保第一条数据有图片
  5547. $firstWithImage = $group->first(function ($item) {
  5548. return !empty($item->imgurl);
  5549. });
  5550. if ($firstWithImage) {
  5551. // 如果有带图片的文章,将其放在第一位
  5552. $group = $group->filter(function ($item) use ($firstWithImage) {
  5553. return $item->id !== $firstWithImage->id;
  5554. })->prepend($firstWithImage);
  5555. }
  5556. return [
  5557. 'category_name' => $group->first()->category_name,
  5558. 'catid' => $group->first()->category_id,
  5559. 'pinyin' => $group->first()->pinyin,
  5560. 'parent_pinyin' => $group->first()->parent_pinyin,
  5561. 'list' => $group->take(4)->map(function ($item) {
  5562. return [
  5563. 'id' => $item->id,
  5564. 'title' => $item->title,
  5565. ];
  5566. })->values()
  5567. ];
  5568. })
  5569. ->values()
  5570. ->toArray();
  5571. return Result::success($articlesList);
  5572. }
  5573. }