mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 15:02:47 +08:00
模型类增加setInc和setDec方法
This commit is contained in:
@@ -1132,6 +1132,66 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段值(延迟)增长
|
||||||
|
* @access public
|
||||||
|
* @param string $field 字段名
|
||||||
|
* @param integer $step 增长值
|
||||||
|
* @param integer $lazyTime 延时时间(s)
|
||||||
|
* @return integer|true
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function setInc($field, $step = 1, $lazyTime = 0)
|
||||||
|
{
|
||||||
|
// 删除条件
|
||||||
|
$pk = $this->getPk();
|
||||||
|
|
||||||
|
if (is_string($pk) && isset($this->data[$pk])) {
|
||||||
|
$where = [$pk => $this->data[$pk]];
|
||||||
|
} elseif (!empty($this->updateWhere)) {
|
||||||
|
$where = $this->updateWhere;
|
||||||
|
} else {
|
||||||
|
$where = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->getQuery()->where($where)->setInc($field, $step, $lazyTime);
|
||||||
|
if (true !== $result) {
|
||||||
|
$this->data[$field] += $step;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段值(延迟)增长
|
||||||
|
* @access public
|
||||||
|
* @param string $field 字段名
|
||||||
|
* @param integer $step 增长值
|
||||||
|
* @param integer $lazyTime 延时时间(s)
|
||||||
|
* @return integer|true
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function setDec($field, $step = 1, $lazyTime = 0)
|
||||||
|
{
|
||||||
|
// 删除条件
|
||||||
|
$pk = $this->getPk();
|
||||||
|
|
||||||
|
if (is_string($pk) && isset($this->data[$pk])) {
|
||||||
|
$where = [$pk => $this->data[$pk]];
|
||||||
|
} elseif (!empty($this->updateWhere)) {
|
||||||
|
$where = $this->updateWhere;
|
||||||
|
} else {
|
||||||
|
$where = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->getQuery()->where($where)->setDec($field, $step, $lazyTime);
|
||||||
|
if (true !== $result) {
|
||||||
|
$this->data[$field] -= $step;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存多个数据到当前数据对象
|
* 保存多个数据到当前数据对象
|
||||||
* @access public
|
* @access public
|
||||||
|
|||||||
Reference in New Issue
Block a user