| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?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 = 30, $type=2)
- {
- $cacheKey = "caches:notices:index_{$type}";
- $datas = RedisService::get($cacheKey);
- if($datas){
- return $datas;
- }
- $datas = $this->model->where(['type'=>$type,'status'=>1,'mark'=>1])
- ->select(['id','title','type','create_time','content','status'])
- ->limit($num)
- ->get();
- $datas = $datas? $datas->toArray() : [];
- if($datas){
- RedisService::set($cacheKey, $datas, rand(300, 600));
- }
- return $datas;
- }
- /**
- * @param $title
- * @param $content
- * @param int $type
- * @return mixed
- */
- public function updateOrderNotice($title, $content, $type = 2)
- {
- RedisService::clear("caches:notices:index_{$type}");
- $this->model->where(['type'=>2])->where('create_time','<=', time() - 7 * 86400)->delete();
- return $this->model->insertGetId(['title'=>$title,'content'=>$content,'type'=>2,'status'=>1,'create_time'=>time()]);
- }
- }
|