// +---------------------------------------------------------------------- namespace App\Services\Api; use App\Models\SocialCircleModel; use App\Services\BaseService; use App\Services\ConfigService; use App\Services\RedisService; /** * 生活圈-服务类 * @author laravel开发员 * @since 2020/11/11 * @package App\Services\Api */ class SocialCircleService extends BaseService { // 静态对象 protected static $instance = null; /** * 构造函数 * @author laravel开发员 * @since 2020/11/11 */ public function __construct() { $this->model = new SocialCircleModel(); } /** * 静态入口 */ public static function make() { if (!self::$instance) { self::$instance = new static(); } return self::$instance; } /** * 主页列表 * @param int $num * @return array|mixed */ public function getIndexList($num = 0) { $num = ConfigService::make()->getConfigByCode('show_social_num', 12); $cacheKey = "caches:socials:list_{$num}"; $datas = RedisService::get($cacheKey); if($datas){ return $datas; } $datas = $this->model->where(['status'=>1,'mark'=>1]) ->select(['id','name','logo','link_type','app_id','sort','status']) ->orderBy('sort','desc') ->orderBy('id','asc') ->limit($num) ->get(); $datas = $datas? $datas->toArray() : []; if($datas){ $datas = $datas?array_chunk($datas,8) : []; RedisService::set($cacheKey, $datas, rand(300, 600)); } return $datas; } }