model = new ShopGoodsMenuModel(); } /** * 静态化入口 * @return static|null */ public static function make() { if(!self::$instance){ self::$instance = new static(); } return self::$instance; } /** * 获取列表 * @param $map 分组 * @param $pageSize 分页大小 * @param $field 返回字段 * @param $cache 是否缓存数据,默认是 * @return array|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getList($map, $pageSize=10, $field='', $cache=true) { $page = request()->post('page', 1); $cacheKey = "caches:goodsMenu:list_{$page}_{$pageSize}_".md5(json_encode($map, 256).$field); $list = RedisCache::get($cacheKey); if($list && $cache){ return $list; } $where = ['status'=> 1]; $field = $field? $field : '*'; $order = isset($map['sort']) && $map['sort']? $map['sort'] : 'sort desc,id asc'; $list = $this->model->where($where) ->field($field) ->order($order) ->paginate($pageSize); $list = $list? $list->toArray():[]; if($list){ RedisCache::set($cacheKey, $list, rand(5,10)); } return $list; } }