|
@@ -8,7 +8,7 @@ import ( |
|
@@ -8,7 +8,7 @@ import ( |
8
|
"github.com/astaxie/beego/orm"
|
8
|
"github.com/astaxie/beego/orm"
|
9
|
)
|
9
|
)
|
10
|
|
10
|
|
11
|
-func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceReserveTypeList {
|
11
|
+func GetReserveTypeLsit(pageIndex int, pageSize int, companyid int64) protocol.ResponseChanceReserveTypeList {
|
12
|
rsp := protocol.ResponseChanceReserveTypeList{
|
12
|
rsp := protocol.ResponseChanceReserveTypeList{
|
13
|
ResponsePageInfo: protocol.ResponsePageInfo{
|
13
|
ResponsePageInfo: protocol.ResponsePageInfo{
|
14
|
TotalPage: 0,
|
14
|
TotalPage: 0,
|
|
@@ -22,7 +22,7 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese |
|
@@ -22,7 +22,7 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese |
22
|
err error
|
22
|
err error
|
23
|
)
|
23
|
)
|
24
|
o := orm.NewOrm()
|
24
|
o := orm.NewOrm()
|
25
|
- cnt, err = o.QueryTable(&models.ChanceReserveType{}).Count()
|
25
|
+ cnt, err = o.QueryTable(&models.ChanceReserveType{}).Filter("company_id", companyid).Count()
|
26
|
if err != nil {
|
26
|
if err != nil {
|
27
|
log.Error("获取chance_reserve_type记录数失败,err:%s", err)
|
27
|
log.Error("获取chance_reserve_type记录数失败,err:%s", err)
|
28
|
return rsp
|
28
|
return rsp
|
|
@@ -32,6 +32,7 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese |
|
@@ -32,6 +32,7 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese |
32
|
}
|
32
|
}
|
33
|
first := (pageIndex - 1) * pageSize
|
33
|
first := (pageIndex - 1) * pageSize
|
34
|
_, err = o.QueryTable(&models.ChanceReserveType{}).
|
34
|
_, err = o.QueryTable(&models.ChanceReserveType{}).
|
|
|
35
|
+ Filter("company_id", companyid).
|
35
|
OrderBy("-create_at").
|
36
|
OrderBy("-create_at").
|
36
|
Limit(pageSize, first).
|
37
|
Limit(pageSize, first).
|
37
|
All(&allData)
|
38
|
All(&allData)
|
|
@@ -50,9 +51,14 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese |
|
@@ -50,9 +51,14 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese |
50
|
return rsp
|
51
|
return rsp
|
51
|
}
|
52
|
}
|
52
|
|
53
|
|
53
|
-func AddReserveType(name string) error {
|
54
|
+func AddReserveType(name string, companyid int64) error {
|
|
|
55
|
+ has := models.HasChanceReserveTypeName(name, companyid, 0)
|
|
|
56
|
+ if has {
|
|
|
57
|
+ return protocol.NewErrWithMessage("10131")
|
|
|
58
|
+ }
|
54
|
m := &models.ChanceReserveType{
|
59
|
m := &models.ChanceReserveType{
|
55
|
- Name: name,
|
60
|
+ Name: name,
|
|
|
61
|
+ CompanyId: companyid,
|
56
|
}
|
62
|
}
|
57
|
_, err := models.AddChanceReserveType(m)
|
63
|
_, err := models.AddChanceReserveType(m)
|
58
|
if err != nil {
|
64
|
if err != nil {
|
|
@@ -61,20 +67,49 @@ func AddReserveType(name string) error { |
|
@@ -61,20 +67,49 @@ func AddReserveType(name string) error { |
61
|
return nil
|
67
|
return nil
|
62
|
}
|
68
|
}
|
63
|
|
69
|
|
64
|
-func EditReserveType(id int, name string) error {
|
|
|
65
|
- m := &models.ChanceReserveType{
|
|
|
66
|
- Id: id,
|
|
|
67
|
- Name: name,
|
70
|
+func EditReserveType(id int, name string, companyid int64) error {
|
|
|
71
|
+ has := models.HasChanceReserveTypeName(name, companyid, id)
|
|
|
72
|
+ if has {
|
|
|
73
|
+ return protocol.NewErrWithMessage("10131")
|
|
|
74
|
+ }
|
|
|
75
|
+ m := &models.ChanceReserveType{}
|
|
|
76
|
+ var err error
|
|
|
77
|
+ m, err = models.GetChanceReserveTypeById(id)
|
|
|
78
|
+ if err != nil {
|
|
|
79
|
+ log.Error("获取chance_resersve_type数据失败,err:%s", err)
|
|
|
80
|
+ return protocol.NewErrWithMessage("1")
|
|
|
81
|
+ }
|
|
|
82
|
+ if m.CompanyId != companyid {
|
|
|
83
|
+ log.Error("chance_resersve_type数据对应公司错误")
|
|
|
84
|
+ return protocol.NewErrWithMessage("1")
|
68
|
}
|
85
|
}
|
69
|
- err := models.UpdateChanceReserveType(m, []string{"Name"})
|
86
|
+ m.Name = name
|
|
|
87
|
+ err = models.UpdateChanceReserveType(m, []string{"Name"})
|
70
|
if err != nil {
|
88
|
if err != nil {
|
71
|
log.Error("更新储备池类似失败,err:%s", err)
|
89
|
log.Error("更新储备池类似失败,err:%s", err)
|
72
|
}
|
90
|
}
|
73
|
return nil
|
91
|
return nil
|
74
|
}
|
92
|
}
|
75
|
|
93
|
|
76
|
-func DeleteReserveType(id int) error {
|
|
|
77
|
- err := models.DeleteChanceReserveType(id)
|
94
|
+func DeleteReserveType(id int, companyid int64) error {
|
|
|
95
|
+ m := &models.ChanceReserveType{}
|
|
|
96
|
+ var err error
|
|
|
97
|
+ m, err = models.GetChanceReserveTypeById(id)
|
|
|
98
|
+ if err != nil {
|
|
|
99
|
+ log.Error("获取chance_resersve_type数据失败,err:%s", err)
|
|
|
100
|
+ return protocol.NewErrWithMessage("1")
|
|
|
101
|
+ }
|
|
|
102
|
+ if m.CompanyId != companyid {
|
|
|
103
|
+ log.Error("chance_resersve_type数据对应公司错误")
|
|
|
104
|
+ return protocol.NewErrWithMessage("1")
|
|
|
105
|
+ }
|
|
|
106
|
+ //是否可以被删除
|
|
|
107
|
+ o := orm.NewOrm()
|
|
|
108
|
+ has := o.QueryTable(&models.Chance{}).Filter("reserve_type_id", id).Exist()
|
|
|
109
|
+ if has {
|
|
|
110
|
+ return protocol.NewErrWithMessage("10132")
|
|
|
111
|
+ }
|
|
|
112
|
+ err = models.DeleteChanceReserveType(id)
|
78
|
if err != nil {
|
113
|
if err != nil {
|
79
|
log.Error("删除储备池类似失败,err:%s", err)
|
114
|
log.Error("删除储备池类似失败,err:%s", err)
|
80
|
}
|
115
|
}
|