| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?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;
- }
- /**
- * 获取详情
- * @param $id
- * @return array|mixed
- */
- public function getInfo($id)
- {
- $cacheKey = "caches:notices:info_{$id}";
- $info = RedisService::get($cacheKey);
- if($info){
- return $info;
- }
- $info = $this->model->where(['id'=> $id,'status'=>1,'mark'=>1])
- ->select(['id','title','author','content','create_time'])
- ->first();
- $info = $info? $info->toArray() : [];
- if($info){
- $info['create_time'] = $info['create_time']? datetime($info['create_time'],'Y-m-d') : '';
- $info['content'] = get_format_content($info['content']);
- RedisService::set($cacheKey, $info, rand(5,10));
- }
- return $info;
- }
- }
|