...
|
...
|
@@ -2,7 +2,6 @@ package service |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/astaxie/beego"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"strconv"
|
|
|
"time"
|
...
|
...
|
@@ -59,22 +58,34 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
systemUnChangeSuMoney = value2
|
|
|
}
|
|
|
|
|
|
// TODO 获取上一个现金池现金值
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
cashPoolRepository = value
|
|
|
}
|
|
|
|
|
|
rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemChangedSuMoney), 64)
|
|
|
_, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
"companyId": createCashPoolCommand.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemChangedSuMoney), 64) // 平均兑换汇率
|
|
|
newCashPool := &domain.CashPool{
|
|
|
CompanyId: createCashPoolCommand.CompanyId,
|
|
|
Cash: createCashPoolCommand.Cash,
|
|
|
ExchangedCash: systemExchangedCash,
|
|
|
UnExchangeCash: createCashPoolCommand.Cash, // TODO 投入的现金 + 系统未兑换的现金
|
|
|
UnExchangeCash: createCashPoolCommand.Cash + cashPools[0].UnExchangeCash,
|
|
|
ExchangedSuMoney: systemChangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnChangeSuMoney,
|
|
|
Rate: rate,
|
|
|
CreateTime: time.Now(),
|
|
|
}
|
|
|
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
...
|
...
|
@@ -131,12 +142,9 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
|
|
|
|
// 新增兑换现金活动
|
|
|
func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchangeCashActivityCommand *command.CreateExchangeCashActivityCommand) (interface{}, error) {
|
|
|
// 校验新增任务命令
|
|
|
if err := createExchangeCashActivityCommand.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())
|
...
|
...
|
@@ -148,7 +156,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 创建兑换活动
|
|
|
newActivity := &domain.ExchangeCashActivity{
|
|
|
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
|
|
|
CompanyId: createExchangeCashActivityCommand.CompanyId,
|
...
|
...
|
@@ -160,7 +167,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
CreateTime: time.Now(),
|
|
|
}
|
|
|
|
|
|
// 兑换活动资源库
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -252,7 +258,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang |
|
|
if activity == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashActivityCommand.ActivityId)))
|
|
|
}
|
|
|
|
|
|
if activityDeleted, err := exchangeCashActivityRepository.Remove(activity); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -335,15 +340,12 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
if activity == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
if activity == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if activityUpdated, err := exchangeCashActivityRepository.Save(activity); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -383,7 +385,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
|
|
|
// TODO 新增兑换人员时,判断成员是否存在,以手机账号为判断依据
|
|
|
|
|
|
// 创建兑换清单
|
|
|
newPerson := &domain.ExchangeCashPersonList{
|
|
|
EmployeeInfo: &domain.EmployeeInfo{
|
|
|
EmployeeName: createExchangeCashPersonCommand.PersonName,
|
...
|
...
|
@@ -402,7 +403,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
} else {
|
|
|
exchangeCashPersonListRepository = value
|
|
|
}
|
|
|
|
|
|
if person, err := exchangeCashPersonListRepository.Save(newPerson); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -524,9 +524,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
if person == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
|
|
|
}
|
|
|
|
|
|
beego.Info(person)
|
|
|
|
|
|
if personDeleted, err := exchangeCashPersonListRepository.Remove(person); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
|