<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Res\Util; use Illuminate\Support\Facades\Cache; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Util\ArrayUtil; class ResCatUtil { public static function clearCache() { goto CevX9; qgCMA: Cache::forget('ResCatGroupCatMap'); goto nl9jp; TtAYT: Cache::forget('ResCatGroups'); goto qgCMA; CevX9: Cache::forget('ResCats'); goto TtAYT; nl9jp: } public static function groups($tKN9l = 0) { goto QKXly; FQdSv: if ($tKN9l >= 0) { $fccWO = array_values(array_filter($fccWO, function ($OUUYw) use($tKN9l) { return in_array($tKN9l, $OUUYw['categoryIds']); })); } goto jnBG4; jnBG4: return $fccWO; goto E3qTL; QKXly: $fccWO = Cache::rememberForever('ResCatGroups', function () { $sX2oK = ModelUtil::all('res_cat_group', array(), array('id', 'pid', 'title', 'icon', 'categoryIds'), array('sort', 'asc')); ModelUtil::decodeRecordsJson($sX2oK, array('categoryIds')); return $sX2oK; }); goto FQdSv; E3qTL: } public static function cats() { return Cache::rememberForever('ResCats', function () { return ModelUtil::all('res_cat', array(), array('id', 'groupId', 'title'), array('sort', 'asc')); }); } public static function listCatsByIds($HuJ3G) { return array_values(array_filter(self::cats(), function ($OUUYw) use($HuJ3G) { return in_array($OUUYw['id'], $HuJ3G); })); } public static function mergeCats(&$sX2oK) { goto ZlPgk; hzyvr: foreach ($sX2oK as $kEhTf => $y2Ltn) { goto eMOwR; cVwW8: foreach ($wj66m as $P112c) { if ($P112c['assetId'] == $y2Ltn['id']) { $HuJ3G[] = $P112c['catId']; } } goto O7L17; YumKX: $sX2oK[$kEhTf]['_cats'] = self::listCatsByIds($HuJ3G); goto OzJDP; eMOwR: $HuJ3G = array(); goto cVwW8; O7L17: $sX2oK[$kEhTf]['_catIds'] = $HuJ3G; goto YumKX; OzJDP: } goto K_Stn; ZlPgk: $CQYv7 = array_column($sX2oK, 'id'); goto zNkwu; zNkwu: $wj66m = ModelUtil::allIn('res_cat_map', 'assetId', $CQYv7, array('assetId', 'catId')); goto hzyvr; K_Stn: } public static function groupCatMap($tKN9l = 0) { goto YEPU8; EzJ_Y: $la7E1 = self::cats(); goto XXazY; AEPXo: return $fccWO; goto xKUrp; YEPU8: $fccWO = self::groups($tKN9l); goto EzJ_Y; XXazY: foreach ($fccWO as $NAFuY => $uOsK7) { $fccWO[$NAFuY]['_cats'] = array_values(array_filter($la7E1, function ($CQpWy) use($uOsK7) { return $CQpWy['groupId'] == $uOsK7['id']; })); $fccWO[$NAFuY]['_catIds'] = ArrayUtil::flatItemsByKey($fccWO[$NAFuY]['_cats'], 'id'); } goto AEPXo; xKUrp: } }