...
|
...
|
@@ -25,6 +25,7 @@ func addAchievementProvider(addData []protocol.AchievementProvider, achievementI |
|
|
AchievementId: achievementId,
|
|
|
UserCompanyId: v.UserCompanyId,
|
|
|
UserGraspScore: v.UserGraspScore,
|
|
|
DepartmentId: v.DepartmentId,
|
|
|
CreateAt: nowTime,
|
|
|
}
|
|
|
providerList = append(providerList, m)
|
...
|
...
|
@@ -54,6 +55,10 @@ func addAchievementChance(addData []protocol.AchievementChance, achievementId in |
|
|
return err
|
|
|
}
|
|
|
|
|
|
func achievementGraspScoreRemain(graspScore, userGraspScore, providerScoreAll float64) float64 {
|
|
|
return graspScore - userGraspScore - providerScoreAll
|
|
|
}
|
|
|
|
|
|
//AddAchievement 添加成果
|
|
|
func AddAchievement(addData *protocol.RequestAddAchievement, companyid int64) error {
|
|
|
var (
|
...
|
...
|
@@ -61,18 +66,24 @@ func AddAchievement(addData *protocol.RequestAddAchievement, companyid int64) er |
|
|
err error
|
|
|
)
|
|
|
nowTime := time.Now()
|
|
|
var providerScore float64
|
|
|
for _, v := range addData.Provider {
|
|
|
providerScore += v.UserGraspScore
|
|
|
}
|
|
|
scoreRemain := achievementGraspScoreRemain(addData.GraspScore, addData.UserGraspScore, providerScore)
|
|
|
achievementData = &models.Achievement{
|
|
|
CompanyId: companyid,
|
|
|
DepartmentId: addData.DepartmentId,
|
|
|
UserCompanyId: addData.UserCompanyId,
|
|
|
ChanceTypeId: addData.ChanceTypeId,
|
|
|
AuditTemplateId: addData.AuditTemplateId,
|
|
|
SourceContent: addData.SourceContent,
|
|
|
GraspScore: addData.GraspScore,
|
|
|
UserGraspScore: addData.UserGraspScore,
|
|
|
CreateAt: nowTime,
|
|
|
UpdateAt: nowTime,
|
|
|
Status: models.ACHIEVEMENT_STATUS_YES,
|
|
|
CompanyId: companyid,
|
|
|
DepartmentId: addData.DepartmentId,
|
|
|
UserCompanyId: addData.UserCompanyId,
|
|
|
ChanceTypeId: addData.ChanceTypeId,
|
|
|
AuditTemplateId: addData.AuditTemplateId,
|
|
|
SourceContent: addData.SourceContent,
|
|
|
GraspScore: addData.GraspScore,
|
|
|
UserGraspScore: addData.UserGraspScore,
|
|
|
CreateAt: nowTime,
|
|
|
UpdateAt: nowTime,
|
|
|
Status: models.ACHIEVEMENT_STATUS_YES,
|
|
|
GraspScoreRemain: scoreRemain,
|
|
|
}
|
|
|
if imgData, err := json.Marshal(addData.Images); err == nil {
|
|
|
achievementData.Images = string(imgData)
|
...
|
...
|
@@ -105,12 +116,8 @@ func AddAchievement(addData *protocol.RequestAddAchievement, companyid int64) er |
|
|
}
|
|
|
}
|
|
|
//操作achievement_score福利池数据
|
|
|
var providerScore float64
|
|
|
for _, v := range addData.Provider {
|
|
|
providerScore += v.UserGraspScore
|
|
|
}
|
|
|
addScore := addData.GraspScore - addData.UserGraspScore - providerScore
|
|
|
err = models.IncreaseAchevementScore(companyid, addScore, o)
|
|
|
|
|
|
err = models.IncreaseAchevementScore(companyid, scoreRemain, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
log.Error("更新福利池分数achevement_score失败")
|
...
|
...
|
@@ -130,6 +137,16 @@ func EditAchievement(editData *protocol.RequestEditAchievement, companyid int64) |
|
|
log.Error("获取achievement失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
var (
|
|
|
oldRemain float64
|
|
|
newRamain float64
|
|
|
providerScore float64
|
|
|
)
|
|
|
oldRemain = achievementData.GraspScoreRemain
|
|
|
for _, v := range editData.Provider {
|
|
|
providerScore += v.UserGraspScore
|
|
|
}
|
|
|
newRamain = achievementGraspScoreRemain(editData.GraspScore, editData.UserGraspScore, providerScore)
|
|
|
nowTime := time.Now()
|
|
|
achievementData.UpdateAt = nowTime
|
|
|
achievementData.ChanceTypeId = editData.ChanceTypeId
|
...
|
...
|
@@ -137,8 +154,11 @@ func EditAchievement(editData *protocol.RequestEditAchievement, companyid int64) |
|
|
achievementData.SourceContent = editData.SourceContent
|
|
|
achievementData.GraspScore = editData.GraspScore
|
|
|
achievementData.UpdateAt = nowTime
|
|
|
achievementData.UserGraspScore = editData.UserGraspScore
|
|
|
achievementData.GraspScoreRemain = newRamain
|
|
|
cols := []string{
|
|
|
"UpdateAt", "ChanceTypeId", "AuditTemplateId", "SourceContent", "GraspScore",
|
|
|
"UserGraspScore",
|
|
|
}
|
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
...
|
...
|
@@ -158,13 +178,33 @@ func EditAchievement(editData *protocol.RequestEditAchievement, companyid int64) |
|
|
log.Info("删除achievement_chance数据失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
|
|
|
err = addAchievementChance(editData.ChanceData, achievementData.Id, o)
|
|
|
if err != nil {
|
|
|
log.Error("添加achievement_chance失败:%s", err)
|
|
|
o.Rollback()
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
//删除提供者分数
|
|
|
_, err = o.QueryTable(&models.AchievementProvider{}).
|
|
|
Filter("achievement_id", editData.AchievementId).
|
|
|
Delete()
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
log.Info("删除achievement_provider数据失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
err = addAchievementProvider(editData.Provider, achievementData.Id, o)
|
|
|
if err != nil {
|
|
|
log.Error("添加achievement_provider失败:%s", err)
|
|
|
o.Rollback()
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
err = models.IncreaseAchevementScore(companyid, newRamain-oldRemain, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
log.Error("更新福利池分数achevement_score失败")
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
o.Commit()
|
|
|
return nil
|
|
|
}
|
...
|
...
|
@@ -184,7 +224,7 @@ func GetAchievementList(pageIndex int, pageSize int, companyId int64, status int |
|
|
dataSql += ` AND a.status>0 `
|
|
|
countSql += ` AND a.status>0 `
|
|
|
}
|
|
|
dataSql = fmt.Sprintf("%s ORDER BY a.create_at LIMIT %d,%d", dataSql, pageStart, pageSize)
|
|
|
dataSql = fmt.Sprintf("%s ORDER BY a.create_at DESC LIMIT %d,%d", dataSql, pageStart, pageSize)
|
|
|
type SqlData struct {
|
|
|
Id int64 `orm:"column(id)"`
|
|
|
ChanceTypeId int `orm:"column(chance_type_id)"`
|
...
|
...
|
|