作者 陈志颖

feat:素币管理应用层以及资源库

正在显示 38 个修改的文件 包含 569 行增加60 行删除
... ... @@ -109,3 +109,12 @@ func CreateExchangeSuMoneyService(options map[string]interface{}) (service.Excha
}
return domainService.NewExchangeSuMoneyService(transactionContext)
}
func CreateInputCashPoolService(options map[string]interface{}) (service.InputCashPoolService, error) {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return domainService.NewCashPoolService(transactionContext)
}
... ...
... ... @@ -6,6 +6,7 @@ import (
"github.com/astaxie/beego/validation"
)
// 获取系统现金值
type SystemCashStatisticsCommand struct {
CompanyId int64 `json:"companyId" valid:"Required"` // 公司ID
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"github.com/astaxie/beego/validation"
)
// 获取系统素币值
type SystemSuMoneyStatisticsCommand struct {
CompanyId int64 `json:"companyId" valid:"Required"` // 公司ID
}
... ...
... ... @@ -206,6 +206,7 @@ func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMone
if err := systemSuMoneyStatisticsCommand.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())
... ... @@ -227,7 +228,7 @@ func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMone
}
if systemSuMoneyStatistics, err := employeeDao.CalculateSystemExchangedCash(systemSuMoneyStatisticsCommand.CompanyId); err != nil {
if systemSuMoneyStatistics, err := employeeDao.CalculateSystemCash(systemSuMoneyStatisticsCommand.CompanyId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
... ... @@ -238,13 +239,6 @@ func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMone
}
}
/**
* 获取系统现金统计
*/
//func (statisticsService *StatisticsService) SystemCashStatistics(systemCashStatisticsCommand *command.SystemCashStatisticsCommand) (interface{}, error) {
//
//}
func NewStatisticsService(options map[string]interface{}) *StatisticsService {
newStatisticsService := &StatisticsService{}
return newStatisticsService
... ...
... ... @@ -6,10 +6,15 @@ import (
"github.com/astaxie/beego/validation"
)
// 创建现金池
type CreateCashPoolCommand struct {
CashPoolId int64 `json:"cashPoolId" valid:"Required"` // 现金池ID
CompanyId int64 `json:"companyId" valid:"Requires"` // 公司ID
//CashPoolId int64 `json:"cashPoolId" valid:"Required"` // 现金池ID
CompanyId int64 `json:"companyId" valid:"Required"` // 公司ID
Cash float64 `json:"cash" valid:"Required"` // 投入的现金值
ExchangedCash float64 `json:"exchangedCash,omitempty"` // 现金池已兑换现金值
UnExchangeCash float64 `json:"unExchangeCash,omitempty"` // 现金池未兑换现金值
ExchangedSuMoney float64 `json:"exchangedSuMoney,omitempty"` // 现金池已兑换素币值
UnExchangeSuMoney float64 `json:"unExchangeSuMoney,omitempty"` // 现金池未兑换素币值
Operator int64 `json:"operator,omitempty"` // 操作人UID
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"time"
)
// 创建现金兑换活动
type CreateExchangeActivityCommand struct {
CompanyId int64 `json:"companyId" valid:"Required"` // 公司id
ExchangeActivityName string `json:"exchangeActivityName"` // 活动名称
CashPool *domain.CashPool `json:"cashPool"` // 兑换现金活动关联的现金池,最新的现金池
Deadline time.Time `json:"deadline"` // 活动截止时间
CountDown int64 `json:"countDown"` // 活动倒计时
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币
ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金
ExchangeRate float64 `json:"exchangeRate"` // 兑换汇率
ExchangeCashPeople []*domain.ExchangeCashPerson `json:"exchangeList"` // 兑换活动清单
}
func (createExchangeActivityCommand *CreateExchangeActivityCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createExchangeActivityCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
\ No newline at end of file
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
)
type CreateExchangeCashPersonCommand struct {
ExchangeCashPerson *domain.Employee `json:"exchangeCashPerson"` // 兑换现金人员
ExchangeCashActivityId int64 `json:"exchangeCashActivityId"` // 参与的兑换活动id
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币值
ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金值
}
func (createExchangeCashPersonCommand *CreateExchangeCashPersonCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createExchangeCashPersonCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
\ No newline at end of file
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
// 删除兑换现金活动
type RemoveExchangeCashActivityCommand struct {
ExchangeCashActivityId int64 `json:"exchangeCashActivityId" valid:"Required"`
}
func (removeExchangeCashActivityCommand *RemoveExchangeCashActivityCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeExchangeCashActivityCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
\ No newline at end of file
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
// 移除兑换现金人员
type RemoveExchangeCashPersonCommand struct {
ExchangeCashActivityId int64 `json:"exchangeCashActivityId" valid:"Required"` // 兑换现金人员参与的活动ID
ExchangeCashPersonId int64 `json:"exchangeCashId" valid:"Required"` // 兑换现金人员编号
}
func (removeExchangeCashPersonCommand *RemoveExchangeCashPersonCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeExchangeCashPersonCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
\ No newline at end of file
... ...
... ... @@ -14,11 +14,11 @@ type SearchSuMoneyTransactionRecordCommand struct {
RecordType int `json:"recordType,omitempty"`
// 记录类型列表(1兑换,2任务奖励,3增加,4扣除)
RecordTypes []int `json:"recordTypes,omitempty"`
// 操作人UID
// 事务时间区间-开始时间
TransactionStartTime time.Time `json:"transactionStartTime,omitempty"`
// 事务时间区间-截止时间
TransactionEndTime time.Time `json:"transactionEndTime,omitempty"`
// 操作人UID
Operator int64 `json:"operator,omitempty"`
// 查询偏离量
Offset int `json:"offset,omitempty"`
... ...
... ... @@ -7,7 +7,8 @@ import (
"time"
)
type CreateExchangeActivityCommand struct {
type UpdateExchangeCashActivity struct {
ExchangeCashActivityId int64 `json:"exchangeCashActivityId"` // 兑换现金活动id
CompanyId int64 `json:"companyId" valid:"Required"` // 公司id
ExchangeActivityName string `json:"exchangeActivityName"` // 活动名称
Deadline time.Time `json:"deadline"` // 活动截止时间
... ... @@ -15,12 +16,12 @@ type CreateExchangeActivityCommand struct {
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币
ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金
ExchangeRate float64 `json:"exchangeRate"` // 兑换汇率
ExchangeCashPeople []*domain.ExchangeCashPerson `json:"exchangeList"` // 兑换活动清单
ExchangeCashPeople []*domain.ExchangeCashPerson `json:"exchangeCashPeople"` // 兑换活动清单
}
func (createExchangeActivityCommand *CreateExchangeActivityCommand) ValidateCommand() error {
func (updateExchangeCashActivity *UpdateExchangeCashActivity) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createExchangeActivityCommand)
b, err := valid.Valid(updateExchangeCashActivity)
if err != nil {
return err
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type UpdateExchangeCashPersonCommand struct {
ExchangeCashPersonId int64 `json:"exchangeCashPersonId" valid:"Required"` // 兑换现金人员编号
ExchangeCashActivityId int64 `json:"exchangeCashActivityId" valid:"Required"` // 参与的兑换现金活动id
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币(需要和当前的已兑换素币进行比较,少于当前已兑换素币则生成一条扣除素币记录,大于当前已兑换素币则生成一条增加素币记录)
ExchangedCash float64 `json:"exchangedCash"` // 已兑换的现金
}
func (updateExchangeCashPersonCommand *UpdateExchangeCashPersonCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateExchangeCashPersonCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
\ No newline at end of file
... ...
package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
// 获取现金池
type GetCashPoolQuery struct {
CompanyId int64 `json:"companyId"` // 公司id
}
func (getCashPoolQuery *GetCashPoolQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getCashPoolQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
\ No newline at end of file
... ...
package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
// 获取兑换现金活动
type GetExchangeCashActivityQuery struct {
ExchangeCashActivityId int64 `json:"exchangeCashActivityId"` // 兑换现金活动id
}
func (getExchangeCashActivityQuery *GetExchangeCashActivityQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getExchangeCashActivityQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
\ No newline at end of file
... ...
package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
// 获取兑换现金活动列表
type ListExchangeCashActivityQuery struct {
CompanyId int64 `json:"companyId"` // 公司id
}
func (listExchangeCashActivityQuery *ListExchangeCashActivityQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listExchangeCashActivityQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
\ No newline at end of file
... ...
package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
// 获取兑换活动兑换清单
type ListExchangeCashPersonQuery struct {
ExchangeCashActivityId int64 `json:"exchangeCashActivityId"` // 兑换现金活动id
}
func (listExchangeCashPersonQuery *ListExchangeCashPersonQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listExchangeCashPersonQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
\ No newline at end of file
... ...
package service
// 投入现金服务
type CashService struct {
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
)
// 现金池服务
type CashPoolService struct {
}
// 投入现金
//func (cashService *CashService) InputCashPool(inputCashPoolCommand *command.InputCashPooCommand) (interface{}, error) {
//
//}
\ No newline at end of file
// 操作现金池
func (cashService *CashPoolService) OperationCashPool(createCashPoolCommand *command.CreateCashPoolCommand) (interface{}, error) {
if err := createCashPoolCommand.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())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var cashPoolService service.InputCashPoolService
if value, err := factory.CreateInputCashPoolService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cashPoolService = value
}
if task, err := cashPoolService.Input(createCashPoolCommand.CompanyId, createCashPoolCommand.Operator, createCashPoolCommand.Cash); err != 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 task, nil
}
}
func NewCashPoolService(options map[string]interface{}) *CashPoolService {
newCashPoolService := &CashPoolService{}
return newCashPoolService
}
... ...
... ... @@ -114,9 +114,6 @@ func (suMoneyService *SuMoneyService) ExchangeSuMoney(exchangeSuMoneyCommand *co
}
}
// 素币兑换现金
//func (suMoneyService *SuMoneyService) ExchangeCash(exchangeCashComman *)
// 搜索素币事务记录
func (suMoneyService *SuMoneyService) SearchSuMoneyTransactionRecord(searchSuMoneyTransactionRecordCommand *command.SearchSuMoneyTransactionRecordCommand) (interface{}, error) {
if err := searchSuMoneyTransactionRecordCommand.ValidateCommand(); err != nil {
... ...
package domain
import "time"
// 现金池
type CashPool struct {
CashPoolId int64 `json:"cashPoolId"` // 现金池id
... ... @@ -9,11 +11,14 @@ type CashPool struct {
UnExchangeCash float64 `json:"unExchangeCash"` // 未兑换的现金
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币
UnExchangeSuMoney float64 `json:"unExchangeSuMoney"` // 未兑换的素币
Operator *EmployeeInfo `json:"operator"` // 操作人
Rate float64 `json:"rate"` // 平均兑换汇率
CreateTime time.Time `json:"createTime"` // 现金投入现金池时间
}
type CashPoolRepository interface {
Save(cashPool *CashPool) (*CashPool, error)
FindOne(queryOptions map[string]interface{}) (*CashPool, error)
}
func (cashPool *CashPool) Identity() interface{} {
... ...
... ... @@ -2,9 +2,9 @@ package domain
// 参与兑换现金人员
type ExchangeCashPerson struct {
PersonId int64 `json:"employeeId"` // 兑换人员ID
ExchangeCashPersonId int64 `json:"employeeId"` // 兑换人员ID
CompanyId int64 `json:"companyId"` // 公司id
PersonInfo *EmployeeInfo `json:"employeeInfo"` // 兑换人员信息
ExchangeCashPersonInfo *EmployeeInfo `json:"employeeInfo"` // 兑换人员信息
ExchangedSuMoney float64 `json:"suMoney"` // 已兑换的素币
ExchangedCash float64 `json:"cash"` // 已兑换的现金
}
... ... @@ -17,8 +17,8 @@ type ExchangeCashPersonRepository interface {
}
func (exchangeCashPerson *ExchangeCashPerson) Identity() interface{} {
if exchangeCashPerson.PersonId == 0 {
if exchangeCashPerson.ExchangeCashPersonId == 0 {
return nil
}
return exchangeCashPerson.PersonId
return exchangeCashPerson.ExchangeCashPersonId
}
\ No newline at end of file
... ...
package service
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
)
type InputCashPoolService interface {
coreDomain.DomainEventPublisher
Input(companyId int64, operatorUid int64, cash float64) (*domain.CashPool, error)
}
... ...
... ... @@ -19,7 +19,7 @@ type SuMoneyTransactionRecord struct {
CashPoolBeforeTransaction *CashPool `json:"cashPoolBeforeTransaction"` // 事务处理前现金池,用于兑换现金操作
CurrentCashPool *CashPool `json:"currentCashPool"` // 当前现金池,用于兑换现金操作
SuMoney float64 `json:"suMoney"` // 事务素币值
Cash float64 `json:"cash"` // 事务现金值,用于兑换现金
Cash float64 `json:"cash"` // 事务现金值,用于兑换现金操作
Operator *EmployeeInfo `json:"operator"` // 操作人
RecordDescription string `json:"recordDescription"` // 素币事务记录描述
CreateTime time.Time `json:"createTime"` // 创建时间
... ...
... ... @@ -115,8 +115,8 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{
}
func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
var incomeSuMoney float64
var expendSuMoney float64
var incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加)
var expendSuMoney float64 // 消耗的素币(1:兑换(物资、现金),4: 扣除)
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
if err := tx.Model(suMoneyTransactionRecordModel).
... ... @@ -143,40 +143,47 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
}, nil
}
func (dao *EmployeeDao) CalculateSystemUnChangeSuMoney(companyId int64) (map[string]interface{}, error) {
var unExchangeSuMoney float64
// 计算系统素币
func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) ( float64, float64, error) {
var systemUnExchangeSuMoney float64
var systemExchangedSuMoney float64
tx := dao.transactionContext.PgTx
employeeModel := new(models.Employee)
employeeModel := new(models.Employee)
if err := tx.Model(employeeModel).
ColumnExpr("sum(employee.su_money) AS unExchangeSuMoney").
ColumnExpr("sum(employee.su_money) AS system_unExchange_su_money").
Where("employee.company_id = ?", companyId).
Select(&employeeModel); err != nil {
return nil, err
Select(&systemUnExchangeSuMoney); err != nil {
return 0, 0, err
}
return map[string]interface{}{
"unExchangeSuMoney": unExchangeSuMoney,
}, nil
exchangeCashActivityModel := new(models.ExchangeCashActivity)
if err := tx.Model(exchangeCashActivityModel).
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
}
return systemUnExchangeSuMoney, systemExchangedSuMoney, nil
}
func (dao *EmployeeDao) CalculateSystemExchangedCash(companyId int64) (map[string]interface{}, error) {
var exchangedCash float64
// 计算系统已兑换现金
func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (float64, error) {
var systemExchangedCash float64 // 系统已兑换现金
tx := dao.transactionContext.PgTx
suMoneyExchangeTransactionRecordModel := new(models.SuMoneyExchangeTransactionRecord)
exchangeCashActivityModel := new(models.ExchangeCashActivity)
if err := tx.Model(suMoneyExchangeTransactionRecordModel).
ColumnExpr("sum(su_money_exchange_transaction_record.cash) AS exchangedCash").
Where("su_money_exchange_transaction_record.company_id = ?", companyId).
Select(&suMoneyExchangeTransactionRecordModel) ; err != nil {
return nil, err
if err := tx.Model(exchangeCashActivityModel).
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
}
return map[string]interface{}{
"exchangedCash": exchangedCash,
}, nil
return systemExchangedCash, nil
}
func NewEmployeeDao(transactionContext *pgTransaction.TransactionContext) (*EmployeeDao, error) {
... ...
package domain_service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository"
"time"
)
type CashPoolService struct {
coreDomain.BaseEventPublisher
transactionContext *pgTransaction.TransactionContext
}
func (service *CashPoolService) Input(companyId int64, operatorUid int64, cash float64) (*domain.CashPool, error) {
var cashPoolRepository domain.CashPoolRepository
var employeeRepository domain.EmployeeRepository
if repository, err := repository.NewEmployeeRepository(service.transactionContext); err != nil {
return nil, err
} else {
employeeRepository = repository
}
transactionContext, err := factory.CreateTransactionContext(nil)
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
employeeDao = value
}
var systemExchangedCash float64
if value, err := employeeDao.CalculateSystemCash(companyId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
systemExchangedCash = value
}
var (
systemChangedSuMoney float64
systemUnChangeSuMoney float64
)
if value1, value2, err := employeeDao.CalculateSystemSuMoney(companyId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
systemChangedSuMoney = value1
systemUnChangeSuMoney = value2
}
operator, err := employeeRepository.FindOne(map[string]interface{}{
"uid": operatorUid,
})
if err != nil {
return nil, err
}
if operator == nil {
return nil, fmt.Errorf("无效的操作者")
}
currentCashPool, err := cashPoolRepository.FindOne(map[string]interface{}{
"companyId": companyId,
})
if err != nil {
return nil, err
}
if currentCashPool.ExchangedCash > cash {
return nil, fmt.Errorf("当前投入现金少于系统已兑换现金值")
}
cashPoolInfo := &domain.CashPool{
CompanyId: companyId,
Cash: cash,
ExchangedCash: systemExchangedCash,
UnExchangeCash: currentCashPool.UnExchangeCash + cash,
ExchangedSuMoney: systemChangedSuMoney,
UnExchangeSuMoney: systemUnChangeSuMoney,
Rate: systemExchangedCash / systemChangedSuMoney,
Operator: operator.EmployeeInfo,
CreateTime: time.Now(),
}
if cashPool, err := cashPoolRepository.Save(cashPoolInfo); err != nil {
return nil, err
} else {
return cashPool, nil
}
}
func NewCashPoolService(transactionContext *pgTransaction.TransactionContext) (*CashPoolService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CashPoolService{
transactionContext: transactionContext,
}, nil
}
}
\ No newline at end of file
... ...
... ... @@ -37,6 +37,7 @@ func init() {
(*models.Notification)(nil),
(*models.SentNotification)(nil),
(*models.ExchangeActivities)(nil),
(*models.CashPool)(nil),
} {
err := DB.CreateTable(model, &orm.CreateTableOptions{
Temp: false,
... ...
package models
type CashPool struct {
Id int64 `json:"id"` // 现金池id
}
... ...
... ... @@ -5,7 +5,7 @@ import (
"time"
)
type ExchangeActivities struct {
type ExchangeCashActivity struct {
TableName string `pg:"exchange_activities,alias:exchange_activity"`
Id int64 `pg:",pk"` // 兑换活动ID
CompanyId int64 // 公司ID
... ...
package models
type ExchangeCashPerson struct {
}
\ No newline at end of file
... ...
package repository
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
)
type CashPoolRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repostitory *CashPoolRepository) Save() (*domain.CashPool, error) {
return nil, nil
}
func (repostitory *CashPoolRepository) FindOne(queryOptions map[string]interface{}) (*domain.CashPool, error) {
return nil, nil
}
func (repository *CashPoolRepository) transformPgModelToDomainModel(cashPoolModel *models.CashPool) (*domain.CashPool, error) {
return &domain.CashPool{
CashPoolId: cashPoolModel.Id,
}, nil
}
func NewCashPoolRepository(transactionContext *pgTransaction.TransactionContext) (*CashPoolRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为null")
} else {
return &CashPoolRepository{
transactionContext: transactionContext,
}, nil
}
}
\ No newline at end of file
... ...
package repository
import (
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)
type ExchangeCashActivityRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *ExchangeCashActivityRepository) Save() (*ExchangeCashActivityRepository, error) {
return nil, nil
}
func (repository *ExchangeCashActivityRepository) FindOne(queryOptions map[string]interface{}) (*ExchangeCashActivityRepository, error) {
return nil, nil
}
func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]interface{}) (*ExchangeCashActivityRepository, error) {
return nil, nil
}
func (repository *ExchangeCashActivityRepository) Remove() (*ExchangeCashActivityRepository, error) {
return nil, nil
}
//func (repository *ExchangeCashActivityRepository) transformPgModelToDomainModel(customerValueModel *models.CustomerValue) (*domain.CustomerValue, error) {
// return &domain.CustomerValue{
// CustomerValueId: customerValueModel.Id,
// CustomerValueName: customerValueModel.CustomerValueName,
// CompanyId: customerValueModel.CompanyId,
// }, nil
//}
//func NewExchangeCashActivityRepository(transactionContext *pgTransaction.TransactionContext) (*CustomerValueRepository, error) {
// if transactionContext == nil {
// return nil, fmt.Errorf("transactionContext参数不能为nil")
// } else {
// return &CustomerValueRepository{
// transactionContext: transactionContext,
// }, nil
// }
//}
\ No newline at end of file
... ...