Think\Db\Query::setInc PHP Method

setInc() public method

字段值(延迟)增长
public setInc ( string $field, integer $step = 1, integer $lazyTime ) : integer | true
$field string 字段名
$step integer 增长值
$lazyTime integer 延时时间(s)
return integer | true
    public function setInc($field, $step = 1, $lazyTime = 0)
    {
        $condition = !empty($this->options['where']) ? $this->options['where'] : [];
        if (empty($condition)) {
            // 没有条件不做任何更新
            throw new Exception('no data to update');
        }
        if ($lazyTime > 0) {
            // 延迟写入
            $guid = md5($this->getTable() . '_' . $field . '_' . serialize($condition));
            $step = $this->lazyWrite('inc', $guid, $step, $lazyTime);
            if (false === $step) {
                // 清空查询条件
                $this->options = [];
                return true;
            } else {
                return $this->setField($field, $step);
            }
        }
        return $this->setField($field, ['exp', $field . '+' . $step]);
    }