作者 yangfu

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

…ion-cooperation into dev
... ... @@ -200,6 +200,8 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
Department: undertakerDomain.Department,
Roles: undertakerDomain.Roles,
UserInfo: undertakerDomain.UserInfo,
UserName: undertakerDomain.UserName,
UserPhone: undertakerDomain.UserPhone,
UserType: undertakerDomain.UserType,
Referrer: referrerDomain,
Salesman: salesmanDomain,
... ...
... ... @@ -592,7 +592,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
for _, errorData := range errorDataList {
if len(errorData.GoodLine) == 0 { // 订单错误
for _, line := range errorData.LineNumbers {
//s := strconv.Itoa(line + 1)
tmpRow := &domain.FailInfo{
FailReason: "数据校验错误:" + errorData.Error.Error(),
}
... ... @@ -601,7 +600,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
}
} else if len(errorData.GoodLine) > 0 { // 订单产品错误
for line := range errorData.GoodLine {
//s := strconv.Itoa(line + 1)
tmpRow := &domain.FailInfo{
FailReason: "订单产品信息错误:" + errorData.Error.Error(),
}
... ...
... ... @@ -76,7 +76,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
if dividendsIncentivesRuleMatched != nil {
for _, undertaker := range cooperationContract.Undertakers {
// 添加承接人分红预算信息详情
undertakerDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage
// TODO 使用decimal提高精度
undertakerDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage / 100
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.UserId,
... ... @@ -98,7 +99,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
})
// 添加推荐人分红预算信息详情
if undertaker.Referrer != nil {
referrerDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.ReferrerPercentage
referrerDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.ReferrerPercentage / 100
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.Referrer.UserId,
... ... @@ -120,7 +121,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
}
// 添加关联业务员分红预算信息详情
if undertaker.Salesman != nil {
salesmanDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.SalesmanPercentage
salesmanDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.SalesmanPercentage / 100
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.Salesman.UserId,
... ... @@ -163,7 +164,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
// 计算分红
for _, undertaker := range cooperationContract.Undertakers {
// 添加承接人分红退货预算信息详情
undertakerDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage
undertakerDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage / 100
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.UserId,
... ... @@ -185,7 +186,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
})
// 添加推荐人分红退货预算信息详情
if undertaker.Referrer != nil {
referrerDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.ReferrerPercentage
referrerDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.ReferrerPercentage / 100
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.Referrer.UserId,
... ... @@ -207,7 +208,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
}
// 添加关联业务员分红退货预算信息详情
if undertaker.Salesman != nil {
salesmanDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.SalesmanPercentage
salesmanDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.SalesmanPercentage / 100
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.Salesman.UserId,
... ...
... ... @@ -139,6 +139,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)
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
... ...
... ... @@ -250,6 +250,9 @@ func (repository *CooperationProjectRepository) Find(queryOptions map[string]int
if keyword, ok := queryOptions["keyword"]; ok && keyword != "" {
query.Where("cooperation_project_description like ?", fmt.Sprintf("%%%s%%", keyword))
}
if departmentName, ok := queryOptions["departmentName"]; ok && departmentName != "" {
query.Where("department->>'departmentName' like ? ", fmt.Sprintf("%%%s%%", departmentName))
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
... ...
... ... @@ -110,8 +110,8 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
OrderGoodName: good.OrderGoodName,
OrderGoodPrice: good.OrderGoodPrice,
OrderGoodQuantity: good.OrderGoodQuantity,
DividendsOrderNumber: good.DividendsOrderNumber,
DividendsReturnedOrderNumber: good.DividendsReturnedOrderNumber,
DividendsOrderNumber: dividendsOrder.DividendsOrderNumber,
DividendsReturnedOrderNumber: "",
CooperationContractNumber: good.CooperationContractNumber,
CompanyId: good.CompanyId,
OrgId: good.OrgId,
... ... @@ -334,7 +334,10 @@ func (repository *DividendsOrderRepository) Remove(dividendsOrder *domain.Divide
} else {
// 删除订单产品
var orderGoodModels []*models.OrderGood
if _, err := tx.Model(&orderGoodModels).Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).Delete(); err != nil {
if _, err := tx.Model(&orderGoodModels).
Where("company_id = ?", dividendsOrderModel.Company.CompanyId).
Where("org_id = ?", dividendsOrderModel.Org.OrgId).
Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).Delete(); err != nil {
return nil, err
}
}
... ... @@ -355,7 +358,10 @@ func (repository *DividendsOrderRepository) BatchRemove(dividendsOrders []*domai
for _, dividendsOrder := range dividendsOrders {
// 删除订单产品
var orderGoodModels []*models.OrderGood
if _, err := tx.Model(&orderGoodModels).Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).Delete(); err != nil {
if _, err := tx.Model(&orderGoodModels).
Where("company_id = ?", dividendsOrder.Company.CompanyId).
Where("org_id = ?", dividendsOrder.Org.OrgId).
Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).Delete(); err != nil {
return nil, err
}
}
... ... @@ -368,7 +374,6 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte
dividendsOrderModel := new(models.DividendsOrder)
query := sqlbuilder.BuildQuery(tx.Model(dividendsOrderModel), queryOptions)
query.SetWhereByQueryOption("dividends_order.dividends_order_id = ?", "dividendsOrderId")
//query.SetWhereByQueryOption("dividends_order.dividends_order_number = ?", "dividendsOrderNumber")
if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" {
query.Where("dividends_order.dividends_order_number = ?", dividendsOrderNumber)
}
... ... @@ -385,7 +390,10 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte
// 获取订单产品
var orderGoodModels []*models.OrderGood
orderGoodModelQuery := tx.Model(&orderGoodModels)
if err := orderGoodModelQuery.Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber).Select(); err != nil {
if err := orderGoodModelQuery.
Where("company_id = ?", dividendsOrderModel.Company.CompanyId).
Where("org_id = ?", dividendsOrderModel.Org.OrgId).
Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber).Select(); err != nil {
return nil, err
}
// 聚合分红订单
... ... @@ -434,8 +442,8 @@ func (repository *DividendsOrderRepository) Find(queryOptions map[string]interfa
var orderGoodModels []*models.OrderGood
orderGoodModelQuery := tx.Model(&orderGoodModels)
if err := orderGoodModelQuery.
Where("company->>'companyId' = '?'", dividendsOrderModel.Company.CompanyId).
Where("org->>'orgId' = '?'", dividendsOrderModel.Org.OrgId).
Where("company_id = ?", dividendsOrderModel.Company.CompanyId).
Where("org_id = ?", dividendsOrderModel.Org.OrgId).
Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber).
Select(); err != nil {
return 0, nil, err
... ...
... ... @@ -339,7 +339,10 @@ func (repository *DividendsReturnedOrderRepository) Remove(dividendsReturnedOrde
} else {
// 删除分红退货单产品
var orderGoodModels []*models.OrderGood
if _, err := tx.Model(&orderGoodModels).Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Delete(); err != nil {
if _, err := tx.Model(&orderGoodModels).
Where("company_id = ?", dividendsReturnedOrder.Company.CompanyId).
Where("org_id = ?", dividendsReturnedOrder.Org.OrgId).
Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Delete(); err != nil {
return nil, err
}
}
... ... @@ -360,7 +363,10 @@ func (repository *DividendsReturnedOrderRepository) BatchRemove(dividendsReturne
for _, dividendsReturnedOrder := range dividendsReturnedOrders {
// 删除退货单产品
var orderGoodModels []*models.OrderGood
if _, err := tx.Model(&orderGoodModels).Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Delete(); err != nil {
if _, err := tx.Model(&orderGoodModels).
Where("company_id = ?", dividendsReturnedOrder.Company.CompanyId).
Where("org_id = ?", dividendsReturnedOrder.Org.OrgId).
Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Delete(); err != nil {
return nil, err
}
}
... ... @@ -387,7 +393,10 @@ func (repository *DividendsReturnedOrderRepository) FindOne(queryOptions map[str
// 获取订单产品
var orderGoodModels []*models.OrderGood
orderGoodModelQuery := tx.Model(&orderGoodModels)
if err := orderGoodModelQuery.Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).Select(); err != nil {
if err := orderGoodModelQuery.
Where("company_id = ?", dividendsReturnedOrderModel.Company.CompanyId).
Where("org_id = ?", dividendsReturnedOrderModel.Org.OrgId).
Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).Select(); err != nil {
return nil, err
}
// 聚合分红退货单
... ... @@ -436,8 +445,8 @@ func (repository *DividendsReturnedOrderRepository) Find(queryOptions map[string
var orderGoodModels []*models.OrderGood
orderGoodModelQuery := tx.Model(&orderGoodModels)
if err := orderGoodModelQuery.
Where("company->>'companyId' = '?'", dividendsReturnedOrderModel.Company.CompanyId).
Where("org->>'orgId' = '?'", dividendsReturnedOrderModel.Org.OrgId).
Where("company_id = ?", dividendsReturnedOrderModel.Company.CompanyId).
Where("org_id = ?", dividendsReturnedOrderModel.Org.OrgId).
Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).
Select(); err != nil {
return 0, nil, err
... ...