public static function getDmaList(array $args = []) { if (empty($args) || empty($args['str'])) { return []; } $str = $args['str']; if (strlen($str) < 2) { return []; } $limit = 10; if (!empty($args['limit'])) { $limit = intval($args['limit']); } $offset = 0; if (!empty($args['offset'])) { $offset = intval($args['offset']); } $max = '+inf'; $min = '-inf'; self::setDmaListCache($str); $list = []; $cache_key = self::getDmaListCacheKey($str); $results = Redis::zrangebyscore($cache_key, $min, $max, ['limit' => [$offset, $limit]]); if (!empty($results)) { $j = 0; foreach ($results as $rec) { $dma = json_decode($rec); if (!empty($dma)) { $list[$j] = ['code' => $dma->code, 'region' => $dma->region]; $j++; } } } return $list; }
public static function getFeatured(array $args = []) { $cache_key = self::getFeaturedCompaniesCacheKey(); self::setFeaturedCompaniesCache(); $limit = 20; if (!empty($args['limit'])) { $limit = intval($args['limit']); } $offset = 0; if (!empty($args['offset'])) { $offset = intval($args['offset']); } $flag = ''; if (!empty($args['flag'])) { $flag = $args['flag']; } $max = '+inf'; $min = '-inf'; $total = Redis::zcard($cache_key); if ($flag == 'random') { if ($total > $limit) { $offset = rand(0, $total - $limit); } } $keys = Redis::zrangebyscore($cache_key, $min, $max, ['limit' => [$offset, $limit]]); $final_list = []; if (!empty($keys)) { foreach ($keys as $key) { $org_info = self::getInfo($key, ['CompanyStrId', 'CompanyName', 'CompanyImg']); if (!empty($org_info['CompanyStrId'])) { $final_list[] = $org_info; } } } return ['total' => $total, 'companies' => $final_list]; }