From c659275872faa0169d7ec1777e5179e925ecec8f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 3 Jan 2017 13:59:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB=E7=9A=84data?= =?UTF-8?q?=E7=9A=84=E5=A4=9A=E6=AC=A1=E8=AE=BE=E7=BD=AE=20=20inc=20?= =?UTF-8?q?=E5=92=8Cdec=E6=96=B9=E6=B3=95=20=E6=94=AF=E6=8C=81=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index c6586c00..21c70a03 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -807,7 +807,7 @@ class Query public function data($field, $value = null) { if (is_array($field)) { - $this->options['data'] = $field; + $this->options['data'] = isset($this->options['data']) ? array_merge($this->options['data'], $field) : $field; } else { $this->options['data'][$field] = $value; } @@ -817,26 +817,32 @@ class Query /** * 字段值增长 * @access public - * @param string $field 字段名 - * @param integer $step 增长值 + * @param string|array $field 字段名 + * @param integer $step 增长值 * @return $this */ public function inc($field, $step = 1) { - $this->data($field, ['exp', $field . '+' . $step]); + $fields = is_string($field) ? explode(',', $field) : $field; + foreach ($fields as $field) { + $this->data($field, ['exp', $field . '+' . $step]); + } return $this; } /** * 字段值减少 * @access public - * @param string $field 字段名 - * @param integer $step 增长值 + * @param string|array $field 字段名 + * @param integer $step 增长值 * @return $this */ public function dec($field, $step = 1) { - $this->data($field, ['exp', $field . '-' . $step]); + $fields = is_string($field) ? explode(',', $field) : $field; + foreach ($fields as $field) { + $this->data($field, ['exp', $field . '-' . $step]); + } return $this; }