...
|
...
|
@@ -62,7 +62,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
|
|
|
// 现金池仓储初始化
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -97,19 +97,19 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) // 平台已兑换素币
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) // 平台未兑换素币
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) // 平台未兑换素币
|
|
|
|
|
|
// 获取当前公司现金池
|
|
|
count, cashPools, err := cashPoolRepository.Find(tool_funs.SimpleStructToMap(createCashPoolCommand))
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if len(cashPools) > 0 { // 更新现金池
|
|
|
if len(cashPools) > 0 { // 更新现金池
|
|
|
cashPoolExchangeCash := cashPools[0].ExchangedCash
|
|
|
cashPoolUnExchangeCash := cashPools[0].UnExchangeCash
|
|
|
cashPoolCash := cashPools[0].Cash
|
|
|
|
|
|
if createCashPoolCommand.Cash < cashPoolExchangeCash {
|
|
|
if createCashPoolCommand.Cash < cashPoolExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "投入的现金值必须大于当前已兑换现金值")
|
|
|
}
|
|
|
|
...
|
...
|
@@ -125,16 +125,16 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
var lastActivityRate float64
|
|
|
listExchangeCashActivityQuery := map[string]interface{}{
|
|
|
"companyId": createCashPoolCommand.CompanyId,
|
|
|
"order": "deadline DESC",
|
|
|
"nearest": true,
|
|
|
"limit": 1,
|
|
|
"order": "deadline DESC",
|
|
|
"nearest": true,
|
|
|
"limit": 1,
|
|
|
}
|
|
|
if _, activities, err := exchangeActivityRepository.Find(listExchangeCashActivityQuery); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if len(activities) > 0 {
|
|
|
lastActivityRate = activities[0].Rate
|
|
|
} else { // 未查询到相关兑换活动
|
|
|
} else { // 未查询到相关兑换活动
|
|
|
lastActivityRate = 0
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -143,15 +143,15 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
|
|
|
// 更新现金池命令
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPools[0].CashPoolId,
|
|
|
Cash: createCashPoolCommand.Cash,
|
|
|
CashPoolId: cashPools[0].CashPoolId,
|
|
|
Cash: createCashPoolCommand.Cash,
|
|
|
ExchangedCash: cashPoolExchangeCash,
|
|
|
//UnExchangeCash: cashPoolUnExchangeCash + (createCashPoolCommand.Cash - cashPoolCash),
|
|
|
UnExchangeCash: unExchangeCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeCash: unExchangeCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
|
|
LastRate: lastActivityRate,
|
|
|
Rate: newRate,
|
|
|
LastRate: lastActivityRate,
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
...
|
...
|
@@ -180,36 +180,36 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
cashPool.LastRate, _ = decimal.NewFromFloatWithExponent(cashPool.LastRate, -2).Float64()
|
|
|
return cashPool, nil
|
|
|
}
|
|
|
} else { // 新增现金池
|
|
|
} else { // 新增现金池
|
|
|
// 获取上次兑换活动兑换汇率查询
|
|
|
var lastActivityRate float64
|
|
|
listExchangeCashActivityQuery := map[string]interface{}{
|
|
|
"companyId": createCashPoolCommand.CompanyId,
|
|
|
"order": "deadline DESC",
|
|
|
"nearest": true,
|
|
|
"limit": 1,
|
|
|
"order": "deadline DESC",
|
|
|
"nearest": true,
|
|
|
"limit": 1,
|
|
|
}
|
|
|
if _, activities, err := exchangeActivityRepository.Find(listExchangeCashActivityQuery); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if len(activities) > 0 {
|
|
|
lastActivityRate = activities[0].Rate
|
|
|
} else { // 未查询到相关兑换活动
|
|
|
} else { // 未查询到相关兑换活动
|
|
|
lastActivityRate = 0
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
|
|
newCashPool := &domain.CashPool{
|
|
|
CompanyId: createCashPoolCommand.CompanyId,
|
|
|
Cash: createCashPoolCommand.Cash,
|
|
|
ExchangedCash: 0,
|
|
|
UnExchangeCash: createCashPoolCommand.Cash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
CompanyId: createCashPoolCommand.CompanyId,
|
|
|
Cash: createCashPoolCommand.Cash,
|
|
|
ExchangedCash: 0,
|
|
|
UnExchangeCash: createCashPoolCommand.Cash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
LastRate: lastActivityRate,
|
|
|
Rate: 0,
|
|
|
CreateTime: time.Now().Local(),
|
|
|
LastRate: lastActivityRate,
|
|
|
Rate: 0,
|
|
|
CreateTime: time.Now().Local(),
|
|
|
}
|
|
|
if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -271,7 +271,7 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
|
|
|
|
// 现金池仓储初始化
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -304,16 +304,16 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
|
var lastActivityRate float64
|
|
|
listExchangeCashActivityQuery := map[string]interface{}{
|
|
|
"companyId": getCashPoolQuery.CompanyId,
|
|
|
"order": "deadline DESC",
|
|
|
"nearest": true,
|
|
|
"limit": 1,
|
|
|
"order": "deadline DESC",
|
|
|
"nearest": true,
|
|
|
"limit": 1,
|
|
|
}
|
|
|
if _, activities, err := exchangeActivityRepository.Find(listExchangeCashActivityQuery); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if len(activities) > 0 {
|
|
|
lastActivityRate = activities[0].Rate
|
|
|
} else { // 未查询到相关兑换活动
|
|
|
} else { // 未查询到相关兑换活动
|
|
|
lastActivityRate = 0
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -327,7 +327,7 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
//systemUnExchangeSuMoney, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)), 64) // 平台未兑换素币
|
|
|
systemUnExchangeSuMoney, _ := decimal.NewFromFloatWithExponent(systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64), -2).Float64() // 平台未兑换素币
|
|
|
systemUnExchangeSuMoney, _ := decimal.NewFromFloatWithExponent(systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64), -2).Float64() // 平台未兑换素币
|
|
|
|
|
|
// 查找当前公司现金池
|
|
|
if count, cashPools, err := cashPoolRepository.Find(tool_funs.SimpleStructToMap(getCashPoolQuery)); err != nil {
|
...
|
...
|
@@ -338,17 +338,17 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
|
}
|
|
|
// 现金池为空时处理
|
|
|
if count == 0 {
|
|
|
return map[string] interface{} {
|
|
|
"cashPoolId": 0,
|
|
|
"cash": 0,
|
|
|
"companyId": getCashPoolQuery.CompanyId,
|
|
|
"exchangedCash": 0,
|
|
|
"unExchangeCash": 0,
|
|
|
"exchangedSuMoney": 0,
|
|
|
return map[string]interface{}{
|
|
|
"cashPoolId": 0,
|
|
|
"cash": 0,
|
|
|
"companyId": getCashPoolQuery.CompanyId,
|
|
|
"exchangedCash": 0,
|
|
|
"unExchangeCash": 0,
|
|
|
"exchangedSuMoney": 0,
|
|
|
"unExchangeSuMoney": systemUnExchangeSuMoney,
|
|
|
"rate": 0, // 平均兑换汇率
|
|
|
"lastRate": 0, // 上期活动兑换汇率
|
|
|
"createTime": time.Now().Local(),
|
|
|
"rate": 0, // 平均兑换汇率
|
|
|
"lastRate": 0, // 上期活动兑换汇率
|
|
|
"createTime": time.Now().Local(),
|
|
|
}, nil
|
|
|
} else {
|
|
|
//cashPools[0].Rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPools[0].Rate), 64)
|
...
|
...
|
@@ -426,13 +426,13 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
// 创建兑换活动命令
|
|
|
newActivity := &domain.ExchangeCashActivity{
|
|
|
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
|
|
|
CompanyId: createExchangeCashActivityCommand.CompanyId,
|
|
|
ExchangedCash: 0,
|
|
|
ExchangedSuMoney: 0,
|
|
|
Deadline: t2,
|
|
|
CountDown: int64(math.Ceil(t2.Sub(t1).Hours() / 24)), // 计算活动截止倒计时
|
|
|
Rate: createExchangeCashActivityCommand.ExchangeRate,
|
|
|
CreateTime: time.Now().Local(),
|
|
|
CompanyId: createExchangeCashActivityCommand.CompanyId,
|
|
|
ExchangedCash: 0,
|
|
|
ExchangedSuMoney: 0,
|
|
|
Deadline: t2,
|
|
|
CountDown: int64(math.Ceil(t2.Sub(t1).Hours() / 24)), // 计算活动截止倒计时
|
|
|
Rate: createExchangeCashActivityCommand.ExchangeRate,
|
|
|
CreateTime: time.Now().Local(),
|
|
|
}
|
|
|
|
|
|
// 倒计时结束判断
|
...
|
...
|
@@ -543,13 +543,13 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma |
|
|
var t2 = activity.Deadline
|
|
|
|
|
|
// 获取兑换活动前先更新兑换活动倒计时命令
|
|
|
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
|
|
|
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: activity.ActivityId,
|
|
|
CountDown: int64(math.Ceil(t2.Sub(t1).Hours() / 24)), // 计算倒计时
|
|
|
Deadline: activity.Deadline,
|
|
|
ExchangedSuMoney: activity.ExchangedSuMoney,
|
|
|
ExchangedCash: activity.ExchangedCash,
|
|
|
ExchangeRate: activity.Rate,
|
|
|
CountDown: int64(math.Ceil(t2.Sub(t1).Hours() / 24)), // 计算倒计时
|
|
|
Deadline: activity.Deadline,
|
|
|
ExchangedSuMoney: activity.ExchangedSuMoney,
|
|
|
ExchangedCash: activity.ExchangedCash,
|
|
|
ExchangeRate: activity.Rate,
|
|
|
}
|
|
|
|
|
|
// 倒计时结束处理
|
...
|
...
|
@@ -579,16 +579,16 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma |
|
|
//suMoney, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedSuMoney), 64)
|
|
|
cash, _ := decimal.NewFromFloatWithExponent(activity.ExchangedCash, -2).Float64()
|
|
|
suMoney, _ := decimal.NewFromFloatWithExponent(activity.ExchangedSuMoney, -2).Float64()
|
|
|
activityFormat := map[string]interface{} {
|
|
|
"activityId": activity.ActivityId,
|
|
|
activityFormat := map[string]interface{}{
|
|
|
"activityId": activity.ActivityId,
|
|
|
"exchangeActivityName": activity.ExchangeActivityName,
|
|
|
"companyId": activity.CompanyId,
|
|
|
"exchangedCash": cash,
|
|
|
"exchangedSuMoney": suMoney,
|
|
|
"deadline": activity.Deadline.Local(),
|
|
|
"countDown": activity.CountDown,
|
|
|
"rate": activity.Rate,
|
|
|
"createTime": activity.CreateTime.Local(),
|
|
|
"companyId": activity.CompanyId,
|
|
|
"exchangedCash": cash,
|
|
|
"exchangedSuMoney": suMoney,
|
|
|
"deadline": activity.Deadline.Local(),
|
|
|
"countDown": activity.CountDown,
|
|
|
"rate": activity.Rate,
|
|
|
"createTime": activity.CreateTime.Local(),
|
|
|
}
|
|
|
activitiesFormat = append(activitiesFormat, activityFormat)
|
|
|
}
|
...
|
...
|
@@ -598,7 +598,7 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma |
|
|
}
|
|
|
|
|
|
return map[string]interface{}{
|
|
|
"count": count,
|
|
|
"count": count,
|
|
|
"activities": activitiesFormat,
|
|
|
}, nil
|
|
|
}
|
...
|
...
|
@@ -633,12 +633,12 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
|
|
|
// 查找兑换现金活动
|
|
|
if count, activitiesFound, err := exchangeActivityRepository.Find(map[string]interface{}{
|
|
|
"companyId": listExchangeCashActivityQuery.CompanyId,
|
|
|
"companyId": listExchangeCashActivityQuery.CompanyId,
|
|
|
"activityNameMatch": listExchangeCashActivityQuery.ActivityNameMatch,
|
|
|
"offset": listExchangeCashActivityQuery.Offset,
|
|
|
"limit": listExchangeCashActivityQuery.Limit,
|
|
|
"countdown": 0,
|
|
|
"isEnd": listExchangeCashActivityQuery.IsEnd,
|
|
|
"offset": listExchangeCashActivityQuery.Offset,
|
|
|
"limit": listExchangeCashActivityQuery.Limit,
|
|
|
"countdown": 0,
|
|
|
"isEnd": listExchangeCashActivityQuery.IsEnd,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -647,13 +647,13 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
var t2 = activityFound.Deadline.Local()
|
|
|
|
|
|
// 更新兑换现金活动倒计时命令
|
|
|
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
|
|
|
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: activityFound.ActivityId,
|
|
|
CountDown: int64(math.Ceil(t2.Sub(t1).Hours() / 24)),
|
|
|
Deadline: activityFound.Deadline.Local(),
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
CountDown: int64(math.Ceil(t2.Sub(t1).Hours() / 24)),
|
|
|
Deadline: activityFound.Deadline.Local(),
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
}
|
|
|
|
|
|
// 倒计时结束处理
|
...
|
...
|
@@ -684,16 +684,16 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
//suMoney, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activityFound.ExchangedSuMoney), 64)
|
|
|
cash, _ := decimal.NewFromFloatWithExponent(activityFound.ExchangedCash, -2).Float64()
|
|
|
suMoney, _ := decimal.NewFromFloatWithExponent(activityFound.ExchangedSuMoney, -2).Float64()
|
|
|
activityWithTs := map[string]interface{} {
|
|
|
"activityId": activityFound.ActivityId,
|
|
|
activityWithTs := map[string]interface{}{
|
|
|
"activityId": activityFound.ActivityId,
|
|
|
"exchangeActivityName": activityFound.ExchangeActivityName,
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
"exchangedCash": cash,
|
|
|
"exchangedSuMoney": suMoney,
|
|
|
"deadline": activityFound.Deadline.Local().UnixNano() / 1e6, // 秒级时间戳转换
|
|
|
"countDown": activityFound.CountDown,
|
|
|
"rate": activityFound.Rate,
|
|
|
"createTime": activityFound.CreateTime.Local(),
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
"exchangedCash": cash,
|
|
|
"exchangedSuMoney": suMoney,
|
|
|
"deadline": activityFound.Deadline.Local().UnixNano() / 1e6, // 秒级时间戳转换
|
|
|
"countDown": activityFound.CountDown,
|
|
|
"rate": activityFound.Rate,
|
|
|
"createTime": activityFound.CreateTime.Local(),
|
|
|
}
|
|
|
activitiesWithTs = append(activitiesWithTs, activityWithTs)
|
|
|
}
|
...
|
...
|
@@ -703,7 +703,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
}
|
|
|
|
|
|
return map[string]interface{}{
|
|
|
"count": count,
|
|
|
"count": count,
|
|
|
"activities": activitiesWithTs,
|
|
|
}, nil
|
|
|
}
|
...
|
...
|
@@ -798,13 +798,13 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA |
|
|
var t2 = activityFound.Deadline
|
|
|
|
|
|
// 更新兑换现金活动倒计时命令
|
|
|
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
|
|
|
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: activityFound.ActivityId,
|
|
|
CountDown: int64(math.Ceil(t2.Sub(t1).Hours() / 24)),
|
|
|
Deadline: activityFound.Deadline,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
CountDown: int64(math.Ceil(t2.Sub(t1).Hours() / 24)),
|
|
|
Deadline: activityFound.Deadline,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
}
|
|
|
|
|
|
// 倒计时结束处理
|
...
|
...
|
@@ -877,7 +877,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
|
|
|
// 现金池仓储初始化
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -903,8 +903,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
if activityFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
activityFoundExchangedSuMoney := activityFound.ExchangedSuMoney // 当前活动已兑换素币
|
|
|
activityFoundExchangedCash := activityFound.ExchangedCash // 当前活动已兑换现金
|
|
|
activityFoundExchangedSuMoney := activityFound.ExchangedSuMoney // 当前活动已兑换素币
|
|
|
activityFoundExchangedCash := activityFound.ExchangedCash // 当前活动已兑换现金
|
|
|
|
|
|
// 获取当前公司现金池
|
|
|
cashPoolFound, err := cashPoolRepository.FindOne(map[string]interface{}{
|
...
|
...
|
@@ -968,9 +968,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
// 获取当前兑换活动汇率
|
|
|
activityFoundRate := activityFound.Rate
|
|
|
|
|
|
if updateExchangeCashActivityCommand.ExchangeRate != activityFoundRate && updateExchangeCashActivityCommand.ExchangeRate != 0 { // 更新兑换活动兑换汇率
|
|
|
if updateExchangeCashActivityCommand.ExchangeRate != activityFoundRate && updateExchangeCashActivityCommand.ExchangeRate != 0 { // 更新兑换活动兑换汇率
|
|
|
// 判断兑换活动清单中现金总金额是否超过平台未兑换现金值
|
|
|
if activityFoundExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolFoundUnExchangeCash {
|
|
|
if activityFoundExchangedSuMoney*updateExchangeCashActivityCommand.ExchangeRate > cashPoolFoundUnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
|
}
|
|
|
|
...
|
...
|
@@ -988,9 +988,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
|
|
|
// 更新兑换清单命令
|
|
|
exchangeCash, _ := decimal.NewFromFloat(updateExchangeCashActivityCommand.ExchangeRate).Mul(decimal.NewFromFloat(personFoundExchangedSuMoney)).Float64()
|
|
|
updateExchangeCashPerson := &command.UpdateExchangeCashPersonCommand {
|
|
|
updateExchangeCashPerson := &command.UpdateExchangeCashPersonCommand{
|
|
|
//ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * personFoundExchangedSuMoney,
|
|
|
ExchangedCash: exchangeCash,
|
|
|
ExchangedCash: exchangeCash,
|
|
|
ExchangedSuMoney: personFoundExchangedSuMoney,
|
|
|
}
|
|
|
|
...
|
...
|
@@ -1000,7 +1000,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
}
|
|
|
|
|
|
// 保存素币兑换清单更新
|
|
|
if _, err := exchangeCashPersonListRepository.Save(personFound);err != nil {
|
|
|
if _, err := exchangeCashPersonListRepository.Save(personFound); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -1034,16 +1034,16 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
exchangedCash, _ := decimal.NewFromFloat(cashPoolFoundExchangedCash).Add(decimal.NewFromFloat(updateExchangeCashActivityCommand.ExchangedCash).Sub(decimal.NewFromFloat(activityFoundExchangedCash))).Float64()
|
|
|
unExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Sub(decimal.NewFromFloat(updateExchangeCashActivityCommand.ExchangedCash).Sub(decimal.NewFromFloat(activityFoundExchangedCash))).Float64()
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolFound.CashPoolId,
|
|
|
CashPoolId: cashPoolFound.CashPoolId,
|
|
|
//ExchangedCash: cashPoolFoundExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFoundExchangedCash),
|
|
|
//UnExchangeCash: cashPoolFoundUnExchangeCash - (updateExchangeCashActivityCommand.ExchangedCash - activityFoundExchangedCash),
|
|
|
ExchangedCash: exchangedCash,
|
|
|
UnExchangeCash: unExchangeCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: rate,
|
|
|
LastRate: cashPoolFound.LastRate,
|
|
|
Cash: cashPoolFound.Cash,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
UnExchangeCash: unExchangeCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: rate,
|
|
|
LastRate: cashPoolFound.LastRate,
|
|
|
Cash: cashPoolFound.Cash,
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
...
|
...
|
@@ -1169,7 +1169,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
|
|
|
// 现金池仓储初始化
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -1218,9 +1218,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
activityFoundExchangedSuMoney := activityFound.ExchangedSuMoney
|
|
|
activityFoundExchangedCash := activityFound.ExchangedCash
|
|
|
|
|
|
// TODO 更改:根据uid和companyId,判断当前员工是否有效
|
|
|
//更改:根据uid和companyId,判断当前员工是否有效
|
|
|
getEmployee := map[string]interface{}{
|
|
|
"account": personFound.EmployeeInfo.EmployeeAccount,
|
|
|
"uid": personFound.EmployeeInfo.Uid,
|
|
|
//"account": personFound.EmployeeInfo.EmployeeAccount,
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
}
|
|
|
employeeFound, err := employeeRepository.FindOne(getEmployee)
|
...
|
...
|
@@ -1257,15 +1258,15 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
// 更新素币兑换活动命令
|
|
|
exchangedSuMoney, _ := decimal.NewFromFloat(activityFoundExchangedSuMoney).Add(decimal.NewFromFloat(updateExchangeCashPersonCommand.ExchangedSuMoney).Sub(decimal.NewFromFloat(personFoundExchangedSuMoney))).Float64()
|
|
|
exchangedCash, _ := decimal.NewFromFloat(activityFoundExchangedCash).Add(decimal.NewFromFloat(updateExchangeCashPersonCommand.ExchangedSuMoney).Sub(decimal.NewFromFloat(personFoundExchangedSuMoney)).Mul(decimal.NewFromFloat(activityFound.Rate))).Float64()
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personFound.ExchangeCashActivityId,
|
|
|
//ExchangedSuMoney: activityFoundExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney),
|
|
|
//ExchangedCash: activityFoundExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
|
|
|
ExchangedSuMoney: exchangedSuMoney,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
ExchangedSuMoney: exchangedSuMoney,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
}
|
|
|
|
|
|
// 操作素币服务以及生成素币兑换流水记录命令
|
...
|
...
|
@@ -1278,11 +1279,11 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
}
|
|
|
|
|
|
// 判断操作素币类型
|
|
|
if updateExchangeCashPersonCommand.ExchangedSuMoney > personFoundExchangedSuMoney { // 追加素币兑换
|
|
|
if updateExchangeCashPersonCommand.ExchangedSuMoney > personFoundExchangedSuMoney { // 追加素币兑换
|
|
|
//operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
|
|
|
operationSuMoneyCommand.SuMoney, _ = decimal.NewFromFloat(updateExchangeCashPersonCommand.ExchangedSuMoney).Sub(decimal.NewFromFloat(personFoundExchangedSuMoney)).Abs().Float64()
|
|
|
operationSuMoneyCommand.OperationType = 4
|
|
|
} else { // 撤回素币兑换
|
|
|
} else { // 撤回素币兑换
|
|
|
//operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
|
|
|
operationSuMoneyCommand.SuMoney, _ = decimal.NewFromFloat(updateExchangeCashPersonCommand.ExchangedSuMoney).Sub(decimal.NewFromFloat(personFoundExchangedSuMoney)).Abs().Float64()
|
|
|
operationSuMoneyCommand.OperationType = 41
|
...
|
...
|
@@ -1338,7 +1339,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
|
|
|
// 判断是否超过平台未兑换现金
|
|
|
if activityUpdated.ExchangedSuMoney > activityFoundExchangedSuMoney {
|
|
|
if (activityUpdated.ExchangedSuMoney - activityFoundExchangedSuMoney) * activityUpdated.Rate > cashPoolFoundUnExchangeCash {
|
|
|
if (activityUpdated.ExchangedSuMoney-activityFoundExchangedSuMoney)*activityUpdated.Rate > cashPoolFoundUnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -1359,15 +1360,15 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
// 更新现金池命令
|
|
|
unExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Sub((decimal.NewFromFloat(updateExchangeCashPersonCommand.ExchangedSuMoney).Sub(decimal.NewFromFloat(personFoundExchangedSuMoney))).Mul(decimal.NewFromFloat(activityUpdated.Rate))).Float64()
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolFound.CashPoolId,
|
|
|
Cash: cashPoolFound.Cash,
|
|
|
ExchangedCash: systemExchangedCash,
|
|
|
CashPoolId: cashPoolFound.CashPoolId,
|
|
|
Cash: cashPoolFound.Cash,
|
|
|
ExchangedCash: systemExchangedCash,
|
|
|
//UnExchangeCash: cashPoolFoundUnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityUpdated.Rate,
|
|
|
UnExchangeCash: unExchangeCash,
|
|
|
Rate: newRate,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
LastRate: cashPoolFound.LastRate,
|
|
|
LastRate: cashPoolFound.LastRate,
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
...
|
...
|
@@ -1443,7 +1444,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
|
|
|
// 现金池仓储初始化
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return []interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -1505,8 +1506,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
failureDataList = append(failureDataList, row)
|
|
|
continue
|
|
|
}
|
|
|
activityFoundExchangedSuMoney := activityFound.ExchangedSuMoney // 当前兑换活动未兑换素币
|
|
|
activityFoundExchangedCash := activityFound.ExchangedCash // 当前兑换活动已兑换素币
|
|
|
activityFoundExchangedSuMoney := activityFound.ExchangedSuMoney // 当前兑换活动未兑换素币
|
|
|
activityFoundExchangedCash := activityFound.ExchangedCash // 当前兑换活动已兑换素币
|
|
|
|
|
|
// 获取当前公司现金池
|
|
|
cashPoolFound, err := cashPoolRepository.FindOne(map[string]interface{}{
|
...
|
...
|
@@ -1532,12 +1533,13 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
failureDataList = append(failureDataList, row)
|
|
|
continue
|
|
|
}
|
|
|
cashPoolFoundUnExchangeCash := cashPoolFound.UnExchangeCash // 当前公司现金池未兑换现金
|
|
|
cashPoolFoundExchangedCash := cashPoolFound.ExchangedCash // 当前公司现金池已兑换现金
|
|
|
cashPoolFoundUnExchangeCash := cashPoolFound.UnExchangeCash // 当前公司现金池未兑换现金
|
|
|
cashPoolFoundExchangedCash := cashPoolFound.ExchangedCash // 当前公司现金池已兑换现金
|
|
|
|
|
|
// TODO 更改:根据uid和companyId,判断当前员工是否有效
|
|
|
// 更改:根据uid、account和companyId,判断当前员工是否有效(身份有效、手机账号有效)
|
|
|
getEmployee := map[string]interface{}{
|
|
|
"account": createExchangeCashPersonCommand.PersonAccount,
|
|
|
"uid": createExchangeCashPersonCommand.Uid,
|
|
|
"account": createExchangeCashPersonCommand.PersonAccount,
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
}
|
|
|
employeeFound, err := employeeRepository.FindOne(getEmployee)
|
...
|
...
|
@@ -1561,14 +1563,15 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
failureDataList = append(failureDataList, row)
|
|
|
continue
|
|
|
}
|
|
|
employeeFoundSuMoney := employeeFound.SuMoney // 当前导入员工持有的素币值
|
|
|
employeeFoundSuMoney := employeeFound.SuMoney // 当前导入员工持有的素币值
|
|
|
|
|
|
// TODO 更改:根据uid和activityId判断当前员工是否已经在素币兑换清单中,
|
|
|
// 更改:根据uid、employeeAccount和activityId判断当前员工是否已经在素币兑换清单中,
|
|
|
personFound, _ := exchangeCashPersonListRepository.FindOne(map[string]interface{}{
|
|
|
"uid": employeeFound.EmployeeInfo.Uid,
|
|
|
"employeeAccount": employeeFound.EmployeeInfo.EmployeeAccount,
|
|
|
"activityId": activityFound.ActivityId,
|
|
|
"activityId": activityFound.ActivityId,
|
|
|
})
|
|
|
if personFound == nil { // 当前人员不在兑换素币清单中,新增兑换素币清单
|
|
|
if personFound == nil { // 当前人员不在兑换素币清单中,新增兑换素币清单
|
|
|
// 判断该员工兑换的素币是否超过本人持有的素币
|
|
|
if createExchangeCashPersonCommand.ExchangedSuMoney > employeeFoundSuMoney {
|
|
|
row := []interface{}{
|
...
|
...
|
@@ -1591,8 +1594,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
EmployeeAccount: employeeFound.EmployeeInfo.EmployeeAccount,
|
|
|
},
|
|
|
ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: newPersonExchangedCash,
|
|
|
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: newPersonExchangedCash,
|
|
|
}
|
|
|
personSaved, err := exchangeCashPersonListRepository.Save(newPerson)
|
|
|
if err != nil {
|
...
|
...
|
@@ -1617,11 +1620,11 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
}
|
|
|
|
|
|
// 操作素币,生成素币流水
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
Uid: employeeFound.EmployeeInfo.Uid,
|
|
|
Operator: createExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
OperationType: 4, // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
|
|
|
OperationType: 4, // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
|
|
|
OperationDescription: "参与" + activityFound.ExchangeActivityName,
|
|
|
}
|
|
|
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
...
|
...
|
@@ -1649,16 +1652,16 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
// 更新兑换活动
|
|
|
exchangedSuMoney, _ := decimal.NewFromFloat(activityFoundExchangedSuMoney).Add(decimal.NewFromFloat(createExchangeCashPersonCommand.ExchangedSuMoney)).Float64()
|
|
|
exchangedCash, _ := decimal.NewFromFloat(activityFoundExchangedCash).Add(decimal.NewFromFloat(createExchangeCashPersonCommand.ExchangedSuMoney).Mul(decimal.NewFromFloat(activityFound.Rate))).Float64()
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
|
|
|
ExchangeActivityName: activityFound.ExchangeActivityName,
|
|
|
//ExchangedSuMoney: activityFoundExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
//ExchangedCash: activityFoundExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
ExchangedSuMoney: exchangedSuMoney,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
ExchangedSuMoney: exchangedSuMoney,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
}
|
|
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
row := []interface{}{
|
...
|
...
|
@@ -1693,7 +1696,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
}
|
|
|
|
|
|
// 判断是否超过平台未兑换现金
|
|
|
if createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate > cashPoolFoundUnExchangeCash {
|
|
|
if createExchangeCashPersonCommand.ExchangedSuMoney*activityFound.Rate > cashPoolFoundUnExchangeCash {
|
|
|
row := []interface{}{
|
|
|
createExchangeCashPersonCommand.PersonName,
|
|
|
createExchangeCashPersonCommand.PersonAccount,
|
...
|
...
|
@@ -1727,7 +1730,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
continue
|
|
|
}
|
|
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) // 公司已兑换素币
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) // 公司未兑换素币
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) // 公司未兑换素币
|
|
|
|
|
|
// 更新现金池
|
|
|
var newRate float64
|
...
|
...
|
@@ -1737,19 +1740,19 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
//newRate = (cashPoolFoundExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney
|
|
|
newRate, _ = decimal.NewFromFloat(cashPoolFoundExchangedCash).Add(decimal.NewFromFloat(personSaved.ExchangedCash)).Div(decimal.NewFromFloat(systemExchangedSuMoney)).Float64()
|
|
|
}
|
|
|
newExchangedCash, _ := decimal.NewFromFloat(cashPoolFoundExchangedCash).Add(decimal.NewFromFloat(personSaved.ExchangedCash)).Float64()
|
|
|
unExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Sub(decimal.NewFromFloat(personSaved.ExchangedCash)).Float64()
|
|
|
newExchangedCash, _ := decimal.NewFromFloat(cashPoolFoundExchangedCash).Add(decimal.NewFromFloat(personSaved.ExchangedCash)).Float64()
|
|
|
unExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Sub(decimal.NewFromFloat(personSaved.ExchangedCash)).Float64()
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolFound.CashPoolId,
|
|
|
Cash: cashPoolFound.Cash,
|
|
|
CashPoolId: cashPoolFound.CashPoolId,
|
|
|
Cash: cashPoolFound.Cash,
|
|
|
//ExchangedCash: cashPoolFoundExchangedCash + personSaved.ExchangedCash,
|
|
|
//UnExchangeCash: cashPoolFoundUnExchangeCash - personSaved.ExchangedCash,
|
|
|
ExchangedCash: newExchangedCash,
|
|
|
ExchangedCash: newExchangedCash,
|
|
|
UnExchangeCash: unExchangeCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
|
|
LastRate: cashPoolFound.LastRate,
|
|
|
LastRate: cashPoolFound.LastRate,
|
|
|
}
|
|
|
if err := cashPoolFound.Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
row := []interface{}{
|
...
|
...
|
@@ -1782,10 +1785,10 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
failureDataList = append(failureDataList, row)
|
|
|
continue
|
|
|
}
|
|
|
} else { // 当前人员存在兑换素币清单中
|
|
|
personFoundExchangedSuMoney := personFound.ExchangedSuMoney // 当前素币清单已兑换素币
|
|
|
personFoundExchangedCash := personFound.ExchangedCash // 当前素币清单已兑换现金
|
|
|
if createExchangeCashPersonCommand.ExchangedSuMoney < personFoundExchangedSuMoney { // 当前兑换的素币小于本人已兑换素币,撤回兑换素币
|
|
|
} else { // 当前人员存在兑换素币清单中
|
|
|
personFoundExchangedSuMoney := personFound.ExchangedSuMoney // 当前素币清单已兑换素币
|
|
|
personFoundExchangedCash := personFound.ExchangedCash // 当前素币清单已兑换现金
|
|
|
if createExchangeCashPersonCommand.ExchangedSuMoney < personFoundExchangedSuMoney { // 当前兑换的素币小于本人已兑换素币,撤回兑换素币
|
|
|
// 素币减量
|
|
|
//suMoneyDecrement := personFoundExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney
|
|
|
suMoneyDecrement, _ := decimal.NewFromFloat(personFoundExchangedSuMoney).Sub(decimal.NewFromFloat(createExchangeCashPersonCommand.ExchangedSuMoney)).Float64()
|
...
|
...
|
@@ -1796,14 +1799,14 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
|
|
|
// 更新兑换素币清单
|
|
|
exchangedSuMoney, _ := decimal.NewFromFloat(personFoundExchangedSuMoney).Sub(decimal.NewFromFloat(suMoneyDecrement)).Float64()
|
|
|
exchangedCash, _ := decimal.NewFromFloat(personFoundExchangedCash).Sub(decimal.NewFromFloat(cashDecrement)).Float64()
|
|
|
exchangedCash, _ := decimal.NewFromFloat(personFoundExchangedCash).Sub(decimal.NewFromFloat(cashDecrement)).Float64()
|
|
|
updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{
|
|
|
ListId: personFound.ListId,
|
|
|
ListId: personFound.ListId,
|
|
|
//ExchangedSuMoney: personFoundExchangedSuMoney - suMoneyDecrement,
|
|
|
//ExchangedCash: personFoundExchangedCash - cashDecrement,
|
|
|
ExchangedSuMoney: exchangedSuMoney,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Operator: createExchangeCashPersonCommand.Operator,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Operator: createExchangeCashPersonCommand.Operator,
|
|
|
}
|
|
|
if err := personFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
|
|
row := []interface{}{
|
...
|
...
|
@@ -1838,17 +1841,17 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
}
|
|
|
|
|
|
// 更新素币兑换活动
|
|
|
newExchangedSuMoney, _ := decimal.NewFromFloat(activityFoundExchangedSuMoney).Sub(decimal.NewFromFloat(suMoneyDecrement)).Float64()
|
|
|
newExchangedSuMoney, _ := decimal.NewFromFloat(activityFoundExchangedSuMoney).Sub(decimal.NewFromFloat(suMoneyDecrement)).Float64()
|
|
|
newExchangedCash, _ := decimal.NewFromFloat(activityFoundExchangedCash).Sub(decimal.NewFromFloat(cashDecrement)).Float64()
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personFound.ExchangeCashActivityId,
|
|
|
//ExchangedSuMoney: activityFoundExchangedSuMoney - suMoneyDecrement,
|
|
|
//ExchangedCash: activityFoundExchangedCash - cashDecrement,
|
|
|
ExchangedSuMoney: newExchangedSuMoney,
|
|
|
ExchangedCash: newExchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
ExchangedSuMoney: newExchangedSuMoney,
|
|
|
ExchangedCash: newExchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
}
|
|
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
row := []interface{}{
|
...
|
...
|
@@ -1887,7 +1890,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
Uid: employeeFound.EmployeeInfo.Uid,
|
|
|
Operator: createExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: suMoneyDecrement,
|
|
|
OperationType: 41, // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
|
|
|
OperationType: 41, // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
|
|
|
OperationDescription: activityFound.ExchangeActivityName + "调整",
|
|
|
}
|
|
|
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
...
|
...
|
@@ -1935,7 +1938,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
continue
|
|
|
}
|
|
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) // 公司已兑换素币
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) // 公司未兑换素币
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) // 公司未兑换素币
|
|
|
|
|
|
// 更新现金池
|
|
|
var newRate float64
|
...
|
...
|
@@ -1948,8 +1951,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
cashPoolExchangedCash, _ := decimal.NewFromFloat(cashPoolFoundExchangedCash).Sub(decimal.NewFromFloat(cashDecrement)).Float64()
|
|
|
unExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Add(decimal.NewFromFloat(cashDecrement)).Float64()
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolFound.CashPoolId,
|
|
|
Cash: cashPoolFound.Cash,
|
|
|
CashPoolId: cashPoolFound.CashPoolId,
|
|
|
Cash: cashPoolFound.Cash,
|
|
|
//ExchangedCash: cashPoolFoundExchangedCash - cashDecrement,
|
|
|
//UnExchangeCash: cashPoolFoundUnExchangeCash + cashDecrement,
|
|
|
ExchangedCash: cashPoolExchangedCash,
|
...
|
...
|
@@ -1957,7 +1960,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
|
|
LastRate: cashPoolFound.LastRate,
|
|
|
LastRate: cashPoolFound.LastRate,
|
|
|
}
|
|
|
if err := cashPoolFound.Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
row := []interface{}{
|
...
|
...
|
@@ -1990,7 +1993,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
failureDataList = append(failureDataList, row)
|
|
|
continue
|
|
|
}
|
|
|
} else { // 当前兑换素币大于等于已兑换素币,追加兑换素币
|
|
|
} else { // 当前兑换素币大于等于已兑换素币,追加兑换素币
|
|
|
// 素币增量
|
|
|
//suMoneyIncrement := createExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney
|
|
|
suMoneyIncrement, _ := decimal.NewFromFloat(createExchangeCashPersonCommand.ExchangedSuMoney).Sub(decimal.NewFromFloat(personFoundExchangedSuMoney)).Float64()
|
...
|
...
|
@@ -2014,12 +2017,12 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
exchangedSuMoney, _ := decimal.NewFromFloat(personFoundExchangedSuMoney).Add(decimal.NewFromFloat(suMoneyIncrement)).Float64()
|
|
|
exchangedCash, _ := decimal.NewFromFloat(personFoundExchangedCash).Add(decimal.NewFromFloat(cashIncrement)).Float64()
|
|
|
updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{
|
|
|
ListId: personFound.ListId,
|
|
|
ListId: personFound.ListId,
|
|
|
//ExchangedSuMoney: personFoundExchangedSuMoney + suMoneyIncrement,
|
|
|
//ExchangedCash: personFoundExchangedCash + cashIncrement,
|
|
|
ExchangedSuMoney: exchangedSuMoney,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Operator: createExchangeCashPersonCommand.Operator,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Operator: createExchangeCashPersonCommand.Operator,
|
|
|
}
|
|
|
if err := personFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
|
|
row := []interface{}{
|
...
|
...
|
@@ -2060,11 +2063,11 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
ExchangeCashActivityId: personFound.ExchangeCashActivityId,
|
|
|
//ExchangedSuMoney: activityFoundExchangedSuMoney + suMoneyIncrement,
|
|
|
//ExchangedCash: activityFoundExchangedCash + cashIncrement,
|
|
|
ExchangedSuMoney: newExchangedSuMoney,
|
|
|
ExchangedCash: newExchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
ExchangedSuMoney: newExchangedSuMoney,
|
|
|
ExchangedCash: newExchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
}
|
|
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
row := []interface{}{
|
...
|
...
|
@@ -2103,7 +2106,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
Uid: employeeFound.EmployeeInfo.Uid,
|
|
|
Operator: createExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: suMoneyIncrement,
|
|
|
OperationType: 4, // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
|
|
|
OperationType: 4, // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
|
|
|
OperationDescription: activityFound.ExchangeActivityName + "调整",
|
|
|
}
|
|
|
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
...
|
...
|
@@ -2176,8 +2179,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
newCashPoolExchangedCash, _ := decimal.NewFromFloat(cashPoolFoundExchangedCash).Add(decimal.NewFromFloat(cashIncrement)).Float64()
|
|
|
unExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Sub(decimal.NewFromFloat(cashIncrement)).Float64()
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolFound.CashPoolId,
|
|
|
Cash: cashPoolFound.Cash,
|
|
|
CashPoolId: cashPoolFound.CashPoolId,
|
|
|
Cash: cashPoolFound.Cash,
|
|
|
//ExchangedCash: cashPoolFoundExchangedCash + cashIncrement,
|
|
|
//UnExchangeCash: cashPoolFoundUnExchangeCash - cashIncrement,
|
|
|
ExchangedCash: newCashPoolExchangedCash,
|
...
|
...
|
@@ -2185,7 +2188,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
|
|
LastRate: cashPoolFound.LastRate,
|
|
|
LastRate: cashPoolFound.LastRate,
|
|
|
}
|
|
|
if err := cashPoolFound.Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
row := []interface{}{
|
...
|
...
|
@@ -2271,7 +2274,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
|
|
|
// 现金池仓储初始化
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -2319,7 +2322,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
|
|
|
// 判断当前员工是否有效
|
|
|
getEmployee := map[string]interface{}{
|
|
|
"uid": createExchangeCashPersonCommand.Uid,
|
|
|
"uid": createExchangeCashPersonCommand.Uid,
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
}
|
|
|
employeeFound, err := employeeRepository.FindOne(getEmployee)
|
...
|
...
|
@@ -2334,7 +2337,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
// 判断当前员工是否已经存在兑换素币清单中
|
|
|
if _, people, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
|
|
|
"exchangeCashActivityId": activityFound.ActivityId,
|
|
|
"uid": employeeFound.EmployeeInfo.Uid,
|
|
|
"uid": employeeFound.EmployeeInfo.Uid,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -2358,8 +2361,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
EmployeeAccount: employeeFound.EmployeeInfo.EmployeeAccount,
|
|
|
},
|
|
|
ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: newPersonExchangedCash,
|
|
|
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: newPersonExchangedCash,
|
|
|
}
|
|
|
|
|
|
// 保存兑换素币清单
|
...
|
...
|
@@ -2369,7 +2372,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
}
|
|
|
|
|
|
// 操作素币命令
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
Uid: employeeFound.EmployeeInfo.Uid,
|
|
|
Operator: createExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
...
|
...
|
@@ -2387,18 +2390,18 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
}
|
|
|
|
|
|
// 更新兑换活动命令
|
|
|
exchangedSuMoney, _ := decimal.NewFromFloat(activityFoundExchangedSuMoney).Add(decimal.NewFromFloat(createExchangeCashPersonCommand.ExchangedSuMoney)).Float64()
|
|
|
exchangedCash, _ := decimal.NewFromFloat(activityFoundExchangedCash).Add(decimal.NewFromFloat(createExchangeCashPersonCommand.ExchangedSuMoney).Mul(decimal.NewFromFloat(activityFound.Rate))).Float64()
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
exchangedSuMoney, _ := decimal.NewFromFloat(activityFoundExchangedSuMoney).Add(decimal.NewFromFloat(createExchangeCashPersonCommand.ExchangedSuMoney)).Float64()
|
|
|
exchangedCash, _ := decimal.NewFromFloat(activityFoundExchangedCash).Add(decimal.NewFromFloat(createExchangeCashPersonCommand.ExchangedSuMoney).Mul(decimal.NewFromFloat(activityFound.Rate))).Float64()
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
|
|
|
ExchangeActivityName: activityFound.ExchangeActivityName,
|
|
|
//ExchangedSuMoney: activityFoundExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
//ExchangedCash: activityFoundExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
ExchangedSuMoney: exchangedSuMoney,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
ExchangedSuMoney: exchangedSuMoney,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
}
|
|
|
|
|
|
// 更新兑换活动
|
...
|
...
|
@@ -2429,7 +2432,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
cashPoolFoundExchangedCash := cashPoolsFound[0].ExchangedCash
|
|
|
|
|
|
// 判断是否超过平台未兑换现金
|
|
|
if createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate > cashPoolFoundUnExchangeCash {
|
|
|
if createExchangeCashPersonCommand.ExchangedSuMoney*activityFound.Rate > cashPoolFoundUnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
|
}
|
|
|
|
...
|
...
|
@@ -2454,11 +2457,11 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
|
|
newCashPoolExchangedCash, _ := decimal.NewFromFloat(cashPoolFoundExchangedCash).Add(decimal.NewFromFloat(personSaved.ExchangedCash)).Float64()
|
|
|
unExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Sub(decimal.NewFromFloat(personSaved.ExchangedCash)).Float64()
|
|
|
newCashPoolExchangedCash, _ := decimal.NewFromFloat(cashPoolFoundExchangedCash).Add(decimal.NewFromFloat(personSaved.ExchangedCash)).Float64()
|
|
|
unExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Sub(decimal.NewFromFloat(personSaved.ExchangedCash)).Float64()
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
//ExchangedCash: cashPoolFoundExchangedCash + personSaved.ExchangedCash,
|
|
|
//UnExchangeCash: cashPoolFoundUnExchangeCash - personSaved.ExchangedCash,
|
|
|
ExchangedCash: newCashPoolExchangedCash,
|
...
|
...
|
@@ -2466,7 +2469,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
|
|
LastRate: cashPoolsFound[0].LastRate,
|
|
|
LastRate: cashPoolsFound[0].LastRate,
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
...
|
...
|
@@ -2589,8 +2592,8 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP |
|
|
// 获取该公司活动下所有兑换员工
|
|
|
if count, people, err := exchangeCashPersonListRepository.FindAll(map[string]interface{}{
|
|
|
"exchangeCashActivityIds": activityIds,
|
|
|
"offset": listExchangeCashPersonQuery.Offset,
|
|
|
"limit": listExchangeCashPersonQuery.Limit,
|
|
|
"offset": listExchangeCashPersonQuery.Offset,
|
|
|
"limit": listExchangeCashPersonQuery.Limit,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -2602,8 +2605,8 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP |
|
|
people[i].ExchangedCash, _ = decimal.NewFromFloatWithExponent(people[i].ExchangedCash, -2).Float64()
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"count": count,
|
|
|
"people": people,
|
|
|
"count": count,
|
|
|
"people": people,
|
|
|
}, nil
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -2620,8 +2623,8 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP |
|
|
people[i].ExchangedCash, _ = decimal.NewFromFloatWithExponent(people[i].ExchangedCash, -2).Float64()
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"count": count,
|
|
|
"people": people,
|
|
|
"count": count,
|
|
|
"people": people,
|
|
|
}, nil
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -2665,7 +2668,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
|
|
|
// 现金池仓储初始化
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -2732,7 +2735,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
|
|
|
// 判断当前员工是否有效
|
|
|
getEmployee := map[string]interface{}{
|
|
|
"uid": personFound.EmployeeInfo.Uid,
|
|
|
"uid": personFound.EmployeeInfo.Uid,
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
}
|
|
|
employeeFound, err := employeeRepository.FindOne(getEmployee)
|
...
|
...
|
@@ -2745,16 +2748,16 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
|
|
|
// 更新兑换素币活动命令
|
|
|
exchangedSuMoney, _ := decimal.NewFromFloat(activityFoundExchangedSuMoney).Sub(decimal.NewFromFloat(personFoundExchangedSuMoney)).Float64()
|
|
|
exchangedCash, _ := decimal.NewFromFloat(activityFoundExchangedCash).Sub(decimal.NewFromFloat(personFoundExchangedCash)).Float64()
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
exchangedCash, _ := decimal.NewFromFloat(activityFoundExchangedCash).Sub(decimal.NewFromFloat(personFoundExchangedCash)).Float64()
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personFound.ExchangeCashActivityId,
|
|
|
//ExchangedSuMoney: activityFoundExchangedSuMoney - personFoundExchangedSuMoney,
|
|
|
//ExchangedCash: activityFoundExchangedCash - personFoundExchangedCash,
|
|
|
ExchangedSuMoney: exchangedSuMoney,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
ExchangedSuMoney: exchangedSuMoney,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
}
|
|
|
|
|
|
// 更新兑换活动
|
...
|
...
|
@@ -2772,11 +2775,11 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
}
|
|
|
|
|
|
// 操作素币命令
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
Uid: personFound.EmployeeInfo.Uid,
|
|
|
Operator: removeExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: personFoundExchangedSuMoney,
|
|
|
OperationType: 41, // 删除兑换素币清单,撤回已兑换素币
|
|
|
OperationType: 41, // 删除兑换素币清单,撤回已兑换素币
|
|
|
OperationDescription: activityFound.ExchangeActivityName + "调整",
|
|
|
}
|
|
|
|
...
|
...
|
@@ -2824,12 +2827,12 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
|
|
newExchangedCash, _ := decimal.NewFromFloat(cashPoolFoundExchangedCash).Sub(decimal.NewFromFloat(personFoundExchangedCash)).Float64()
|
|
|
UnExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Add(decimal.NewFromFloat(personFoundExchangedCash)).Float64()
|
|
|
newExchangedCash, _ := decimal.NewFromFloat(cashPoolFoundExchangedCash).Sub(decimal.NewFromFloat(personFoundExchangedCash)).Float64()
|
|
|
UnExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Add(decimal.NewFromFloat(personFoundExchangedCash)).Float64()
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
LastRate: cashPoolsFound[0].LastRate,
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
LastRate: cashPoolsFound[0].LastRate,
|
|
|
//ExchangedCash: cashPoolFoundExchangedCash - personFoundExchangedCash,
|
|
|
//UnExchangeCash: cashPoolFoundUnExchangeCash + personFoundExchangedCash,
|
|
|
ExchangedCash: newExchangedCash,
|
...
|
...
|
@@ -2999,17 +3002,47 @@ func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQ |
|
|
}
|
|
|
|
|
|
// 兑换素币清单排行榜
|
|
|
for i, _ := range exchangeCashListRankingStatistics["people"].([]struct{Uid int64; EmployeeName string; SuMoney float64; Cash float64; Ranking int}) {
|
|
|
uid := exchangeCashListRankingStatistics["people"].([]struct{Uid int64; EmployeeName string; SuMoney float64; Cash float64; Ranking int})[i].Uid
|
|
|
for i, _ := range exchangeCashListRankingStatistics["people"].([]struct {
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
SuMoney float64
|
|
|
Cash float64
|
|
|
Ranking int
|
|
|
}) {
|
|
|
uid := exchangeCashListRankingStatistics["people"].([]struct {
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
SuMoney float64
|
|
|
Cash float64
|
|
|
Ranking int
|
|
|
})[i].Uid
|
|
|
if uidName[uid] != nil {
|
|
|
exchangeCashListRankingStatistics["people"].([]struct{Uid int64; EmployeeName string; SuMoney float64; Cash float64; Ranking int})[i].EmployeeName = uidName[uid].(string)
|
|
|
exchangeCashListRankingStatistics["people"].([]struct {
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
SuMoney float64
|
|
|
Cash float64
|
|
|
Ranking int
|
|
|
})[i].EmployeeName = uidName[uid].(string)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 个人素币兑换清单
|
|
|
if exchangeCashListRankingStatistics["currentEmployee"] != nil {
|
|
|
currentEmployeeExchangeCashList := exchangeCashListRankingStatistics["currentEmployee"].(struct{Uid int64;EmployeeName string;SuMoney float64; Cash float64;Ranking int})
|
|
|
uidExchangeCashList := exchangeCashListRankingStatistics["currentEmployee"].(struct{Uid int64;EmployeeName string;SuMoney float64; Cash float64;Ranking int}).Uid
|
|
|
currentEmployeeExchangeCashList := exchangeCashListRankingStatistics["currentEmployee"].(struct {
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
SuMoney float64
|
|
|
Cash float64
|
|
|
Ranking int
|
|
|
})
|
|
|
uidExchangeCashList := exchangeCashListRankingStatistics["currentEmployee"].(struct {
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
SuMoney float64
|
|
|
Cash float64
|
|
|
Ranking int
|
|
|
}).Uid
|
|
|
if uidName[uidExchangeCashList] != nil {
|
|
|
currentEmployeeExchangeCashList.EmployeeName = uidName[uidExchangeCashList].(string)
|
|
|
}
|
...
|
...
|
|