作者 陈志颖

fix:整理现金池处理逻辑

@@ -86,11 +86,11 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -86,11 +86,11 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
86 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) // 平台已兑换素币 86 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) // 平台已兑换素币
87 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) // 平台未兑换素币 87 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) // 平台未兑换素币
88 88
  89 + // 获取当前公司现金池
89 count, cashPools, err := cashPoolRepository.Find(tool_funs.SimpleStructToMap(createCashPoolCommand)) 90 count, cashPools, err := cashPoolRepository.Find(tool_funs.SimpleStructToMap(createCashPoolCommand))
90 if err != nil { 91 if err != nil {
91 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 92 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
92 } 93 }
93 - fmt.Print(count, "\n")  
94 if count == 0 { // 新增现金池 94 if count == 0 { // 新增现金池
95 newCashPool := &domain.CashPool{ 95 newCashPool := &domain.CashPool{
96 CompanyId: createCashPoolCommand.CompanyId, 96 CompanyId: createCashPoolCommand.CompanyId,
@@ -226,7 +226,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC @@ -226,7 +226,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
226 if systemSuMoneyStatistics == nil { 226 if systemSuMoneyStatistics == nil {
227 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 227 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
228 } 228 }
229 - //systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) // 平台已兑换素币  
230 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) // 平台未兑换素币 229 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) // 平台未兑换素币
231 230
232 // 查找当前公司现金池 231 // 查找当前公司现金池
@@ -273,12 +272,23 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang @@ -273,12 +272,23 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
273 transactionContext.RollbackTransaction() 272 transactionContext.RollbackTransaction()
274 }() 273 }()
275 274
  275 + // 兑换现金活动仓储初始化
  276 + var exchangeCashActivityRepository domain.ExchangeActivityRepository
  277 + if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
  278 + "transactionContext": transactionContext,
  279 + }); err != nil {
  280 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  281 + } else {
  282 + exchangeCashActivityRepository = value
  283 + }
  284 +
276 // 时间格式化 285 // 时间格式化
277 var timeNow = time.Now() 286 var timeNow = time.Now()
278 var deadline = createExchangeCashActivityCommand.Deadline 287 var deadline = createExchangeCashActivityCommand.Deadline
279 var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local) 288 var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
280 var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 999999, time.Local) 289 var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 999999, time.Local)
281 290
  291 + // 创建兑换活动命令
282 newActivity := &domain.ExchangeCashActivity{ 292 newActivity := &domain.ExchangeCashActivity{
283 ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName, 293 ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
284 CompanyId: createExchangeCashActivityCommand.CompanyId, 294 CompanyId: createExchangeCashActivityCommand.CompanyId,
@@ -290,20 +300,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang @@ -290,20 +300,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
290 CreateTime: time.Now(), 300 CreateTime: time.Now(),
291 } 301 }
292 302
293 - // 倒计时结束 303 + // 倒计时结束判断
294 if t2.Before(t1) { 304 if t2.Before(t1) {
295 newActivity.CountDown = 0 305 newActivity.CountDown = 0
296 } 306 }
297 307
298 - var exchangeCashActivityRepository domain.ExchangeActivityRepository  
299 - if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{  
300 - "transactionContext": transactionContext,  
301 - }); err != nil {  
302 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
303 - } else {  
304 - exchangeCashActivityRepository = value  
305 - }  
306 - 308 + // 保存兑换活动
307 if activity, err := exchangeCashActivityRepository.Save(newActivity); err != nil { 309 if activity, err := exchangeCashActivityRepository.Save(newActivity); err != nil {
308 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 310 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
309 } else { 311 } else {
@@ -330,6 +332,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc @@ -330,6 +332,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc
330 transactionContext.RollbackTransaction() 332 transactionContext.RollbackTransaction()
331 }() 333 }()
332 334
  335 + // 兑换现金活动仓储初始化
333 var exchangeActivityRepository domain.ExchangeActivityRepository 336 var exchangeActivityRepository domain.ExchangeActivityRepository
334 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ 337 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
335 "transactionContext": transactionContext, 338 "transactionContext": transactionContext,
@@ -339,6 +342,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc @@ -339,6 +342,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc
339 exchangeActivityRepository = value 342 exchangeActivityRepository = value
340 } 343 }
341 344
  345 + // 获取该公司所有兑换现金活动
342 if _, activities, err := exchangeActivityRepository.FindAll(tool_funs.SimpleStructToMap(listExchangeCashActivityDeadlineQuery)); err != nil { 346 if _, activities, err := exchangeActivityRepository.FindAll(tool_funs.SimpleStructToMap(listExchangeCashActivityDeadlineQuery)); err != nil {
343 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 347 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
344 } else { 348 } else {
@@ -346,6 +350,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc @@ -346,6 +350,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc
346 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 350 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
347 } 351 }
348 352
  353 + // 提取兑换现金活动截止时间
349 var deadlines []interface{} 354 var deadlines []interface{}
350 for _, activity := range activities { 355 for _, activity := range activities {
351 deadlines = append(deadlines, activity.Deadline) 356 deadlines = append(deadlines, activity.Deadline)
@@ -377,6 +382,7 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma @@ -377,6 +382,7 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma
377 transactionContext.RollbackTransaction() 382 transactionContext.RollbackTransaction()
378 }() 383 }()
379 384
  385 + // 兑换现金活动仓储初始化
380 var exchangeActivityRepository domain.ExchangeActivityRepository 386 var exchangeActivityRepository domain.ExchangeActivityRepository
381 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ 387 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
382 "transactionContext": transactionContext, 388 "transactionContext": transactionContext,
@@ -386,6 +392,7 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma @@ -386,6 +392,7 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma
386 exchangeActivityRepository = value 392 exchangeActivityRepository = value
387 } 393 }
388 394
  395 + // 查找兑换现金活动
389 if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(activityCommand)); err != nil { 396 if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(activityCommand)); err != nil {
390 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 397 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
391 } else { 398 } else {
@@ -393,25 +400,28 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma @@ -393,25 +400,28 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma
393 var t1 = time.Now() 400 var t1 = time.Now()
394 var t2 = activity.Deadline 401 var t2 = activity.Deadline
395 402
  403 + // 更新兑换活动命令
396 updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand { 404 updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
397 ExchangeCashActivityId: activity.ActivityId, 405 ExchangeCashActivityId: activity.ActivityId,
398 - CountDown: int64(t2.Sub(t1).Hours() / 24), 406 + CountDown: int64(t2.Sub(t1).Hours() / 24), // 计算倒计时
399 Deadline: activity.Deadline, 407 Deadline: activity.Deadline,
400 ExchangedSuMoney: activity.ExchangedSuMoney, 408 ExchangedSuMoney: activity.ExchangedSuMoney,
401 ExchangedCash: activity.ExchangedCash, 409 ExchangedCash: activity.ExchangedCash,
402 ExchangeRate: activity.Rate, 410 ExchangeRate: activity.Rate,
403 } 411 }
404 412
405 - // 倒计时结束 413 + // 倒计时结束处理
406 if t2.Before(t1) { 414 if t2.Before(t1) {
407 updateExchangeCashActivity.CountDown = 0 415 updateExchangeCashActivity.CountDown = 0
408 updateExchangeCashActivity.Deadline = activity.Deadline 416 updateExchangeCashActivity.Deadline = activity.Deadline
409 } 417 }
410 418
  419 + // 更新兑换现金活动
411 if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil { 420 if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
412 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 421 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
413 } 422 }
414 423
  424 + // 保存更新
415 _, err := exchangeActivityRepository.Save(activity) 425 _, err := exchangeActivityRepository.Save(activity)
416 if err != nil { 426 if err != nil {
417 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 427 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -445,6 +455,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas @@ -445,6 +455,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
445 transactionContext.RollbackTransaction() 455 transactionContext.RollbackTransaction()
446 }() 456 }()
447 457
  458 + // 兑换现金活动仓储初始化
448 var exchangeActivityRepository domain.ExchangeActivityRepository 459 var exchangeActivityRepository domain.ExchangeActivityRepository
449 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ 460 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
450 "transactionContext": transactionContext, 461 "transactionContext": transactionContext,
@@ -454,6 +465,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas @@ -454,6 +465,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
454 exchangeActivityRepository = value 465 exchangeActivityRepository = value
455 } 466 }
456 467
  468 + // 查找兑换现金活动
457 if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashActivityQuery)); err != nil { 469 if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashActivityQuery)); err != nil {
458 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 470 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
459 } else { 471 } else {
@@ -461,25 +473,28 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas @@ -461,25 +473,28 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
461 var t1 = time.Now() 473 var t1 = time.Now()
462 var t2 = activity.Deadline 474 var t2 = activity.Deadline
463 475
  476 + // 更新兑换现金活动命令
464 updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand { 477 updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
465 ExchangeCashActivityId: activity.ActivityId, 478 ExchangeCashActivityId: activity.ActivityId,
466 - CountDown: int64(t2.Sub(t1).Hours() / 24), 479 + CountDown: int64(t2.Sub(t1).Hours() / 24), // 重新计算活动倒计时
467 Deadline: activity.Deadline, 480 Deadline: activity.Deadline,
468 ExchangedSuMoney: activity.ExchangedSuMoney, 481 ExchangedSuMoney: activity.ExchangedSuMoney,
469 ExchangedCash: activity.ExchangedCash, 482 ExchangedCash: activity.ExchangedCash,
470 ExchangeRate: activity.Rate, 483 ExchangeRate: activity.Rate,
471 } 484 }
472 485
473 - // 倒计时结束 486 + // 倒计时结束处理
474 if t2.Before(t1) { 487 if t2.Before(t1) {
475 updateExchangeCashActivity.CountDown = 0 488 updateExchangeCashActivity.CountDown = 0
476 updateExchangeCashActivity.Deadline = activity.Deadline 489 updateExchangeCashActivity.Deadline = activity.Deadline
477 } 490 }
478 491
  492 + // 更新兑换现金活动
479 if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil { 493 if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
480 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 494 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
481 } 495 }
482 496
  497 + // 保存兑换现金活动更新
483 _, err := exchangeActivityRepository.Save(activity) 498 _, err := exchangeActivityRepository.Save(activity)
484 if err != nil { 499 if err != nil {
485 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 500 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -490,6 +505,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas @@ -490,6 +505,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
490 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 505 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
491 } 506 }
492 507
  508 + // 兑换现金活动返回截止时间处理
493 var activitiesWithTs []interface{} 509 var activitiesWithTs []interface{}
494 for _, activity := range activities { 510 for _, activity := range activities {
495 activityWithTs := map[string]interface{} { 511 activityWithTs := map[string]interface{} {
@@ -498,7 +514,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas @@ -498,7 +514,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
498 "companyId": activity.CompanyId, 514 "companyId": activity.CompanyId,
499 "exchangedCash": activity.ExchangedCash, 515 "exchangedCash": activity.ExchangedCash,
500 "exchangedSuMoney": activity.ExchangedSuMoney, 516 "exchangedSuMoney": activity.ExchangedSuMoney,
501 - "deadline": activity.Deadline.UnixNano() / 1e6, 517 + "deadline": activity.Deadline.UnixNano() / 1e6, // 秒级时间戳转换
502 "countDown": activity.CountDown, 518 "countDown": activity.CountDown,
503 "rate": activity.Rate, 519 "rate": activity.Rate,
504 "createTime": activity.CreateTime, 520 "createTime": activity.CreateTime,
@@ -529,6 +545,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang @@ -529,6 +545,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang
529 transactionContext.RollbackTransaction() 545 transactionContext.RollbackTransaction()
530 }() 546 }()
531 547
  548 + // 兑换现金活动仓储初始化
532 var exchangeCashActivityRepository domain.ExchangeActivityRepository 549 var exchangeCashActivityRepository domain.ExchangeActivityRepository
533 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ 550 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
534 "transactionContext": transactionContext, 551 "transactionContext": transactionContext,
@@ -538,15 +555,17 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang @@ -538,15 +555,17 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang
538 exchangeCashActivityRepository = value 555 exchangeCashActivityRepository = value
539 } 556 }
540 557
541 - activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": removeExchangeCashActivityCommand.ActivityId}) 558 + // 查找兑换现金活动
  559 + activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": removeExchangeCashActivityCommand.ActivityId})
542 if err != nil { 560 if err != nil {
543 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 561 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
544 } 562 }
545 - if activity == nil { 563 + if activityFound == nil {
546 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashActivityCommand.ActivityId))) 564 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashActivityCommand.ActivityId)))
547 } 565 }
548 566
549 - if activityDeleted, err := exchangeCashActivityRepository.Remove(activity); err != nil { 567 + // 删除兑换现金活动
  568 + if activityDeleted, err := exchangeCashActivityRepository.Remove(activityFound); err != nil {
550 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 569 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
551 } else { 570 } else {
552 if err := transactionContext.CommitTransaction(); err != nil { 571 if err := transactionContext.CommitTransaction(); err != nil {
@@ -572,6 +591,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA @@ -572,6 +591,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA
572 transactionContext.RollbackTransaction() 591 transactionContext.RollbackTransaction()
573 }() 592 }()
574 593
  594 + // 兑换现金活动仓储初始化
575 var exchangeCashActivityRepository domain.ExchangeActivityRepository 595 var exchangeCashActivityRepository domain.ExchangeActivityRepository
576 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ 596 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
577 "transactionContext": transactionContext, 597 "transactionContext": transactionContext,
@@ -581,51 +601,55 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA @@ -581,51 +601,55 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA
581 exchangeCashActivityRepository = value 601 exchangeCashActivityRepository = value
582 } 602 }
583 603
584 - // 需要更新兑换活动结束倒计时  
585 - activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": getExchangeCashActivityQuery.ExchangeCashActivityId}) 604 + // 获取兑换现金活动
  605 + activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": getExchangeCashActivityQuery.ExchangeCashActivityId})
586 if err != nil { 606 if err != nil {
587 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 607 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
588 } 608 }
589 - if activity == nil { 609 + if activityFound == nil {
590 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashActivityQuery.ExchangeCashActivityId))) 610 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashActivityQuery.ExchangeCashActivityId)))
591 } 611 }
592 612
593 - var timeNow = time.Now()  
594 - var deadline = activity.Deadline  
595 - var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)  
596 - var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local) 613 + //var timeNow = time.Now()
  614 + //var deadline = activityFound.Deadline
  615 + //var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
  616 + var t1 = time.Now()
  617 + //var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, time.Local)
  618 + var t2 = activityFound.Deadline
597 619
  620 + // 更新兑换现金活动倒计时命令
598 updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand { 621 updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
599 - ExchangeCashActivityId: activity.ActivityId, 622 + ExchangeCashActivityId: activityFound.ActivityId,
600 CountDown: int64(t2.Sub(t1).Hours() / 24), 623 CountDown: int64(t2.Sub(t1).Hours() / 24),
601 - Deadline: activity.Deadline,  
602 - ExchangedSuMoney: activity.ExchangedSuMoney,  
603 - ExchangedCash: activity.ExchangedCash,  
604 - ExchangeRate: activity.Rate, 624 + Deadline: activityFound.Deadline,
  625 + ExchangedSuMoney: activityFound.ExchangedSuMoney,
  626 + ExchangedCash: activityFound.ExchangedCash,
  627 + ExchangeRate: activityFound.Rate,
605 } 628 }
606 629
607 - // 倒计时结束 630 + // 倒计时结束处理
608 if t2.Before(t1) { 631 if t2.Before(t1) {
609 updateExchangeCashActivity.CountDown = 0 632 updateExchangeCashActivity.CountDown = 0
610 - updateExchangeCashActivity.Deadline = activity.Deadline 633 + updateExchangeCashActivity.Deadline = activityFound.Deadline
611 } 634 }
612 635
613 - if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil { 636 + // 更新兑换现活动
  637 + if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
614 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 638 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
615 } 639 }
616 640
617 - activityFound, err := exchangeCashActivityRepository.Save(activity) 641 + // 保存兑换现金活动更新
  642 + activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
618 if err != nil { 643 if err != nil {
619 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 644 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
620 } 645 }
621 -  
622 - if activityFound == nil { 646 + if activityUpdated == nil {
623 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 647 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
624 } else { 648 } else {
625 if err := transactionContext.CommitTransaction(); err != nil { 649 if err := transactionContext.CommitTransaction(); err != nil {
626 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 650 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
627 } 651 }
628 - return activityFound, nil 652 + return activityUpdated, nil
629 } 653 }
630 } 654 }
631 655
@@ -645,7 +669,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -645,7 +669,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
645 transactionContext.RollbackTransaction() 669 transactionContext.RollbackTransaction()
646 }() 670 }()
647 671
648 - // 更新兑换活动 672 + // 兑换现金活动仓储初始化
649 var exchangeCashActivityRepository domain.ExchangeActivityRepository 673 var exchangeCashActivityRepository domain.ExchangeActivityRepository
650 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ 674 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
651 "transactionContext": transactionContext, 675 "transactionContext": transactionContext,
@@ -655,71 +679,84 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -655,71 +679,84 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
655 exchangeCashActivityRepository = value 679 exchangeCashActivityRepository = value
656 } 680 }
657 681
658 - activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": updateExchangeCashActivityCommand.ExchangeCashActivityId}) 682 + // 兑换素币清单仓储初始化
  683 + var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
  684 + if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
  685 + "transactionContext": transactionContext,
  686 + }); err != nil {
  687 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  688 + } else {
  689 + exchangeCashPersonListRepository = value
  690 + }
  691 +
  692 + // 现金池仓储初始化
  693 + var cashPoolRepository domain.CashPoolRepository
  694 + if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
  695 + "transactionContext": transactionContext,
  696 + }); err != nil {
  697 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  698 + } else {
  699 + cashPoolRepository = value
  700 + }
  701 +
  702 + // 现金池DAO初始化
  703 + var cashPoolDao *dao.CashPoolDao
  704 + if value, err := factory.CreateCashPoolDao(map[string]interface{}{
  705 + "transactionContext": transactionContext,
  706 + }); err != nil {
  707 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  708 + } else {
  709 + cashPoolDao = value
  710 + }
  711 +
  712 + // 员工DAO初始化
  713 + var employeeDao *dao.EmployeeDao
  714 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  715 + "transactionContext": transactionContext,
  716 + }); err != nil {
  717 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  718 + } else {
  719 + employeeDao = value
  720 + }
  721 +
  722 + // 获取当前活动
  723 + activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": updateExchangeCashActivityCommand.ExchangeCashActivityId})
659 if err != nil { 724 if err != nil {
660 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 725 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
661 } 726 }
662 - if activity == nil { 727 + if activityFound == nil {
663 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId))) 728 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
664 } 729 }
665 730
666 - // 更新兑换活动兑换汇率  
667 - if updateExchangeCashActivityCommand.ExchangeRate != 0 {  
668 - // 获取当前现金池  
669 - var cashPoolRepository domain.CashPoolRepository  
670 - if value, err := factory.CreateCashPoolRepository(map[string] interface{} {  
671 - "transactionContext": transactionContext,  
672 - }); err != nil {  
673 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
674 - } else {  
675 - cashPoolRepository = value  
676 - }  
677 -  
678 - _, cashPools, err := cashPoolRepository.Find(map[string]interface{}{  
679 - "companyId": activity.CompanyId, 731 + if updateExchangeCashActivityCommand.ExchangeRate != 0 { // 更新兑换活动兑换汇率
  732 + // 获取当前公司现金池
  733 + _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
  734 + "companyId": activityFound.CompanyId,
680 }) 735 })
681 if err != nil { 736 if err != nil {
682 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 737 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
683 } 738 }
684 - if len(cashPools) == 0 {  
685 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activity.CompanyId))) 739 + if len(cashPoolsFound) == 0 {
  740 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
686 } 741 }
687 742
688 - // 判断兑换活动清单中现金总金额是否超过平台未兑换现金值  
689 - var cashPoolDao *dao.CashPoolDao  
690 - if value, err := factory.CreateCashPoolDao(map[string]interface{}{  
691 - "transactionContext": transactionContext,  
692 - }); err != nil {  
693 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
694 - } else {  
695 - cashPoolDao = value  
696 - }  
697 -  
698 - activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activity.ActivityId) 743 + // 获取活动素币统计
  744 + activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.ActivityId)
699 if err != nil { 745 if err != nil {
700 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 746 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
701 } 747 }
702 if activitySuMoneyStatistics == nil { 748 if activitySuMoneyStatistics == nil {
703 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业") 749 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
704 } 750 }
705 -  
706 activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64) 751 activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
707 752
708 - if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPools[0].UnExchangeCash {  
709 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")  
710 - }  
711 -  
712 - // 批量更新兑换清单中已兑换现金值  
713 - var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository  
714 - if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{  
715 - "transactionContext": transactionContext,  
716 - }); err != nil {  
717 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
718 - } else {  
719 - exchangeCashPersonListRepository = value 753 + // 判断兑换活动清单中现金总金额是否超过平台未兑换现金值
  754 + if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
  755 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
720 } 756 }
721 757
722 - _, people, err := exchangeCashPersonListRepository.Find(map[string]interface{}{ 758 + // 获取该活动所有兑换清单
  759 + _, peopleFound, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
723 "exchangeCashActivityId": updateExchangeCashActivityCommand.ExchangeCashActivityId, 760 "exchangeCashActivityId": updateExchangeCashActivityCommand.ExchangeCashActivityId,
724 }) 761 })
725 if err != nil { 762 if err != nil {
@@ -727,54 +764,45 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -727,54 +764,45 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
727 } 764 }
728 765
729 // 批量更新兑换清单,更新已兑换现金值 766 // 批量更新兑换清单,更新已兑换现金值
730 - for _, person := range people { 767 + for _, personFound := range peopleFound {
  768 + // 更新兑换清单命令
731 updateExchangeCashPerson := &command.UpdateExchangeCashPersonCommand { 769 updateExchangeCashPerson := &command.UpdateExchangeCashPersonCommand {
732 - ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * person.ExchangedSuMoney, 770 + ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * personFound.ExchangedSuMoney,
  771 + ExchangedSuMoney: personFound.ExchangedSuMoney,
733 } 772 }
734 773
735 - if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPerson)); err != nil { 774 + // 更新素币兑换清单
  775 + if err := personFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashPerson)); err != nil {
736 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 776 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
737 } 777 }
738 778
739 - if _, err := exchangeCashPersonListRepository.Save(person);err != nil { 779 + // 保存素币兑换清单更新
  780 + if _, err := exchangeCashPersonListRepository.Save(personFound);err != nil {
740 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 781 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
741 } 782 }
742 } 783 }
743 -  
744 - // 计算系统平均兑换汇率并更新现金池  
745 - var employeeDao *dao.EmployeeDao  
746 - if value, err := factory.CreateEmployeeDao(map[string]interface{}{  
747 - "transactionContext": transactionContext,  
748 - }); err != nil {  
749 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
750 - } else {  
751 - employeeDao = value  
752 - }  
753 -  
754 // 获取平台素币状况 784 // 获取平台素币状况
755 - systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activity.CompanyId) 785 + systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
756 if err != nil { 786 if err != nil {
757 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 787 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
758 } 788 }
759 if systemSuMoneyStatistics == nil { 789 if systemSuMoneyStatistics == nil {
760 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 790 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
761 } 791 }
762 -  
763 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) 792 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
764 793
765 // 获取平台现金状况 794 // 获取平台现金状况
766 - systemCashStatistics, err := employeeDao.CalculateSystemCash(activity.CompanyId) 795 + systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
767 if err != nil { 796 if err != nil {
768 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 797 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
769 } 798 }
770 if systemCashStatistics == nil { 799 if systemCashStatistics == nil {
771 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 800 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
772 } 801 }
773 -  
774 systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64) 802 systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
775 systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64) 803 systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
776 804
777 - // 平均兑换汇率 805 + // 计算平均兑换汇率
778 var rate float64 806 var rate float64
779 if systemExchangedSuMoney == 0 { 807 if systemExchangedSuMoney == 0 {
780 rate = 0 808 rate = 0
@@ -782,19 +810,23 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -782,19 +810,23 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
782 rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) 810 rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
783 } 811 }
784 812
  813 + // 更新现金池命令
785 updateCashPoolCommand := &command.UpdateCashPoolCommand{ 814 updateCashPoolCommand := &command.UpdateCashPoolCommand{
786 - CashPoolId: cashPools[0].CashPoolId,  
787 - ExchangedCash: systemUnExchangeCash, 815 + CashPoolId: cashPoolsFound[0].CashPoolId,
  816 + ExchangedCash: systemUnExchangeCash,
788 UnExchangeCash: systemUnExchangeCash, 817 UnExchangeCash: systemUnExchangeCash,
789 - Rate: rate, 818 + Rate: rate,
790 } 819 }
791 820
  821 + fmt.Printf("更新现金池命令:%+v\n", updateCashPoolCommand)
  822 +
792 // 更新现金池 823 // 更新现金池
793 - if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil { 824 + if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
794 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 825 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
795 } 826 }
796 827
797 - cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0]) 828 + // 保存现金池更新
  829 + cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
798 if err != nil { 830 if err != nil {
799 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 831 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
800 } 832 }
@@ -802,32 +834,35 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -802,32 +834,35 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
802 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 834 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
803 } 835 }
804 836
805 - // 更新兑换活动已兑换现金  
806 - updateExchangeCashActivityCommand.ExchangedCash = updateExchangeCashActivityCommand.ExchangeRate * activity.ExchangedSuMoney  
807 - } else {  
808 - updateExchangeCashActivityCommand.ExchangedCash = activity.ExchangedCash  
809 - } 837 + // 更新兑换活动命令已兑换现金
  838 + updateExchangeCashActivityCommand.ExchangedCash = updateExchangeCashActivityCommand.ExchangeRate * activityFound.ExchangedSuMoney
810 839
811 - var timeNow = time.Now()  
812 - var deadline = updateExchangeCashActivityCommand.Deadline  
813 - var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)  
814 - var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local) 840 + } else { // 未更新兑换活动汇率
  841 + updateExchangeCashActivityCommand.ExchangedCash = activityFound.ExchangedCash
  842 + }
815 843
816 // 计算倒计时 844 // 计算倒计时
  845 + var t1 = time.Now()
  846 + var t2 = activityFound.Deadline
817 updateExchangeCashActivityCommand.CountDown = int64(t2.Sub(t1).Hours() / 24) 847 updateExchangeCashActivityCommand.CountDown = int64(t2.Sub(t1).Hours() / 24)
818 848
819 - // 倒计时结束 849 + // 倒计时结束处理
820 if t2.Before(t1) { 850 if t2.Before(t1) {
821 updateExchangeCashActivityCommand.CountDown = 0 851 updateExchangeCashActivityCommand.CountDown = 0
822 } 852 }
823 853
824 - updateExchangeCashActivityCommand.ExchangedSuMoney = activity.ExchangedSuMoney 854 + // 更新兑换活动命令已兑换素币
  855 + updateExchangeCashActivityCommand.ExchangedSuMoney = activityFound.ExchangedSuMoney
  856 +
  857 + fmt.Printf("更新兑换活动命令:%+v\n", updateExchangeCashActivityCommand)
825 858
826 - if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil { 859 + // 更新兑换活动
  860 + if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
827 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 861 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
828 } 862 }
829 863
830 - if activityUpdated, err := exchangeCashActivityRepository.Save(activity); err != nil { 864 + // 保存兑换活动更新
  865 + if activityUpdated, err := exchangeCashActivityRepository.Save(activityFound); err != nil {
831 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 866 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
832 } else { 867 } else {
833 if err := transactionContext.CommitTransaction(); err != nil { 868 if err := transactionContext.CommitTransaction(); err != nil {
@@ -854,7 +889,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -854,7 +889,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
854 transactionContext.RollbackTransaction() 889 transactionContext.RollbackTransaction()
855 }() 890 }()
856 891
857 - // 获取兑换活动兑换汇率 892 + // 兑换活动仓储初始化
858 var exchangeCashActivityRepository domain.ExchangeActivityRepository 893 var exchangeCashActivityRepository domain.ExchangeActivityRepository
859 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ 894 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
860 "transactionContext": transactionContext, 895 "transactionContext": transactionContext,
@@ -864,16 +899,27 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -864,16 +899,27 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
864 exchangeCashActivityRepository = value 899 exchangeCashActivityRepository = value
865 } 900 }
866 901
867 - activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})  
868 - if err != nil { 902 + // 兑换素币清单仓储初始化
  903 + var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
  904 + if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
  905 + "transactionContext": transactionContext,
  906 + }); err != nil {
869 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 907 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  908 + } else {
  909 + exchangeCashPersonListRepository = value
870 } 910 }
871 911
872 - fmt.Print(activity.Rate, "\n")  
873 -  
874 - rate := activity.Rate 912 + // 现金池仓储初始化
  913 + var cashPoolRepository domain.CashPoolRepository
  914 + if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
  915 + "transactionContext": transactionContext,
  916 + }); err != nil {
  917 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  918 + } else {
  919 + cashPoolRepository = value
  920 + }
875 921
876 - // 根据uid/手机账号判断成员是否存在,素币是否超过本人持有的真实素币 922 + // 员工仓储初始化
877 var employeeRepository domain.EmployeeRepository 923 var employeeRepository domain.EmployeeRepository
878 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{ 924 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
879 "transactionContext": transactionContext, 925 "transactionContext": transactionContext,
@@ -883,7 +929,43 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -883,7 +929,43 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
883 employeeRepository = value 929 employeeRepository = value
884 } 930 }
885 931
886 - // 判断是excel导入还是页面增加 932 + // 现金池DAO初始化
  933 + var cashPoolDao *dao.CashPoolDao
  934 + if value, err := factory.CreateCashPoolDao(map[string]interface{}{
  935 + "transactionContext": transactionContext,
  936 + }); err != nil {
  937 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  938 + } else {
  939 + cashPoolDao = value
  940 + }
  941 +
  942 + // 员工DAO初始化
  943 + var employeeDao *dao.EmployeeDao
  944 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  945 + "transactionContext": transactionContext,
  946 + }); err != nil {
  947 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  948 + } else {
  949 + employeeDao = value
  950 + }
  951 +
  952 + // 操作素币服务初始化
  953 + var operationSuMoneyService service.OperationSuMoneyService
  954 + if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
  955 + "transactionContext": transactionContext,
  956 + }); err != nil {
  957 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  958 + } else {
  959 + operationSuMoneyService = value
  960 + }
  961 +
  962 + // 获取当前兑换清单兑换活动
  963 + activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
  964 + if err != nil {
  965 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  966 + }
  967 +
  968 + // 判断导入方式,页面/Excel
887 getEmployee := map[string]interface{}{} 969 getEmployee := map[string]interface{}{}
888 if createExchangeCashPersonCommand.PersonAccount == "" { 970 if createExchangeCashPersonCommand.PersonAccount == "" {
889 getEmployee = map[string]interface{}{ 971 getEmployee = map[string]interface{}{
@@ -895,62 +977,48 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -895,62 +977,48 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
895 } 977 }
896 } 978 }
897 979
898 - employee, err := employeeRepository.FindOne(getEmployee) 980 + // 判断当前员工是否有效
  981 + employeeFound, err := employeeRepository.FindOne(getEmployee)
899 if err != nil { 982 if err != nil {
900 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 983 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
901 } 984 }
902 - if employee == nil { 985 + if employeeFound == nil {
903 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工") 986 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
904 } 987 }
905 988
906 - if employee.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney { 989 + // 判断该员工兑换的素币是否超过本人持有的素币
  990 + if employeeFound.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {
907 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值") 991 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
908 } 992 }
909 993
910 - // 新增兑换清单  
911 - var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository  
912 - if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{  
913 - "transactionContext": transactionContext,  
914 - }); err != nil {  
915 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
916 - } else {  
917 - exchangeCashPersonListRepository = value  
918 - }  
919 - 994 + // 新增兑换清单命令
920 newPerson := &domain.ExchangeCashPersonList{ 995 newPerson := &domain.ExchangeCashPersonList{
921 EmployeeInfo: &domain.EmployeeInfo{ 996 EmployeeInfo: &domain.EmployeeInfo{
922 - Uid: employee.EmployeeInfo.Uid,  
923 - EmployeeName: employee.EmployeeInfo.EmployeeName,  
924 - EmployeeAccount: employee.EmployeeInfo.EmployeeAccount, 997 + Uid: employeeFound.EmployeeInfo.Uid,
  998 + EmployeeName: employeeFound.EmployeeInfo.EmployeeName,
  999 + EmployeeAccount: employeeFound.EmployeeInfo.EmployeeAccount,
925 }, 1000 },
926 ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId, 1001 ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
927 ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney, 1002 ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
928 - ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney * rate, 1003 + ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
929 } 1004 }
930 1005
931 - person, err := exchangeCashPersonListRepository.Save(newPerson) 1006 + // 保存兑换素币清单
  1007 + personSaved, err := exchangeCashPersonListRepository.Save(newPerson)
932 if err != nil { 1008 if err != nil {
933 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1009 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
934 } 1010 }
935 1011
936 - // 生成素币流水,更新个人素币  
937 - var operationSuMoneyService service.OperationSuMoneyService  
938 - if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{  
939 - "transactionContext": transactionContext,  
940 - }); err != nil {  
941 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
942 - } else {  
943 - operationSuMoneyService = value  
944 - }  
945 - 1012 + // 操作素币命令
946 operationSuMoneyCommand := &command.OperationSuMoneyCommand{ 1013 operationSuMoneyCommand := &command.OperationSuMoneyCommand{
947 - Uid: person.EmployeeInfo.Uid,  
948 - Operator: createExchangeCashPersonCommand.Operator,  
949 - SuMoney: person.ExchangedSuMoney,  
950 - OperationType: 3, 1014 + Uid: employeeFound.EmployeeInfo.Uid,
  1015 + Operator: createExchangeCashPersonCommand.Operator,
  1016 + SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
  1017 + OperationType: 4,
951 OperationDescription: "素币兑换现金", 1018 OperationDescription: "素币兑换现金",
952 } 1019 }
953 1020
  1021 + // 操作素币,生成素币流水
954 task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription) 1022 task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
955 if err != nil { 1023 if err != nil {
956 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1024 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -959,30 +1027,14 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -959,30 +1027,14 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
959 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid))) 1027 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
960 } 1028 }
961 1029
962 - if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{  
963 - "transactionContext": transactionContext,  
964 - }); err != nil {  
965 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
966 - } else {  
967 - exchangeCashActivityRepository = value  
968 - }  
969 -  
970 - // 获取相关兑换活动  
971 - activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})  
972 - if err != nil {  
973 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
974 - }  
975 - if activityFound == nil {  
976 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))  
977 - }  
978 - 1030 + // 更新兑换活动命令
979 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{ 1031 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
980 - ExchangeCashActivityId: person.ExchangeCashActivityId,  
981 - ExchangedSuMoney: activityFound.ExchangedSuMoney + person.ExchangedSuMoney,  
982 - ExchangedCash: activityFound.ExchangedCash + person.ExchangedCash,  
983 - Deadline: activityFound.Deadline,  
984 - CountDown: activityFound.CountDown,  
985 - ExchangeRate: activityFound.Rate, 1032 + ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
  1033 + ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
  1034 + ExchangedCash: activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
  1035 + Deadline: activityFound.Deadline,
  1036 + CountDown: activityFound.CountDown,
  1037 + ExchangeRate: activityFound.Rate,
986 } 1038 }
987 1039
988 // 更新兑换活动 1040 // 更新兑换活动
@@ -990,6 +1042,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -990,6 +1042,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
990 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 1042 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
991 } 1043 }
992 1044
  1045 + // 保存兑换现金活动更新
993 activityUpdated, err := exchangeCashActivityRepository.Save(activityFound) 1046 activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
994 if err != nil { 1047 if err != nil {
995 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1048 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -998,15 +1051,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -998,15 +1051,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
998 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId))) 1051 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
999 } 1052 }
1000 1053
1001 - var cashPoolDao *dao.CashPoolDao  
1002 - if value, err := factory.CreateCashPoolDao(map[string]interface{}{  
1003 - "transactionContext": transactionContext,  
1004 - }); err != nil {  
1005 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
1006 - } else {  
1007 - cashPoolDao = value  
1008 - }  
1009 -  
1010 // 获取兑换活动素币兑换情况 1054 // 获取兑换活动素币兑换情况
1011 activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.CompanyId) 1055 activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.CompanyId)
1012 if err != nil { 1056 if err != nil {
@@ -1015,20 +1059,25 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1015,20 +1059,25 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1015 if activitySuMoneyStatistics == nil { 1059 if activitySuMoneyStatistics == nil {
1016 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业") 1060 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
1017 } 1061 }
1018 -  
1019 activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64) 1062 activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
1020 1063
1021 - // 现金池操作  
1022 - var employeeDao *dao.EmployeeDao  
1023 - if value, err := factory.CreateEmployeeDao(map[string]interface{}{  
1024 - "transactionContext": transactionContext,  
1025 - }); err != nil {  
1026 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
1027 - } else {  
1028 - employeeDao = value 1064 + // 获取当前现金池
  1065 + _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
  1066 + "companyId": activityFound.CompanyId,
  1067 + })
  1068 + if err != nil {
  1069 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1070 + }
  1071 + if len(cashPoolsFound) == 0 {
  1072 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
  1073 + }
  1074 +
  1075 + // 判断兑换活动的现金是否超过现金池未兑换现金
  1076 + if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
  1077 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
1029 } 1078 }
1030 1079
1031 - // 获取平台现金 1080 + // 获取平台现金兑换情
1032 systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId) 1081 systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
1033 if err != nil { 1082 if err != nil {
1034 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1083 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -1036,47 +1085,20 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1036,47 +1085,20 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1036 if systemCashStatistics == nil { 1085 if systemCashStatistics == nil {
1037 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 1086 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
1038 } 1087 }
1039 -  
1040 systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64) 1088 systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
1041 //systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64) 1089 //systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
1042 1090
1043 - // 获取平台素币状况  
1044 - systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activity.CompanyId) 1091 + // 获取平台素币兑换情况
  1092 + systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
1045 if err != nil { 1093 if err != nil {
1046 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1094 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1047 } 1095 }
1048 if systemSuMoneyStatistics == nil { 1096 if systemSuMoneyStatistics == nil {
1049 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 1097 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
1050 } 1098 }
1051 -  
1052 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) 1099 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
1053 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) 1100 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
1054 1101
1055 - var cashPoolRepository domain.CashPoolRepository  
1056 - if value, err := factory.CreateCashPoolRepository(map[string] interface{} {  
1057 - "transactionContext": transactionContext,  
1058 - }); err != nil {  
1059 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1060 - } else {  
1061 - cashPoolRepository = value  
1062 - }  
1063 -  
1064 - // 获取现金池  
1065 - _, cashPools, err := cashPoolRepository.Find(map[string]interface{}{  
1066 - "companyId": activity.CompanyId,  
1067 - })  
1068 - if err != nil {  
1069 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1070 - }  
1071 - if len(cashPools) == 0 {  
1072 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activity.CompanyId)))  
1073 - }  
1074 -  
1075 - // 判断兑换的现金是否超过现金池未兑换现金  
1076 - if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPools[0].UnExchangeCash {  
1077 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")  
1078 - }  
1079 -  
1080 // 计算平均兑换汇率 1102 // 计算平均兑换汇率
1081 var newRate float64 1103 var newRate float64
1082 if systemExchangedSuMoney == 0 { 1104 if systemExchangedSuMoney == 0 {
@@ -1085,21 +1107,23 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1085,21 +1107,23 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1085 newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) 1107 newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
1086 } 1108 }
1087 1109
  1110 + // 更新现金池命令
1088 updateCashPoolCommand := &command.UpdateCashPoolCommand{ 1111 updateCashPoolCommand := &command.UpdateCashPoolCommand{
1089 - CashPoolId: cashPools[0].CashPoolId,  
1090 - ExchangedCash: cashPools[0].ExchangedCash + person.ExchangedCash,  
1091 - ExchangedSuMoney: systemExchangedSuMoney,  
1092 - UnExchangeCash: cashPools[0].UnExchangeCash - person.ExchangedCash, 1112 + CashPoolId: cashPoolsFound[0].CashPoolId,
  1113 + ExchangedCash: cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash,
  1114 + UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personSaved.ExchangedCash,
  1115 + ExchangedSuMoney: systemExchangedSuMoney,
1093 UnExchangeSuMoney: systemUnExchangeSuMoney, 1116 UnExchangeSuMoney: systemUnExchangeSuMoney,
1094 - Rate: newRate, 1117 + Rate: newRate,
1095 } 1118 }
1096 1119
1097 // 更新现金池 1120 // 更新现金池
1098 - if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil { 1121 + if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
1099 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 1122 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
1100 } 1123 }
1101 1124
1102 - cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0]) 1125 + // 保存现金池更新
  1126 + cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
1103 if err != nil { 1127 if err != nil {
1104 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1128 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1105 } 1129 }
@@ -1110,7 +1134,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1110,7 +1134,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1110 if err := transactionContext.CommitTransaction(); err != nil { 1134 if err := transactionContext.CommitTransaction(); err != nil {
1111 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1135 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1112 } 1136 }
1113 - return person, nil 1137 + return personSaved, nil
1114 } 1138 }
1115 1139
1116 // 返回兑换素币清单 1140 // 返回兑换素币清单
@@ -1129,6 +1153,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer @@ -1129,6 +1153,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer
1129 transactionContext.RollbackTransaction() 1153 transactionContext.RollbackTransaction()
1130 }() 1154 }()
1131 1155
  1156 + // 兑换素币清单仓储初始化
1132 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository 1157 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
1133 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ 1158 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
1134 "transactionContext": transactionContext, 1159 "transactionContext": transactionContext,
@@ -1138,17 +1163,18 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer @@ -1138,17 +1163,18 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer
1138 exchangeCashPersonListRepository = value 1163 exchangeCashPersonListRepository = value
1139 } 1164 }
1140 1165
1141 - person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": getExchangeCashPersonQuery.ExchangeCashPersonId}) 1166 + // 获取当前兑换素币清单
  1167 + personFound, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": getExchangeCashPersonQuery.ExchangeCashPersonId})
1142 if err != nil { 1168 if err != nil {
1143 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1169 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1144 } 1170 }
1145 - if person == nil { 1171 + if personFound == nil {
1146 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashPersonQuery.ExchangeCashPersonId))) 1172 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashPersonQuery.ExchangeCashPersonId)))
1147 } else { 1173 } else {
1148 if err := transactionContext.CommitTransaction(); err != nil { 1174 if err := transactionContext.CommitTransaction(); err != nil {
1149 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1175 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1150 } 1176 }
1151 - return person, nil 1177 + return personFound, nil
1152 } 1178 }
1153 } 1179 }
1154 1180
@@ -1168,6 +1194,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP @@ -1168,6 +1194,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP
1168 transactionContext.RollbackTransaction() 1194 transactionContext.RollbackTransaction()
1169 }() 1195 }()
1170 1196
  1197 + // 素币兑换清单仓储初始化
1171 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository 1198 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
1172 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ 1199 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
1173 "transactionContext": transactionContext, 1200 "transactionContext": transactionContext,
@@ -1177,24 +1204,26 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP @@ -1177,24 +1204,26 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP
1177 exchangeCashPersonListRepository = value 1204 exchangeCashPersonListRepository = value
1178 } 1205 }
1179 1206
  1207 + // 兑换素币活动仓储初始化
  1208 + var exchangeActivityRepository domain.ExchangeActivityRepository
  1209 + if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
  1210 + "transactionContext": transactionContext,
  1211 + }); err != nil {
  1212 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1213 + } else {
  1214 + exchangeActivityRepository = value
  1215 + }
  1216 +
1180 // 返回兑换现金活动总榜 1217 // 返回兑换现金活动总榜
1181 if listExchangeCashPersonQuery.ExchangeCashActivityId == 0 && listExchangeCashPersonQuery.CompanyId != 0 { 1218 if listExchangeCashPersonQuery.ExchangeCashActivityId == 0 && listExchangeCashPersonQuery.CompanyId != 0 {
1182 // 找到该公司下的所有活动id 1219 // 找到该公司下的所有活动id
1183 - var exchangeActivityRepository domain.ExchangeActivityRepository  
1184 - if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{  
1185 - "transactionContext": transactionContext,  
1186 - }); err != nil {  
1187 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1188 - } else {  
1189 - exchangeActivityRepository = value  
1190 - }  
1191 -  
1192 if _, activities, err := exchangeActivityRepository.FindAll(map[string]interface{}{ 1220 if _, activities, err := exchangeActivityRepository.FindAll(map[string]interface{}{
1193 "companyId": listExchangeCashPersonQuery.CompanyId, 1221 "companyId": listExchangeCashPersonQuery.CompanyId,
1194 }); err != nil { 1222 }); err != nil {
1195 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1223 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1196 } else { 1224 } else {
1197 var activityIds []int64 1225 var activityIds []int64
  1226 +
1198 for _, activity := range activities { 1227 for _, activity := range activities {
1199 activityIds = append(activityIds, activity.ActivityId) 1228 activityIds = append(activityIds, activity.ActivityId)
1200 } 1229 }
@@ -1209,6 +1238,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP @@ -1209,6 +1238,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP
1209 if err := transactionContext.CommitTransaction(); err != nil { 1238 if err := transactionContext.CommitTransaction(); err != nil {
1210 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1239 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1211 } 1240 }
  1241 +
1212 return map[string]interface{}{ 1242 return map[string]interface{}{
1213 "count": count, 1243 "count": count,
1214 "people": people, 1244 "people": people,
@@ -1306,7 +1336,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1306,7 +1336,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1306 employeeDao = value 1336 employeeDao = value
1307 } 1337 }
1308 1338
1309 - // 获取兑换清单 1339 + // 获取兑换清单员工
1310 personFound, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": updateExchangeCashPersonCommand.ListId}) 1340 personFound, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": updateExchangeCashPersonCommand.ListId})
1311 if err != nil { 1341 if err != nil {
1312 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1342 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -1315,7 +1345,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1315,7 +1345,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1315 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ListId))) 1345 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ListId)))
1316 } 1346 }
1317 1347
1318 - fmt.Printf("Person Found: %+v\n", personFound) 1348 + // 获取兑换清单员工已兑换素币
  1349 + personFoundExchangedSuMoney := personFound.ExchangedSuMoney
1319 1350
1320 // 获取相关兑换活动 1351 // 获取相关兑换活动
1321 activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": personFound.ExchangeCashActivityId}) 1352 activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": personFound.ExchangeCashActivityId})
@@ -1340,13 +1371,11 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1340,13 +1371,11 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1340 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1371 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1341 } 1372 }
1342 1373
1343 - fmt.Printf("Person Updated: %+v\n", personUpdated)  
1344 -  
1345 // 更新素币兑换活动命令 1374 // 更新素币兑换活动命令
1346 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{ 1375 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
1347 ExchangeCashActivityId: personFound.ExchangeCashActivityId, 1376 ExchangeCashActivityId: personFound.ExchangeCashActivityId,
1348 - ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFound.ExchangedSuMoney),  
1349 - ExchangedCash: activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFound.ExchangedSuMoney) * activityFound.Rate, 1377 + ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney),
  1378 + ExchangedCash: activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
1350 Deadline: activityFound.Deadline, 1379 Deadline: activityFound.Deadline,
1351 CountDown: activityFound.CountDown, 1380 CountDown: activityFound.CountDown,
1352 ExchangeRate: activityFound.Rate, 1381 ExchangeRate: activityFound.Rate,
@@ -1363,10 +1392,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1363,10 +1392,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1363 1392
1364 // 判断操作素币类型 1393 // 判断操作素币类型
1365 if updateExchangeCashActivityCommand.ExchangedSuMoney - personUpdated.ExchangedSuMoney > 0 { 1394 if updateExchangeCashActivityCommand.ExchangedSuMoney - personUpdated.ExchangedSuMoney > 0 {
1366 - operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personUpdated.ExchangedSuMoney)  
1367 - operationSuMoneyCommand.OperationType = 1 1395 + operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
  1396 + operationSuMoneyCommand.OperationType = 4
1368 } else { 1397 } else {
1369 - operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personUpdated.ExchangedSuMoney) 1398 + operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
1370 operationSuMoneyCommand.OperationType = 3 1399 operationSuMoneyCommand.OperationType = 3
1371 } 1400 }
1372 1401
@@ -1379,8 +1408,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1379,8 +1408,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1379 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid))) 1408 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
1380 } 1409 }
1381 1410
1382 - fmt.Printf("Activity Found: %+v\n", activityFound)  
1383 -  
1384 // 更新兑换活动 1411 // 更新兑换活动
1385 if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil { 1412 if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
1386 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 1413 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
@@ -1395,8 +1422,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1395,8 +1422,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1395 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId))) 1422 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
1396 } 1423 }
1397 1424
1398 - fmt.Printf("Activity Updated: %+v\n", activityUpdated)  
1399 -  
1400 // 统计活动已兑换素币 1425 // 统计活动已兑换素币
1401 activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityUpdated.ActivityId) 1426 activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityUpdated.ActivityId)
1402 if err != nil { 1427 if err != nil {
@@ -1431,7 +1456,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1431,7 +1456,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1431 1456
1432 // 判断是否超过平台未兑换现金 1457 // 判断是否超过平台未兑换现金
1433 if activitySuMoney * activityUpdated.Rate > systemUnExchangeCash { 1458 if activitySuMoney * activityUpdated.Rate > systemUnExchangeCash {
1434 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金") 1459 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
1435 } 1460 }
1436 1461
1437 // 重新获取系统现金兑换情况 1462 // 重新获取系统现金兑换情况
@@ -1446,13 +1471,13 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1446,13 +1471,13 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1446 //newSystemUnExchangeCash := newSystemCashStatistics["systemUnExchangeCash"].(float64) 1471 //newSystemUnExchangeCash := newSystemCashStatistics["systemUnExchangeCash"].(float64)
1447 1472
1448 // 获取当前现金池 1473 // 获取当前现金池
1449 - _, cashPools, err := cashPoolRepository.Find(map[string]interface{}{ 1474 + _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
1450 "companyId": activityUpdated.CompanyId, 1475 "companyId": activityUpdated.CompanyId,
1451 }) 1476 })
1452 if err != nil { 1477 if err != nil {
1453 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1478 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1454 } 1479 }
1455 - if cashPools == nil { 1480 + if cashPoolsFound == nil {
1456 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId))) 1481 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
1457 } 1482 }
1458 1483
@@ -1464,38 +1489,23 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1464,38 +1489,23 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1464 newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) 1489 newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
1465 } 1490 }
1466 1491
1467 - fmt.Printf("CashPool Found: %+v\n", cashPools[0])  
1468 -  
1469 - fmt.Printf("UpdateExchangeCashPersonCommand: %+v\n", updateExchangeCashPersonCommand)  
1470 -  
1471 - updateExchangedCash := cashPools[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFound.ExchangedSuMoney) * activityUpdated.Rate  
1472 - fmt.Print(updateExchangedCash,"\n")  
1473 -  
1474 - updateUnExchangeCash := cashPools[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - personFound.ExchangedSuMoney) * activityUpdated.Rate  
1475 - fmt.Print(updateUnExchangeCash, "\n")  
1476 -  
1477 - updateExchangedSuMoney := cashPools[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFound.ExchangedSuMoney)  
1478 - fmt.Print(updateExchangedSuMoney, "\n")  
1479 -  
1480 // 更新现金池命令 1492 // 更新现金池命令
1481 updateCashPoolCommand := &command.UpdateCashPoolCommand{ 1493 updateCashPoolCommand := &command.UpdateCashPoolCommand{
1482 - CashPoolId: cashPools[0].CashPoolId,  
1483 - ExchangedCash: updateExchangedCash,  
1484 - UnExchangeCash: updateUnExchangeCash,  
1485 - Rate: newRate,  
1486 - ExchangedSuMoney: updateExchangedSuMoney, 1494 + CashPoolId: cashPoolsFound[0].CashPoolId,
  1495 + ExchangedCash: cashPoolsFound[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
  1496 + UnExchangeCash: cashPoolsFound[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
  1497 + Rate: newRate,
  1498 + ExchangedSuMoney: cashPoolsFound[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney),
1487 UnExchangeSuMoney: systemUnExchangeSuMoney, 1499 UnExchangeSuMoney: systemUnExchangeSuMoney,
1488 } 1500 }
1489 1501
1490 - fmt.Printf("UpdateCashPoolCommand=%+v\n", updateCashPoolCommand)  
1491 -  
1492 // 更新现金池 1502 // 更新现金池
1493 - if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil { 1503 + if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
1494 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 1504 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
1495 } 1505 }
1496 1506
1497 // 保存现金池更新 1507 // 保存现金池更新
1498 - cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0]) 1508 + cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
1499 if err != nil { 1509 if err != nil {
1500 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1510 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1501 } 1511 }
@@ -1503,8 +1513,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1503,8 +1513,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1503 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1513 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1504 } 1514 }
1505 1515
1506 - fmt.Printf("Updated CashPool: %+v\n", cashPoolUpdated)  
1507 -  
1508 if err := transactionContext.CommitTransaction(); err != nil { 1516 if err := transactionContext.CommitTransaction(); err != nil {
1509 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1517 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1510 } 1518 }
@@ -1528,7 +1536,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1528,7 +1536,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1528 transactionContext.RollbackTransaction() 1536 transactionContext.RollbackTransaction()
1529 }() 1537 }()
1530 1538
1531 - // 移除兑换素币清单 1539 + // 兑换素币清单仓储初始化
1532 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository 1540 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
1533 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ 1541 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
1534 "transactionContext": transactionContext, 1542 "transactionContext": transactionContext,
@@ -1538,40 +1546,78 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1538,40 +1546,78 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1538 exchangeCashPersonListRepository = value 1546 exchangeCashPersonListRepository = value
1539 } 1547 }
1540 1548
1541 - // 获取待删除人员  
1542 - person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": removeExchangeCashPersonCommand.ListId})  
1543 - if err != nil { 1549 + // 素币兑换活动仓储初始化
  1550 + var exchangeCashActivityRepository domain.ExchangeActivityRepository
  1551 + if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
  1552 + "transactionContext": transactionContext,
  1553 + }); err != nil {
1544 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1554 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1555 + } else {
  1556 + exchangeCashActivityRepository = value
1545 } 1557 }
1546 - if person == nil {  
1547 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId))) 1558 +
  1559 + // 现金池仓储初始化
  1560 + var cashPoolRepository domain.CashPoolRepository
  1561 + if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
  1562 + "transactionContext": transactionContext,
  1563 + }); err != nil {
  1564 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1565 + } else {
  1566 + cashPoolRepository = value
1548 } 1567 }
1549 1568
1550 - var exchangeCashActivityRepository domain.ExchangeActivityRepository  
1551 - if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ 1569 + // 员工DAO初始化
  1570 + var employeeDao *dao.EmployeeDao
  1571 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  1572 + "transactionContext": transactionContext,
  1573 + }); err != nil {
  1574 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1575 + } else {
  1576 + employeeDao = value
  1577 + }
  1578 +
  1579 + // 操作素币服务初始化
  1580 + var operationSuMoneyService service.OperationSuMoneyService
  1581 + if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
1552 "transactionContext": transactionContext, 1582 "transactionContext": transactionContext,
1553 }); err != nil { 1583 }); err != nil {
1554 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1584 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1555 } else { 1585 } else {
1556 - exchangeCashActivityRepository = value 1586 + operationSuMoneyService = value
  1587 + }
  1588 +
  1589 + // 获取待删除兑换清单人员
  1590 + personFound, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": removeExchangeCashPersonCommand.ListId})
  1591 + if err != nil {
  1592 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1593 + }
  1594 + if personFound == nil {
  1595 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
1557 } 1596 }
1558 1597
  1598 + // 获取兑换清单员工已兑换素币
  1599 + personFoundExchangedSuMoney := personFound.ExchangedSuMoney
  1600 +
  1601 + // 删除兑换清单人员
  1602 + personDeleted, err := exchangeCashPersonListRepository.Remove(personFound)
  1603 +
1559 // 获取相关兑换活动 1604 // 获取相关兑换活动
1560 - activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": person.ExchangeCashActivityId}) 1605 + activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": personFound.ExchangeCashActivityId})
1561 if err != nil { 1606 if err != nil {
1562 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1607 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1563 } 1608 }
1564 if activityFound == nil { 1609 if activityFound == nil {
1565 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(person.ExchangeCashActivityId))) 1610 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(personFound.ExchangeCashActivityId)))
1566 } 1611 }
1567 1612
  1613 + // 更新兑换素币活动命令
1568 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{ 1614 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
1569 - ExchangeCashActivityId: person.ExchangeCashActivityId,  
1570 - ExchangedSuMoney: activityFound.ExchangedSuMoney - person.ExchangedSuMoney,  
1571 - ExchangedCash: activityFound.ExchangedCash - person.ExchangedCash,  
1572 - Deadline: activityFound.Deadline,  
1573 - CountDown: activityFound.CountDown,  
1574 - ExchangeRate: activityFound.Rate, 1615 + ExchangeCashActivityId: personFound.ExchangeCashActivityId,
  1616 + ExchangedSuMoney: activityFound.ExchangedSuMoney - personFoundExchangedSuMoney,
  1617 + ExchangedCash: activityFound.ExchangedCash - personFoundExchangedSuMoney,
  1618 + Deadline: activityFound.Deadline,
  1619 + CountDown: activityFound.CountDown,
  1620 + ExchangeRate: activityFound.Rate,
1575 } 1621 }
1576 1622
1577 // 更新兑换活动 1623 // 更新兑换活动
@@ -1579,6 +1625,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1579,6 +1625,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1579 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 1625 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
1580 } 1626 }
1581 1627
  1628 + // 保存兑换活动更新
1582 activityUpdated, err := exchangeCashActivityRepository.Save(activityFound) 1629 activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
1583 if err != nil { 1630 if err != nil {
1584 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1631 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -1587,24 +1634,16 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1587,24 +1634,16 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1587 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId))) 1634 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
1588 } 1635 }
1589 1636
1590 - // 还原个人素币值,生成素币流水,描述修改成和活动相关  
1591 - var operationSuMoneyService service.OperationSuMoneyService  
1592 - if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{  
1593 - "transactionContext": transactionContext,  
1594 - }); err != nil {  
1595 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1596 - } else {  
1597 - operationSuMoneyService = value  
1598 - }  
1599 - 1637 + // 操作素币命令
1600 operationSuMoneyCommand := &command.OperationSuMoneyCommand{ 1638 operationSuMoneyCommand := &command.OperationSuMoneyCommand{
1601 - Uid: person.EmployeeInfo.Uid,  
1602 - Operator: removeExchangeCashPersonCommand.Operator,  
1603 - SuMoney: person.ExchangedSuMoney,  
1604 - OperationType: 1, // 增加素币 1639 + Uid: personFound.EmployeeInfo.Uid,
  1640 + Operator: removeExchangeCashPersonCommand.Operator,
  1641 + SuMoney: personFoundExchangedSuMoney,
  1642 + OperationType: 1, // 增加素币
1605 OperationDescription: activityFound.ExchangeActivityName + "素币调整", 1643 OperationDescription: activityFound.ExchangeActivityName + "素币调整",
1606 } 1644 }
1607 1645
  1646 + // 操作素币,生成素币流水
1608 task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription) 1647 task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
1609 if err != nil { 1648 if err != nil {
1610 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1649 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -1613,17 +1652,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1613,17 +1652,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1613 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid))) 1652 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
1614 } 1653 }
1615 1654
1616 - // 更新现金池  
1617 - var employeeDao *dao.EmployeeDao  
1618 - if value, err := factory.CreateEmployeeDao(map[string]interface{}{  
1619 - "transactionContext": transactionContext,  
1620 - }); err != nil {  
1621 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
1622 - } else {  
1623 - employeeDao = value  
1624 - }  
1625 -  
1626 - // 获取平台现金状况 1655 + // 获取平台现金兑换情况
1627 systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId) 1656 systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
1628 if err != nil { 1657 if err != nil {
1629 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1658 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -1631,11 +1660,10 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1631,11 +1660,10 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1631 if systemCashStatistics == nil { 1660 if systemCashStatistics == nil {
1632 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 1661 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
1633 } 1662 }
1634 -  
1635 systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64) 1663 systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
1636 //systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64) 1664 //systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
1637 1665
1638 - // 获取平台素币 1666 + // 获取平台素币兑换情
1639 systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId) 1667 systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
1640 if err != nil { 1668 if err != nil {
1641 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1669 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -1643,27 +1671,17 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1643,27 +1671,17 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1643 if systemSuMoneyStatistics == nil { 1671 if systemSuMoneyStatistics == nil {
1644 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 1672 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
1645 } 1673 }
1646 -  
1647 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) 1674 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
1648 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) 1675 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
1649 1676
1650 - var cashPoolRepository domain.CashPoolRepository  
1651 - if value, err := factory.CreateCashPoolRepository(map[string] interface{} {  
1652 - "transactionContext": transactionContext,  
1653 - }); err != nil {  
1654 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1655 - } else {  
1656 - cashPoolRepository = value  
1657 - }  
1658 -  
1659 - // 获取现金池  
1660 - _, cashPools, err := cashPoolRepository.Find(map[string]interface{}{ 1677 + // 获取当前现金池
  1678 + _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
1661 "companyId": activityFound.CompanyId, 1679 "companyId": activityFound.CompanyId,
1662 }) 1680 })
1663 if err != nil { 1681 if err != nil {
1664 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1682 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1665 } 1683 }
1666 - if cashPools == nil { 1684 + if cashPoolsFound == nil {
1667 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId))) 1685 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
1668 } 1686 }
1669 1687
@@ -1675,21 +1693,23 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1675,21 +1693,23 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1675 newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) 1693 newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
1676 } 1694 }
1677 1695
  1696 + // 更新现金池命令
1678 updateCashPoolCommand := &command.UpdateCashPoolCommand{ 1697 updateCashPoolCommand := &command.UpdateCashPoolCommand{
1679 - CashPoolId: cashPools[0].CashPoolId,  
1680 - ExchangedCash: cashPools[0].ExchangedCash - person.ExchangedCash,  
1681 - UnExchangeCash: cashPools[0].UnExchangeCash + person.ExchangedCash,  
1682 - Rate: newRate,  
1683 - ExchangedSuMoney: cashPools[0].ExchangedSuMoney - person.ExchangedSuMoney, 1698 + CashPoolId: cashPoolsFound[0].CashPoolId,
  1699 + ExchangedCash: cashPoolsFound[0].ExchangedCash - personFoundExchangedSuMoney,
  1700 + UnExchangeCash: cashPoolsFound[0].UnExchangeCash + personFoundExchangedSuMoney,
  1701 + Rate: newRate,
  1702 + ExchangedSuMoney: cashPoolsFound[0].ExchangedSuMoney - personFoundExchangedSuMoney,
1684 UnExchangeSuMoney: systemUnExchangeSuMoney, 1703 UnExchangeSuMoney: systemUnExchangeSuMoney,
1685 } 1704 }
1686 1705
1687 // 更新现金池 1706 // 更新现金池
1688 - if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil { 1707 + if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
1689 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 1708 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
1690 } 1709 }
1691 1710
1692 - cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0]) 1711 + // 保存现金池更新
  1712 + cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
1693 if err != nil { 1713 if err != nil {
1694 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1714 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1695 } 1715 }
@@ -1697,7 +1717,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1697,7 +1717,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1697 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1717 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1698 } 1718 }
1699 1719
1700 - personDeleted, err := exchangeCashPersonListRepository.Remove(person)  
1701 if err != nil { 1720 if err != nil {
1702 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1721 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1703 } else { 1722 } else {
@@ -1708,7 +1727,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1708,7 +1727,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1708 } 1727 }
1709 } 1728 }
1710 1729
1711 -// 根据id获取兑换清单 1730 +// 根据员工ids获取兑换清单
1712 func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchangeCashListCommand *command.ExportExchangeCashListCommand) ([]*domain.ExchangeCashPersonList, error) { 1731 func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchangeCashListCommand *command.ExportExchangeCashListCommand) ([]*domain.ExchangeCashPersonList, error) {
1713 if err := exportExchangeCashListCommand.ValidateCommand(); err != nil { 1732 if err := exportExchangeCashListCommand.ValidateCommand(); err != nil {
1714 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 1733 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -1104,8 +1104,8 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask @@ -1104,8 +1104,8 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask
1104 } 1104 }
1105 // TODO 任务返回错误类型 1105 // TODO 任务返回错误类型
1106 if err := task.Update(updateData); err != nil { 1106 if err := task.Update(updateData); err != nil {
1107 - //return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
1108 - return nil, err 1107 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  1108 + //return nil, err
1109 } 1109 }
1110 if task, err := taskRepository.Save(task); err != nil { 1110 if task, err := taskRepository.Save(task); err != nil {
1111 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1111 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -49,9 +49,5 @@ func (cashPool *CashPool) Identity() interface{} { @@ -49,9 +49,5 @@ func (cashPool *CashPool) Identity() interface{} {
49 return nil 49 return nil
50 } 50 }
51 return cashPool.CashPoolId 51 return cashPool.CashPoolId
52 - //if cashPool.CompanyId == 0 {  
53 - // return nil  
54 - //}  
55 - //return cashPool.CompanyId  
56 } 52 }
57 53
@@ -140,7 +140,7 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{ @@ -140,7 +140,7 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{
140 }, nil 140 }, nil
141 } 141 }
142 142
143 -// 计算系统已兑换素币、未兑换素币 143 +// 计算系统已兑换现金素币、未兑换素币
144 func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] interface{}, error) { 144 func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] interface{}, error) {
145 var systemUnExchangeSuMoney float64 145 var systemUnExchangeSuMoney float64
146 var systemExchangedSuMoney float64 146 var systemExchangedSuMoney float64
@@ -157,7 +157,7 @@ func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] int @@ -157,7 +157,7 @@ func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] int
157 // 系统已兑换现金素币 157 // 系统已兑换现金素币
158 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 158 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
159 if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint"). 159 if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
160 - ColumnExpr("sum(su_money_transaction_record.su_money) AS system_changed_su_money"). 160 + ColumnExpr("sum(su_money_transaction_record.su_money) AS system_exchanged_su_money").
161 Where("e.company_id = ?", companyId). 161 Where("e.company_id = ?", companyId).
162 Where("e.status = ?", 1). 162 Where("e.status = ?", 1).
163 Where(`su_money_transaction_record.record_type = ?`, 5). 163 Where(`su_money_transaction_record.record_type = ?`, 5).
@@ -343,6 +343,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -343,6 +343,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
343 EmployeesContributions float64 343 EmployeesContributions float64
344 Ranking int 344 Ranking int
345 } 345 }
  346 +
346 tx := dao.transactionContext.PgTx 347 tx := dao.transactionContext.PgTx
347 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 348 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
348 349
@@ -65,10 +65,14 @@ func (service *OperationSuMoneyService) Operation(uid int64, operatorUid int64, @@ -65,10 +65,14 @@ func (service *OperationSuMoneyService) Operation(uid int64, operatorUid int64,
65 recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_DEDUCT 65 recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_DEDUCT
66 transferSuMoney = 0 - suMoney 66 transferSuMoney = 0 - suMoney
67 } 67 }
68 - if operationType == 3 { // 兑换 68 + if operationType == 3 { // 兑换物资
69 recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE 69 recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE
70 transferSuMoney = 0 - suMoney 70 transferSuMoney = 0 - suMoney
71 } 71 }
  72 + if operationType == 4 { // 兑换现金
  73 + recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH
  74 + transferSuMoney = 0 - suMoney
  75 + }
72 suMoneyTransactionRecord := &domain.SuMoneyTransactionRecord{ 76 suMoneyTransactionRecord := &domain.SuMoneyTransactionRecord{
73 RecordType: recordType, 77 RecordType: recordType,
74 Employee: employee.EmployeeInfo, 78 Employee: employee.EmployeeInfo,
@@ -106,6 +106,7 @@ func (repository *CashPoolRepository) transformPgModelToDomainModel(cashPoolMode @@ -106,6 +106,7 @@ func (repository *CashPoolRepository) transformPgModelToDomainModel(cashPoolMode
106 ExchangedSuMoney: cashPoolModel.ExchangedSuMoney, 106 ExchangedSuMoney: cashPoolModel.ExchangedSuMoney,
107 UnExchangeSuMoney: cashPoolModel.UnExchangeSuMoney, 107 UnExchangeSuMoney: cashPoolModel.UnExchangeSuMoney,
108 Rate: cashPoolModel.Rate, 108 Rate: cashPoolModel.Rate,
  109 + LastRate: cashPoolModel.LastRate,
109 CreateTime: cashPoolModel.CreateTime, 110 CreateTime: cashPoolModel.CreateTime,
110 }, nil 111 }, nil
111 } 112 }