作者 陈志颖

refactor:优化退货单导入

@@ -372,15 +372,15 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -372,15 +372,15 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
372 // 返回信息表头定义 372 // 返回信息表头定义
373 var tableHeader = map[string]interface{}{ 373 var tableHeader = map[string]interface{}{
374 "failReason": "失败原因", 374 "failReason": "失败原因",
375 - "originalOrderNum": "来源单号",  
376 - "dividendsCustomerName": "客户名称",  
377 - "orderGoodName": "产品名称",  
378 - "orderTime": "订单日期",  
379 - "regionName": "订单区域",  
380 - "orderGoodQuantity": "产品数量",  
381 - "orderGoodPrice": "产品价格",  
382 - "expense": "费用",  
383 - "cooperationContractNumber": "项目合约编号", 375 + "originalOrderNum": "来源单号", // 0
  376 + "dividendsCustomerName": "客户名称", // 1
  377 + "orderGoodName": "产品名称", // 2
  378 + "orderTime": "订单日期", // 3
  379 + "regionName": "订单区域", // 4
  380 + "orderGoodQuantity": "产品数量", // 5
  381 + "orderGoodPrice": "产品价格", // 6
  382 + "expense": "费用", // 7
  383 + "cooperationContractNumber": "项目合约编号", // 8
384 } 384 }
385 385
386 /************************************************ 1.空文件校验 ******************************************************/ 386 /************************************************ 1.空文件校验 ******************************************************/
@@ -582,6 +582,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -582,6 +582,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
582 aggregateErrorList = append(aggregateErrorList, tmpRow) 582 aggregateErrorList = append(aggregateErrorList, tmpRow)
583 continue 583 continue
584 } 584 }
  585 +
585 price, err := strconv.ParseFloat(dividendsOrder.OrderGoodPrice, 64) 586 price, err := strconv.ParseFloat(dividendsOrder.OrderGoodPrice, 64)
586 if err != nil { 587 if err != nil {
587 tmpRow := &domain.FailInfo{ 588 tmpRow := &domain.FailInfo{
@@ -591,6 +592,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -591,6 +592,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
591 aggregateErrorList = append(aggregateErrorList, tmpRow) 592 aggregateErrorList = append(aggregateErrorList, tmpRow)
592 continue 593 continue
593 } 594 }
  595 +
594 var expense float64 596 var expense float64
595 if dividendsOrder.Expense != "" { 597 if dividendsOrder.Expense != "" {
596 if expenseParse, err := strconv.ParseFloat(dividendsOrder.Expense, 64); err != nil { 598 if expenseParse, err := strconv.ParseFloat(dividendsOrder.Expense, 64); err != nil {
@@ -643,6 +645,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -643,6 +645,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
643 aggregateErrorList = append(aggregateErrorList, tmpRow) 645 aggregateErrorList = append(aggregateErrorList, tmpRow)
644 continue 646 continue
645 } 647 }
  648 +
646 price, err := strconv.ParseFloat(dividendsOrder.OrderGoodPrice, 64) 649 price, err := strconv.ParseFloat(dividendsOrder.OrderGoodPrice, 64)
647 if err != nil { 650 if err != nil {
648 tmpRow := &domain.FailInfo{ 651 tmpRow := &domain.FailInfo{
@@ -652,6 +655,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -652,6 +655,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
652 aggregateErrorList = append(aggregateErrorList, tmpRow) 655 aggregateErrorList = append(aggregateErrorList, tmpRow)
653 continue 656 continue
654 } 657 }
  658 +
655 var expense float64 659 var expense float64
656 if dividendsOrder.Expense != "" { 660 if dividendsOrder.Expense != "" {
657 if expenseParse, err := strconv.ParseFloat(dividendsOrder.Expense, 64); err != nil { 661 if expenseParse, err := strconv.ParseFloat(dividendsOrder.Expense, 64); err != nil {
@@ -17,16 +17,16 @@ type ( @@ -17,16 +17,16 @@ type (
17 OrderGoodName string `json:"orderGoodName"` 17 OrderGoodName string `json:"orderGoodName"`
18 //退货日期 18 //退货日期
19 DividendsReturnedDate string `json:"dividendsReturnedDate"` 19 DividendsReturnedDate string `json:"dividendsReturnedDate"`
  20 + //订单日期
  21 + OrderTime string `json:"orderTime"`
20 //退货区域名称 22 //退货区域名称
21 RegionName string `json:"regionName"` 23 RegionName string `json:"regionName"`
22 - //订单产品单价  
23 - OrderGoodPrice string `json:"orderGoodPrice"`  
24 //订单产品数量 24 //订单产品数量
25 OrderGoodQuantity string `json:"orderGoodQuantity"` 25 OrderGoodQuantity string `json:"orderGoodQuantity"`
  26 + //订单产品单价
  27 + OrderGoodPrice string `json:"orderGoodPrice"`
26 //合约编号 28 //合约编号
27 CooperationContractNumber string `json:"cooperationContractNumber"` 29 CooperationContractNumber string `json:"cooperationContractNumber"`
28 - //订单日期  
29 - OrderTime string `json:"orderTime"`  
30 } 30 }
31 31
32 // ImportDividendsReturnedOrderCommand 请求参数 32 // ImportDividendsReturnedOrderCommand 请求参数
@@ -412,15 +412,15 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide @@ -412,15 +412,15 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
412 // 返回信息表头定义 412 // 返回信息表头定义
413 var tableHeader = map[string]interface{}{ 413 var tableHeader = map[string]interface{}{
414 "failReason": "错误详情", 414 "failReason": "错误详情",
415 - "originalOrderNum": "来源单号",  
416 - "dividendsReturnedCustomerName": "客户名称",  
417 - "orderGoodName": "产品名称",  
418 - "dividendsReturnedDate": "退货日期",  
419 - "regionName": "订单日期",  
420 - "orderGoodPrice": "订单区域",  
421 - "orderGoodQuantity": "退货数量",  
422 - "cooperationContractNumber": "退货价格",  
423 - "orderTime": "项目合约编号", 415 + "originalOrderNum": "来源单号", // 0
  416 + "dividendsReturnedCustomerName": "客户名称", // 1
  417 + "orderGoodName": "产品名称", // 2
  418 + "dividendsReturnedDate": "退货日期", // 3
  419 + "orderTime": "订单日期", // 4
  420 + "regionName": "订单区域", // 5
  421 + "orderGoodQuantity": "退货数量", // 6
  422 + "orderGoodPrice": "退货价格", // 7
  423 + "cooperationContractNumber": "项目合约编号", // 8
424 } 424 }
425 425
426 /***************************************************** 空文件校验 ***************************************************/ 426 /***************************************************** 空文件校验 ***************************************************/
@@ -446,7 +446,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide @@ -446,7 +446,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
446 v := reflect.ValueOf(dividendsReturnedOrder) 446 v := reflect.ValueOf(dividendsReturnedOrder)
447 for k := 0; k < t.NumField(); k++ { 447 for k := 0; k < t.NumField(); k++ {
448 fmt.Println("name:", fmt.Sprintf("%+v", t.Field(k).Name), ", value:", fmt.Sprintf("%v", v.Field(k).Interface())) 448 fmt.Println("name:", fmt.Sprintf("%+v", t.Field(k).Name), ", value:", fmt.Sprintf("%v", v.Field(k).Interface()))
449 - if t.Field(k).Name != "RegionName" && t.Field(k).Name != "CooperationContractNumber" { 449 + if t.Field(k).Name != "RegionName" {
450 if v.Field(k).Interface() == "" { 450 if v.Field(k).Interface() == "" {
451 col := strconv.Itoa(k + 1) 451 col := strconv.Itoa(k + 1)
452 nullCell = append(nullCell, col) 452 nullCell = append(nullCell, col)
@@ -581,10 +581,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide @@ -581,10 +581,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
581 var dividendsReturnedOrderCommands = make(map[string]*command.CreateDividendsReturnedOrderCommand) 581 var dividendsReturnedOrderCommands = make(map[string]*command.CreateDividendsReturnedOrderCommand)
582 582
583 for i, dividendsReturnedOrder := range importDividendsReturnedOrderCommand.DividendsReturnedOrderData { 583 for i, dividendsReturnedOrder := range importDividendsReturnedOrderCommand.DividendsReturnedOrderData {
584 - hashValue := md5.Sum([]byte(dividendsReturnedOrder.OriginalOrderNum)) 584 + hashValue := md5.Sum([]byte(dividendsReturnedOrder.OriginalOrderNum + dividendsReturnedOrder.OrderTime))
585 hashString := hex.EncodeToString(hashValue[:]) 585 hashString := hex.EncodeToString(hashValue[:])
586 if _, ok := dividendsReturnedOrderCommands[hashString]; !ok { 586 if _, ok := dividendsReturnedOrderCommands[hashString]; !ok {
587 -  
588 // 订单日期时间格式转换 587 // 订单日期时间格式转换
589 timeValue, err := time.ParseInLocation("2006/01/02", dividendsReturnedOrder.OrderTime, time.Local) 588 timeValue, err := time.ParseInLocation("2006/01/02", dividendsReturnedOrder.OrderTime, time.Local)
590 if err != nil { 589 if err != nil {
@@ -600,7 +599,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide @@ -600,7 +599,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
600 timeValue2, err := time.ParseInLocation("2006/01/02", dividendsReturnedOrder.DividendsReturnedDate, time.Local) 599 timeValue2, err := time.ParseInLocation("2006/01/02", dividendsReturnedOrder.DividendsReturnedDate, time.Local)
601 if err != nil { 600 if err != nil {
602 tmpRow := &domain.FailReturnedInfo{ 601 tmpRow := &domain.FailReturnedInfo{
603 - FailReason: "无效的订单日期", 602 + FailReason: "无效的退货日期",
604 ImportDividendsReturnedOrderData: &dividendsReturnedOrder, 603 ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
605 } 604 }
606 aggregateErrorList = append(aggregateErrorList, tmpRow) 605 aggregateErrorList = append(aggregateErrorList, tmpRow)
@@ -617,6 +616,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide @@ -617,6 +616,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
617 aggregateErrorList = append(aggregateErrorList, tmpRow) 616 aggregateErrorList = append(aggregateErrorList, tmpRow)
618 continue 617 continue
619 } 618 }
  619 +
620 price, err := strconv.ParseFloat(dividendsReturnedOrder.OrderGoodPrice, 64) 620 price, err := strconv.ParseFloat(dividendsReturnedOrder.OrderGoodPrice, 64)
621 if err != nil { 621 if err != nil {
622 tmpRow := &domain.FailReturnedInfo{ 622 tmpRow := &domain.FailReturnedInfo{
@@ -666,6 +666,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide @@ -666,6 +666,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
666 aggregateErrorList = append(aggregateErrorList, tmpRow) 666 aggregateErrorList = append(aggregateErrorList, tmpRow)
667 continue 667 continue
668 } 668 }
  669 +
669 price, err := strconv.ParseFloat(dividendsReturnedOrder.OrderGoodPrice, 64) 670 price, err := strconv.ParseFloat(dividendsReturnedOrder.OrderGoodPrice, 64)
670 if err != nil { 671 if err != nil {
671 tmpRow := &domain.FailReturnedInfo{ 672 tmpRow := &domain.FailReturnedInfo{
@@ -782,14 +783,6 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide @@ -782,14 +783,6 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
782 783
783 // 批量导入创建退货单 784 // 批量导入创建退货单
784 for i, dividendsReturnedOrder := range createDividendsReturnedOrderCommands { 785 for i, dividendsReturnedOrder := range createDividendsReturnedOrderCommands {
785 - // 生成退货订单号  
786 - //dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber(map[string]interface{}{  
787 - // "companyId": importDividendsReturnedOrderCommand.CompanyId,  
788 - //})  
789 - //if err != nil {  
790 - // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
791 - //}  
792 -  
793 // 生成分红订单号 786 // 生成分红订单号
794 dividendsReturnedOrderNumber, err := dividendsReturnedOrder.GenerateSpecificDividendsReturnedOrderNumber(int64(count), time.Time{}, int64(i)) 787 dividendsReturnedOrderNumber, err := dividendsReturnedOrder.GenerateSpecificDividendsReturnedOrderNumber(int64(count), time.Time{}, int64(i))
795 if err != nil { 788 if err != nil {
@@ -831,16 +824,16 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide @@ -831,16 +824,16 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
831 returnedTime := utils.TransformTimestampToTime(returnedTimeInt) 824 returnedTime := utils.TransformTimestampToTime(returnedTimeInt)
832 825
833 // 校验退货订单编号是否唯一 826 // 校验退货订单编号是否唯一
834 - numberAvailable, err3 := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{  
835 - "companyId": importDividendsReturnedOrderCommand.CompanyId,  
836 - "dividendsReturnedOrderNumber": dividendsReturnedOrderNumber,  
837 - })  
838 - if err3 != nil {  
839 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())  
840 - }  
841 - if !numberAvailable {  
842 - return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常")  
843 - } 827 + //numberAvailable, err3 := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{
  828 + // "companyId": importDividendsReturnedOrderCommand.CompanyId,
  829 + // "dividendsReturnedOrderNumber": dividendsReturnedOrderNumber,
  830 + //})
  831 + //if err3 != nil {
  832 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
  833 + //}
  834 + //if !numberAvailable {
  835 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常")
  836 + //}
844 837
845 // 新增订单产品 838 // 新增订单产品
846 var orderGoods []*domain.OrderGood 839 var orderGoods []*domain.OrderGood
@@ -856,7 +849,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide @@ -856,7 +849,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
856 } 849 }
857 } 850 }
858 if !contractNumberExist { 851 if !contractNumberExist {
859 - orderGoodErrMap[dividendsReturnedOrder.OrderGoods[j].LineNumber] = "单产品关联的共创合约不存在" 852 + orderGoodErrMap[dividendsReturnedOrder.OrderGoods[j].LineNumber] = "退货单产品关联的共创合约不存在"
860 continue 853 continue
861 } 854 }
862 855
@@ -909,8 +902,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide @@ -909,8 +902,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
909 UpdatedAt: time.Time{}, 902 UpdatedAt: time.Time{},
910 }) 903 })
911 904
912 - // 计算分红订单金额  
913 - dividendsReturnedOrderAmount = dividendsReturnedOrderAmount + orderGood.OrderGoodAmount 905 + // 计算分红退货单金额
  906 + dividendsReturnedOrderAmount, _ = decimal.NewFromFloat(dividendsReturnedOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity))).Float64()
  907 + //dividendsReturnedOrderAmount + orderGood.OrderGoodAmount
914 } 908 }
915 909
916 if len(orderGoodErrMap) > 0 { 910 if len(orderGoodErrMap) > 0 {
@@ -89,8 +89,8 @@ func (dao *DividendsReturnedOrderDao) CountDividendsReturnedOrder(queryOptions m @@ -89,8 +89,8 @@ func (dao *DividendsReturnedOrderDao) CountDividendsReturnedOrder(queryOptions m
89 currentTime := time.Now() 89 currentTime := time.Now()
90 todayZeroTime := utils.GetZeroTime(currentTime) 90 todayZeroTime := utils.GetZeroTime(currentTime)
91 nextDayZeroTime := utils.GetNextDayZeroTime(currentTime) 91 nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
92 - query.Where("dividends_order.created_at >= ?", todayZeroTime)  
93 - query.Where("dividends_order.created_at < ?", nextDayZeroTime) 92 + query.Where("dividends_returned_order.created_at >= ?", todayZeroTime)
  93 + query.Where("dividends_returned_order.created_at < ?", nextDayZeroTime)
94 if count, err := query.AllWithDeleted().SelectAndCount(); err != nil { 94 if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
95 return 0, err 95 return 0, err
96 } else { 96 } else {