作者 陈志颖

Merge branch 'fix-bugs' into dev

... ... @@ -902,6 +902,16 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
exchangeCashPersonListRepository = value
}
// 员工仓储初始化
var employeeRepository domain.EmployeeRepository
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
employeeRepository = value
}
// 兑换现金活动仓储初始化
var exchangeCashActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
... ... @@ -951,9 +961,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ListId)))
}
// 获取兑换清单员工已兑换素币
personFoundExchangedSuMoney := personFound.ExchangedSuMoney
// 获取相关兑换活动
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": personFound.ExchangeCashActivityId})
if err != nil {
... ... @@ -963,6 +970,29 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(personFound.ExchangeCashActivityId)))
}
// 获取员工查询条件
getEmployee := map[string]interface{}{
"account": personFound.EmployeeInfo.EmployeeAccount,
"companyId": activityFound.CompanyId,
}
// 判断当前员工是否有效
employeeFound, err := employeeRepository.FindOne(getEmployee)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if employeeFound == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
}
// 判断该员工兑换的素币是否超过本人持有的素币
if employeeFound.SuMoney < updateExchangeCashPersonCommand.ExchangedSuMoney {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
}
// 获取兑换清单员工已兑换素币
personFoundExchangedSuMoney := personFound.ExchangedSuMoney
// 更新兑换清单,个人已兑换现金计算
updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"fmt"
"strconv"
"github.com/go-pg/pg"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
... ... @@ -72,8 +73,9 @@ func (repository *ExchangeCashPersonListRepository) FindById(queryOptions map[st
if personNameMatch, ok := where.(map[string]interface{})["personNameMatch"]; ok && (personNameMatch != "") {
query = query.Where(`exchange_cash_person_list.employee_name LIKE ?`, fmt.Sprintf("%%%s%%", personNameMatch.(string)))
}
if activityId, ok := where.(map[string]interface{})["activityId"]; ok && activityId.(float64) != 0 {
query = query.Where("exchange_cash_person_list.activity_id = ?", activityId)
if activityId, ok := where.(map[string]interface{})["activityId"]; ok && activityId != "" {
float, _ := strconv.ParseFloat(activityId.(string),64)
query = query.Where("exchange_cash_person_list.activity_id = ?", float)
}
}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
... ...