作者 陈志颖

refactor:优化现金池

@@ -358,18 +358,16 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc @@ -358,18 +358,16 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc
358 for _, activity := range activities { 358 for _, activity := range activities {
359 deadlines = append(deadlines, activity.Deadline.Format("2006-01-02")) 359 deadlines = append(deadlines, activity.Deadline.Format("2006-01-02"))
360 } 360 }
361 -  
362 if len(deadlines) == 0 { 361 if len(deadlines) == 0 {
363 deadlines = []interface{}{} 362 deadlines = []interface{}{}
364 } 363 }
365 -  
366 return map[string]interface{}{ 364 return map[string]interface{}{
367 "deadlines": deadlines, 365 "deadlines": deadlines,
368 }, nil 366 }, nil
369 } 367 }
370 } 368 }
371 369
372 -// 搜索兑换现金活动 370 +// 搜索兑换现金活动 for PC
373 func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityCommand *command.SearchExchangeCashActivityCommand) (interface{}, error) { 371 func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityCommand *command.SearchExchangeCashActivityCommand) (interface{}, error) {
374 if err := activityCommand.ValidateCommand(); err != nil { 372 if err := activityCommand.ValidateCommand(); err != nil {
375 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 373 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -434,7 +432,6 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma @@ -434,7 +432,6 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma
434 if err := transactionContext.CommitTransaction(); err != nil { 432 if err := transactionContext.CommitTransaction(); err != nil {
435 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 433 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
436 } 434 }
437 -  
438 return map[string]interface{}{ 435 return map[string]interface{}{
439 "count": count, 436 "count": count,
440 "activities": activities, 437 "activities": activities,
@@ -442,7 +439,7 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma @@ -442,7 +439,7 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma
442 } 439 }
443 } 440 }
444 441
445 -// 返回兑换现金活动列表 442 +// 返回兑换现金活动列表 for app
446 func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCashActivityQuery *query.ListExchangeCashActivityQuery) (interface{}, error) { 443 func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCashActivityQuery *query.ListExchangeCashActivityQuery) (interface{}, error) {
447 if err := listExchangeCashActivityQuery.ValidateQuery(); err != nil { 444 if err := listExchangeCashActivityQuery.ValidateQuery(); err != nil {
448 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 445 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -476,7 +473,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas @@ -476,7 +473,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
476 var t1 = time.Now() 473 var t1 = time.Now()
477 var t2 = activity.Deadline 474 var t2 = activity.Deadline
478 475
479 - // 更新兑换现金活动命令 476 + // 更新兑换现金活动倒计时命令
480 updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand { 477 updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
481 ExchangeCashActivityId: activity.ActivityId, 478 ExchangeCashActivityId: activity.ActivityId,
482 CountDown: int64(t2.Sub(t1).Hours() / 24), // 重新计算活动倒计时 479 CountDown: int64(t2.Sub(t1).Hours() / 24), // 重新计算活动倒计时
@@ -489,15 +486,14 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas @@ -489,15 +486,14 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
489 // 倒计时结束处理 486 // 倒计时结束处理
490 if t2.Before(t1) { 487 if t2.Before(t1) {
491 updateExchangeCashActivity.CountDown = 0 488 updateExchangeCashActivity.CountDown = 0
492 - updateExchangeCashActivity.Deadline = activity.Deadline  
493 } 489 }
494 490
495 - // 更新兑换现金活动 491 + // 更新兑换现金活动倒计时
496 if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil { 492 if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
497 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 493 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
498 } 494 }
499 495
500 - // 保存兑换现金活动更新 496 + // 保存兑换现金活动倒计时更新
501 _, err := exchangeActivityRepository.Save(activity) 497 _, err := exchangeActivityRepository.Save(activity)
502 if err != nil { 498 if err != nil {
503 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 499 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -524,7 +520,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas @@ -524,7 +520,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
524 } 520 }
525 activitiesWithTs = append(activitiesWithTs, activityWithTs) 521 activitiesWithTs = append(activitiesWithTs, activityWithTs)
526 } 522 }
527 -  
528 return map[string]interface{}{ 523 return map[string]interface{}{
529 "count": count, 524 "count": count,
530 "activities": activitiesWithTs, 525 "activities": activitiesWithTs,
@@ -699,14 +694,14 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -699,14 +694,14 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
699 } 694 }
700 695
701 // 现金池DAO初始化 696 // 现金池DAO初始化
702 - var cashPoolDao *dao.CashPoolDao  
703 - if value, err := factory.CreateCashPoolDao(map[string]interface{}{  
704 - "transactionContext": transactionContext,  
705 - }); err != nil {  
706 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
707 - } else {  
708 - cashPoolDao = value  
709 - } 697 + //var cashPoolDao *dao.CashPoolDao
  698 + //if value, err := factory.CreateCashPoolDao(map[string]interface{}{
  699 + // "transactionContext": transactionContext,
  700 + //}); err != nil {
  701 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  702 + //} else {
  703 + // cashPoolDao = value
  704 + //}
710 705
711 // 员工DAO初始化 706 // 员工DAO初始化
712 var employeeDao *dao.EmployeeDao 707 var employeeDao *dao.EmployeeDao
@@ -728,15 +723,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -728,15 +723,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
728 } 723 }
729 724
730 if updateExchangeCashActivityCommand.ExchangeRate != 0 { // 更新兑换活动兑换汇率 725 if updateExchangeCashActivityCommand.ExchangeRate != 0 { // 更新兑换活动兑换汇率
731 - //// 增大汇率  
732 - //if updateExchangeCashActivityCommand.ExchangeRate > activityFound.Rate {  
733 - //  
734 - //}  
735 - //  
736 - //// 减小汇率  
737 - //if updateExchangeCashActivityCommand.ExchangeRate < activityFound.Rate {  
738 - //  
739 - //}  
740 // 获取当前公司现金池 726 // 获取当前公司现金池
741 _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{ 727 _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
742 "companyId": activityFound.CompanyId, 728 "companyId": activityFound.CompanyId,
@@ -749,18 +735,18 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -749,18 +735,18 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
749 } 735 }
750 736
751 // 获取活动素币统计 737 // 获取活动素币统计
752 - activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.ActivityId)  
753 - if err != nil {  
754 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
755 - }  
756 - if activitySuMoneyStatistics == nil {  
757 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")  
758 - }  
759 - activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64) 738 + //activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.ActivityId)
  739 + //if err != nil {
  740 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  741 + //}
  742 + //if activitySuMoneyStatistics == nil {
  743 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
  744 + //}
  745 + //activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
760 746
761 // 判断兑换活动清单中现金总金额是否超过平台未兑换现金值 747 // 判断兑换活动清单中现金总金额是否超过平台未兑换现金值
762 - if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {  
763 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金") 748 + if activityFound.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
  749 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
764 } 750 }
765 751
766 // 获取该活动所有兑换清单 752 // 获取该活动所有兑换清单
@@ -776,9 +762,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -776,9 +762,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
776 personFoundExchangedSuMoney := personFound.ExchangedSuMoney 762 personFoundExchangedSuMoney := personFound.ExchangedSuMoney
777 763
778 // 更新兑换清单命令 764 // 更新兑换清单命令
779 - updateExchangeCashActivityExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", updateExchangeCashActivityCommand.ExchangeRate * personFoundExchangedSuMoney), 64) 765 + //updateExchangeCashActivityExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", updateExchangeCashActivityCommand.ExchangeRate * personFoundExchangedSuMoney), 64)
780 updateExchangeCashPerson := &command.UpdateExchangeCashPersonCommand { 766 updateExchangeCashPerson := &command.UpdateExchangeCashPersonCommand {
781 - ExchangedCash: updateExchangeCashActivityExchangedCash, 767 + ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * personFoundExchangedSuMoney,
782 ExchangedSuMoney: personFoundExchangedSuMoney, 768 ExchangedSuMoney: personFoundExchangedSuMoney,
783 } 769 }
784 770
@@ -805,32 +791,32 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -805,32 +791,32 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
805 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) 791 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
806 792
807 // 获取平台现金状况 793 // 获取平台现金状况
808 - systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)  
809 - if err != nil {  
810 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
811 - }  
812 - if systemCashStatistics == nil {  
813 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")  
814 - }  
815 - systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)  
816 - systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64) 794 + //systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
  795 + //if err != nil {
  796 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  797 + //}
  798 + //if systemCashStatistics == nil {
  799 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
  800 + //}
  801 + //systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
  802 + //systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
817 803
818 // 更新兑换活动命令已兑换现金 804 // 更新兑换活动命令已兑换现金
819 - updateExchangeCashActivityCommand.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", updateExchangeCashActivityCommand.ExchangeRate * activityFound.ExchangedSuMoney), 64) 805 + updateExchangeCashActivityCommand.ExchangedCash = updateExchangeCashActivityCommand.ExchangeRate * activityFound.ExchangedSuMoney
820 806
821 // 计算平均兑换汇率 807 // 计算平均兑换汇率
822 var rate float64 808 var rate float64
823 if systemExchangedSuMoney == 0 { 809 if systemExchangedSuMoney == 0 {
824 rate = 0 810 rate = 0
825 } else { 811 } else {
826 - rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (systemExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash)) / systemExchangedSuMoney), 64) 812 + rate = (cashPoolsFound[0].ExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash)) / systemExchangedSuMoney
827 } 813 }
828 814
829 // 更新现金池命令 815 // 更新现金池命令
830 updateCashPoolCommand := &command.UpdateCashPoolCommand{ 816 updateCashPoolCommand := &command.UpdateCashPoolCommand{
831 CashPoolId: cashPoolsFound[0].CashPoolId, 817 CashPoolId: cashPoolsFound[0].CashPoolId,
832 - ExchangedCash: systemExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash),  
833 - UnExchangeCash: systemUnExchangeCash - (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash) , 818 + ExchangedCash: cashPoolsFound[0].ExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash),
  819 + UnExchangeCash: cashPoolsFound[0].UnExchangeCash - (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash) ,
834 ExchangedSuMoney: systemExchangedSuMoney, 820 ExchangedSuMoney: systemExchangedSuMoney,
835 UnExchangeSuMoney: systemUnExchangeSuMoney, 821 UnExchangeSuMoney: systemUnExchangeSuMoney,
836 Rate: rate, 822 Rate: rate,
@@ -865,7 +851,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -865,7 +851,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
865 } 851 }
866 852
867 // 更新兑换活动命令已兑换素币 853 // 更新兑换活动命令已兑换素币
868 - updateExchangeCashActivityCommand.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityFound.ExchangedSuMoney), 64) 854 + updateExchangeCashActivityCommand.ExchangedSuMoney = activityFound.ExchangedSuMoney
869 855
870 // 更新兑换活动 856 // 更新兑换活动
871 if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil { 857 if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
@@ -939,15 +925,15 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -939,15 +925,15 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
939 employeeRepository = value 925 employeeRepository = value
940 } 926 }
941 927
942 - // 现金池DAO初始化  
943 - var cashPoolDao *dao.CashPoolDao  
944 - if value, err := factory.CreateCashPoolDao(map[string]interface{}{  
945 - "transactionContext": transactionContext,  
946 - }); err != nil {  
947 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
948 - } else {  
949 - cashPoolDao = value  
950 - } 928 + //// 现金池DAO初始化
  929 + //var cashPoolDao *dao.CashPoolDao
  930 + //if value, err := factory.CreateCashPoolDao(map[string]interface{}{
  931 + // "transactionContext": transactionContext,
  932 + //}); err != nil {
  933 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  934 + //} else {
  935 + // cashPoolDao = value
  936 + //}
951 937
952 // 员工DAO初始化 938 // 员工DAO初始化
953 var employeeDao *dao.EmployeeDao 939 var employeeDao *dao.EmployeeDao
@@ -1003,9 +989,19 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1003,9 +989,19 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1003 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值") 989 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
1004 } 990 }
1005 991
1006 - newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64) 992 + // 判断当前员工是否已经在素币兑换清单中
  993 + employeeExist, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{
  994 + "uid": employeeFound.EmployeeInfo.Uid,
  995 + })
  996 + if err != nil {
  997 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  998 + }
  999 + if employeeExist != nil {
  1000 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前员工已经在素币兑换清单中")
  1001 + }
1007 1002
1008 // 新增兑换清单命令 1003 // 新增兑换清单命令
  1004 + newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)
1009 newPerson := &domain.ExchangeCashPersonList{ 1005 newPerson := &domain.ExchangeCashPersonList{
1010 EmployeeInfo: &domain.EmployeeInfo{ 1006 EmployeeInfo: &domain.EmployeeInfo{
1011 Uid: employeeFound.EmployeeInfo.Uid, 1007 Uid: employeeFound.EmployeeInfo.Uid,
@@ -1041,14 +1037,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1041,14 +1037,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1041 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid))) 1037 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
1042 } 1038 }
1043 1039
1044 - updateExchangeCashActivityExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)  
1045 -  
1046 // 更新兑换活动命令 1040 // 更新兑换活动命令
1047 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{ 1041 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
1048 ExchangeCashActivityId: personSaved.ExchangeCashActivityId, 1042 ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
1049 ExchangeActivityName: activityFound.ExchangeActivityName, 1043 ExchangeActivityName: activityFound.ExchangeActivityName,
1050 ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney, 1044 ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
1051 - ExchangedCash: updateExchangeCashActivityExchangedCash, 1045 + ExchangedCash: activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
1052 Deadline: activityFound.Deadline, 1046 Deadline: activityFound.Deadline,
1053 CountDown: activityFound.CountDown, 1047 CountDown: activityFound.CountDown,
1054 ExchangeRate: activityFound.Rate, 1048 ExchangeRate: activityFound.Rate,
@@ -1069,14 +1063,14 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1069,14 +1063,14 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1069 } 1063 }
1070 1064
1071 // 获取兑换活动素币兑换情况 1065 // 获取兑换活动素币兑换情况
1072 - activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.ActivityId)  
1073 - if err != nil {  
1074 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1075 - }  
1076 - if activitySuMoneyStatistics == nil {  
1077 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")  
1078 - }  
1079 - activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64) 1066 + //activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.ActivityId)
  1067 + //if err != nil {
  1068 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1069 + //}
  1070 + //if activitySuMoneyStatistics == nil {
  1071 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
  1072 + //}
  1073 + //activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
1080 1074
1081 // 获取当前现金池 1075 // 获取当前现金池
1082 _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{ 1076 _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
@@ -1090,7 +1084,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1090,7 +1084,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1090 } 1084 }
1091 1085
1092 // 判断兑换活动的现金是否超过现金池未兑换现金 1086 // 判断兑换活动的现金是否超过现金池未兑换现金
1093 - if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash { 1087 + if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
1094 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金") 1088 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
1095 } 1089 }
1096 1090
@@ -1121,18 +1115,15 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1121,18 +1115,15 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1121 if systemExchangedSuMoney == 0 { 1115 if systemExchangedSuMoney == 0 {
1122 newRate = 0 1116 newRate = 0
1123 } else { 1117 } else {
1124 - newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney), 64) 1118 + newRate = (cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney
1125 } 1119 }
1126 1120
1127 - updateCashPoolExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash), 64)  
1128 - updateCashPoolUnExchangeCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cashPoolsFound[0].UnExchangeCash - personSaved.ExchangedCash), 64)  
1129 -  
1130 // 更新现金池命令 1121 // 更新现金池命令
1131 updateCashPoolCommand := &command.UpdateCashPoolCommand{ 1122 updateCashPoolCommand := &command.UpdateCashPoolCommand{
1132 CashPoolId: cashPoolsFound[0].CashPoolId, 1123 CashPoolId: cashPoolsFound[0].CashPoolId,
1133 Cash: cashPoolsFound[0].Cash, 1124 Cash: cashPoolsFound[0].Cash,
1134 - ExchangedCash: updateCashPoolExchangedCash,  
1135 - UnExchangeCash: updateCashPoolUnExchangeCash, 1125 + ExchangedCash: cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash,
  1126 + UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personSaved.ExchangedCash,
1136 ExchangedSuMoney: systemExchangedSuMoney, 1127 ExchangedSuMoney: systemExchangedSuMoney,
1137 UnExchangeSuMoney: systemUnExchangeSuMoney, 1128 UnExchangeSuMoney: systemUnExchangeSuMoney,
1138 Rate: newRate, 1129 Rate: newRate,
@@ -1338,15 +1329,15 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1338,15 +1329,15 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1338 operationSuMoneyService = value 1329 operationSuMoneyService = value
1339 } 1330 }
1340 1331
1341 - // 现金池DAO初始化  
1342 - var cashPoolDao *dao.CashPoolDao  
1343 - if value, err := factory.CreateCashPoolDao(map[string]interface{}{  
1344 - "transactionContext": transactionContext,  
1345 - }); err != nil {  
1346 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
1347 - } else {  
1348 - cashPoolDao = value  
1349 - } 1332 + //// 现金池DAO初始化
  1333 + //var cashPoolDao *dao.CashPoolDao
  1334 + //if value, err := factory.CreateCashPoolDao(map[string]interface{}{
  1335 + // "transactionContext": transactionContext,
  1336 + //}); err != nil {
  1337 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1338 + //} else {
  1339 + // cashPoolDao = value
  1340 + //}
1350 1341
1351 // 用户DAO初始化 1342 // 用户DAO初始化
1352 var employeeDao *dao.EmployeeDao 1343 var employeeDao *dao.EmployeeDao
@@ -1380,7 +1371,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1380,7 +1371,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1380 } 1371 }
1381 1372
1382 // 更新兑换清单,个人已兑换现金计算 1373 // 更新兑换清单,个人已兑换现金计算
1383 - updateExchangeCashPersonCommand.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64) 1374 + updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
1384 1375
1385 // 更新兑换素币清单 1376 // 更新兑换素币清单
1386 if err := personFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil { 1377 if err := personFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
@@ -1393,13 +1384,11 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1393,13 +1384,11 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1393 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1384 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1394 } 1385 }
1395 1386
1396 - updateActivityExchangeCash ,_ := strconv.ParseFloat(fmt.Sprintf("%.2f", activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate), 64)  
1397 -  
1398 // 更新素币兑换活动命令 1387 // 更新素币兑换活动命令
1399 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{ 1388 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
1400 ExchangeCashActivityId: personFound.ExchangeCashActivityId, 1389 ExchangeCashActivityId: personFound.ExchangeCashActivityId,
1401 ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney), 1390 ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney),
1402 - ExchangedCash: updateActivityExchangeCash, 1391 + ExchangedCash: activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
1403 Deadline: activityFound.Deadline, 1392 Deadline: activityFound.Deadline,
1404 CountDown: activityFound.CountDown, 1393 CountDown: activityFound.CountDown,
1405 ExchangeRate: activityFound.Rate, 1394 ExchangeRate: activityFound.Rate,
@@ -1415,12 +1404,12 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1415,12 +1404,12 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1415 } 1404 }
1416 1405
1417 // 判断操作素币类型 1406 // 判断操作素币类型
1418 - if updateExchangeCashActivityCommand.ExchangedSuMoney - personUpdated.ExchangedSuMoney > 0 { 1407 + if updateExchangeCashActivityCommand.ExchangedSuMoney - personFound.ExchangedSuMoney > 0 { // 追加素币兑换
1419 operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personFoundExchangedSuMoney) 1408 operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
1420 operationSuMoneyCommand.OperationType = 4 1409 operationSuMoneyCommand.OperationType = 4
1421 - } else { 1410 + } else { // 撤回素币兑换
1422 operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personFoundExchangedSuMoney) 1411 operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
1423 - operationSuMoneyCommand.OperationType = 3 1412 + operationSuMoneyCommand.OperationType = 41
1424 } 1413 }
1425 1414
1426 // 操作素币并生成素币流水 1415 // 操作素币并生成素币流水
@@ -1446,26 +1435,26 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1446,26 +1435,26 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1446 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId))) 1435 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
1447 } 1436 }
1448 1437
1449 - // 统计活动已兑换素币  
1450 - activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityUpdated.ActivityId)  
1451 - if err != nil {  
1452 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1453 - }  
1454 - if activitySuMoneyStatistics == nil {  
1455 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")  
1456 - }  
1457 - activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64) 1438 + //// 统计活动已兑换素币
  1439 + //activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityUpdated.ActivityId)
  1440 + //if err != nil {
  1441 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1442 + //}
  1443 + //if activitySuMoneyStatistics == nil {
  1444 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
  1445 + //}
  1446 + //activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
1458 1447
1459 - // 统计平台现金兑换情况  
1460 - systemCashStatistics, err := employeeDao.CalculateSystemCash(activityUpdated.CompanyId)  
1461 - if err != nil {  
1462 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1463 - }  
1464 - if systemCashStatistics == nil {  
1465 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")  
1466 - }  
1467 - //systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)  
1468 - systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64) 1448 + //// 统计平台现金兑换情况
  1449 + //systemCashStatistics, err := employeeDao.CalculateSystemCash(activityUpdated.CompanyId)
  1450 + //if err != nil {
  1451 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1452 + //}
  1453 + //if systemCashStatistics == nil {
  1454 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
  1455 + //}
  1456 + ////systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
  1457 + //systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
1469 1458
1470 // 统计平台素币兑换状况 1459 // 统计平台素币兑换状况
1471 systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityUpdated.CompanyId) 1460 systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityUpdated.CompanyId)
@@ -1475,14 +1464,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1475,14 +1464,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1475 if systemSuMoneyStatistics == nil { 1464 if systemSuMoneyStatistics == nil {
1476 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 1465 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
1477 } 1466 }
1478 - //systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) 1467 + systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
1479 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) 1468 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
1480 1469
1481 - // 判断是否超过平台未兑换现金  
1482 - if activitySuMoney * activityUpdated.Rate > systemUnExchangeCash {  
1483 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")  
1484 - }  
1485 -  
1486 // 获取当前现金池 1470 // 获取当前现金池
1487 _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{ 1471 _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
1488 "companyId": activityUpdated.CompanyId, 1472 "companyId": activityUpdated.CompanyId,
@@ -1494,25 +1478,28 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1494,25 +1478,28 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1494 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId))) 1478 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
1495 } 1479 }
1496 1480
1497 - systemExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cashPoolsFound[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate), 64)  
1498 - systemExchangedSuMoney := cashPoolsFound[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) 1481 + // 判断是否超过平台未兑换现金
  1482 + if activityUpdated.ExchangedSuMoney * activityUpdated.Rate > cashPoolsFound[0].UnExchangeCash {
  1483 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
  1484 + }
  1485 +
  1486 + systemExchangedCash := cashPoolsFound[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityUpdated.Rate
  1487 + //systemExchangedSuMoney := cashPoolsFound[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
1499 1488
1500 // 计算现金池平均兑换汇率 1489 // 计算现金池平均兑换汇率
1501 var newRate float64 1490 var newRate float64
1502 if systemExchangedSuMoney == 0 { 1491 if systemExchangedSuMoney == 0 {
1503 newRate = 0 1492 newRate = 0
1504 } else { 1493 } else {
1505 - newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) 1494 + newRate = systemExchangedCash / systemExchangedSuMoney
1506 } 1495 }
1507 1496
1508 - updateCashPoolUnExchangeCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cashPoolsFound[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate), 64)  
1509 -  
1510 // 更新现金池命令 1497 // 更新现金池命令
1511 updateCashPoolCommand := &command.UpdateCashPoolCommand{ 1498 updateCashPoolCommand := &command.UpdateCashPoolCommand{
1512 CashPoolId: cashPoolsFound[0].CashPoolId, 1499 CashPoolId: cashPoolsFound[0].CashPoolId,
1513 Cash: cashPoolsFound[0].Cash, 1500 Cash: cashPoolsFound[0].Cash,
1514 ExchangedCash: systemExchangedCash, 1501 ExchangedCash: systemExchangedCash,
1515 - UnExchangeCash: updateCashPoolUnExchangeCash, 1502 + UnExchangeCash: cashPoolsFound[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityUpdated.Rate,
1516 Rate: newRate, 1503 Rate: newRate,
1517 ExchangedSuMoney: systemExchangedSuMoney, 1504 ExchangedSuMoney: systemExchangedSuMoney,
1518 UnExchangeSuMoney: systemUnExchangeSuMoney, 1505 UnExchangeSuMoney: systemUnExchangeSuMoney,
@@ -1618,9 +1605,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1618,9 +1605,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1618 // 获取兑换清单员工已兑换素币 1605 // 获取兑换清单员工已兑换素币
1619 personFoundExchangedSuMoney := personFound.ExchangedSuMoney 1606 personFoundExchangedSuMoney := personFound.ExchangedSuMoney
1620 1607
1621 - // 删除兑换清单人员  
1622 - personDeleted, err := exchangeCashPersonListRepository.Remove(personFound)  
1623 -  
1624 // 获取相关兑换活动 1608 // 获取相关兑换活动
1625 activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": personFound.ExchangeCashActivityId}) 1609 activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": personFound.ExchangeCashActivityId})
1626 if err != nil { 1610 if err != nil {
@@ -1659,8 +1643,8 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1659,8 +1643,8 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1659 Uid: personFound.EmployeeInfo.Uid, 1643 Uid: personFound.EmployeeInfo.Uid,
1660 Operator: removeExchangeCashPersonCommand.Operator, 1644 Operator: removeExchangeCashPersonCommand.Operator,
1661 SuMoney: personFoundExchangedSuMoney, 1645 SuMoney: personFoundExchangedSuMoney,
1662 - OperationType: 1, // 增加素币  
1663 - OperationDescription: activityFound.ExchangeActivityName + "素币调整", 1646 + OperationType: 41, // 删除兑换素币清单,撤回已兑换素币
  1647 + OperationDescription: "删除兑换素币清单",
1664 } 1648 }
1665 1649
1666 // 操作素币,生成素币流水 1650 // 操作素币,生成素币流水
@@ -1710,7 +1694,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1710,7 +1694,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1710 if systemExchangedSuMoney == 0 { 1694 if systemExchangedSuMoney == 0 {
1711 newRate = 0 1695 newRate = 0
1712 } else { 1696 } else {
1713 - newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (cashPoolsFound[0].ExchangedCash - personFoundExchangedSuMoney) / systemExchangedSuMoney), 64) 1697 + newRate = (cashPoolsFound[0].ExchangedCash - personFoundExchangedSuMoney) / systemExchangedSuMoney
1714 } 1698 }
1715 1699
1716 // 更新现金池命令 1700 // 更新现金池命令
@@ -1719,7 +1703,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1719,7 +1703,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1719 ExchangedCash: cashPoolsFound[0].ExchangedCash - personFoundExchangedSuMoney, 1703 ExchangedCash: cashPoolsFound[0].ExchangedCash - personFoundExchangedSuMoney,
1720 UnExchangeCash: cashPoolsFound[0].UnExchangeCash + personFoundExchangedSuMoney, 1704 UnExchangeCash: cashPoolsFound[0].UnExchangeCash + personFoundExchangedSuMoney,
1721 Rate: newRate, 1705 Rate: newRate,
1722 - ExchangedSuMoney: cashPoolsFound[0].ExchangedSuMoney - personFoundExchangedSuMoney, 1706 + ExchangedSuMoney: systemExchangedSuMoney,
1723 UnExchangeSuMoney: systemUnExchangeSuMoney, 1707 UnExchangeSuMoney: systemUnExchangeSuMoney,
1724 } 1708 }
1725 1709
@@ -1737,6 +1721,9 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1737,6 +1721,9 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1737 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1721 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1738 } 1722 }
1739 1723
  1724 + // 删除兑换清单人员
  1725 + personDeleted, err := exchangeCashPersonListRepository.Remove(personFound)
  1726 +
1740 if err != nil { 1727 if err != nil {
1741 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1728 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1742 } else { 1729 } else {
1 package domain 1 package domain
2 2
3 -import "time" 3 +import (
  4 + "fmt"
  5 + "strconv"
  6 + "time"
  7 +)
4 8
5 // 现金池 9 // 现金池
6 type CashPool struct { 10 type CashPool struct {
@@ -27,19 +31,19 @@ func (cashPool *CashPool) Update(data map[string]interface{}) error { @@ -27,19 +31,19 @@ func (cashPool *CashPool) Update(data map[string]interface{}) error {
27 cashPool.Cash = cash.(float64) 31 cashPool.Cash = cash.(float64)
28 } 32 }
29 if exchangedCash, ok := data["exchangedCash"]; ok { 33 if exchangedCash, ok := data["exchangedCash"]; ok {
30 - cashPool.ExchangedCash = exchangedCash.(float64) 34 + cashPool.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangedCash.(float64)), 64)
31 } 35 }
32 if unExchangeCash, ok := data["unExchangeCash"]; ok { 36 if unExchangeCash, ok := data["unExchangeCash"]; ok {
33 - cashPool.UnExchangeCash = unExchangeCash.(float64) 37 + cashPool.UnExchangeCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", unExchangeCash.(float64)), 64)
34 } 38 }
35 if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok { 39 if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok {
36 - cashPool.ExchangedSuMoney = exchangedSuMoney.(float64) 40 + cashPool.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangedSuMoney.(float64)), 64)
37 } 41 }
38 if unExchangeSuMoney, ok := data["unExchangeSuMoney"]; ok { 42 if unExchangeSuMoney, ok := data["unExchangeSuMoney"]; ok {
39 - cashPool.UnExchangeSuMoney = unExchangeSuMoney.(float64) 43 + cashPool.UnExchangeSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", unExchangeSuMoney.(float64)), 64)
40 } 44 }
41 if rate, ok := data["rate"]; ok { 45 if rate, ok := data["rate"]; ok {
42 - cashPool.Rate = rate.(float64) 46 + cashPool.Rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", rate.(float64)), 64)
43 } 47 }
44 return nil 48 return nil
45 } 49 }
1 package domain 1 package domain
2 2
3 -import "time" 3 +import (
  4 + "fmt"
  5 + "strconv"
  6 + "time"
  7 +)
4 8
5 // 兑换现金活动 9 // 兑换现金活动
6 type ExchangeCashActivity struct { 10 type ExchangeCashActivity struct {
@@ -41,13 +45,13 @@ func (exchangeCashActivity *ExchangeCashActivity) Update(data map[string]interfa @@ -41,13 +45,13 @@ func (exchangeCashActivity *ExchangeCashActivity) Update(data map[string]interfa
41 exchangeCashActivity.CountDown = countDown.(int64) 45 exchangeCashActivity.CountDown = countDown.(int64)
42 } 46 }
43 if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok && exchangedSuMoney != 0 { 47 if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok && exchangedSuMoney != 0 {
44 - exchangeCashActivity.ExchangedSuMoney = exchangedSuMoney.(float64) 48 + exchangeCashActivity.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangedSuMoney.(float64)), 64)
45 } 49 }
46 if exchangedCash, ok := data["exchangedCash"]; ok && exchangedCash != 0 { 50 if exchangedCash, ok := data["exchangedCash"]; ok && exchangedCash != 0 {
47 - exchangeCashActivity.ExchangedCash = exchangedCash.(float64) 51 + exchangeCashActivity.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangedCash.(float64)), 64)
48 } 52 }
49 if exchangeRate, ok := data["exchangeRate"]; ok && exchangeRate != 0 { 53 if exchangeRate, ok := data["exchangeRate"]; ok && exchangeRate != 0 {
50 - exchangeCashActivity.Rate = exchangeRate.(float64) 54 + exchangeCashActivity.Rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangeRate.(float64)), 64)
51 } 55 }
52 return nil 56 return nil
53 } 57 }
1 package domain 1 package domain
2 2
  3 +import (
  4 + "fmt"
  5 + "strconv"
  6 +)
  7 +
3 // 参与兑换现金人员 8 // 参与兑换现金人员
4 type ExchangeCashPersonList struct { 9 type ExchangeCashPersonList struct {
5 ListId int64 `json:"listId"` // 清单id 10 ListId int64 `json:"listId"` // 清单id
@@ -30,7 +35,7 @@ func (exchangeCashPersonList *ExchangeCashPersonList) Update(data map[string]int @@ -30,7 +35,7 @@ func (exchangeCashPersonList *ExchangeCashPersonList) Update(data map[string]int
30 exchangeCashPersonList.ExchangedSuMoney = exchangedSuMoney.(float64) 35 exchangeCashPersonList.ExchangedSuMoney = exchangedSuMoney.(float64)
31 } 36 }
32 if exchangedCash, ok := data["exchangedCash"]; ok && exchangedCash != 0 { 37 if exchangedCash, ok := data["exchangedCash"]; ok && exchangedCash != 0 {
33 - exchangeCashPersonList.ExchangedCash = exchangedCash.(float64) 38 + exchangeCashPersonList.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2F", exchangedCash.(float64)), 64)
34 } 39 }
35 return nil 40 return nil
36 } 41 }
@@ -8,6 +8,7 @@ const ( @@ -8,6 +8,7 @@ const (
8 SU_MONEY_TRANSACTION_RECORD_TYPE_INCREASE //增加 8 SU_MONEY_TRANSACTION_RECORD_TYPE_INCREASE //增加
9 SU_MONEY_TRANSACTION_RECORD_TYPE_DEDUCT //扣除 9 SU_MONEY_TRANSACTION_RECORD_TYPE_DEDUCT //扣除
10 SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH //兑换现金 10 SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH //兑换现金
  11 + SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH_RESTORE // 兑换现金撤销
11 ) 12 )
12 13
13 // 素币事务记录 14 // 素币事务记录
@@ -10,49 +10,6 @@ type CashPoolDao struct { @@ -10,49 +10,6 @@ type CashPoolDao struct {
10 transactionContext *pgTransaction.TransactionContext 10 transactionContext *pgTransaction.TransactionContext
11 } 11 }
12 12
13 -// 计算系统已兑换素币、未兑换素币  
14 -//func (dao *CashPoolDao) CalculateSystemSuMoney(companyId int64) ( map[string]interface{}, error) {  
15 -// var systemUnExchangeSuMoney float64  
16 -// var systemExchangedSuMoney float64  
17 -// tx := dao.transactionContext.PgTx  
18 -// employeeModel := new(models.Employee)  
19 -// if err := tx.Model(employeeModel).  
20 -// ColumnExpr("sum(employee.su_money) AS system_unExchange_su_money").  
21 -// Where("employee.company_id = ?", companyId).  
22 -// Select(&systemUnExchangeSuMoney); err != nil {  
23 -// return nil, err  
24 -// }  
25 -// exchangeCashActivityModel := new(models.ExchangeCashActivity)  
26 -// if err := tx.Model(exchangeCashActivityModel).  
27 -// ColumnExpr("sum(exchange_cash_activity.exchanged_su_money) AS system_changed_su_money").  
28 -// Where("exchange_cash_activity.company_id = ?", companyId).  
29 -// Select(&systemExchangedSuMoney); err != nil {  
30 -// return nil, err  
31 -// }  
32 -// return map[string]interface{}{  
33 -// "systemUnExchangeSuMoney": systemUnExchangeSuMoney,  
34 -// "systemExchangedSuMoney": systemExchangedSuMoney,  
35 -// }, nil  
36 -//}  
37 -  
38 -// 计算系统已兑换现金、未兑换现金  
39 -//func (dao *CashPoolDao) CalculateSystemCash(companyId int64) (map[string]interface{}, error) {  
40 -// var systemExchangedCash float64 // 系统已兑换现金  
41 -// var systemUnExchangeCash float64 // 系统未兑换现金  
42 -// tx := dao.transactionContext.PgTx  
43 -// exchangeCashActivityModel := new(models.ExchangeCashActivity)  
44 -// if err := tx.Model(exchangeCashActivityModel).  
45 -// ColumnExpr("sum(exchange_cash_activity.exchanged_cash) AS system_exchanged_cash").  
46 -// Where("exchange_cash_activity.company_id = ?", companyId).  
47 -// Select(&systemExchangedCash) ; err != nil {  
48 -// return nil, err  
49 -// }  
50 -// return map[string]interface{}{  
51 -// "systemExchangedCash": systemExchangedCash,  
52 -// "systemUnExchangeCash": systemUnExchangeCash,  
53 -// }, nil  
54 -//}  
55 -  
56 // 兑换活动兑换清单已兑换素币、已兑换现金 13 // 兑换活动兑换清单已兑换素币、已兑换现金
57 func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map[string]interface{}, error) { 14 func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map[string]interface{}, error) {
58 var activityExchangedSuMoney float64 15 var activityExchangedSuMoney float64
@@ -144,6 +144,7 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{ @@ -144,6 +144,7 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{
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
  147 + var systemExchangedSuMoneyRestore float64
147 tx := dao.transactionContext.PgTx 148 tx := dao.transactionContext.PgTx
148 // 系统未兑换素币 149 // 系统未兑换素币
149 employeeModel := new(models.Employee) 150 employeeModel := new(models.Employee)
@@ -160,13 +161,22 @@ func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] int @@ -160,13 +161,22 @@ func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] int
160 ColumnExpr("sum(su_money_transaction_record.su_money) AS system_exchanged_su_money"). 161 ColumnExpr("sum(su_money_transaction_record.su_money) AS system_exchanged_su_money").
161 Where("e.company_id = ?", companyId). 162 Where("e.company_id = ?", companyId).
162 Where("e.status = ?", 1). 163 Where("e.status = ?", 1).
163 - Where(`su_money_transaction_record.record_type = ?`, 5). 164 + Where(`su_money_transaction_record.record_type = ?`, domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH).
164 Select(&systemExchangedSuMoney); err != nil { 165 Select(&systemExchangedSuMoney); err != nil {
165 return nil, err 166 return nil, err
166 } 167 }
  168 + // 系统撤销的兑换现金素币
  169 + if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
  170 + ColumnExpr("sum(su_money_transaction_record.su_money) AS system_exchanged_su_money").
  171 + Where("e.company_id = ?", companyId).
  172 + Where("e.status = ?", 1).
  173 + Where(`su_money_transaction_record.record_type = ?`, domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH_RESTORE).
  174 + Select(&systemExchangedSuMoneyRestore); err != nil {
  175 + return nil, err
  176 + }
167 return map[string] interface{} { 177 return map[string] interface{} {
168 "systemUnExchangeSuMoney": systemUnExchangeSuMoney, 178 "systemUnExchangeSuMoney": systemUnExchangeSuMoney,
169 - "systemExchangedSuMoney": systemExchangedSuMoney, 179 + "systemExchangedSuMoney": systemExchangedSuMoney - systemExchangedSuMoneyRestore,
170 },nil 180 },nil
171 } 181 }
172 182
@@ -205,7 +215,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf @@ -205,7 +215,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf
205 // 计算个人素币收支 215 // 计算个人素币收支
206 func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) { 216 func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
207 var ( 217 var (
208 - incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加) 218 + incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加 6: 兑换素币撤回
209 expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除, 5: 兑换现金) 219 expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除, 5: 兑换现金)
210 ) 220 )
211 tx := dao.transactionContext.PgTx 221 tx := dao.transactionContext.PgTx
@@ -214,7 +224,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction @@ -214,7 +224,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
214 if err := tx.Model(suMoneyTransactionRecordModel). 224 if err := tx.Model(suMoneyTransactionRecordModel).
215 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 225 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
216 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 226 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
217 - Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). 227 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3, 6})).
218 Where(`su_money_transaction_record.create_time > ?`, transactionStartTime). 228 Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
219 Where(`su_money_transaction_record.create_time < ?`, transactionEndTime). 229 Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
220 Select(&incomeSuMoney); err != nil { 230 Select(&incomeSuMoney); err != nil {
@@ -270,54 +280,6 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans @@ -270,54 +280,6 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans
270 }, nil 280 }, nil
271 } 281 }
272 282
273 -//func (dao *EmployeeDao) CalculateEmployeesSuMoney(queryOptions map[string]interface{}) (map[string]interface{}, error) {  
274 -// var ret []struct {  
275 -// Uid int  
276 -// EmployeeName string  
277 -// EmployeeSuMoney float64  
278 -// }  
279 -// tx := dao.transactionContext.PgTx  
280 -// var (  
281 -// startTime time.Time  
282 -// endTime time.Time  
283 -// companyId int  
284 -// )  
285 -// if company, ok := queryOptions["companyId"].(int); ok {  
286 -// companyId = company  
287 -// }  
288 -// if start, ok := queryOptions["startTime"].(time.Time); ok {  
289 -// startTime = start  
290 -// } else {  
291 -// startTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location())  
292 -// }  
293 -// if end, ok := queryOptions["endTime"].(time.Time); ok {  
294 -// endTime = end  
295 -// } else {  
296 -// endTime = time.Now()  
297 -// }  
298 -// fmt.Print(startTime, "\n")  
299 -// fmt.Print(endTime, "\n")  
300 -// fmt.Print(companyId, "\n")  
301 -// suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)  
302 -// if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").  
303 -// ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").  
304 -// ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").  
305 -// ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money").  
306 -// Where(`e.company_id = ?`, companyId).  
307 -// Where(`e.status = ?`, 1).  
308 -// Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的  
309 -// Where(`su_money_transaction_record.create_time > ?`, startTime).  
310 -// Where(`su_money_transaction_record.create_time < ?`, endTime).  
311 -// Group("su_money_transaction_record.employee").  
312 -// Order("employee_su_money DESC").  
313 -// Select(&ret); err != nil {  
314 -// return nil, err  
315 -// }  
316 -// return map[string]interface{}{  
317 -// "employeesSuMoney": ret,  
318 -// }, nil  
319 -//}  
320 -  
321 // 贡献值、财富值总榜和年榜, 283 // 贡献值、财富值总榜和年榜,
322 func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]interface{}) (interface{}, error) { 284 func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]interface{}) (interface{}, error) {
323 var retWealth []struct { // 个人财富值 285 var retWealth []struct { // 个人财富值
@@ -356,7 +318,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -356,7 +318,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
356 queryWealth = queryWealth.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money") 318 queryWealth = queryWealth.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money")
357 queryWealth = queryWealth.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking") 319 queryWealth = queryWealth.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking")
358 queryWealth = queryWealth.Where(`e.status = ?`, 1) 320 queryWealth = queryWealth.Where(`e.status = ?`, 1)
359 - queryWealth = queryWealth.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})) 321 + queryWealth = queryWealth.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3, 6}))
360 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) { 322 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
361 queryWealth = queryWealth.Where("e.company_id = ?", companyId) 323 queryWealth = queryWealth.Where("e.company_id = ?", companyId)
362 } 324 }
@@ -508,98 +470,6 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -508,98 +470,6 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
508 }, nil 470 }, nil
509 } 471 }
510 472
511 -// 排行榜统计,排名  
512 -//func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime time.Time, endTime time.Time, offset int, limit int) (map[string]interface{}, error) {  
513 -// var retWealth []struct {  
514 -// Uid int  
515 -// EmployeeName string  
516 -// EmployeeSuMoney float64  
517 -// Ranking int  
518 -// }  
519 -// var retContributions []struct { // 员工贡献值  
520 -// Uid int  
521 -// EmployeeName string  
522 -// EmployeesContributions float64  
523 -// Ranking int  
524 -// }  
525 -// var retContributionDecrease []struct { // 员工减少的贡献值  
526 -// Uid int  
527 -// EmployeeName string  
528 -// EmployeesContributions float64  
529 -// Ranking int  
530 -// }  
531 -// tx := dao.transactionContext.PgTx  
532 -// suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)  
533 -// if limit < -1 {  
534 -// limit = 20  
535 -// }  
536 -// if offset < -1 {  
537 -// offset = 0  
538 -// }  
539 -// // 员工财富值  
540 -// if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").  
541 -// ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").  
542 -// ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").  
543 -// ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money").  
544 -// Where(`e.company_id = ?`, companyId).  
545 -// Where(`e.status = ?`, 1).  
546 -// Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的  
547 -// Where(`su_money_transaction_record.create_time > ?`, startTime).  
548 -// Where(`su_money_transaction_record.create_time < ?`, endTime).  
549 -// Group("su_money_transaction_record.employee").  
550 -// Order("employee_su_money DESC").  
551 -// Limit(limit).  
552 -// Offset(offset).  
553 -// Select(&retWealth); err != nil {  
554 -// return nil, err  
555 -// }  
556 -// // 增加的贡献值  
557 -// if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").  
558 -// ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").  
559 -// ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").  
560 -// ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions").  
561 -// Where(`e.company_id = ?`, companyId).  
562 -// Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).  
563 -// Where(`e.status = ?`, 1).  
564 -// Where(`su_money_transaction_record.create_time > ?`, startTime).  
565 -// Where(`su_money_transaction_record.create_time < ?`, endTime).  
566 -// Group("su_money_transaction_record.employee").  
567 -// Order("employees_contributions DESC").  
568 -// Limit(limit).  
569 -// Offset(offset).  
570 -// Select(&retContributions); err != nil {  
571 -// return nil, err  
572 -// }  
573 -// // 减少的贡献值  
574 -// if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").  
575 -// ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").  
576 -// ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").  
577 -// ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions").  
578 -// Where(`e.company_id = ?`, companyId).  
579 -// Where(`su_money_transaction_record.record_type = ?`, 4).  
580 -// Where(`e.status = ?`, 1).  
581 -// Where(`su_money_transaction_record.create_time > ?`, startTime).  
582 -// Where(`su_money_transaction_record.create_time < ?`, endTime).  
583 -// Group("su_money_transaction_record.employee").  
584 -// Order("employees_contributions DESC").  
585 -// Limit(limit).  
586 -// Offset(offset).  
587 -// Select(&retContributionDecrease); err != nil {  
588 -// return nil, err  
589 -// }  
590 -// for i := 0; i < len(retContributions); i++ {  
591 -// for j := 0; j < len(retContributionDecrease); j++ {  
592 -// if retContributions[i].Uid == retContributionDecrease[j].Uid {  
593 -// retContributions[i].EmployeesContributions -= retContributionDecrease[j].EmployeesContributions  
594 -// }  
595 -// }  
596 -// }  
597 -// return map[string]interface{}{  
598 -// "employeesContributions": retContributions,  
599 -// "employeesWealth": retWealth,  
600 -// }, nil  
601 -//}  
602 -  
603 // 公司员工贡献值分组统计 473 // 公司员工贡献值分组统计
604 func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) { 474 func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
605 var ret []struct { // 员工贡献值 475 var ret []struct { // 员工贡献值
@@ -73,6 +73,10 @@ func (service *OperationSuMoneyService) Operation(uid int64, operatorUid int64, @@ -73,6 +73,10 @@ func (service *OperationSuMoneyService) Operation(uid int64, operatorUid int64,
73 recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH 73 recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH
74 transferSuMoney = 0 - suMoney 74 transferSuMoney = 0 - suMoney
75 } 75 }
  76 + if operationType == 41 { // 兑换素币调整退回
  77 + recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH_RESTORE
  78 + transferSuMoney = suMoney
  79 + }
76 if operationType == 5 { // 任务奖励 80 if operationType == 5 { // 任务奖励
77 recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_AWARD 81 recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_AWARD
78 transferSuMoney = suMoney 82 transferSuMoney = suMoney