Skip to content

Commit 44c8031

Browse files
committed
model类save方法成功后处理Express对象数据
1 parent fc17197 commit 44c8031

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/Model.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use think\contract\Arrayable;
2020
use think\contract\Jsonable;
2121
use think\db\BaseQuery as Query;
22+
use think\db\Express;
2223
use think\model\contract\Modelable;
2324

2425
/**
@@ -691,15 +692,28 @@ public function save(array | object $data = [], ?string $sequence = null): bool
691692
// 写入回调
692693
$this->trigger('AfterWrite');
693694

694-
if (!empty($this->change)) {
695-
// 处理递增递减数据
696-
foreach ($this->change as $field => $val) {
697-
$this->data[$field] = $val;
695+
if (!$this->entity) {
696+
if (!empty($this->change)) {
697+
// 处理递增递减数据
698+
foreach ($this->change as $field => $val) {
699+
$this->data[$field] = $val;
700+
}
701+
$this->change = [];
698702
}
699-
$this->change = [];
700-
}
701703

702-
if (!$this->entity) {
704+
foreach ($this->data as $name => &$val) {
705+
if ($val instanceof Express) {
706+
$step = $val->getStep();
707+
$origin = $this->origin[$name];
708+
$val = match ($val->getType()) {
709+
'+' => $origin + $step,
710+
'-' => $origin - $step,
711+
'*' => $origin * $step,
712+
'/' => $origin / $step,
713+
default => $origin,
714+
};
715+
}
716+
}
703717
// 重新记录原始数据
704718
$this->origin = $this->data;
705719
$this->get = [];

0 commit comments

Comments
 (0)