achievement.go
7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package controllers
import (
"encoding/json"
"fmt"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
serveachievement "oppmg/services/achievement"
"github.com/astaxie/beego/orm"
)
type AchievementController struct {
BaseController
}
//AchievementList 成果列表
//@router /achievement/list
func (c AchievementController) AchievementList() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
protocol.RequestPageInfo
Status int `json:"status"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
rspdata := serveachievement.GetAchievementList(param.PageIndex, param.PageSize, companyid, param.Status)
msg = protocol.NewPageDataResponse(rspdata, nil)
return
}
//AddAchievement 添加成果列表
//@router /achievement/add
func (c AchievementController) AddAchievement() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var param protocol.RequestAddAchievement
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
if len(param.ChanceData) == 0 {
log.Error("len(param.ChanceData) == 0 ")
msg = protocol.BadRequestParam("11102")
return
}
if param.ChanceTypeId == 0 {
log.Error(" param.ChanceTypeId == 0 ")
msg = protocol.BadRequestParam("11101")
return
}
if param.GraspScore < 0 || param.GraspScore > 100 {
log.Error(" param.GraspScore < 0 || param.GraspScore > 100 ")
msg = protocol.BadRequestParam("11104")
return
}
if param.UserGraspScore < 0 || param.UserGraspScore > 100 {
log.Error("param.UserGraspScore < 0 || param.UserGraspScore > 100")
msg = protocol.BadRequestParam("11105")
}
var providerScore float64
for _, v := range param.Provider {
providerScore += v.UserGraspScore
}
remainScore := param.GraspScore - param.UserGraspScore - providerScore
if remainScore < 0 {
log.Error("分配的总分不可大于把握分")
msg = protocol.BadRequestParam("11105")
return
}
companyid := c.GetCompanyId()
err := serveachievement.AddAchievement(¶m, companyid)
msg = protocol.NewReturnResponse(nil, err)
return
}
//EditAchievement 编辑成果
//@router /achievement/edit
func (c AchievementController) EditAchievement() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var param protocol.RequestEditAchievement
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
if len(param.ChanceData) == 0 {
log.Error("len(param.ChanceData) == 0 ")
msg = protocol.BadRequestParam("11102")
return
}
if param.ChanceTypeId == 0 {
log.Error(" param.ChanceTypeId == 0 ")
msg = protocol.BadRequestParam("11101")
return
}
if param.GraspScore < 0 || param.GraspScore > 100 {
log.Error(" param.GraspScore < 0 || param.GraspScore > 100 ")
msg = protocol.BadRequestParam("11104")
return
}
if param.UserGraspScore < 0 || param.UserGraspScore > 100 {
log.Error("param.UserGraspScore < 0 || param.UserGraspScore > 100")
msg = protocol.BadRequestParam("11105")
}
var providerScore float64
for _, v := range param.Provider {
providerScore += v.UserGraspScore
}
remainScore := param.GraspScore - param.UserGraspScore - providerScore
if remainScore < 0 {
log.Error("分配的总分不可大于把握分")
msg = protocol.BadRequestParam("11105")
return
}
companyid := c.GetCompanyId()
err := serveachievement.EditAchievement(¶m, companyid)
msg = protocol.NewReturnResponse(nil, err)
return
}
//EditAchievement 成果详情
//@router /achievement/info
func (c AchievementController) AchievementInfo() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Id int64 `json:"id"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
rspData := serveachievement.GetAchievementInfo(param.Id, companyid)
msg = protocol.NewReturnResponse(rspData, nil)
return
}
//EditAchievement 删除成果
//@router /achievement/delete
func (c AchievementController) DeleteAchievement() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Id int64 `json:"id"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
var (
err error
achievementData *models.Achievement
)
achievementData, err = models.GetAchievementById(param.Id)
if err != nil {
log.Error("获取achievement数据失败:%s", err)
msg = protocol.BadRequestParam("1")
return
}
if achievementData.CompanyId != companyid {
log.Error("achievement数据公司不匹配")
msg = protocol.BadRequestParam("1")
return
}
achievementData.Status = models.ACHIEVEMENT_STATUS_DEL
o := orm.NewOrm()
o.Begin()
err = models.UpdateAchievementById(achievementData, []string{"Status"})
if err != nil {
o.Rollback()
log.Error("更新achievement数据失败:%s", err)
}
err = models.IncreaseAchevementScore(companyid, -achievementData.GraspScoreRemain, o)
if err != nil {
o.Rollback()
log.Error("更新福利池失败数据失败:%s", err)
}
o.Commit()
msg = protocol.NewReturnResponse(nil, nil)
return
}
//EditAchievement 显示隐藏成果
//@router /achievement/forbid_allow
func (c AchievementController) ForbidAllowAchievement() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Id int64 `json:"id"`
Status int8 `json:"status"` //[1:显示][2:隐藏]
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
if param.Status != 1 && param.Status != 2 {
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
var (
err error
achievementData *models.Achievement
)
achievementData, err = models.GetAchievementById(param.Id)
if err != nil {
log.Error("获取achievement数据失败:%s", err)
msg = protocol.BadRequestParam("1")
return
}
if achievementData.CompanyId != companyid {
log.Error("achievement数据公司不匹配")
msg = protocol.BadRequestParam("1")
return
}
achievementData.Status = param.Status
err = models.UpdateAchievementById(achievementData, []string{"Status"})
if err != nil {
log.Error("更新achievement数据失败:%s", err)
}
msg = protocol.NewReturnResponse(nil, nil)
return
}
//AchievementScoreRemain 获取福利池分数
//@router /achievement/remain/score
func (c AchievementController) AchievementScoreRemain() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
companyid := c.GetCompanyId()
scoreData, err := models.GetAchevementScoreByCompanyId(companyid)
rspData := map[string]string{
"score": "0",
}
if err == nil {
rspData["score"] = fmt.Sprintf("%.1f", scoreData.GraspScoreRemain)
}
msg = protocol.NewReturnResponse(rspData, nil)
return
}