Commit 2d3034cf authored by hujiebin's avatar hujiebin

Merge branch 'feature/modify-nameplate' into 'master'

feat:更新名字同步铭牌

See merge request !3
parents 738a1fcb 721581fa
...@@ -2,6 +2,7 @@ package groupPower_m ...@@ -2,6 +2,7 @@ package groupPower_m
import ( import (
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm" "gorm.io/gorm"
"hilo-group/_const/enum/groupPower_e" "hilo-group/_const/enum/groupPower_e"
"hilo-group/common" "hilo-group/common"
...@@ -116,9 +117,13 @@ func UpdateFamily(model *domain.Model, familyId uint64, name, nameplate, declara ...@@ -116,9 +117,13 @@ func UpdateFamily(model *domain.Model, familyId uint64, name, nameplate, declara
if familyId == 0 || (name == "" && nameplate == "" && declaration == "" && icon == "") { if familyId == 0 || (name == "" && nameplate == "" && declaration == "" && icon == "") {
return nil return nil
} }
var groupPower GroupPower
if err := model.DB().Model(GroupPower{}).Where("id = ?", familyId).First(&groupPower).Error; err != nil {
return err
}
// 修改铭牌 // 修改铭牌
if nameplate != "" { if nameplate != "" {
sql := "UPDATE `group_power` a left join (SELECT ? `id` FROM group_power WHERE nameplate = ?) b on a.id = b.id SET a.`nameplate`=? where a.id=? and b.id is null;" sql := "UPDATE `group_power` a left join (SELECT ? `id` FROM group_power WHERE nameplate = ?) b on a.id = b.id SET a.`nameplate`=?,modify_nameplate = 1 where a.id=? and b.id is null;"
result := model.Db.Exec(sql, familyId, nameplate, nameplate, familyId) result := model.Db.Exec(sql, familyId, nameplate, nameplate, familyId)
if result.Error != nil { if result.Error != nil {
return myerr.WrapErr(result.Error) return myerr.WrapErr(result.Error)
...@@ -132,6 +137,14 @@ func UpdateFamily(model *domain.Model, familyId uint64, name, nameplate, declara ...@@ -132,6 +137,14 @@ func UpdateFamily(model *domain.Model, familyId uint64, name, nameplate, declara
updateMap := make(map[string]interface{}) updateMap := make(map[string]interface{})
if name != "" { if name != "" {
updateMap["name"] = name updateMap["name"] = name
if groupPower.ModifyNameplate != mysql.YES {
// 同步修改铭牌
n := len([]rune(name))
if n > 6 {
n = 6
}
updateMap["nameplate"] = string([]rune(name[0:n]))
}
} }
if declaration != "" { if declaration != "" {
updateMap["declaration"] = declaration updateMap["declaration"] = declaration
......
...@@ -32,6 +32,7 @@ type GroupPower struct { ...@@ -32,6 +32,7 @@ type GroupPower struct {
GradeName mysql.Str // 等级称号 GradeName mysql.Str // 等级称号
GradeMedal mysql.Str // 等级勋章图片 GradeMedal mysql.Str // 等级勋章图片
Grade groupPower_e.GroupPowerGrade `gorm:"-"` Grade groupPower_e.GroupPowerGrade `gorm:"-"`
ModifyNameplate mysql.YesNo
} }
type GroupPowerUser struct { type GroupPowerUser struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment