作者 陈志颖

refactor:优化合约变更记录

... ... @@ -28,7 +28,7 @@ type UpdateCooperationContractCommand struct {
// 金额激励规则列表
MoneyIncentivesRules []*CreateMoneyIncentivesRulesCommand `cname:"金额激励规则列表" json:"moneyIncentivesRules,omitempty"`
// 承接方列表
Undertakers []*CreateUndertakersCommand `cname:"承接方列表" json:"undertakers,omitempty"`
Undertakers []*CreateUndertakersCommand `cname:"承接方列表" json:"undertakers" valid:"Required"`
// 相关人UID列表
RelevantIds []string `cname:"相关人列表" json:"relevantIds,omitempty"`
// 公司ID,通过集成REST上下文获取
... ...
... ... @@ -3,11 +3,8 @@ package service
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"strconv"
"time"
"unsafe"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/command"
... ... @@ -19,6 +16,8 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
"strconv"
"time"
)
// CooperationContractService 共创合约服务
... ... @@ -1270,18 +1269,33 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
} else if cooperationContractFound.IncentivesType == cooperationContract.IncentivesType { // 2.激励规则内容变更
if cooperationContractFound.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES { // 业绩分红规则内容变更
// 计算原合约哈希值
cooperationContractFoundByte := *(*[]byte)(unsafe.Pointer(&cooperationContractFound.DividendsIncentivesRules))
cooperationContractFoundHashValue := md5.Sum(cooperationContractFoundByte)
// cooperationContractFoundByte := *(*[]byte)(unsafe.Pointer(&cooperationContractFound.DividendsIncentivesRules))
var cooperationContractFoundBytes []byte
for _, rule := range cooperationContractFound.DividendsIncentivesRules {
jsons, errs := json.Marshal(rule)
if errs != nil {
fmt.Println(errs.Error())
}
cooperationContractFoundBytes = append(cooperationContractFoundBytes, jsons...)
}
cooperationContractFoundHashValue := md5.Sum(cooperationContractFoundBytes)
cooperationContractFoundHashString := hex.EncodeToString(cooperationContractFoundHashValue[:])
// 计算更新后的合约哈希值
cooperationContractByte := *(*[]byte)(unsafe.Pointer(&cooperationContract.DividendsIncentivesRules))
cooperationContractHashValue := md5.Sum(cooperationContractByte)
// cooperationContractByte := *(*[]byte)(unsafe.Pointer(&cooperationContract.DividendsIncentivesRules))
var cooperationContractBytes []byte
for _, rule := range cooperationContract.DividendsIncentivesRules {
jsons, errs := json.Marshal(rule)
if errs != nil {
fmt.Println(errs.Error())
}
cooperationContractBytes = append(cooperationContractBytes, jsons...)
}
cooperationContractHashValue := md5.Sum(cooperationContractBytes)
cooperationContractHashString := hex.EncodeToString(cooperationContractHashValue[:])
if cooperationContractFoundHashString != cooperationContractHashString {
// 业绩分红-->业绩分红
incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContract.IncentivesType))
//【第一阶段:20,2021-01-01~2021-12-31,,,;第二阶段:20,2021-01-01~2021-12-31,30,10】变更为【第一阶段:20,2021-01-01~2021-12-31,,,;】
// 原业绩分红激励规则
... ... @@ -1311,13 +1325,29 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
}
} else if cooperationContractFound.IncentivesType == domain.TYPE_MONEY_INCENTIVES { // 金额激励规则内容变更
// 计算原合约哈希值
cooperationContractFoundByte := *(*[]byte)(unsafe.Pointer(&cooperationContractFound.MoneyIncentivesRules))
cooperationContractFoundHashValue := md5.Sum(cooperationContractFoundByte)
//cooperationContractFoundByte := *(*[]byte)(unsafe.Pointer(&cooperationContractFound.MoneyIncentivesRules))
var cooperationContractFoundBytes []byte
for _, rule := range cooperationContractFound.MoneyIncentivesRules {
jsons, errs := json.Marshal(rule)
if errs != nil {
fmt.Println(errs.Error())
}
cooperationContractFoundBytes = append(cooperationContractFoundBytes, jsons...)
}
cooperationContractFoundHashValue := md5.Sum(cooperationContractFoundBytes)
cooperationContractFoundHashString := hex.EncodeToString(cooperationContractFoundHashValue[:])
// 计算更新后的合约哈希值
cooperationContractByte := *(*[]byte)(unsafe.Pointer(&cooperationContract.MoneyIncentivesRules))
cooperationContractHashValue := md5.Sum(cooperationContractByte)
//cooperationContractByte := *(*[]byte)(unsafe.Pointer(&cooperationContract.MoneyIncentivesRules))
var cooperationContractBytes []byte
for _, rule := range cooperationContract.MoneyIncentivesRules {
jsons, errs := json.Marshal(rule)
if errs != nil {
fmt.Println(errs.Error())
}
cooperationContractBytes = append(cooperationContractBytes, jsons...)
}
cooperationContractHashValue := md5.Sum(cooperationContractBytes)
cooperationContractHashString := hex.EncodeToString(cooperationContractHashValue[:])
if cooperationContractFoundHashString != cooperationContractHashString {
... ... @@ -1351,13 +1381,28 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
/*********************************************** 承接人变更 *****************************************************/
// 计算原合约哈希值
cooperationContractFoundByte := *(*[]byte)(unsafe.Pointer(&cooperationContractFound.Undertakers))
cooperationContractFoundHashValue := md5.Sum(cooperationContractFoundByte)
//cooperationContractFoundByte := *(*[]byte)(unsafe.Pointer(&cooperationContractFound.Undertakers))
var cooperationContractFoundBytes []byte
for _, undertaker := range cooperationContractFound.Undertakers {
jsons, errs := json.Marshal(undertaker)
if errs != nil {
fmt.Println(errs.Error())
}
cooperationContractFoundBytes = append(cooperationContractFoundBytes, jsons...)
}
cooperationContractFoundHashValue := md5.Sum(cooperationContractFoundBytes)
cooperationContractFoundHashString := hex.EncodeToString(cooperationContractFoundHashValue[:])
// 计算更新后的合约哈希值
cooperationContractByte := *(*[]byte)(unsafe.Pointer(&cooperationContract.Undertakers))
cooperationContractHashValue := md5.Sum(cooperationContractByte)
var cooperationContractBytes []byte
for _, undertaker := range cooperationContract.Undertakers {
jsons, errs := json.Marshal(undertaker) //转换成JSON返回的是byte[]
if errs != nil {
fmt.Println(errs.Error())
}
cooperationContractBytes = append(cooperationContractBytes, jsons...)
}
cooperationContractHashValue := md5.Sum(cooperationContractBytes)
cooperationContractHashString := hex.EncodeToString(cooperationContractHashValue[:])
if cooperationContractFoundHashString != cooperationContractHashString { // 【1(张三,李四,王五)2(买买买,,)】变更为【1(张三,,)】
... ...
... ... @@ -710,6 +710,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,
CooperationContractNumber: orderGood.CooperationContractNumber,
DividendsUser: dividendsEstimateDetail.DividendsUser,
DividendsPercentage: dividendsEstimateDetail.DividendsPercentage,
DividendsStage: dividendsEstimateDetail.DividendsStage,
Org: organization,
Company: company,
... ... @@ -765,6 +766,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,
CooperationContractNumber: orderGood.CooperationContractNumber,
DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
DividendsPercentage: dividendsReturnedEstimateDetail.DividendsPercentage,
DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
Org: organization,
Company: company,
... ... @@ -1108,6 +1110,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
OrderOrReturnedOrderNum: "",
CooperationContractNumber: cooperationContract.CooperationContractNumber,
DividendsUser: dividendsEstimateDetail.DividendsUser,
DividendsPercentage: dividendsEstimateDetail.DividendsPercentage,
DividendsStage: dividendsEstimateDetail.DividendsStage,
Org: organization,
Company: company,
... ...
... ... @@ -557,7 +557,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
var dividendsOrderCommands = make(map[string]*command.CreateDividendsOrderCommand)
for i, dividendsOrder := range importDividendsOrderCommand.DividendsOrderData {
hashValue := md5.Sum([]byte(dividendsOrder.OriginalOrderNum))
hashValue := md5.Sum([]byte(dividendsOrder.OriginalOrderNum + dividendsOrder.OrderTime))
hashString := hex.EncodeToString(hashValue[:])
if _, ok := dividendsOrderCommands[hashString]; !ok {
// 订单日期时间格式转换
... ...
... ... @@ -47,6 +47,8 @@ type DividendsEstimate struct {
CooperationContractUndertakerId int64 `json:"cooperationContractUndertakerId"`
// 分红用户(共创参与)
DividendsUser *User `json:"dividendsUser"`
// 分红比例
DividendsPercentage float64 `json:"dividendsPercentage"`
// 分红阶段
DividendsStage int32 `json:"dividendsStage"`
// 数据所属组织机构
... ...
... ... @@ -31,11 +31,11 @@ type DividendsIncentivesRule struct {
// 公司
Company *Company `json:"company"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
UpdatedAt time.Time `json:"-"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
DeletedAt time.Time `json:"-"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
CreatedAt time.Time `json:"-"`
}
type DividendsIncentivesRuleRepository interface {
... ...
... ... @@ -33,11 +33,11 @@ type MoneyIncentivesRule struct {
// 公司
Company *Company `json:"company"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
UpdatedAt time.Time `json:"-"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
DeletedAt time.Time `json:"-"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
CreatedAt time.Time `json:"-"`
}
type MoneyIncentivesRuleRepository interface {
... ...
... ... @@ -9,6 +9,7 @@ import (
type DividendsEstimateDetail struct {
DividendsUser *domain.User `json:"dividendsUser"` // 共创参与(分红用户)
DividendsPercentage float64 `json:"dividendsPercentage"` // 分红比例
DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与类型 1承接人,2推荐人,3关联业务员
DividendsStage int32 `json:"dividendsStage"` // 分红阶段
DividendsAmount float64 `json:"dividendsAmount"` // 分红金额
... ...
... ... @@ -249,9 +249,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
DividendsPercentage: dividendsIncentivesRuleMatched.DividendsIncentivesPercentage,
})
}
// 添加推荐人分红预算信息详情
if undertaker.Referrer != nil {
if dividendsIncentivesRuleMatched.ReferrerPercentage > 0 {
... ... @@ -276,6 +276,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
DividendsPercentage: dividendsIncentivesRuleMatched.ReferrerPercentage,
})
}
}
... ... @@ -303,6 +304,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
DividendsPercentage: dividendsIncentivesRuleMatched.SalesmanPercentage,
})
}
}
... ... @@ -373,6 +375,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
DividendsPercentage: dividendsIncentivesRuleMatched.DividendsIncentivesPercentage,
})
}
... ... @@ -400,6 +403,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
DividendsPercentage: dividendsIncentivesRuleMatched.ReferrerPercentage,
})
}
}
... ... @@ -428,9 +432,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
DividendsPercentage: dividendsIncentivesRuleMatched.SalesmanPercentage,
})
}
}
}
}
... ...
... ... @@ -126,9 +126,9 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
DividendsStage: stage,
DividendsAmount: undertakerDividendsAmount,
CooperationContractUndertakerId: undertaker.UndertakerId,
DividendsPercentage: moneyIncentivesRuleMatched.SalesmanPercentage,
})
}
}
// 判断推荐人在当前阶段是否已经分红
... ... @@ -167,6 +167,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
DividendsStage: stage,
DividendsAmount: undertakerDividendsAmount,
CooperationContractUndertakerId: undertaker.UndertakerId,
DividendsPercentage: moneyIncentivesRuleMatched.ReferrerPercentage,
})
}
}
... ...
... ... @@ -33,6 +33,8 @@ type DividendsEstimate struct {
CooperationContractUndertakerId int64 `comment:"共创合约承接人ID"`
// 分红用户
DividendsUser *domain.User `comment:"分红用户"`
// 分红比例
DividendsPercentage float64 `comment:"分红比例"`
// 分红阶段
DividendsStage int32 `comment:"分红阶段"`
// 数据所属组织机构
... ...
... ... @@ -22,6 +22,7 @@ func TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel
CooperationContractNumber: dividendsEstimateModel.CooperationContractNumber,
CooperationContractUndertakerId: dividendsEstimateModel.CooperationContractUndertakerId,
DividendsUser: dividendsEstimateModel.DividendsUser,
DividendsPercentage: dividendsEstimateModel.DividendsPercentage,
DividendsStage: dividendsEstimateModel.DividendsStage,
Org: dividendsEstimateModel.Org,
Company: dividendsEstimateModel.Company,
... ...
... ... @@ -38,6 +38,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
"order_or_returned_order_num",
"cooperation_contract_number",
"dividends_user",
"dividends_percentage",
"dividends_stage",
"org",
"company",
... ... @@ -77,6 +78,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
&dividendsEstimate.OrderOrReturnedOrderNum,
&dividendsEstimate.CooperationContractNumber,
&dividendsEstimate.DividendsUser,
&dividendsEstimate.DividendsPercentage,
&dividendsEstimate.DividendsStage,
&dividendsEstimate.Org,
&dividendsEstimate.Company,
... ... @@ -102,6 +104,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
dividendsEstimate.OrderOrReturnedOrderNum,
dividendsEstimate.CooperationContractNumber,
dividendsEstimate.DividendsUser,
dividendsEstimate.DividendsPercentage,
dividendsEstimate.DividendsStage,
dividendsEstimate.Org,
dividendsEstimate.Company,
... ... @@ -131,6 +134,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
&dividendsEstimate.OrderOrReturnedOrderNum,
&dividendsEstimate.CooperationContractNumber,
&dividendsEstimate.DividendsUser,
&dividendsEstimate.DividendsPercentage,
&dividendsEstimate.DividendsStage,
&dividendsEstimate.Org,
&dividendsEstimate.Company,
... ... @@ -156,6 +160,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
dividendsEstimate.OrderOrReturnedOrderNum,
dividendsEstimate.CooperationContractNumber,
dividendsEstimate.DividendsUser,
dividendsEstimate.DividendsPercentage,
dividendsEstimate.DividendsStage,
dividendsEstimate.Org,
dividendsEstimate.Company,
... ... @@ -200,6 +205,7 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
OrderOrReturnedOrderNum: dividendsEstimate.OrderOrReturnedOrderNum,
CooperationContractNumber: dividendsEstimate.CooperationContractNumber,
DividendsUser: dividendsEstimate.DividendsUser,
DividendsPercentage: dividendsEstimate.DividendsPercentage,
DividendsStage: dividendsEstimate.DividendsStage,
Org: dividendsEstimate.Org,
Company: dividendsEstimate.Company,
... ... @@ -247,6 +253,7 @@ func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*
OrderOrReturnedOrderNum: dividendsEstimate.OrderOrReturnedOrderNum,
CooperationContractNumber: dividendsEstimate.CooperationContractNumber,
DividendsUser: dividendsEstimate.DividendsUser,
DividendsPercentage: dividendsEstimate.DividendsPercentage,
DividendsStage: dividendsEstimate.DividendsStage,
Org: dividendsEstimate.Org,
Company: dividendsEstimate.Company,
... ...
... ... @@ -236,9 +236,9 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
OrgId: goodDomain.OrgId,
CompanyId: goodDomain.CompanyId,
OrderGoodDividendsStatus: goodDomain.OrderGoodDividendsStatus,
CreatedAt: time.Time{},
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Now(),
UpdatedAt: time.Time{},
})
}
// 添加分红退货订单产品
... ...