| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Api;
- use App\Models\AdModel;
- use App\Services\BaseService;
- use App\Services\RedisService;
- /**
- * 广告管理-服务类
- * Class AdService
- * @package App\Services\Api
- */
- class AdService extends BaseService
- {
- /**
- * 构造函数
- * AdService constructor.
- */
- public function __construct()
- {
- $this->model = new AdModel();
- }
- /**
- * 静态入口
- * @return AdService|null
- */
- public static function make()
- {
- return parent::make(); // TODO: Change the autogenerated stub
- }
- /**
- * 获取广告列表
- * @param int $position 广告位置:1-首页
- * @param int $listRows 返回数量
- * @return array|false|mixed
- */
- public function getList($position=1, $listRows = 6)
- {
- $cacheKey = "caches:adverts:index_{$position}_{$listRows}";
- if($list = RedisService::get($cacheKey)){
- return $list;
- }
- $list = $this->model->where(['position'=> $position,'mark'=>1,'status'=>1])
- ->select(['id','title','cover as image','type'])
- ->orderBy('sort','desc')
- ->limit($listRows)
- ->get()
- ->each(function($item, $k){
- $item['image'] = $item['image']? get_image_url($item['image']) : '';
- });
- $list = $list? $list->toArray() : [];
- if($list){
- RedisService::set($cacheKey, $list, rand(10, 30));
- }
- return $list;
- }
- }
|