LiveCategoryService.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Api;
  12. use App\Models\LiveCategoryModel;
  13. use App\Services\BaseService;
  14. use App\Services\RedisService;
  15. /**
  16. * 直播分类管理-服务类
  17. * @author laravel开发员
  18. * @since 2020/11/11
  19. * @package App\Services\Api
  20. */
  21. class LiveCategoryService extends BaseService
  22. {
  23. // 静态对象
  24. protected static $instance = null;
  25. /**
  26. * 构造函数
  27. * @author laravel开发员
  28. * @since 2020/11/11
  29. * GoodsCategoryService constructor.
  30. */
  31. public function __construct()
  32. {
  33. $this->model = new LiveCategoryModel();
  34. }
  35. /**
  36. * 静态入口
  37. * @return static|null
  38. */
  39. public static function make()
  40. {
  41. if (!self::$instance) {
  42. self::$instance = (new static());
  43. }
  44. return self::$instance;
  45. }
  46. public function search($params)
  47. {
  48. }
  49. /**
  50. * 分类
  51. * @return array|mixed
  52. */
  53. public function options()
  54. {
  55. $cacheKey = "caches:live:categorys";
  56. $datas = RedisService::get($cacheKey);
  57. if($datas){
  58. return $datas;
  59. }
  60. $categorys = [];
  61. $datas = $this->model->where(['status'=>1,'mark'=>1])
  62. ->select(['id','pid','name','name_sk','name_fr','name_ind','name_en','name_jap','name_mal','name_vie','name_tha','status'])
  63. ->orderBy('sort','desc')
  64. ->orderBy('id','asc')
  65. ->get();
  66. $datas = $datas? $datas->toArray() : [];
  67. if($datas){
  68. foreach($datas as $item){
  69. $item['checked'] = false;
  70. $item['children'] = [];
  71. if($item['pid']){
  72. $categorys[$item['pid']]['children'] = isset($categorys[$item['pid']]['children'])? $categorys[$item['pid']]['children'] : [];
  73. $categorys[$item['pid']]['children'][] = $item;
  74. }else if ($item['pid'] == 0){
  75. $categorys[$item['id']] = $item;
  76. }
  77. }
  78. RedisService::set($cacheKey, $categorys, 3600);
  79. }
  80. return $categorys;
  81. }
  82. }