|
|
package service
|
|
|
|
|
|
import (
|
|
|
"crypto/md5"
|
|
|
"encoding/hex"
|
|
|
"fmt"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
"unsafe"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
...
|
...
|
@@ -746,7 +749,7 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
for _, cooperationContractOperated := range cooperationContractsOperated {
|
|
|
for _, cooperationContractOperated := range cooperationContracts {
|
|
|
// 新增共创合约变更记录
|
|
|
var operationType int32
|
|
|
if batchOperateCooperationContractCommand.Action == 1 {
|
...
|
...
|
@@ -764,6 +767,7 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper |
|
|
Org: cooperationContractOperated.Org,
|
|
|
Operator: operator,
|
|
|
CreatedAt: time.Now(),
|
|
|
OperatorTime: time.Now(),
|
|
|
}
|
|
|
|
|
|
// 保存共创合约变更记录
|
...
|
...
|
@@ -939,24 +943,16 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
}
|
|
|
|
|
|
// 获取待更新的共创合约
|
|
|
cooperationContract, err8 := cooperationContractRepository.FindOne(map[string]interface{}{
|
|
|
cooperationContractFound, err8 := cooperationContractRepository.FindOne(map[string]interface{}{
|
|
|
"cooperationContractId": updateCooperationContractCommand.CooperationContractId,
|
|
|
})
|
|
|
if err8 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创合约不存在")
|
|
|
}
|
|
|
if cooperationContract == nil {
|
|
|
if cooperationContractFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationContractCommand.CooperationContractId)))
|
|
|
}
|
|
|
|
|
|
// 缓存共创合约
|
|
|
cooperationContractFound := cooperationContract
|
|
|
|
|
|
// 更新合约基础信息
|
|
|
if err9 := cooperationContract.Update(tool_funs.SimpleStructToMap(updateCooperationContractCommand)); err9 != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err9.Error())
|
|
|
}
|
|
|
|
|
|
// 用户REST服务初始化
|
|
|
var userService service.UserService
|
|
|
if value, err10 := factory.CreateUserService(map[string]interface{}{}); err10 != nil {
|
...
|
...
|
@@ -985,6 +981,22 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
operator = data
|
|
|
}
|
|
|
|
|
|
// 获取待更新的共创合约
|
|
|
cooperationContract, err8 := cooperationContractRepository.FindOne(map[string]interface{}{
|
|
|
"cooperationContractId": updateCooperationContractCommand.CooperationContractId,
|
|
|
})
|
|
|
if err8 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创合约不存在")
|
|
|
}
|
|
|
if cooperationContract == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationContractCommand.CooperationContractId)))
|
|
|
}
|
|
|
|
|
|
// 更新合约基础信息
|
|
|
if err9 := cooperationContract.Update(tool_funs.SimpleStructToMap(updateCooperationContractCommand)); err9 != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err9.Error())
|
|
|
}
|
|
|
|
|
|
// 更新发起人
|
|
|
cooperationContract.CooperationContractSponsor = sponsor
|
|
|
|
...
|
...
|
@@ -1195,10 +1207,10 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
var undertakerChange string
|
|
|
|
|
|
// 规则变更,原【(激励阶段:激励百分点,阶段有效期,推荐人抽点,关联业务员抽点),(激励阶段:激励百分点,阶段有效期,推荐人抽点,关联业务员抽点)】-->更新后【(激励阶段:激励百分点,阶段有效期,推荐人抽点,关联业务员抽点)】
|
|
|
if cooperationContractFound.IncentivesType != cooperationContractSaved.IncentivesType { // 1.激励规则类型变更
|
|
|
if cooperationContractFound.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES && cooperationContractSaved.IncentivesType == domain.TYPE_MONEY_INCENTIVES { // 业绩分红变更为金额激励
|
|
|
if cooperationContractFound.IncentivesType != cooperationContract.IncentivesType { // 1.激励规则类型变更
|
|
|
if cooperationContractFound.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES && cooperationContract.IncentivesType == domain.TYPE_MONEY_INCENTIVES { // 业绩分红变更为金额激励
|
|
|
// 业绩分红-->金额激励
|
|
|
incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractSaved.IncentivesType))
|
|
|
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,,,;】
|
|
|
// 原业绩分红激励规则
|
|
|
var dividendsIncentivesRuleOriginal string
|
...
|
...
|
@@ -1214,10 +1226,10 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
|
|
|
// 变更后的金额激励规则
|
|
|
var moneyIncentivesRuleChanged string
|
|
|
for _, moneyIncentivesRule := range cooperationContractSaved.MoneyIncentivesRules {
|
|
|
for _, moneyIncentivesRule := range cooperationContract.MoneyIncentivesRules {
|
|
|
moneyIncentivesRuleChanged = moneyIncentivesRuleChanged + moneyIncentivesRule.MoneyIncentivesStageCN +
|
|
|
":" +
|
|
|
"," + moneyIncentivesRule.MoneyIncentivesStageStart.Format("2006-01-02") +
|
|
|
"," + moneyIncentivesRule.MoneyIncentivesTime.Format("2006-01-02") +
|
|
|
"," + fmt.Sprint(moneyIncentivesRule.ReferrerPercentage) +
|
|
|
"," + fmt.Sprint(moneyIncentivesRule.SalesmanPercentage) + ";"
|
|
|
}
|
...
|
...
|
@@ -1225,16 +1237,16 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
|
|
|
// 拼接规则变更
|
|
|
incentivesRuleChangeDetail = dividendsIncentivesRuleOriginalTmp + " 变更为 " + moneyIncentivesRuleOriginalTmp
|
|
|
} else if cooperationContractFound.IncentivesType == domain.TYPE_MONEY_INCENTIVES && cooperationContractSaved.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES { // 金额激励变更为业绩分红
|
|
|
} else if cooperationContractFound.IncentivesType == domain.TYPE_MONEY_INCENTIVES && cooperationContract.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES { // 金额激励变更为业绩分红
|
|
|
// 金额激励-->业绩分红
|
|
|
incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractSaved.IncentivesType))
|
|
|
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,,,;】
|
|
|
// 原金额激励规则
|
|
|
var moneyIncentivesRuleOriginal string
|
|
|
for _, moneyIncentivesRule := range cooperationContractFound.MoneyIncentivesRules {
|
|
|
moneyIncentivesRuleOriginal = moneyIncentivesRuleOriginal + moneyIncentivesRule.MoneyIncentivesStageCN +
|
|
|
":" +
|
|
|
"," + moneyIncentivesRule.MoneyIncentivesStageStart.Format("2006-01-02") +
|
|
|
"," + moneyIncentivesRule.MoneyIncentivesTime.Format("2006-01-02") +
|
|
|
"," + fmt.Sprint(moneyIncentivesRule.ReferrerPercentage) +
|
|
|
"," + fmt.Sprint(moneyIncentivesRule.SalesmanPercentage) + ";"
|
|
|
}
|
...
|
...
|
@@ -1242,7 +1254,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
|
|
|
// 变更后的业绩分红激励规则
|
|
|
var dividendsIncentivesRuleChanged string
|
|
|
for _, dividendsIncentivesRule := range cooperationContractSaved.DividendsIncentivesRules {
|
|
|
for _, dividendsIncentivesRule := range cooperationContract.DividendsIncentivesRules {
|
|
|
dividendsIncentivesRuleChanged = dividendsIncentivesRuleChanged + dividendsIncentivesRule.DividendsIncentivesStageCN +
|
|
|
":" + fmt.Sprint(dividendsIncentivesRule.DividendsIncentivesPercentage) +
|
|
|
"," + dividendsIncentivesRule.DividendsIncentivesStageStart.Format("2006-01-02") +
|
...
|
...
|
@@ -1255,11 +1267,22 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
// 拼接规则变更
|
|
|
incentivesRuleChangeDetail = moneyIncentivesRuleOriginalTmp + " 变更为 " + dividendsIncentivesRuleOriginalTmp
|
|
|
}
|
|
|
} else if cooperationContractFound.IncentivesType == cooperationContractSaved.IncentivesType { // 2.激励规则内容变更
|
|
|
} else if cooperationContractFound.IncentivesType == cooperationContract.IncentivesType { // 2.激励规则内容变更
|
|
|
if cooperationContractFound.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES { // 业绩分红规则内容变更
|
|
|
if !cooperationContract.DividendsIncentivesRuleSliceEqualBCE(cooperationContractFound.DividendsIncentivesRules, cooperationContractSaved.DividendsIncentivesRules) {
|
|
|
// 计算原合约哈希值
|
|
|
cooperationContractFoundByte := *(*[]byte)(unsafe.Pointer(&cooperationContractFound.DividendsIncentivesRules))
|
|
|
cooperationContractFoundHashValue := md5.Sum(cooperationContractFoundByte)
|
|
|
cooperationContractFoundHashString := hex.EncodeToString(cooperationContractFoundHashValue[:])
|
|
|
|
|
|
// 计算更新后的合约哈希值
|
|
|
cooperationContractByte := *(*[]byte)(unsafe.Pointer(&cooperationContract.DividendsIncentivesRules))
|
|
|
cooperationContractHashValue := md5.Sum(cooperationContractByte)
|
|
|
cooperationContractHashString := hex.EncodeToString(cooperationContractHashValue[:])
|
|
|
|
|
|
if cooperationContractFoundHashString != cooperationContractHashString {
|
|
|
// 业绩分红-->业绩分红
|
|
|
incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractSaved.IncentivesType))
|
|
|
|
|
|
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,,,;】
|
|
|
// 原业绩分红激励规则
|
|
|
var dividendsIncentivesRuleOriginal string
|
...
|
...
|
@@ -1274,7 +1297,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
dividendsIncentivesRuleOriginalTmp := "【" + dividendsIncentivesRuleOriginal + "】"
|
|
|
// 变更后的业绩分红激励规则
|
|
|
var dividendsIncentivesRuleChanged string
|
|
|
for _, dividendsIncentivesRule := range cooperationContractSaved.DividendsIncentivesRules {
|
|
|
for _, dividendsIncentivesRule := range cooperationContract.DividendsIncentivesRules {
|
|
|
dividendsIncentivesRuleChanged = dividendsIncentivesRuleChanged + dividendsIncentivesRule.DividendsIncentivesStageCN +
|
|
|
":" + fmt.Sprint(dividendsIncentivesRule.DividendsIncentivesPercentage) +
|
|
|
"," + dividendsIncentivesRule.DividendsIncentivesStageStart.Format("2006-01-02") +
|
...
|
...
|
@@ -1286,26 +1309,36 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
// 拼接规则变更
|
|
|
incentivesRuleChangeDetail = dividendsIncentivesRuleOriginalTmp + " 变更为 " + dividendsIncentivesRuleChangedTmp
|
|
|
}
|
|
|
} else if cooperationContractFound.IncentivesType == domain.MONEY_INCENTIVES { // 金额激励规则内容变更
|
|
|
if !cooperationContract.MoneyIncentivesRuleSliceEqualBCE(cooperationContractFound.MoneyIncentivesRules, cooperationContractSaved.MoneyIncentivesRules) {
|
|
|
incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractSaved.IncentivesType))
|
|
|
} else if cooperationContractFound.IncentivesType == domain.TYPE_MONEY_INCENTIVES { // 金额激励规则内容变更
|
|
|
// 计算原合约哈希值
|
|
|
cooperationContractFoundByte := *(*[]byte)(unsafe.Pointer(&cooperationContractFound.MoneyIncentivesRules))
|
|
|
cooperationContractFoundHashValue := md5.Sum(cooperationContractFoundByte)
|
|
|
cooperationContractFoundHashString := hex.EncodeToString(cooperationContractFoundHashValue[:])
|
|
|
|
|
|
// 计算更新后的合约哈希值
|
|
|
cooperationContractByte := *(*[]byte)(unsafe.Pointer(&cooperationContract.MoneyIncentivesRules))
|
|
|
cooperationContractHashValue := md5.Sum(cooperationContractByte)
|
|
|
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,,,;】
|
|
|
// 原金额激励规则
|
|
|
var moneyIncentivesRuleOriginal string
|
|
|
for _, moneyIncentivesRule := range cooperationContractFound.MoneyIncentivesRules {
|
|
|
moneyIncentivesRuleOriginal = moneyIncentivesRuleOriginal + moneyIncentivesRule.MoneyIncentivesStageCN +
|
|
|
":" +
|
|
|
"," + moneyIncentivesRule.MoneyIncentivesStageStart.Format("2006-01-02") +
|
|
|
"," + moneyIncentivesRule.MoneyIncentivesTime.Format("2006-01-02") +
|
|
|
"," + fmt.Sprint(moneyIncentivesRule.ReferrerPercentage) +
|
|
|
"," + fmt.Sprint(moneyIncentivesRule.SalesmanPercentage) + ";"
|
|
|
}
|
|
|
moneyIncentivesRuleOriginalTmp := "【" + moneyIncentivesRuleOriginal + "】"
|
|
|
// 变更后的激励规则
|
|
|
var moneyIncentivesRuleChanged string
|
|
|
for _, moneyIncentivesRule := range cooperationContractSaved.MoneyIncentivesRules {
|
|
|
for _, moneyIncentivesRule := range cooperationContract.MoneyIncentivesRules {
|
|
|
moneyIncentivesRuleChanged = moneyIncentivesRuleChanged + moneyIncentivesRule.MoneyIncentivesStageCN +
|
|
|
":" +
|
|
|
"," + moneyIncentivesRule.MoneyIncentivesStageStart.Format("2006-01-02") +
|
|
|
"," + moneyIncentivesRule.MoneyIncentivesTime.Format("2006-01-02") +
|
|
|
"," + fmt.Sprint(moneyIncentivesRule.ReferrerPercentage) +
|
|
|
"," + fmt.Sprint(moneyIncentivesRule.SalesmanPercentage) + ";"
|
|
|
}
|
...
|
...
|
@@ -1316,8 +1349,18 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 承接人变更
|
|
|
if !cooperationContract.UndertakerSliceEqualBCE(cooperationContractFound.Undertakers, cooperationContractSaved.Undertakers) { // 【1(张三,李四,王五)2(买买买,,)】变更为【1(张三,,)】
|
|
|
/*********************************************** 承接人变更 *****************************************************/
|
|
|
// 计算原合约哈希值
|
|
|
cooperationContractFoundByte := *(*[]byte)(unsafe.Pointer(&cooperationContractFound.Undertakers))
|
|
|
cooperationContractFoundHashValue := md5.Sum(cooperationContractFoundByte)
|
|
|
cooperationContractFoundHashString := hex.EncodeToString(cooperationContractFoundHashValue[:])
|
|
|
|
|
|
// 计算更新后的合约哈希值
|
|
|
cooperationContractByte := *(*[]byte)(unsafe.Pointer(&cooperationContract.Undertakers))
|
|
|
cooperationContractHashValue := md5.Sum(cooperationContractByte)
|
|
|
cooperationContractHashString := hex.EncodeToString(cooperationContractHashValue[:])
|
|
|
|
|
|
if cooperationContractFoundHashString != cooperationContractHashString { // 【1(张三,李四,王五)2(买买买,,)】变更为【1(张三,,)】
|
|
|
// 原承接人
|
|
|
var undertakersOriginal string
|
|
|
for i, undertaker := range cooperationContractFound.Undertakers {
|
...
|
...
|
@@ -1357,7 +1400,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
|
|
|
// 变更承接人
|
|
|
var undertakersChanged string
|
|
|
for i, undertaker := range cooperationContractSaved.Undertakers {
|
|
|
for i, undertaker := range cooperationContract.Undertakers {
|
|
|
if undertaker.Referrer == nil {
|
|
|
undertaker.Referrer = &domain.Referrer{
|
|
|
UserId: 0,
|
...
|
...
|
@@ -1401,7 +1444,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
IncentivesRuleDetail: incentivesRuleChangeDetail,
|
|
|
OperationType: domain.EDIT,
|
|
|
Undertakers: undertakerChange,
|
|
|
CooperationContractNumber: cooperationContractSaved.CooperationContractNumber,
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
Company: company,
|
|
|
Org: organization,
|
|
|
Operator: operator,
|
...
|
...
|
|