作者 yangfu

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…

…ion-cooperation into dev
正在显示 25 个修改的文件 包含 381 行增加63 行删除
... ... @@ -17,6 +17,8 @@ type SearchCooperationApplicationQuery struct {
ApplicantName string `cname:"申请人姓名" json:"applicantName,omitempty"`
// 共创申请审核状态,1待审核,2已同意,3已拒绝
CooperationApplicationStatus int32 `cname:"共创申请审核状态" json:"cooperationApplicationStatus,omitempty"`
// 是否被取消标记 1正常,2取消,3所有
IsCanceled int32 `cname:"取消状态" json:"isCanceled,omitempty"`
// 页面大小
PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"`
// 页面大小
... ...
... ... @@ -205,6 +205,11 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
if cooperationApplication, err := cooperationApplicationRepository.Save(newCooperationApplication); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
// 更新共创项目申请人计数
cooperationProject.ApplicantCount = cooperationProject.ApplicantCount + 1
if _, err := cooperationProjectRepository.Save(cooperationProject); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -269,6 +274,11 @@ func (cooperationApplicationService *CooperationApplicationService) ApprovalCoop
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(cooperationApplicationId, 10)))
}
// 校验共创申请是否已经审核过
if cooperationApplication.CooperationApplicationStatus != 1 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "改申请已经审核过")
}
if approvalCooperationApplicationCommand.Action == 1 {
cooperationApplication.CooperationApplicationStatus = 2
} else if approvalCooperationApplicationCommand.Action == 2 {
... ... @@ -346,7 +356,12 @@ func (cooperationApplicationService *CooperationApplicationService) BatchApprova
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 {
for i, _ := range cooperationApplications {
for i, cooperationApplication := range cooperationApplications {
// 校验共创申请是否已经审核过
if cooperationApplication.CooperationApplicationStatus != 1 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "改申请已经审核过")
}
// 更新共创申请数据
cooperationApplications[i].CooperationApplicationVerifyDescription = batchApprovalCooperationApplicationCommand.CooperationApplicationVerifyDescription
if batchApprovalCooperationApplicationCommand.Action == 1 { // 同意
cooperationApplications[i].CooperationApplicationStatus = 2
... ... @@ -421,7 +436,12 @@ func (cooperationApplicationService *CooperationApplicationService) OneClickAppr
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 {
for i, _ := range cooperationApplications {
for i, cooperationApplication := range cooperationApplications {
// 校验共创申请是否已经审核过
if cooperationApplication.CooperationApplicationStatus != 1 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "改申请已经审核过")
}
// 更新共创申请
if oneClickApprovalCooperationApplicationCommand.Action == 1 {
cooperationApplications[i].CooperationApplicationStatus = 2
} else if oneClickApprovalCooperationApplicationCommand.Action == 2 {
... ... @@ -784,8 +804,19 @@ func (cooperationApplicationService *CooperationApplicationService) CancelCooper
defer func() {
_ = transactionContext.RollbackTransaction()
}()
//TODO 校验用户菜单模块权限
// 共创项目仓储初始化
var cooperationProjectRepository domain.CooperationProjectRepository
if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationProjectRepository = value
}
// 共创申请仓储初始化
var cooperationApplicationRepository domain.CooperationApplicationRepository
if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
... ... @@ -811,13 +842,26 @@ func (cooperationApplicationService *CooperationApplicationService) CancelCooper
}); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if cooperationApplication, err := cooperationApplicationRepository.Save(cooperationApplication); err != nil {
if cooperationApplicationSaved, err := cooperationApplicationRepository.Save(cooperationApplication); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
// 获取共创项目
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": cooperationApplicationSaved.CooperationProject.CooperationProjectId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创项目不存在")
}
if cooperationProject == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s不存在", strconv.FormatInt(cooperationApplicationSaved.CooperationProject.CooperationProjectId, 10)))
}
// 更新共创项目申请统计
cooperationProject.ApplicantCount = cooperationProject.ApplicantCount - 1
if _, err := cooperationProjectRepository.Save(cooperationProject); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cooperationApplication, nil
return cooperationApplicationSaved, nil
}
}
... ...
... ... @@ -17,6 +17,8 @@ type SearchCooperationContractQuery struct {
CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber,omitempty"`
// 发起人姓名
SponsorName string `cname:"发起人姓名" json:"sponsorName,omitempty"`
// 激励类型
IncentivesType int32 `cname:"激励类型" json:"incentivesType,omitempty"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId"`
// 组织机构ID
... ... @@ -30,7 +32,6 @@ type SearchCooperationContractQuery struct {
}
func (searchCooperationContractQuery *SearchCooperationContractQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (searchCooperationContractQuery *SearchCooperationContractQuery) ValidateQuery() error {
... ...
... ... @@ -126,7 +126,9 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
}
// 生成共创合约编号
contractNumber, err2 := cooperationContractDao.GenerateContractNumber()
contractNumber, err2 := cooperationContractDao.GenerateContractNumber(map[string]interface{}{
"companyId": createCooperationContractCommand.CompanyId,
})
if err2 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err2.Error())
}
... ... @@ -134,7 +136,6 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
// 校验共创合约编号是否唯一
numberAvailable, _ := cooperationContractDao.CheckContractNumberAvailable(map[string]interface{}{
"companyId": createCooperationContractCommand.CompanyId,
"orgId": createCooperationContractCommand.OrgId,
"cooperationContractNumber": contractNumber,
})
if !numberAvailable {
... ... @@ -1054,6 +1055,16 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err16.Error())
}
var contractAttachments []*domain.Attachment
for _, attachment := range undertaker.ContractAttachment {
contractAttachments = append(contractAttachments, &domain.Attachment{
FileType: attachment.FileType,
Name: attachment.Name,
Url: attachment.Url,
FileSize: attachment.FileSize,
})
}
undertakers = append(undertakers, &domain.Undertaker{
UndertakerId: undertakerId,
UserId: undertakerDomain.UserId,
... ... @@ -1069,7 +1080,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
Salesman: salesmanDomain,
Status: undertakerDomain.Status,
Company: undertakerDomain.Company,
ContractAttachment: nil,
ContractAttachment: contractAttachments,
})
}
// 更新承接人
... ... @@ -1117,7 +1128,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
MoneyIncentivesStage: moneyIncentivesRule.MoneyIncentivesStage,
MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd,
MoneyIncentivesStageStart: moneyIncentivesRule.MoneyIncentivesStageStart,
MoneyIncentivesTime: time.Now(),
MoneyIncentivesTime: moneyIncentivesRule.MoneyIncentivesTime,
ReferrerPercentage: moneyIncentivesRule.ReferrerPercentage,
SalesmanPercentage: moneyIncentivesRule.SalesmanPercentage,
Org: organization,
... ...
... ... @@ -163,7 +163,9 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro
cooperationProjectDao = value
}
// 生成共创项目编号
projectNumber, err2 := cooperationProjectDao.GenerateProjectNumber()
projectNumber, err2 := cooperationProjectDao.GenerateProjectNumber(map[string]interface{}{
"companyId": createCooperationProjectCommand.CompanyId,
})
if err2 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -145,7 +145,6 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred
}
// 预算明细
var creditAccounts []*domain.CreditAccount
var accountDetail []*domain.AccountDetail
var settlementAmount float64
for _, dividendsEstimate := range dividendsEstimates {
... ... @@ -158,7 +157,9 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred
}
// 生成账期结算单号
creditAccountNumber, err12 := creditAccountDao.GenerateCreditAccountNumber()
creditAccountNumber, err12 := creditAccountDao.GenerateCreditAccountNumber(map[string]interface{}{
"companyId": createCreditAccountCommand.CompanyId,
})
if err12 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "生成账期结算单号错误")
}
... ... @@ -179,7 +180,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred
Department: dividendsEstimates[0].DividendsUser.Department,
Roles: dividendsEstimates[0].DividendsUser.Roles,
UserInfo: dividendsEstimates[0].DividendsUser.UserInfo,
UserName: dividendsEstimates[0].DividendsUser.UserName,
UserName: dividendsEstimates[0].DividendsUser.UserInfo.UserName,
UserPhone: dividendsEstimates[0].DividendsUser.UserPhone,
UserType: dividendsEstimates[0].DividendsUser.UserType,
Status: dividendsEstimates[0].DividendsUser.Status,
... ... @@ -199,13 +200,19 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred
if creditAccount, err13 := creditAccountRepository.Save(newCreditAccount); err13 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err13.Error())
} else {
creditAccounts = append(creditAccounts, creditAccount)
// 变更分红预算单结算状态
for i, _ := range dividendsEstimates {
dividendsEstimates[i].DividendsAccountStatus = 2
}
_, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimates)
if err3 != nil {
return nil, err3
}
if err14 := transactionContext.CommitTransaction(); err14 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err14.Error())
}
return creditAccounts, nil
return creditAccount, nil
}
}
}
... ... @@ -353,6 +360,7 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco
if creditAccountSaved, err4 := creditAccountRepository.Save(creditAccount); err4 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
} else {
// TODO 更新分红预算单结算状态(已支付)
if err3 := transactionContext.CommitTransaction(); err3 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
}
... ...
... ... @@ -609,8 +609,11 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
})
}
// 统计分红订单
var countDividendsOrders int32
// 统计成功预算的分红订单
var estimateSuccessfullyDividendsOrders map[string]int
// 统计预算失败的分红订单
var estimateFailedDividendsOrders map[string]int
// 获取订单产品
if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{
... ... @@ -622,7 +625,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
// 统计当前分红预算单数
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
"orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -694,7 +696,11 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
} else {
for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
// 生成分红预算单号
dividendsEstimateOrderNumber, err := dividendsEstimateDao.GenerateDividendsEstimateNumber()
dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
countDividendsEstimate = countDividendsEstimate + 1
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -730,16 +736,17 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
log.Logger.Info("新增的分红预算单", map[string]interface{}{
"dividendsEstimates": dividendsEstimates,
})
if dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// TODO 分析成功和失败原因
// 分析成功和失败原因
successfullyCount := len(dividendsEstimatesSaved)
return fmt.Sprintf("已完成%d笔单订单分红预算,生成%d笔单分红预算,%d笔订单分红预算失败,失败原因:%s", countDividendsOrders, successfullyCount, 0, ""), nil
return map[string]interface{}{
"report": fmt.Sprintf("已完成%d笔单订单分红预算,生成%d笔单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), ""),
}, nil
}
}
}
... ... @@ -849,16 +856,22 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
var dividendsEstimates []*domain.DividendsEstimate
// 统计当前分红预算单数
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
"companyId": confirmMoneyIncentivesEstimateCommand.CompanyId,
})
var countDividendsEstimate int64
// 共创合约预算
if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage, undertakerUIDs); err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
} else {
for _, dividendsEstimateDetail := range dividendsEstimateDetails {
// 生成分红预算单号
dividendsEstimateOrderNumber, err := dividendsEstimateDao.GenerateDividendsEstimateNumber()
dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
countDividendsEstimate = countDividendsEstimate + 1
dividendsEstimate := &domain.DividendsEstimate{
DividendsEstimateId: 0,
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
... ...
... ... @@ -100,7 +100,9 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
}
// 生成分红订单号
dividendsOrderNumber, err := dividendsOrderDao.GenerateDividendsOrderNumber()
dividendsOrderNumber, err := dividendsOrderDao.GenerateDividendsOrderNumber(map[string]interface{}{
"companyId": createDividendsOrderCommand.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -108,7 +110,6 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
// 校验分红订单编号是否唯一
numberAvailable, err := dividendsOrderDao.CheckDividendsOrderNumberAvailable(map[string]interface{}{
"companyId": createDividendsOrderCommand.CompanyId,
"orgId": createDividendsOrderCommand.OrgId,
"dividendsOrderNumber": dividendsOrderNumber,
})
if err != nil {
... ... @@ -118,11 +119,44 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常")
}
// 合约仓储初始化
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractRepository = value
}
// 查找合约
var cooperationContractsMap map[string]*domain.CooperationContract
if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
"companyId": createDividendsOrderCommand.CompanyId,
"orgId": createDividendsOrderCommand.OrgId,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 {
for _, cooperationContract := range cooperationContracts {
cooperationContractsMap[cooperationContract.CooperationContractNumber] = cooperationContract
}
}
}
// 新增订单产品
var orderGoods []*domain.OrderGood
var dividendsOrderAmount float64
for _, orderGood := range createDividendsOrderCommand.OrderGoods {
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Float64()
// 计算订单产品金额
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
// 校验共创合约
if orderGood.CooperationContractNumber != "" {
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单产品不能关联金额激励规则")
}
}
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: 0,
OrderGoodAmount: orderGoodAmount,
... ... @@ -141,7 +175,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
UpdatedAt: time.Time{},
})
// 计算分红订单金额
dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense))).Float64()
dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense))).Float64()
}
// 订单时间转换
... ... @@ -269,13 +303,20 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
}
// 查找合约
_, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
var cooperationContractsMap map[string]*domain.CooperationContract
countContracts, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
"offsetLimit": false,
"companyId": importDividendsOrderCommand.CompanyId,
"orgId": importDividendsOrderCommand.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if countContracts > 0 {
for _, cooperationContract := range cooperationContracts {
cooperationContractsMap[cooperationContract.CooperationContractNumber] = cooperationContract
}
}
}
// 分红订单DAO初始化
... ... @@ -673,7 +714,14 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
}
// 计算产品金额
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Float64()
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
// 校验共创合约激励类型是否正确
if orderGood.CooperationContractNumber != "" {
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则")
}
}
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: 0,
... ...
... ... @@ -24,6 +24,8 @@ type OrderGoods struct {
CooperationContractNumber string `cname:"关联的共创合约编号" json:"cooperationContractNumber"`
// 订单产品费用
OrderGoodExpense float64 `cname:"订单产品费用" json:"orderGoodExpense"`
//行号-错误信息返回
LineNumber int `json:"lineNumber"`
}
type CreateDividendsReturnedOrderCommand struct {
... ...
... ... @@ -99,7 +99,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
}
// 生成分红订单号
dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber()
dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber(map[string]interface{}{
"companyId": createDividendsReturnedOrderCommand.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -121,7 +123,6 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
// 校验分红退货单编号是否唯一
numberAvailable, err := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{
"companyId": createDividendsReturnedOrderCommand.CompanyId,
"orgId": createDividendsReturnedOrderCommand.OrgId,
"dividendsReturnedOrderNumber": dividendsReturnedOrderNumber,
})
if err != nil {
... ... @@ -131,13 +132,46 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单号已存在")
}
// 合约仓储初始化
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractRepository = value
}
// 查找合约
var cooperationContractsMap map[string]*domain.CooperationContract
if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
"companyId": createDividendsReturnedOrderCommand.CompanyId,
"orgId": createDividendsReturnedOrderCommand.OrgId,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 {
for _, cooperationContract := range cooperationContracts {
cooperationContractsMap[cooperationContract.CooperationContractNumber] = cooperationContract
}
}
}
// 退货金额
var dividendsReturnedOrderRefund float64
// 获取分红退货单产品
// 新增分红退货单产品
var orderGoods []*domain.OrderGood
for _, orderGood := range createDividendsReturnedOrderCommand.OrderGoods {
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Float64()
// 退货产品金额计算
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
// 校验合约激励类型是否正确
if orderGood.CooperationContractNumber != "" {
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则")
}
}
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: 0,
OrderGoodAmount: orderGoodAmount,
... ... @@ -321,6 +355,33 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
dividendsReturnedOrderRepository = value
}
// 合约仓储初始化
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractRepository = value
}
// 查找合约
var cooperationContractsMap map[string]*domain.CooperationContract
countContracts, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
"offsetLimit": false,
"companyId": importDividendsReturnedOrderCommand.CompanyId,
"orgId": importDividendsReturnedOrderCommand.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if countContracts > 0 {
for _, cooperationContract := range cooperationContracts {
cooperationContractsMap[cooperationContract.CooperationContractNumber] = cooperationContract
}
}
}
// 返回信息表头定义
var tableHeader = map[string]interface{}{
"failReason": "错误详情",
... ... @@ -664,7 +725,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
// 批量导入创建退货单
for _, dividendsReturnedOrder := range createDividendsReturnedOrderCommands {
// 生成退货订单号
dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber()
dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber(map[string]interface{}{
"companyId": importDividendsReturnedOrderCommand.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -672,7 +735,6 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
// 校验退货订单编号是否唯一
numberAvailable, err3 := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{
"companyId": importDividendsReturnedOrderCommand.CompanyId,
"orgId": importDividendsReturnedOrderCommand.OrgId,
"dividendsReturnedOrderNumber": dividendsReturnedOrderNumber,
})
if err3 != nil {
... ... @@ -685,10 +747,32 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
// 新增订单产品
var orderGoods []*domain.OrderGood
var dividendsReturnedOrderAmount float64
for _, orderGood := range dividendsReturnedOrder.OrderGoods {
orderGoodErrMap := make(map[int]interface{}, 0)
for i, orderGood := range dividendsReturnedOrder.OrderGoods {
// 校验共创合约是否合法
contractNumberExist := false
for _, cooperationContract := range cooperationContracts {
if orderGood.CooperationContractNumber == cooperationContract.CooperationContractNumber {
contractNumberExist = true
break
}
}
if !contractNumberExist {
orderGoodErrMap[dividendsReturnedOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("共创合约编号不存在:%s", err))
}
// 计算产品金额
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
// 校验合约激励类型是否正确
if orderGood.CooperationContractNumber != "" {
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
orderGoodErrMap[dividendsReturnedOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则")
}
}
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: 0,
OrderGoodAmount: orderGood.OrderGoodAmount,
OrderGoodAmount: orderGoodAmount,
OrderGoodName: orderGood.OrderGoodName,
OrderGoodPrice: orderGood.OrderGoodPrice,
OrderGoodQuantity: orderGood.OrderGoodQuantity,
... ...
... ... @@ -26,7 +26,7 @@ type CooperationApplication struct {
CooperationProject *CooperationProject `json:"cooperationProject"`
// 数据所属组织机构
Org *Org `json:"org"`
// 是否被取消标志位
// 是否被取消标志位 1未取消,2取消
IsCanceled int32 `json:"isCanceled"`
// 公司
Company *Company `json:"company"`
... ...
... ... @@ -22,7 +22,7 @@ type CooperationProject struct {
CooperationMode *CooperationMode `json:"cooperationMode"`
// 共创项目发起部门
Department *Department `json:"department"`
// 共创项目承接对象,1员工,2共创用户,3公开,可以多选
// 共创项目承接对象,1员工,2共创用户,4公开,可以多选
CooperationProjectUndertakerTypes []int32 `json:"cooperationProjectUndertakerTypes"`
// 数据所属组织机构
Org *Org `json:"org"`
... ...
... ... @@ -17,7 +17,7 @@ type CooperationContractDao struct {
}
// GenerateContractNumber 生成共创合约编号
func (dao *CooperationContractDao) GenerateContractNumber() (string, error) {
func (dao *CooperationContractDao) GenerateContractNumber(queryOptions map[string]interface{}) (string, error) {
tx := dao.transactionContext.PgTx
var cooperationContractModels []*models.CooperationContract
query := tx.Model(&cooperationContractModels)
... ... @@ -26,9 +26,13 @@ func (dao *CooperationContractDao) GenerateContractNumber() (string, error) {
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("cooperation_contract.created_at >= ?", todayZeroTime)
query.Where("cooperation_contract.created_at < ?", nextDayZeroTime)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`cooperation_contract.company @> '{"companyId":"?"}'`, companyId)
}
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
if count < 1000 {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
... ... @@ -36,6 +40,16 @@ func (dao *CooperationContractDao) GenerateContractNumber() (string, error) {
timeString = timeString[2:len(timeString)]
contractNumber := "HY" + timeString + "#" + countStr
return contractNumber, nil
} else {
countStr := fmt.Sprintf("%d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
dividendsOrderNumber := "HY" + timeString + "#" + countStr
return dividendsOrderNumber, nil
}
}
}
... ...
... ... @@ -13,7 +13,7 @@ type CooperationProjectDao struct {
}
// GenerateProjectNumber 生成共创项目编码
func (dao *CooperationProjectDao) GenerateProjectNumber() (string, error) {
func (dao *CooperationProjectDao) GenerateProjectNumber(queryOptions map[string]interface{}) (string, error) {
tx := dao.transactionContext.PgTx
var cooperationProjectModels []*models.CooperationProject
query := tx.Model(&cooperationProjectModels)
... ... @@ -22,9 +22,13 @@ func (dao *CooperationProjectDao) GenerateProjectNumber() (string, error) {
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("cooperation_project.created_at >= ?", todayZeroTime)
query.Where("cooperation_project.created_at < ?", nextDayZeroTime)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`cooperation_contract.company @> '{"companyId":"?"}'`, companyId)
}
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
if count < 1000 {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
... ... @@ -32,6 +36,15 @@ func (dao *CooperationProjectDao) GenerateProjectNumber() (string, error) {
timeString = timeString[2:len(timeString)]
contractNumber := "XM" + timeString + "#" + countStr
return contractNumber, nil
} else {
countStr := fmt.Sprintf("%d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
contractNumber := "XM" + timeString + "#" + countStr
return contractNumber, nil
}
}
}
... ...
... ... @@ -13,7 +13,7 @@ type CreditAccountDao struct {
}
// GenerateCreditAccountNumber 生成账期结算单号
func (dao *CreditAccountDao) GenerateCreditAccountNumber() (string, error) {
func (dao *CreditAccountDao) GenerateCreditAccountNumber(queryOptions map[string]interface{}) (string, error) {
tx := dao.transactionContext.PgTx
var creditAccountModels []*models.CreditAccount
query := tx.Model(&creditAccountModels)
... ... @@ -22,9 +22,13 @@ func (dao *CreditAccountDao) GenerateCreditAccountNumber() (string, error) {
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("credit_account.created_at >= ?", todayZeroTime)
query.Where("credit_account.created_at < ?", nextDayZeroTime)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`credit_account.company @> '{"companyId":"?"}'`, companyId)
}
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
if count < 1000 {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
... ... @@ -32,6 +36,15 @@ func (dao *CreditAccountDao) GenerateCreditAccountNumber() (string, error) {
timeString = timeString[2:len(timeString)]
creditAccountNumber := "JS" + timeString + "#" + countStr
return creditAccountNumber, nil
} else {
countStr := fmt.Sprintf("%d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
creditAccountNumber := "JS" + timeString + "#" + countStr
return creditAccountNumber, nil
}
}
}
... ...
... ... @@ -13,7 +13,7 @@ type DividendsEstimateDao struct {
}
// GenerateDividendsEstimateNumber 生成分红预算单号
func (dao *DividendsEstimateDao) GenerateDividendsEstimateNumber() (string, error) {
func (dao *DividendsEstimateDao) GenerateDividendsEstimateNumber(queryOptions map[string]interface{}) (string, error) {
tx := dao.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
query := tx.Model(&dividendsEstimateModels)
... ... @@ -22,9 +22,13 @@ func (dao *DividendsEstimateDao) GenerateDividendsEstimateNumber() (string, erro
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("dividends_estimate.created_at >= ?", todayZeroTime)
query.Where("dividends_estimate.created_at < ?", nextDayZeroTime)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
}
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
if count < 1000 {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
... ... @@ -32,6 +36,16 @@ func (dao *DividendsEstimateDao) GenerateDividendsEstimateNumber() (string, erro
timeString = timeString[2:len(timeString)]
dividendsOrderNumber := "FH" + timeString + "#" + countStr
return dividendsOrderNumber, nil
} else {
countStr := fmt.Sprintf("%d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
dividendsOrderNumber := "FH" + timeString + "#" + countStr
return dividendsOrderNumber, nil
}
}
}
... ...
... ... @@ -13,7 +13,7 @@ type DividendsOrderDao struct {
}
// GenerateDividendsOrderNumber 生成分红订单号
func (dao *DividendsOrderDao) GenerateDividendsOrderNumber() (string, error) {
func (dao *DividendsOrderDao) GenerateDividendsOrderNumber(queryOptions map[string]interface{}) (string, error) {
tx := dao.transactionContext.PgTx
var dividendsOrderModels []*models.DividendsOrder
query := tx.Model(&dividendsOrderModels)
... ... @@ -22,6 +22,9 @@ func (dao *DividendsOrderDao) GenerateDividendsOrderNumber() (string, error) {
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("dividends_order.created_at >= ?", todayZeroTime)
query.Where("dividends_order.created_at < ?", nextDayZeroTime)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_order.company @> '{"companyId":"?"}'`, companyId)
}
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
... ...
... ... @@ -13,7 +13,7 @@ type DividendsReturnedOrderDao struct {
}
// GenerateDividendsReturnedOrderNumber 生成分红退货单号
func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber() (string, error) {
func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber(queryOptions map[string]interface{}) (string, error) {
tx := dao.transactionContext.PgTx
var dividendsReturnedOrderModels []*models.DividendsReturnedOrder
query := tx.Model(&dividendsReturnedOrderModels)
... ... @@ -22,6 +22,9 @@ func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber() (st
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("dividends_returned_order.created_at >= ?", todayZeroTime)
query.Where("dividends_returned_order.created_at < ?", nextDayZeroTime)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_returned_order.company @> '{"companyId":"?"}'`, companyId)
}
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
... ...
... ... @@ -50,6 +50,8 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
for _, dividendsEstimate := range dividendsEstimates {
// 根据当前分红预算单的分红订单号或退货单号获取分红预算单
if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
"companyId": dividendsEstimate.Company.CompanyId,
"orgId": dividendsEstimate.Org.OrgId,
"orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
}); err2 != nil {
return nil, err2
... ... @@ -86,6 +88,8 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
// 获取分红订单
if countDividendsOrder, orders, err4 := dividendsOrderRepository.Find(map[string]interface{}{
"companyId": dividendsEstimates[0].Company.CompanyId,
"orgId": dividendsEstimates[0].Org.OrgId,
"dividendsOrderNumbers": orderNums,
}); err4 != nil {
return nil, err4
... ... @@ -103,6 +107,8 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
// 获取分红退货单
if countDividendsReturnedOrder, returnedOrders, err5 := dividendsReturnedOrderRepository.Find(map[string]interface{}{
"companyId": dividendsEstimates[0].Company.CompanyId,
"orgId": dividendsEstimates[0].Org.OrgId,
"dividendsReturnedOrderNumbers": returnedOrderNums,
}); err5 != nil {
return nil, err5
... ...
... ... @@ -5,6 +5,7 @@ import (
"github.com/linmadan/egglib-go/core/application"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/shopspring/decimal"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
... ... @@ -18,37 +19,62 @@ type ConfirmDividendsIncentivesEstimateService struct {
// Confirm 确认业绩分红预算
func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoods []*domain.OrderGood) ([]*service.DividendsEstimateDetail, error) {
var cooperationContractRepository domain.CooperationContractRepository // 共创合约仓储
var cooperationProjectRepository domain.CooperationProjectRepository // 共创项目仓储
var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储
// 共创合约仓储初始化
if repo, err := repository.NewCooperationContractRepository(domainService.transactionContext); err != nil {
return nil, err
} else {
cooperationContractRepository = repo
}
// 共创项目仓储初始化
if repo, err := repository.NewCooperationProjectRepository(domainService.transactionContext); err != nil {
return nil, err
} else {
cooperationProjectRepository = repo
}
// 分红订单仓储初始化
if repo, err := repository.NewDividendsOrderRepository(domainService.transactionContext); err != nil {
return nil, err
} else {
dividendsOrderRepository = repo
}
// 分红退货单仓储初始化
if repo, err := repository.NewDividendsReturnedOrderRepository(domainService.transactionContext); err != nil {
return nil, err
} else {
dividendsReturnedOrderRepository = repo
}
// 确认业绩分红预算
var dividendsEstimateDetails []*service.DividendsEstimateDetail
for _, orderGood := range orderGoods {
// 获取合约
cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractNumber": orderGood.CooperationContractNumber})
cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{
"cooperationContractNumber": orderGood.CooperationContractNumber,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationContract == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber))
}
// TODO 校验合约关联的项目是否已结束
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{
"cooperationProjectNumber": cooperationContract.CooperationProjectNumber,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationProject == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s不存在", cooperationContract.CooperationProjectNumber))
}
if orderGood.DividendsOrderNumber != "" {
// 获取分红订单
dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{
... ... @@ -78,8 +104,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
if dividendsIncentivesRuleMatched != nil {
for _, undertaker := range cooperationContract.Undertakers {
// 添加承接人分红预算信息详情
// TODO 使用decimal提高精度
undertakerDividendsAmount := orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage / 100
undertakerDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.DividendsIncentivesPercentage).Div(decimal.NewFromFloat(100))).Float64()
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.UserId,
... ... @@ -101,7 +126,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
})
// 添加推荐人分红预算信息详情
if undertaker.Referrer != nil {
referrerDividendsAmount := orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.ReferrerPercentage / 100
referrerDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.ReferrerPercentage).Div(decimal.NewFromFloat(100))).Float64()
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.Referrer.UserId,
... ... @@ -123,7 +148,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
}
// 添加关联业务员分红预算信息详情
if undertaker.Salesman != nil {
salesmanDividendsAmount := orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.SalesmanPercentage / 100
salesmanDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.SalesmanPercentage).Div(decimal.NewFromFloat(100))).Float64()
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.Salesman.UserId,
... ... @@ -166,7 +191,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
// 计算分红
for _, undertaker := range cooperationContract.Undertakers {
// 添加承接人分红退货预算信息详情
undertakerDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage / 100
undertakerDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.DividendsIncentivesPercentage).Div(decimal.NewFromFloat(100))).Float64()
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.UserId,
... ... @@ -184,11 +209,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
},
DividendsParticipateType: domain.UNDERTAKER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: undertakerDividendsAmount,
DividendsAmount: -undertakerDividendsAmount,
})
// 添加推荐人分红退货预算信息详情
if undertaker.Referrer != nil {
referrerDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.ReferrerPercentage / 100
referrerDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.ReferrerPercentage).Div(decimal.NewFromFloat(100))).Float64()
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.Referrer.UserId,
... ... @@ -205,12 +230,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
},
DividendsParticipateType: domain.REFERRER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: referrerDividendsAmount,
DividendsAmount: -referrerDividendsAmount,
})
}
// 添加关联业务员分红退货预算信息详情
if undertaker.Salesman != nil {
salesmanDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.SalesmanPercentage / 100
salesmanDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.SalesmanPercentage).Div(decimal.NewFromFloat(100))).Float64()
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.Salesman.UserId,
... ... @@ -227,7 +252,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
},
DividendsParticipateType: domain.SALESMAN,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: salesmanDividendsAmount,
DividendsAmount: -salesmanDividendsAmount,
})
}
}
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/shopspring/decimal"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
... ... @@ -68,7 +69,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
if undertakerEstimated {
return nil, fmt.Errorf("用户 " + undertaker.UserName + " 已分红")
} else {
undertakerDividendsAmount := moneyIncentivesRuleMatched.MoneyIncentivesAmount * (1 - (moneyIncentivesRuleMatched.SalesmanPercentage+moneyIncentivesRuleMatched.ReferrerPercentage)/100)
undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(1).Sub(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Add(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage))).Div(decimal.NewFromFloat(100))).Float64()
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.UserId,
... ... @@ -103,7 +104,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
if salesmanEstimated {
return nil, fmt.Errorf("业务员 " + undertaker.Salesman.UserName + " 已分红")
} else {
undertakerDividendsAmount := moneyIncentivesRuleMatched.MoneyIncentivesAmount * (moneyIncentivesRuleMatched.SalesmanPercentage / 100)
undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Div(decimal.NewFromFloat(100))).Float64()
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.Salesman.UserId,
... ... @@ -139,8 +140,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
if referrerEstimated {
return nil, fmt.Errorf("推荐人 " + undertaker.Salesman.UserName + " 已分红")
} else {
// TODO 使用decimal提高精度
undertakerDividendsAmount := moneyIncentivesRuleMatched.MoneyIncentivesAmount * (moneyIncentivesRuleMatched.ReferrerPercentage / 100)
undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage).Div(decimal.NewFromFloat(100))).Float64()
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.Referrer.UserId,
... ...
... ... @@ -248,6 +248,9 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 {
query.Where(`(cooperation_application.cooperation_application_applicant->>'userBaseId' ='?')`, userBaseId)
}
if isCanceled, ok := queryOptions["isCanceled"]; ok && isCanceled.(int32) != 3 {
query.Where("is_canceled = ?", isCanceled)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
... ... @@ -265,7 +268,7 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.Where("is_canceled = ?", 1)
query.SetOrderDirect("cooperation_application_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, cooperationApplications, err
... ...
... ... @@ -1159,6 +1159,9 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
if cooperationContractNumbers, ok := queryOptions["cooperationContractNumbers"]; ok && len(cooperationContractNumbers.([]string)) != 0 {
query.Where("cooperation_contract_number in (?)", pg.In(cooperationContractNumbers))
}
if incentivesType, ok := queryOptions["incentivesType"]; ok && incentivesType.(int32) != 0 {
query.Where("incentives_type = ?", incentivesType)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
... ...
... ... @@ -211,6 +211,12 @@ func (repository *CooperationProjectRepository) FindOne(queryOptions map[string]
if cooperationProjectNumber, ok := queryOptions["cooperationProjectNumber"]; ok && cooperationProjectNumber != "" {
query.Where("cooperation_project.cooperation_project_number = ?", cooperationProjectNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query.Where("org->>'orgId' = '?'", orgId)
}
if cooperationProjectId, ok := queryOptions["cooperationProjectId"]; ok && cooperationProjectId.(int64) != 0 {
query.Where("cooperation_project.cooperation_project_id = ?", cooperationProjectId)
}
... ...
... ... @@ -112,7 +112,7 @@ func (controller *CooperationContractController) SearchCooperationContract() {
_ = controller.Unmarshal(searchCooperationContractQuery)
header := controller.GetRequestHeader(controller.Ctx)
searchCooperationContractQuery.CompanyId = header.CompanyId
searchCooperationContractQuery.OrgId = header.OrgId
//searchCooperationContractQuery.OrgId = header.OrgId
searchCooperationContractQuery.UserId = header.UserId
searchCooperationContractQuery.UserBaseId = header.UserBaseId
data, err := cooperationContractService.SearchCooperationContract(searchCooperationContractQuery)
... ...