作者 陈志颖

Merge branch 'dev-chenzhiying' into dev

... ... @@ -705,12 +705,12 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
if err := updateCooperationContractCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
transactionContext, err1 := factory.CreateTransactionContext(nil)
if err1 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err1.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
if err2 := transactionContext.StartTransaction(); err2 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err2.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
... ... @@ -718,59 +718,76 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 公司REST服务初始化
var companyService service.CompanyService
if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if value, err3 := factory.CreateCompanyService(map[string]interface{}{}); err3 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
} else {
companyService = value
}
// 获取公司信息
var company *domain.Company
if data, err := companyService.CompanyFrom(updateCooperationContractCommand.CompanyId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if data, err4 := companyService.CompanyFrom(updateCooperationContractCommand.CompanyId); err4 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
} else {
company = data
}
// 组织机构REST服务初始化
var organizationService service.OrgService
if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if value, err5 := factory.CreateOrganizationService(map[string]interface{}{}); err5 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err5.Error())
} else {
organizationService = value
}
// 获取组织机构信息
var organization *domain.Org
if data, err := organizationService.OrgFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if data, err6 := organizationService.OrgFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId); err6 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
} else {
organization = data
}
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
// 共创合约变更记录仓储初始化
var cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractChangeLogRepository = value
}
// 共创合约仓储初始化
var cooperationContractRepository domain.CooperationContractRepository
if value, err7 := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err7 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err7.Error())
} else {
cooperationContractRepository = value
}
cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": updateCooperationContractCommand.CooperationContractId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// 获取待更新的共创合约
cooperationContract, err8 := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": updateCooperationContractCommand.CooperationContractId})
if err8 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err8.Error())
}
if cooperationContract == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationContractCommand.CooperationContractId)))
}
cooperationContractFound := cooperationContract
// 更新合约基础信息
if err := cooperationContract.Update(tool_funs.SimpleStructToMap(updateCooperationContractCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
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, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if value, err10 := factory.CreateUserService(map[string]interface{}{}); err10 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err10.Error())
} else {
userService = value
}
... ... @@ -778,12 +795,20 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 获取发起人
var sponsor *domain.User
sponsorUid, _ := strconv.ParseInt(updateCooperationContractCommand.SponsorUid, 10, 64)
if data, err := userService.OperatorFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, sponsorUid); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if data, err11 := userService.OperatorFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, sponsorUid); err11 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err11.Error())
} else {
sponsor = data
}
// 获取操作人
var operator *domain.User
if data, err := userService.OperatorFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, updateCooperationContractCommand.UserId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
operator = data
}
// 更新发起人
cooperationContract.CooperationContractSponsor = sponsor
... ... @@ -792,8 +817,8 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
for _, relevantPersonUid := range updateCooperationContractCommand.RelevantPeople {
var relevantDomain *domain.Relevant
relevantUid, _ := strconv.ParseInt(relevantPersonUid, 10, 64)
if data, err := userService.RelevantFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, relevantUid); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if data, err12 := userService.RelevantFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, relevantUid); err12 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err12.Error())
} else {
relevantDomain = data
}
... ... @@ -821,8 +846,8 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
for _, undertaker := range updateCooperationContractCommand.Undertakers {
var undertakerDomain *domain.Undertaker
undertakerUid, _ := strconv.ParseInt(undertaker.UserId, 10, 64)
if data, err := userService.UndertakerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, undertakerUid); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if data, err13 := userService.UndertakerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, undertakerUid); err13 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err13.Error())
} else {
undertakerDomain = data
}
... ... @@ -831,8 +856,8 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
var referrerDomain *domain.Referrer
referrerUid, _ := strconv.ParseInt(undertaker.ReferrerId, 10, 64)
if referrerUid > 0 {
if data, err := userService.ReferrerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, referrerUid); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if data, err14 := userService.ReferrerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, referrerUid); err14 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err14.Error())
} else {
referrerDomain = data
}
... ... @@ -840,18 +865,21 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 获取业务员
var salesmanDomain *domain.Salesman
salesmanUid, _ := strconv.ParseInt(undertaker.SalesmanId, 10, 64)
salesmanUid, err22 := strconv.ParseInt(undertaker.SalesmanId, 10, 64)
if err22 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err22.Error())
}
if salesmanUid > 0 {
if data, err := userService.SalesmanFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, salesmanUid); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if data, err15 := userService.SalesmanFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, salesmanUid); err15 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err15.Error())
} else {
salesmanDomain = data
}
}
undertakerId, err3 := strconv.ParseInt(undertaker.UndertakerId, 10, 64)
if err3 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
undertakerId, err16 := strconv.ParseInt(undertaker.UndertakerId, 10, 64)
if err16 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err16.Error())
}
undertakers = append(undertakers, &domain.Undertaker{
UndertakerId: undertakerId,
... ... @@ -877,9 +905,9 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 获取分红规则列表
var dividendsIncentivesRules []*domain.DividendsIncentivesRule
for _, dividendsIncentivesRule := range updateCooperationContractCommand.DividendsIncentivesRules {
dividendsIncentivesRuleId, err2 := strconv.ParseInt(dividendsIncentivesRule.DividendsIncentivesRuleId, 10, 64)
if err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
dividendsIncentivesRuleId, err17 := strconv.ParseInt(dividendsIncentivesRule.DividendsIncentivesRuleId, 10, 64)
if err17 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err17.Error())
}
dividendsIncentivesRules = append(dividendsIncentivesRules, &domain.DividendsIncentivesRule{
DividendsIncentivesRuleId: dividendsIncentivesRuleId,
... ... @@ -903,9 +931,9 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 获取金额激励规则列表
var moneyIncentivesRules []*domain.MoneyIncentivesRule
for _, moneyIncentivesRule := range updateCooperationContractCommand.MoneyIncentivesRules {
moneyIncentivesRuleId, err4 := strconv.ParseInt(moneyIncentivesRule.MoneyIncentivesRuleId, 10, 64)
if err4 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
moneyIncentivesRuleId, err18 := strconv.ParseInt(moneyIncentivesRule.MoneyIncentivesRuleId, 10, 64)
if err18 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err18.Error())
}
moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{
MoneyIncentivesRuleId: moneyIncentivesRuleId,
... ... @@ -927,13 +955,190 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 更新金额激励规则列表
cooperationContract.MoneyIncentivesRules = moneyIncentivesRules
if cooperationContract, err := cooperationContractRepository.Save(cooperationContract); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// 判断激励规则变更
incentivesType := 0
if len(dividendsIncentivesRules) > 0 {
incentivesType = domain.TYPE_DIVIDNEDS_INCENTIVES
} else if len(moneyIncentivesRules) > 0 {
incentivesType = domain.TYPE_MONEY_INCENTIVES
}
cooperationContract.IncentivesType = int32(incentivesType)
// 保存共创合约变更
if cooperationContractSaved, err19 := cooperationContractRepository.Save(cooperationContract); err19 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err19.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// 保存共创合约变更记录
// 原【(激励阶段:激励百分点,阶段有效期,推荐人抽点,关联业务员抽点),(激励阶段:激励百分点,阶段有效期,推荐人抽点,关联业务员抽点)】-->更新后【(激励阶段:激励百分点,阶段有效期,推荐人抽点,关联业务员抽点)】
var incentivesRuleChange string
var incentivesRuleChangeDetail string
if cooperationContractFound.IncentivesType != cooperationContractSaved.IncentivesType && cooperationContractFound.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES && cooperationContractSaved.IncentivesType == domain.TYPE_MONEY_INCENTIVES { // 1.激励类型变更
// 业绩分红-->金额激励
incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractSaved.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
for _, dividendsIncentivesRule := range cooperationContractFound.DividendsIncentivesRules {
dividendsIncentivesRuleOriginal = dividendsIncentivesRuleOriginal + dividendsIncentivesRule.DividendsIncentivesStageCN +
":" + fmt.Sprint(dividendsIncentivesRule.DividendsIncentivesPercentage) +
"," + dividendsIncentivesRule.DividendsIncentivesStageStart.Format("2006-01-02") +
"~" + dividendsIncentivesRule.DividendsIncentivesStageEnd.Format("2006-01-02") +
"," + fmt.Sprint(dividendsIncentivesRule.ReferrerPercentage) +
"," + fmt.Sprint(dividendsIncentivesRule.SalesmanPercentage) + ";"
}
dividendsIncentivesRuleOriginalTmp := "【" + dividendsIncentivesRuleOriginal + "】"
// 变更后的金额激励规则
var moneyIncentivesRuleChanged string
for _, moneyIncentivesRule := range cooperationContractSaved.MoneyIncentivesRules {
moneyIncentivesRuleChanged = moneyIncentivesRuleChanged + moneyIncentivesRule.MoneyIncentivesStageCN +
":" +
"," + moneyIncentivesRule.MoneyIncentivesStageStart.Format("2006-01-02") +
"," + fmt.Sprint(moneyIncentivesRule.ReferrerPercentage) +
"," + fmt.Sprint(moneyIncentivesRule.SalesmanPercentage) + ";"
}
moneyIncentivesRuleOriginalTmp := "【" + moneyIncentivesRuleChanged + "】"
// 拼接规则变更
incentivesRuleChangeDetail = dividendsIncentivesRuleOriginalTmp + " 变更为 " + moneyIncentivesRuleOriginalTmp
} else if cooperationContractFound.IncentivesType != cooperationContractSaved.IncentivesType && cooperationContractFound.IncentivesType == domain.TYPE_MONEY_INCENTIVES && cooperationContractSaved.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES {
// 金额激励-->业绩分红
incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractSaved.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") +
"," + fmt.Sprint(moneyIncentivesRule.ReferrerPercentage) +
"," + fmt.Sprint(moneyIncentivesRule.SalesmanPercentage) + ";"
}
moneyIncentivesRuleOriginalTmp := "【" + moneyIncentivesRuleOriginal + "】"
// 变更后的业绩分红激励规则
var dividendsIncentivesRuleChanged string
for _, dividendsIncentivesRule := range cooperationContractSaved.DividendsIncentivesRules {
dividendsIncentivesRuleChanged = dividendsIncentivesRuleChanged + dividendsIncentivesRule.DividendsIncentivesStageCN +
":" + fmt.Sprint(dividendsIncentivesRule.DividendsIncentivesPercentage) +
"," + dividendsIncentivesRule.DividendsIncentivesStageStart.Format("2006-01-02") +
"~" + dividendsIncentivesRule.DividendsIncentivesStageEnd.Format("2006-01-02") +
"," + fmt.Sprint(dividendsIncentivesRule.ReferrerPercentage) +
"," + fmt.Sprint(dividendsIncentivesRule.SalesmanPercentage) + ";"
}
dividendsIncentivesRuleOriginalTmp := "【" + dividendsIncentivesRuleChanged + "】"
// 拼接规则变更
incentivesRuleChangeDetail = moneyIncentivesRuleOriginalTmp + " 变更为 " + dividendsIncentivesRuleOriginalTmp
} else { // 2.激励规则变更
if cooperationContractFound.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES { // 业绩分红激励规则变更
if !cooperationContract.DividendsIncentivesRuleSliceEqualBCE(cooperationContractFound.DividendsIncentivesRules, cooperationContractSaved.DividendsIncentivesRules) {
// 业绩分红-->业绩分红
incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractSaved.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
for _, dividendsIncentivesRule := range cooperationContractFound.DividendsIncentivesRules {
dividendsIncentivesRuleOriginal = dividendsIncentivesRuleOriginal + dividendsIncentivesRule.DividendsIncentivesStageCN +
":" + fmt.Sprint(dividendsIncentivesRule.DividendsIncentivesPercentage) +
"," + dividendsIncentivesRule.DividendsIncentivesStageStart.Format("2006-01-02") +
"~" + dividendsIncentivesRule.DividendsIncentivesStageEnd.Format("2006-01-02") +
"," + fmt.Sprint(dividendsIncentivesRule.ReferrerPercentage) +
"," + fmt.Sprint(dividendsIncentivesRule.SalesmanPercentage) + ";"
}
dividendsIncentivesRuleOriginalTmp := "【" + dividendsIncentivesRuleOriginal + "】"
// 变更后的业绩分红激励规则
var dividendsIncentivesRuleChanged string
for _, dividendsIncentivesRule := range cooperationContractSaved.DividendsIncentivesRules {
dividendsIncentivesRuleChanged = dividendsIncentivesRuleChanged + dividendsIncentivesRule.DividendsIncentivesStageCN +
":" + fmt.Sprint(dividendsIncentivesRule.DividendsIncentivesPercentage) +
"," + dividendsIncentivesRule.DividendsIncentivesStageStart.Format("2006-01-02") +
"~" + dividendsIncentivesRule.DividendsIncentivesStageEnd.Format("2006-01-02") +
"," + fmt.Sprint(dividendsIncentivesRule.ReferrerPercentage) +
"," + fmt.Sprint(dividendsIncentivesRule.SalesmanPercentage) + ";"
}
dividendsIncentivesRuleChangedTmp := "【" + dividendsIncentivesRuleChanged + "】"
// 拼接规则变更
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))
//【第一阶段: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") +
"," + fmt.Sprint(moneyIncentivesRule.ReferrerPercentage) +
"," + fmt.Sprint(moneyIncentivesRule.SalesmanPercentage) + ";"
}
moneyIncentivesRuleOriginalTmp := "【" + moneyIncentivesRuleOriginal + "】"
// 变更后的激励规则
var moneyIncentivesRuleChanged string
for _, moneyIncentivesRule := range cooperationContractSaved.MoneyIncentivesRules {
moneyIncentivesRuleChanged = moneyIncentivesRuleChanged + moneyIncentivesRule.MoneyIncentivesStageCN +
":" +
"," + moneyIncentivesRule.MoneyIncentivesStageStart.Format("2006-01-02") +
"," + fmt.Sprint(moneyIncentivesRule.ReferrerPercentage) +
"," + fmt.Sprint(moneyIncentivesRule.SalesmanPercentage) + ";"
}
moneyIncentivesRuleChangedTmp := "【" + moneyIncentivesRuleChanged + "】"
// 拼接规则变更
incentivesRuleChangeDetail = moneyIncentivesRuleOriginalTmp + " 变更为 " + moneyIncentivesRuleChangedTmp
}
}
}
return cooperationContract, nil
// 【1(张三,李四,王五)2(买买买,,)】变更为【1(张三,,)】
var undertakerChange string
if !cooperationContract.UndertakerSliceEqualBCE(cooperationContractFound.Undertakers, cooperationContractSaved.Undertakers) { // 3.承接人变更
// 原承接人
var undertakersOriginal string
for i, undertaker := range cooperationContractFound.Undertakers {
undertakersOriginal = undertakersOriginal + strconv.FormatInt(int64(i), 10) + "(" + undertaker.UserName + "," + undertaker.Referrer.UserName + "," + undertaker.Salesman.UserName + ")"
}
undertakerChangeTmp1 := "【" + undertakersOriginal + "】"
// 变更承接人
var undertakersChanged string
for i, undertaker := range cooperationContractSaved.Undertakers {
undertakersChanged = undertakersChanged + strconv.FormatInt(int64(i), 10) + "(" + undertaker.UserName + "," + undertaker.Referrer.UserName + "," + undertaker.Salesman.UserName + ")"
}
undertakerChangeTemp2 := "【" + undertakersChanged + "】"
// 拼接承接人变更记录
undertakerChange = undertakerChangeTmp1 + " 变更为 " + undertakerChangeTemp2
}
// 新增共创合约变更记录
newCooperationContractChangeLog := &domain.CooperationContractChangeLog{
IncentivesRule: incentivesRuleChange,
IncentivesRuleDetail: incentivesRuleChangeDetail,
OperationType: domain.EDIT,
Undertakers: undertakerChange,
CooperationContractNumber: cooperationContractSaved.CooperationContractNumber,
Company: company,
Operator: operator,
UpdatedAt: time.Time{},
CreatedAt: time.Now(),
}
// 保存共创合约变更记录
if _, err20 := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err20 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error())
}
if err21 := transactionContext.CommitTransaction(); err21 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err21.Error())
}
return cooperationContractSaved, nil
}
}
... ...
... ... @@ -65,6 +65,16 @@ func (cooperationContractChangeLogService *CooperationContractChangeLogService)
operator = data
}
// 共创合约变更记录仓储初始化
var cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractChangeLogRepository = value
}
newCooperationContractChangeLog := &domain.CooperationContractChangeLog{
IncentivesRule: createCooperationContractChangeLogCommand.IncentivesRule,
IncentivesRuleDetail: createCooperationContractChangeLogCommand.IncentivesRuleDetail,
... ... @@ -77,14 +87,7 @@ func (cooperationContractChangeLogService *CooperationContractChangeLogService)
DeletedAt: time.Time{},
CreatedAt: time.Now(),
}
var cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractChangeLogRepository = value
}
if cooperationContractChangeLog, err := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -126,8 +126,8 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
DividendsReturnedOrderNumber: "",
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderGoodExpense: orderGood.OrderGoodExpense,
OrgId: organization.OrgId,
CompanyId: company.CompanyId,
OrgId: createDividendsOrderCommand.OrgId,
CompanyId: createDividendsOrderCommand.CompanyId,
CreatedAt: time.Time{},
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
... ... @@ -148,7 +148,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
DividendsOrderAmount: dividendsOrderAmount,
OrderTime: orderTime,
DividendTime: time.Time{},
DividendStatus: 0,
DividendStatus: domain.TO_BE_DIVIDEND,
Region: &domain.RegionInfo{
RegionNumber: "",
RegionName: createDividendsOrderCommand.RegionName,
... ...
... ... @@ -5,6 +5,7 @@ import (
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
"time"
)
type OrderGoods struct {
... ... @@ -36,7 +37,7 @@ type CreateDividendsReturnedOrderCommand struct {
// 备注
Remarks string `cname:"备注" json:"remarks" valid:"Required"`
// 退货日期
DividendsReturnedDate string `cname:"退货日期" json:"dividendsReturnedDate" valid:"Required"`
DividendsReturnedDate time.Time `cname:"退货日期" json:"dividendsReturnedDate" valid:"Required"`
// 退货区域名称
RegionName string `cname:"退货区域名称" json:"regionName,omitempty"`
// 订单产品列表
... ...
... ... @@ -121,8 +121,8 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
DividendsReturnedOrderNumber: dividendsReturnedOrderNumber,
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderGoodExpense: 0,
OrgId: organization.OrgId,
CompanyId: company.CompanyId,
OrgId: createDividendsReturnedOrderCommand.OrgId,
CompanyId: createDividendsReturnedOrderCommand.CompanyId,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
... ... @@ -135,19 +135,18 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
OriginalOrderNum: createDividendsReturnedOrderCommand.OriginalOrderNum,
DividendsOrderNumber: createDividendsReturnedOrderCommand.DividendsOrderNumber,
DividendsReturnedCustomerName: createDividendsReturnedOrderCommand.DividendsReturnedCustomerName,
DividendsReturnedDate: time.Time{},
DividendsReturnedDate: createDividendsReturnedOrderCommand.DividendsReturnedDate,
Region: &domain.RegionInfo{
RegionNumber: "",
RegionName: createDividendsReturnedOrderCommand.RegionName,
},
Goods: orderGoods,
Remarks: createDividendsReturnedOrderCommand.Remarks,
DividendStatus: 1,
DividendStatus: domain.TO_BE_DIVIDENDED,
DividendTime: time.Time{},
Org: organization,
Company: company,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
Operator: operator,
OperateTime: time.Now(),
... ...
... ... @@ -9,6 +9,28 @@ const (
TYPE_MONEY_INCENTIVES
)
type IncentivesType int32
const (
DividendsIncentives IncentivesType = 1
MoneyIncentives IncentivesType = 2
)
func (p IncentivesType) String() string {
switch p {
case DividendsIncentives:
return "业绩分红"
case MoneyIncentives:
return "金额激励"
default:
return "未知类型"
}
}
func (cooperationContract *CooperationContract) ReturnIncentivesName(p IncentivesType) string {
return p.String()
}
// CooperationContract 共创项目合约实体
type CooperationContract struct {
// 共创合约ID
... ... @@ -101,3 +123,54 @@ func (cooperationContract *CooperationContract) Update(data map[string]interface
}
return nil
}
// UndertakerSliceEqualBCE 判断承接人Slice是否一样
func (cooperationContract *CooperationContract) UndertakerSliceEqualBCE(a, b []*Undertaker) bool {
if len(a) != len(b) {
return false
}
if (a == nil) != (b == nil) {
return false
}
b = b[:len(a)]
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
// DividendsIncentivesRuleSliceEqualBCE 判断业绩分红激励规则Slice是否一样
func (cooperationContract *CooperationContract) DividendsIncentivesRuleSliceEqualBCE(a, b []*DividendsIncentivesRule) bool {
if len(a) != len(b) {
return false
}
if (a == nil) != (b == nil) {
return false
}
b = b[:len(a)]
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
// MoneyIncentivesRuleSliceEqualBCE 判断金额激励规则Slice是否一样
func (cooperationContract *CooperationContract) MoneyIncentivesRuleSliceEqualBCE(a, b []*MoneyIncentivesRule) bool {
if len(a) != len(b) {
return false
}
if (a == nil) != (b == nil) {
return false
}
b = b[:len(a)]
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
... ...
... ... @@ -2,6 +2,12 @@ package domain
import "time"
const (
EDIT = iota + 1 // 编辑
PAUSE // 暂停
RECOVER // 恢复
)
// CooperationContractChangeLog 共创合约变更日志
type CooperationContractChangeLog struct {
// 共创合约变更日志
... ... @@ -20,6 +26,8 @@ type CooperationContractChangeLog struct {
Company *Company `json:"company"`
// 操作人
Operator *User `json:"operator"`
// 操作时间
OperatorTime time.Time `json:"operatorTime"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 删除时间
... ... @@ -58,56 +66,5 @@ func (cooperationContractChangeLog *CooperationContractChangeLog) Update(data ma
if undertakers, ok := data["undertakers"]; ok {
cooperationContractChangeLog.Undertakers = undertakers.(string)
}
if companyId, ok := data["companyId"]; ok {
cooperationContractChangeLog.Company.CompanyId = companyId.(int64)
}
if companyLogo, ok := data["companyLogo"]; ok {
cooperationContractChangeLog.Company.CompanyLogo = companyLogo.(string)
}
if companyName, ok := data["companyName"]; ok {
cooperationContractChangeLog.Company.CompanyName = companyName.(string)
}
if userId, ok := data["userId"]; ok {
cooperationContractChangeLog.Operator.UserId = userId.(int64)
}
if userBaseId, ok := data["userBaseId"]; ok {
cooperationContractChangeLog.Operator.UserBaseId = userBaseId.(int64)
}
if orgId, ok := data["orgId"]; ok {
cooperationContractChangeLog.Operator.Org.OrgId = orgId.(int64)
}
if orgName, ok := data["orgName"]; ok {
cooperationContractChangeLog.Operator.Org.OrgName = orgName.(string)
}
if departmentId, ok := data["departmentId"]; ok {
cooperationContractChangeLog.Operator.Department.DepartmentId = departmentId.(int64)
}
if departmentName, ok := data["departmentName"]; ok {
cooperationContractChangeLog.Operator.Department.DepartmentName = departmentName.(string)
}
if departmentNumber, ok := data["departmentNumber"]; ok {
cooperationContractChangeLog.Operator.Department.DepartmentNumber = departmentNumber.(string)
}
if userAvatar, ok := data["userAvatar"]; ok {
cooperationContractChangeLog.Operator.UserInfo.UserAvatar = userAvatar.(string)
}
if userEmail, ok := data["userEmail"]; ok {
cooperationContractChangeLog.Operator.UserInfo.UserEmail = userEmail.(string)
}
if userName, ok := data["userName"]; ok {
cooperationContractChangeLog.Operator.UserInfo.UserName = userName.(string)
}
if userPhone, ok := data["userPhone"]; ok {
cooperationContractChangeLog.Operator.UserInfo.UserPhone = userPhone.(string)
}
if userAccount, ok := data["userAccount"]; ok {
cooperationContractChangeLog.Operator.UserInfo.UserAccount = userAccount.(string)
}
if userType, ok := data["userType"]; ok {
cooperationContractChangeLog.Operator.UserType = userType.(int32)
}
if status, ok := data["status"]; ok {
cooperationContractChangeLog.Operator.Status = status.(int32)
}
return nil
}
... ...
... ... @@ -2,6 +2,12 @@ package domain
import "time"
const (
TO_BE_DIVIDEND = iota + 1
ALL_DIVIDENDED
PART_DIVIDENDED
)
// DividendsOrder 分红订单实体
type DividendsOrder struct {
// 分红订单ID
... ...
... ... @@ -23,6 +23,8 @@ type CooperationContractChangeLog struct {
Company *domain.Company `comment:"公司"`
// 操作人
Operator *domain.User `comment:"操作人"`
// 操作时间
OperatorTime time.Time `comment:"操作时间"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 删除时间
... ...
... ... @@ -34,6 +34,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
"undertakers",
"company",
"operator",
"operator_time",
"updated_at",
"deleted_at",
"created_at",
... ... @@ -60,6 +61,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
&cooperationContractChangeLog.Undertakers,
&cooperationContractChangeLog.Company,
&cooperationContractChangeLog.Operator,
&cooperationContractChangeLog.OperatorTime,
&cooperationContractChangeLog.UpdatedAt,
&cooperationContractChangeLog.DeletedAt,
&cooperationContractChangeLog.CreatedAt,
... ... @@ -72,6 +74,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
cooperationContractChangeLog.Undertakers,
cooperationContractChangeLog.Company,
cooperationContractChangeLog.Operator,
cooperationContractChangeLog.OperatorTime,
cooperationContractChangeLog.UpdatedAt,
nil,
cooperationContractChangeLog.CreatedAt,
... ... @@ -88,6 +91,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
&cooperationContractChangeLog.Undertakers,
&cooperationContractChangeLog.Company,
&cooperationContractChangeLog.Operator,
&cooperationContractChangeLog.OperatorTime,
&cooperationContractChangeLog.UpdatedAt,
&cooperationContractChangeLog.DeletedAt,
&cooperationContractChangeLog.CreatedAt,
... ... @@ -100,6 +104,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
cooperationContractChangeLog.Undertakers,
cooperationContractChangeLog.Company,
cooperationContractChangeLog.Operator,
cooperationContractChangeLog.OperatorTime,
cooperationContractChangeLog.UpdatedAt,
nil,
cooperationContractChangeLog.CreatedAt,
... ...