yxh пре 6 година
родитељ
комит
a8276bbde0

+ 94 - 0
app/controller/admin/config_params.go

@@ -0,0 +1,94 @@
+package admin
+
+import (
+	"gfast/app/model/admin/sys_config"
+	"gfast/app/service/admin/params_service"
+	"gfast/app/service/admin/user_service"
+	"gfast/library/response"
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/net/ghttp"
+	"github.com/gogf/gf/util/gvalid"
+)
+
+type Params struct{}
+
+//参数列表
+func (c *Params) ParamsList(r *ghttp.Request) {
+	var req *sys_config.SelectPageReq
+	//获取参数
+	if err := r.Parse(&req); err != nil {
+		response.FailJson(true, r, err.(*gvalid.Error).FirstString())
+	}
+	total, page, list, err := params_service.SelectListByPage(req)
+	if err != nil {
+		response.FailJson(true, r, err.Error())
+	}
+	result := g.Map{
+		"currentPage": page,
+		"total":       total,
+		"list":        list,
+		"searchTypes": map[string]string{"": "所有", "0": "否", "1": "是"},
+	}
+	response.SusJson(true, r, "字典列表", result)
+}
+
+//添加参数
+func (c *Params) ParamsAdd(r *ghttp.Request) {
+	if r.Method == "POST" {
+		var req *sys_config.AddReq
+		//获取参数
+		if err := r.Parse(&req); err != nil {
+			response.FailJson(true, r, err.(*gvalid.Error).FirstString())
+		}
+		err := params_service.CheckConfigKeyUniqueAll(req.ConfigKey)
+		if err != nil {
+			response.FailJson(true, r, err.Error())
+		}
+		userId := user_service.GetLoginID(r) //获取登陆用户id
+		_, err = params_service.AddSave(req, userId)
+		if err != nil {
+			response.FailJson(true, r, err.Error())
+		}
+		response.SusJson(true, r, "添加参数成功")
+	}
+}
+
+//修改参数
+func (c *Params) ParamsEdit(r *ghttp.Request) {
+	if r.Method == "POST" {
+		var req *sys_config.EditReq
+		//获取参数
+		if err := r.Parse(&req); err != nil {
+			response.FailJson(true, r, err.(*gvalid.Error).FirstString())
+		}
+		err := params_service.CheckConfigKeyUnique(req.ConfigKey, req.ConfigId)
+		if err != nil {
+			response.FailJson(true, r, err.Error())
+		}
+		userId := user_service.GetLoginID(r) //获取登陆用户id
+		_, err = params_service.EditSave(req, userId)
+		if err != nil {
+			response.FailJson(true, r, err.Error())
+		}
+		response.SusJson(true, r, "修改参数成功")
+	}
+	id := r.GetInt("id")
+	params, err := params_service.GetParamsById(id)
+	if err != nil {
+		response.FailJson(true, r, err.Error())
+	}
+	response.SusJson(true, r, "ok", g.Map{"params": params})
+}
+
+//删除参数
+func (c *Params) ParamsDelete(r *ghttp.Request) {
+	ids := r.GetInts("ids")
+	if len(ids) == 0 {
+		response.FailJson(true, r, "删除失败")
+	}
+	err := params_service.DeleteByIds(ids)
+	if err != nil {
+		response.FailJson(true, r, "删除失败")
+	}
+	response.SusJson(true, r, "删除成功")
+}

+ 28 - 0
app/model/admin/sys_config/sys_config.go

@@ -0,0 +1,28 @@
+package sys_config
+
+// Fill with you ideas below.
+//新增页面请求参数
+type AddReq struct {
+	ConfigName  string `p:"configName"  v:"required#参数名称不能为空"`
+	ConfigKey   string `p:"configKey"  v:"required#参数键名不能为空"`
+	ConfigValue string `p:"configValue"  v:"required#参数键值不能为空"`
+	ConfigType  int    `p:"configType"    v:"required|in:0,1#系统内置不能为空|系统内置类型只能为0或1"`
+	Remark      string `p:"remark"`
+}
+
+//修改页面请求参数
+type EditReq struct {
+	ConfigId int64 `p:"configId" v:"required|min:1#主键ID不能为空|主键ID参数错误"`
+	AddReq
+}
+
+//分页请求参数
+type SelectPageReq struct {
+	ConfigName string `p:"configName"` //参数名称
+	ConfigKey  string `p:"configKey"`  //参数键名
+	ConfigType string `p:"configType"` //状态
+	BeginTime  string `p:"beginTime"`  //开始时间
+	EndTime    string `p:"endTime"`    //结束时间
+	PageNum    int    `p:"page"`       //当前页码
+	PageSize   int    `p:"pageSize"`   //每页数
+}

+ 61 - 0
app/model/admin/sys_config/sys_config_entity.go

@@ -0,0 +1,61 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. You may not really want to edit it.
+// ==========================================================================
+
+package sys_config
+
+import (
+	"database/sql"
+	"github.com/gogf/gf/database/gdb"
+)
+
+// Entity is the golang structure for table qxkj_sys_config.
+type Entity struct {
+	ConfigId    uint   `orm:"config_id,primary" json:"config_id"`    // 参数主键
+	ConfigName  string `orm:"config_name"       json:"config_name"`  // 参数名称
+	ConfigKey   string `orm:"config_key"        json:"config_key"`   // 参数键名
+	ConfigValue string `orm:"config_value"      json:"config_value"` // 参数键值
+	ConfigType  int    `orm:"config_type"       json:"config_type"`  // 系统内置(Y是 N否)
+	CreateBy    uint   `orm:"create_by"         json:"create_by"`    // 创建者
+	CreateTime  uint64 `orm:"create_time"       json:"create_time"`  // 创建时间
+	UpdateBy    uint   `orm:"update_by"         json:"update_by"`    // 更新者
+	UpdateTime  uint64 `orm:"update_time"       json:"update_time"`  // 更新时间
+	Remark      string `orm:"remark"            json:"remark"`       // 备注
+}
+
+// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
+// the data and where attributes for empty values.
+func (r *Entity) OmitEmpty() *arModel {
+	return Model.Data(r).OmitEmpty()
+}
+
+// Inserts does "INSERT...INTO..." statement for inserting current object into table.
+func (r *Entity) Insert() (result sql.Result, err error) {
+	return Model.Data(r).Insert()
+}
+
+// Replace does "REPLACE...INTO..." statement for inserting current object into table.
+// If there's already another same record in the table (it checks using primary key or unique index),
+// it deletes it and insert this one.
+func (r *Entity) Replace() (result sql.Result, err error) {
+	return Model.Data(r).Replace()
+}
+
+// Save does "INSERT...INTO..." statement for inserting/updating current object into table.
+// It updates the record if there's already another same record in the table
+// (it checks using primary key or unique index).
+func (r *Entity) Save() (result sql.Result, err error) {
+	return Model.Data(r).Save()
+}
+
+// Update does "UPDATE...WHERE..." statement for updating current object from table.
+// It updates the record if there's already another same record in the table
+// (it checks using primary key or unique index).
+func (r *Entity) Update() (result sql.Result, err error) {
+	return Model.Data(r).Where(gdb.GetWhereConditionOfStruct(r)).Update()
+}
+
+// Delete does "DELETE FROM...WHERE..." statement for deleting current object from table.
+func (r *Entity) Delete() (result sql.Result, err error) {
+	return Model.Where(gdb.GetWhereConditionOfStruct(r)).Delete()
+}

+ 367 - 0
app/model/admin/sys_config/sys_config_model.go

@@ -0,0 +1,367 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. You may not really want to edit it.
+// ==========================================================================
+
+package sys_config
+
+import (
+	"database/sql"
+	"github.com/gogf/gf/database/gdb"
+	"github.com/gogf/gf/frame/g"
+	"time"
+)
+
+// arModel is a active record design model for table qxkj_sys_config operations.
+type arModel struct {
+	M *gdb.Model
+}
+
+var (
+	// Table is the table name of qxkj_sys_config.
+	Table = "qxkj_sys_config"
+	// Model is the model object of qxkj_sys_config.
+	Model = &arModel{g.DB("default").Table(Table).Safe()}
+)
+
+// FindOne is a convenience method for Model.FindOne.
+// See Model.FindOne.
+func FindOne(where ...interface{}) (*Entity, error) {
+	return Model.FindOne(where...)
+}
+
+// FindAll is a convenience method for Model.FindAll.
+// See Model.FindAll.
+func FindAll(where ...interface{}) ([]*Entity, error) {
+	return Model.FindAll(where...)
+}
+
+// FindValue is a convenience method for Model.FindValue.
+// See Model.FindValue.
+func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
+	return Model.FindValue(fieldsAndWhere...)
+}
+
+// FindCount is a convenience method for Model.FindCount.
+// See Model.FindCount.
+func FindCount(where ...interface{}) (int, error) {
+	return Model.FindCount(where...)
+}
+
+// Insert is a convenience method for Model.Insert.
+func Insert(data ...interface{}) (result sql.Result, err error) {
+	return Model.Insert(data...)
+}
+
+// Replace is a convenience method for Model.Replace.
+func Replace(data ...interface{}) (result sql.Result, err error) {
+	return Model.Replace(data...)
+}
+
+// Save is a convenience method for Model.Save.
+func Save(data ...interface{}) (result sql.Result, err error) {
+	return Model.Save(data...)
+}
+
+// Update is a convenience method for Model.Update.
+func Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
+	return Model.Update(dataAndWhere...)
+}
+
+// Delete is a convenience method for Model.Delete.
+func Delete(where ...interface{}) (result sql.Result, err error) {
+	return Model.Delete(where...)
+}
+
+// As sets an alias name for current table.
+func (m *arModel) As(as string) *arModel {
+	return &arModel{m.M.As(as)}
+}
+
+// TX sets the transaction for current operation.
+func (m *arModel) TX(tx *gdb.TX) *arModel {
+	return &arModel{m.M.TX(tx)}
+}
+
+// Master marks the following operation on master node.
+func (m *arModel) Master() *arModel {
+	return &arModel{m.M.Master()}
+}
+
+// Slave marks the following operation on slave node.
+// Note that it makes sense only if there's any slave node configured.
+func (m *arModel) Slave() *arModel {
+	return &arModel{m.M.Slave()}
+}
+
+// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
+func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
+	return &arModel{m.M.LeftJoin(joinTable, on)}
+}
+
+// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
+func (m *arModel) RightJoin(joinTable string, on string) *arModel {
+	return &arModel{m.M.RightJoin(joinTable, on)}
+}
+
+// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
+func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
+	return &arModel{m.M.InnerJoin(joinTable, on)}
+}
+
+// Fields sets the operation fields of the model, multiple fields joined using char ','.
+func (m *arModel) Fields(fields string) *arModel {
+	return &arModel{m.M.Fields(fields)}
+}
+
+// FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
+func (m *arModel) FieldsEx(fields string) *arModel {
+	return &arModel{m.M.FieldsEx(fields)}
+}
+
+// Option sets the extra operation option for the model.
+func (m *arModel) Option(option int) *arModel {
+	return &arModel{m.M.Option(option)}
+}
+
+// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
+// the data and where attributes for empty values.
+func (m *arModel) OmitEmpty() *arModel {
+	return &arModel{m.M.OmitEmpty()}
+}
+
+// Filter marks filtering the fields which does not exist in the fields of the operated table.
+func (m *arModel) Filter() *arModel {
+	return &arModel{m.M.Filter()}
+}
+
+// Where sets the condition statement for the model. The parameter <where> can be type of
+// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
+// multiple conditions will be joined into where statement using "AND".
+// Eg:
+// Where("uid=10000")
+// Where("uid", 10000)
+// Where("money>? AND name like ?", 99999, "vip_%")
+// Where("uid", 1).Where("name", "john")
+// Where("status IN (?)", g.Slice{1,2,3})
+// Where("age IN(?,?)", 18, 50)
+// Where(User{ Id : 1, UserName : "john"})
+func (m *arModel) Where(where interface{}, args ...interface{}) *arModel {
+	return &arModel{m.M.Where(where, args...)}
+}
+
+// And adds "AND" condition to the where statement.
+func (m *arModel) And(where interface{}, args ...interface{}) *arModel {
+	return &arModel{m.M.And(where, args...)}
+}
+
+// Or adds "OR" condition to the where statement.
+func (m *arModel) Or(where interface{}, args ...interface{}) *arModel {
+	return &arModel{m.M.Or(where, args...)}
+}
+
+// Group sets the "GROUP BY" statement for the model.
+func (m *arModel) Group(groupBy string) *arModel {
+	return &arModel{m.M.Group(groupBy)}
+}
+
+// Order sets the "ORDER BY" statement for the model.
+func (m *arModel) Order(orderBy string) *arModel {
+	return &arModel{m.M.Order(orderBy)}
+}
+
+// Limit sets the "LIMIT" statement for the model.
+// The parameter <limit> can be either one or two number, if passed two number is passed,
+// it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
+// statement.
+func (m *arModel) Limit(limit ...int) *arModel {
+	return &arModel{m.M.Limit(limit...)}
+}
+
+// Offset sets the "OFFSET" statement for the model.
+// It only makes sense for some databases like SQLServer, PostgreSQL, etc.
+func (m *arModel) Offset(offset int) *arModel {
+	return &arModel{m.M.Offset(offset)}
+}
+
+// Page sets the paging number for the model.
+// The parameter <page> is started from 1 for paging.
+// Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
+func (m *arModel) Page(page, limit int) *arModel {
+	return &arModel{m.M.Page(page, limit)}
+}
+
+// Batch sets the batch operation number for the model.
+func (m *arModel) Batch(batch int) *arModel {
+	return &arModel{m.M.Batch(batch)}
+}
+
+// Cache sets the cache feature for the model. It caches the result of the sql, which means
+// if there's another same sql request, it just reads and returns the result from cache, it
+// but not committed and executed into the database.
+//
+// If the parameter <duration> < 0, which means it clear the cache with given <name>.
+// If the parameter <duration> = 0, which means it never expires.
+// If the parameter <duration> > 0, which means it expires after <duration>.
+//
+// The optional parameter <name> is used to bind a name to the cache, which means you can later
+// control the cache like changing the <duration> or clearing the cache with specified <name>.
+//
+// Note that, the cache feature is disabled if the model is operating on a transaction.
+func (m *arModel) Cache(expire time.Duration, name ...string) *arModel {
+	return &arModel{m.M.Cache(expire, name...)}
+}
+
+// Data sets the operation data for the model.
+// The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
+// Eg:
+// Data("uid=10000")
+// Data("uid", 10000)
+// Data(g.Map{"uid": 10000, "name":"john"})
+// Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
+func (m *arModel) Data(data ...interface{}) *arModel {
+	return &arModel{m.M.Data(data...)}
+}
+
+// Insert does "INSERT INTO ..." statement for the model.
+// The optional parameter <data> is the same as the parameter of Model.Data function,
+// see Model.Data.
+func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) {
+	return m.M.Insert(data...)
+}
+
+// Replace does "REPLACE INTO ..." statement for the model.
+// The optional parameter <data> is the same as the parameter of Model.Data function,
+// see Model.Data.
+func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) {
+	return m.M.Replace(data...)
+}
+
+// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model.
+// It updates the record if there's primary or unique index in the saving data,
+// or else it inserts a new record into the table.
+//
+// The optional parameter <data> is the same as the parameter of Model.Data function,
+// see Model.Data.
+func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) {
+	return m.M.Save(data...)
+}
+
+// Update does "UPDATE ... " statement for the model.
+//
+// If the optional parameter <dataAndWhere> is given, the dataAndWhere[0] is the updated
+// data field, and dataAndWhere[1:] is treated as where condition fields.
+// Also see Model.Data and Model.Where functions.
+func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
+	return m.M.Update(dataAndWhere...)
+}
+
+// Delete does "DELETE FROM ... " statement for the model.
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) {
+	return m.M.Delete(where...)
+}
+
+// Count does "SELECT COUNT(x) FROM ..." statement for the model.
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+func (m *arModel) Count(where ...interface{}) (int, error) {
+	return m.M.Count(where...)
+}
+
+// All does "SELECT FROM ..." statement for the model.
+// It retrieves the records from table and returns the result as []*Entity.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+func (m *arModel) All(where ...interface{}) ([]*Entity, error) {
+	all, err := m.M.All(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*Entity
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// One retrieves one record from table and returns the result as *Entity.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+func (m *arModel) One(where ...interface{}) (*Entity, error) {
+	one, err := m.M.One(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *Entity
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// Value retrieves a specified record value from table and returns the result as interface type.
+// It returns nil if there's no record found with the given conditions from table.
+//
+// If the optional parameter <fieldsAndWhere> is given, the fieldsAndWhere[0] is the selected fields
+// and fieldsAndWhere[1:] is treated as where condition fields.
+// Also see Model.Fields and Model.Where functions.
+func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) {
+	return m.M.Value(fieldsAndWhere...)
+}
+
+// FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
+// Also see Model.WherePri and Model.One.
+func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
+	one, err := m.M.FindOne(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *Entity
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindAll retrieves and returns Result by by Model.WherePri and Model.All.
+// Also see Model.WherePri and Model.All.
+func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
+	all, err := m.M.FindAll(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*Entity
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// FindValue retrieves and returns single field value by Model.WherePri and Model.Value.
+// Also see Model.WherePri and Model.Value.
+func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
+	return m.M.FindValue(fieldsAndWhere...)
+}
+
+// FindCount retrieves and returns the record number by Model.WherePri and Model.Count.
+// Also see Model.WherePri and Model.Count.
+func (m *arModel) FindCount(where ...interface{}) (int, error) {
+	return m.M.FindCount(where...)
+}
+
+// Chunk iterates the table with given size and callback function.
+func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
+	m.M.Chunk(limit, func(result gdb.Result, err error) bool {
+		var entities []*Entity
+		err = result.Structs(&entities)
+		if err == sql.ErrNoRows {
+			return false
+		}
+		return callback(entities, err)
+	})
+}

+ 151 - 0
app/service/admin/params_service/params.go

@@ -0,0 +1,151 @@
+package params_service
+
+import (
+	"gfast/app/model/admin/sys_config"
+	"gfast/library/utils"
+	"github.com/gogf/gf/errors/gerror"
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/os/gtime"
+	"github.com/gogf/gf/util/gconv"
+)
+
+//保存参数
+func AddSave(req *sys_config.AddReq, userId int) (id int64, err error) {
+	var entity sys_config.Entity
+	entity.ConfigName = req.ConfigName
+	entity.ConfigKey = req.ConfigKey
+	entity.ConfigType = req.ConfigType
+	entity.ConfigValue = req.ConfigValue
+	entity.Remark = req.Remark
+	entity.CreateTime = gconv.Uint64(gtime.Timestamp())
+	entity.CreateBy = gconv.Uint(userId)
+	result, err := entity.Insert()
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("保存失败")
+	}
+	id, err = result.LastInsertId()
+	if err != nil {
+		g.Log().Error()
+		err = gerror.New("获取插入的主键ID失败")
+	}
+	return
+}
+
+//修改保存
+func EditSave(req *sys_config.EditReq, userId int) (int64, error) {
+	entity, err := GetParamsById(gconv.Int(req.ConfigId))
+	if err != nil {
+		return 0, err
+	}
+	entity.ConfigName = req.ConfigName
+	entity.ConfigKey = req.ConfigKey
+	entity.ConfigType = req.ConfigType
+	entity.ConfigValue = req.ConfigValue
+	entity.Remark = req.Remark
+	entity.UpdateTime = gconv.Uint64(gtime.Timestamp())
+	entity.UpdateBy = gconv.Uint(userId)
+	result, err := entity.Update()
+	if err != nil {
+		g.Log().Error(err)
+		return 0, gerror.New("修改失败")
+	}
+	rows, err := result.RowsAffected()
+	if err != nil {
+		g.Log().Error(err)
+		return 0, gerror.New("修改失败")
+	}
+	return rows, nil
+}
+
+//验证参数键名是否存在
+func CheckConfigKeyUniqueAll(configKey string) error {
+	entity, err := sys_config.Model.FindOne("config_key", configKey)
+	if err != nil {
+		g.Log().Error(err)
+		return gerror.New("校验数据失败")
+	}
+	if entity != nil {
+		return gerror.New("参数键名已经存在")
+	}
+	return nil
+}
+
+//列表分页搜索查询
+func SelectListByPage(req *sys_config.SelectPageReq) (total, page int, list []*sys_config.Entity, err error) {
+	model := sys_config.Model
+	if req != nil {
+		if req.ConfigName != "" {
+			model = model.Where("config_name like ?", "%"+req.ConfigName+"%")
+		}
+		if req.ConfigType != "" {
+			model.Where("status = ", gconv.Int(req.ConfigType))
+		}
+		if req.ConfigKey != "" {
+			model.Where("config_key like ?", "%"+req.ConfigKey+"%")
+		}
+		if req.BeginTime != "" {
+			model = model.Where("create_time >= ? ", utils.StrToTimestamp(req.BeginTime))
+		}
+
+		if req.EndTime != "" {
+			model = model.Where("create_time<=?", utils.StrToTimestamp(req.EndTime))
+		}
+	}
+	total, err = model.Count()
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("获取总行数失败")
+		return
+	}
+	if req.PageNum == 0 {
+		req.PageNum = 1
+	}
+	page = req.PageNum
+	if req.PageSize == 0 {
+		req.PageSize = utils.AdminPageNum
+	}
+	list, err = model.Page(page, req.PageSize).Order("config_id asc").All()
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("获取数据失败")
+		return
+	}
+	return
+}
+
+//通过id查询参数数据
+func GetParamsById(id int) (entity *sys_config.Entity, err error) {
+	entity, err = sys_config.Model.FindOne("config_id", id)
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("查询参数数据出错")
+	}
+	if entity == nil {
+		err = gerror.New("未查询到参数数据")
+	}
+	return
+}
+
+//检查键是否已经存在
+func CheckConfigKeyUnique(configKey string, configId int64) error {
+	entity, err := sys_config.Model.FindOne("config_key=? and config_id!=?", configKey, configId)
+	if err != nil {
+		g.Log().Error(err)
+		return gerror.New("校验数据失败")
+	}
+	if entity != nil {
+		return gerror.New("参数键名已经存在")
+	}
+	return nil
+}
+
+//删除参数
+func DeleteByIds(ids []int) error {
+	_, err := sys_config.Model.Delete("config_id in (?)", ids)
+	if err != nil {
+		g.Log().Error(err)
+		return gerror.New("删除失败")
+	}
+	return nil
+}

+ 1 - 0
router/router.go

@@ -19,4 +19,5 @@ func init() {
 	systemGroup.ALL("/cms", new(admin.CmsMenu))
 	systemGroup.ALL("/cms", new(admin.CmsNews))
 	systemGroup.ALL("/config", new(admin.Dict))
+	systemGroup.ALL("/config", new(admin.Params))
 }