作者 陈志颖

fix:修复更新共创合约

... ... @@ -30,7 +30,7 @@ type UpdateCooperationContractCommand struct {
// 承接方列表
Undertakers []*CreateUndertakersCommand `cname:"承接方列表" json:"undertakers,omitempty"`
// 相关人UID列表
RelevantPeople []string `cname:"相关人列表" json:"relevantPeople,omitempty"`
RelevantIds []string `cname:"相关人列表" json:"relevantIds,omitempty"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"`
// 组织机构ID
... ...
... ... @@ -840,7 +840,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 获取公司信息
var company *domain.Company
if data, err4 := companyService.CompanyFrom(updateCooperationContractCommand.CompanyId); err4 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司信息失败")
} else {
company = data
}
... ... @@ -856,7 +856,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 获取组织机构信息
var organization *domain.Org
if data, err6 := organizationService.OrgFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId); err6 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取组织机构失败")
} else {
organization = data
}
... ... @@ -907,9 +907,12 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 获取发起人
var sponsor *domain.User
sponsorUid, _ := strconv.ParseInt(updateCooperationContractCommand.SponsorUid, 10, 64)
sponsorUid, err := strconv.ParseInt(updateCooperationContractCommand.SponsorUid, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "发起人UID类型错误")
}
if data, err11 := userService.OperatorFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, sponsorUid); err11 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err11.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取发起人失败")
} else {
sponsor = data
}
... ... @@ -917,7 +920,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 获取操作人
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())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取操作人失败")
} else {
operator = data
}
... ... @@ -927,11 +930,14 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 获取相关人
var relevantPeople []*domain.Relevant
for _, relevantPersonUid := range updateCooperationContractCommand.RelevantPeople {
for _, relevantPersonUid := range updateCooperationContractCommand.RelevantIds {
var relevantDomain *domain.Relevant
relevantUid, _ := strconv.ParseInt(relevantPersonUid, 10, 64)
relevantUid, err := strconv.ParseInt(relevantPersonUid, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "相关人UID类型错误")
}
if data, err12 := userService.RelevantFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, relevantUid); err12 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err12.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取相关人失败")
} else {
relevantDomain = data
}
... ... @@ -958,7 +964,10 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
var undertakers []*domain.Undertaker
for _, undertaker := range updateCooperationContractCommand.Undertakers {
var undertakerDomain *domain.Undertaker
undertakerUid, _ := strconv.ParseInt(undertaker.UserId, 10, 64)
undertakerUid, err := strconv.ParseInt(undertaker.UserId, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "承接人UID类型错误")
}
if data, err13 := userService.UndertakerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, undertakerUid); err13 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err13.Error())
} else {
... ... @@ -967,33 +976,42 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 获取推荐人
var referrerDomain *domain.Referrer
referrerUid, _ := strconv.ParseInt(undertaker.ReferrerId, 10, 64)
if undertaker.ReferrerId != "" {
referrerUid, err := strconv.ParseInt(undertaker.ReferrerId, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "推荐人UID类型错误")
}
if referrerUid > 0 {
if data, err14 := userService.ReferrerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, referrerUid); err14 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err14.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取推荐人失败")
} else {
referrerDomain = data
}
}
}
// 获取业务员
var salesmanDomain *domain.Salesman
if undertaker.SalesmanId != "" {
salesmanUid, err22 := strconv.ParseInt(undertaker.SalesmanId, 10, 64)
if err22 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err22.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "业务员UID类型错误")
}
if salesmanUid > 0 {
if data, err15 := userService.SalesmanFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, salesmanUid); err15 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err15.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取业务员失败")
} else {
salesmanDomain = data
}
}
}
// 承接人ID类型转换
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,
UserId: undertakerDomain.UserId,
... ... @@ -1038,6 +1056,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
CreatedAt: time.Now(),
})
}
// 更新分红规则列表
cooperationContract.DividendsIncentivesRules = dividendsIncentivesRules
... ... @@ -1065,6 +1084,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
CreatedAt: time.Now(),
})
}
// 更新金额激励规则列表
cooperationContract.MoneyIncentivesRules = moneyIncentivesRules
... ... @@ -1218,9 +1238,40 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 原承接人
var undertakersOriginal string
for i, undertaker := range cooperationContractFound.Undertakers {
if undertaker.Referrer == nil {
undertaker.Referrer = &domain.Referrer{
UserId: 0,
UserBaseId: 0,
Roles: nil,
Orgs: nil,
Org: nil,
Department: nil,
Company: nil,
UserInfo: nil,
UserType: 0,
UserName: "",
UserPhone: "",
}
}
if undertaker.Salesman == nil {
undertaker.Salesman = &domain.Salesman{
UserId: 0,
UserBaseId: 0,
Roles: nil,
Orgs: nil,
Org: nil,
Department: nil,
Company: nil,
UserInfo: nil,
UserType: 0,
UserName: "",
UserPhone: "",
}
}
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 {
... ...
... ... @@ -19,7 +19,7 @@ type OrderGoods struct {
// 订单产品数量
OrderGoodQuantity int64 `json:"orderGoodQuantity"`
// 关联分红订单号
DividendsOrderNumber int64 `json:"dividendsOrderNumber"`
DividendsOrderNumber string `json:"dividendsOrderNumber"`
// 关联的共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 订单产品费用
... ...
... ... @@ -307,6 +307,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
CreatedAt: time.Now(),
})
}
// 添加相关人
if len(cooperationContractRelevantPeopleToAddModels) > 0 {
if _, err := tx.Model(&cooperationContractRelevantPeopleToAddModels).Insert(); err != nil {
... ... @@ -394,8 +395,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
Roles: undertakerDomain.Roles,
UserInfo: undertakerDomain.UserInfo,
UserType: undertakerDomain.UserType,
Referrer: undertakerDomain.Referrer,
Salesman: undertakerDomain.Salesman,
Status: undertakerDomain.Status,
Company: undertakerDomain.Company,
ContractAttachment: undertakerDomain.ContractAttachment,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
... ... @@ -430,6 +434,32 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
log.Logger.Info("待更新的承接人", map[string]interface{}{
"待更新的承接人": undertakerModelsToUpdate,
})
for i, undertakerModelToUpdate := range undertakerModelsToUpdate {
for j, undertaker := range cooperationContract.Undertakers {
if undertaker.UndertakerId == undertakerModelToUpdate.CooperationContractUndertakerId {
undertakerModelsToUpdate[i] = &models.CooperationContractUndertaker{
CooperationContractUndertakerId: cooperationContract.Undertakers[j].UndertakerId,
CooperationContractNumber: cooperationContract.Undertakers[j].CooperationContractNumber,
UserId: cooperationContract.Undertakers[j].UserId,
UserBaseId: cooperationContract.Undertakers[j].UserBaseId,
Org: cooperationContract.Undertakers[j].Org,
Orgs: cooperationContract.Undertakers[j].Orgs,
Department: cooperationContract.Undertakers[j].Department,
Roles: cooperationContract.Undertakers[j].Roles,
UserInfo: cooperationContract.Undertakers[j].UserInfo,
UserType: cooperationContract.Undertakers[j].UserType,
Referrer: cooperationContract.Undertakers[j].Referrer,
Salesman: cooperationContract.Undertakers[j].Salesman,
Status: cooperationContract.Undertakers[j].Status,
Company: cooperationContract.Undertakers[j].Company,
ContractAttachment: cooperationContract.Undertakers[j].ContractAttachment,
CreatedAt: undertakerModelsToUpdate[i].CreatedAt,
UpdatedAt: time.Now(),
DeletedAt: undertakerModelsToUpdate[i].DeletedAt,
}
}
}
}
if len(undertakerModelsToUpdate) > 0 {
if _, err := tx.Model(&undertakerModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
... ... @@ -492,6 +522,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
DividendsIncentivesStage: dividendsIncentivesRuleDomain.DividendsIncentivesStage,
DividendsIncentivesStageEnd: dividendsIncentivesRuleDomain.DividendsIncentivesStageEnd,
DividendsIncentivesStageStart: dividendsIncentivesRuleDomain.DividendsIncentivesStageStart,
Remarks: dividendsIncentivesRuleDomain.Remarks,
Org: dividendsIncentivesRuleDomain.Org,
Company: dividendsIncentivesRuleDomain.Company,
UpdatedAt: time.Time{},
... ... @@ -588,6 +619,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
MoneyIncentivesTime: moneyIncentivesRuleDomain.MoneyIncentivesTime,
ReferrerPercentage: moneyIncentivesRuleDomain.ReferrerPercentage,
SalesmanPercentage: moneyIncentivesRuleDomain.SalesmanPercentage,
Remarks: moneyIncentivesRuleDomain.Remarks,
Org: moneyIncentivesRuleDomain.Org,
Company: moneyIncentivesRuleDomain.Company,
UpdatedAt: time.Time{},
... ... @@ -673,6 +705,7 @@ func (repository *CooperationContractRepository) UpdateOne(cooperationContract *
CooperationModeNumber: cooperationContract.CooperationMode.CooperationModeNumber,
Status: cooperationContract.Status,
Org: cooperationContract.Org,
IncentivesType: cooperationContract.IncentivesType,
Company: cooperationContract.Company,
Department: cooperationContract.Department,
Operator: cooperationContract.Operator,
... ... @@ -702,6 +735,7 @@ func (repository *CooperationContractRepository) UpdateMany(cooperationContracts
CooperationModeNumber: cooperationContract.CooperationMode.CooperationModeNumber,
Status: cooperationContract.Status,
Org: cooperationContract.Org,
IncentivesType: cooperationContract.IncentivesType,
Company: cooperationContract.Company,
Department: cooperationContract.Department,
Operator: cooperationContract.Operator,
... ...