vr-shopxo-source/app/service/BannerService.php

76 lines
2.5 KiB
PHP
Raw Normal View History

2018-12-28 10:58:37 +00:00
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
2021-03-16 02:34:52 +00:00
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
2018-12-28 10:58:37 +00:00
// +----------------------------------------------------------------------
2021-03-16 02:34:52 +00:00
// | Licensed ( https://opensource.org/licenses/mit-license.php )
2018-12-28 10:58:37 +00:00
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\service;
2021-07-18 15:42:10 +00:00
use think\facade\Db;
2022-04-21 14:08:53 +00:00
use app\service\SystemService;
use app\service\ResourcesService;
2018-12-28 10:58:37 +00: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 10:58:37 +00:00
{
2020-04-03 08:28:01 +00:00
// 缓存
2022-04-21 14:08:53 +00:00
$key = SystemService::CacheKey('shopxo.cache_banner_list_key').APPLICATION_CLIENT_TYPE;
2021-07-18 15:42:10 +00:00
$data = MyCache($key);
2021-07-23 07:58:46 +00:00
if($data === null || MyEnv('app_debug'))
2018-12-28 10:58:37 +00:00
{
2020-04-03 08:28:01 +00:00
// 获取banner数据
2020-06-20 14:04:28 +00:00
$field = 'name,images_url,event_value,event_type,bg_color';
2020-07-03 15:18:46 +00:00
$order_by = 'sort asc,id asc';
$data = Db::name('Slide')->field($field)->where(['platform'=>APPLICATION_CLIENT_TYPE, 'is_enable'=>1])->order($order_by)->select()->toArray();
2020-04-03 08:28:01 +00:00
if(!empty($data))
2018-12-28 10:58:37 +00:00
{
2020-04-03 08:28:01 +00:00
foreach($data as &$v)
{
2020-08-11 14:45:56 +00:00
// 图片地址
2020-04-03 08:28:01 +00:00
$v['images_url'] = ResourcesService::AttachmentPathViewHandle($v['images_url']);
2020-08-11 14:45:56 +00:00
// 事件值
if(!empty($v['event_value']))
{
// 地图
if($v['event_type'] == 3)
{
$v['event_value_data'] = explode('|', $v['event_value']);
}
$v['event_value'] = htmlspecialchars_decode($v['event_value']);
2020-08-11 14:45:56 +00:00
} else {
$v['event_value'] = null;
}
2020-04-03 08:28:01 +00:00
}
2021-07-23 07:58:46 +00:00
} else {
$data = [];
2018-12-28 10:58:37 +00:00
}
2020-04-03 08:28:01 +00:00
// 存储缓存
2021-07-23 07:58:46 +00:00
MyCache($key, $data, 180);
2018-12-28 10:58:37 +00:00
}
2020-04-03 08:28:01 +00:00
return $data;
2018-12-28 10:58:37 +00:00
}
}
?>