Browse Source

!463 有权重字段时,模型添加数据后会自动用ID替换,导致添加时设置的权重值无法保存
Merge pull request !463 from simon429/develop

Karson 1 year ago
parent
commit
1a8f81cc35

+ 4 - 2
application/admin/command/Crud/stubs/mixins/modelinit.stub

@@ -2,7 +2,9 @@
     protected static function init()
     {
         self::afterInsert(function ($row) {
-            $pk = $row->getPk();
-            $row->getQuery()->where($pk, $row[$pk])->update(['{%order%}' => $row[$pk]]);
+            if (!$row['{%order%}']) {
+                $pk = $row->getPk();
+                $row->getQuery()->where($pk, $row[$pk])->update(['{%order%}' => $row[$pk]]);
+            }
         });
     }

+ 4 - 2
application/admin/model/UserRule.php

@@ -23,8 +23,10 @@ class UserRule extends Model
     protected static function init()
     {
         self::afterInsert(function ($row) {
-            $pk = $row->getPk();
-            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
+            if (!$row['weigh']) {
+                $pk = $row->getPk();
+                $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
+            }
         });
     }
 

+ 3 - 1
application/common/model/Category.php

@@ -24,7 +24,9 @@ class Category extends Model
     protected static function init()
     {
         self::afterInsert(function ($row) {
-            $row->save(['weigh' => $row['id']]);
+            if (!$row['weigh']) {
+                $row->save(['weigh' => $row['id']]);
+            }
         });
     }