作者 陈志颖

fix:修复更新兑换素币清单时的判断问题

@@ -990,13 +990,14 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -990,13 +990,14 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
990 } 990 }
991 991
992 // 判断当前员工是否已经在素币兑换清单中 992 // 判断当前员工是否已经在素币兑换清单中
993 - employeeExist, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{ 993 + count, _, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
994 "uid": employeeFound.EmployeeInfo.Uid, 994 "uid": employeeFound.EmployeeInfo.Uid,
  995 + "activityId": activityFound.ActivityId,
995 }) 996 })
996 if err != nil { 997 if err != nil {
997 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 998 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
998 } 999 }
999 - if employeeExist != nil { 1000 + if count > 0 {
1000 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前员工已经在素币兑换清单中") 1001 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前员工已经在素币兑换清单中")
1001 } 1002 }
1002 1003
@@ -1404,11 +1405,11 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1404,11 +1405,11 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1404 } 1405 }
1405 1406
1406 // 判断操作素币类型 1407 // 判断操作素币类型
1407 - if updateExchangeCashActivityCommand.ExchangedSuMoney - personFound.ExchangedSuMoney > 0 { // 追加素币兑换  
1408 - operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personFoundExchangedSuMoney) 1408 + if updateExchangeCashPersonCommand.ExchangedSuMoney > personFoundExchangedSuMoney { // 追加素币兑换
  1409 + operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
1409 operationSuMoneyCommand.OperationType = 4 1410 operationSuMoneyCommand.OperationType = 4
1410 } else { // 撤回素币兑换 1411 } else { // 撤回素币兑换
1411 - operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personFoundExchangedSuMoney) 1412 + operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
1412 operationSuMoneyCommand.OperationType = 41 1413 operationSuMoneyCommand.OperationType = 41
1413 } 1414 }
1414 1415
@@ -37,9 +37,15 @@ func (repository *ExchangeCashPersonListRepository) FindOne(queryOptions map[str @@ -37,9 +37,15 @@ func (repository *ExchangeCashPersonListRepository) FindOne(queryOptions map[str
37 tx := repository.transactionContext.PgTx 37 tx := repository.transactionContext.PgTx
38 exchangeCashListModel := new(models.ExchangeCashPersonList) 38 exchangeCashListModel := new(models.ExchangeCashPersonList)
39 query := tx.Model(exchangeCashListModel) 39 query := tx.Model(exchangeCashListModel)
  40 + if uid, ok := queryOptions["uid"]; ok {
  41 + query = query.Where("exchange_cash_person_list.uid = ?", uid)
  42 + }
40 if exchangeCashListId, ok := queryOptions["listId"]; ok { 43 if exchangeCashListId, ok := queryOptions["listId"]; ok {
41 query = query.Where("exchange_cash_person_list.id = ?", exchangeCashListId) 44 query = query.Where("exchange_cash_person_list.id = ?", exchangeCashListId)
42 } 45 }
  46 + if activityId, ok := queryOptions["activityId"]; ok {
  47 + query = query.Where("exchange_cash_person_list.activity_id = ?", activityId)
  48 + }
43 if err := query.First(); err != nil { 49 if err := query.First(); err != nil {
44 if err.Error() == "pg: no rows in result set" { 50 if err.Error() == "pg: no rows in result set" {
45 return nil, fmt.Errorf("没有此资源") 51 return nil, fmt.Errorf("没有此资源")
@@ -131,6 +137,9 @@ func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string @@ -131,6 +137,9 @@ func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string
131 if personNameMatch, ok := queryOptions["exchangeCashPersonNameMatch"]; ok && (personNameMatch != ""){ 137 if personNameMatch, ok := queryOptions["exchangeCashPersonNameMatch"]; ok && (personNameMatch != ""){
132 query = query.Where("exchange_cash_person_list.employee_name LIKE ?", fmt.Sprintf("%%%s%%", personNameMatch.(string))) 138 query = query.Where("exchange_cash_person_list.employee_name LIKE ?", fmt.Sprintf("%%%s%%", personNameMatch.(string)))
133 } 139 }
  140 + if uid, ok := queryOptions["uid"]; ok {
  141 + query = query.Where("exchange_cash_person_list.uid = ?", uid)
  142 + }
134 if offset, ok := queryOptions["offset"]; ok { 143 if offset, ok := queryOptions["offset"]; ok {
135 offset := offset.(int) 144 offset := offset.(int)
136 if offset > -1 { 145 if offset > -1 {