Example #1
0
 /**
  *
  * 取得一组记录的数目,用于分页
  *
  * @return int 查询条数
  *
  * @param array $condArray 查询条件数组,例如:
  *                         array(
  *                         array('supplier_id = ?', $supplier_id)
  *                         array('is_on_sale = ?', 1)
  *                         array('create_time > ? or create_time < ?', $timeMin, $timeMax)
  * )
  *
  * @param int   $ttl       缓存多少时间
  *
  */
 public function countOrderSettleArray(array $condArray, $ttl = 0)
 {
     // 参数验证
     $validator = new Validator(array('condArray' => $condArray), '');
     $condArray = $validator->requireArray(true)->validate('condArray');
     $this->validate($validator);
     return $this->_countArray('order_settle', $condArray, null, $ttl);
 }
Example #2
0
 /**
  *
  * 取得一组记录的数目,用于分页
  *
  * @return int 查询条数
  *
  * @param mixed $table        需要查询的数据表,可以是单个表,例如:'user',
  *                      也可以是多个表的数组,例如:array('user' ,'order_info' => 'oi')
  *
  * @param array $condArray    查询条件数组,例如:
  *                            array(
  *                            array('supplier_id = ?', $supplier_id)
  *                            array('is_on_sale = ?', 1)
  *                            array('supplier_price > ? or supplier_price < ?', $priceMin, $priceMax)
  * )
  * 这些查询条件最终会用 and 拼接起来
  * @param array $optionArray  目前不支持 Having 查询,留待以后扩展
  * @param int   $ttl          缓存多少时间
  *
  */
 public function _countArray($table, array $condArray = null, array $optionArray = null, $ttl = 0)
 {
     // 构造参数验证数组
     $validatorArray = array();
     $validatorArray['table'] = $table;
     $validatorArray['ttl'] = $ttl;
     if (null != $condArray) {
         $validatorArray['condArray'] = $condArray;
     }
     if (null != $optionArray) {
         $validatorArray['optionArray'] = $optionArray;
     }
     // 参数验证
     $validator = new Validator($validatorArray, '');
     $table = $validator->required()->validate('table');
     $ttl = $validator->digits()->min(0)->validate('ttl');
     if (null != $condArray) {
         $condArray = $validator->requireArray(false)->validate('condArray');
     }
     if (null != $optionArray) {
         $optionArray = $validator->requireArray(false)->validate('optionArray');
     }
     $this->validate($validator);
     // 构造查询条件
     $filter = null;
     if (!empty($condArray)) {
         $filter = QueryBuilder::buildAndFilter($condArray);
     }
     // 创建 DataMapper
     $dataMapper = new DataMapper($table);
     if (is_string($table)) {
         //简单的单表查询
         $table = array($table);
     }
     if (is_array($table)) {
         // 复杂的多表查询
         return $dataMapper->selectCount($table, $filter, $optionArray, $ttl);
     }
     throw new \InvalidArgumentException('table should be string or array');
 }
Example #3
0
 /**
  *
  * 对 order_info , order_goods 做 inner_join 查询
  *
  * @param array $condArray
  * @param int   $offset
  * @param int   $limit
  * @param int   $ttl
  *
  * @return array
  */
 public function fetchOrderInfoOrderGoodsArray(array $condArray, $offset = 0, $limit = 10, $ttl = 0)
 {
     // 参数验证
     $validator = new Validator(array('condArray' => $condArray), '');
     $condArray = $validator->requireArray(true)->validate('condArray');
     $this->validate($validator);
     $tableInnerJoinStr = DataMapper::tableName('order_goods') . ' as og INNER JOIN ' . DataMapper::tableName('order_info') . ' as oi ON og.order_id = oi.order_id';
     return $this->_fetchArray($tableInnerJoinStr, 'og.*, oi.user_id, oi.pay_time, oi.add_time, oi.order_sn, ' . 'oi.consignee, oi.address, oi.mobile', $condArray, array('order' => 'og.order_id desc, og.rec_id desc'), $offset, $limit, $ttl);
 }