<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Banner\Util; use Illuminate\Support\Facades\Cache; use ModStart\Core\Dao\ModelUtil; use Module\Banner\Type\BannerPosition; class BannerUtil { const CACHE_KEY_PREFIX = 'banner:'; public static function listByPosition($FcLCS = 'home') { return ModelUtil::model('banner')->where(array('position' => $FcLCS))->orderBy('sort', 'asc')->get()->toArray(); } public static function listByPositionWithCache($FcLCS = 'home', $K9IuV = 60) { return Cache::remember(self::CACHE_KEY_PREFIX . $FcLCS, $K9IuV, function () use($FcLCS) { return self::listByPosition($FcLCS); }); } public static function insertIfMissing($FcLCS, $U8wjN) { $U8wjN['position'] = $FcLCS; if (!ModelUtil::exists('banner', $U8wjN)) { ModelUtil::insert('banner', $U8wjN); } } public static function hasData($FcLCS = 'home') { return !empty(self::listByPositionWithCache($FcLCS)); } public static function clearCache() { foreach (BannerPosition::getList() as $kEhTf => $plloB) { Cache::forget(self::CACHE_KEY_PREFIX . $kEhTf); } } }