|
|
package domainService
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
|
|
|
coreDomain "github.com/linmadan/egglib-go/core/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain/event"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/repository"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
|
|
|
)
|
|
|
|
|
|
type OrderServices struct {
|
|
|
//WxOrderServices 处理来自微信小程序(海鲜干货)的订单
|
|
|
type WxOrderServices struct {
|
|
|
coreDomain.BaseEventPublisher
|
|
|
transactionContext *transaction.TransactionContext
|
|
|
}
|
|
|
|
|
|
//UpdateOrderGoodData 修改订单中的货品数据
|
|
|
func (serve OrderServices) UpdateOrderGoodData(orderId int64, goodId int64, adminId int64, updateData map[string]string) error {
|
|
|
var err error
|
|
|
//ModifyOrderGoodData 修改订单中的单个货品的数量
|
|
|
func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64, adminId int64, goodNumber int) error {
|
|
|
var (
|
|
|
userRepository domain.UsersRepository
|
|
|
orderBaseReponsitory domain.OrderBaseRepository
|
|
|
orderGoodRepository domain.OrderGoodRepository
|
|
|
oldOrderGoods domain.OrderGood
|
|
|
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", goodId, 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)
|
|
|
}
|
|
|
if adminUser.CompanyId != oldOrderGoods.CompanyId {
|
|
|
e := fmt.Sprintf("获取管理员用户(id=%d)和货品(id=%d)不在同一家公司", adminId, goodId)
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
//TODO数据更新操作
|
|
|
//事件发布
|
|
|
modifyEvent := event.OrderGoodModify{
|
|
|
OrderId: orderId,
|
|
|
GoodId: goodId,
|
|
|
AdminId: adminId,
|
|
|
UpdateGoodData: updateData,
|
|
|
// modifyEvent := event.OrderModify{
|
|
|
// OrderId: oldOrderGoods.OrderId,
|
|
|
// AdminId: adminId,
|
|
|
// //
|
|
|
// }
|
|
|
// if err = serve.Publish(modifyEvent); err != nil {
|
|
|
// return err
|
|
|
// }
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//ModifyOrderGoodData 修改订单中的单个货品的合伙人分成比例
|
|
|
func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, goodId int64, adminId int64, goodNumber int) error {
|
|
|
var (
|
|
|
userRepository domain.UsersRepository
|
|
|
orderBaseReponsitory domain.OrderBaseRepository
|
|
|
orderGoodRepository domain.OrderGoodRepository
|
|
|
oldOrderGoods domain.OrderGood
|
|
|
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 err = serve.Publish(modifyEvent); err != nil {
|
|
|
return err
|
|
|
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", goodId, 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)
|
|
|
}
|
|
|
if adminUser.CompanyId != oldOrderGoods.CompanyId {
|
|
|
e := fmt.Sprintf("获取管理员用户(id=%d)和货品(id=%d)不在同一家公司", adminId, goodId)
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
//TODO数据更新操作
|
|
|
//事件发布
|
|
|
// modifyEvent := event.OrderModify{
|
|
|
// OrderId: oldOrderGoods.OrderId,
|
|
|
// AdminId: adminId,
|
|
|
// //
|
|
|
// }
|
|
|
// if err = serve.Publish(modifyEvent); err != nil {
|
|
|
// return err
|
|
|
// }
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//PayOrderGoodBonus 支付订单中货品的分红
|
|
|
func (serve OrderServices) PayOrderGoodBonus(orderId int64, goodId int64, adminId int64) error {
|
|
|
func (serve WxOrderServices) PayOrderGoodBonus(goodId int64, adminId int64) error {
|
|
|
var err error
|
|
|
//TODO
|
|
|
payEvent := event.PayOrderGoodBonus{
|
|
|
OrderId: orderId,
|
|
|
GoodId: goodId,
|
|
|
AdminId: adminId,
|
|
|
}
|
...
|
...
|
|