作者 陈志颖

fix:修复删除兑换清单

... ... @@ -102,24 +102,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
}
}
// 更新现金池
func (cashPoolService *CashPoolService) UpdateCashPool(updateCashPoolCommand *command.UpdateCashPoolCommand) (interface{}, error) {
if err := updateCashPoolCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
return nil , nil
}
// 返回现金池
func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetCashPoolQuery) (interface{}, error) {
if err := getCashPoolQuery.ValidateQuery(); err != nil {
... ... @@ -425,7 +407,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA
}
}
// TODO 更新兑换现金活动
// 更新兑换现金活动
func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchangeCashActivityCommand *command.UpdateExchangeCashActivityCommand) (interface{}, error) {
if err := updateExchangeCashActivityCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -613,7 +595,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
} else {
exchangeCashActivityRepository = value
}
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"exchangeCashActivityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -628,7 +610,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
employeeRepository = value
}
getEmployee := map[string]interface{}{}
if createExchangeCashPersonCommand.PersonName == "" {
if createExchangeCashPersonCommand.PersonAccount == "" {
getEmployee = map[string]interface{}{
"uid": createExchangeCashPersonCommand.Uid,
}
... ... @@ -637,6 +619,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
"account": createExchangeCashPersonCommand.PersonAccount,
}
}
fmt.Print(getEmployee, "\n")
employee, err := employeeRepository.FindOne(getEmployee)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -686,6 +669,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
OperationType: 3,
OperationDescription: "素币兑换现金",
}
fmt.Print(operationSuMoneyCommand, "\n")
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -693,6 +677,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
if task == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
}
fmt.Print(task, "\n")
// 更新兑换活动
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -946,6 +931,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
OperationType: 1,
OperationDescription: "素币兑换现金调整",
}
fmt.Print(removeExchangeCashPersonCommand.Operator, "\n")
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -1160,6 +1146,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
employeeDao = value
}
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
fmt.Print(activitySuMoney , "\n")
fmt.Print(updateExchangeCashActivityCommand.ExchangeRate, "\n")
fmt.Print(systemCashStatistics["systemUnExchangeCash"].(float64), "\n")
if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > systemCashStatistics["systemUnExchangeCash"].(float64) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
}
... ... @@ -1171,6 +1160,13 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
OperationType: 0,
OperationDescription: "参与兑换素币活动",
}
//if (person.ExchangedSuMoney - updateExchangeCashPersonCommand.ExchangedSuMoney) > 0 {
// operationSuMoneyCommand.SuMoney = math.Abs(person.ExchangedSuMoney - updateExchangeCashPersonCommand.ExchangedSuMoney)
// operationSuMoneyCommand.OperationType = 1
//} else {
// operationSuMoneyCommand.SuMoney = math.Abs(person.ExchangedSuMoney - updateExchangeCashPersonCommand.ExchangedSuMoney)
// operationSuMoneyCommand.OperationType = 3
//}
if updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney > 0 {
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
operationSuMoneyCommand.OperationType = 5
... ... @@ -1178,6 +1174,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
operationSuMoneyCommand.OperationType = 3
}
fmt.Print(updateExchangeCashPersonCommand.Operator, "\n")
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -1186,7 +1183,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
}
// 更新现金池
// 获取平台现金状况
newSystemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -15,7 +15,6 @@ type OperationSuMoneyService struct {
transactionContext *pgTransaction.TransactionContext
}
// TODO 增加兑换现金事务记录
func (service *OperationSuMoneyService) Operation(uid int64, operatorUid int64, suMoney float64, operationType int, recordDescription string) (*domain.SuMoneyTransactionRecord, error) {
var employeeRepository domain.EmployeeRepository
var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository
... ...
... ... @@ -37,7 +37,7 @@ func (repository *ExchangeCashPersonListRepository) FindOne(queryOptions map[str
tx := repository.transactionContext.PgTx
exchangeCashListModel := new(models.ExchangeCashPersonList)
query := tx.Model(exchangeCashListModel)
if exchangeCashListId, ok := queryOptions["listId"]; ok {
if exchangeCashListId, ok := queryOptions["id"]; ok {
query = query.Where("exchange_cash_person_list.id = ?", exchangeCashListId)
}
if err := query.First(); err != nil {
... ...
... ... @@ -287,7 +287,9 @@ func (controller *SuMoneyController) RemoveExchangeCashPerson() {
cashPoolService := service.NewCashPoolService(nil)
removeExchangeCashPersonCommand := &command.RemoveExchangeCashPersonCommand{}
personId, _ := controller.GetInt64(":listId")
operatorId, _ := controller.GetInt64("operator")
removeExchangeCashPersonCommand.ListId = personId
removeExchangeCashPersonCommand.Operator = operatorId
data, err := cashPoolService.RemoveExchangeCashPerson(removeExchangeCashPersonCommand)
var response utils.JsonResponse
if err != nil {
... ... @@ -321,6 +323,7 @@ func (controller *SuMoneyController) ImportExchangeList () {
cashPoolService := service.NewCashPoolService(nil)
createExchangeCashPersonCommand := &command.CreateExchangeCashPersonCommand{}
activityId, _ := controller.GetInt64("activityId")
operatorId, _ := controller.GetInt64("operatorId")
file, h, _ := controller.GetFile("file") //获取上传的文件
ext := path.Ext(h.Filename)
AllowExtMap := map[string]bool{
... ... @@ -339,9 +342,10 @@ func (controller *SuMoneyController) ImportExchangeList () {
dataList := make([]interface{}, 0)
rows, _ := xlsx.GetRows("Sheet1")
for i, row := range rows {
if i > 3 {
if i > 2 {
for _, _ = range row {
createExchangeCashPersonCommand.ExchangeCashActivityId = activityId
createExchangeCashPersonCommand.Operator = operatorId
createExchangeCashPersonCommand.PersonName = row[0]
createExchangeCashPersonCommand.PersonAccount = row[1]
createExchangeCashPersonCommand.ExchangedSuMoney, _ = strconv.ParseFloat(row[2], 64)
... ...