作者 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 @@ -200,6 +200,8 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
200 Department: undertakerDomain.Department, 200 Department: undertakerDomain.Department,
201 Roles: undertakerDomain.Roles, 201 Roles: undertakerDomain.Roles,
202 UserInfo: undertakerDomain.UserInfo, 202 UserInfo: undertakerDomain.UserInfo,
  203 + UserName: undertakerDomain.UserName,
  204 + UserPhone: undertakerDomain.UserPhone,
203 UserType: undertakerDomain.UserType, 205 UserType: undertakerDomain.UserType,
204 Referrer: referrerDomain, 206 Referrer: referrerDomain,
205 Salesman: salesmanDomain, 207 Salesman: salesmanDomain,
@@ -592,7 +592,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -592,7 +592,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
592 for _, errorData := range errorDataList { 592 for _, errorData := range errorDataList {
593 if len(errorData.GoodLine) == 0 { // 订单错误 593 if len(errorData.GoodLine) == 0 { // 订单错误
594 for _, line := range errorData.LineNumbers { 594 for _, line := range errorData.LineNumbers {
595 - //s := strconv.Itoa(line + 1)  
596 tmpRow := &domain.FailInfo{ 595 tmpRow := &domain.FailInfo{
597 FailReason: "数据校验错误:" + errorData.Error.Error(), 596 FailReason: "数据校验错误:" + errorData.Error.Error(),
598 } 597 }
@@ -601,7 +600,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -601,7 +600,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
601 } 600 }
602 } else if len(errorData.GoodLine) > 0 { // 订单产品错误 601 } else if len(errorData.GoodLine) > 0 { // 订单产品错误
603 for line := range errorData.GoodLine { 602 for line := range errorData.GoodLine {
604 - //s := strconv.Itoa(line + 1)  
605 tmpRow := &domain.FailInfo{ 603 tmpRow := &domain.FailInfo{
606 FailReason: "订单产品信息错误:" + errorData.Error.Error(), 604 FailReason: "订单产品信息错误:" + errorData.Error.Error(),
607 } 605 }
@@ -76,7 +76,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -76,7 +76,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
76 if dividendsIncentivesRuleMatched != nil { 76 if dividendsIncentivesRuleMatched != nil {
77 for _, undertaker := range cooperationContract.Undertakers { 77 for _, undertaker := range cooperationContract.Undertakers {
78 // 添加承接人分红预算信息详情 78 // 添加承接人分红预算信息详情
79 - undertakerDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage 79 + // TODO 使用decimal提高精度
  80 + undertakerDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage / 100
80 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ 81 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
81 DividendsUser: &domain.User{ 82 DividendsUser: &domain.User{
82 UserId: undertaker.UserId, 83 UserId: undertaker.UserId,
@@ -98,7 +99,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -98,7 +99,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
98 }) 99 })
99 // 添加推荐人分红预算信息详情 100 // 添加推荐人分红预算信息详情
100 if undertaker.Referrer != nil { 101 if undertaker.Referrer != nil {
101 - referrerDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.ReferrerPercentage 102 + referrerDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.ReferrerPercentage / 100
102 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ 103 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
103 DividendsUser: &domain.User{ 104 DividendsUser: &domain.User{
104 UserId: undertaker.Referrer.UserId, 105 UserId: undertaker.Referrer.UserId,
@@ -120,7 +121,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -120,7 +121,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
120 } 121 }
121 // 添加关联业务员分红预算信息详情 122 // 添加关联业务员分红预算信息详情
122 if undertaker.Salesman != nil { 123 if undertaker.Salesman != nil {
123 - salesmanDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.SalesmanPercentage 124 + salesmanDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.SalesmanPercentage / 100
124 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ 125 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
125 DividendsUser: &domain.User{ 126 DividendsUser: &domain.User{
126 UserId: undertaker.Salesman.UserId, 127 UserId: undertaker.Salesman.UserId,
@@ -163,7 +164,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -163,7 +164,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
163 // 计算分红 164 // 计算分红
164 for _, undertaker := range cooperationContract.Undertakers { 165 for _, undertaker := range cooperationContract.Undertakers {
165 // 添加承接人分红退货预算信息详情 166 // 添加承接人分红退货预算信息详情
166 - undertakerDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage 167 + undertakerDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage / 100
167 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ 168 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
168 DividendsUser: &domain.User{ 169 DividendsUser: &domain.User{
169 UserId: undertaker.UserId, 170 UserId: undertaker.UserId,
@@ -185,7 +186,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -185,7 +186,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
185 }) 186 })
186 // 添加推荐人分红退货预算信息详情 187 // 添加推荐人分红退货预算信息详情
187 if undertaker.Referrer != nil { 188 if undertaker.Referrer != nil {
188 - referrerDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.ReferrerPercentage 189 + referrerDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.ReferrerPercentage / 100
189 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ 190 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
190 DividendsUser: &domain.User{ 191 DividendsUser: &domain.User{
191 UserId: undertaker.Referrer.UserId, 192 UserId: undertaker.Referrer.UserId,
@@ -207,7 +208,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -207,7 +208,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
207 } 208 }
208 // 添加关联业务员分红退货预算信息详情 209 // 添加关联业务员分红退货预算信息详情
209 if undertaker.Salesman != nil { 210 if undertaker.Salesman != nil {
210 - salesmanDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.SalesmanPercentage 211 + salesmanDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.SalesmanPercentage / 100
211 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ 212 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
212 DividendsUser: &domain.User{ 213 DividendsUser: &domain.User{
213 UserId: undertaker.Salesman.UserId, 214 UserId: undertaker.Salesman.UserId,
@@ -139,6 +139,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -139,6 +139,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
139 if referrerEstimated { 139 if referrerEstimated {
140 return nil, fmt.Errorf("推荐人 " + undertaker.Salesman.UserName + " 已分红") 140 return nil, fmt.Errorf("推荐人 " + undertaker.Salesman.UserName + " 已分红")
141 } else { 141 } else {
  142 + // TODO 使用decimal提高精度
142 undertakerDividendsAmount := moneyIncentivesRuleMatched.MoneyIncentivesAmount * (moneyIncentivesRuleMatched.ReferrerPercentage / 100) 143 undertakerDividendsAmount := moneyIncentivesRuleMatched.MoneyIncentivesAmount * (moneyIncentivesRuleMatched.ReferrerPercentage / 100)
143 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ 144 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
144 DividendsUser: &domain.User{ 145 DividendsUser: &domain.User{
@@ -250,6 +250,9 @@ func (repository *CooperationProjectRepository) Find(queryOptions map[string]int @@ -250,6 +250,9 @@ func (repository *CooperationProjectRepository) Find(queryOptions map[string]int
250 if keyword, ok := queryOptions["keyword"]; ok && keyword != "" { 250 if keyword, ok := queryOptions["keyword"]; ok && keyword != "" {
251 query.Where("cooperation_project_description like ?", fmt.Sprintf("%%%s%%", keyword)) 251 query.Where("cooperation_project_description like ?", fmt.Sprintf("%%%s%%", keyword))
252 } 252 }
  253 + if departmentName, ok := queryOptions["departmentName"]; ok && departmentName != "" {
  254 + query.Where("department->>'departmentName' like ? ", fmt.Sprintf("%%%s%%", departmentName))
  255 + }
253 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { 256 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
254 query.Where("company->>'companyId' = '?'", companyId) 257 query.Where("company->>'companyId' = '?'", companyId)
255 } 258 }
@@ -110,8 +110,8 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend @@ -110,8 +110,8 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
110 OrderGoodName: good.OrderGoodName, 110 OrderGoodName: good.OrderGoodName,
111 OrderGoodPrice: good.OrderGoodPrice, 111 OrderGoodPrice: good.OrderGoodPrice,
112 OrderGoodQuantity: good.OrderGoodQuantity, 112 OrderGoodQuantity: good.OrderGoodQuantity,
113 - DividendsOrderNumber: good.DividendsOrderNumber,  
114 - DividendsReturnedOrderNumber: good.DividendsReturnedOrderNumber, 113 + DividendsOrderNumber: dividendsOrder.DividendsOrderNumber,
  114 + DividendsReturnedOrderNumber: "",
115 CooperationContractNumber: good.CooperationContractNumber, 115 CooperationContractNumber: good.CooperationContractNumber,
116 CompanyId: good.CompanyId, 116 CompanyId: good.CompanyId,
117 OrgId: good.OrgId, 117 OrgId: good.OrgId,
@@ -334,7 +334,10 @@ func (repository *DividendsOrderRepository) Remove(dividendsOrder *domain.Divide @@ -334,7 +334,10 @@ func (repository *DividendsOrderRepository) Remove(dividendsOrder *domain.Divide
334 } else { 334 } else {
335 // 删除订单产品 335 // 删除订单产品
336 var orderGoodModels []*models.OrderGood 336 var orderGoodModels []*models.OrderGood
337 - if _, err := tx.Model(&orderGoodModels).Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).Delete(); err != nil { 337 + if _, err := tx.Model(&orderGoodModels).
  338 + Where("company_id = ?", dividendsOrderModel.Company.CompanyId).
  339 + Where("org_id = ?", dividendsOrderModel.Org.OrgId).
  340 + Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).Delete(); err != nil {
338 return nil, err 341 return nil, err
339 } 342 }
340 } 343 }
@@ -355,7 +358,10 @@ func (repository *DividendsOrderRepository) BatchRemove(dividendsOrders []*domai @@ -355,7 +358,10 @@ func (repository *DividendsOrderRepository) BatchRemove(dividendsOrders []*domai
355 for _, dividendsOrder := range dividendsOrders { 358 for _, dividendsOrder := range dividendsOrders {
356 // 删除订单产品 359 // 删除订单产品
357 var orderGoodModels []*models.OrderGood 360 var orderGoodModels []*models.OrderGood
358 - if _, err := tx.Model(&orderGoodModels).Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).Delete(); err != nil { 361 + if _, err := tx.Model(&orderGoodModels).
  362 + Where("company_id = ?", dividendsOrder.Company.CompanyId).
  363 + Where("org_id = ?", dividendsOrder.Org.OrgId).
  364 + Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).Delete(); err != nil {
359 return nil, err 365 return nil, err
360 } 366 }
361 } 367 }
@@ -368,7 +374,6 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte @@ -368,7 +374,6 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte
368 dividendsOrderModel := new(models.DividendsOrder) 374 dividendsOrderModel := new(models.DividendsOrder)
369 query := sqlbuilder.BuildQuery(tx.Model(dividendsOrderModel), queryOptions) 375 query := sqlbuilder.BuildQuery(tx.Model(dividendsOrderModel), queryOptions)
370 query.SetWhereByQueryOption("dividends_order.dividends_order_id = ?", "dividendsOrderId") 376 query.SetWhereByQueryOption("dividends_order.dividends_order_id = ?", "dividendsOrderId")
371 - //query.SetWhereByQueryOption("dividends_order.dividends_order_number = ?", "dividendsOrderNumber")  
372 if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" { 377 if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" {
373 query.Where("dividends_order.dividends_order_number = ?", dividendsOrderNumber) 378 query.Where("dividends_order.dividends_order_number = ?", dividendsOrderNumber)
374 } 379 }
@@ -385,7 +390,10 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte @@ -385,7 +390,10 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte
385 // 获取订单产品 390 // 获取订单产品
386 var orderGoodModels []*models.OrderGood 391 var orderGoodModels []*models.OrderGood
387 orderGoodModelQuery := tx.Model(&orderGoodModels) 392 orderGoodModelQuery := tx.Model(&orderGoodModels)
388 - if err := orderGoodModelQuery.Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber).Select(); err != nil { 393 + if err := orderGoodModelQuery.
  394 + Where("company_id = ?", dividendsOrderModel.Company.CompanyId).
  395 + Where("org_id = ?", dividendsOrderModel.Org.OrgId).
  396 + Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber).Select(); err != nil {
389 return nil, err 397 return nil, err
390 } 398 }
391 // 聚合分红订单 399 // 聚合分红订单
@@ -434,8 +442,8 @@ func (repository *DividendsOrderRepository) Find(queryOptions map[string]interfa @@ -434,8 +442,8 @@ func (repository *DividendsOrderRepository) Find(queryOptions map[string]interfa
434 var orderGoodModels []*models.OrderGood 442 var orderGoodModels []*models.OrderGood
435 orderGoodModelQuery := tx.Model(&orderGoodModels) 443 orderGoodModelQuery := tx.Model(&orderGoodModels)
436 if err := orderGoodModelQuery. 444 if err := orderGoodModelQuery.
437 - Where("company->>'companyId' = '?'", dividendsOrderModel.Company.CompanyId).  
438 - Where("org->>'orgId' = '?'", dividendsOrderModel.Org.OrgId). 445 + Where("company_id = ?", dividendsOrderModel.Company.CompanyId).
  446 + Where("org_id = ?", dividendsOrderModel.Org.OrgId).
439 Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber). 447 Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber).
440 Select(); err != nil { 448 Select(); err != nil {
441 return 0, nil, err 449 return 0, nil, err
@@ -339,7 +339,10 @@ func (repository *DividendsReturnedOrderRepository) Remove(dividendsReturnedOrde @@ -339,7 +339,10 @@ func (repository *DividendsReturnedOrderRepository) Remove(dividendsReturnedOrde
339 } else { 339 } else {
340 // 删除分红退货单产品 340 // 删除分红退货单产品
341 var orderGoodModels []*models.OrderGood 341 var orderGoodModels []*models.OrderGood
342 - if _, err := tx.Model(&orderGoodModels).Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Delete(); err != nil { 342 + if _, err := tx.Model(&orderGoodModels).
  343 + Where("company_id = ?", dividendsReturnedOrder.Company.CompanyId).
  344 + Where("org_id = ?", dividendsReturnedOrder.Org.OrgId).
  345 + Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Delete(); err != nil {
343 return nil, err 346 return nil, err
344 } 347 }
345 } 348 }
@@ -360,7 +363,10 @@ func (repository *DividendsReturnedOrderRepository) BatchRemove(dividendsReturne @@ -360,7 +363,10 @@ func (repository *DividendsReturnedOrderRepository) BatchRemove(dividendsReturne
360 for _, dividendsReturnedOrder := range dividendsReturnedOrders { 363 for _, dividendsReturnedOrder := range dividendsReturnedOrders {
361 // 删除退货单产品 364 // 删除退货单产品
362 var orderGoodModels []*models.OrderGood 365 var orderGoodModels []*models.OrderGood
363 - if _, err := tx.Model(&orderGoodModels).Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Delete(); err != nil { 366 + if _, err := tx.Model(&orderGoodModels).
  367 + Where("company_id = ?", dividendsReturnedOrder.Company.CompanyId).
  368 + Where("org_id = ?", dividendsReturnedOrder.Org.OrgId).
  369 + Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Delete(); err != nil {
364 return nil, err 370 return nil, err
365 } 371 }
366 } 372 }
@@ -387,7 +393,10 @@ func (repository *DividendsReturnedOrderRepository) FindOne(queryOptions map[str @@ -387,7 +393,10 @@ func (repository *DividendsReturnedOrderRepository) FindOne(queryOptions map[str
387 // 获取订单产品 393 // 获取订单产品
388 var orderGoodModels []*models.OrderGood 394 var orderGoodModels []*models.OrderGood
389 orderGoodModelQuery := tx.Model(&orderGoodModels) 395 orderGoodModelQuery := tx.Model(&orderGoodModels)
390 - if err := orderGoodModelQuery.Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).Select(); err != nil { 396 + if err := orderGoodModelQuery.
  397 + Where("company_id = ?", dividendsReturnedOrderModel.Company.CompanyId).
  398 + Where("org_id = ?", dividendsReturnedOrderModel.Org.OrgId).
  399 + Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).Select(); err != nil {
391 return nil, err 400 return nil, err
392 } 401 }
393 // 聚合分红退货单 402 // 聚合分红退货单
@@ -436,8 +445,8 @@ func (repository *DividendsReturnedOrderRepository) Find(queryOptions map[string @@ -436,8 +445,8 @@ func (repository *DividendsReturnedOrderRepository) Find(queryOptions map[string
436 var orderGoodModels []*models.OrderGood 445 var orderGoodModels []*models.OrderGood
437 orderGoodModelQuery := tx.Model(&orderGoodModels) 446 orderGoodModelQuery := tx.Model(&orderGoodModels)
438 if err := orderGoodModelQuery. 447 if err := orderGoodModelQuery.
439 - Where("company->>'companyId' = '?'", dividendsReturnedOrderModel.Company.CompanyId).  
440 - Where("org->>'orgId' = '?'", dividendsReturnedOrderModel.Org.OrgId). 448 + Where("company_id = ?", dividendsReturnedOrderModel.Company.CompanyId).
  449 + Where("org_id = ?", dividendsReturnedOrderModel.Org.OrgId).
441 Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber). 450 Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).
442 Select(); err != nil { 451 Select(); err != nil {
443 return 0, nil, err 452 return 0, nil, err