mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 07:12:47 +08:00
改进Query类的data的多次设置 inc 和dec方法 支持批量设置
This commit is contained in:
@@ -807,7 +807,7 @@ class Query
|
|||||||
public function data($field, $value = null)
|
public function data($field, $value = null)
|
||||||
{
|
{
|
||||||
if (is_array($field)) {
|
if (is_array($field)) {
|
||||||
$this->options['data'] = $field;
|
$this->options['data'] = isset($this->options['data']) ? array_merge($this->options['data'], $field) : $field;
|
||||||
} else {
|
} else {
|
||||||
$this->options['data'][$field] = $value;
|
$this->options['data'][$field] = $value;
|
||||||
}
|
}
|
||||||
@@ -817,26 +817,32 @@ class Query
|
|||||||
/**
|
/**
|
||||||
* 字段值增长
|
* 字段值增长
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $field 字段名
|
* @param string|array $field 字段名
|
||||||
* @param integer $step 增长值
|
* @param integer $step 增长值
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function inc($field, $step = 1)
|
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;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字段值减少
|
* 字段值减少
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $field 字段名
|
* @param string|array $field 字段名
|
||||||
* @param integer $step 增长值
|
* @param integer $step 增长值
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function dec($field, $step = 1)
|
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;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user