作者 陈志颖

fix:空现金池更新活动时间问题

@@ -786,6 +786,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -786,6 +786,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
786 if err := updateExchangeCashActivityCommand.ValidateCommand(); err != nil { 786 if err := updateExchangeCashActivityCommand.ValidateCommand(); err != nil {
787 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 787 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
788 } 788 }
  789 +
789 transactionContext, err := factory.CreateTransactionContext(nil) 790 transactionContext, err := factory.CreateTransactionContext(nil)
790 if err != nil { 791 if err != nil {
791 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 792 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -856,13 +857,33 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -856,13 +857,33 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
856 if err != nil { 857 if err != nil {
857 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 858 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
858 } 859 }
859 - if len(cashPoolsFound) == 0 { 860 + if len(cashPoolsFound) == 0 { // 现金池不存在
860 var t1 = time.Now().Local() 861 var t1 = time.Now().Local()
861 var t2 = updateExchangeCashActivityCommand.Deadline.Local() 862 var t2 = updateExchangeCashActivityCommand.Deadline.Local()
862 863
863 updateExchangeCashActivityCommand.CountDown = int64(math.Ceil(t2.Sub(t1).Hours() / 24)) 864 updateExchangeCashActivityCommand.CountDown = int64(math.Ceil(t2.Sub(t1).Hours() / 24))
864 updateExchangeCashActivityCommand.Deadline = time.Date(t2.Year(), t2.Month(), t2.Day(), 23, 59, 59, 0, time.Local) 865 updateExchangeCashActivityCommand.Deadline = time.Date(t2.Year(), t2.Month(), t2.Day(), 23, 59, 59, 0, time.Local)
865 866
  867 + if _, activitiesFound, err := exchangeCashActivityRepository.FindAll(map[string]interface{}{
  868 + "companyId": activityFound.CompanyId,
  869 + }); err != nil {
  870 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  871 + } else {
  872 + var currentExchangeCashActivityIndex int
  873 + for i, activity := range activitiesFound {
  874 + if activityFound.Deadline.Local().Equal(activity.Deadline.Local()) {
  875 + currentExchangeCashActivityIndex = i
  876 + }
  877 + }
  878 + for i, activity := range activitiesFound {
  879 + if i != currentExchangeCashActivityIndex {
  880 + if updateExchangeCashActivityCommand.Deadline.Local().Equal(activity.Deadline.Local()) {
  881 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "兑换活动截止时间不能重合")
  882 + }
  883 + }
  884 + }
  885 + }
  886 +
866 // 更新兑换活动 887 // 更新兑换活动
867 if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil { 888 if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
868 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 889 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
@@ -882,6 +903,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -882,6 +903,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
882 return activityUpdated, nil 903 return activityUpdated, nil
883 } 904 }
884 } 905 }
  906 +
885 cashPoolFoundUnExchangeCash := cashPoolsFound[0].UnExchangeCash 907 cashPoolFoundUnExchangeCash := cashPoolsFound[0].UnExchangeCash
886 cashPoolFoundExchangedCash := cashPoolsFound[0].ExchangedCash 908 cashPoolFoundExchangedCash := cashPoolsFound[0].ExchangedCash
887 909