作者 陈志颖

feat:增加现金池未兑换现金累积

... ... @@ -2,7 +2,6 @@ package service
import (
"fmt"
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/utils/tool_funs"
"strconv"
"time"
... ... @@ -59,22 +58,34 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
systemUnChangeSuMoney = value2
}
// TODO 获取上一个现金池现金值
var cashPoolRepository domain.CashPoolRepository
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cashPoolRepository = value
}
rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemChangedSuMoney), 64)
_, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
"companyId": createCashPoolCommand.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemChangedSuMoney), 64) // 平均兑换汇率
newCashPool := &domain.CashPool{
CompanyId: createCashPoolCommand.CompanyId,
Cash: createCashPoolCommand.Cash,
ExchangedCash: systemExchangedCash,
UnExchangeCash: createCashPoolCommand.Cash, // TODO 投入的现金 + 系统未兑换的现金
UnExchangeCash: createCashPoolCommand.Cash + cashPools[0].UnExchangeCash,
ExchangedSuMoney: systemChangedSuMoney,
UnExchangeSuMoney: systemUnChangeSuMoney,
Rate: rate,
CreateTime: time.Now(),
}
var cashPoolRepository domain.CashPoolRepository
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
... ... @@ -131,12 +142,9 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
// 新增兑换现金活动
func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchangeCashActivityCommand *command.CreateExchangeCashActivityCommand) (interface{}, error) {
// 校验新增任务命令
if err := createExchangeCashActivityCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
// 新建校验任务事务
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -148,7 +156,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
transactionContext.RollbackTransaction()
}()
// 创建兑换活动
newActivity := &domain.ExchangeCashActivity{
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
CompanyId: createExchangeCashActivityCommand.CompanyId,
... ... @@ -160,7 +167,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
CreateTime: time.Now(),
}
// 兑换活动资源库
var exchangeCashActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -252,7 +258,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang
if activity == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashActivityCommand.ActivityId)))
}
if activityDeleted, err := exchangeCashActivityRepository.Remove(activity); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -335,15 +340,12 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
if activity == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
}
if activity == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
}
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if activityUpdated, err := exchangeCashActivityRepository.Save(activity); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -383,7 +385,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
// TODO 新增兑换人员时,判断成员是否存在,以手机账号为判断依据
// 创建兑换清单
newPerson := &domain.ExchangeCashPersonList{
EmployeeInfo: &domain.EmployeeInfo{
EmployeeName: createExchangeCashPersonCommand.PersonName,
... ... @@ -402,7 +403,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
} else {
exchangeCashPersonListRepository = value
}
if person, err := exchangeCashPersonListRepository.Save(newPerson); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -524,9 +524,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
if person == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
}
beego.Info(person)
if personDeleted, err := exchangeCashPersonListRepository.Remove(person); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -4,14 +4,14 @@ import "time"
// 兑换现金活动
type ExchangeCashActivity struct {
ActivityId int64 `json:"activityId"` // 兑换现金活动id
ActivityId int64 `json:"activityId"` // 兑换现金活动id
ExchangeActivityName string `json:"exchangeActivityName"` // 兑换现金活动名称
CompanyId int64 `json:"companyId"` // 公司ID
ExchangedCash float64 `json:"exchangedCash"` // 已兑换的现金
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币
CreateTime time.Time `json:"createTime"` // 创建兑换现金活动时间
Deadline time.Time `json:"deadline"` // 兑换现金活动截止时间
CountDown int64 `json:"countDown"` // 兑换现金活动结束倒计时
CountDown int64 `json:"countDown"` // 兑换现金活动结束倒计时
Rate float64 `json:"rate"` // 兑换汇率
}
... ... @@ -56,11 +56,6 @@ func (exchangeCashActivity *ExchangeCashActivity) TransferSuMoney(rate float64)
return nil
}
//func (exchangeCashActivity *ExchangeCashActivity) TransferLastRate(lastRate float64) error {
// exchangeCashActivity.LastRate = lastRate
// return nil
//}
func (exchangeCashActivity *ExchangeCashActivity) TransferCountDown() error {
exchangeCashActivity.CountDown = int64(time.Until(exchangeCashActivity.Deadline))
return nil
... ...
... ... @@ -19,16 +19,16 @@ func (dao *CashPoolDao) CalculateSystemSuMoney(companyId int64) ( float64, float
employeeModel := new(models.Employee)
if err := tx.Model(employeeModel).
ColumnExpr("sum(employees.su_money) AS system_unExchange_su_money").
Where("employees.company_id = ?", companyId).
ColumnExpr("sum(employee.su_money) AS system_unExchange_su_money").
Where("employee.company_id = ?", companyId).
Select(&systemUnExchangeSuMoney); err != nil {
return 0, 0, err
}
exchangeCashActivityModel := new(models.ExchangeCashActivity)
if err := tx.Model(exchangeCashActivityModel).
ColumnExpr("sum(exchange_cash_activities.exchanged_su_money) AS system_changed_su_money").
Where("exchange_cash_activities.company_id = ?", companyId).
ColumnExpr("sum(exchange_cash_activity.exchanged_su_money) AS system_changed_su_money").
Where("exchange_cash_activity.company_id = ?", companyId).
Select(&systemExchangedSuMoney); err != nil {
return 0, 0, err
}
... ... @@ -44,8 +44,8 @@ func (dao *CashPoolDao) CalculateSystemCash(companyId int64) (float64, error) {
exchangeCashActivityModel := new(models.ExchangeCashActivity)
if err := tx.Model(exchangeCashActivityModel).
ColumnExpr("sum(exchange_cash_activities.exchanged_cash) AS system_exchanged_cash").
Where("exchange_cash_activities.company_id = ?", companyId).
ColumnExpr("sum(exchange_cash_activity.exchanged_cash) AS system_exchanged_cash").
Where("exchange_cash_activity.company_id = ?", companyId).
Select(&systemExchangedCash) ; err != nil {
return 0, err
}
... ...
... ... @@ -60,15 +60,12 @@ func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]i
var exchangeCashActivityModels []*models.ExchangeCashActivity
exchangeCashActivities := make([]*domain.ExchangeCashActivity, 0)
query := tx.Model(&exchangeCashActivityModels)
// 公司相关活动搜索
if companyId, ok := queryOptions["companyId"]; ok {
query = query.Where(`exchange_cash_activity.company_id = ?`, companyId)
}
// 活动名称模糊搜索
if exchangeCashActivityNameMatch, ok := queryOptions["exchangeCashActivityNameMatch"]; ok && (exchangeCashActivityNameMatch != "") {
query = query.Where(`exchange_cash_activity.activity_name LIKE ?`, fmt.Sprintf("%%%s%%", exchangeCashActivityNameMatch.(string)))
}
// 活动截止时间搜索
if deadline, ok := queryOptions["exchangeCashActivityDeadline"]; ok && !deadline.(time.Time).IsZero() {
query = query.Where(`exchange_cash_activity.deadline < ?`, deadline)
}
... ... @@ -105,7 +102,6 @@ func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]i
func (repository *ExchangeCashActivityRepository) Remove(exchangeCashActivity *domain.ExchangeCashActivity) (*domain.ExchangeCashActivity, error) {
tx := repository.transactionContext.PgTx
exchangeCashActivityModel := new(models.ExchangeCashActivity)
//exchangeCashActivity.ActivityId = exchangeCashActivity.Identity().(int64)
exchangeCashActivityModel.Id = exchangeCashActivity.ActivityId
if _, err := tx.Model(exchangeCashActivityModel).WherePK().Delete(); err != nil {
return exchangeCashActivity, err
... ...
... ... @@ -98,7 +98,6 @@ func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string
func (repository *ExchangeCashPersonListRepository) Remove(exchangeCashList *domain.ExchangeCashPersonList) (*domain.ExchangeCashPersonList, error) {
tx := repository.transactionContext.PgTx
exchangeCashListModel := new(models.ExchangeCashPersonList)
//exchangeCashList.ListId = exchangeCashList.Identity().(int64)
exchangeCashListModel.Id = exchangeCashList.ListId
if _, err := tx.Model(exchangeCashListModel).WherePK().Delete(); err != nil {
return exchangeCashList, err
... ...