<?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($z8wh0 = 'home') { return ModelUtil::model('banner')->where(array('position' => $z8wh0))->orderBy('sort', 'asc')->get()->toArray(); } public static function listByPositionWithCache($z8wh0 = 'home', $seQTq = 60) { return Cache::remember(self::CACHE_KEY_PREFIX . $z8wh0, $seQTq, function () use($z8wh0) { return self::listByPosition($z8wh0); }); } public static function insertIfMissing($z8wh0, $Pg57y) { $Pg57y['position'] = $z8wh0; if (!ModelUtil::exists('banner', $Pg57y)) { ModelUtil::insert('banner', $Pg57y); } } public static function hasData($z8wh0 = 'home') { return !empty(self::listByPositionWithCache($z8wh0)); } public static function clearCache() { foreach (BannerPosition::getList() as $MFVkb => $FViDa) { Cache::forget(self::CACHE_KEY_PREFIX . $MFVkb); } } }