5.0.0 - 普通 - 未处理
thinkphp5 model 中的 setDec setInc 问题如果要增加或减少的字段值为null的话,那么就不会进行操作了
更改方法
public function setInc($field, $step = 1, $lazyTime = 0)
{
$condition = $this->options['where'];
if (empty($condition)) {
// 没有条件不做任何更新
throw new Exception('no data to update');
}
if ($lazyTime > 0) {
// 延迟写入
$guid = md5($this->name . '_' . $field . '_' . serialize($condition));
$step = $this->lazyWrite($guid, $step, $lazyTime);
if (empty($step)) {
return true; // 等待下次写入
} elseif ($step < 0) {
$step = '-' . $step;
}
}
$this->duplicate = [];
return $this->setField($field, ['exp','(case when '. $field.' is null then 0 else '.$field.' end)' . '+' . $step]);
}
