Add key only control
This commit is contained in:
1 parent
6d2c267121
commit
68d3ce0a22
3 files changed
+50
-3
No files matched your search
+16
-1
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
orm "go-admin/database"
|
||||
"go-admin/tools"
|
||||
_ "time"
|
||||
@@ -27,6 +28,12 @@ func (SysConfig) TableName() string {
|
||||
// Config 创建
|
||||
func (e *SysConfig) Create() (SysConfig, error) {
|
||||
var doc SysConfig
|
||||
i := 0
|
||||
orm.Eloquent.Table(e.TableName()).Where("config_name=? or config_key = ?", e.ConfigName, e.ConfigKey).Count(&i)
|
||||
if i > 0 {
|
||||
return doc, errors.New("参数名称或者参数键名已经存在!")
|
||||
}
|
||||
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
@@ -80,7 +87,7 @@ func (e *SysConfig) GetPage(pageSize int, pageIndex int) ([]SysConfig, int, erro
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Count(&count)
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
@@ -89,6 +96,14 @@ func (e *SysConfig) Update(id int) (update SysConfig, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if e.ConfigName != "" && e.ConfigName != update.ConfigName {
|
||||
return update, errors.New("参数名称不允许修改!")
|
||||
}
|
||||
|
||||
if e.ConfigKey != "" && e.ConfigKey != update.ConfigKey {
|
||||
return update, errors.New("参数键名不允许修改!")
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
|
||||
Reference in new issue
Block a user