model = new AddressModel(); } /** * 静态化入口 * @return static|null */ public static function make() { if(!self::$instance){ self::$instance = new static(); } return self::$instance; } /** * 获取列表 * @param $sid 上级ID * @return array|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getListByParent($sid) { $cacheKey = "caches:address:list_{$sid}"; $data = RedisCache::get($cacheKey); if($data){ return $data; } $data = $this->model->where(['pid'=> $sid])->field('id,name,first,pinyin')->select(); $data = $data? $data->toArray():[]; if($data){ RedisCache::set($cacheKey, $data, rand(5,10)); } return $data; } }