mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 18:20:50 +00:00
Add key only control
This commit is contained in:
+17
-1
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
orm "go-admin/database"
|
||||
"go-admin/tools"
|
||||
)
|
||||
@@ -24,6 +25,13 @@ func (DictType) TableName() string {
|
||||
|
||||
func (e *DictType) Create() (DictType, error) {
|
||||
var doc DictType
|
||||
|
||||
i := 0
|
||||
orm.Eloquent.Table(e.TableName()).Where("dict_name=? or dict_type = ?", e.DictName, e.DictType).Count(&i)
|
||||
if i > 0 {
|
||||
return doc, errors.New("字典名称或者字典类型已经存在!")
|
||||
}
|
||||
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
@@ -94,7 +102,7 @@ func (e *DictType) GetPage(pageSize int, pageIndex int) ([]DictType, int, error)
|
||||
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
|
||||
}
|
||||
|
||||
@@ -103,6 +111,14 @@ func (e *DictType) Update(id int) (update DictType, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if e.DictName != "" && e.DictName != update.DictName {
|
||||
return update, errors.New("名称不允许修改!")
|
||||
}
|
||||
|
||||
if e.DictType != "" && e.DictType != update.DictType {
|
||||
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