|
@@ -723,16 +723,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -723,16 +723,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
723
|
cashPoolRepository = value
|
723
|
cashPoolRepository = value
|
724
|
}
|
724
|
}
|
725
|
|
725
|
|
726
|
- // 现金池DAO初始化
|
|
|
727
|
- //var cashPoolDao *dao.CashPoolDao
|
|
|
728
|
- //if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
|
|
729
|
- // "transactionContext": transactionContext,
|
|
|
730
|
- //}); err != nil {
|
|
|
731
|
- // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
732
|
- //} else {
|
|
|
733
|
- // cashPoolDao = value
|
|
|
734
|
- //}
|
|
|
735
|
-
|
|
|
736
|
// 员工DAO初始化
|
726
|
// 员工DAO初始化
|
737
|
var employeeDao *dao.EmployeeDao
|
727
|
var employeeDao *dao.EmployeeDao
|
738
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
728
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
@@ -764,16 +754,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -764,16 +754,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
764
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
|
754
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
|
765
|
}
|
755
|
}
|
766
|
|
756
|
|
767
|
- // 获取活动素币统计
|
|
|
768
|
- //activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.ActivityId)
|
|
|
769
|
- //if err != nil {
|
|
|
770
|
- // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
771
|
- //}
|
|
|
772
|
- //if activitySuMoneyStatistics == nil {
|
|
|
773
|
- // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
|
|
|
774
|
- //}
|
|
|
775
|
- //activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
|
|
|
776
|
-
|
|
|
777
|
// 判断兑换活动清单中现金总金额是否超过平台未兑换现金值
|
757
|
// 判断兑换活动清单中现金总金额是否超过平台未兑换现金值
|
778
|
if activityFound.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
|
758
|
if activityFound.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
|
779
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
759
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
@@ -792,7 +772,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -792,7 +772,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
792
|
personFoundExchangedSuMoney := personFound.ExchangedSuMoney
|
772
|
personFoundExchangedSuMoney := personFound.ExchangedSuMoney
|
793
|
|
773
|
|
794
|
// 更新兑换清单命令
|
774
|
// 更新兑换清单命令
|
795
|
- //updateExchangeCashActivityExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", updateExchangeCashActivityCommand.ExchangeRate * personFoundExchangedSuMoney), 64)
|
|
|
796
|
updateExchangeCashPerson := &command.UpdateExchangeCashPersonCommand {
|
775
|
updateExchangeCashPerson := &command.UpdateExchangeCashPersonCommand {
|
797
|
ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * personFoundExchangedSuMoney,
|
776
|
ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * personFoundExchangedSuMoney,
|
798
|
ExchangedSuMoney: personFoundExchangedSuMoney,
|
777
|
ExchangedSuMoney: personFoundExchangedSuMoney,
|
|
@@ -820,17 +799,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -820,17 +799,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
820
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
799
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
821
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
800
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
822
|
|
801
|
|
823
|
- // 获取平台现金状况
|
|
|
824
|
- //systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
|
|
825
|
- //if err != nil {
|
|
|
826
|
- // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
827
|
- //}
|
|
|
828
|
- //if systemCashStatistics == nil {
|
|
|
829
|
- // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
830
|
- //}
|
|
|
831
|
- //systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
|
|
832
|
- //systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
833
|
-
|
|
|
834
|
// 更新兑换活动命令已兑换现金
|
802
|
// 更新兑换活动命令已兑换现金
|
835
|
updateExchangeCashActivityCommand.ExchangedCash = updateExchangeCashActivityCommand.ExchangeRate * activityFound.ExchangedSuMoney
|
803
|
updateExchangeCashActivityCommand.ExchangedCash = updateExchangeCashActivityCommand.ExchangeRate * activityFound.ExchangedSuMoney
|
836
|
|
804
|
|
|
@@ -899,8 +867,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -899,8 +867,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
899
|
}
|
867
|
}
|
900
|
}
|
868
|
}
|
901
|
|
869
|
|
902
|
-// 新增兑换素币清单
|
|
|
903
|
-func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeCashPersonCommand *command.CreateExchangeCashPersonCommand) (interface{}, error) {
|
870
|
+// 新增导入兑换素币清单
|
|
|
871
|
+func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExchangeCashPersonCommand *command.CreateExchangeCashPersonCommand) (interface{}, error) {
|
904
|
if err := createExchangeCashPersonCommand.ValidateCommand(); err != nil {
|
872
|
if err := createExchangeCashPersonCommand.ValidateCommand(); err != nil {
|
905
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
873
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
906
|
}
|
874
|
}
|
|
@@ -955,16 +923,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -955,16 +923,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
955
|
employeeRepository = value
|
923
|
employeeRepository = value
|
956
|
}
|
924
|
}
|
957
|
|
925
|
|
958
|
- //// 现金池DAO初始化
|
|
|
959
|
- //var cashPoolDao *dao.CashPoolDao
|
|
|
960
|
- //if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
|
|
961
|
- // "transactionContext": transactionContext,
|
|
|
962
|
- //}); err != nil {
|
|
|
963
|
- // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
964
|
- //} else {
|
|
|
965
|
- // cashPoolDao = value
|
|
|
966
|
- //}
|
|
|
967
|
-
|
|
|
968
|
// 员工DAO初始化
|
926
|
// 员工DAO初始化
|
969
|
var employeeDao *dao.EmployeeDao
|
927
|
var employeeDao *dao.EmployeeDao
|
970
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
928
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
@@ -991,19 +949,11 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -991,19 +949,11 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
991
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
949
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
992
|
}
|
950
|
}
|
993
|
|
951
|
|
994
|
- // 判断导入方式,页面/Excel
|
|
|
995
|
- getEmployee := map[string]interface{}{}
|
|
|
996
|
- if createExchangeCashPersonCommand.PersonAccount == "" {
|
|
|
997
|
- getEmployee = map[string]interface{}{
|
|
|
998
|
- "uid": createExchangeCashPersonCommand.Uid,
|
|
|
999
|
- "companyId": activityFound.CompanyId,
|
|
|
1000
|
- }
|
|
|
1001
|
- } else {
|
|
|
1002
|
- getEmployee = map[string]interface{}{
|
952
|
+ // 获取员工查询条件
|
|
|
953
|
+ getEmployee := map[string]interface{}{
|
1003
|
"account": createExchangeCashPersonCommand.PersonAccount,
|
954
|
"account": createExchangeCashPersonCommand.PersonAccount,
|
1004
|
"companyId": activityFound.CompanyId,
|
955
|
"companyId": activityFound.CompanyId,
|
1005
|
}
|
956
|
}
|
1006
|
- }
|
|
|
1007
|
|
957
|
|
1008
|
// 判断当前员工是否有效
|
958
|
// 判断当前员工是否有效
|
1009
|
employeeFound, err := employeeRepository.FindOne(getEmployee)
|
959
|
employeeFound, err := employeeRepository.FindOne(getEmployee)
|
|
@@ -1020,19 +970,164 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -1020,19 +970,164 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
1020
|
}
|
970
|
}
|
1021
|
|
971
|
|
1022
|
// 判断当前员工是否已经在素币兑换清单中
|
972
|
// 判断当前员工是否已经在素币兑换清单中
|
1023
|
- count, _, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
|
|
|
1024
|
- "uid": employeeFound.EmployeeInfo.Uid,
|
973
|
+ count, peopleFound, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
|
|
|
974
|
+ "employeeAccount": employeeFound.EmployeeInfo.EmployeeAccount,
|
1025
|
"exchangeCashActivityId": activityFound.ActivityId,
|
975
|
"exchangeCashActivityId": activityFound.ActivityId,
|
|
|
976
|
+ "offset": 0,
|
|
|
977
|
+ "limit": 1,
|
1026
|
})
|
978
|
})
|
1027
|
if err != nil {
|
979
|
if err != nil {
|
1028
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
980
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1029
|
}
|
981
|
}
|
1030
|
- if count > 0 {
|
|
|
1031
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前员工已经在素币兑换清单中")
|
982
|
+
|
|
|
983
|
+ // 更新兑换素币清单命令
|
|
|
984
|
+ updateExchangeCashPersonCommand := command.UpdateExchangeCashPersonCommand{
|
|
|
985
|
+ ListId: peopleFound[0].ListId,
|
|
|
986
|
+ ExchangedSuMoney: peopleFound[0].ExchangedSuMoney,
|
|
|
987
|
+ ExchangedCash: peopleFound[0].ExchangedCash,
|
1032
|
}
|
988
|
}
|
1033
|
|
989
|
|
|
|
990
|
+ if count > 0 { // 追加素币兑换或撤回素币兑换
|
|
|
991
|
+ operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
992
|
+ Uid: employeeFound.EmployeeInfo.Uid,
|
|
|
993
|
+ Operator: createExchangeCashPersonCommand.Operator,
|
|
|
994
|
+ SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
995
|
+ OperationType: 4,
|
|
|
996
|
+ OperationDescription: "素币兑换现金",
|
|
|
997
|
+ }
|
|
|
998
|
+ if createExchangeCashPersonCommand.ExchangedSuMoney < peopleFound[0].ExchangedSuMoney { // 当前兑换的素币小于已兑换素币,撤回兑换素币
|
|
|
999
|
+ //suMoneyDecrement := peopleFound[0].ExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney // 减量
|
|
|
1000
|
+ // 更新兑换素币清单命令
|
|
|
1001
|
+
|
|
|
1002
|
+ // 操作素币命令
|
|
|
1003
|
+ operationSuMoneyCommand.OperationType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH_RESTORE
|
|
|
1004
|
+ operationSuMoneyCommand.OperationDescription = ""
|
|
|
1005
|
+
|
|
|
1006
|
+ } else if createExchangeCashPersonCommand.ExchangedSuMoney > peopleFound[0].ExchangedSuMoney { // 当前兑换素币大于已兑换素币,追加兑换素币
|
|
|
1007
|
+ //suMoneyIncrement := createExchangeCashPersonCommand.ExchangedSuMoney - peopleFound[0].ExchangedSuMoney // 增量
|
|
|
1008
|
+ // 更新兑换素币清单命令
|
|
|
1009
|
+
|
|
|
1010
|
+ // 操作素币命令
|
|
|
1011
|
+ operationSuMoneyCommand.OperationType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH
|
|
|
1012
|
+ operationSuMoneyCommand.OperationDescription = ""
|
|
|
1013
|
+
|
|
|
1014
|
+
|
|
|
1015
|
+ }
|
|
|
1016
|
+ // 更新兑换素币清单
|
|
|
1017
|
+ if err := peopleFound[0].Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
|
|
1018
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
1019
|
+ }
|
|
|
1020
|
+
|
|
|
1021
|
+ // 保存兑换素币清单更新
|
|
|
1022
|
+ personUpdated, err := exchangeCashPersonListRepository.Save(peopleFound[0])
|
|
|
1023
|
+ if err != nil {
|
|
|
1024
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1025
|
+ }
|
|
|
1026
|
+
|
|
|
1027
|
+ // 操作素币,生成素币流水
|
|
|
1028
|
+ task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
|
|
1029
|
+ if err != nil {
|
|
|
1030
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1031
|
+ }
|
|
|
1032
|
+ if task == nil {
|
|
|
1033
|
+ return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
|
|
1034
|
+ }
|
|
|
1035
|
+
|
|
|
1036
|
+ // 更新兑换活动命令
|
|
|
1037
|
+ updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
1038
|
+ ExchangeCashActivityId: personUpdated.ExchangeCashActivityId,
|
|
|
1039
|
+ ExchangeActivityName: activityFound.ExchangeActivityName,
|
|
|
1040
|
+ ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
1041
|
+ ExchangedCash: activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
1042
|
+ Deadline: activityFound.Deadline,
|
|
|
1043
|
+ CountDown: activityFound.CountDown,
|
|
|
1044
|
+ ExchangeRate: activityFound.Rate,
|
|
|
1045
|
+ }
|
|
|
1046
|
+
|
|
|
1047
|
+ // 更新兑换活动
|
|
|
1048
|
+ if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
1049
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
1050
|
+ }
|
|
|
1051
|
+
|
|
|
1052
|
+ // 保存兑换现金活动更新
|
|
|
1053
|
+ activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
|
|
1054
|
+ if err != nil {
|
|
|
1055
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1056
|
+ }
|
|
|
1057
|
+ if activityUpdated == nil {
|
|
|
1058
|
+ return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
|
|
|
1059
|
+ }
|
|
|
1060
|
+
|
|
|
1061
|
+ // 获取当前现金池
|
|
|
1062
|
+ _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
1063
|
+ "companyId": activityFound.CompanyId,
|
|
|
1064
|
+ })
|
|
|
1065
|
+ if err != nil {
|
|
|
1066
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1067
|
+ }
|
|
|
1068
|
+ if len(cashPoolsFound) == 0 {
|
|
|
1069
|
+ return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "当前现金池为空,请先投入现金")
|
|
|
1070
|
+ }
|
|
|
1071
|
+
|
|
|
1072
|
+ // 判断兑换活动的现金是否超过现金池未兑换现金
|
|
|
1073
|
+ if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
|
|
|
1074
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
|
|
|
1075
|
+ }
|
|
|
1076
|
+
|
|
|
1077
|
+ // 获取平台素币兑换情况
|
|
|
1078
|
+ systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
|
|
1079
|
+ if err != nil {
|
|
|
1080
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1081
|
+ }
|
|
|
1082
|
+ if systemSuMoneyStatistics == nil {
|
|
|
1083
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
1084
|
+ }
|
|
|
1085
|
+ systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
1086
|
+ systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
|
|
1087
|
+
|
|
|
1088
|
+ // 计算平均兑换汇率
|
|
|
1089
|
+ var newRate float64
|
|
|
1090
|
+ if systemExchangedSuMoney == 0 {
|
|
|
1091
|
+ newRate = 0
|
|
|
1092
|
+ } else {
|
|
|
1093
|
+ newRate = (cashPoolsFound[0].ExchangedCash + personUpdated.ExchangedCash) / systemExchangedSuMoney
|
|
|
1094
|
+ }
|
|
|
1095
|
+
|
|
|
1096
|
+ // 更新现金池命令
|
|
|
1097
|
+ updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
1098
|
+ CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
1099
|
+ Cash: cashPoolsFound[0].Cash,
|
|
|
1100
|
+ ExchangedCash: cashPoolsFound[0].ExchangedCash + personUpdated.ExchangedCash,
|
|
|
1101
|
+ UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personUpdated.ExchangedCash,
|
|
|
1102
|
+ ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
1103
|
+ UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
1104
|
+ Rate: newRate,
|
|
|
1105
|
+ LastRate: cashPoolsFound[0].LastRate,
|
|
|
1106
|
+ }
|
|
|
1107
|
+
|
|
|
1108
|
+ // 更新现金池
|
|
|
1109
|
+ if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
1110
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
1111
|
+ }
|
|
|
1112
|
+
|
|
|
1113
|
+ // 保存现金池更新
|
|
|
1114
|
+ cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
|
|
|
1115
|
+ if err != nil {
|
|
|
1116
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1117
|
+ }
|
|
|
1118
|
+ if cashPoolUpdated == nil {
|
|
|
1119
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1120
|
+ }
|
|
|
1121
|
+
|
|
|
1122
|
+ if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
1123
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
1124
|
+ }
|
|
|
1125
|
+ return nil, nil
|
|
|
1126
|
+ } else if count == 0 { // 新增
|
1034
|
// 新增兑换清单命令
|
1127
|
// 新增兑换清单命令
|
1035
|
newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)
|
1128
|
newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)
|
|
|
1129
|
+
|
|
|
1130
|
+ // 新增兑换素币清单命令
|
1036
|
newPerson := &domain.ExchangeCashPersonList{
|
1131
|
newPerson := &domain.ExchangeCashPersonList{
|
1037
|
EmployeeInfo: &domain.EmployeeInfo{
|
1132
|
EmployeeInfo: &domain.EmployeeInfo{
|
1038
|
Uid: employeeFound.EmployeeInfo.Uid,
|
1133
|
Uid: employeeFound.EmployeeInfo.Uid,
|
|
@@ -1056,7 +1151,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -1056,7 +1151,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
1056
|
Operator: createExchangeCashPersonCommand.Operator,
|
1151
|
Operator: createExchangeCashPersonCommand.Operator,
|
1057
|
SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
1152
|
SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
1058
|
OperationType: 4,
|
1153
|
OperationType: 4,
|
1059
|
- OperationDescription: "参与" + activityFound.ExchangeActivityName,
|
1154
|
+ OperationDescription: "素币兑换现金",
|
1060
|
}
|
1155
|
}
|
1061
|
|
1156
|
|
1062
|
// 操作素币,生成素币流水
|
1157
|
// 操作素币,生成素币流水
|
|
@@ -1093,16 +1188,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -1093,16 +1188,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
1093
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
|
1188
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
|
1094
|
}
|
1189
|
}
|
1095
|
|
1190
|
|
1096
|
- // 获取兑换活动素币兑换情况
|
|
|
1097
|
- //activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.ActivityId)
|
|
|
1098
|
- //if err != nil {
|
|
|
1099
|
- // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1100
|
- //}
|
|
|
1101
|
- //if activitySuMoneyStatistics == nil {
|
|
|
1102
|
- // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
|
|
|
1103
|
- //}
|
|
|
1104
|
- //activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
|
|
|
1105
|
-
|
|
|
1106
|
// 获取当前现金池
|
1191
|
// 获取当前现金池
|
1107
|
_, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
|
1192
|
_, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
|
1108
|
"companyId": activityFound.CompanyId,
|
1193
|
"companyId": activityFound.CompanyId,
|
|
@@ -1119,16 +1204,277 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -1119,16 +1204,277 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
1119
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
|
1204
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
|
1120
|
}
|
1205
|
}
|
1121
|
|
1206
|
|
1122
|
- // 获取平台现金兑换情况
|
|
|
1123
|
- //systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
|
|
1124
|
- //if err != nil {
|
1207
|
+ // 获取平台素币兑换情况
|
|
|
1208
|
+ systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
|
|
1209
|
+ if err != nil {
|
|
|
1210
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1211
|
+ }
|
|
|
1212
|
+ if systemSuMoneyStatistics == nil {
|
|
|
1213
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
1214
|
+ }
|
|
|
1215
|
+ systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
1216
|
+ systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
|
|
1217
|
+
|
|
|
1218
|
+ // 计算平均兑换汇率
|
|
|
1219
|
+ var newRate float64
|
|
|
1220
|
+ if systemExchangedSuMoney == 0 {
|
|
|
1221
|
+ newRate = 0
|
|
|
1222
|
+ } else {
|
|
|
1223
|
+ newRate = (cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney
|
|
|
1224
|
+ }
|
|
|
1225
|
+
|
|
|
1226
|
+ // 更新现金池命令
|
|
|
1227
|
+ updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
1228
|
+ CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
1229
|
+ Cash: cashPoolsFound[0].Cash,
|
|
|
1230
|
+ ExchangedCash: cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash,
|
|
|
1231
|
+ UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personSaved.ExchangedCash,
|
|
|
1232
|
+ ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
1233
|
+ UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
1234
|
+ Rate: newRate,
|
|
|
1235
|
+ LastRate: cashPoolsFound[0].LastRate,
|
|
|
1236
|
+ }
|
|
|
1237
|
+
|
|
|
1238
|
+ // 更新现金池
|
|
|
1239
|
+ if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
1240
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
1241
|
+ }
|
|
|
1242
|
+
|
|
|
1243
|
+ // 保存现金池更新
|
|
|
1244
|
+ cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
|
|
|
1245
|
+ if err != nil {
|
|
|
1246
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1247
|
+ }
|
|
|
1248
|
+ if cashPoolUpdated == nil {
|
|
|
1249
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1250
|
+ }
|
|
|
1251
|
+
|
|
|
1252
|
+ if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
1253
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
1254
|
+ }
|
|
|
1255
|
+ return personSaved, nil
|
|
|
1256
|
+ }
|
|
|
1257
|
+ return nil, nil
|
|
|
1258
|
+}
|
|
|
1259
|
+
|
|
|
1260
|
+// 新增兑换素币清单
|
|
|
1261
|
+func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeCashPersonCommand *command.CreateExchangeCashPersonCommand) (interface{}, error) {
|
|
|
1262
|
+ if err := createExchangeCashPersonCommand.ValidateCommand(); err != nil {
|
|
|
1263
|
+ return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
1264
|
+ }
|
|
|
1265
|
+ transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
1266
|
+ if err != nil {
|
|
|
1267
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
1268
|
+ }
|
|
|
1269
|
+ if err := transactionContext.StartTransaction(); err != nil {
|
|
|
1270
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
1271
|
+ }
|
|
|
1272
|
+ defer func() {
|
|
|
1273
|
+ transactionContext.RollbackTransaction()
|
|
|
1274
|
+ }()
|
|
|
1275
|
+
|
|
|
1276
|
+ // 兑换活动仓储初始化
|
|
|
1277
|
+ var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
1278
|
+ if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
1279
|
+ "transactionContext": transactionContext,
|
|
|
1280
|
+ }); err != nil {
|
|
|
1281
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1282
|
+ } else {
|
|
|
1283
|
+ exchangeCashActivityRepository = value
|
|
|
1284
|
+ }
|
|
|
1285
|
+
|
|
|
1286
|
+ // 兑换素币清单仓储初始化
|
|
|
1287
|
+ var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
1288
|
+ if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
1289
|
+ "transactionContext": transactionContext,
|
|
|
1290
|
+ }); err != nil {
|
|
|
1291
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1292
|
+ } else {
|
|
|
1293
|
+ exchangeCashPersonListRepository = value
|
|
|
1294
|
+ }
|
|
|
1295
|
+
|
|
|
1296
|
+ // 现金池仓储初始化
|
|
|
1297
|
+ var cashPoolRepository domain.CashPoolRepository
|
|
|
1298
|
+ if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
|
|
1299
|
+ "transactionContext": transactionContext,
|
|
|
1300
|
+ }); err != nil {
|
|
|
1301
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1302
|
+ } else {
|
|
|
1303
|
+ cashPoolRepository = value
|
|
|
1304
|
+ }
|
|
|
1305
|
+
|
|
|
1306
|
+ // 员工仓储初始化
|
|
|
1307
|
+ var employeeRepository domain.EmployeeRepository
|
|
|
1308
|
+ if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
|
|
1309
|
+ "transactionContext": transactionContext,
|
|
|
1310
|
+ }); err != nil {
|
|
|
1311
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1312
|
+ } else {
|
|
|
1313
|
+ employeeRepository = value
|
|
|
1314
|
+ }
|
|
|
1315
|
+
|
|
|
1316
|
+ // 员工DAO初始化
|
|
|
1317
|
+ var employeeDao *dao.EmployeeDao
|
|
|
1318
|
+ if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
|
1319
|
+ "transactionContext": transactionContext,
|
|
|
1320
|
+ }); err != nil {
|
|
|
1321
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
1322
|
+ } else {
|
|
|
1323
|
+ employeeDao = value
|
|
|
1324
|
+ }
|
|
|
1325
|
+
|
|
|
1326
|
+ // 操作素币服务初始化
|
|
|
1327
|
+ var operationSuMoneyService service.OperationSuMoneyService
|
|
|
1328
|
+ if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
|
1329
|
+ "transactionContext": transactionContext,
|
|
|
1330
|
+ }); err != nil {
|
|
|
1331
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1332
|
+ } else {
|
|
|
1333
|
+ operationSuMoneyService = value
|
|
|
1334
|
+ }
|
|
|
1335
|
+
|
|
|
1336
|
+ // 获取当前兑换清单兑换活动
|
|
|
1337
|
+ activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
|
|
|
1338
|
+ if err != nil {
|
|
|
1339
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1340
|
+ }
|
|
|
1341
|
+
|
|
|
1342
|
+ getEmployee := map[string]interface{}{
|
|
|
1343
|
+ "uid": createExchangeCashPersonCommand.Uid,
|
|
|
1344
|
+ "companyId": activityFound.CompanyId,
|
|
|
1345
|
+ }
|
|
|
1346
|
+
|
|
|
1347
|
+ // 判断当前员工是否有效
|
|
|
1348
|
+ employeeFound, err := employeeRepository.FindOne(getEmployee)
|
|
|
1349
|
+ if err != nil {
|
|
|
1350
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1351
|
+ }
|
|
|
1352
|
+ if employeeFound == nil {
|
|
|
1353
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
|
|
|
1354
|
+ }
|
|
|
1355
|
+
|
|
|
1356
|
+ // 判断该员工兑换的素币是否超过本人持有的素币
|
|
|
1357
|
+ if employeeFound.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {
|
|
|
1358
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
|
|
|
1359
|
+ }
|
|
|
1360
|
+
|
|
|
1361
|
+ //// 判断当前员工是否已经在素币兑换清单中,区分excel导入新增和页面添加新增
|
|
|
1362
|
+ //if !createFlag { // 页面新增
|
|
|
1363
|
+ // count, _, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
|
|
|
1364
|
+ // "uid": employeeFound.EmployeeInfo.Uid,
|
|
|
1365
|
+ // "exchangeCashActivityId": activityFound.ActivityId,
|
|
|
1366
|
+ // })
|
|
|
1367
|
+ // if err != nil {
|
1125
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1368
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1369
|
+ // }
|
|
|
1370
|
+ // if count > 0 { // 已存在兑换素币清单
|
|
|
1371
|
+ // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前员工已经在素币兑换清单中")
|
|
|
1372
|
+ // }
|
|
|
1373
|
+ // if count == 0 { // 未存在,新增兑换素币清单
|
|
|
1374
|
+ //
|
|
|
1375
|
+ // }
|
|
|
1376
|
+ //} else { // 导入新增
|
|
|
1377
|
+ // count, peopleFound, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
|
|
|
1378
|
+ // "employeeAccount": employeeFound.EmployeeInfo.EmployeeAccount,
|
|
|
1379
|
+ // "exchangeCashActivityId": activityFound.ActivityId,
|
|
|
1380
|
+ // "offset": 0,
|
|
|
1381
|
+ // "limit": 1,
|
|
|
1382
|
+ // })
|
|
|
1383
|
+ // if err != nil {
|
|
|
1384
|
+ // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1385
|
+ // }
|
|
|
1386
|
+ // if count > 0 { // 追加素币兑换或撤回素币兑换
|
|
|
1387
|
+ // if createExchangeCashPersonCommand.ExchangedSuMoney < peopleFound[0].ExchangedSuMoney { // 当前兑换的素币小于已兑换素币,撤回兑换素币
|
|
|
1388
|
+ // suMoneyDecrement := peopleFound[0].ExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney // 减量
|
|
|
1389
|
+ //
|
|
|
1390
|
+ // } else if createExchangeCashPersonCommand.ExchangedSuMoney > peopleFound[0].ExchangedSuMoney { // 当前兑换素币大于已兑换素币,追加兑换素币
|
|
|
1391
|
+ // suMoneyIncrement := createExchangeCashPersonCommand.ExchangedSuMoney - peopleFound[0].ExchangedSuMoney // 增量
|
|
|
1392
|
+ //
|
|
|
1393
|
+ // }
|
|
|
1394
|
+ // }
|
|
|
1395
|
+ // if count == 0 { // 新增
|
|
|
1396
|
+ //
|
|
|
1397
|
+ // }
|
1126
|
//}
|
1398
|
//}
|
1127
|
- //if systemCashStatistics == nil {
|
|
|
1128
|
- // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
1129
|
- //}
|
|
|
1130
|
- //systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
|
|
1131
|
- //systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
1399
|
+
|
|
|
1400
|
+ // 新增兑换清单命令
|
|
|
1401
|
+ newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)
|
|
|
1402
|
+
|
|
|
1403
|
+ newPerson := &domain.ExchangeCashPersonList{
|
|
|
1404
|
+ EmployeeInfo: &domain.EmployeeInfo{
|
|
|
1405
|
+ Uid: employeeFound.EmployeeInfo.Uid,
|
|
|
1406
|
+ EmployeeName: employeeFound.EmployeeInfo.EmployeeName,
|
|
|
1407
|
+ EmployeeAccount: employeeFound.EmployeeInfo.EmployeeAccount,
|
|
|
1408
|
+ },
|
|
|
1409
|
+ ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
|
|
|
1410
|
+ ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
1411
|
+ ExchangedCash: newPersonExchangedCash,
|
|
|
1412
|
+ }
|
|
|
1413
|
+
|
|
|
1414
|
+ // 保存兑换素币清单
|
|
|
1415
|
+ personSaved, err := exchangeCashPersonListRepository.Save(newPerson)
|
|
|
1416
|
+ if err != nil {
|
|
|
1417
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1418
|
+ }
|
|
|
1419
|
+
|
|
|
1420
|
+ // 操作素币命令
|
|
|
1421
|
+ operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
1422
|
+ Uid: employeeFound.EmployeeInfo.Uid,
|
|
|
1423
|
+ Operator: createExchangeCashPersonCommand.Operator,
|
|
|
1424
|
+ SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
1425
|
+ OperationType: 4,
|
|
|
1426
|
+ OperationDescription: "参与" + activityFound.ExchangeActivityName,
|
|
|
1427
|
+ }
|
|
|
1428
|
+
|
|
|
1429
|
+ // 操作素币,生成素币流水
|
|
|
1430
|
+ task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
|
|
1431
|
+ if err != nil {
|
|
|
1432
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1433
|
+ }
|
|
|
1434
|
+ if task == nil {
|
|
|
1435
|
+ return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
|
|
1436
|
+ }
|
|
|
1437
|
+
|
|
|
1438
|
+ // 更新兑换活动命令
|
|
|
1439
|
+ updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
1440
|
+ ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
|
|
|
1441
|
+ ExchangeActivityName: activityFound.ExchangeActivityName,
|
|
|
1442
|
+ ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
1443
|
+ ExchangedCash: activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
1444
|
+ Deadline: activityFound.Deadline,
|
|
|
1445
|
+ CountDown: activityFound.CountDown,
|
|
|
1446
|
+ ExchangeRate: activityFound.Rate,
|
|
|
1447
|
+ }
|
|
|
1448
|
+
|
|
|
1449
|
+ // 更新兑换活动
|
|
|
1450
|
+ if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
1451
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
1452
|
+ }
|
|
|
1453
|
+
|
|
|
1454
|
+ // 保存兑换现金活动更新
|
|
|
1455
|
+ activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
|
|
1456
|
+ if err != nil {
|
|
|
1457
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1458
|
+ }
|
|
|
1459
|
+ if activityUpdated == nil {
|
|
|
1460
|
+ return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
|
|
|
1461
|
+ }
|
|
|
1462
|
+
|
|
|
1463
|
+ // 获取当前现金池
|
|
|
1464
|
+ _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
1465
|
+ "companyId": activityFound.CompanyId,
|
|
|
1466
|
+ })
|
|
|
1467
|
+ if err != nil {
|
|
|
1468
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1469
|
+ }
|
|
|
1470
|
+ if len(cashPoolsFound) == 0 {
|
|
|
1471
|
+ return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "当前现金池为空,请先投入现金")
|
|
|
1472
|
+ }
|
|
|
1473
|
+
|
|
|
1474
|
+ // 判断兑换活动的现金是否超过现金池未兑换现金
|
|
|
1475
|
+ if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
|
|
|
1476
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
|
|
|
1477
|
+ }
|
1132
|
|
1478
|
|
1133
|
// 获取平台素币兑换情况
|
1479
|
// 获取平台素币兑换情况
|
1134
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
1480
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
|
@@ -1360,16 +1706,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1360,16 +1706,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1360
|
operationSuMoneyService = value
|
1706
|
operationSuMoneyService = value
|
1361
|
}
|
1707
|
}
|
1362
|
|
1708
|
|
1363
|
- //// 现金池DAO初始化
|
|
|
1364
|
- //var cashPoolDao *dao.CashPoolDao
|
|
|
1365
|
- //if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
|
|
1366
|
- // "transactionContext": transactionContext,
|
|
|
1367
|
- //}); err != nil {
|
|
|
1368
|
- // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
1369
|
- //} else {
|
|
|
1370
|
- // cashPoolDao = value
|
|
|
1371
|
- //}
|
|
|
1372
|
-
|
|
|
1373
|
// 用户DAO初始化
|
1709
|
// 用户DAO初始化
|
1374
|
var employeeDao *dao.EmployeeDao
|
1710
|
var employeeDao *dao.EmployeeDao
|
1375
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
1711
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|