| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Api;
- use App\Models\NoticeModel;
- use App\Services\BaseService;
- use App\Services\RedisService;
- /**
- * 通知公告-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * Class NoticeService
- * @package App\Services\Api
- */
- class NoticeService extends BaseService
- {
- // 静态对象
- protected static $instance = null;
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- * NoticeService constructor.
- */
- public function __construct()
- {
- $this->model = new NoticeModel();
- }
- /**
- * 静态入口
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 列表
- * @param int $num
- * @return array|mixed
- */
- public function getDataList($num = 9)
- {
- $cacheKey = "caches:index:notices";
- $datas = RedisService::get($cacheKey);
- if($datas){
- return $datas;
- }
- $datas = $this->model->where(['status'=>1,'mark'=>1])
- ->select(['id','title','create_time','content','status'])
- ->limit($num)
- ->get();
- $datas = $datas? $datas->toArray() : [];
- if($datas){
- RedisService::set($cacheKey, $datas, rand(300, 600));
- }
- return $datas;
- }
- }
|