作者 陈志颖

feat:共创激励规则增加阶段转换方法

... ... @@ -4,6 +4,7 @@ go 1.16
require (
github.com/Shopify/sarama v1.25.0
github.com/Tnze/go.num/v2 v2.0.0-20191006170829-cb483d4c9152 // indirect
github.com/ajg/form v1.5.1 // indirect
github.com/beego/beego/v2 v2.0.1
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect
... ...
... ... @@ -5,6 +5,8 @@ github.com/Shopify/sarama v1.25.0 h1:ch1ywjRLjfJtU+EaiJ+l0rWffQ6TRpyYmW4DX7Cb2SU
github.com/Shopify/sarama v1.25.0/go.mod h1:y/CFFTO9eaMTNriwu/Q+W4eioLqiDMGkA1W+gmdfj8w=
github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/Tnze/go.num/v2 v2.0.0-20191006170829-cb483d4c9152 h1:6Ny2zcG2k/0aOE8rLbDdLdPMr0o7lqMfdnYJe6pZj9w=
github.com/Tnze/go.num/v2 v2.0.0-20191006170829-cb483d4c9152/go.mod h1:fNGLFjpxgDvBqQPv1HYSuGi6pRuI8wdKvvspYvUQufc=
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
... ...
package domain
import "time"
import (
"time"
)
// DividendsIncentivesRule 金额激励规则实体
type DividendsIncentivesRule struct {
... ... @@ -77,8 +79,3 @@ func (dividendsIncentivesRule *DividendsIncentivesRule) Update(data map[string]i
}
return nil
}
// NumberToCNNumber 数字转中文数字
func (dividendsIncentivesRule *DividendsIncentivesRule) NumberToCNNumber() (string, error) {
return "", nil
}
... ...
package domain
import "time"
import (
"time"
)
// MoneyIncentivesRule 金额激励规则实体
type MoneyIncentivesRule struct {
... ... @@ -82,8 +84,3 @@ func (moneyIncentivesRule *MoneyIncentivesRule) Update(data map[string]interface
}
return nil
}
// NumberToCNNumber 数字转中文数字
func (moneyIncentivesRule *MoneyIncentivesRule) NumberToCNNumber() (string, error) {
return "", nil
}
... ...
... ... @@ -3,6 +3,7 @@ package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
)
func TransformToCooperationContractDomainModelFromPgModels(
... ... @@ -15,6 +16,7 @@ func TransformToCooperationContractDomainModelFromPgModels(
// 分红激励规则
var dividendsIncentivesRulesDomain []*domain.DividendsIncentivesRule
for _, rule := range dividendsIncentivesRules {
stageString := utils.NumberToCNNumber(int(rule.DividendsIncentivesStage))
dividendsIncentivesRulesDomain = append(dividendsIncentivesRulesDomain, &domain.DividendsIncentivesRule{
DividendsIncentivesRuleId: rule.DividendsIncentivesRuleId,
CooperationContractNumber: rule.CooperationContractNumber,
... ... @@ -22,6 +24,7 @@ func TransformToCooperationContractDomainModelFromPgModels(
SalesmanPercentage: rule.SalesmanPercentage,
DividendsIncentivesPercentage: rule.DividendsIncentivesPercentage,
DividendsIncentivesStage: rule.DividendsIncentivesStage,
DividendsIncentivesStageCN: stageString,
DividendsIncentivesStageEnd: rule.DividendsIncentivesStageEnd,
DividendsIncentivesStageStart: rule.DividendsIncentivesStageStart,
Org: rule.Org,
... ... @@ -34,11 +37,13 @@ func TransformToCooperationContractDomainModelFromPgModels(
// 金额激励规则
var moneyIncentivesRulesDomain []*domain.MoneyIncentivesRule
for _, rule := range moneyIncentivesRules {
stageString := utils.NumberToCNNumber(int(rule.MoneyIncentivesStage))
moneyIncentivesRulesDomain = append(moneyIncentivesRulesDomain, &domain.MoneyIncentivesRule{
MoneyIncentivesRuleId: rule.MoneyIncentivesRuleId,
CooperationContractNumber: rule.CooperationContractNumber,
MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
MoneyIncentivesStage: rule.MoneyIncentivesStage,
MoneyIncentivesStageCN: stageString,
MoneyIncentivesStageEnd: rule.MoneyIncentivesStageEnd,
MoneyIncentivesStageStart: rule.MoneyIncentivesStageStart,
MoneyIncentivesTime: rule.MoneyIncentivesTime,
... ...
package utils
import (
"strconv"
"fmt"
"github.com/shopspring/decimal"
"strconv"
"strings"
)
// Intersect 返回两个数组的交集
... ... @@ -77,4 +79,40 @@ func Round(value float64, places int32) float64 {
d := quantity.Round(places)
rsp, _ := d.Float64()
return rsp
}
\ No newline at end of file
}
// NumberToCNNumber 数字转中文数字
func NumberToCNNumber(num int) string {
chineseMap := []string{"阶段", "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千"}
chineseNum := []string{"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"}
var listNum []int
for ; num > 0; num = num / 10 {
listNum = append(listNum, num%10)
}
n := len(listNum)
chinese := ""
//注意这里是倒序的
for i := n - 1; i >= 0; i-- {
chinese = fmt.Sprintf("%s%s%s", chinese, chineseNum[listNum[i]], chineseMap[i])
}
//注意替换顺序
for {
copyChinese := chinese
copyChinese = strings.Replace(copyChinese, "零万", "万", 1)
copyChinese = strings.Replace(copyChinese, "零亿", "亿", 1)
copyChinese = strings.Replace(copyChinese, "零十", "零", 1)
copyChinese = strings.Replace(copyChinese, "零百", "零", 1)
copyChinese = strings.Replace(copyChinese, "零千", "零", 1)
copyChinese = strings.Replace(copyChinese, "零零", "零", 1)
copyChinese = strings.Replace(copyChinese, "零圆", "圆", 1)
if copyChinese == chinese {
break
} else {
chinese = copyChinese
}
}
return "第" + chinese
}
... ...