Files
shopxo/application/service/BannerService.php

71 lines
2.2 KiB
PHP
Raw Normal View History

2018-12-28 18:58:37 +08:00
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
2019-02-18 13:52:07 +08:00
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
2018-12-28 18:58:37 +08:00
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\service;
use think\Db;
use app\service\ResourcesService;
2018-12-28 18:58:37 +08:00
/**
* 轮播服务层
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class BannerService
{
/**
* 获取轮播
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-08-29
* @desc description
* @param [array] $params [输入参数]
*/
public static function Banner($params = [])
2018-12-28 18:58:37 +08:00
{
2019-12-16 15:06:22 +08:00
// 平台
$platform = APPLICATION_CLIENT_TYPE;
// web端手机访问
if($platform == 'pc' && IsMobile())
{
$platform = 'h5';
}
2020-04-03 16:28:01 +08:00
// 缓存
$key = config('shopxo.cache_banner_list_key').$platform;
$data = cache($key);
if(empty($data))
2018-12-28 18:58:37 +08:00
{
2020-04-03 16:28:01 +08:00
// 获取banner数据
2020-06-20 22:04:28 +08:00
$field = 'name,images_url,event_value,event_type,bg_color';
2020-07-03 23:18:46 +08:00
$order_by = 'sort asc,id asc';
2020-06-20 22:04:28 +08:00
$data = Db::name('Slide')->field($field)->where(['platform'=>$platform, 'is_enable'=>1])->order($order_by)->select();
2020-04-03 16:28:01 +08:00
if(!empty($data))
2018-12-28 18:58:37 +08:00
{
2020-04-03 16:28:01 +08:00
foreach($data as &$v)
{
$v['images_url_old'] = $v['images_url'];
$v['images_url'] = ResourcesService::AttachmentPathViewHandle($v['images_url']);
$v['event_value'] = empty($v['event_value']) ? null : $v['event_value'];
}
2018-12-28 18:58:37 +08:00
}
2020-04-03 16:28:01 +08:00
// 存储缓存
cache($key, $data, 3600*24);
2018-12-28 18:58:37 +08:00
}
2020-04-03 16:28:01 +08:00
return $data;
2018-12-28 18:58:37 +08:00
}
}
?>