add($data); return $res; } /** * 更新 * @param $map * @param $save * @return mixed */ public function updateData($map, $save) { $res = $this->where($map)->save($save); return $res; } /** * 获取一条 * @param array $map * @param string $field * @return mixed */ public function getFind($map = array('id' => array('gt', 0)), $field = '*') { $res = $this->field($field)->where($map)->find(); return $res; } /** * 获取一条 * @param $map * @param string $field * @return mixed */ public function getFindTrue($map, $field = '*') { $res = $this->field($field, true)->where($map)->find(); return $res; } /** * 获取一条 * @param $map * @param string $field * @param string $order * @return mixed */ public function getOrderFind($map, $field = '*', $order = 'id asc') { $res = $this->field($field)->where($map)->order($order)->find(); return $res; } /** * 查询多条 * @param $map 查询条件 * @param string $field 获取的字段类型 * @param string $order 排序规则 * @param string $page 分页(英文逗号拼接的两个数字) * @return mixed */ public function getSelect($map, $field = '*', $order = 'id asc', $page = '') { if ($page) { $res = $this->field($field)->where($map)->order($order)->page($page)->select(); } else { $res = $this->field($field)->where($map)->order($order)->select(); } return $res; } /** * 获取数量 * @param $map * @return mixed */ public function getCount($map) { $res = $this->where($map)->count(); return (int)$res; } /** * 获取某字段的sum值 * @param $map * @param $key * @return mixed */ public function getSum($map, $key) { $res = $this->where($map)->sum($key); return $res ? $res : 0; } /** * 获取某字段 * @param $map * @param string $fields * @param $bol //true为获取多条 * @return mixed */ public function getFindField($map, $fields = 'id', $bol = false) { $res = $this->where($map)->getField($fields, $bol); return $res; } /** * 获取某字段 * @param $map * @param string $fields * @param string $order * @param $bol //true为获取多条 * @return mixed */ public function getOrderFindField($map, $fields = 'id', $order = 'id asc', $bol = false) { $res = $this->where($map)->order($order)->getField($fields, $bol); return $res; } /** * 某个字段向上增加 * @param $map 条件 * @param $key 字段名 * @param $val 增加的值 * @return mixed */ public function toSetInc($map, $key, $val) { $res = $this->where($map)->setInc($key, $val); return $res; } /** * 某个字段向下加减少 * @param $map 条件 * @param $key 字段名 * @param $val 减少的值 * @return mixed */ public function toSetDec($map, $key, $val) { $res = $this->where($map)->setDec($key, $val); return $res; } /** * 删除记录 * @param $map * @return mixed */ public function deleteData($map) { $res = $this->where($map)->delete(); return $res; } /** * group分组查询 * @param $map * @param $group * @param string $fields * @param bool $bol * @return mixed */ public function getGroupFindField($map, $group, $fields = 'id', $bol = false) { $res = $this->where($map)->group($group)->getField($fields, $bol); return $res; } /** * group分组查询,分页 * @param $map * @param $group * @param string $fields * @param bool $bol * @param string $page * @param string $limit * @return mixed */ public function getGroupFindFieldSelect($map, $group, $fields = 'id', $bol = false, $page = '', $limit = '') { $res = $this->where($map)->group($group)->page($page, $limit)->getField($fields, $bol); return $res; } /** * 统计分组数量 * @param $map * @param $group * @return mixed */ public function getGroupCount($map, $group) { $res = $this->where($map)->count('distinct(' . $group . ')'); return (int)$res; } /** * 查询根据某个字段排序的列表 * @param $map * @param $group_field * @param string $field * @param string $order * @param string $page * @return mixed */ public function getGroupSelect($map, $group_field, $field = '*', $order = '', $page = '') { $res = $this->field($field)->where($map)->group($group_field)->order($order)->page($page)->select(); return $res; } /** * 查询根据某个字段最大的key * @param $map * @param $key * @return mixed */ public function getMax($map, $key) { $res = $this->where($map)->max($key); return $res; } }