<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Banner\Util; use Illuminate\Support\Facades\Cache; use ModStart\Core\Assets\AssetsUtil; use ModStart\Core\Dao\ModelUtil; use Module\Banner\Type\BannerPosition; class BannerUtil { const CACHE_KEY_PREFIX = 'banner:'; public static function listByPosition($zeOUe = 'home') { goto A_DnF; A_DnF: $MCyeh = ModelUtil::model('banner')->where(array('position' => $zeOUe))->orderBy('sort', 'asc')->get()->toArray(); goto pFz_Y; pFz_Y: foreach ($MCyeh as $i0YzC => $Iim2u) { if ($Iim2u['image']) { $MCyeh[$i0YzC]['image'] = AssetsUtil::fixFull($Iim2u['image']); } if ($Iim2u['video']) { $MCyeh[$i0YzC]['video'] = AssetsUtil::fixFull($Iim2u['video']); } } goto iV5Gw; iV5Gw: return $MCyeh; goto uh_ct; uh_ct: } public static function listByPositionWithCache($zeOUe = 'home', $Vr9BY = 60) { return Cache::remember(self::CACHE_KEY_PREFIX . $zeOUe, $Vr9BY, function () use($zeOUe) { return self::listByPosition($zeOUe); }); } public static function insertIfMissing($zeOUe, $avcnU) { $avcnU['position'] = $zeOUe; if (!ModelUtil::exists('banner', $avcnU)) { ModelUtil::insert('banner', $avcnU); } } public static function hasData($zeOUe = 'home') { return !empty(self::listByPositionWithCache($zeOUe)); } public static function clearCache() { foreach (BannerPosition::getList() as $KAKiA => $NMB1l) { Cache::forget(self::CACHE_KEY_PREFIX . $KAKiA); } } }