作者 陈志颖

Merge branch 'fix-bugs' into dev

@@ -902,6 +902,16 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -902,6 +902,16 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
902 exchangeCashPersonListRepository = value 902 exchangeCashPersonListRepository = value
903 } 903 }
904 904
  905 + // 员工仓储初始化
  906 + var employeeRepository domain.EmployeeRepository
  907 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  908 + "transactionContext": transactionContext,
  909 + }); err != nil {
  910 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  911 + } else {
  912 + employeeRepository = value
  913 + }
  914 +
905 // 兑换现金活动仓储初始化 915 // 兑换现金活动仓储初始化
906 var exchangeCashActivityRepository domain.ExchangeActivityRepository 916 var exchangeCashActivityRepository domain.ExchangeActivityRepository
907 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ 917 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
@@ -951,9 +961,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -951,9 +961,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
951 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ListId))) 961 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ListId)))
952 } 962 }
953 963
954 - // 获取兑换清单员工已兑换素币  
955 - personFoundExchangedSuMoney := personFound.ExchangedSuMoney  
956 -  
957 // 获取相关兑换活动 964 // 获取相关兑换活动
958 activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": personFound.ExchangeCashActivityId}) 965 activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": personFound.ExchangeCashActivityId})
959 if err != nil { 966 if err != nil {
@@ -963,6 +970,29 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -963,6 +970,29 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
963 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(personFound.ExchangeCashActivityId))) 970 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(personFound.ExchangeCashActivityId)))
964 } 971 }
965 972
  973 + // 获取员工查询条件
  974 + getEmployee := map[string]interface{}{
  975 + "account": personFound.EmployeeInfo.EmployeeAccount,
  976 + "companyId": activityFound.CompanyId,
  977 + }
  978 +
  979 + // 判断当前员工是否有效
  980 + employeeFound, err := employeeRepository.FindOne(getEmployee)
  981 + if err != nil {
  982 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  983 + }
  984 + if employeeFound == nil {
  985 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
  986 + }
  987 +
  988 + // 判断该员工兑换的素币是否超过本人持有的素币
  989 + if employeeFound.SuMoney < updateExchangeCashPersonCommand.ExchangedSuMoney {
  990 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
  991 + }
  992 +
  993 + // 获取兑换清单员工已兑换素币
  994 + personFoundExchangedSuMoney := personFound.ExchangedSuMoney
  995 +
966 // 更新兑换清单,个人已兑换现金计算 996 // 更新兑换清单,个人已兑换现金计算
967 updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate 997 updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
968 998
@@ -2,6 +2,7 @@ package repository @@ -2,6 +2,7 @@ package repository
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "strconv"
5 6
6 "github.com/go-pg/pg" 7 "github.com/go-pg/pg"
7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
@@ -72,8 +73,9 @@ func (repository *ExchangeCashPersonListRepository) FindById(queryOptions map[st @@ -72,8 +73,9 @@ func (repository *ExchangeCashPersonListRepository) FindById(queryOptions map[st
72 if personNameMatch, ok := where.(map[string]interface{})["personNameMatch"]; ok && (personNameMatch != "") { 73 if personNameMatch, ok := where.(map[string]interface{})["personNameMatch"]; ok && (personNameMatch != "") {
73 query = query.Where(`exchange_cash_person_list.employee_name LIKE ?`, fmt.Sprintf("%%%s%%", personNameMatch.(string))) 74 query = query.Where(`exchange_cash_person_list.employee_name LIKE ?`, fmt.Sprintf("%%%s%%", personNameMatch.(string)))
74 } 75 }
75 - if activityId, ok := where.(map[string]interface{})["activityId"]; ok && activityId.(float64) != 0 {  
76 - query = query.Where("exchange_cash_person_list.activity_id = ?", activityId) 76 + if activityId, ok := where.(map[string]interface{})["activityId"]; ok && activityId != "" {
  77 + float, _ := strconv.ParseFloat(activityId.(string),64)
  78 + query = query.Where("exchange_cash_person_list.activity_id = ?", float)
77 } 79 }
78 } 80 }
79 if count, err := query.Order("id DESC").SelectAndCount(); err != nil { 81 if count, err := query.Order("id DESC").SelectAndCount(); err != nil {