Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
*/
private $replace = false;

/**
* 保存数据额外参数.
*
* @var string
*/
private $extraSave = '';

/**
* 数据表后缀
*
Expand Down Expand Up @@ -468,6 +475,20 @@ public function replace(bool $replace = true)
return $this;
}

/**
* 设置保存数据的额外参数.
*
* @param string $extraSave 额外信息
*
* @return $this
*/
public function extraSave(string $extraSave)
{
$this->extraSave = $extraSave;

return $this;
}

/**
* 刷新模型数据.
*
Expand Down Expand Up @@ -656,6 +677,7 @@ protected function updateData(): bool
->cache(true)
->setOption('key', $this->key)
->field($allowFields)
->extra($this->extraSave)
->update($data);

$this->checkResult($result);
Expand Down Expand Up @@ -710,6 +732,7 @@ protected function insertData(string $sequence = null): bool
$result = $db->strict(false)
->field($allowFields)
->replace($this->replace)
->extra($this->extraSave)
->sequence($sequence)
->insert($data, true);

Expand Down Expand Up @@ -848,10 +871,11 @@ public function delete(): bool
* @param array $allowField 允许字段
* @param bool $replace 使用Replace
* @param string $suffix 数据表后缀
* @param string $extraSave 保存数据额外参数
*
* @return static
*/
public static function create(array $data, array $allowField = [], bool $replace = false, string $suffix = ''): Model
public static function create(array $data, array $allowField = [], bool $replace = false, string $suffix = '', string $extraSave = ''): Model
{
$model = new static();

Expand All @@ -863,7 +887,7 @@ public static function create(array $data, array $allowField = [], bool $replace
$model->setSuffix($suffix);
}

$model->replace($replace)->save($data);
$model->replace($replace)->extraSave($extraSave)->save($data);

return $model;
}
Expand Down