SocialCircleService.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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\SocialCircleModel;
  13. use App\Services\BaseService;
  14. use App\Services\ConfigService;
  15. use App\Services\RedisService;
  16. /**
  17. * 生活圈-服务类
  18. * @author laravel开发员
  19. * @since 2020/11/11
  20. * @package App\Services\Api
  21. */
  22. class SocialCircleService extends BaseService
  23. {
  24. // 静态对象
  25. protected static $instance = null;
  26. /**
  27. * 构造函数
  28. * @author laravel开发员
  29. * @since 2020/11/11
  30. */
  31. public function __construct()
  32. {
  33. $this->model = new SocialCircleModel();
  34. }
  35. /**
  36. * 静态入口
  37. */
  38. public static function make()
  39. {
  40. if (!self::$instance) {
  41. self::$instance = new static();
  42. }
  43. return self::$instance;
  44. }
  45. /**
  46. * 主页列表
  47. * @param int $num
  48. * @return array|mixed
  49. */
  50. public function getIndexList($num = 0)
  51. {
  52. $num = ConfigService::make()->getConfigByCode('show_social_num', 12);
  53. $cacheKey = "caches:socials:list_{$num}";
  54. $datas = RedisService::get($cacheKey);
  55. if($datas){
  56. return $datas;
  57. }
  58. $datas = $this->model->where(['status'=>1,'mark'=>1])
  59. ->select(['id','name','logo','link_type','app_id','sort','status'])
  60. ->orderBy('sort','desc')
  61. ->orderBy('id','asc')
  62. ->limit($num)
  63. ->get();
  64. $datas = $datas? $datas->toArray() : [];
  65. if($datas){
  66. $datas = $datas?array_chunk($datas,8) : [];
  67. RedisService::set($cacheKey, $datas, rand(300, 600));
  68. }
  69. return $datas;
  70. }
  71. }