作者 陈志颖

fix:修复导出素币清单问题

@@ -6,7 +6,7 @@ import ( @@ -6,7 +6,7 @@ import (
6 ) 6 )
7 7
8 type ExportExchangeCashListCommand struct { 8 type ExportExchangeCashListCommand struct {
9 - IDs []int `json:"ids"` 9 + Ids []int `json:"ids"`
10 Where map[string]interface{} `json:"where"` 10 Where map[string]interface{} `json:"where"`
11 } 11 }
12 12
@@ -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,18 +949,10 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -991,18 +949,10 @@ 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{}{  
1003 - "account": createExchangeCashPersonCommand.PersonAccount,  
1004 - "companyId": activityFound.CompanyId,  
1005 - } 952 + // 获取员工查询条件
  953 + getEmployee := map[string]interface{}{
  954 + "account": createExchangeCashPersonCommand.PersonAccount,
  955 + "companyId": activityFound.CompanyId,
1006 } 956 }
1007 957
1008 // 判断当前员工是否有效 958 // 判断当前员工是否有效
@@ -1020,19 +970,436 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1020,19 +970,436 @@ 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 }
  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 { // 新增
  1127 + // 新增兑换清单命令
  1128 + newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)
  1129 +
  1130 + // 新增兑换素币清单命令
  1131 + newPerson := &domain.ExchangeCashPersonList{
  1132 + EmployeeInfo: &domain.EmployeeInfo{
  1133 + Uid: employeeFound.EmployeeInfo.Uid,
  1134 + EmployeeName: employeeFound.EmployeeInfo.EmployeeName,
  1135 + EmployeeAccount: employeeFound.EmployeeInfo.EmployeeAccount,
  1136 + },
  1137 + ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
  1138 + ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
  1139 + ExchangedCash: newPersonExchangedCash,
  1140 + }
  1141 +
  1142 + // 保存兑换素币清单
  1143 + personSaved, err := exchangeCashPersonListRepository.Save(newPerson)
  1144 + if err != nil {
  1145 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1146 + }
  1147 +
  1148 + // 操作素币命令
  1149 + operationSuMoneyCommand := &command.OperationSuMoneyCommand{
  1150 + Uid: employeeFound.EmployeeInfo.Uid,
  1151 + Operator: createExchangeCashPersonCommand.Operator,
  1152 + SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
  1153 + OperationType: 4,
  1154 + OperationDescription: "素币兑换现金",
  1155 + }
  1156 +
  1157 + // 操作素币,生成素币流水
  1158 + task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
  1159 + if err != nil {
  1160 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1161 + }
  1162 + if task == nil {
  1163 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
  1164 + }
  1165 +
  1166 + // 更新兑换活动命令
  1167 + updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
  1168 + ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
  1169 + ExchangeActivityName: activityFound.ExchangeActivityName,
  1170 + ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
  1171 + ExchangedCash: activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
  1172 + Deadline: activityFound.Deadline,
  1173 + CountDown: activityFound.CountDown,
  1174 + ExchangeRate: activityFound.Rate,
  1175 + }
  1176 +
  1177 + // 更新兑换活动
  1178 + if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
  1179 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  1180 + }
  1181 +
  1182 + // 保存兑换现金活动更新
  1183 + activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
  1184 + if err != nil {
  1185 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1186 + }
  1187 + if activityUpdated == nil {
  1188 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
  1189 + }
  1190 +
  1191 + // 获取当前现金池
  1192 + _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
  1193 + "companyId": activityFound.CompanyId,
  1194 + })
  1195 + if err != nil {
  1196 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1197 + }
  1198 + if len(cashPoolsFound) == 0 {
  1199 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "当前现金池为空,请先投入现金")
  1200 + }
  1201 +
  1202 + // 判断兑换活动的现金是否超过现金池未兑换现金
  1203 + if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
  1204 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
  1205 + }
  1206 +
  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 {
  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 + // }
  1398 + //}
1033 1399
1034 // 新增兑换清单命令 1400 // 新增兑换清单命令
1035 newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64) 1401 newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)
  1402 +
1036 newPerson := &domain.ExchangeCashPersonList{ 1403 newPerson := &domain.ExchangeCashPersonList{
1037 EmployeeInfo: &domain.EmployeeInfo{ 1404 EmployeeInfo: &domain.EmployeeInfo{
1038 Uid: employeeFound.EmployeeInfo.Uid, 1405 Uid: employeeFound.EmployeeInfo.Uid,
@@ -1093,16 +1460,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1093,16 +1460,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1093 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId))) 1460 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
1094 } 1461 }
1095 1462
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 // 获取当前现金池 1463 // 获取当前现金池
1107 _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{ 1464 _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
1108 "companyId": activityFound.CompanyId, 1465 "companyId": activityFound.CompanyId,
@@ -1119,17 +1476,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1119,17 +1476,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1119 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金") 1476 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
1120 } 1477 }
1121 1478
1122 - // 获取平台现金兑换情况  
1123 - //systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)  
1124 - //if err != nil {  
1125 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1126 - //}  
1127 - //if systemCashStatistics == nil {  
1128 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")  
1129 - //}  
1130 - //systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)  
1131 - //systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)  
1132 -  
1133 // 获取平台素币兑换情况 1479 // 获取平台素币兑换情况
1134 systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId) 1480 systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
1135 if err != nil { 1481 if err != nil {
@@ -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{}{
@@ -68,10 +68,13 @@ func (repository *ExchangeCashPersonListRepository) FindById(queryOptions map[st @@ -68,10 +68,13 @@ func (repository *ExchangeCashPersonListRepository) FindById(queryOptions map[st
68 if ids, ok := queryOptions["ids"]; ok && len(ids.([]int)) != 0 { 68 if ids, ok := queryOptions["ids"]; ok && len(ids.([]int)) != 0 {
69 query = query.Where("exchange_cash_person_list.id IN (?)", pg.In(ids.([]int)) ) 69 query = query.Where("exchange_cash_person_list.id IN (?)", pg.In(ids.([]int)) )
70 } 70 }
71 - // TODO 获取where条件  
72 - if where, ok := queryOptions["where"]; ok && where != nil {  
73 - query = query.Where(`exchange_cash_person_list.employee_name LIKE ?`, where.(map[string]interface{})["personNameMatch"])  
74 - query = query.Where("exchange_cash_person_list.activity_id = ?", where.(map[string]interface{})["activityId"]) 71 + if where, ok := queryOptions["where"]; ok && where.(map[string]interface{}) != nil {
  72 + if personNameMatch, ok := where.(map[string]interface{})["personNameMatch"]; ok && (personNameMatch != "") {
  73 + query = query.Where(`exchange_cash_person_list.employee_name LIKE ?`, fmt.Sprintf("%%%s%%", personNameMatch.(string)))
  74 + }
  75 + if activityId, ok := where.(map[string]interface{})["activityId"]; ok && activityId.(float64) != 0 {
  76 + query = query.Where("exchange_cash_person_list.activity_id = ?", activityId)
  77 + }
75 } 78 }
76 if count, err := query.Order("id DESC").SelectAndCount(); err != nil { 79 if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
77 return 0, exchangeCashPeople, err 80 return 0, exchangeCashPeople, err
@@ -137,6 +140,9 @@ func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string @@ -137,6 +140,9 @@ func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string
137 if personNameMatch, ok := queryOptions["exchangeCashPersonNameMatch"]; ok && (personNameMatch != ""){ 140 if personNameMatch, ok := queryOptions["exchangeCashPersonNameMatch"]; ok && (personNameMatch != ""){
138 query = query.Where("exchange_cash_person_list.employee_name LIKE ?", fmt.Sprintf("%%%s%%", personNameMatch.(string))) 141 query = query.Where("exchange_cash_person_list.employee_name LIKE ?", fmt.Sprintf("%%%s%%", personNameMatch.(string)))
139 } 142 }
  143 + if employeeAccount, ok := queryOptions["employeeAccount"]; ok && (employeeAccount != "") {
  144 + query = query.Where("exchange_cash_person_list.employee_account =?", employeeAccount)
  145 + }
140 if uid, ok := queryOptions["uid"]; ok { 146 if uid, ok := queryOptions["uid"]; ok {
141 query = query.Where("exchange_cash_person_list.uid = ?", uid) 147 query = query.Where("exchange_cash_person_list.uid = ?", uid)
142 } 148 }
@@ -397,55 +397,107 @@ func (controller *SuMoneyController) ImportExchangeList () { @@ -397,55 +397,107 @@ func (controller *SuMoneyController) ImportExchangeList () {
397 createExchangeCashPersonCommand := &command.CreateExchangeCashPersonCommand{} 397 createExchangeCashPersonCommand := &command.CreateExchangeCashPersonCommand{}
398 activityId, _ := controller.GetInt64("activityId") 398 activityId, _ := controller.GetInt64("activityId")
399 operator, _ := controller.GetInt64("operator") 399 operator, _ := controller.GetInt64("operator")
400 - file, h, _ := controller.GetFile("file") //获取上传的文件  
401 - ext := path.Ext(h.Filename) 400 + file, h, _ := controller.GetFile("file")
  401 +
  402 + // 错误信息返回
  403 + var response utils.JsonResponse
  404 +
  405 + // 返回字段定义
  406 + ret := map[string]interface{}{}
  407 +
  408 + // 返回信息表头定义
  409 + var tableHeader = [...]string{"错误详情", "员工姓名", "手机号", "已兑换素币"}
  410 +
402 // 文件后缀名校验 411 // 文件后缀名校验
  412 + ext := path.Ext(h.Filename)
403 AllowExtMap := map[string]bool{ 413 AllowExtMap := map[string]bool{
404 ".xlsx":true, 414 ".xlsx":true,
405 } 415 }
406 if _,ok:=AllowExtMap[ext];!ok{ 416 if _,ok:=AllowExtMap[ext];!ok{
407 - controller.Ctx.WriteString( "后缀名不符合上传要求" )  
408 - return 417 + err := fmt.Errorf("%s", "后缀名不符合上传要求")
  418 + response = utils.ResponseError(controller.Ctx, err)
  419 + controller.Data["json"] = response
  420 + controller.ServeJSON()
409 } 421 }
  422 +
410 xlsx, err := excelize.OpenReader(file) 423 xlsx, err := excelize.OpenReader(file)
411 if err != nil { 424 if err != nil {
412 fmt.Println(err) 425 fmt.Println(err)
413 return 426 return
414 } 427 }
415 - // 记录非空校验  
416 - var response utils.JsonResponse  
417 - dataList := make([]interface{}, 0) 428 +
  429 + // 文件行数校验
418 rows, _ := xlsx.GetRows("Sheet1") 430 rows, _ := xlsx.GetRows("Sheet1")
419 - if len(rows) > 1000 {  
420 - controller.Ctx.WriteString( "导入行数超过1000行" )  
421 - return 431 + if len(rows) > 302 {
  432 + err := fmt.Errorf("%s", "导入行数超过300行")
  433 + response = utils.ResponseError(controller.Ctx, err)
  434 + controller.Data["json"] = response
  435 + controller.ServeJSON()
422 } 436 }
  437 +
  438 + // 空行记录
  439 + nullLine := make([]interface{}, 0)
  440 +
  441 + // 单元格非空校验
423 for i, row := range rows { 442 for i, row := range rows {
424 if i > 2 { 443 if i > 2 {
425 for _, _ = range row { 444 for _, _ = range row {
426 - createExchangeCashPersonCommand.ExchangeCashActivityId = activityId  
427 r2, _ := strconv.ParseFloat(row[2], 64) 445 r2, _ := strconv.ParseFloat(row[2], 64)
428 if row[0] == "" || row[1] == "" || r2 == 0 { 446 if row[0] == "" || row[1] == "" || r2 == 0 {
429 - controller.Ctx.WriteString("单元格包含空字段")  
430 - return 447 + row = append(row, "单元格包含空字符")
  448 + nullLine = append(nullLine, row)
431 } 449 }
  450 + }
  451 + }
  452 + }
  453 + if len(nullLine) > 0 {
  454 + ret = map[string]interface{}{
  455 + "successCount": 0,
  456 + "fail": map[string]interface{}{
  457 + "tableHeader": tableHeader,
  458 + "tableData": nullLine,
  459 + },
  460 + }
  461 + response = utils.ResponseData(controller.Ctx, ret)
  462 + controller.Data["json"] = response
  463 + controller.ServeJSON()
  464 + }
  465 +
  466 + // 新增失败记录
  467 + failureDataList := make([]interface{}, 0)
  468 +
  469 + // 新增成功计数
  470 + var successDataCount int64
  471 +
  472 + for i, row := range rows {
  473 + if i > 2 {
  474 + for _, _ = range row {
  475 + r2, _ := strconv.ParseFloat(row[2], 64)
  476 + createExchangeCashPersonCommand.ExchangeCashActivityId = activityId
432 createExchangeCashPersonCommand.Operator = operator 477 createExchangeCashPersonCommand.Operator = operator
433 createExchangeCashPersonCommand.PersonName = row[0] 478 createExchangeCashPersonCommand.PersonName = row[0]
434 createExchangeCashPersonCommand.PersonAccount = row[1] 479 createExchangeCashPersonCommand.PersonAccount = row[1]
435 - createExchangeCashPersonCommand.ExchangedSuMoney, _ = strconv.ParseFloat(row[2], 64) 480 + createExchangeCashPersonCommand.ExchangedSuMoney = r2
436 } 481 }
437 - data, err := cashPoolService.CreateExchangeCashPerson(createExchangeCashPersonCommand)  
438 - if err != nil {  
439 - response = utils.ResponseError(controller.Ctx, err)  
440 - } else {  
441 - dataList = append(dataList, data) 482 + // 创建兑换素币清单
  483 + _, err := cashPoolService.ImportCreateExchangeCashPerson(createExchangeCashPersonCommand)
  484 + if err != nil { // 导入失败处理
  485 + rows[i] = append(rows[i], err.Error())
  486 + failureDataList = append(failureDataList, rows[i]) // 导入失败的记录
  487 + } else { // 导入成功处理
  488 + successDataCount += 1
442 } 489 }
443 } 490 }
444 } 491 }
445 - ret := map[string]interface{}{  
446 - "count": len(dataList),  
447 - "people": dataList, 492 +
  493 + ret = map[string]interface{}{
  494 + "successCount": successDataCount,
  495 + "fail": map[string]interface{}{
  496 + "tableHeader": tableHeader,
  497 + "tableData": failureDataList,
  498 + },
448 } 499 }
  500 +
449 response = utils.ResponseData(controller.Ctx, ret) 501 response = utils.ResponseData(controller.Ctx, ret)
450 controller.Data["json"] = response 502 controller.Data["json"] = response
451 controller.ServeJSON() 503 controller.ServeJSON()
@@ -514,18 +566,23 @@ func (controller *SuMoneyController) ExportExchangeList() { @@ -514,18 +566,23 @@ func (controller *SuMoneyController) ExportExchangeList() {
514 } 566 }
515 } 567 }
516 } 568 }
  569 +
517 f.SetActiveSheet(index) 570 f.SetActiveSheet(index)
  571 +
518 // 创建下载文件夹 572 // 创建下载文件夹
519 mkErr :=os.Mkdir("download", os.ModePerm) 573 mkErr :=os.Mkdir("download", os.ModePerm)
520 if err!=nil{ 574 if err!=nil{
521 fmt.Println(mkErr) 575 fmt.Println(mkErr)
522 } 576 }
  577 +
523 //保存为文件 578 //保存为文件
524 f.Path="download/素币兑换清单.xlsx" 579 f.Path="download/素币兑换清单.xlsx"
525 if err := f.Save(); err != nil { 580 if err := f.Save(); err != nil {
526 fmt.Println(err) 581 fmt.Println(err)
527 } 582 }
  583 +
528 controller.Ctx.Output.Download(f.Path,"素币兑换清单.xlsx") 584 controller.Ctx.Output.Download(f.Path,"素币兑换清单.xlsx")
  585 +
529 // 下载完成删除文件 586 // 下载完成删除文件
530 removeErr := os.Remove(f.Path) 587 removeErr := os.Remove(f.Path)
531 if err != nil { 588 if err != nil {
@@ -565,12 +622,15 @@ func (controller *SuMoneyController) ExportSuMoney() { @@ -565,12 +622,15 @@ func (controller *SuMoneyController) ExportSuMoney() {
565 } else { 622 } else {
566 // 新建文件 623 // 新建文件
567 f := excelize.NewFile() 624 f := excelize.NewFile()
  625 +
568 // 新建工作簿 626 // 新建工作簿
569 index := f.NewSheet("Sheet1") 627 index := f.NewSheet("Sheet1")
  628 +
570 //列标题赋值 629 //列标题赋值
571 for column, v := range titles { 630 for column, v := range titles {
572 f.SetCellValue("Sheet1", cells[column]+"1", v) 631 f.SetCellValue("Sheet1", cells[column]+"1", v)
573 } 632 }
  633 +
574 for lineNum, v := range data { //行数 lineNum 行内容 v 634 for lineNum, v := range data { //行数 lineNum 行内容 v
575 for columnNum := 0; columnNum < len(v); columnNum ++ { 635 for columnNum := 0; columnNum < len(v); columnNum ++ {
576 cell := cells[columnNum] 636 cell := cells[columnNum]
@@ -591,18 +651,23 @@ func (controller *SuMoneyController) ExportSuMoney() { @@ -591,18 +651,23 @@ func (controller *SuMoneyController) ExportSuMoney() {
591 } 651 }
592 } 652 }
593 } 653 }
  654 +
594 f.SetActiveSheet(index) 655 f.SetActiveSheet(index)
  656 +
595 // 创建下载文件夹 657 // 创建下载文件夹
596 mkErr :=os.Mkdir("download", os.ModePerm) 658 mkErr :=os.Mkdir("download", os.ModePerm)
597 if err!=nil{ 659 if err!=nil{
598 fmt.Println(mkErr) 660 fmt.Println(mkErr)
599 } 661 }
  662 +
600 //保存为文件 663 //保存为文件
601 f.Path="download/素币流水.xlsx" 664 f.Path="download/素币流水.xlsx"
602 if err := f.Save(); err != nil { 665 if err := f.Save(); err != nil {
603 fmt.Println(err) 666 fmt.Println(err)
604 } 667 }
  668 +
605 controller.Ctx.Output.Download(f.Path,"素币流水.xlsx") 669 controller.Ctx.Output.Download(f.Path,"素币流水.xlsx")
  670 +
606 // 下载完成删除文件 671 // 下载完成删除文件
607 removeErr := os.Remove(f.Path) 672 removeErr := os.Remove(f.Path)
608 if err != nil { 673 if err != nil {