/** * 给出一组商品 ID,取得所有商品的图片, * 这是一个大查询,可能会很多数据,之所以加这个大查询的目的是, * 我们宁可要一个几百条记录的大查询,也不要几百个一条记录的小查询 * * @return array 图像集合 array(array(图片1), array(图片2)) * * @param array $goodsIdArray 商品的 ID 数组 * @param int $ttl 缓存时间 */ public function fetchGoodsGalleryArrayByGoodsIdArray(array $goodsIdArray, $ttl = 0) { if (!is_array($goodsIdArray) || empty($goodsIdArray)) { throw new \InvalidArgumentException('goodsIdArray must be an array not empty'); } // 参数验证 $validator = new Validator(array('ttl' => $ttl)); $ttl = $validator->digits()->min(0)->validate('ttl'); $this->validate($validator); $dataMapper = new DataMapper('goods_gallery'); $sqlInClause = QueryBuilder::buildInCondition('goods_id', $goodsIdArray, \PDO::PARAM_INT); return $dataMapper->find(array($sqlInClause), array('order' => 'goods_id asc , img_sort_order desc, img_id asc'), $ttl); }
/** * 取得用户的 account_log 列表 * * @return array 格式 array(array('key'=>'value', 'key'=>'value', ...)) * * @param int $userId 用户 ID * @param string $filter 查询条件 * @param int $offset 用于分页的开始 >= 0 * @param int $limit 每页多少条 * @param int $ttl 缓存多少时间 */ public function fetchUserAccountLogArray($userId, $filter, $offset = 0, $limit = 10, $ttl = 0) { // 参数验证 $validator = new Validator(array('userId' => $userId, 'filter' => $filter, 'offset' => $offset, 'limit' => $limit, 'ttl' => $ttl)); $userId = $validator->required()->digits()->min(1)->validate('userId'); $filter = $validator->validate('filter'); $offset = $validator->digits()->min(0)->validate('offset'); $limit = $validator->required()->digits()->min(1)->validate('limit'); $ttl = $validator->digits()->min(0)->validate('ttl'); $this->validate($validator); // 需要联表查询 $accountLog = new DataMapper('account_log'); if (!empty($filter)) { $filter .= ' and user_id = ?'; } else { $filter = 'user_id = ?'; } return $accountLog->find(array($filter, $userId), array('order' => 'log_id desc', 'offset' => $offset, 'limit' => $limit), $ttl); }