123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Common;
- use App\Models\AdModel;
- use App\Services\BaseService;
- use App\Services\RedisService;
- /**
- * 广告管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * Class AdService
- * @package App\Services\Common
- */
- class AdService extends BaseService
- {
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- * AdService constructor.
- */
- public function __construct()
- {
- $this->model = new AdModel();
- }
- /**
- * 按广告位获取缓存列表
- * @param $position
- * @param int $num
- * @return array|mixed
- */
- public function getListByPosition($position, $num=0)
- {
- $cacheKey = "caches:banners:{$position}";
- $datas = RedisService::get($cacheKey);
- if($datas){
- return $datas;
- }
- $showNum = \App\Services\ConfigService::make()->getConfigByCode('show_banner_num', 6);
- $num = $num? $num : $showNum;
- $datas = $this->model->where(['position'=> $position,'status'=> 1,'mark'=>1])
- ->select(['id','cover','title','url','description','type'])
- ->limit($num)
- ->get()
- ->each(function($item, $k){
- $item['cover'] = $item['cover']? get_image_url($item['cover']) : '';
- });
- $datas = $datas? $datas->toArray() : [];
- if($datas){
- RedisService::set($cacheKey, $datas, rand(5, 10));
- }
- return $datas;
- }
- /**
- * 添加或编辑
- * @return array
- * @since 2020/11/11
- * @author laravel开发员
- */
- public function edit()
- {
- $data = request()->all();
- // 图片处理
- if(isset($data['cover'])){
- $data['cover'] = get_image_path($data['cover']);
- }
- // 结束时间
- if (isset($data['end_time'])) {
- $data['end_time'] = strtotime($data['end_time']);
- }
- return parent::edit($data); // TODO: Change the autogenerated stub
- }
- }
|