| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Api;
- use App\Models\LiveCategoryModel;
- use App\Services\BaseService;
- use App\Services\RedisService;
- /**
- * 直播分类管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Services\Api
- */
- class LiveCategoryService extends BaseService
- {
- // 静态对象
- protected static $instance = null;
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- * GoodsCategoryService constructor.
- */
- public function __construct()
- {
- $this->model = new LiveCategoryModel();
- }
- /**
- * 静态入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = (new static());
- }
- return self::$instance;
- }
- public function search($params)
- {
- }
- /**
- * 分类
- * @return array|mixed
- */
- public function options()
- {
- $cacheKey = "caches:live:categorys";
- $datas = RedisService::get($cacheKey);
- if($datas){
- return $datas;
- }
- $categorys = [];
- $datas = $this->model->where(['status'=>1,'mark'=>1])
- ->select(['id','pid','name','name_sk','name_fr','name_ind','name_en','name_jap','name_mal','name_vie','name_tha','status'])
- ->orderBy('sort','desc')
- ->orderBy('id','asc')
- ->get();
- $datas = $datas? $datas->toArray() : [];
- if($datas){
- foreach($datas as $item){
- $item['checked'] = false;
- $item['children'] = [];
- if($item['pid']){
- $categorys[$item['pid']]['children'] = isset($categorys[$item['pid']]['children'])? $categorys[$item['pid']]['children'] : [];
- $categorys[$item['pid']]['children'][] = $item;
- }else if ($item['pid'] == 0){
- $categorys[$item['id']] = $item;
- }
- }
- RedisService::set($cacheKey, $categorys, 3600);
- }
- return $categorys;
- }
- }
|