...
|
...
|
@@ -8,7 +8,7 @@ import ( |
|
|
"github.com/astaxie/beego/orm"
|
|
|
)
|
|
|
|
|
|
func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceReserveTypeList {
|
|
|
func GetReserveTypeLsit(pageIndex int, pageSize int, companyid int64) protocol.ResponseChanceReserveTypeList {
|
|
|
rsp := protocol.ResponseChanceReserveTypeList{
|
|
|
ResponsePageInfo: protocol.ResponsePageInfo{
|
|
|
TotalPage: 0,
|
...
|
...
|
@@ -22,7 +22,7 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese |
|
|
err error
|
|
|
)
|
|
|
o := orm.NewOrm()
|
|
|
cnt, err = o.QueryTable(&models.ChanceReserveType{}).Count()
|
|
|
cnt, err = o.QueryTable(&models.ChanceReserveType{}).Filter("company_id", companyid).Count()
|
|
|
if err != nil {
|
|
|
log.Error("获取chance_reserve_type记录数失败,err:%s", err)
|
|
|
return rsp
|
...
|
...
|
@@ -32,6 +32,7 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese |
|
|
}
|
|
|
first := (pageIndex - 1) * pageSize
|
|
|
_, err = o.QueryTable(&models.ChanceReserveType{}).
|
|
|
Filter("company_id", companyid).
|
|
|
OrderBy("-create_at").
|
|
|
Limit(pageSize, first).
|
|
|
All(&allData)
|
...
|
...
|
@@ -50,9 +51,14 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese |
|
|
return rsp
|
|
|
}
|
|
|
|
|
|
func AddReserveType(name string) error {
|
|
|
func AddReserveType(name string, companyid int64) error {
|
|
|
has := models.HasChanceReserveTypeName(name, companyid, 0)
|
|
|
if has {
|
|
|
return protocol.NewErrWithMessage("10131")
|
|
|
}
|
|
|
m := &models.ChanceReserveType{
|
|
|
Name: name,
|
|
|
Name: name,
|
|
|
CompanyId: companyid,
|
|
|
}
|
|
|
_, err := models.AddChanceReserveType(m)
|
|
|
if err != nil {
|
...
|
...
|
@@ -61,20 +67,49 @@ func AddReserveType(name string) error { |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func EditReserveType(id int, name string) error {
|
|
|
m := &models.ChanceReserveType{
|
|
|
Id: id,
|
|
|
Name: name,
|
|
|
func EditReserveType(id int, name string, companyid int64) error {
|
|
|
has := models.HasChanceReserveTypeName(name, companyid, id)
|
|
|
if has {
|
|
|
return protocol.NewErrWithMessage("10131")
|
|
|
}
|
|
|
m := &models.ChanceReserveType{}
|
|
|
var err error
|
|
|
m, err = models.GetChanceReserveTypeById(id)
|
|
|
if err != nil {
|
|
|
log.Error("获取chance_resersve_type数据失败,err:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if m.CompanyId != companyid {
|
|
|
log.Error("chance_resersve_type数据对应公司错误")
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
err := models.UpdateChanceReserveType(m, []string{"Name"})
|
|
|
m.Name = name
|
|
|
err = models.UpdateChanceReserveType(m, []string{"Name"})
|
|
|
if err != nil {
|
|
|
log.Error("更新储备池类似失败,err:%s", err)
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func DeleteReserveType(id int) error {
|
|
|
err := models.DeleteChanceReserveType(id)
|
|
|
func DeleteReserveType(id int, companyid int64) error {
|
|
|
m := &models.ChanceReserveType{}
|
|
|
var err error
|
|
|
m, err = models.GetChanceReserveTypeById(id)
|
|
|
if err != nil {
|
|
|
log.Error("获取chance_resersve_type数据失败,err:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if m.CompanyId != companyid {
|
|
|
log.Error("chance_resersve_type数据对应公司错误")
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
//是否可以被删除
|
|
|
o := orm.NewOrm()
|
|
|
has := o.QueryTable(&models.Chance{}).Filter("reserve_type_id", id).Exist()
|
|
|
if has {
|
|
|
return protocol.NewErrWithMessage("10132")
|
|
|
}
|
|
|
err = models.DeleteChanceReserveType(id)
|
|
|
if err != nil {
|
|
|
log.Error("删除储备池类似失败,err:%s", err)
|
|
|
}
|
...
|
...
|
|