作者 陈志颖

feat:添加兑换活动领域对象、现金池领域对象

正在显示 37 个修改的文件 包含 192 行增加0 行删除
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type InputCashPooCommand struct {
  10 + Cash float64 `json:"cash" valid:"Required"` // 投入的现金值
  11 + Operator int64 `json:"operator,omitempty"` // 操作人UID
  12 + InputDescription string `json:"inputDescription" valid:"Required"` // 投入描述
  13 +}
  14 +
  15 +func (inputCashPooCommand *InputCashPooCommand) ValidateCommand() error {
  16 + valid := validation.Validation{}
  17 + rt, err := valid.Valid(inputCashPooCommand)
  18 + if err != nil {
  19 + return err
  20 + }
  21 + if !rt {
  22 + for _, validErr := range valid.Errors {
  23 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  24 + }
  25 + }
  26 + return nil
  27 +}
  1 +package service
  2 +
  3 +// 投入现金服务
  4 +type CashService struct {
  5 +}
  6 +
  7 +// 投入现金
  8 +//func (cashService *CashService) InputCashPool(inputCashPoolCommand *command.InputCashPooCommand) (interface{}, error) {
  9 +//
  10 +//}
  1 +package domain
  2 +
  3 +// 现金池信息
  4 +type CashPoolInfo struct {
  5 + Cash float64 `json:"cash"` // 投入现金池的现金
  6 + ExchangedCash float64 `json:"exchangedCash"` // 已兑换的现金
  7 + UnExchangeCash float64 `json:"unExchangeCash"` // 未兑换的现金
  8 + ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币
  9 + UnExchangeSuMoney float64 `json:"unExchangeSuMoney"` // 未兑换的素币
  10 + Rate float64 `json:"rate"` // 平均兑换汇率
  11 +}
  1 +package domain
  2 +
  3 +// 兑换活动
  4 +type ExchangeActivity struct {
  5 + ActivityId int64 `json:"activityId"` // 活动编号
  6 + ExchangedCash float64 `json:"exchangedCash"` // 已兑换的现金
  7 + ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币
  8 + Rate float64 `json:"rate"` // 兑换汇率
  9 +}
  10 +
  11 +type ExchangeActivityRepository interface {
  12 + Save(activity *ExchangeActivity) (*ExchangeActivity, error)
  13 + Remove(activity *ExchangeActivity) (*ExchangeActivity, error)
  14 + FindOne(queryOptions map[string]interface{}) (*ExchangeActivity, error)
  15 + Find(queryOptions map[string]interface{}) (int64, []*ExchangeActivity, error)
  16 +}
  17 +
  18 +func (activity *ExchangeActivity) Identity() interface{} {
  19 + if activity.ActivityId == 0 {
  20 + return nil
  21 + }
  22 + return activity.ActivityId
  23 +}
  24 +
  25 +func (activity *ExchangeActivity) TransferSuMoney(rate float64) error {
  26 + activity.ExchangedSuMoney = activity.ExchangedCash * rate
  27 + return nil
  28 +}
  1 +package domain
  2 +
  3 +// 兑换人
  4 +type ExchangePerson struct {
  5 + Uid int64 `json:"uid"` // 统一用户ID
  6 + Name string `json:"name"` // 已兑换人员名称
  7 + Account string `json:"account"` // 已兑换人员账号
  8 + ExchangedSuMoney float64 `json:"exchangeSuMoney"` // 已兑换素币
  9 + ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金
  10 +}
  11 +
  12 +type ExchangePersonRepository interface {
  13 + Save(exchangePerson *ExchangePerson) (*ExchangePerson, error)
  14 + Remove(exchangePerson *ExchangePerson) (*ExchangePerson, error)
  15 + FindOne(queryOptions map[string]interface{}) (*ExchangePerson, error)
  16 + Find(queryOptions map[string]interface{}) (int64, []*ExchangePerson, error)
  17 +}
  18 +
  19 +func (exchangePerson *ExchangePerson) TransferSuMoney(rate float64) error {
  20 + exchangePerson.ExchangedCash = exchangePerson.ExchangedSuMoney / rate
  21 + return nil
  22 +}
  1 +package models
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  5 + "time"
  6 +)
  7 +
  8 +type CashPoolTransactionRecord struct {
  9 + TableName string `pg:"cash_pool"`
  10 + CreateTime time.Time // 创建时间
  11 +}
  1 +package routers
  2 +
  3 +//func init() {
  4 +// /*****************************************现金池**********************************/
  5 +// beego.Router("/", &controllers.ConfigController{}, "POST:CashInput") // 现金池投入
  6 +//
  7 +// /*****************************************兑换活动*********************************/
  8 +// beego.Router("/", &controllers.ConfigController{}, "GET:ListExchangeActivities") // 返回兑换活动列表
  9 +// beego.Router("/", &controllers.ConfigController{}, "PUT:UpdateExchangeActivities") // 更新兑换活动信息
  10 +// beego.Router("/", &controllers.ConfigController{}, "POST:CreateExchangeActivities") // 新增兑换活动
  11 +// beego.Router("/", &controllers.ConfigController{}, "DELETE:DeleteExchangeActivities") // 删除兑换活动
  12 +// beego.Router("/", &controllers.ConfigController{}, "POST:SearchExchangeActivities") // 搜索兑换素币活动
  13 +// beego.Router("/", &controllers.ConfigController{}, "GET:ExchangeActivitiesStatistics") // 兑换活动数据统计
  14 +//
  15 +// /*****************************************兑换素币清单****************************/
  16 +// beego.Router("/", &controllers.ConfigController{}, "GET:ListExchangeList") // 返回素币兑换清单列表
  17 +// beego.Router("/", &controllers.ConfigController{}, "GET:GetExchangeList") // 返回素币兑换清单
  18 +// beego.Router("/", &controllers.ConfigController{}, "POST:CreateExchangeList") // 新增素币兑换清单
  19 +// beego.Router("/", &controllers.ConfigController{}, "PUT:UpdateExchangeList") // 更新素币兑换清单
  20 +// beego.Router("/", &controllers.ConfigController{}, "DELETE:RemoveExchangeList") // 删除素币兑换清单
  21 +// beego.Router("/", &controllers.ConfigController{}, "POST:SearchExchangeList") // 搜索素币兑换记录
  22 +// beego.Router("/", &controllers.ConfigController{}, "POST:ExportExchangeList") // 导出素币兑换清单
  23 +// beego.Router("/", &controllers.ConfigController{}, "POST:ImportExchangeList") // 导入素币兑换清单
  24 +//}
  1 +package cashPool
  2 +
  3 +import (
  4 + "github.com/onsi/ginkgo"
  5 + "github.com/onsi/gomega"
  6 + "net/http"
  7 + "net/http/httptest"
  8 + "testing"
  9 +
  10 + "github.com/astaxie/beego"
  11 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  12 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego"
  13 +)
  14 +
  15 +func TestConfig(t *testing.T) {
  16 + gomega.RegisterFailHandler(Fail)
  17 + ginkgo.RunSpecs()
  18 +}
  19 +
  20 +var handler http.Handler
  21 +var server *httptest.Server
  22 +
  23 +var _ = BeforeSuite(func() {
  24 + handler = beego.BeeApp.Handlers
  25 + server = httptest.NewServer(handler)
  26 +})
  27 +
  28 +var _ = ginkgo.AfterSuite(func() {
  29 + server.Close()
  30 +})