作者 陈志颖

fix:财富值贡献值排行榜调整

... ... @@ -302,12 +302,36 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
exchangeCashActivityRepository = value
}
// 兑换现金活动仓储初始化
var exchangeActivityRepository 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 {
exchangeActivityRepository = value
}
// 时间格式化
dd, _ := time.ParseDuration("24h")
var deadline = createExchangeCashActivityCommand.Deadline.Add(dd)
//dd, _ := time.ParseDuration("24h")
//var deadline = createExchangeCashActivityCommand.Deadline.Add(dd)
var deadline = createExchangeCashActivityCommand.Deadline
var t1 = time.Now()
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, time.Local)
// 获取该公司所有兑换现金活动
if _, activities, err := exchangeActivityRepository.FindAll(map[string]interface{}{
"companyId": createExchangeCashActivityCommand.CompanyId,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for _, activity := range activities {
if t2.Equal(activity.Deadline) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "兑换活动截止时间不能重合")
}
}
}
// 创建兑换活动命令
newActivity := &domain.ExchangeCashActivity{
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
... ... @@ -332,6 +356,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
activity.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedCash), 64)
activity.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedSuMoney), 64)
return activity, nil
}
}
... ... @@ -454,12 +480,14 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma
var activitiesFormat []interface{}
for _, activity := range activities {
cash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedCash), 64)
suMoney, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedSuMoney), 64)
activityFormat := map[string]interface{} {
"activityId": activity.ActivityId,
"exchangeActivityName": activity.ExchangeActivityName,
"companyId": activity.CompanyId,
"exchangedCash": activity.ExchangedCash,
"exchangedSuMoney": activity.ExchangedSuMoney,
"exchangedCash": cash,
"exchangedSuMoney": suMoney,
"deadline": activity.Deadline.UTC().Format("2006-01-02"),
"countDown": activity.CountDown,
"rate": activity.Rate,
... ... @@ -682,6 +710,8 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
activityUpdated.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedSuMoney), 64)
activityUpdated.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedCash), 64)
return activityUpdated, nil
}
}
... ... @@ -872,6 +902,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
activityUpdated.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedSuMoney), 64)
activityUpdated.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedCash), 64)
return activityUpdated, nil
}
}
... ... @@ -1831,7 +1863,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
// 判断兑换活动的现金是否超过现金池未兑换现金
if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池未兑换现金")
}
// 获取平台素币兑换情况
... ...
package domain
import (
"fmt"
"strconv"
"time"
)
... ... @@ -45,13 +43,13 @@ func (exchangeCashActivity *ExchangeCashActivity) Update(data map[string]interfa
exchangeCashActivity.CountDown = countDown.(int64)
}
if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok && exchangedSuMoney != 0 {
exchangeCashActivity.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangedSuMoney.(float64)), 64)
exchangeCashActivity.ExchangedSuMoney = exchangedSuMoney.(float64)
}
if exchangedCash, ok := data["exchangedCash"]; ok && exchangedCash != 0 {
exchangeCashActivity.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangedCash.(float64)), 64)
exchangeCashActivity.ExchangedCash = exchangedCash.(float64)
}
if exchangeRate, ok := data["exchangeRate"]; ok && exchangeRate != 0 {
exchangeCashActivity.Rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangeRate.(float64)), 64)
exchangeCashActivity.Rate = exchangeRate.(float64)
}
return nil
}
... ...
... ... @@ -385,7 +385,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryContributionsDecrease = queryContributionsDecrease.Where("e.company_id = ?", companyId)
}
queryContributionsDecrease = queryContributionsDecrease.Where(`e.status = ?`, 1)
//queryContributionsDecrease = queryContributionsDecrease.Where(`e.status = ?`, 1)
queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.record_type = ?`, 4)
if startTime, ok := queryOptions["startTime"]; ok {
queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.create_time > ?`, startTime)
... ... @@ -406,6 +406,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
queryContributions = queryContributions.ColumnExpr(`(sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease) AS employees_contributions`)
queryContributions = queryContributions.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease DESC) AS ranking")
queryContributions = queryContributions.Where(`e.status = ?`, 1)
queryContributions = queryContributions.Where("e.uid = t.uid::bigint")
queryContributions = queryContributions.Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3}))
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryContributions = queryContributions.Where("e.company_id = ?", companyId)
... ...