作者 陈志颖

fix:修改更新兑换现金活动时的现金池更新机制

  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type UpdateCashPoolCommand struct {
  9 + CashPoolId int64 `json:"cashPoolId"` // 现金池编号
  10 + ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金
  11 + ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币
  12 + UnExchangeCash float64 `json:"unExchangeCash"` // 未兑换现金
  13 + UnExchangeSuMoney float64 `json:"unExchangedSuMoney"` // 未兑换素币
  14 + Rate float64 `json:"rate"` // 平均兑换汇率
  15 +}
  16 +
  17 +func (updateCashPoolCommand *UpdateCashPoolCommand) ValidateCommand() error {
  18 + valid := validation.Validation{}
  19 + b, err := valid.Valid(updateCashPoolCommand)
  20 + if err != nil {
  21 + return err
  22 + }
  23 + if !b {
  24 + for _, validErr := range valid.Errors {
  25 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  26 + }
  27 + }
  28 + return nil
  29 +}
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 "github.com/linmadan/egglib-go/utils/tool_funs" 5 "github.com/linmadan/egglib-go/utils/tool_funs"
6 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service" 6 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao" 7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
  8 + "math"
8 "strconv" 9 "strconv"
9 "time" 10 "time"
10 11
@@ -34,6 +35,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -34,6 +35,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
34 defer func() { 35 defer func() {
35 transactionContext.RollbackTransaction() 36 transactionContext.RollbackTransaction()
36 }() 37 }()
  38 + // 计算系统平均兑换汇率
37 var employeeDao *dao.EmployeeDao 39 var employeeDao *dao.EmployeeDao
38 if value, err := factory.CreateEmployeeDao(map[string]interface{}{ 40 if value, err := factory.CreateEmployeeDao(map[string]interface{}{
39 "transactionContext": transactionContext, 41 "transactionContext": transactionContext,
@@ -42,7 +44,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -42,7 +44,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
42 } else { 44 } else {
43 employeeDao = value 45 employeeDao = value
44 } 46 }
45 - // 统计系统素币  
46 systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId) 47 systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId)
47 if err != nil { 48 if err != nil {
48 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 49 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -50,16 +51,18 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -50,16 +51,18 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
50 if systemSuMoneyStatistics == nil { 51 if systemSuMoneyStatistics == nil {
51 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 52 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
52 } 53 }
  54 +
53 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) 55 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
54 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) 56 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
55 - // 统计系统现金  
56 systemCashStatistics, err := employeeDao.CalculateSystemCash(createCashPoolCommand.CompanyId) 57 systemCashStatistics, err := employeeDao.CalculateSystemCash(createCashPoolCommand.CompanyId)
  58 +
57 if err != nil { 59 if err != nil {
58 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 60 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
59 } 61 }
60 if systemCashStatistics == nil { 62 if systemCashStatistics == nil {
61 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 63 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
62 } 64 }
  65 +
63 systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64) 66 systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
64 systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64) 67 systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
65 var cashPoolRepository domain.CashPoolRepository 68 var cashPoolRepository domain.CashPoolRepository
@@ -88,13 +91,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -88,13 +91,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
88 Rate: rate, 91 Rate: rate,
89 CreateTime: time.Now(), 92 CreateTime: time.Now(),
90 } 93 }
91 - if value, err := factory.CreateCashPoolRepository(map[string] interface{} {  
92 - "transactionContext": transactionContext,  
93 - }); err != nil {  
94 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
95 - } else {  
96 - cashPoolRepository = value  
97 - }  
98 if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil { 94 if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil {
99 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 95 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
100 } else { 96 } else {
@@ -105,6 +101,38 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -105,6 +101,38 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
105 } 101 }
106 } 102 }
107 103
  104 +// 更新现金池
  105 +func (cashPoolService *CashPoolService) UpdateCashPool(updateCashPoolCommand *command.UpdateCashPoolCommand) (interface{}, error) {
  106 + if err := updateCashPoolCommand.ValidateCommand(); err != nil {
  107 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  108 + }
  109 + transactionContext, err := factory.CreateTransactionContext(nil)
  110 + if err != nil {
  111 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  112 + }
  113 + if err := transactionContext.StartTransaction(); err != nil {
  114 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  115 + }
  116 + defer func() {
  117 + transactionContext.RollbackTransaction()
  118 + }()
  119 +
  120 + //var cashPoolRepository domain.CashPoolRepository
  121 + //if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
  122 + // "transactionContext": transactionContext,
  123 + //}); err != nil {
  124 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  125 + //} else {
  126 + // cashPoolRepository = value
  127 + //}
  128 + //
  129 + //count, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
  130 + // "companyId":
  131 + //})
  132 +
  133 + return nil , nil
  134 +}
  135 +
108 // 返回现金池 136 // 返回现金池
109 func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetCashPoolQuery) (interface{}, error) { 137 func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetCashPoolQuery) (interface{}, error) {
110 if err := getCashPoolQuery.ValidateQuery(); err != nil { 138 if err := getCashPoolQuery.ValidateQuery(); err != nil {
@@ -240,6 +268,9 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas @@ -240,6 +268,9 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
240 } else { 268 } else {
241 exchangeActivityRepository = value 269 exchangeActivityRepository = value
242 } 270 }
  271 +
  272 + // TODO 需要更新兑换活动结束倒计时
  273 +
243 if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashActivityQuery)); err != nil { 274 if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashActivityQuery)); err != nil {
244 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 275 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
245 } else { 276 } else {
@@ -316,6 +347,9 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA @@ -316,6 +347,9 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA
316 } else { 347 } else {
317 exchangeCashActivityRepository = value 348 exchangeCashActivityRepository = value
318 } 349 }
  350 +
  351 + // TODO 需要更新兑换活动结束倒计时
  352 +
319 activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"exchangeCashActivityId": getExchangeCashActivityQuery.ExchangeCashActivityId}) 353 activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"exchangeCashActivityId": getExchangeCashActivityQuery.ExchangeCashActivityId})
320 if err != nil { 354 if err != nil {
321 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 355 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -330,7 +364,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA @@ -330,7 +364,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA
330 } 364 }
331 } 365 }
332 366
333 -// 更新兑换现金活动 367 +// 更新兑换现金活动,名称,截止日期、汇率
334 func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchangeCashActivityCommand *command.UpdateExchangeCashActivityCommand) (interface{}, error) { 368 func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchangeCashActivityCommand *command.UpdateExchangeCashActivityCommand) (interface{}, error) {
335 if err := updateExchangeCashActivityCommand.ValidateCommand(); err != nil { 369 if err := updateExchangeCashActivityCommand.ValidateCommand(); err != nil {
336 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 370 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -345,9 +379,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -345,9 +379,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
345 defer func() { 379 defer func() {
346 transactionContext.RollbackTransaction() 380 transactionContext.RollbackTransaction()
347 }() 381 }()
348 -  
349 - // TODO 更新汇率判断  
350 -  
351 var exchangeCashActivityRepository domain.ExchangeActivityRepository 382 var exchangeCashActivityRepository domain.ExchangeActivityRepository
352 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ 383 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
353 "transactionContext": transactionContext, 384 "transactionContext": transactionContext,
@@ -366,20 +397,104 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -366,20 +397,104 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
366 if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil { 397 if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
367 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 398 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
368 } 399 }
369 - activityUpdated, err := exchangeCashActivityRepository.Save(activity)  
370 - if err != nil {  
371 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
372 - } 400 + if updateExchangeCashActivityCommand.ExchangeRate != 0 {
  401 + var cashPoolRepository domain.CashPoolRepository
  402 + if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
  403 + "transactionContext": transactionContext,
  404 + }); err != nil {
  405 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  406 + } else {
  407 + cashPoolRepository = value
  408 + }
  409 + _, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
  410 + "companyId": activity.CompanyId,
  411 + })
  412 + if err != nil {
  413 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  414 + }
  415 + if cashPools == nil {
  416 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activity.CompanyId)))
  417 + }
  418 + // 修改汇率时判断兑换活动清单中现金总金额是否超过平台未兑换现金值
  419 + var cashPoolDao *dao.CashPoolDao
  420 + if value, err := factory.CreateCashPoolDao(map[string]interface{}{
  421 + "transactionContext": transactionContext,
  422 + }); err != nil {
  423 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  424 + } else {
  425 + cashPoolDao = value
  426 + }
  427 + activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activity.CompanyId)
  428 + if err != nil {
  429 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  430 + }
  431 + if activitySuMoneyStatistics == nil {
  432 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
  433 + }
  434 + activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
  435 + if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPools[0].UnExchangeCash {
  436 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
  437 + }
  438 + // 计算系统平均兑换汇率
  439 + var employeeDao *dao.EmployeeDao
  440 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  441 + "transactionContext": transactionContext,
  442 + }); err != nil {
  443 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  444 + } else {
  445 + employeeDao = value
  446 + }
  447 + systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activity.CompanyId)
  448 + if err != nil {
  449 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  450 + }
  451 + if systemSuMoneyStatistics == nil {
  452 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
  453 + }
  454 + systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
  455 + //systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
  456 + systemCashStatistics, err := employeeDao.CalculateSystemCash(activity.CompanyId)
  457 + if err != nil {
  458 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  459 + }
  460 + if systemCashStatistics == nil {
  461 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
  462 + }
  463 + systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
  464 + systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
  465 + rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) // 平均兑换汇率
  466 + // 更新现金池
  467 + updateCashPoolCommand := &command.UpdateCashPoolCommand{
  468 + CashPoolId: cashPools[0].CashPoolId,
  469 + //ExchangedSuMoney: systemExchangedSuMoney,
  470 + ExchangedCash: systemExchangedCash,
  471 + UnExchangeCash: systemUnExchangeCash,
  472 + //UnExchangeSuMoney: systemUnExchangeSuMoney,
  473 + Rate: rate,
  474 + }
  475 + if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
  476 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  477 + }
  478 + cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0])
  479 + if err != nil {
  480 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  481 + }
  482 + if cashPoolUpdated == nil {
  483 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  484 + }
373 485
374 - // TODO 更新现金池  
375 - // 获取现金池 486 + // TODO 更新兑换清单中已兑换现金值
376 487
377 - // 更新现金池 488 + }
378 489
379 - if err := transactionContext.CommitTransaction(); err != nil {  
380 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 490 + if activityUpdated, err := exchangeCashActivityRepository.Save(activity); err != nil {
  491 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  492 + } else {
  493 + if err := transactionContext.CommitTransaction(); err != nil {
  494 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  495 + }
  496 + return activityUpdated, nil
381 } 497 }
382 - return activityUpdated, nil  
383 } 498 }
384 499
385 // 新增兑换素币清单 500 // 新增兑换素币清单
@@ -407,7 +522,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -407,7 +522,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
407 if activity != nil { 522 if activity != nil {
408 rate = activity.Rate 523 rate = activity.Rate
409 } 524 }
410 - // 根据uid/手机账号判断成员是否存在 525 + // 根据uid/手机账号判断成员是否存在,素币是否超过本人持有的真实素币
411 var employeeRepository domain.EmployeeRepository 526 var employeeRepository domain.EmployeeRepository
412 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{ 527 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
413 "transactionContext": transactionContext, 528 "transactionContext": transactionContext,
@@ -490,8 +605,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -490,8 +605,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
490 if activityFound == nil { 605 if activityFound == nil {
491 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId))) 606 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
492 } 607 }
493 - createExchangeCashPersonCommand.ExchangedSuMoney += activityFound.ExchangedSuMoney  
494 - if err := activityFound.Update(tool_funs.SimpleStructToMap(createExchangeCashPersonCommand)); err != nil { 608 + updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
  609 + ExchangeCashActivityId: person.ExchangeCashActivityId,
  610 + ExchangedSuMoney: activityFound.ExchangedSuMoney + person.ExchangedSuMoney,
  611 + ExchangedCash: activityFound.ExchangedCash - person.ExchangedCash,
  612 + }
  613 + if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
495 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 614 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
496 } 615 }
497 activityUpdated, err := exchangeCashActivityRepository.Save(activityFound) 616 activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
@@ -663,7 +782,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -663,7 +782,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
663 } 782 }
664 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{ 783 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
665 ExchangeCashActivityId: person.ExchangeCashActivityId, 784 ExchangeCashActivityId: person.ExchangeCashActivityId,
666 - ExchangedSuMoney: activityFound.ExchangedSuMoney + person.ExchangedSuMoney, 785 + ExchangedSuMoney: activityFound.ExchangedSuMoney - person.ExchangedSuMoney,
667 ExchangedCash: activityFound.ExchangedCash + person.ExchangedCash, 786 ExchangedCash: activityFound.ExchangedCash + person.ExchangedCash,
668 } 787 }
669 if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil { 788 if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
@@ -728,27 +847,57 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -728,27 +847,57 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
728 if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil { 847 if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
729 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 848 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
730 } 849 }
731 - personUpdated, err := exchangeCashPersonListRepository.Save(person) 850 + // 更新兑换活动
  851 + var exchangeCashActivityRepository domain.ExchangeActivityRepository
  852 + if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
  853 + "transactionContext": transactionContext,
  854 + }); err != nil {
  855 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  856 + } else {
  857 + exchangeCashActivityRepository = value
  858 + }
  859 + activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": person.ExchangeCashActivityId})
732 if err != nil { 860 if err != nil {
733 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 861 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
734 } 862 }
735 -  
736 - // TODO 更新兑换活动  
737 - 863 + if activityFound == nil {
  864 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(person.ExchangeCashActivityId)))
  865 + }
  866 + updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
  867 + ExchangeCashActivityId: person.ExchangeCashActivityId,
  868 + ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
  869 + ExchangedCash: activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
  870 + }
  871 + if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
  872 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  873 + }
  874 + activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
  875 + if err != nil {
  876 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  877 + }
  878 + if activityUpdated == nil {
  879 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
  880 + }
738 881
739 // TODO 判断现金池未兑换现金 882 // TODO 判断现金池未兑换现金
740 883
741 -  
742 // TODO 更新现金池 884 // TODO 更新现金池
743 885
744 // 生成素币兑换流水记录,更新员工素币 886 // 生成素币兑换流水记录,更新员工素币
745 - operationSuMoneyCommand := &command.OperationSuMoneyCommand{ 887 + operationSuMoneyCommand := &command.OperationSuMoneyCommand{
746 Uid: person.EmployeeInfo.Uid, 888 Uid: person.EmployeeInfo.Uid,
747 Operator: updateExchangeCashPersonCommand.Operator, 889 Operator: updateExchangeCashPersonCommand.Operator,
748 - SuMoney: updateExchangeCashPersonCommand.ExchangedSuMoney,  
749 - OperationType: 3, 890 + SuMoney: 0,
  891 + OperationType: 0,
750 OperationDescription: "参与兑换素币活动", 892 OperationDescription: "参与兑换素币活动",
751 } 893 }
  894 + if updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney > 0 {
  895 + operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
  896 + operationSuMoneyCommand.OperationType = 5
  897 + } else {
  898 + operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
  899 + operationSuMoneyCommand.OperationType = 3
  900 + }
752 task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription) 901 task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
753 if err != nil { 902 if err != nil {
754 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 903 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -756,6 +905,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -756,6 +905,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
756 if task == nil { 905 if task == nil {
757 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid))) 906 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
758 } 907 }
  908 + personUpdated, err := exchangeCashPersonListRepository.Save(person)
  909 + if err != nil {
  910 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  911 + }
759 if err := transactionContext.CommitTransaction(); err != nil { 912 if err := transactionContext.CommitTransaction(); err != nil {
760 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 913 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
761 } 914 }
@@ -29,8 +29,10 @@ type CreateTaskCommand struct { @@ -29,8 +29,10 @@ type CreateTaskCommand struct {
29 TaskNature int `json:"taskNature,omitempty"` 29 TaskNature int `json:"taskNature,omitempty"`
30 // 奖励素币 30 // 奖励素币
31 SuMoney float64 `json:"suMoney,omitempty"` 31 SuMoney float64 `json:"suMoney,omitempty"`
32 - // 奖励素币参考值范围(1000~3000)  
33 - ReferenceSuMoney string `json:"referenceSuMoney"` 32 + // 最小奖励素币
  33 + MinSuMoney float64 `json:"minSuMoney"`
  34 + // 最大奖励素币
  35 + MaxSuMoney float64 `json:"maxSuMoney"`
34 // 验收标准 36 // 验收标准
35 AcceptanceStandard string `json:"acceptanceStandard,omitempty"` 37 AcceptanceStandard string `json:"acceptanceStandard,omitempty"`
36 // 任务描述 38 // 任务描述
@@ -23,8 +23,12 @@ type UpdateTaskCommand struct { @@ -23,8 +23,12 @@ type UpdateTaskCommand struct {
23 CustomerValues []int `json:"customerValues,omitempty"` 23 CustomerValues []int `json:"customerValues,omitempty"`
24 // 任务性质 24 // 任务性质
25 TaskNature int `json:"taskNature,omitempty"` 25 TaskNature int `json:"taskNature,omitempty"`
26 - // 奖励素币 26 + // 实际奖励素币
27 SuMoney float64 `json:"suMoney,omitempty"` 27 SuMoney float64 `json:"suMoney,omitempty"`
  28 + // 最小奖励素币
  29 + MinSuMoney float64 `json:"minSuMoney,omitempty"`
  30 + // 最大奖励素币
  31 + MaxSuMoney float64 `json:"maxSuMoney,omitempty"`
28 // 验收标准 32 // 验收标准
29 AcceptanceStandard string `json:"acceptanceStandard,omitempty"` 33 AcceptanceStandard string `json:"acceptanceStandard,omitempty"`
30 // 任务描述 34 // 任务描述
@@ -841,7 +841,8 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask @@ -841,7 +841,8 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
841 CustomerValues: createTaskCommand.CustomerValues, 841 CustomerValues: createTaskCommand.CustomerValues,
842 TaskNature: createTaskCommand.TaskNature, 842 TaskNature: createTaskCommand.TaskNature,
843 SuMoney: createTaskCommand.SuMoney, 843 SuMoney: createTaskCommand.SuMoney,
844 - ReferenceSuMoney: createTaskCommand.ReferenceSuMoney, // 奖励素币范围 844 + MinSuMoney: createTaskCommand.MinSuMoney,
  845 + MaxSuMoney: createTaskCommand.MaxSuMoney,
845 AcceptanceStandard: createTaskCommand.AcceptanceStandard, 846 AcceptanceStandard: createTaskCommand.AcceptanceStandard,
846 TaskDescription: createTaskCommand.TaskDescription, 847 TaskDescription: createTaskCommand.TaskDescription,
847 TaskPictureUrls: createTaskCommand.TaskPictureUrls, 848 TaskPictureUrls: createTaskCommand.TaskPictureUrls,
@@ -1209,11 +1210,11 @@ func (taskService *TaskService) ListTask(listTaskQuery *query.ListTaskQuery) (in @@ -1209,11 +1210,11 @@ func (taskService *TaskService) ListTask(listTaskQuery *query.ListTaskQuery) (in
1209 if err := transactionContext.CommitTransaction(); err != nil { 1210 if err := transactionContext.CommitTransaction(); err != nil {
1210 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1211 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1211 } 1212 }
1212 - // 拼接奖励素币范围值  
1213 var retTasks []*domain.Task 1213 var retTasks []*domain.Task
1214 for _, task := range tasks { 1214 for _, task := range tasks {
1215 - if task.ReferenceSuMoney == "" {  
1216 - task.ReferenceSuMoney = "0~" + fmt.Sprintf("%.0f", task.SuMoney) 1215 + if task.TaskStatus != 5 && task.MinSuMoney == 0 && task.MaxSuMoney == 0 {
  1216 + task.MinSuMoney = 0
  1217 + task.MaxSuMoney = task.SuMoney
1217 } 1218 }
1218 retTasks = append(retTasks, task) 1219 retTasks = append(retTasks, task)
1219 } 1220 }
@@ -50,8 +50,10 @@ type Task struct { @@ -50,8 +50,10 @@ type Task struct {
50 TaskNature int `json:"taskNature"` 50 TaskNature int `json:"taskNature"`
51 // 奖励素币 51 // 奖励素币
52 SuMoney float64 `json:"suMoney"` 52 SuMoney float64 `json:"suMoney"`
53 - // 奖励素币参考值  
54 - ReferenceSuMoney string `json:"referenceSuMoney"` 53 + // 最小奖励素币
  54 + MinSuMoney float64 `json:"minSuMoney"`
  55 + // 最大奖励素币
  56 + MaxSuMoney float64 `json:"maxSuMoney"`
55 // 验收标准 57 // 验收标准
56 AcceptanceStandard string `json:"acceptanceStandard"` 58 AcceptanceStandard string `json:"acceptanceStandard"`
57 // 任务描述 59 // 任务描述
@@ -53,7 +53,7 @@ type CashPoolDao struct { @@ -53,7 +53,7 @@ type CashPoolDao struct {
53 // }, nil 53 // }, nil
54 //} 54 //}
55 55
56 -// 兑换兑换活动已兑换素币、已兑换现金 56 +// 兑换活动兑换清单已兑换素币、已兑换现金
57 func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map[string]interface{}, error) { 57 func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map[string]interface{}, error) {
58 var activityExchangedSuMoney float64 58 var activityExchangedSuMoney float64
59 var activityExchangedCash float64 59 var activityExchangedCash float64
@@ -29,8 +29,10 @@ type Task struct { @@ -29,8 +29,10 @@ type Task struct {
29 TaskNature int 29 TaskNature int
30 // 奖励素币 30 // 奖励素币
31 SuMoney float64 31 SuMoney float64
32 - // 奖励素币参考值范围值  
33 - ReferenceSuMoney string 32 + // 最小奖励素币
  33 + MinSuMoney float64
  34 + // 最大奖励素币
  35 + MaxSuMoney float64
34 // 验收标准 36 // 验收标准
35 AcceptanceStandard string 37 AcceptanceStandard string
36 // 任务描述 38 // 任务描述