model = new ExpressShippingMethodModel(); } /** * 静态化入口 * @return static|null */ public static function make() { if(!self::$instance){ self::$instance = new static(); } return self::$instance; } /** * 获取模板列表 * @param $templateId 模板ID * @param bool $cache 是否缓存 * @return array|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getListByTemplate($templateId, $cache=true) { if($templateId<=0){ return false; } $cacheKey = "caches:shippingList:template_{$templateId}"; $data = RedisCache::get($cacheKey); if($data && $cache){ return $data; } $where = ['template_id'=> $templateId]; $data = $this->model->where($where)->select(); $data = $data? $data->toArray():[]; if($data && $cache){ RedisCache::set($cacheKey, $data, rand(10,20)); } return $data; } }