作者 唐旭辉

日常保存

package subscriber
import (
"github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain/event"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
... ... @@ -9,6 +11,24 @@ type OrderLogSubscriber struct {
transactionContext *transaction.TransactionContext
}
func (subscriber OrderLogSubscriber) AddLog() error {
var _ domain.DomainEventSubscriber = (*OrderLogSubscriber)(nil)
func (subscriber *OrderLogSubscriber) HandleEvent(domainEvent domain.DomainEvent) error {
switch domainEvent.EventType() {
case event.UPDATE_BONUS_BY_GOOD_NUMBER_EVENT:
case event.UPDATE_BONUS_BY_PARTENT_BONUS_PERCENT_EVENT:
case event.UPDATE_ORDER_REMARK:
case event.PAY_ORDER_GOOD_BONUS_EVENT:
}
return nil
}
func (subscriber *OrderLogSubscriber) SubscribedToEventTypes() []string {
return []string{
event.UPDATE_BONUS_BY_GOOD_NUMBER_EVENT,
event.UPDATE_BONUS_BY_PARTENT_BONUS_PERCENT_EVENT,
event.UPDATE_ORDER_REMARK,
event.PAY_ORDER_GOOD_BONUS_EVENT,
}
}
... ...
package command
//创建订单
type CreateOrderCommand struct {
//订单类型
OrderType int `json:"orderType"`
... ...
... ... @@ -2,6 +2,7 @@ package command
import "time"
//订单发货
type OrderDeliveryCommand struct {
OrderId int64 `json:"orderId"`
DeliveryTime time.Time `json:"deliveryTime"`
... ...
package command
//更新订单的商品数字并更新分红的数据
//UpdateGoodBouns 更新订单的商品数量,和支付状态 并更新分红的数据
type UpdateGoodBouns struct {
Id int64 `json:"id"` //订单id
GoodBouns []GoodBouns `json:"goodBouns"`
... ...
package command
//UpdateOrderPurposeCommand 更新意向
//UpdateOrderPurposeCommand 更新订单
type UpdateOrderCommand struct {
Id int64 `json:"id"`
//订单编号
... ...
... ... @@ -615,7 +615,7 @@ func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand)
return nil
}
//UpdateGoodBouns 更新货品的分红相关的数值
//UpdateGoodBouns 分红时,更新货品的分红相关的数值
func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
... ... @@ -690,7 +690,7 @@ func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) err
}
}
oldOrderData.Goods = oldOrderGoods
//变更订单类型
err = oldOrderData.Compute()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
... ... @@ -710,3 +710,43 @@ func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) err
return nil
}
//UpdateBounsWithGoodNumber 分红时,因修改订单中商品的数量发生分红变动
func (service OrderInfoService) UpdateBounsByGoodNumber() error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
//TODO
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
//UpdateBounsByPartnerBonusPercent 分红时,因修改订单中商品的合伙人分行比例发生分红变动
func (service OrderInfoService) UpdateBounsByPartnerBonusPercent() error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
//TODO
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
... ...
package event
const (
//订单分红因为货品的数量变动而发送改变
UPDATE_BONUS_BY_GOOD_NUMBER_EVENT string = "UpdateBonusByGoodNumber"
//订单分红因为合伙人分红比例变动而发送改变
UPDATE_BONUS_BY_PARTENT_BONUS_PERCENT_EVENT string = "UpdateBounsByPartnerBonusPercent"
//更新订单的备注
UPDATE_ORDER_REMARK string = "UpdateOrderRemark"
)
//UpdateBonusByGoodNumber
//订单分红因为货品的数量变动而发送改变
type UpdateBonusByGoodNumber struct {
//订单id
OrderId int64
//管理员id
AdminId int64
//货品id
GoodId int64
//货品名称
GoodName string
//旧的货品数量
FormerNumber string
//新的货品数量
NewNumber string
//旧的货品总额
FormerAmount string
//新的货品总额
NewAmount string
}
//EventType 事件名称
func (m UpdateBonusByGoodNumber) EventType() string {
return UPDATE_BONUS_BY_GOOD_NUMBER_EVENT
}
//UpdateBounsByPartnerBonusPercent
//订单分红因为合伙人分红比例变动而发送改变
type UpdateBounsByPartnerBonusPercent struct {
//订单id
OrderId int64
//管理员id
AdminId int64
//货品id
GoodId int64
//货品名称
GoodName string
//旧的合伙人分红比例
FormerPartnerBonusPercent string
//新的合伙人分红比例
NewPartnerBonusPercent string
//旧的合伙人分红
FormerPartnerBonus string
//新的合伙人分红
NewPartnerBonus string
}
//EventType 事件名称
func (m UpdateBounsByPartnerBonusPercent) EventType() string {
return UPDATE_BONUS_BY_PARTENT_BONUS_PERCENT_EVENT
}
//UpdateOrderRemark 更新订单的备注
type UpdateOrderRemark struct {
//订单id
OrderId int64
//管理员id
AdminId int64
//旧的备注
FormerRemark string
//新的备注
NewRemark string
}
//EventType 事件名称
func (m UpdateOrderRemark) EventType() string {
return UPDATE_ORDER_REMARK
}
... ...
package event
const (
PAY_ORDER_GOOD_BONUS_EVENT string = "pay-order-good-bonus-event"
PAY_ORDER_GOOD_BONUS_EVENT string = "PayOrderGoodBonus"
)
//WxPayOrderGoodBonus
//事件:支付来自微信小程序的订单中货品的分红
//PayOrderGoodBonus
//事件:支付订单中货品的分红
type PayOrderGoodBonus struct {
//订单id
OrderId int64
... ...
package event
const (
ORDER_GOOD_MODIFY_EVENT string = "order-good-modify-event"
)
type WxOrderGoodModify struct {
//订单id
GoodId int64
//货品名称 [0]旧值,[1]新值
GoodName [2]string
//商品数量 [0]旧值,[1]新值
GoodNumber [2]string
//合伙人分红比例 [0]旧值,[1]新值
PartnerBonusPercent [2]string
//合伙人应收分红 [0]旧值,[1]新值
PartnerBonus [2]string
//总价
Amount [2]string
}
//OrderModify
//事件:修改微信小程序的订单数据
type WxOrderModify struct {
//订单id
OrderId int64
//管理员id
AdminId int64
//更改的订单基础数据
GoodModify []WxOrderGoodModify
//订单备注 [0]旧值,[1]新值
Remark [2]string
}
//EventType 事件名称
func (m WxOrderModify) EventType() string {
return ORDER_GOOD_MODIFY_EVENT
}
... ... @@ -17,28 +17,29 @@ const (
//OrderLogDescript 描述日志内容
type OrderLogDescript struct {
Title string `json:"title"` //标题
Action string `json:"action"` //执行的动作描述
Item string `json:"item"` //修改的项目
Modifyitem []string `json:"modifyItem"` //动作执行结果
}
//OrderLogContentItem 记录订单的相关属性值的修改
type OrderLogContentItem struct {
Table string `json:"table"` //修改的表数据主体,"order_good","order_base"
TableId string `json:"tableId"` //表id
type OrderLogContent struct {
OrderId string `json:"orderId"` //订单id
GoodId string `json:"goodId"` //货品id
Title string `json:"title"` //名称标题
Item string `json:"item"` //修改的项目
Item string `json:"item"` //修改的数据字段
FormerValue string `json:"formerValue"` //旧值
NewValue string `json:"newValue"` //新值
}
//OrderLog 订单修改记录
type OrderLog struct {
OrderId int64 `json:"order_id"` //订单id
AlterTime time.Time `json:"alter_time"` //时间
Operator string `json:"operator"` //操作人员
OperatorType string `json:"operatorType"` //操作人员的类型
LogAction string `json:"logAction"` //执行动作
Descript []OrderLogDescript `json:"descript"` //描述日志内容
Content []OrderLogContentItem `json:"content"` //记录订单的操作动作
DataFrom string `json:"dataFrom"` //修改操作的来源:"web_admin"
OrderId int64 `json:"order_id"` //订单id
AlterTime time.Time `json:"alter_time"` //时间
Operator string `json:"operator"` //操作人员
OperatorId int64 `json:"operatorId"` //操作人员Id
OperatorType string `json:"operatorType"` //操作人员的类型
LogAction string `json:"logAction"` //执行动作
Descript []OrderLogDescript `json:"descript"` //描述日志内容
Content []OrderLogContent `json:"content"` //记录订单的操作动作
DataFrom string `json:"dataFrom"` //修改操作的来源:"web_admin"
}
... ...
package service
type OrderBonusService interface {
UpdateBounsByGoodNumber(orderId int64, adminId int64, goodWithNumber map[int64]int) error
UpdateBounsByPartnerBonusPercent(orderId int64, adminId int64, goodWithPercent map[int]float64) error
PayOrderGoodBonus(orderId int64, goodId int64, adminId int64) error
}
... ...
... ... @@ -11,19 +11,18 @@ import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
//WxOrderServices 处理来自微信小程序(海鲜干货)的订单
type WxOrderServices struct {
//OrderBonusServices 处理订单分红的相关操作
type OrderBonusServices struct {
coreDomain.BaseEventPublisher
transactionContext *transaction.TransactionContext
}
//ModifyOrderGoodData 修改订单中的单个货品的数量
func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64, adminId int64, goodNumber int) error {
//UpdateBounsWithGoodNumber 分红时,因修改订单中商品的数量发生分红变动
func (serve OrderBonusServices) UpdateBounsByGoodNumber(orderId int64, adminId int64, goodWithNumber map[int64]int) error {
var (
userRepository domain.UsersRepository
orderBaseReponsitory domain.OrderBaseRepository
orderGoodRepository domain.OrderGoodRepository
oldOrderGoods domain.OrderGood
oldOrder *domain.OrderBase
adminUser domain.Users
err error
... ... @@ -44,7 +43,7 @@ func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64,
}
oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单中的货品(id=%d)数据失败,%s", goodId, err)
e := fmt.Sprintf("获取订单(id=%d)中的货品数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId})
... ... @@ -52,10 +51,7 @@ func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64,
e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
if adminUser.CompanyId != oldOrderGoods.CompanyId {
e := fmt.Sprintf("获取管理员用户(id=%d)和货品(id=%d)不在同一家公司", adminId, goodId)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
_ = adminUser
//TODO数据更新操作
//事件发布
// modifyEvent := event.OrderModify{
... ... @@ -69,13 +65,12 @@ func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64,
return nil
}
//ModifyOrderGoodData 修改订单中的单个货品的合伙人分成比例
func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, goodId int64, adminId int64, goodNumber int) error {
//UpdateBounsByPartnerBonusPercent 分红时,因修改订单中商品的合伙人分行比例发生分红变动
func (serve OrderBonusServices) UpdateBounsByPartnerBonusPercent(orderId int64, adminId int64, goodWithPercent map[int]float64) error {
var (
userRepository domain.UsersRepository
orderBaseReponsitory domain.OrderBaseRepository
orderGoodRepository domain.OrderGoodRepository
oldOrderGoods domain.OrderGood
oldOrder *domain.OrderBase
adminUser domain.Users
err error
... ... @@ -96,7 +91,7 @@ func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, g
}
oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单中的货品(id=%d)数据失败,%s", goodId, err)
e := fmt.Sprintf("获取订单中(id=%d)的货品数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId})
... ... @@ -104,10 +99,7 @@ func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, g
e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
if adminUser.CompanyId != oldOrderGoods.CompanyId {
e := fmt.Sprintf("获取管理员用户(id=%d)和货品(id=%d)不在同一家公司", adminId, goodId)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
_ = adminUser
//TODO数据更新操作
//事件发布
// modifyEvent := event.OrderModify{
... ... @@ -122,8 +114,40 @@ func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, g
}
//PayOrderGoodBonus 支付订单中货品的分红
func (serve WxOrderServices) PayOrderGoodBonus(goodId int64, adminId int64) error {
var err error
func (serve OrderBonusServices) PayOrderGoodBonus(orderId int64, goodId int64, adminId int64) error {
var (
userRepository domain.UsersRepository
orderBaseReponsitory domain.OrderBaseRepository
orderGoodRepository domain.OrderGoodRepository
oldOrder *domain.OrderBase
adminUser domain.Users
err error
)
if orderGoodRepository, err = repository.NewOrderGoodRepository(serve.transactionContext); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderBaseReponsitory, err = repository.NewOrderBaseRepository(serve.transactionContext); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if userRepository, err = repository.NewUsersRepository(serve.transactionContext); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
oldOrder, err = orderBaseReponsitory.FindOne(domain.OrderBaseFindOneQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单(id=%d)数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单中(id=%d)的货品数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId})
if err != nil {
e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
_ = adminUser
//TODO
payEvent := event.PayOrderGoodBonus{
GoodId: goodId,
... ...
package models
import (
"context"
"time"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
... ... @@ -12,9 +14,17 @@ type OrderLog struct {
OrderId int64 `` //订单id
AlterTime time.Time `` //时间
Operator string `` //操作人员
OperatorId int64 `` //操作人员Id
OperatorType string `` //操作人员的类型
Action string `` //执行动作
LogAction string `` //执行动作
Descript []domain.OrderLogDescript `` //描述日志内容
//Content []domain.OrderLogContent `` //记录订单的操作动作
DataFrom string `` //修改操作的来源:"web_admin"
Content []domain.OrderLogContent `` //记录订单的操作动作
DataFrom string `` //修改操作的来源:"web_admin"
}
var _ pg.BeforeInsertHook = (*OrderBase)(nil)
func (l *OrderLog) BeforeInsert(ctx context.Context) (context.Context, error) {
l.AlterTime = time.Now()
return ctx, nil
}
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
... ... @@ -19,6 +20,24 @@ func NewOrderInfoRepository(transactionContext *transaction.TransactionContext)
return &OrderLogRepository{transactionContext: transactionContext}, nil
}
func (reponsitory OrderLogRepository) transformPgModelToDomainModel() (data domain.OrderLog, err error) {
return domain.OrderLog{}, nil
func (reponsitory OrderLogRepository) transformPgModelToDomainModel(m *models.OrderLog) (data domain.OrderLog, err error) {
return domain.OrderLog{
OrderId: m.OrderId,
Operator: m.Operator,
OperatorId: m.OperatorId,
OperatorType: m.OperatorType,
AlterTime: m.AlterTime,
LogAction: m.LogAction,
Descript: m.Descript,
DataFrom: m.DataFrom,
Content: m.Content,
}, nil
}
func (reponsitory OrderLogRepository) Add(data domain.OrderLog) error {
return nil
}
func (reponsitory OrderLogRepository) Find(data domain.OrderLog) ([]domain.OrderLog, int, error) {
return nil, 0, nil
}
... ...