...
|
...
|
@@ -86,11 +86,11 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(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())
|
|
|
}
|
|
|
fmt.Print(count, "\n")
|
|
|
if count == 0 { // 新增现金池
|
|
|
newCashPool := &domain.CashPool{
|
|
|
CompanyId: createCashPoolCommand.CompanyId,
|
...
|
...
|
@@ -226,7 +226,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
|
if systemSuMoneyStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
//systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) // 平台已兑换素币
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) // 平台未兑换素币
|
|
|
|
|
|
// 查找当前公司现金池
|
...
|
...
|
@@ -273,12 +272,23 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 兑换现金活动仓储初始化
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
|
|
|
// 时间格式化
|
|
|
var timeNow = time.Now()
|
|
|
var deadline = createExchangeCashActivityCommand.Deadline
|
|
|
var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
|
|
|
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 999999, time.Local)
|
|
|
|
|
|
// 创建兑换活动命令
|
|
|
newActivity := &domain.ExchangeCashActivity{
|
|
|
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
|
|
|
CompanyId: createExchangeCashActivityCommand.CompanyId,
|
...
|
...
|
@@ -290,20 +300,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
CreateTime: time.Now(),
|
|
|
}
|
|
|
|
|
|
// 倒计时结束
|
|
|
// 倒计时结束判断
|
|
|
if t2.Before(t1) {
|
|
|
newActivity.CountDown = 0
|
|
|
}
|
|
|
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
|
|
|
// 保存兑换活动
|
|
|
if activity, err := exchangeCashActivityRepository.Save(newActivity); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -330,6 +332,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 兑换现金活动仓储初始化
|
|
|
var exchangeActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -339,6 +342,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc |
|
|
exchangeActivityRepository = value
|
|
|
}
|
|
|
|
|
|
// 获取该公司所有兑换现金活动
|
|
|
if _, activities, err := exchangeActivityRepository.FindAll(tool_funs.SimpleStructToMap(listExchangeCashActivityDeadlineQuery)); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -346,6 +350,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc |
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 提取兑换现金活动截止时间
|
|
|
var deadlines []interface{}
|
|
|
for _, activity := range activities {
|
|
|
deadlines = append(deadlines, activity.Deadline)
|
...
|
...
|
@@ -377,6 +382,7 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 兑换现金活动仓储初始化
|
|
|
var exchangeActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -386,6 +392,7 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma |
|
|
exchangeActivityRepository = value
|
|
|
}
|
|
|
|
|
|
// 查找兑换现金活动
|
|
|
if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(activityCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -393,25 +400,28 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma |
|
|
var t1 = time.Now()
|
|
|
var t2 = activity.Deadline
|
|
|
|
|
|
// 更新兑换活动命令
|
|
|
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
|
|
|
ExchangeCashActivityId: activity.ActivityId,
|
|
|
CountDown: int64(t2.Sub(t1).Hours() / 24),
|
|
|
CountDown: int64(t2.Sub(t1).Hours() / 24), // 计算倒计时
|
|
|
Deadline: activity.Deadline,
|
|
|
ExchangedSuMoney: activity.ExchangedSuMoney,
|
|
|
ExchangedCash: activity.ExchangedCash,
|
|
|
ExchangeRate: activity.Rate,
|
|
|
}
|
|
|
|
|
|
// 倒计时结束
|
|
|
// 倒计时结束处理
|
|
|
if t2.Before(t1) {
|
|
|
updateExchangeCashActivity.CountDown = 0
|
|
|
updateExchangeCashActivity.Deadline = activity.Deadline
|
|
|
}
|
|
|
|
|
|
// 更新兑换现金活动
|
|
|
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 保存更新
|
|
|
_, err := exchangeActivityRepository.Save(activity)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -445,6 +455,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 兑换现金活动仓储初始化
|
|
|
var exchangeActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -454,6 +465,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
exchangeActivityRepository = value
|
|
|
}
|
|
|
|
|
|
// 查找兑换现金活动
|
|
|
if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashActivityQuery)); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -461,25 +473,28 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
var t1 = time.Now()
|
|
|
var t2 = activity.Deadline
|
|
|
|
|
|
// 更新兑换现金活动命令
|
|
|
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
|
|
|
ExchangeCashActivityId: activity.ActivityId,
|
|
|
CountDown: int64(t2.Sub(t1).Hours() / 24),
|
|
|
CountDown: int64(t2.Sub(t1).Hours() / 24), // 重新计算活动倒计时
|
|
|
Deadline: activity.Deadline,
|
|
|
ExchangedSuMoney: activity.ExchangedSuMoney,
|
|
|
ExchangedCash: activity.ExchangedCash,
|
|
|
ExchangeRate: activity.Rate,
|
|
|
}
|
|
|
|
|
|
// 倒计时结束
|
|
|
// 倒计时结束处理
|
|
|
if t2.Before(t1) {
|
|
|
updateExchangeCashActivity.CountDown = 0
|
|
|
updateExchangeCashActivity.Deadline = activity.Deadline
|
|
|
}
|
|
|
|
|
|
// 更新兑换现金活动
|
|
|
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 保存兑换现金活动更新
|
|
|
_, err := exchangeActivityRepository.Save(activity)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -490,6 +505,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 兑换现金活动返回截止时间处理
|
|
|
var activitiesWithTs []interface{}
|
|
|
for _, activity := range activities {
|
|
|
activityWithTs := map[string]interface{} {
|
...
|
...
|
@@ -498,7 +514,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
"companyId": activity.CompanyId,
|
|
|
"exchangedCash": activity.ExchangedCash,
|
|
|
"exchangedSuMoney": activity.ExchangedSuMoney,
|
|
|
"deadline": activity.Deadline.UnixNano() / 1e6,
|
|
|
"deadline": activity.Deadline.UnixNano() / 1e6, // 秒级时间戳转换
|
|
|
"countDown": activity.CountDown,
|
|
|
"rate": activity.Rate,
|
|
|
"createTime": activity.CreateTime,
|
...
|
...
|
@@ -529,6 +545,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 兑换现金活动仓储初始化
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -538,15 +555,17 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang |
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
|
|
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": removeExchangeCashActivityCommand.ActivityId})
|
|
|
// 查找兑换现金活动
|
|
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": removeExchangeCashActivityCommand.ActivityId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activity == nil {
|
|
|
if activityFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashActivityCommand.ActivityId)))
|
|
|
}
|
|
|
|
|
|
if activityDeleted, err := exchangeCashActivityRepository.Remove(activity); err != nil {
|
|
|
// 删除兑换现金活动
|
|
|
if activityDeleted, err := exchangeCashActivityRepository.Remove(activityFound); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
...
|
...
|
@@ -572,6 +591,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 兑换现金活动仓储初始化
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -581,51 +601,55 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA |
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
|
|
|
// 需要更新兑换活动结束倒计时
|
|
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": getExchangeCashActivityQuery.ExchangeCashActivityId})
|
|
|
// 获取兑换现金活动
|
|
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": getExchangeCashActivityQuery.ExchangeCashActivityId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activity == nil {
|
|
|
if activityFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashActivityQuery.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
var timeNow = time.Now()
|
|
|
var deadline = activity.Deadline
|
|
|
var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
|
|
|
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
|
|
|
//var timeNow = time.Now()
|
|
|
//var deadline = activityFound.Deadline
|
|
|
//var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
|
|
|
var t1 = time.Now()
|
|
|
//var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, time.Local)
|
|
|
var t2 = activityFound.Deadline
|
|
|
|
|
|
// 更新兑换现金活动倒计时命令
|
|
|
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
|
|
|
ExchangeCashActivityId: activity.ActivityId,
|
|
|
ExchangeCashActivityId: activityFound.ActivityId,
|
|
|
CountDown: int64(t2.Sub(t1).Hours() / 24),
|
|
|
Deadline: activity.Deadline,
|
|
|
ExchangedSuMoney: activity.ExchangedSuMoney,
|
|
|
ExchangedCash: activity.ExchangedCash,
|
|
|
ExchangeRate: activity.Rate,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
}
|
|
|
|
|
|
// 倒计时结束
|
|
|
// 倒计时结束处理
|
|
|
if t2.Before(t1) {
|
|
|
updateExchangeCashActivity.CountDown = 0
|
|
|
updateExchangeCashActivity.Deadline = activity.Deadline
|
|
|
updateExchangeCashActivity.Deadline = activityFound.Deadline
|
|
|
}
|
|
|
|
|
|
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
|
|
|
// 更新兑换现活动
|
|
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
activityFound, err := exchangeCashActivityRepository.Save(activity)
|
|
|
// 保存兑换现金活动更新
|
|
|
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if activityFound == nil {
|
|
|
if activityUpdated == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return activityFound, nil
|
|
|
return activityUpdated, nil
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -645,7 +669,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 更新兑换活动
|
|
|
// 兑换现金活动仓储初始化
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -655,17 +679,17 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
|
|
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": updateExchangeCashActivityCommand.ExchangeCashActivityId})
|
|
|
if err != nil {
|
|
|
// 兑换素币清单仓储初始化
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activity == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
} else {
|
|
|
exchangeCashPersonListRepository = value
|
|
|
}
|
|
|
|
|
|
// 更新兑换活动兑换汇率
|
|
|
if updateExchangeCashActivityCommand.ExchangeRate != 0 {
|
|
|
// 获取当前现金池
|
|
|
// 现金池仓储初始化
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -675,17 +699,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
cashPoolRepository = value
|
|
|
}
|
|
|
|
|
|
_, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
"companyId": activity.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if len(cashPools) == 0 {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activity.CompanyId)))
|
|
|
}
|
|
|
|
|
|
// 判断兑换活动清单中现金总金额是否超过平台未兑换现金值
|
|
|
// 现金池DAO初始化
|
|
|
var cashPoolDao *dao.CashPoolDao
|
|
|
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -695,31 +709,54 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
cashPoolDao = value
|
|
|
}
|
|
|
|
|
|
activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activity.ActivityId)
|
|
|
// 员工DAO初始化
|
|
|
var employeeDao *dao.EmployeeDao
|
|
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
employeeDao = value
|
|
|
}
|
|
|
|
|
|
// 获取当前活动
|
|
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": updateExchangeCashActivityCommand.ExchangeCashActivityId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activitySuMoneyStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
|
|
|
if activityFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
|
|
|
|
|
|
if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPools[0].UnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
|
if updateExchangeCashActivityCommand.ExchangeRate != 0 { // 更新兑换活动兑换汇率
|
|
|
// 获取当前公司现金池
|
|
|
_, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if len(cashPoolsFound) == 0 {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
|
|
|
}
|
|
|
|
|
|
// 批量更新兑换清单中已兑换现金值
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
// 获取活动素币统计
|
|
|
activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.ActivityId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashPersonListRepository = value
|
|
|
}
|
|
|
if activitySuMoneyStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
|
|
|
}
|
|
|
activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
|
|
|
|
|
|
// 判断兑换活动清单中现金总金额是否超过平台未兑换现金值
|
|
|
if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
|
|
|
}
|
|
|
|
|
|
_, people, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
|
|
|
// 获取该活动所有兑换清单
|
|
|
_, peopleFound, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
|
|
|
"exchangeCashActivityId": updateExchangeCashActivityCommand.ExchangeCashActivityId,
|
|
|
})
|
|
|
if err != nil {
|
...
|
...
|
@@ -727,54 +764,45 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
}
|
|
|
|
|
|
// 批量更新兑换清单,更新已兑换现金值
|
|
|
for _, person := range people {
|
|
|
for _, personFound := range peopleFound {
|
|
|
// 更新兑换清单命令
|
|
|
updateExchangeCashPerson := &command.UpdateExchangeCashPersonCommand {
|
|
|
ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * person.ExchangedSuMoney,
|
|
|
ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * personFound.ExchangedSuMoney,
|
|
|
ExchangedSuMoney: personFound.ExchangedSuMoney,
|
|
|
}
|
|
|
|
|
|
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPerson)); err != nil {
|
|
|
// 更新素币兑换清单
|
|
|
if err := personFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashPerson)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if _, err := exchangeCashPersonListRepository.Save(person);err != nil {
|
|
|
// 保存素币兑换清单更新
|
|
|
if _, err := exchangeCashPersonListRepository.Save(personFound);err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 计算系统平均兑换汇率并更新现金池
|
|
|
var employeeDao *dao.EmployeeDao
|
|
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
employeeDao = value
|
|
|
}
|
|
|
|
|
|
// 获取平台素币状况
|
|
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activity.CompanyId)
|
|
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if systemSuMoneyStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
|
|
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
|
|
|
// 获取平台现金状况
|
|
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activity.CompanyId)
|
|
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if systemCashStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
|
|
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
|
|
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
|
|
|
// 平均兑换汇率
|
|
|
// 计算平均兑换汇率
|
|
|
var rate float64
|
|
|
if systemExchangedSuMoney == 0 {
|
|
|
rate = 0
|
...
|
...
|
@@ -782,19 +810,23 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
|
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPools[0].CashPoolId,
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
ExchangedCash: systemUnExchangeCash,
|
|
|
UnExchangeCash: systemUnExchangeCash,
|
|
|
Rate: rate,
|
|
|
}
|
|
|
|
|
|
fmt.Printf("更新现金池命令:%+v\n", updateCashPoolCommand)
|
|
|
|
|
|
// 更新现金池
|
|
|
if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0])
|
|
|
// 保存现金池更新
|
|
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -802,32 +834,35 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 更新兑换活动已兑换现金
|
|
|
updateExchangeCashActivityCommand.ExchangedCash = updateExchangeCashActivityCommand.ExchangeRate * activity.ExchangedSuMoney
|
|
|
} else {
|
|
|
updateExchangeCashActivityCommand.ExchangedCash = activity.ExchangedCash
|
|
|
}
|
|
|
// 更新兑换活动命令已兑换现金
|
|
|
updateExchangeCashActivityCommand.ExchangedCash = updateExchangeCashActivityCommand.ExchangeRate * activityFound.ExchangedSuMoney
|
|
|
|
|
|
var timeNow = time.Now()
|
|
|
var deadline = updateExchangeCashActivityCommand.Deadline
|
|
|
var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
|
|
|
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
|
|
|
} else { // 未更新兑换活动汇率
|
|
|
updateExchangeCashActivityCommand.ExchangedCash = activityFound.ExchangedCash
|
|
|
}
|
|
|
|
|
|
// 计算倒计时
|
|
|
var t1 = time.Now()
|
|
|
var t2 = activityFound.Deadline
|
|
|
updateExchangeCashActivityCommand.CountDown = int64(t2.Sub(t1).Hours() / 24)
|
|
|
|
|
|
// 倒计时结束
|
|
|
// 倒计时结束处理
|
|
|
if t2.Before(t1) {
|
|
|
updateExchangeCashActivityCommand.CountDown = 0
|
|
|
}
|
|
|
|
|
|
updateExchangeCashActivityCommand.ExchangedSuMoney = activity.ExchangedSuMoney
|
|
|
// 更新兑换活动命令已兑换素币
|
|
|
updateExchangeCashActivityCommand.ExchangedSuMoney = activityFound.ExchangedSuMoney
|
|
|
|
|
|
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
fmt.Printf("更新兑换活动命令:%+v\n", updateExchangeCashActivityCommand)
|
|
|
|
|
|
// 更新兑换活动
|
|
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if activityUpdated, err := exchangeCashActivityRepository.Save(activity); err != nil {
|
|
|
// 保存兑换活动更新
|
|
|
if activityUpdated, err := exchangeCashActivityRepository.Save(activityFound); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
...
|
...
|
@@ -854,7 +889,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 获取兑换活动兑换汇率
|
|
|
// 兑换活动仓储初始化
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -864,16 +899,27 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
|
|
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
|
|
|
if err != nil {
|
|
|
// 兑换素币清单仓储初始化
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashPersonListRepository = value
|
|
|
}
|
|
|
|
|
|
fmt.Print(activity.Rate, "\n")
|
|
|
|
|
|
rate := activity.Rate
|
|
|
// 现金池仓储初始化
|
|
|
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
|
|
|
}
|
|
|
|
|
|
// 根据uid/手机账号判断成员是否存在,素币是否超过本人持有的真实素币
|
|
|
// 员工仓储初始化
|
|
|
var employeeRepository domain.EmployeeRepository
|
|
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -883,7 +929,43 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
employeeRepository = value
|
|
|
}
|
|
|
|
|
|
// 判断是excel导入还是页面增加
|
|
|
// 现金池DAO初始化
|
|
|
var cashPoolDao *dao.CashPoolDao
|
|
|
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
cashPoolDao = value
|
|
|
}
|
|
|
|
|
|
// 员工DAO初始化
|
|
|
var employeeDao *dao.EmployeeDao
|
|
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
employeeDao = value
|
|
|
}
|
|
|
|
|
|
// 操作素币服务初始化
|
|
|
var operationSuMoneyService service.OperationSuMoneyService
|
|
|
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
operationSuMoneyService = value
|
|
|
}
|
|
|
|
|
|
// 获取当前兑换清单兑换活动
|
|
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 判断导入方式,页面/Excel
|
|
|
getEmployee := map[string]interface{}{}
|
|
|
if createExchangeCashPersonCommand.PersonAccount == "" {
|
|
|
getEmployee = map[string]interface{}{
|
...
|
...
|
@@ -895,62 +977,48 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
}
|
|
|
}
|
|
|
|
|
|
employee, err := employeeRepository.FindOne(getEmployee)
|
|
|
// 判断当前员工是否有效
|
|
|
employeeFound, err := employeeRepository.FindOne(getEmployee)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if employee == nil {
|
|
|
if employeeFound == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
|
|
|
}
|
|
|
|
|
|
if employee.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {
|
|
|
// 判断该员工兑换的素币是否超过本人持有的素币
|
|
|
if employeeFound.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
|
|
|
}
|
|
|
|
|
|
// 新增兑换清单
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashPersonListRepository = value
|
|
|
}
|
|
|
|
|
|
// 新增兑换清单命令
|
|
|
newPerson := &domain.ExchangeCashPersonList{
|
|
|
EmployeeInfo: &domain.EmployeeInfo{
|
|
|
Uid: employee.EmployeeInfo.Uid,
|
|
|
EmployeeName: employee.EmployeeInfo.EmployeeName,
|
|
|
EmployeeAccount: employee.EmployeeInfo.EmployeeAccount,
|
|
|
Uid: employeeFound.EmployeeInfo.Uid,
|
|
|
EmployeeName: employeeFound.EmployeeInfo.EmployeeName,
|
|
|
EmployeeAccount: employeeFound.EmployeeInfo.EmployeeAccount,
|
|
|
},
|
|
|
ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney * rate,
|
|
|
ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
}
|
|
|
|
|
|
person, err := exchangeCashPersonListRepository.Save(newPerson)
|
|
|
// 保存兑换素币清单
|
|
|
personSaved, err := exchangeCashPersonListRepository.Save(newPerson)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 生成素币流水,更新个人素币
|
|
|
var operationSuMoneyService service.OperationSuMoneyService
|
|
|
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
operationSuMoneyService = value
|
|
|
}
|
|
|
|
|
|
// 操作素币命令
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
Uid: person.EmployeeInfo.Uid,
|
|
|
Uid: employeeFound.EmployeeInfo.Uid,
|
|
|
Operator: createExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: person.ExchangedSuMoney,
|
|
|
OperationType: 3,
|
|
|
SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
OperationType: 4,
|
|
|
OperationDescription: "素币兑换现金",
|
|
|
}
|
|
|
|
|
|
// 操作素币,生成素币流水
|
|
|
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())
|
...
|
...
|
@@ -959,27 +1027,11 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
|
|
}
|
|
|
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
|
|
|
// 获取相关兑换活动
|
|
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activityFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
// 更新兑换活动命令
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + person.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash + person.ExchangedCash,
|
|
|
ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -990,6 +1042,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 保存兑换现金活动更新
|
|
|
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -998,15 +1051,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
var cashPoolDao *dao.CashPoolDao
|
|
|
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
cashPoolDao = value
|
|
|
}
|
|
|
|
|
|
// 获取兑换活动素币兑换情况
|
|
|
activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.CompanyId)
|
|
|
if err != nil {
|
...
|
...
|
@@ -1015,20 +1059,25 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
if activitySuMoneyStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
|
|
|
}
|
|
|
|
|
|
activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
|
|
|
|
|
|
// 现金池操作
|
|
|
var employeeDao *dao.EmployeeDao
|
|
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
employeeDao = value
|
|
|
// 获取当前现金池
|
|
|
_, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if len(cashPoolsFound) == 0 {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
|
|
|
}
|
|
|
|
|
|
// 获取平台现金状况
|
|
|
// 判断兑换活动的现金是否超过现金池未兑换现金
|
|
|
if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
|
|
|
}
|
|
|
|
|
|
// 获取平台现金兑换情况
|
|
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -1036,47 +1085,20 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
if systemCashStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
|
|
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
|
|
//systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
|
|
|
// 获取平台素币状况
|
|
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activity.CompanyId)
|
|
|
// 获取平台素币兑换情况
|
|
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if systemSuMoneyStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
|
|
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
// 获取现金池
|
|
|
_, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
"companyId": activity.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if len(cashPools) == 0 {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activity.CompanyId)))
|
|
|
}
|
|
|
|
|
|
// 判断兑换的现金是否超过现金池未兑换现金
|
|
|
if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPools[0].UnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
|
}
|
|
|
|
|
|
// 计算平均兑换汇率
|
|
|
var newRate float64
|
|
|
if systemExchangedSuMoney == 0 {
|
...
|
...
|
@@ -1085,21 +1107,23 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
|
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPools[0].CashPoolId,
|
|
|
ExchangedCash: cashPools[0].ExchangedCash + person.ExchangedCash,
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
ExchangedCash: cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash,
|
|
|
UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personSaved.ExchangedCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeCash: cashPools[0].UnExchangeCash - person.ExchangedCash,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
|
|
if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0])
|
|
|
// 保存现金池更新
|
|
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -1110,7 +1134,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return person, nil
|
|
|
return personSaved, nil
|
|
|
}
|
|
|
|
|
|
// 返回兑换素币清单
|
...
|
...
|
@@ -1129,6 +1153,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 兑换素币清单仓储初始化
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -1138,17 +1163,18 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer |
|
|
exchangeCashPersonListRepository = value
|
|
|
}
|
|
|
|
|
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": getExchangeCashPersonQuery.ExchangeCashPersonId})
|
|
|
// 获取当前兑换素币清单
|
|
|
personFound, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": getExchangeCashPersonQuery.ExchangeCashPersonId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if person == nil {
|
|
|
if personFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashPersonQuery.ExchangeCashPersonId)))
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return person, nil
|
|
|
return personFound, nil
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -1168,6 +1194,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 素币兑换清单仓储初始化
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -1177,9 +1204,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP |
|
|
exchangeCashPersonListRepository = value
|
|
|
}
|
|
|
|
|
|
// 返回兑换现金活动总榜
|
|
|
if listExchangeCashPersonQuery.ExchangeCashActivityId == 0 && listExchangeCashPersonQuery.CompanyId != 0 {
|
|
|
// 找到该公司下的所有活动id
|
|
|
// 兑换素币活动仓储初始化
|
|
|
var exchangeActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -1189,12 +1214,16 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP |
|
|
exchangeActivityRepository = value
|
|
|
}
|
|
|
|
|
|
// 返回兑换现金活动总榜
|
|
|
if listExchangeCashPersonQuery.ExchangeCashActivityId == 0 && listExchangeCashPersonQuery.CompanyId != 0 {
|
|
|
// 找到该公司下的所有活动id
|
|
|
if _, activities, err := exchangeActivityRepository.FindAll(map[string]interface{}{
|
|
|
"companyId": listExchangeCashPersonQuery.CompanyId,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
var activityIds []int64
|
|
|
|
|
|
for _, activity := range activities {
|
|
|
activityIds = append(activityIds, activity.ActivityId)
|
|
|
}
|
...
|
...
|
@@ -1209,6 +1238,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
return map[string]interface{}{
|
|
|
"count": count,
|
|
|
"people": people,
|
...
|
...
|
@@ -1306,7 +1336,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
employeeDao = value
|
|
|
}
|
|
|
|
|
|
// 获取兑换清单
|
|
|
// 获取兑换清单员工
|
|
|
personFound, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": updateExchangeCashPersonCommand.ListId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -1315,7 +1345,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ListId)))
|
|
|
}
|
|
|
|
|
|
fmt.Printf("Person Found: %+v\n", personFound)
|
|
|
// 获取兑换清单员工已兑换素币
|
|
|
personFoundExchangedSuMoney := personFound.ExchangedSuMoney
|
|
|
|
|
|
// 获取相关兑换活动
|
|
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": personFound.ExchangeCashActivityId})
|
...
|
...
|
@@ -1340,13 +1371,11 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
fmt.Printf("Person Updated: %+v\n", personUpdated)
|
|
|
|
|
|
// 更新素币兑换活动命令
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personFound.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFound.ExchangedSuMoney),
|
|
|
ExchangedCash: activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFound.ExchangedSuMoney) * activityFound.Rate,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney),
|
|
|
ExchangedCash: activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -1363,10 +1392,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
|
|
|
// 判断操作素币类型
|
|
|
if updateExchangeCashActivityCommand.ExchangedSuMoney - personUpdated.ExchangedSuMoney > 0 {
|
|
|
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personUpdated.ExchangedSuMoney)
|
|
|
operationSuMoneyCommand.OperationType = 1
|
|
|
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
|
|
|
operationSuMoneyCommand.OperationType = 4
|
|
|
} else {
|
|
|
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personUpdated.ExchangedSuMoney)
|
|
|
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
|
|
|
operationSuMoneyCommand.OperationType = 3
|
|
|
}
|
|
|
|
...
|
...
|
@@ -1379,8 +1408,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
|
|
}
|
|
|
|
|
|
fmt.Printf("Activity Found: %+v\n", activityFound)
|
|
|
|
|
|
// 更新兑换活动
|
|
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
...
|
...
|
@@ -1395,8 +1422,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
fmt.Printf("Activity Updated: %+v\n", activityUpdated)
|
|
|
|
|
|
// 统计活动已兑换素币
|
|
|
activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityUpdated.ActivityId)
|
|
|
if err != nil {
|
...
|
...
|
@@ -1431,7 +1456,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
|
|
|
// 判断是否超过平台未兑换现金
|
|
|
if activitySuMoney * activityUpdated.Rate > systemUnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
|
|
|
}
|
|
|
|
|
|
// 重新获取系统现金兑换情况
|
...
|
...
|
@@ -1446,13 +1471,13 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
//newSystemUnExchangeCash := newSystemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
|
|
|
// 获取当前现金池
|
|
|
_, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
_, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
"companyId": activityUpdated.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if cashPools == nil {
|
|
|
if cashPoolsFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
|
|
|
}
|
|
|
|
...
|
...
|
@@ -1464,38 +1489,23 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
|
|
|
}
|
|
|
|
|
|
fmt.Printf("CashPool Found: %+v\n", cashPools[0])
|
|
|
|
|
|
fmt.Printf("UpdateExchangeCashPersonCommand: %+v\n", updateExchangeCashPersonCommand)
|
|
|
|
|
|
updateExchangedCash := cashPools[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFound.ExchangedSuMoney) * activityUpdated.Rate
|
|
|
fmt.Print(updateExchangedCash,"\n")
|
|
|
|
|
|
updateUnExchangeCash := cashPools[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - personFound.ExchangedSuMoney) * activityUpdated.Rate
|
|
|
fmt.Print(updateUnExchangeCash, "\n")
|
|
|
|
|
|
updateExchangedSuMoney := cashPools[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFound.ExchangedSuMoney)
|
|
|
fmt.Print(updateExchangedSuMoney, "\n")
|
|
|
|
|
|
// 更新现金池命令
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPools[0].CashPoolId,
|
|
|
ExchangedCash: updateExchangedCash,
|
|
|
UnExchangeCash: updateUnExchangeCash,
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
ExchangedCash: cashPoolsFound[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
|
|
|
UnExchangeCash: cashPoolsFound[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
|
|
|
Rate: newRate,
|
|
|
ExchangedSuMoney: updateExchangedSuMoney,
|
|
|
ExchangedSuMoney: cashPoolsFound[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney),
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
}
|
|
|
|
|
|
fmt.Printf("UpdateCashPoolCommand=%+v\n", updateCashPoolCommand)
|
|
|
|
|
|
// 更新现金池
|
|
|
if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 保存现金池更新
|
|
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0])
|
|
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -1503,8 +1513,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
fmt.Printf("Updated CashPool: %+v\n", cashPoolUpdated)
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -1528,7 +1536,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 移除兑换素币清单
|
|
|
// 兑换素币清单仓储初始化
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -1538,37 +1546,75 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
exchangeCashPersonListRepository = value
|
|
|
}
|
|
|
|
|
|
// 获取待删除人员
|
|
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": removeExchangeCashPersonCommand.ListId})
|
|
|
if err != nil {
|
|
|
// 素币兑换活动仓储初始化
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
if person == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
|
|
|
|
|
|
// 现金池仓储初始化
|
|
|
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
|
|
|
}
|
|
|
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
// 员工DAO初始化
|
|
|
var employeeDao *dao.EmployeeDao
|
|
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
employeeDao = value
|
|
|
}
|
|
|
|
|
|
// 操作素币服务初始化
|
|
|
var operationSuMoneyService service.OperationSuMoneyService
|
|
|
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashActivityRepository = value
|
|
|
operationSuMoneyService = value
|
|
|
}
|
|
|
|
|
|
// 获取待删除兑换清单人员
|
|
|
personFound, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": removeExchangeCashPersonCommand.ListId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if personFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
|
|
|
}
|
|
|
|
|
|
// 获取兑换清单员工已兑换素币
|
|
|
personFoundExchangedSuMoney := personFound.ExchangedSuMoney
|
|
|
|
|
|
// 删除兑换清单人员
|
|
|
personDeleted, err := exchangeCashPersonListRepository.Remove(personFound)
|
|
|
|
|
|
// 获取相关兑换活动
|
|
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": person.ExchangeCashActivityId})
|
|
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": personFound.ExchangeCashActivityId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activityFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(person.ExchangeCashActivityId)))
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(personFound.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
// 更新兑换素币活动命令
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney - person.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash - person.ExchangedCash,
|
|
|
ExchangeCashActivityId: personFound.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney - personFoundExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash - personFoundExchangedSuMoney,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -1579,6 +1625,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 保存兑换活动更新
|
|
|
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -1587,24 +1634,16 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
// 还原个人素币值,生成素币流水,描述修改成和活动相关
|
|
|
var operationSuMoneyService service.OperationSuMoneyService
|
|
|
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
operationSuMoneyService = value
|
|
|
}
|
|
|
|
|
|
// 操作素币命令
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
Uid: person.EmployeeInfo.Uid,
|
|
|
Uid: personFound.EmployeeInfo.Uid,
|
|
|
Operator: removeExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: person.ExchangedSuMoney,
|
|
|
SuMoney: personFoundExchangedSuMoney,
|
|
|
OperationType: 1, // 增加素币
|
|
|
OperationDescription: activityFound.ExchangeActivityName + "素币调整",
|
|
|
}
|
|
|
|
|
|
// 操作素币,生成素币流水
|
|
|
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())
|
...
|
...
|
@@ -1613,17 +1652,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
|
|
var employeeDao *dao.EmployeeDao
|
|
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
employeeDao = value
|
|
|
}
|
|
|
|
|
|
// 获取平台现金状况
|
|
|
// 获取平台现金兑换情况
|
|
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -1631,11 +1660,10 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
if systemCashStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
|
|
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
|
|
//systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
|
|
|
// 获取平台素币状况
|
|
|
// 获取平台素币兑换情况
|
|
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -1643,27 +1671,17 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
if systemSuMoneyStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
|
|
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
// 获取现金池
|
|
|
_, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
// 获取当前现金池
|
|
|
_, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if cashPools == nil {
|
|
|
if cashPoolsFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
|
|
|
}
|
|
|
|
...
|
...
|
@@ -1675,21 +1693,23 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
|
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPools[0].CashPoolId,
|
|
|
ExchangedCash: cashPools[0].ExchangedCash - person.ExchangedCash,
|
|
|
UnExchangeCash: cashPools[0].UnExchangeCash + person.ExchangedCash,
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
ExchangedCash: cashPoolsFound[0].ExchangedCash - personFoundExchangedSuMoney,
|
|
|
UnExchangeCash: cashPoolsFound[0].UnExchangeCash + personFoundExchangedSuMoney,
|
|
|
Rate: newRate,
|
|
|
ExchangedSuMoney: cashPools[0].ExchangedSuMoney - person.ExchangedSuMoney,
|
|
|
ExchangedSuMoney: cashPoolsFound[0].ExchangedSuMoney - personFoundExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
|
|
if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0])
|
|
|
// 保存现金池更新
|
|
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -1697,7 +1717,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
personDeleted, err := exchangeCashPersonListRepository.Remove(person)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -1708,7 +1727,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 根据id获取兑换清单
|
|
|
// 根据员工ids获取兑换清单
|
|
|
func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchangeCashListCommand *command.ExportExchangeCashListCommand) ([]*domain.ExchangeCashPersonList, error) {
|
|
|
if err := exportExchangeCashListCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
...
|
...
|
|