File tree Expand file tree Collapse file tree 1 file changed +21
-7
lines changed
Expand file tree Collapse file tree 1 file changed +21
-7
lines changed Original file line number Diff line number Diff line change 1919use think \contract \Arrayable ;
2020use think \contract \Jsonable ;
2121use think \db \BaseQuery as Query ;
22+ use think \db \Express ;
2223use 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 = [];
You can’t perform that action at this time.
0 commit comments