mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52:48 +08:00
改进Query类的data的多次设置 inc 和dec方法 支持批量设置
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user