作者 yangfu

Merge remote-tracking branch 'origin/test'

正在显示 38 个修改的文件 包含 1889 行增加2307 行删除

要显示太多修改。

为保证性能只显示 38 of 38+ 个文件。

... ... @@ -22,6 +22,6 @@
*.sum
/vendor
/*.exe~
/logs
... ...
... ... @@ -5,11 +5,12 @@ WORKDIR $APP_DIR/
COPY ./pkg pkg
COPY ./conf conf
COPY ./go.mod go.mod
COPY ./vendor vendor
COPY ./main.go main.go
RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"]
ENV GO111MODULE on
ENV GOPROXY https://goproxy.cn
RUN ["go","mod","tidy"]
RUN ["go","build"]
# RUN ["go","mod","tidy"]
RUN ["go","build","-mod=vendor"]
EXPOSE 8082
ENTRYPOINT ["./partnermg"]
\ No newline at end of file
... ...
... ... @@ -21,18 +21,10 @@ func CreatePartnerInfoDao(options map[string]interface{}) (*dao.PartnerInfoDao,
return dao.NewPartnerInfoDao(transactionContext)
}
func CreateOrderDao(options map[string]interface{}) (*dao.OrderDao, error) {
func CreateOrderBaseDao(options map[string]interface{}) (*dao.OrderBaseDao, error) {
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*transaction.TransactionContext)
}
return dao.NewOrderDao(transactionContext)
}
func CreateOrderPaymentDao(options map[string]interface{}) (*dao.OrderPayment, error) {
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*transaction.TransactionContext)
}
return dao.NewOrderPayment(transactionContext)
return dao.NewOrderBaseDao(transactionContext)
}
... ...
... ... @@ -33,20 +33,20 @@ func CreateAdminPermissionRepository(options map[string]interface{}) (domain.Adm
return repository.NewAdminPermissionRepository(transactionContext)
}
//CreateOrderPaymentRepository 分红单信息
func CreateOrderPaymentRepository(options map[string]interface{}) (domain.OrderPaymentRepository, error) {
//CreateOrderBaseRepository 订单信息
func CreateOrderBaseRepository(options map[string]interface{}) (domain.OrderBaseRepository, error) {
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*transaction.TransactionContext)
}
return repository.NewOrderPaymentRepository(transactionContext)
return repository.NewOrderBaseRepository(transactionContext)
}
//CreateOrderRepository 订单信息
func CreateOrderRepository(options map[string]interface{}) (domain.OrderRepository, error) {
//CreateOrderGoodRepository 订单信息
func CreateOrderGoodRepository(options map[string]interface{}) (domain.OrderGoodRepository, error) {
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*transaction.TransactionContext)
}
return repository.NewOrderRepository(transactionContext)
return repository.NewOrderGoodRepository(transactionContext)
}
... ...
package command
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
type CreateOrderCommand struct {
//订单区域
OrderRegion string
//订单编号
OrderCode string `json:"orderCode"`
//订单名称
OrderName string `json:"oderName"`
//数量
OrderCount int `json:"orderCount"`
//实际订单数量
OrderActualCount int `json:"orderActualCount"`
//订单金额
OrderAmount float64 `json:"orderAmount"`
//订单实际金额
OrderActualAmount float64 `json:"orderActualAmount"`
//订单状态
OrderStatus int `json:"orderStatus"`
//买家
BuyerName string `json:"buyerName"`
//买家电话
BuyerPhone string `json:"buyerPhone"`
//地址
BuyerAddress string `json:"address"`
//合伙人数据
PartnerId int64 `json:"partId"`
//合伙人分红百分比
PartnerBonusPercent float64 `json:"partnerBonusPercent"`
//业务员分红百分比
SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
//订单类型
OrderType int `json:"orderType"`
}
func (command CreateOrderCommand) ValidateCommand() error {
if len(command.BuyerName) == 0 || len(command.BuyerPhone) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "买家信息必填")
}
if len(command.BuyerAddress) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "买家地址必填")
}
if len(command.OrderCode) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单编号必填")
}
if len(command.OrderRegion) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
}
if !(command.OrderType == domain.OrderReal ||
command.OrderType == domain.OrderIntention) {
return lib.ThrowError(lib.ARG_ERROR, "订单类型错误")
}
if !(command.OrderStatus == domain.OrderStatusDeliverSome ||
command.OrderStatus == domain.OrderStatusDeliverAll ||
command.OrderStatus == domain.OrderStatusReserve) {
return lib.ThrowError(lib.ARG_ERROR, "订单状态设置错误")
}
return nil
}
package command
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
type UpdateOrderCommand struct {
//id
Id int64 `json:"id"`
//订单编号
OrderCode string `json:"orderCode"`
//订单名称
OrderName string `json:"oderName"`
//数量
OrderCount int `json:"orderCount"`
//订单金额
OrderAmount float64 `json:"orderAmount"`
//买家
BuyerPhone string `json:"buyerPhone"`
//地址
BuyerAddress string `json:"address"`
//订单区域
OrderRegion string `json:"orderRegion"`
//合伙人分红百分比
PartnerBonusPercent float64 `json:"partnerBonusPercent"`
//业务员分红百分比
SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
//订单状态
OrderStatus int `json:"orderStatus"`
//订单类型
OrderType int `json:"orderType"`
}
func (command UpdateOrderCommand) ValidateCommand() error {
if command.Id == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单id错误")
}
if len(command.BuyerPhone) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "买家信息必填")
}
if len(command.BuyerAddress) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "买家地址必填")
}
if len(command.OrderCode) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单编号必填")
}
if len(command.OrderRegion) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
}
if !(command.OrderType == domain.OrderReal ||
command.OrderType == domain.OrderIntention) {
return lib.ThrowError(lib.ARG_ERROR, "订单类型错误")
}
if !(command.OrderStatus == domain.OrderStatusDeliverSome ||
command.OrderStatus == domain.OrderStatusDeliverAll ||
command.OrderStatus == domain.OrderStatusReserve) {
return lib.ThrowError(lib.ARG_ERROR, "订单状态设置错误")
}
return nil
}
package command
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
type UpdateOrderRealCommand struct {
//id
Id int64 `json:"id"`
//订单编号
OrderCode string `json:"orderCode"`
//订单名称
OrderName string `json:"oderName"`
//数量
OrderActualCount int `json:"orderActualCount"`
//订单金额
OrderActualAmount float64 `json:"orderActualAmount"`
//买家
BuyerPhone string `json:"buyerPhone"`
//地址
BuyerAddress string `json:"address"`
//订单区域
OrderRegion string `json:"orderRegion"`
//合伙人分红百分比
PartnerBonusPercent float64 `json:"partnerBonusPercent"`
//业务员分红百分比
SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
//状态
OrderStatus int `json:"orderStatus"`
Reason string `json:"reason"`
}
func (command UpdateOrderRealCommand) ValidateCommand() error {
if command.Id == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单id错误")
}
if len(command.BuyerPhone) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "买家信息必填")
}
if len(command.BuyerAddress) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "买家地址必填")
}
if len(command.OrderCode) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单编号必填")
}
if len(command.OrderRegion) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
}
if !(command.OrderStatus == domain.OrderStatusDeliverSome ||
command.OrderStatus == domain.OrderStatusDeliverAll) {
return lib.ThrowError(lib.ARG_ERROR, "订单状态设置错误")
}
return nil
}
package service
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/command"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/query"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
//OrderService 管理员相关服务
type OrderService struct {
}
func NewOrderService(option map[string]interface{}) *OrderService {
newAdminUserService := new(OrderService)
return newAdminUserService
}
func (service OrderService) PageListOrder(listOrderQuery query.ListOrderQuery) ([]domain.Order, int, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
var (
orderRepository domain.OrderRepository
orders []domain.Order
cnt int
)
if value, err := factory.CreateOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderRepository = value
}
query := domain.OrderFindQuery{
PartnerId: listOrderQuery.PartnerId,
OrderCode: listOrderQuery.OrderCode,
Offset: listOrderQuery.Offset,
Limit: listOrderQuery.Limit,
OrderType: listOrderQuery.OrderType,
}
orders, err = orderRepository.Find(query)
if err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
cnt, err = orderRepository.CountAll(query)
if err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range orders {
var partnerData *domain.PartnerInfo
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: orders[i].PartnerInfo.Id})
if err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
orders[i].PartnerInfo = partnerData.Partner
}
return orders, cnt, nil
}
func (service OrderService) GetOrder(getOrderQuery query.GetOrderQuery) (*domain.Order, error) {
//实际业务
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
var (
orderRepository domain.OrderRepository
order *domain.Order
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if value, err := factory.CreateOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderRepository = value
}
order, err = orderRepository.FindOne(domain.OrderFindOneQuery{
OrderId: getOrderQuery.OrderId,
})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var partnerData *domain.PartnerInfo
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: order.PartnerInfo.Id})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
order.PartnerInfo = partnerData.Partner
err = transactionContext.CommitTransaction()
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return order, nil
}
//CreateOrder 创建意向单
func (service OrderService) CreateOrder(command command.CreateOrderCommand) error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = command.ValidateCommand(); err != nil {
return lib.ThrowError(lib.ARG_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
orderDao, _ := factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
ok, err := orderDao.OrderCodeIsExist(command.OrderCode, 0)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if ok {
return lib.ThrowError(lib.BUSINESS_ERROR, "订单编号已存在")
}
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var partnerData *domain.PartnerInfo
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: command.PartnerId})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var orderRepository domain.OrderRepository
if orderRepository, err = factory.CreateOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
newOrder := domain.Order{
//订单类型
OrderType: command.OrderType,
//订单编号
OrderCode: command.OrderCode,
//订单名称
OrderName: command.OrderName,
//订单状态
OrderStatus: command.OrderStatus,
//数量
OrderCount: command.OrderCount,
//实际数量
OrderActualCount: command.OrderActualCount,
//订单金额
OrderAmount: command.OrderAmount,
//实际订单金额
OrderActualAmount: command.OrderActualAmount,
//订单已支付分红金额(货款)
OrderPaymentAmount: 0,
//订单区域信息
OrderRegionInfo: domain.RegionInfo{
RegionName: command.OrderRegion,
},
//买家
Buyer: domain.Buyer{
BuyerName: command.BuyerName,
ShippingAddress: command.BuyerAddress,
ContactInfo: command.BuyerPhone,
},
PartnerInfo: partnerData.Partner,
//合伙人分红百分比
PartnerBonusPercent: command.PartnerBonusPercent,
//业务员分红百分比
SalesmanBonusPercent: command.SalesmanBonusPercent,
}
err = orderRepository.Save(newOrder)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
//UpdateOrderPurpose 更新意向单
func (service OrderService) UpdateOrderPurpose(command command.UpdateOrderCommand) error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = command.ValidateCommand(); err != nil {
return lib.ThrowError(lib.ARG_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
orderDao, _ := factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
ok, err := orderDao.OrderCodeIsExist(command.OrderCode, command.Id)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if ok {
return lib.ThrowError(lib.BUSINESS_ERROR, "订单编号已存在")
}
var (
orderRepository domain.OrderRepository
orderData *domain.Order
)
if orderRepository, err = factory.CreateOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
orderData, err = orderRepository.FindOne(domain.OrderFindOneQuery{
OrderId: command.Id,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderData.OrderType != domain.OrderIntention {
return lib.ThrowError(lib.BUSINESS_ERROR, "订单不是意向单")
}
updateMap := map[string]interface{}{
//订单编号
"orderCode": command.OrderCode,
"oderName": command.OrderName,
"orderCount": command.OrderCount,
"orderAmount": command.OrderAmount,
"orderActualCount": command.OrderCount,
"orderActualAmount": command.OrderAmount,
"buyer": domain.Buyer{
BuyerName: orderData.Buyer.BuyerName,
ContactInfo: command.BuyerPhone,
ShippingAddress: command.BuyerAddress,
},
"orderRegion": domain.RegionInfo{
RegionName: command.OrderRegion,
},
"partnerBonusPercent": command.PartnerBonusPercent,
"salesmanBonusPercent": command.SalesmanBonusPercent,
"orderStatus": command.OrderStatus,
"orderType": command.OrderType,
}
err = orderData.Update(updateMap)
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
err = orderRepository.Save(*orderData)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
//RemoveOrder 删除意向单
func (service OrderService) RemoveOrder(id int64) error {
//实际业务
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var (
orderRepository domain.OrderRepository
order *domain.Order
)
if value, err := factory.CreateOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderRepository = value
}
order, err = orderRepository.FindOne(domain.OrderFindOneQuery{
OrderId: id,
})
if err != nil {
return lib.ThrowError(lib.RES_NO_FIND_ERROR, err.Error())
}
if order.OrderType != domain.OrderIntention {
return lib.ThrowError(lib.BUSINESS_ERROR, "订单不是意向单")
}
err = orderRepository.Remove(order.Id)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
//UpdateOrderReal 更新为实发单
func (service OrderService) UpdateOrderReal(command command.UpdateOrderRealCommand) error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = command.ValidateCommand(); err != nil {
return lib.ThrowError(lib.ARG_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
orderDao, _ := factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
ok, err := orderDao.OrderCodeIsExist(command.OrderCode, command.Id)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if ok {
return lib.ThrowError(lib.BUSINESS_ERROR, "订单编号已存在")
}
var (
orderRepository domain.OrderRepository
orderData *domain.Order
)
if orderRepository, err = factory.CreateOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
orderData, err = orderRepository.FindOne(domain.OrderFindOneQuery{
OrderId: command.Id,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = orderData.Update(map[string]interface{}{
//订单编号
"orderCode": command.OrderCode,
"oderName": command.OrderName,
"orderActualCount": command.OrderActualCount,
"orderActualAmount": command.OrderActualAmount,
"buyer": domain.Buyer{
BuyerName: orderData.Buyer.BuyerName,
ContactInfo: command.BuyerPhone,
ShippingAddress: command.BuyerAddress,
},
"orderRegion": domain.RegionInfo{
RegionName: command.OrderRegion,
},
"partnerBonusPercent": command.PartnerBonusPercent,
"salesmanBonusPercent": command.SalesmanBonusPercent,
"orderStatus": command.OrderStatus,
"orderType": domain.OrderReal,
"reason": command.Reason,
})
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
err = orderRepository.Save(*orderData)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
package command
type CreateOrderPaymentCommand struct {
//订单编号
OrderId int64 `json:"orderId"`
DivdendPaymentItem []DivdendPyamentItem `json:"dividendPayment"`
TotalPaymentAmount float64 `json:"payment_amount"`
}
type DivdendPyamentItem struct {
// 货款
PaymentForGoods float64 `json:"paymentForGoods,omitempty"`
// 支付状态
StateOfPayment int `json:"stateOfPayment,omitempty"`
//支付批次
PaymentSn int `json:"paymentSn,omitempty"`
//支付编号
PaymentId int `json:"id,omitempty"`
}
func (command CreateOrderPaymentCommand) ValidateCommand() error {
return nil
}
package query
type ListDividendOrdersQuery struct {
// 合伙人类别
PartnerId int `json:"partner"`
SearchText string `json:"searchText"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
}
func (q *ListDividendOrdersQuery) ValidateQuery() error {
return nil
}
package query
type GetOrderPaymentQuery struct {
// 合伙人类别
OrderId int64 `json:"orderId"`
}
func (q *GetOrderPaymentQuery) ValidateQuery() error {
return nil
}
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils"
"time"
//"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
// 客户价值服务
type OrderPaymentService struct {
}
func NewOrderPaymentService(options map[string]interface{}) *OrderPaymentService {
newOrderPaymentService := &OrderPaymentService{}
return newOrderPaymentService
}
// 创建订单支付数据
func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *command.CreateOrderPaymentCommand) (data interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
OrderPaymentDao, _ = factory.CreateOrderPaymentDao(map[string]interface{}{"transactionContext": transactionContext})
)
if err = command.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
if err == nil {
err = transactionContext.CommitTransaction()
}
if err != nil {
transactionContext.RollbackTransaction()
}
}()
//检查订单是否存在
var OrderPaymentRepository domain.OrderPaymentRepository
if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
orderBase, e := OrderDao.GetOrderBaseInfo(command.OrderId)
if e != nil {
err = e
return
}
var excludeIdList []int
var bonusStatus int = domain.BonusPaid //分红状态
excludeIdList = append(excludeIdList, 0)
for i := range command.DivdendPaymentItem {
paymentItem := command.DivdendPaymentItem[i]
dm := &domain.OrderPayment{
OrderId: command.OrderId,
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
if bonusStatus == domain.BonusPaid && paymentItem.StateOfPayment == domain.BonusWaitPay {
bonusStatus = domain.BonusWaitPay
}
if paymentItem.PaymentId > 0 {
//检查货款 已存在 / 未存在
if findDm, e := OrderPaymentRepository.FindOne(domain.OrderPaymentFindOneQuery{OrderId: command.OrderId, PaymentId: paymentItem.PaymentId}); e == nil {
//状态更金额一样的时候 不做更新
if findDm.BonusStatus == paymentItem.StateOfPayment && findDm.PaymentAmount == paymentItem.PaymentForGoods {
excludeIdList = append(excludeIdList, paymentItem.PaymentId)
continue
}
dm = findDm
}
}
dm.PartnerId = orderBase["PartnerId"].(int64)
bonusPercent := orderBase["PartnerBonusPercent"].(float64)
dm.BonusAmount = utils.Decimal(paymentItem.PaymentForGoods * (bonusPercent / 100.0))
dm.PaymentAmount = paymentItem.PaymentForGoods
dm.BonusStatus = paymentItem.StateOfPayment
dm.UpdateAt = time.Now()
if data, err = OrderPaymentRepository.Save(dm); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
excludeIdList = append(excludeIdList, int(dm.Id))
}
if err = OrderPaymentDao.Remove(command.OrderId, domain.BonusWaitPay, excludeIdList); err != nil {
return
}
if err = OrderDao.Update(map[string]interface{}{"id": command.OrderId, "orderPaymentAmount": command.TotalPaymentAmount, "bonusStatus": bonusStatus}); err != nil {
return
}
return
}
// 返回订单支付列表
func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymentQuery *query.GetOrderPaymentQuery) ([]*domain.OrderPayment, error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
OrderPayments []*domain.OrderPayment
err error
)
if err = listOrderPaymentQuery.ValidateQuery(); err != nil {
return nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var OrderPaymentRepository domain.OrderPaymentRepository
if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
queryOption := domain.OrderPaymentQuery{
OrderId: listOrderPaymentQuery.OrderId,
}
_, e := OrderDao.GetOrderBaseInfo(listOrderPaymentQuery.OrderId)
if e != nil {
return nil, e
}
if OrderPayments, err = OrderPaymentRepository.Find(queryOption); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if err = transactionContext.CommitTransaction(); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
return OrderPayments, nil
}
// 返回分红管理列表
func (OrderPaymentService *OrderPaymentService) ListDividendOrders(listOrderPaymentQuery *query.ListDividendOrdersQuery) (int, interface{}, error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
//OrderPayments []*domain.OrderPayment
count int
err error
OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
orders []*models.Order
)
if err = listOrderPaymentQuery.ValidateQuery(); err != nil {
return 0, nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if count, orders, err = OrderDao.GetDividendOrders(map[string]interface{}{
"orderCode": listOrderPaymentQuery.SearchText,
"partnerId": listOrderPaymentQuery.PartnerId,
"orderType": 1,
"offset": (listOrderPaymentQuery.PageNumber - 1) * listOrderPaymentQuery.PageSize,
"limit": listOrderPaymentQuery.PageSize,
}); err != nil {
return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
type DividendOrderItem struct {
OrderId string `json:"id"` //订单编号
OrderNumber string `json:"orderNumber"` //订单号
OrderState int `json:"orderState"` //订单状态
StateOfPayment int `json:"stateOfPayment"` //支付状态
CreateTime string `json:"createTime"` //订单创建时间
PartnerName string `json:"partnerName"` //合伙人姓名
DividendProportion float64 `json:"dividendProportion"` //分红比例
DividendsReceivable float64 `json:"dividendsReceivable"` //应收分红
DividendSpending float64 `json:"dividendSpending"` //分红支出
ReceiveDividends float64 `json:"receiveDividends"` //实收分红
CommissionProportion float64 `json:"commissionProportion"` //业务员抽成比例
}
var list = make([]DividendOrderItem, 0)
for i := range orders {
order := orders[i]
item := DividendOrderItem{
OrderId: fmt.Sprintf("%v", order.Id),
OrderNumber: order.OrderCode,
OrderState: order.OrderStatus,
StateOfPayment: order.BonusStatus,
CreateTime: order.CreateAt.Local().Format("2006-01-02 15:04:05"),
PartnerName: order.PartnerInfo.PartnerName,
DividendProportion: order.PartnerBonusPercent,
DividendsReceivable: utils.Decimal(order.OrderAmount * (order.PartnerBonusPercent / 100.0)),
DividendSpending: 0,
ReceiveDividends: utils.Decimal(order.OrderActualAmount * (order.PartnerBonusPercent / 100.0)),
CommissionProportion: order.SalesmanBonusPercent,
}
if order.OrderActualAmount < order.OrderAmount {
item.DividendSpending = utils.Decimal((order.OrderAmount - order.OrderActualAmount) * (order.PartnerBonusPercent / 100.0))
}
list = append(list, item)
}
if err = transactionContext.CommitTransaction(); err != nil {
return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
return count, list, nil
}
package command
type CreateOrderCommand struct {
//订单类型
OrderType int `json:"orderType"`
//订单编号
OrderCode string `json:"orderCode"`
//交货编号
DeliveryCode string `json:"deliveryCode"`
//买家
BuyerName string `json:"buyerName"`
//订单区域信息
OrderRegion string `json:"orderRegion"`
//订单对应的合伙人
PartnerId int64 `json:"partnerId"`
//业务员抽成比例
SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
//货品
Goods []OrderGoodData `json:"goods"`
}
... ...
package command
//DisableOrderCommand 开启关闭订单
type DisableOrderCommand struct {
OrderId int64 `json:"orderId"`
IsDisable int `json:"isDisable"`
OrderType int `json:"orderType"`
}
... ...
package command
type OrderGoodData struct {
//货品id
Id int64 `json:"id"`
//货品名称 长度可能较长
GoodName string `json:"goodName"`
//预计的货品数量
PlanGoodNumber int `json:"planGoodNumber"`
//货品单价
Price float64 `json:"price"`
//合伙人分红比例
PartnerBonusPercent float64 `json:"partnerBonusPercent"`
//备注信息
Remark string `json:"remark"`
}
... ...
package command
import "time"
type OrderDeliveryCommand struct {
OrderId int64 `json:"orderId"`
DeliveryTime time.Time `json:"deliveryTime"`
DeliveryCode string `json:"deliveryCode"`
Goods []OrderGoodData `json:"goods"`
}
... ...
package command
//更新订单的商品数字并更新分红的数据
type UpdateGoodBouns struct {
Id int64 `json:"id"` //订单id
GoodBouns []GoodBouns `json:"goodBouns"`
}
//GoodBoun 商品数量调整
type GoodBouns struct {
GoodId int64 `json:"goodId"` //货品id
UseGoodNumber int `json:"useGoodNumber"` //货品数量调整的数值
Remark string `json:"remark"` //原因
BounsStatus int `json:"BounsStatus"`
}
... ...
package command
//UpdateOrderPurposeCommand 更新意向单
type UpdateOrderCommand struct {
Id int64 `json:"id"`
//订单编号
OrderCode string `json:"orderCode"`
//交货编号
DeliveryCode string `json:"deliveryCode"`
//买家
BuyerName string `json:"buyerName"`
//订单区域信息
OrderRegion string `json:"orderRegion"`
//订单对应的合伙人
PartnerId int64 `json:"partnerId"`
//业务员抽成比例
SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
//订单类型
OrderType int `json:"orderType"`
//货品
Goods []OrderGoodData `json:"goods"`
}
... ...
package query
//ListOrderQuery 获取用户列表
//GetOrderQuery 获取订单详情
type GetOrderQuery struct {
OrderId int64 `json:"orderId"`
}
... ...
package query
//ListOrderQuery 获取用户列表
type ListOrderQuery struct {
type ListOrderBaseQuery struct {
//合伙人id
PartnerId int64 `json:"partnerId" `
//订单编号
... ... @@ -12,4 +12,6 @@ type ListOrderQuery struct {
Limit int `json:"limit"`
//订单类型
OrderType int `json:"orderType"`
//发货单号
DeliveryCode string `json:"deliveryCode"`
}
... ...
package service
import (
"fmt"
"time"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/command"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/query"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
//OrderService 管理员相关服务
type OrderInfoService struct {
}
func NewOrderInfoService(option map[string]interface{}) *OrderInfoService {
newAdminUserService := new(OrderInfoService)
return newAdminUserService
}
// PageListOrderBase 获取订单列表
func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrderBaseQuery) ([]domain.OrderBase, int, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
var (
orderRepository domain.OrderBaseRepository
orders []domain.OrderBase
cnt int
)
if value, err := factory.CreateOrderBaseRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderRepository = value
}
query := domain.OrderBaseFindQuery{
PartnerId: listOrderQuery.PartnerId,
OrderCode: listOrderQuery.OrderCode,
Offset: listOrderQuery.Offset,
Limit: listOrderQuery.Limit,
OrderType: listOrderQuery.OrderType,
DeliveryCode: listOrderQuery.DeliveryCode,
}
orders, cnt, err = orderRepository.Find(query)
if err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range orders {
var partnerData *domain.PartnerInfo
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
UserId: orders[i].PartnerId,
})
if err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
orders[i].PartnerInfo = partnerData.Partner
}
return orders, cnt, nil
}
//GetOrderDetail 获取订单详情
func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery) (*domain.OrderBase, error) {
//实际业务
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
var (
orderBaseRepository domain.OrderBaseRepository
PartnerInfoRepository domain.PartnerInfoRepository
orderGoodRepository domain.OrderGoodRepository
order *domain.OrderBase
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if value, err := factory.CreateOrderBaseRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderBaseRepository = value
}
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
order, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
OrderId: getOrderQuery.OrderId,
})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取订单数据失败:%s", err))
}
var (
partnerData *domain.PartnerInfo
goods []domain.OrderGood
)
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: order.PartnerId})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("检索合伙人数据失败:%s", err))
}
order.PartnerInfo = partnerData.Partner
goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
OrderId: order.Id,
})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取订单中的商品列表失败:%s", err))
}
order.Goods = goods
err = transactionContext.CommitTransaction()
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return order, nil
}
func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (*domain.OrderBase, error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var partnerData *domain.PartnerInfo
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: cmd.PartnerId})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("检索合伙人数据失败"))
}
var (
orderBaseRepository domain.OrderBaseRepository
orderGoodRepository domain.OrderGoodRepository
orderBaseDao *dao.OrderBaseDao
)
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
//检查order_code是否重复
if ok, err := orderBaseDao.OrderCodeExist(cmd.OrderCode); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在")
}
//检查delivery_code是否重复
if len(cmd.DeliveryCode) > 0 {
if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
}
}
newOrder := &domain.OrderBase{
OrderType: cmd.OrderType, OrderCode: cmd.OrderCode,
DeliveryCode: cmd.DeliveryCode,
Buyer: &domain.Buyer{
BuyerName: cmd.BuyerName,
},
RegionInfo: &domain.RegionInfo{
RegionName: cmd.OrderRegion,
},
PartnerId: cmd.PartnerId,
PartnerInfo: partnerData.Partner,
SalesmanBonusPercent: cmd.SalesmanBonusPercent,
}
var orderGoods []domain.OrderGood
for _, good := range cmd.Goods {
m := domain.NewOrderGood()
m.OrderId = 0
m.GoodName = good.GoodName
m.PlanGoodNumber = good.PlanGoodNumber
m.Price = good.Price
m.PartnerBonusPercent = good.PartnerBonusPercent
m.Remark = good.Remark
err = m.Compute()
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
}
err = m.CurrentBonusStatus.WartPayPartnerBonus(&m)
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
}
orderGoods = append(orderGoods, m)
}
newOrder.Goods = orderGoods
err = newOrder.Compute()
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
}
err = orderBaseRepository.Save(newOrder)
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
}
for i := range newOrder.Goods {
newOrder.Goods[i].OrderId = newOrder.Id
}
err = orderGoodRepository.Save(orderGoods)
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
}
newOrder.Goods = orderGoods
err = transactionContext.CommitTransaction()
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return newOrder, nil
}
//DeleteOrder 删除订单
func (service OrderInfoService) DeleteOrder(orderId int64) 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()
}()
var (
orderBaseRepository domain.OrderBaseRepository
orderGoodRepository domain.OrderGoodRepository
)
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = orderBaseRepository.Remove(orderId)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单数据失败:%s", err))
}
err = orderGoodRepository.Remove(orderId)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单中商品数据失败:%s", err))
}
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
//UpdateOrderData 编辑订单
func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) (*domain.OrderBase, error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var partnerData *domain.PartnerInfo
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: cmd.PartnerId})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("检索合伙人数据失败"))
}
var (
orderBaseRepository domain.OrderBaseRepository
orderGoodRepository domain.OrderGoodRepository
oldOrderData *domain.OrderBase
oldOrderGoods []domain.OrderGood
newOrderGoods []domain.OrderGood
delGoods []int64
orderBaseDao *dao.OrderBaseDao
)
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
//获取旧的订单
oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
OrderId: cmd.Id,
})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
}
//判定要求的更新的订单类型
if oldOrderData.OrderType != cmd.OrderType {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, fmt.Sprintf("操作失败,待更新的订单的类型已变更"))
}
if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
//检查order_code是否重复
if ok, err := orderBaseDao.OrderCodeExist(cmd.OrderCode, cmd.Id); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在")
}
//检查delivery_code是否重复
if len(cmd.DeliveryCode) > 0 {
if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.Id); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
}
}
//获取旧的订单中的商品
oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
OrderId: cmd.Id,
})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
}
for _, good := range cmd.Goods {
m := domain.NewOrderGood()
m.OrderId = oldOrderData.Id
m.GoodName = good.GoodName
m.PlanGoodNumber = good.PlanGoodNumber
m.Price = good.Price
m.PartnerBonusPercent = good.PartnerBonusPercent
m.Remark = good.Remark
err = m.Compute()
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
}
err = m.CurrentBonusStatus.WartPayPartnerBonus(&m)
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
}
newOrderGoods = append(newOrderGoods, m)
}
oldOrderData.OrderCode = cmd.OrderCode
oldOrderData.DeliveryCode = cmd.DeliveryCode
oldOrderData.Buyer.BuyerName = cmd.BuyerName
oldOrderData.RegionInfo.RegionName = cmd.OrderRegion
oldOrderData.PartnerId = cmd.PartnerId
oldOrderData.PartnerInfo = partnerData.Partner
oldOrderData.SalesmanBonusPercent = cmd.SalesmanBonusPercent
oldOrderData.Goods = newOrderGoods
err = oldOrderData.Compute()
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
}
err = orderBaseRepository.Save(oldOrderData)
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
}
err = orderGoodRepository.Save(newOrderGoods)
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
}
oldOrderData.Goods = newOrderGoods
//删不需要的订单总不需要的商品
delGoods = service.deleteOldOrderGoods(newOrderGoods, oldOrderGoods)
err = orderGoodRepository.Remove(oldOrderData.Id, delGoods...)
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单中的商品数据失败:%s", err))
}
err = transactionContext.CommitTransaction()
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return oldOrderData, nil
}
//deleteOldOrderGoods 新旧商品列表对比
func (service OrderInfoService) deleteOldOrderGoods(newGoods []domain.OrderGood, oldGoods []domain.OrderGood) (goodIds []int64) {
for _, old := range oldGoods {
var hasIn bool
for _, new := range newGoods {
if old.Id == new.Id {
hasIn = true
break
}
}
if !hasIn {
goodIds = append(goodIds, old.Id)
}
}
return
}
//Delivery 发货
func (service OrderInfoService) Delivery(cmd command.OrderDeliveryCommand) 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()
}()
var (
orderBaseRepository domain.OrderBaseRepository
orderGoodRepository domain.OrderGoodRepository
oldOrderData *domain.OrderBase
oldOrderGoods []domain.OrderGood
orderBaseDao *dao.OrderBaseDao
)
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
//获取旧的订单
oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
OrderId: cmd.OrderId,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
}
if oldOrderData.OrderType != domain.OrderIntention {
return lib.ThrowError(lib.BUSINESS_ERROR, "订单类型已发生变更")
}
if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
//检查delivery_code是否重复
if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.OrderId); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
}
//获取旧的订单中的商品
oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
OrderId: cmd.OrderId,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
}
for _, newGood := range cmd.Goods {
for i := range oldOrderGoods {
if newGood.Id != oldOrderGoods[i].Id {
continue
}
oldOrderGoods[i].GoodName = newGood.GoodName
oldOrderGoods[i].PlanGoodNumber = newGood.PlanGoodNumber
oldOrderGoods[i].Price = newGood.Price
oldOrderGoods[i].PartnerBonusPercent = newGood.PartnerBonusPercent
oldOrderGoods[i].Remark = newGood.Remark
err = oldOrderGoods[i].Compute()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
}
err = oldOrderGoods[i].CurrentBonusStatus.WartPayPartnerBonus(&oldOrderGoods[i])
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
}
}
}
oldOrderData.DeliveryCode = cmd.DeliveryCode
oldOrderData.DeliveryTime = time.Now()
oldOrderData.Goods = oldOrderGoods
//变更订单类型
oldOrderData.OrderType = domain.OrderReal
err = oldOrderData.Compute()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
}
err = orderBaseRepository.Save(oldOrderData)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
}
err = orderGoodRepository.Save(oldOrderGoods)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
}
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
//DisableOrEnable 开启关闭订单
func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand) 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()
}()
var (
orderBaseRepository domain.OrderBaseRepository
oldOrderData *domain.OrderBase
)
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
//获取旧的订单
oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
OrderId: cmd.OrderId,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
}
if oldOrderData.OrderType != cmd.OrderType {
return lib.ThrowError(lib.BUSINESS_ERROR, fmt.Sprintf("操作失败,指定的订单的类型发生变更"))
}
oldOrderData.IsDisable = cmd.IsDisable
err = orderBaseRepository.Save(oldOrderData)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
}
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
//UpdateGoodBouns 更新货品的分红相关的数值
func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) 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()
}()
var (
orderBaseRepository domain.OrderBaseRepository
orderGoodRepository domain.OrderGoodRepository
oldOrderData *domain.OrderBase
oldOrderGoods []domain.OrderGood
)
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
//获取旧的订单
oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
OrderId: cmd.Id,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
}
if oldOrderData.OrderType != domain.OrderReal {
return lib.ThrowError(lib.BUSINESS_ERROR, fmt.Sprintf("指定的订单的订单类型发生变更"))
}
//获取旧的订单中的商品
oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
OrderId: cmd.Id,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
}
for _, newGood := range cmd.GoodBouns {
for i := range oldOrderGoods {
if newGood.GoodId != oldOrderGoods[i].Id {
continue
}
oldOrderGoods[i].UseGoodNumber = newGood.UseGoodNumber
oldOrderGoods[i].Remark = newGood.Remark
oldOrderGoods[i].BonusStatus = newGood.BounsStatus
err = oldOrderGoods[i].Compute()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
}
switch newGood.BounsStatus {
case domain.OrderGoodWaitPay:
err = oldOrderGoods[i].CurrentBonusStatus.WartPayPartnerBonus(&oldOrderGoods[i])
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
}
case domain.OrderGoodHasPay:
err = oldOrderGoods[i].CurrentBonusStatus.PayPartnerBonus(&oldOrderGoods[i])
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
}
default:
return lib.ThrowError(lib.ARG_ERROR, fmt.Sprintf("货品的支付状态错误"))
}
}
}
oldOrderData.Goods = oldOrderGoods
//变更订单类型
err = oldOrderData.Compute()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
}
err = orderBaseRepository.Save(oldOrderData)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
}
err = orderGoodRepository.Save(oldOrderGoods)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
}
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
... ...
package domain
import (
"time"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils"
)
const (
OrderStatusReserve int = iota + 1 //预定中
OrderStatusDeliverSome //部分发货
OrderStatusDeliverAll //全部发货
)
const (
OrderReal int = iota + 1 //实发订单
OrderIntention //意向订单
)
//买家
type Buyer struct {
//买家姓名
BuyerName string `json:"buyerName"`
//联系方式
ContactInfo string `json:"contactInfo"`
//收获地址
ShippingAddress string `json:"shippingAddress"`
}
type Order struct {
Id int64 `json:"id"`
//订单类型
OrderType int `json:"orderType"`
//订单编号
OrderCode string `json:"orderCode"`
//订单名称
OrderName string `json:"oderName"`
//订单状态
OrderStatus int `json:"orderStatus"`
//数量
OrderCount int `json:"orderCount"`
//实际数量
OrderActualCount int `json:"orderActualCount"`
//订单金额
OrderAmount float64 `json:"orderAmount"`
//实际订单金额
OrderActualAmount float64 `json:"orderActualAmount"`
//订单已支付分红金额(货款)
OrderPaymentAmount float64 `json:"orderPaymentAmount"`
//订单区域信息
OrderRegionInfo RegionInfo `json:"orderRegionInfo"`
//买家
Buyer Buyer `json:"buyer"`
//合伙人数据
PartnerInfo Partner `json:"partnerInfo"`
//合伙人分红百分比
PartnerBonusPercent float64 `json:"partnerBonusPercent"`
//业务员分红百分比
SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
//最后查看得时间
LastViewTime time.Time `json:"lastViewTime"`
//更新时间
UpdateAt time.Time `json:"updateAt"`
CreateAt time.Time `json:"createAt"`
//理由
Reason string
}
//TODO
func (order *Order) Update(data map[string]interface{}) error {
if v, ok := data["orderType"]; ok {
order.OrderType = v.(int)
}
if v, ok := data["orderCode"]; ok {
order.OrderCode = v.(string)
}
if v, ok := data["oderName"]; ok {
order.OrderName = v.(string)
}
if v, ok := data["orderStatus"]; ok {
order.OrderStatus = v.(int)
}
if v, ok := data["orderCount"]; ok {
order.OrderCount = v.(int)
}
if v, ok := data["orderActualCount"]; ok {
order.OrderActualCount = v.(int)
}
if v, ok := data["orderAmount"]; ok {
order.OrderAmount = v.(float64)
}
if v, ok := data["orderActualAmount"]; ok {
order.OrderActualAmount = v.(float64)
}
if v, ok := data["orderPaymentAmount"]; ok {
order.OrderPaymentAmount = v.(float64)
}
if v, ok := data["orderRegion"]; ok {
order.OrderRegionInfo = v.(RegionInfo)
}
if v, ok := data["buyer"]; ok {
order.Buyer = v.(Buyer)
}
if v, ok := data["partnerInfo"]; ok {
order.PartnerInfo = v.(Partner)
}
if v, ok := data["partnerBonusPercent"]; ok {
order.PartnerBonusPercent = v.(float64)
}
if v, ok := data["salesmanBonusPercent"]; ok {
order.SalesmanBonusPercent = v.(float64)
}
if v, ok := data["reason"]; ok {
order.Reason = v.(string)
}
return nil
}
//订单累计分红
func (m *Order) OrderTotalBonus() float64 {
return utils.Decimal(m.OrderActualAmount * (m.PartnerBonusPercent / 100.0))
}
//订单已收分红
func (m *Order) OrderBonusReceive() float64 {
return utils.Decimal(m.OrderPaymentAmount * (m.PartnerBonusPercent / 100.0))
}
//订单未收分红
func (m *Order) OrderBonusWait() float64 {
bonusWait := m.OrderTotalBonus() - m.OrderBonusReceive()
if bonusWait < 0 {
return 0
}
return bonusWait
}
//分红支出
func (m *Order) OrderBonusOutstanding() float64 {
if m.OrderAmount <= m.OrderActualAmount {
return 0
}
return utils.Decimal((m.OrderAmount - m.OrderActualAmount) * (m.PartnerBonusPercent / 100.0))
}
//订单被取消金额
func (m *Order) OrderAmountCancel() float64 {
if m.OrderAmount <= m.OrderActualAmount {
return 0
}
return utils.Decimal((m.OrderAmount - m.OrderActualAmount))
}
type OrderFindOneQuery struct {
OrderId int64
}
type OrderFindQuery struct {
PartnerId int64
OrderCode string
Offset int
Limit int
OrderType int
}
type OrderRepository interface {
Save(order Order) error
FindOne(qureyOptions OrderFindOneQuery) (*Order, error)
Find(queryOptions OrderFindQuery) ([]Order, error)
CountAll(queryOption OrderFindQuery) (int, error)
Remove(id int64) error
}
package domain
import (
"time"
"github.com/shopspring/decimal"
)
const (
OrderReal = iota + 1 //实发订单
OrderIntention //意向订单
)
const (
OrderDisableNot = iota //订单未关闭
OrderDisableYes //订单已关闭
)
//Buyer 买家
type Buyer struct {
//买家姓名
BuyerName string `json:"buyerName"`
//联系方式
ContactInfo string `json:"contactInfo"`
//收获地址
ShippingAddress string `json:"shippingAddress"`
}
//OrderBase 订单基础
type OrderBase struct {
//表id
Id int64 `json:"id"`
//订单类型
OrderType int `json:"orderType"`
//订单编号
OrderCode string `json:"orderCode"`
//交货编号
DeliveryCode string `json:"deliveryCode"`
//买家
Buyer *Buyer `json:"buyer"`
//订单区域信息
RegionInfo *RegionInfo `json:"regionInfo"`
//订单对应的合伙人
PartnerId int64 `json:"partnerId"`
PartnerInfo Partner `json:"partnerInfo"`
//业务员抽成比例
SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
//订单的创建时间
CreateTime time.Time `json:"createTime"`
//发货时间
DeliveryTime time.Time `json:"deliveryTime"`
//更新时间
UpdateTime time.Time `json:"updateTime"`
//货品
Goods []OrderGood `json:"goods"`
//核算订单相关数据
OrderCompute OrderCompute `json:"orderCompute"`
//是否关闭订单
IsDisable int `json:"isDisable"`
//分红支付状态
BonusStatus int `json:"bonusStatus"`
}
type OrderCompute struct {
//合伙人应收分红
PlanPartnerBonus float64 `json:"planPartnerBonus"`
//调整后的合伙人应收分红 (初始值=-1);
//业务判定时0是有效值,
//所以用空串表示无值,转换到数据库中为负值
UsePartnerBonus float64 `json:"usePartnerBonus"`
//合伙人已收分红
PartnerBonusHas float64 `json:"partnerBonusHas"`
//合伙人未收分红
PartnerBonusNot float64 `json:"partnerBonusNot"`
//合伙人分红支出
PartnerBonusExpense float64 `json:"partnerBonusExpense"`
//业务员抽成
SalesmanBonus float64 `json:"salesmanBonus"`
//预计的订单内货品总数
PlanOrderCount int `json:"planOrderCount"`
//预计的订单的总金额
PlanOrderAmount float64 `json:"planOrderAmount"`
//按需使用的订单内货品总数 (初始值=-1)
//业务判定时0是有效值,
//所以用空串表示无值,转换到数据库中为负值
UseOrderCount int `json:"useOrderCount"`
//按需使用的订单内货总金额 (初始值=-1)
//业务判定时0是有效值,
//所以用空串表示无值,转换到数据库中为负值
UseOrderAmount float64 `json:"useOrderAmount"`
}
//Compute 数据汇总核算
func (order *OrderBase) Compute() error {
planPartnerBonus := decimal.NewFromFloat(0)
planOrderAmount := decimal.NewFromFloat(0)
var (
planOrderCount int = 0
useOrderCount int = 0
HasUseOrderCount bool = false
)
usePartnerBonus := decimal.NewFromFloat(0)
var hasUsePartnerBonus bool = false
useOrderAmount := decimal.NewFromFloat(0)
var hasUseOrderAmount bool = false
partnerBonusHas := decimal.NewFromFloat(0)
partnerBonusNot := decimal.NewFromFloat(0)
partnerBonusExpense := decimal.NewFromFloat(0)
//初始订单的支付状态
order.BonusStatus = OrderGoodWaitPay
//统计所以货品的值
for i := range order.Goods {
if order.Goods[i].BonusStatus == OrderGoodHasPay {
//确定订单的支付状态
order.BonusStatus = OrderGoodHasPay
}
planPartnerBonus = planPartnerBonus.Add(decimal.NewFromFloat(order.Goods[i].GoodCompute.PlanPartnerBonus))
planOrderAmount = planOrderAmount.Add(decimal.NewFromFloat(order.Goods[i].GoodCompute.PlanAmount))
planOrderCount += order.Goods[i].PlanGoodNumber
goodUseAmount := decimal.NewFromFloat(order.Goods[i].GoodCompute.UseAmount)
if goodUseAmount.GreaterThanOrEqual(decimal.NewFromFloat(0)) {
//调整值非负值得情况
hasUseOrderAmount = true
useOrderAmount = useOrderAmount.Add(goodUseAmount)
} else {
useOrderAmount = useOrderAmount.Add(decimal.NewFromFloat(order.Goods[i].GoodCompute.PlanAmount))
}
goodUsePartnerBonus := decimal.NewFromFloat(order.Goods[i].GoodCompute.UsePartnerBonus)
if goodUsePartnerBonus.GreaterThanOrEqual(decimal.NewFromFloat(0)) {
hasUsePartnerBonus = true
usePartnerBonus = usePartnerBonus.Add(goodUsePartnerBonus)
} else {
usePartnerBonus = usePartnerBonus.Add(decimal.NewFromFloat(order.Goods[i].GoodCompute.PlanPartnerBonus))
}
if order.Goods[i].UseGoodNumber >= 0 {
HasUseOrderCount = true
useOrderCount += order.Goods[i].UseGoodNumber
} else {
useOrderCount += order.Goods[i].PlanGoodNumber
}
partnerBonusHas = partnerBonusHas.Add(decimal.NewFromFloat(order.Goods[i].GoodCompute.PartnerBonusHas))
partnerBonusNot = partnerBonusNot.Add(decimal.NewFromFloat(order.Goods[i].GoodCompute.PartnerBonusNot))
partnerBonusExpense = partnerBonusExpense.Add(decimal.NewFromFloat(order.Goods[i].GoodCompute.PartnerBonusExpense))
}
//汇总赋值
order.OrderCompute.PartnerBonusExpense, _ = partnerBonusExpense.Round(2).BigFloat().Float64()
order.OrderCompute.PartnerBonusHas, _ = partnerBonusHas.Round(2).BigFloat().Float64()
order.OrderCompute.PartnerBonusNot, _ = partnerBonusNot.Round(2).BigFloat().Float64()
order.OrderCompute.PlanPartnerBonus, _ = planPartnerBonus.Round(2).BigFloat().Float64()
order.OrderCompute.PlanOrderAmount, _ = planOrderAmount.Round(2).BigFloat().Float64()
order.OrderCompute.PlanOrderCount = planOrderCount
if hasUsePartnerBonus {
order.OrderCompute.UsePartnerBonus, _ = usePartnerBonus.Round(2).BigFloat().Float64()
} else {
order.OrderCompute.UsePartnerBonus = -1
}
if hasUseOrderAmount {
order.OrderCompute.UseOrderAmount, _ = useOrderAmount.Round(2).BigFloat().Float64()
//计算业务员的抽成
order.OrderCompute.SalesmanBonus, _ = useOrderAmount.
Mul(decimal.NewFromFloat(order.SalesmanBonusPercent)).
Div(decimal.NewFromInt(100)).
Round(2).BigFloat().Float64()
} else {
order.OrderCompute.UseOrderAmount = -1
order.OrderCompute.SalesmanBonus, _ = planOrderAmount.
Mul(decimal.NewFromFloat(order.SalesmanBonusPercent)).
Div(decimal.NewFromInt(100)).
Round(2).BigFloat().Float64()
}
if HasUseOrderCount {
order.OrderCompute.UseOrderCount = useOrderCount
} else {
order.OrderCompute.UseOrderCount = -1
}
return nil
}
type OrderBaseFindOneQuery struct {
OrderId int64
}
type OrderBaseFindQuery struct {
PartnerId int64
OrderCode string
DeliveryCode string
Offset int
Limit int
OrderType int
}
type OrderBaseRepository interface {
Save(order *OrderBase) error
FindOne(qureyOptions OrderBaseFindOneQuery) (*OrderBase, error)
Find(queryOptions OrderBaseFindQuery) ([]OrderBase, int, error)
Remove(id int64) error
}
... ...
package domain
import (
"errors"
"github.com/shopspring/decimal"
)
//分红状态
type OrderGoodBonusStatus interface {
//状态变更为待支付
WartPayPartnerBonus(orderGood *OrderGood) error
//状态变更为已支付
PayPartnerBonus(orderGood *OrderGood) error
}
//货单的支付状态
const (
//待支付
OrderGoodWaitPay int = 1
//已支付
OrderGoodHasPay int = 2
)
//OrderGood 订单中的货品
type OrderGood struct {
//货品id
Id int64 `json:"id"`
//所属订单id
OrderId int64 `json:"orderId"`
//货品名称 长度可能较长
GoodName string `json:"goodName"`
//预计的货品数量
PlanGoodNumber int `json:"planGoodNumber"`
//调整后的货品数量
//业务判定时0是有效值,
//所以用空串表示无值,转换到数据库中为负值
UseGoodNumber int `json:"useGoodNumber"`
//货品单价
Price float64 `json:"price"`
//合伙人分红比例
PartnerBonusPercent float64 `json:"partnerBonusPercent"`
//分红支付状态
BonusStatus int `json:"bonusStatus"`
//备注信息
Remark string `json:"remark"`
//当前分红支付状态
CurrentBonusStatus OrderGoodBonusStatus `json:"-"`
///核算订单相关数据
GoodCompute GoodCompute `json:"goodCompute"`
}
type GoodCompute struct {
//预计的货品总额
PlanAmount float64 `json:"planAmount"`
//调整后的货品总额 (初始值=-1)
//业务判定时0是有效值,
//所以用空串表示无值,转换到数据库中为负值
UseAmount float64 `json:"useAmount"`
//预计的合伙人分红
PlanPartnerBonus float64 `json:"planPartnerBonus"`
//合伙人应收分红调整 (初始值=-1),
//业务判定时0是有效值,
//所以用空串表示无值,转换到数据库中为负值
UsePartnerBonus float64 `json:"usePartnerBonus"`
//合伙人已收分红
PartnerBonusHas float64 `json:"partnerBonusHas"`
//合伙人未收分红
PartnerBonusNot float64 `json:"partnerBonusNot"`
//合伙人分红支出
PartnerBonusExpense float64 `json:"partnerBonusExpense"`
}
//OrderGoodBonusWaitPay 货品分红待支付
type OrderGoodBonusWaitPay struct{}
var _ OrderGoodBonusStatus = (*OrderGoodBonusWaitPay)(nil)
//OrderGoodBonusHasPay 货品分红已支付
type OrderGoodBonusHasPay struct{}
var _ OrderGoodBonusStatus = (*OrderGoodBonusHasPay)(nil)
func (waitPay OrderGoodBonusWaitPay) WartPayPartnerBonus(good *OrderGood) error {
good.GoodCompute.PartnerBonusExpense = 0
good.GoodCompute.PartnerBonusHas = 0
//初始状态为待支付时 ,合伙人未收分红等于合伙人应收分红(或者调整的)
if good.UseGoodNumber < 0 {
//数量没有调整,未收等于预计应收分红
good.GoodCompute.PartnerBonusNot = good.GoodCompute.PlanPartnerBonus
} else {
//数量有调整,未收等于调整后的应收分红
good.GoodCompute.PartnerBonusNot = good.GoodCompute.UsePartnerBonus
}
good.CurrentBonusStatus = OrderGoodBonusWaitPay{}
return nil
}
func (waitPay OrderGoodBonusWaitPay) PayPartnerBonus(good *OrderGood) error {
//待支付状态转支付时
//合伙人已收收分红等于合伙人应收分红(或者调整的)
//计算已支付
if good.UseGoodNumber < 0 {
//数量没有调整,已收等于预计应收分红
good.GoodCompute.PartnerBonusHas = good.GoodCompute.PlanPartnerBonus
} else {
//数量有调整,已收等于调整后的应收分红
good.GoodCompute.PartnerBonusHas = good.GoodCompute.UsePartnerBonus
}
good.GoodCompute.PartnerBonusExpense = 0
good.GoodCompute.PartnerBonusNot = 0
good.CurrentBonusStatus = OrderGoodBonusHasPay{}
return nil
}
func (hasPay OrderGoodBonusHasPay) PayPartnerBonus(good *OrderGood) error {
//已支付的值保持不变
//未支付的值保持不变
//计算分红支出
//分红支出=应收分红(有出现调整,则取调整后的应收分红)和已收分红的差额
if good.UseGoodNumber >= 0 {
//有数量调整,分红支出等于 已支付分红-调整后的已收分红
good.GoodCompute.PartnerBonusExpense = good.GoodCompute.PartnerBonusHas - good.GoodCompute.UsePartnerBonus
}
good.CurrentBonusStatus = OrderGoodBonusHasPay{}
return nil
}
func (hasPay OrderGoodBonusHasPay) WartPayPartnerBonus(good *OrderGood) error {
return errors.New("已支付的货单不能将状态回退为待支付")
}
//NewOrderGood 初始值设定
func NewOrderGood() OrderGood {
return OrderGood{
UseGoodNumber: -1,
BonusStatus: OrderGoodWaitPay,
GoodCompute: GoodCompute{
UsePartnerBonus: -1,
UseAmount: -1,
},
CurrentBonusStatus: OrderGoodBonusWaitPay{},
}
}
//Compute 数据汇总核算
func (good *OrderGood) Compute() error {
//计算预计货品总值
//计算预计合伙人分红
price := decimal.NewFromFloat(good.Price)
planamount := price.Mul(decimal.NewFromInt(int64(good.PlanGoodNumber))) //price*planGoodNumber
//price*useGoodNumber
planPartnerBonus := planamount.Mul(decimal.NewFromFloat(good.PartnerBonusPercent)).Div(decimal.NewFromInt(100)) //price*planGoodNumber*PartnerBonusPercent
good.GoodCompute.PlanAmount, _ = planamount.Round(2).BigFloat().Float64()
good.GoodCompute.PlanPartnerBonus, _ = planPartnerBonus.Round(2).BigFloat().Float64()
if good.UseGoodNumber < 0 {
//没有出现数量调整
good.GoodCompute.UsePartnerBonus = -1
good.GoodCompute.UseAmount = -1
} else {
//计算调整后的货品总值
//计算调整后的合伙人分红
useamount := price.Mul(decimal.NewFromInt(int64(good.UseGoodNumber))) //price*useGoodNumber/price*useGoodNumber
usePartnerBonus := useamount.Mul(decimal.NewFromFloat(good.PartnerBonusPercent)).Div(decimal.NewFromInt(100)) //price*useGoodNumber*PartnerBonusPercent
good.GoodCompute.UsePartnerBonus, _ = usePartnerBonus.Round(2).BigFloat().Float64()
good.GoodCompute.UseAmount, _ = useamount.Round(2).BigFloat().Float64()
}
return nil
}
type OrderGoodFindQuery struct {
OrderId int64
Offset int
Limit int
}
type OrderGoodRepository interface {
Save(order []OrderGood) error
Find(queryOptions OrderGoodFindQuery) ([]OrderGood, int, error)
Remove(orderid int64, ids ...int64) error
}
... ...
package domain
import "time"
const (
BonusWaitPay = iota + 1 //等待支付分红
BonusPaid //已经支付分红
)
type OrderPayment struct {
//编号
Id int64 `json:"id"`
//订单编号
OrderId int64 `json:"orderId"`
//合伙人编号
PartnerId int64 `json:"partnerId"`
//支付货款
PaymentAmount float64 `json:"paymentAmount"`
//分红金额
BonusAmount float64 `json:"bonusAmount"`
//分红状态 1.等待支付分红 2.已支付分红
BonusStatus int `json:"bonusStatus"`
//创建时间
CreateAt time.Time `json:"createAt"`
//更新时间
UpdateAt time.Time `json:"updateAt"`
//扩展
PartnerBonusPercent float64 `json:"-"`
}
func (m *OrderPayment) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
func (m *OrderPayment) Update(data map[string]interface{}) error {
if m.BonusStatus != BonusWaitPay {
return nil
}
if paymentAmount, ok := data["paymentAmount"]; ok && paymentAmount != 0 {
m.PaymentAmount = paymentAmount.(float64)
}
if bonusAmount, ok := data["bonusAmount"]; ok && bonusAmount != 0 {
m.BonusAmount = bonusAmount.(float64)
}
if bonusStatus, ok := data["bonusStatus"]; ok && bonusStatus != 0 {
m.BonusStatus = bonusStatus.(int)
}
m.UpdateAt = time.Now()
return nil
}
type OrderPaymentFindOneQuery struct {
Id int64
OrderId int64
PaymentId int
}
type OrderPaymentQuery struct {
Offset int
Limit int
OrderId int64
//PartnerCategory []int //合伙人类型
//RegionInfo *RegionInfo //区域
//PartnerName string //合伙人姓名
}
type OrderPaymentRepository interface {
Save(dm *OrderPayment) (*OrderPayment, error)
FindOne(queryOptions OrderPaymentFindOneQuery) (*OrderPayment, error)
Find(queryOptions OrderPaymentQuery) ([]*OrderPayment, error)
CountAll(queryOptions OrderPaymentQuery) (int, error)
}
package dao
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type OrderBaseDao struct {
transactionContext *transaction.TransactionContext
}
func NewOrderBaseDao(transactionContext *transaction.TransactionContext) (*OrderBaseDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &OrderBaseDao{
transactionContext: transactionContext,
}, nil
}
}
func (dao OrderBaseDao) OrderCodeExist(code string, notId ...int64) (bool, error) {
tx := dao.transactionContext.PgDd
m := &models.OrderBase{}
query := tx.Model(m).Where("order_code=?", code)
if len(notId) > 0 {
query = query.WhereIn("id not in(?)", notId)
}
ok, err := query.Exists()
return ok, err
}
func (dao OrderBaseDao) DeliveryCodeExist(code string, notId ...int64) (bool, error) {
tx := dao.transactionContext.PgDd
m := &models.OrderBase{}
query := tx.Model(m).Where("delivery_code=?", code)
if len(notId) > 0 {
query = query.WhereIn("id not in(?)", notId)
}
ok, err := query.Exists()
return ok, err
}
... ...
package dao
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type OrderDao struct {
transactionContext *transaction.TransactionContext
}
func (dao *OrderDao) Update(options map[string]interface{}) (err error) {
tx := dao.transactionContext.PgTx
order := new(models.Order)
q := tx.Model(order)
if v, ok := options["orderPaymentAmount"]; ok {
q.Set("order_payment_amount = ?", v)
}
if v, ok := options["bonusStatus"]; ok {
q.Set("bonus_status = ?", v)
}
if v, ok := options["id"]; ok {
q.Where("id = ?", v)
}
_, err = q.Update()
return
}
func (dao *OrderDao) OrderCodeIsExist(code string, notId int64) (bool, error) {
tx := dao.transactionContext.PgDd
ok, err := tx.Model(new(models.Order)).
Where("order_code=?", code).
Where("id<>?", notId).
Exists()
return ok, err
}
func (dao *OrderDao) GetOrderBaseInfo(id int64) (data map[string]interface{}, err error) {
tx := dao.transactionContext.PgTx
order := new(models.Order)
data = make(map[string]interface{})
q := tx.Model(order)
q.Column("partner_id", "partner_bonus_percent", "order_payment_amount", "buyer")
q.Where("id = ?", id)
err = q.Select()
if err == nil {
data["PartnerId"] = order.PartnerId
data["PartnerBonusPercent"] = order.PartnerBonusPercent
data["OrderPaymentAmount"] = order.OrderPaymentAmount
data["Buyer"] = order.Buyer
}
return
}
func (dao *OrderDao) GetDividendOrders(options map[string]interface{}) (count int, orders []*models.Order, err error) {
tx := dao.transactionContext.PgTx
//Order:=new(models.Order)
q := tx.Model(&orders)
q.ColumnExpr(`"order".*`, `partner_info.partner_name`)
q.Relation("PartnerInfo")
if v, ok := options["orderCode"]; ok && len(v.(string)) > 0 {
q.Where(`"order".order_code like ?`, fmt.Sprintf("%%%v%%", v))
}
if v, ok := options["orderType"]; ok {
q.Where(`"order".order_type=?`, v)
}
if v, ok := options["partnerId"]; ok && v.(int) > 0 {
q.Where(`"order".partner_id =?`, v)
}
if v, ok := options["offset"]; ok {
q.Offset(v.(int))
}
if v, ok := options["limit"]; ok {
q.Limit(v.(int))
}
q.Order(`order.id DESC`)
count, err = q.SelectAndCount()
return
}
func NewOrderDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &OrderDao{
transactionContext: transactionContext,
}, nil
}
}
package dao
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type OrderPayment struct {
transactionContext *transaction.TransactionContext
}
//删除数据
func (o *OrderPayment) Remove(orderId int64, status int, idList []int) error {
if len(idList) == 0 {
return nil
}
tx := o.transactionContext.PgTx
m := new(models.OrderPayment)
q := tx.Model(m).Where("order_id=?", orderId).
WhereIn("id not in(?)", idList)
_, err := q.Delete()
return err
}
func NewOrderPayment(transactionContext *transaction.TransactionContext) (*OrderPayment, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &OrderPayment{
transactionContext: transactionContext,
}, nil
}
}
package models
import (
"context"
"time"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
//OrderBase 订单基础
type OrderBase struct {
tableName struct{} `pg:"order_base"`
//表id
Id int64 `pg:",pk"`
//订单类型
OrderType int
//订单编号
OrderCode string
//交货编号
DeliveryCode string
//买家
Buyer *domain.Buyer
//订单区域信息
RegionInfo *domain.RegionInfo
//订单对应的合伙人
PartnerId int64
//业务员抽成比例
SalesmanBonusPercent float64 `pg:",use_zero"`
//业务员抽成
SalesmanBonus float64 `pg:",use_zero"`
//预计的订单内货品总数
PlanOrderCount int `pg:",use_zero"`
//预计的订单的总金额
PlanOrderAmount float64 `pg:",use_zero"`
//按需使用的订单内货品总数 (初始值=-1)
//业务判定时0是有效值,负值无效
UseOrderCount int `pg:",use_zero"`
//按需使用的订单内货总金额 (初始值=-1)
//业务判定时0是有效值,负值无效
UseOrderAmount float64 `pg:",use_zero"`
//订单的创建时间
CreateTime time.Time
//发货时间
DeliveryTime time.Time
//更新时间
UpdateTime time.Time
//合伙人应收分红
PlanPartnerBonus float64 `pg:",use_zero"`
//调整后的合伙人应收分红 (初始值=-1);
//业务判定时0是有效值,负值无效
UsePartnerBonus float64 `pg:",use_zero"`
//合伙人已收分红
PartnerBonusHas float64 `pg:",use_zero"`
//合伙人未收分红
PartnerBonusNot float64
//合伙人分红支出
PartnerBonusExpense float64 `pg:",use_zero"`
//上一次查看时间 已读情况
LastViewTime time.Time
//是否关闭订单
IsDisable int `pg:",use_zero"`
//分红支付状态
BonusStatus int
}
var _ pg.BeforeUpdateHook = (*OrderBase)(nil)
func (order *OrderBase) BeforeUpdate(ctx context.Context) (context.Context, error) {
order.UpdateTime = time.Now()
return ctx, nil
}
var _ pg.BeforeInsertHook = (*OrderBase)(nil)
func (order *OrderBase) BeforeInsert(ctx context.Context) (context.Context, error) {
order.CreateTime = time.Now()
order.UpdateTime = time.Now()
return ctx, nil
}
... ...
package models
//OrderGood 订单中的货品
type OrderGood struct {
tableName struct{} `pg:"order_good"`
//货品id
Id int64
//所属订单id
OrderId int64
//货品名称 长度可能较长
GoodName string
//预计的货品数量
PlanGoodNumber int `pg:",use_zero"`
//货品单价
Price float64 `pg:",use_zero"`
//预计的货品总额
PlanAmount float64 `pg:",use_zero"`
//调整后的货品数量(初始值=-1)
//业务判定时0是有效值,负值无效
UseGoodNumber int `pg:",use_zero"`
//调整后的货品总额
UseAmount float64 `pg:",use_zero"`
//合伙人分红比例
PartnerBonusPercent float64 `pg:",use_zero"`
//预计的合伙人分红
PlanPartnerBonus float64 `pg:",use_zero"`
//合伙人应收分红调整 (初始值=-1)
////业务判定时0是有效值,负值无效
UsePartnerBonus float64 `pg:",use_zero"`
//合伙人已收分红
PartnerBonusHas float64 `pg:",use_zero"`
//合伙人未收分红
PartnerBonusNot float64 `pg:",use_zero"`
//合伙人分红支出
PartnerBonusExpense float64 `pg:",use_zero"`
//分红状态
BonusStatus int
//备注信息
Remark string
}
... ...
package repository
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"
)
type OrderBaseRepository struct {
transactionContext *transaction.TransactionContext
}
var (
_ domain.OrderBaseRepository = (*OrderBaseRepository)(nil)
)
func NewOrderBaseRepository(transactionContext *transaction.TransactionContext) (*OrderBaseRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &OrderBaseRepository{transactionContext: transactionContext}, nil
}
func (reponsitory OrderBaseRepository) transformPgModelToDomainModel(orderModel *models.OrderBase) (order domain.OrderBase, err error) {
order = domain.OrderBase{
Id: orderModel.Id, OrderType: orderModel.OrderType, OrderCode: orderModel.OrderCode,
DeliveryCode: orderModel.DeliveryCode, Buyer: orderModel.Buyer, RegionInfo: orderModel.RegionInfo,
PartnerId: orderModel.PartnerId, SalesmanBonusPercent: orderModel.SalesmanBonusPercent,
CreateTime: orderModel.CreateTime, DeliveryTime: orderModel.DeliveryTime, UpdateTime: orderModel.UpdateTime,
IsDisable: orderModel.IsDisable,
OrderCompute: domain.OrderCompute{
PlanPartnerBonus: orderModel.PlanPartnerBonus, UsePartnerBonus: orderModel.UsePartnerBonus,
PartnerBonusHas: orderModel.PartnerBonusHas, PartnerBonusNot: orderModel.PartnerBonusNot,
PartnerBonusExpense: orderModel.PartnerBonusExpense, SalesmanBonus: orderModel.SalesmanBonus,
PlanOrderCount: orderModel.PlanOrderCount, PlanOrderAmount: orderModel.PlanOrderAmount,
UseOrderCount: orderModel.UseOrderCount, UseOrderAmount: orderModel.UseOrderAmount,
},
PartnerInfo: domain.Partner{
Id: orderModel.PartnerId,
},
BonusStatus: orderModel.BonusStatus,
}
return order, nil
}
func (repository OrderBaseRepository) Save(orderInfo *domain.OrderBase) error {
var (
err error
tx = repository.transactionContext.PgTx
)
m := &models.OrderBase{
Id: orderInfo.Id, OrderType: orderInfo.OrderType, OrderCode: orderInfo.OrderCode,
DeliveryCode: orderInfo.DeliveryCode, Buyer: orderInfo.Buyer, RegionInfo: orderInfo.RegionInfo,
PartnerId: orderInfo.PartnerId, SalesmanBonusPercent: orderInfo.SalesmanBonusPercent,
SalesmanBonus: orderInfo.OrderCompute.SalesmanBonus, PlanOrderCount: orderInfo.OrderCompute.PlanOrderCount,
PlanOrderAmount: orderInfo.OrderCompute.PlanOrderAmount, UseOrderCount: orderInfo.OrderCompute.UseOrderCount,
UseOrderAmount: orderInfo.OrderCompute.UseOrderAmount, DeliveryTime: orderInfo.DeliveryTime,
PlanPartnerBonus: orderInfo.OrderCompute.PlanPartnerBonus, UsePartnerBonus: orderInfo.OrderCompute.UsePartnerBonus,
PartnerBonusHas: orderInfo.OrderCompute.PartnerBonusHas, PartnerBonusNot: orderInfo.OrderCompute.PartnerBonusNot,
PartnerBonusExpense: orderInfo.OrderCompute.PartnerBonusExpense, IsDisable: orderInfo.IsDisable,
CreateTime: orderInfo.CreateTime, BonusStatus: orderInfo.BonusStatus,
}
if m.Id == 0 {
_, err = tx.Model(m).
Returning("*").
Insert()
orderInfo.Id = m.Id
orderInfo.CreateTime = m.CreateTime
orderInfo.UpdateTime = m.UpdateTime
} else {
_, err = tx.Model(m).
WherePK().
Returning("*").
Update()
orderInfo.UpdateTime = m.UpdateTime
}
return err
}
func (repository OrderBaseRepository) Find(queryOption domain.OrderBaseFindQuery) ([]domain.OrderBase, int, error) {
db := repository.transactionContext.PgDd
orderModels := []models.OrderBase{}
query := db.Model(&orderModels)
if queryOption.PartnerId > 0 {
query = query.Where("partner_id=?", queryOption.PartnerId)
}
if len(queryOption.OrderCode) > 0 {
query = query.Where("order_code like ?", "%"+queryOption.OrderCode+"%")
}
if len(queryOption.DeliveryCode) > 0 {
query = query.Where("delivery_code like ?", "%"+queryOption.DeliveryCode+"%")
}
if queryOption.OrderType > 0 {
query = query.Where("order_type=?", queryOption.OrderType)
}
if queryOption.Offset > -1 {
query = query.Offset(queryOption.Offset)
}
if queryOption.Limit > 0 {
query = query.Limit(queryOption.Limit)
} else {
query = query.Limit(20)
}
var (
err error
ordersReturn = make([]domain.OrderBase, 0)
)
query = query.Order("order_base.id DESC")
count, err := query.SelectAndCount()
if err != nil {
return ordersReturn, 0, err
}
for i := range orderModels {
domainOrder, err := repository.transformPgModelToDomainModel(&orderModels[i])
if err != nil {
return ordersReturn, 0, err
}
ordersReturn = append(ordersReturn, domainOrder)
}
return ordersReturn, count, nil
}
func (repository OrderBaseRepository) FindOne(qureyOptions domain.OrderBaseFindOneQuery) (*domain.OrderBase, error) {
var (
err error
tx = repository.transactionContext.PgDd
)
m := new(models.OrderBase)
err = tx.Model(m).
Where("id=?", qureyOptions.OrderId).
First()
if err != nil {
return nil, err
}
result, err := repository.transformPgModelToDomainModel(m)
return &result, err
}
func (repository OrderBaseRepository) Remove(id int64) error {
var (
err error
tx = repository.transactionContext.PgTx
)
m := &models.OrderBase{
Id: id,
}
_, err = tx.Model(m).WherePK().Delete()
return err
}
... ...
package repository
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"
)
type OrderGoodRepository struct {
transactionContext *transaction.TransactionContext
}
var (
_ domain.OrderGoodRepository = (*OrderGoodRepository)(nil)
)
func NewOrderGoodRepository(transactionContext *transaction.TransactionContext) (*OrderGoodRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &OrderGoodRepository{transactionContext: transactionContext}, nil
}
func (reponsitory OrderGoodRepository) transformPgModelToDomainModel(orderModel *models.OrderGood) (order domain.OrderGood, err error) {
order = domain.OrderGood{
Id: orderModel.Id, OrderId: orderModel.OrderId, GoodName: orderModel.GoodName,
PlanGoodNumber: orderModel.PlanGoodNumber, UseGoodNumber: orderModel.UseGoodNumber,
Price: orderModel.Price, PartnerBonusPercent: orderModel.PartnerBonusPercent,
BonusStatus: orderModel.BonusStatus, Remark: orderModel.Remark,
GoodCompute: domain.GoodCompute{
PlanAmount: orderModel.PlanAmount,
UseAmount: orderModel.UseAmount,
PlanPartnerBonus: orderModel.PlanPartnerBonus,
UsePartnerBonus: orderModel.UsePartnerBonus,
PartnerBonusHas: orderModel.PartnerBonusHas,
PartnerBonusNot: orderModel.PartnerBonusNot,
PartnerBonusExpense: orderModel.PartnerBonusExpense,
},
}
switch orderModel.BonusStatus {
case domain.OrderGoodWaitPay:
order.CurrentBonusStatus = domain.OrderGoodBonusWaitPay{}
case domain.OrderGoodHasPay:
order.CurrentBonusStatus = domain.OrderGoodBonusHasPay{}
}
return order, nil
}
func (repository OrderGoodRepository) Save(data []domain.OrderGood) error {
var (
err error
tx = repository.transactionContext.PgTx
)
for k, v := range data {
m := &models.OrderGood{
Id: v.Id, OrderId: v.OrderId, GoodName: v.GoodName,
PlanGoodNumber: v.PlanGoodNumber, Price: v.Price,
PlanAmount: v.GoodCompute.PlanAmount, UseGoodNumber: v.UseGoodNumber,
UseAmount: v.GoodCompute.UseAmount, PartnerBonusPercent: v.PartnerBonusPercent,
PlanPartnerBonus: v.GoodCompute.PlanPartnerBonus, UsePartnerBonus: v.GoodCompute.UsePartnerBonus,
PartnerBonusHas: v.GoodCompute.PartnerBonusHas, PartnerBonusNot: v.GoodCompute.PartnerBonusNot,
PartnerBonusExpense: v.GoodCompute.PartnerBonusExpense, BonusStatus: v.BonusStatus,
Remark: v.Remark,
}
if v.Id == 0 {
_, err = tx.Model(m).
Returning("*").
Insert()
if err != nil {
return err
}
data[k].Id = m.Id
} else {
_, err = tx.Model(m).
WherePK().
Update()
if err != nil {
return err
}
}
}
return nil
}
func (repository OrderGoodRepository) Find(queryOption domain.OrderGoodFindQuery) ([]domain.OrderGood, int, error) {
db := repository.transactionContext.PgDd
goodModes := []models.OrderGood{}
query := db.Model(&goodModes)
if queryOption.OrderId > 0 {
query = query.Where("order_id=?", queryOption.OrderId)
}
if queryOption.Offset > -1 {
query = query.Offset(queryOption.Offset)
}
if queryOption.Limit > 0 {
query = query.Limit(queryOption.Limit)
} else {
query = query.Limit(100)
}
var (
err error
orderGoods = make([]domain.OrderGood, 0)
)
query = query.Order("order_good.id")
count, err := query.SelectAndCount()
if err != nil {
return orderGoods, 0, err
}
for i := range goodModes {
domainOrderGood, err := repository.transformPgModelToDomainModel(&goodModes[i])
if err != nil {
return orderGoods, 0, err
}
orderGoods = append(orderGoods, domainOrderGood)
}
return orderGoods, count, nil
}
func (repository OrderGoodRepository) Remove(orderId int64, goodids ...int64) error {
var (
err error
tx = repository.transactionContext.PgTx
)
m := &models.OrderGood{}
query := tx.Model(m).Where("order_id=?", orderId)
if len(goodids) > 0 {
query = query.WhereIn("id in(?)", goodids)
}
_, err = query.Delete()
return err
}
... ...
package repository
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"
)
type OrderPaymentRepository struct {
transactionContext *transaction.TransactionContext
}
func (repository *OrderPaymentRepository) Save(dm *domain.OrderPayment) (*domain.OrderPayment, error) {
var (
err error
tx = repository.transactionContext.PgTx
)
m := &models.OrderPayment{
Id: dm.Id,
OrderId: dm.OrderId,
PartnerId: dm.PartnerId,
PaymentAmount: dm.PaymentAmount,
BonusAmount: dm.BonusAmount,
BonusStatus: dm.BonusStatus,
CreateAt: dm.CreateAt,
UpdateAt: dm.UpdateAt,
}
if m.Id == 0 {
err = tx.Insert(m)
dm.Id = m.Id
if err != nil {
return nil, err
}
} else {
err = tx.Update(m)
if err != nil {
return nil, err
}
}
return dm, nil
}
func (repository *OrderPaymentRepository) Remove(OrderPayment *domain.OrderPayment) (*domain.OrderPayment, error) {
var (
tx = repository.transactionContext.PgTx
OrderPaymentModel = &models.OrderPayment{Id: OrderPayment.Identify().(int64)}
)
if _, err := tx.Model(OrderPaymentModel).Where("id = ?", OrderPayment.Id).Delete(); err != nil {
return OrderPayment, err
}
return OrderPayment, nil
}
func (repository *OrderPaymentRepository) FindOne(queryOptions domain.OrderPaymentFindOneQuery) (*domain.OrderPayment, error) {
tx := repository.transactionContext.PgTx
OrderPaymentModel := new(models.OrderPayment)
query := tx.Model(OrderPaymentModel)
if queryOptions.OrderId > 0 {
query.Where("order_payment.order_id = ?", queryOptions.OrderId)
}
if queryOptions.PaymentId > 0 {
query.Where("order_payment.id = ?", queryOptions.PaymentId)
}
if err := query.First(); err != nil {
return nil, err
}
if OrderPaymentModel.Id == 0 {
return nil, nil
}
return repository.transformPgModelToDomainModel(OrderPaymentModel)
}
func (repository *OrderPaymentRepository) Find(queryOptions domain.OrderPaymentQuery) ([]*domain.OrderPayment, error) {
tx := repository.transactionContext.PgTx
var OrderPaymentModels []*models.OrderPayment
query := tx.Model(&OrderPaymentModels)
query.Where("order_id=?", queryOptions.OrderId)
query.Order("id ASC")
var (
err error
rsp = make([]*domain.OrderPayment, 0)
)
err = query.Select()
if err != nil {
return rsp, err
}
for i := range OrderPaymentModels {
dm, err := repository.transformPgModelToDomainModel(OrderPaymentModels[i])
if err != nil {
return rsp, err
}
rsp = append(rsp, dm)
}
return rsp, nil
}
func (repository OrderPaymentRepository) CountAll(queryOption domain.OrderPaymentQuery) (int, error) {
db := repository.transactionContext.PgDd
partnerModels := models.PartnerInfo{}
query := db.Model(&partnerModels)
//if len(queryOption.PartnerName) > 0 {
// query = query.Where("partner_name like ?", "%"+queryOption.PartnerName+"%")
//}
//if queryOption.RegionInfo != nil {
// query = query.Where("region_info::jsonb->>'regionName' like ?", "%"+queryOption.RegionInfo.RegionName+"%")
//}
//if len(queryOption.PartnerCategory) > 0 {
// query = query.WhereIn("partner_category in(?)", queryOption.PartnerCategory)
//}
cnt, err := query.Count()
return cnt, err
}
func (repository *OrderPaymentRepository) transformPgModelToDomainModel(dm *models.OrderPayment) (*domain.OrderPayment, error) {
m := &domain.OrderPayment{
Id: dm.Id,
OrderId: dm.OrderId,
PartnerId: dm.PartnerId,
PaymentAmount: dm.PaymentAmount,
BonusAmount: dm.BonusAmount,
BonusStatus: dm.BonusStatus,
CreateAt: dm.CreateAt,
UpdateAt: dm.UpdateAt,
}
return m, nil
}
func NewOrderPaymentRepository(transactionContext *transaction.TransactionContext) (*OrderPaymentRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &OrderPaymentRepository{transactionContext: transactionContext}, nil
}
package repository
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"
)
type OrderRepository struct {
transactionContext *transaction.TransactionContext
}
var (
_ domain.OrderRepository = (*OrderRepository)(nil)
)
func NewOrderRepository(transactionContext *transaction.TransactionContext) (*OrderRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &OrderRepository{transactionContext: transactionContext}, nil
}
func (reponsitory OrderRepository) transformPgModelToDomainModel(orderModel *models.Order) (domain.Order, error) {
result := domain.Order{
Id: orderModel.Id,
OrderType: orderModel.OrderType,
OrderCode: orderModel.OrderCode,
OrderName: orderModel.OrderName,
OrderStatus: orderModel.OrderStatus,
OrderCount: orderModel.OrderCount,
OrderActualCount: orderModel.OrderActualCount,
OrderAmount: orderModel.OrderAmount,
OrderActualAmount: orderModel.OrderActualAmount,
OrderPaymentAmount: orderModel.OrderPaymentAmount,
OrderRegionInfo: orderModel.OrderRegionInfo,
Buyer: orderModel.Buyer,
PartnerInfo: domain.Partner{
Id: orderModel.PartnerId,
},
PartnerBonusPercent: orderModel.PartnerBonusPercent,
SalesmanBonusPercent: orderModel.SalesmanBonusPercent,
LastViewTime: orderModel.LastViewTime,
UpdateAt: orderModel.UpdateAt,
CreateAt: orderModel.CreateAt,
Reason: orderModel.Reason,
}
return result, nil
}
func (repository OrderRepository) Save(orderInfo domain.Order) error {
var (
err error
tx = repository.transactionContext.PgTx
)
m := &models.Order{
Id: orderInfo.Id,
OrderType: orderInfo.OrderType,
OrderCode: orderInfo.OrderCode,
OrderName: orderInfo.OrderName,
OrderStatus: orderInfo.OrderStatus,
OrderCount: orderInfo.OrderCount,
OrderActualCount: orderInfo.OrderActualCount,
OrderAmount: orderInfo.OrderAmount,
OrderActualAmount: orderInfo.OrderActualAmount,
OrderPaymentAmount: orderInfo.OrderPaymentAmount,
OrderRegionInfo: orderInfo.OrderRegionInfo,
Buyer: orderInfo.Buyer,
PartnerId: orderInfo.PartnerInfo.Id,
PartnerBonusPercent: orderInfo.PartnerBonusPercent,
SalesmanBonusPercent: orderInfo.SalesmanBonusPercent,
BonusStatus: 1,
Reason: orderInfo.Reason,
}
if m.Id == 0 {
err = tx.Insert(m)
orderInfo.Id = m.Id
} else {
_, err = tx.Model(m).WherePK().
Column("order_type", "order_code", "order_name", "order_status", "order_count",
"order_actual_count", "order_amount", "order_actual_amount", "order_payment_amount",
"order_region_info", "buyer", "partner_id", "partner_bonus_percent", "salesman_bonus_percent",
"update_at", "reason").
Update()
}
return err
}
func (repository OrderRepository) Find(queryOption domain.OrderFindQuery) ([]domain.Order, error) {
db := repository.transactionContext.PgDd
orderModels := []models.Order{}
query := db.Model(&orderModels)
if queryOption.PartnerId > 0 {
query = query.Where("partner_id=?", queryOption.PartnerId)
}
if len(queryOption.OrderCode) > 0 {
query = query.Where("order_code like ?", "%"+queryOption.OrderCode+"%")
}
if queryOption.OrderType > 0 {
query = query.Where("order_type=?", queryOption.OrderType)
}
if queryOption.Offset > -1 {
query = query.Offset(queryOption.Offset)
}
if queryOption.Limit > 0 {
query = query.Limit(queryOption.Limit)
} else {
query = query.Limit(20)
}
var (
err error
ordersReturn = make([]domain.Order, 0)
)
query = query.Order("order.id DESC")
err = query.Select()
if err != nil {
return ordersReturn, err
}
for i := range orderModels {
domainOrder, err := repository.transformPgModelToDomainModel(&orderModels[i])
if err != nil {
return ordersReturn, err
}
ordersReturn = append(ordersReturn, domainOrder)
}
return ordersReturn, nil
}
func (repository OrderRepository) CountAll(queryOption domain.OrderFindQuery) (int, error) {
db := repository.transactionContext.PgDd
orderModels := []models.Order{}
query := db.Model(&orderModels)
if queryOption.PartnerId > 0 {
query = query.Where("partner_id=?", queryOption.PartnerId)
}
if len(queryOption.OrderCode) > 0 {
query = query.Where("order_code like ?", "%"+queryOption.OrderCode+"%")
}
if queryOption.OrderType > 0 {
query = query.Where("order_type=?", queryOption.OrderType)
}
var (
err error
)
cnt, err := query.Count()
if err != nil {
return cnt, err
}
return cnt, nil
}
func (repository OrderRepository) FindOne(qureyOptions domain.OrderFindOneQuery) (*domain.Order, error) {
var (
err error
tx = repository.transactionContext.PgDd
)
m := new(models.Order)
err = tx.Model(m).
Where("id=?", qureyOptions.OrderId).
First()
if err != nil {
return nil, err
}
result, err := repository.transformPgModelToDomainModel(m)
return &result, err
}
func (repository OrderRepository) Remove(id int64) error {
var (
err error
tx = repository.transactionContext.PgTx
)
m := &models.Order{
Id: id,
}
_, err = tx.Model(m).WherePK().Delete()
return err
}
package controllers
import (
"bytes"
"encoding/json"
"errors"
"fmt"
... ... @@ -21,7 +22,10 @@ type BaseController struct {
}
func (controller BaseController) BindJsonData(v interface{}) error {
return json.Unmarshal(controller.Ctx.Input.RequestBody, v)
newDecoder := json.NewDecoder(bytes.NewReader(controller.Ctx.Input.RequestBody))
newDecoder.UseNumber()
err := newDecoder.Decode(v)
return err
}
func (controller BaseController) ResponseError(err error) {
... ... @@ -38,7 +42,6 @@ func (controller BaseController) ResponseError(err error) {
} else {
logs.Error(e.Prefix, e.Message)
}
}
controller.Data["json"] = protocol.ResponseData{
Code: -1,
... ...
package controllers
import (
"errors"
"fmt"
"github.com/astaxie/beego/logs"
OrderPaymentCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command"
OrderPaymentQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query"
OrderPaymentSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils"
OrderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/query"
OrderSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/service"
PartnerInfoQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query"
PartnerInfoSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"strconv"
)
type DividendsController struct {
BaseController
}
////Prepare 重写 BaseController 的Prepare方法
func (c *DividendsController) Prepare() {
c.BaseController.Prepare()
if ok := c.ValidJWTToken(); !ok {
return
}
if ok := c.ValidAdminPermission(domain.PERMISSION_DIVIDEND); !ok {
return
}
}
//Edit 编辑分红支付
func (c *DividendsController) Edit() {
//用与适配前端定义的数据结构
type DividendPaymentItem struct {
PaymentForGoods float64 `json:"paymentForGoods"`
StateOfPayment int `json:"stateOfPayment"`
Id int `json:"id"`
}
type Parameter struct {
Id string `json:"id"` //订单编号
DividendPayment []DividendPaymentItem `json:"dividendPayment"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
if len(param.Id) == 0 {
c.ResponseError(errors.New("id is empty"))
return
}
orderId, _ := strconv.ParseInt(param.Id, 10, 64)
cmd := OrderPaymentCmd.CreateOrderPaymentCommand{
OrderId: orderId,
DivdendPaymentItem: make([]OrderPaymentCmd.DivdendPyamentItem, 0),
}
//编辑
for i := range param.DividendPayment {
item := param.DividendPayment[i]
paymentItem := OrderPaymentCmd.DivdendPyamentItem{}
paymentItem.PaymentForGoods = item.PaymentForGoods
paymentItem.StateOfPayment = item.StateOfPayment
paymentItem.PaymentSn = i + 1
paymentItem.PaymentId = item.Id
if paymentItem.StateOfPayment == domain.BonusPaid {
cmd.TotalPaymentAmount += paymentItem.PaymentForGoods
}
cmd.DivdendPaymentItem = append(cmd.DivdendPaymentItem, paymentItem)
}
serve := OrderPaymentSvr.NewOrderPaymentService(nil)
_, err = serve.CreateOrderPayment(&cmd)
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
return
}
//Edit 分红支付详情
func (c *DividendsController) Detail() {
type Parameter struct {
Id string `json:"id"` //订单编号
}
var (
param Parameter
err error
order *domain.Order
partner *domain.PartnerInfo
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
cmd := OrderPaymentQuery.GetOrderPaymentQuery{}
cmd.OrderId, _ = strconv.ParseInt(param.Id, 10, 64)
var (
OrderPaymentSvr = OrderPaymentSvr.NewOrderPaymentService(nil)
OrderSvr = OrderSvr.NewOrderService(nil)
PartnerInfoSvr = PartnerInfoSvr.NewPartnerInfoService(nil)
)
var data []*domain.OrderPayment
data, err = OrderPaymentSvr.ListOrderPayment(&cmd)
if err != nil {
c.ResponseError(err)
return
}
if order, err = OrderSvr.GetOrder(OrderQuery.GetOrderQuery{OrderId: cmd.OrderId}); err != nil {
c.ResponseError(err)
return
}
if partner, err = PartnerInfoSvr.GetPartnerInfo(PartnerInfoQuery.GetPartnerInfoQuery{Id: order.PartnerInfo.Id}); err != nil {
c.ResponseError(err)
return
}
type DividendPayment struct {
PaymentForGoods float64 `json:"paymentForGoods"`
UpdateTime string `json:"updateTime"`
StateOfPayment int `json:"stateOfPayment"`
Dividend float64 `json:"dividend"`
DividendProportion float64 `json:"dividendProportion"`
Id int64 `json:"id"`
}
type Order struct {
OrderNumber string `json:"orderNumber"` //订单号
OrderState int `json:"orderState"` //订单状态
CreateTime string `json:"createTime"` //订单创建时间
OrderName string `json:"orderName"` //订单名称
OrderNum string `json:"orderNum"` //订单数量
OrderAmount string `json:"orderAmount"` //订单金额
Id string `json:"id"` //订单编号
}
type Partner struct {
PartnerName string `json:"partnerName"` //合伙人姓名
DividendProportion float64 `json:"dividendProportion"` //分红比例
DividendsReceivable float64 `json:"dividendsReceivable"` //应收分红
DividendSpending float64 `json:"dividendSpending"` //分红支出
ReceiveDividends float64 `json:"receiveDividends"` //实收分红
NotReceivedDividends float64 `json:"notReceivedDividends"` //未收分红
RceivedDividends float64 `json:"receivedDividends"` //已收分红
}
type Commission struct {
SalesmanName string `json:"salesmanName"` //业务员名称
CommissionProportion float64 `json:"commissionProportion"` //业务员抽成比例
ExpectedCommission float64 `json:"expectedCommission"` //业务员预计抽成
}
type Response struct {
DividendPayment []DividendPayment `json:"dividendPayment"`
Order Order `json:"order"`
Partner Partner `json:"partner"`
Commission Commission `json:"commission"`
}
rsp := Response{DividendPayment: make([]DividendPayment, 0)}
for i := range data {
item := data[i]
payment := DividendPayment{
PaymentForGoods: item.PaymentAmount,
UpdateTime: item.UpdateAt.Local().Format("2006-01-02 15:04:05"),
StateOfPayment: item.BonusStatus,
Dividend: utils.Decimal(item.PaymentAmount * (order.PartnerBonusPercent / 100.0)),
DividendProportion: order.PartnerBonusPercent,
Id: item.Id,
}
rsp.DividendPayment = append(rsp.DividendPayment, payment)
}
rsp.Order = Order{
OrderNumber: order.OrderCode,
OrderState: order.OrderStatus,
CreateTime: order.CreateAt.Local().Format("2006-01-02 15:04:05"),
OrderName: order.OrderName,
OrderNum: fmt.Sprintf("%v", order.OrderActualCount),
OrderAmount: fmt.Sprintf("%v", order.OrderActualAmount),
Id: fmt.Sprintf("%v", order.Id),
}
rsp.Partner = Partner{
PartnerName: partner.Partner.PartnerName,
DividendProportion: order.PartnerBonusPercent,
DividendsReceivable: order.OrderTotalBonus() + order.OrderBonusOutstanding(), //应收分红 = 实收分红+分红支出
DividendSpending: order.OrderBonusOutstanding(), //分红支出
ReceiveDividends: order.OrderTotalBonus(), //实收分红 = 实际金额 * 比例
NotReceivedDividends: order.OrderBonusWait(), //未收分红
RceivedDividends: order.OrderBonusReceive(), //已收分红
}
rsp.Commission = Commission{
CommissionProportion: order.SalesmanBonusPercent,
ExpectedCommission: utils.Decimal(order.OrderActualAmount * (order.SalesmanBonusPercent / 100)),
}
if len(partner.Salesman) > 0 {
rsp.Commission.SalesmanName = partner.Salesman[0].Name
}
c.ResponseData(rsp)
return
}
//分红管理
func (c *DividendsController) List() {
var (
param OrderPaymentQuery.ListDividendOrdersQuery
err error
count int
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
if param.PageSize == 0 {
param.PageSize = 20
}
if param.PageNumber == 0 {
param.PageNumber = 1
}
serve := OrderPaymentSvr.NewOrderPaymentService(nil)
var data interface{}
count, data, err = serve.ListDividendOrders(&param)
if err != nil {
c.ResponseError(err)
return
}
c.ResponsePageList(data, count, param.PageNumber)
return
}
package controllers
import (
"errors"
"strconv"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
"github.com/astaxie/beego/logs"
orderCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/command"
orderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/query"
orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
type OrderController struct {
BaseController
}
////Prepare 重写 BaseController 的Prepare方法
func (c *OrderController) Prepare() {
c.BaseController.Prepare()
if ok := c.ValidJWTToken(); !ok {
return
}
if ok := c.ValidAdminPermission(domain.PERMISSION_ORDER); !ok {
return
}
}
type orderDetail struct {
//买家姓名
Buyer string `json:"buyer"`
//买家联系方式
BuyerPhone string `json:"buyerPhone"`
//收货地址
Address string `json:"address"`
//对应合伙人 id
Partner int64 `json:"partner"`
//合伙人抽成比例
PartnerRatio float64 `json:"partnerRatio"`
//业务员抽成比例
SalesmanRatio float64 `json:"salesmanRatio"`
//订单号
OrderId string `json:"orderId"`
//订单名称
OrderName string `json:"orderName"`
//订单数量
OrderNum int `json:"orderNum"`
//订单金额
OrderPrice float64 `json:"orderPrice"`
//订单区域
OrderDist string `json:"orderDist"`
//id
Id int64 `json:"id"`
//订单状态
OrderStatue int `json:"orderStatue"`
//理由
Reason string `json:"reason"`
}
//UpdateOrderPurpose 更新意向订单
func (c *OrderController) UpdateOrderPurpose() {
//用与适配前端定义的数据结构
var (
param orderDetail
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
if param.Id == 0 {
err = c.addOrderPurpose(param)
} else {
err = c.editOrderPurpose(param)
}
if err != nil {
c.ResponseError(err)
}
c.ResponseData(nil)
return
}
func (c *OrderController) addOrderPurpose(param orderDetail) error {
orderSrv := orderService.NewOrderService(nil)
Createcmd := orderCmd.CreateOrderCommand{
//订单区域
OrderRegion: param.OrderDist,
//订单编号
OrderCode: param.OrderId,
//订单名称
OrderName: param.OrderName,
//数量
OrderCount: param.OrderNum,
OrderActualCount: param.OrderNum,
//订单金额
OrderAmount: param.OrderPrice,
OrderActualAmount: param.OrderPrice,
//买家
BuyerName: param.Buyer,
//买家电话
BuyerPhone: param.BuyerPhone,
//地址
BuyerAddress: param.Address,
//合伙人数据
PartnerId: param.Partner,
//合伙人分红百分比
PartnerBonusPercent: param.PartnerRatio,
//业务员分红百分比
SalesmanBonusPercent: param.SalesmanRatio,
//订单类型
OrderType: domain.OrderIntention,
OrderStatus: domain.OrderStatusReserve,
}
err := orderSrv.CreateOrder(Createcmd)
return err
}
func (c *OrderController) editOrderPurpose(param orderDetail) error {
updateCmd := orderCmd.UpdateOrderCommand{
Id: param.Id,
//订单区域
OrderRegion: param.OrderDist,
//订单编号
OrderCode: param.OrderId,
//订单名称
OrderName: param.OrderName,
//数量
OrderCount: param.OrderNum,
//订单金额
OrderAmount: param.OrderPrice,
//买家电话
BuyerPhone: param.BuyerPhone,
//地址
BuyerAddress: param.Address,
//合伙人分红百分比
PartnerBonusPercent: param.PartnerRatio,
//业务员分红百分比
SalesmanBonusPercent: param.SalesmanRatio,
OrderStatus: domain.OrderStatusReserve,
OrderType: domain.OrderIntention,
}
orderSrv := orderService.NewOrderService(nil)
err := orderSrv.UpdateOrderPurpose(updateCmd)
return err
}
//GetOrderPurpose 获取意向订单
func (c *OrderController) GetOrderPurpose() {
type Parameter struct {
Id string `json:"id"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
orderid, _ := strconv.ParseInt(param.Id, 10, 64)
orderSrv := orderService.NewOrderService(nil)
orderinfo, err := orderSrv.GetOrder(orderQuery.GetOrderQuery{
OrderId: orderid,
})
if err != nil {
c.ResponseError(err)
return
}
rsp := map[string]interface{}{
"createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),
"updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),
"buyer": orderinfo.Buyer.BuyerName,
"buyerPhone": orderinfo.Buyer.ContactInfo,
"address": orderinfo.Buyer.ShippingAddress,
"id": orderinfo.Id,
"partner": orderinfo.PartnerInfo.Id,
"partnerRatio": orderinfo.PartnerBonusPercent,
"salesmanRatio": orderinfo.SalesmanBonusPercent,
"orderId": orderinfo.OrderCode,
"orderName": orderinfo.OrderName,
"orderNum": orderinfo.OrderCount,
"orderPrice": orderinfo.OrderAmount,
"orderDist": orderinfo.OrderRegionInfo.RegionName,
"orderStatue": orderinfo.OrderStatus,
}
c.ResponseData(rsp)
}
//PageListOrderPurpose 分页获取意向订单列表
func (c *OrderController) PageListOrderPurpose() {
type Parameter struct {
SearchText string `json:"searchText"`
Partner int64 `json:"partner"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
if param.PageNumber == 0 {
param.PageNumber = 1
}
if param.PageSize == 0 {
param.PageSize = 20
}
orderSrv := orderService.NewOrderService(nil)
orderinfos, cnt, err := orderSrv.PageListOrder(orderQuery.ListOrderQuery{
PartnerId: param.Partner,
OrderCode: param.SearchText,
OrderType: domain.OrderIntention,
Limit: param.PageSize,
Offset: (param.PageNumber - 1) * param.PageSize,
})
if err != nil {
c.ResponseError(err)
return
}
rsp := []map[string]interface{}{}
for i := range orderinfos {
orderinfo := orderinfos[i]
m := map[string]interface{}{
"createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),
"updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),
"buyer": orderinfo.Buyer.BuyerName,
"id": orderinfo.Id,
"orderId": orderinfo.OrderCode,
"partner": orderinfo.PartnerInfo.PartnerName,
"partnerRatio": orderinfo.PartnerBonusPercent,
"orderName": orderinfo.OrderName,
"orderNum": orderinfo.OrderCount,
"orderPrice": orderinfo.OrderAmount,
"orderDist": orderinfo.OrderRegionInfo.RegionName,
"orderStatue": orderinfo.OrderStatus,
}
rsp = append(rsp, m)
}
c.ResponsePageList(rsp, cnt, param.PageNumber)
}
//RemoveOrderPurpose 删除意向订单
func (c *OrderController) RemoveOrderPurpose() {
type Parameter struct {
Id int64 `json:"id"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
orderSrv := orderService.NewOrderService(nil)
err = orderSrv.RemoveOrder(param.Id)
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
}
//PageListOrderReal 分页获取实发订单列表
func (c *OrderController) PageListOrderReal() {
type Parameter struct {
SearchText string `json:"searchText"`
Partner int64 `json:"partner"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
if param.PageNumber == 0 {
param.PageNumber = 1
}
if param.PageSize == 0 {
param.PageSize = 20
}
orderSrv := orderService.NewOrderService(nil)
orderinfos, cnt, err := orderSrv.PageListOrder(orderQuery.ListOrderQuery{
PartnerId: param.Partner,
OrderCode: param.SearchText,
OrderType: domain.OrderReal,
Limit: param.PageSize,
Offset: (param.PageNumber - 1) * param.PageSize,
})
if err != nil {
c.ResponseError(err)
return
}
rsp := []map[string]interface{}{}
for i := range orderinfos {
orderinfo := orderinfos[i]
m := map[string]interface{}{
"createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),
"updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),
"buyer": orderinfo.Buyer.BuyerName,
"id": orderinfo.Id,
"orderId": orderinfo.OrderCode,
"partner": orderinfo.PartnerInfo.PartnerName,
"partnerRatio": orderinfo.PartnerBonusPercent,
"orderName": orderinfo.OrderName,
"orderNum": orderinfo.OrderCount,
"orderPrice": orderinfo.OrderAmount,
"orderActualNum": orderinfo.OrderActualCount,
"orderActualPrice": orderinfo.OrderActualAmount,
"orderDist": orderinfo.OrderRegionInfo.RegionName,
"orderStatue": orderinfo.OrderStatus,
}
rsp = append(rsp, m)
}
c.ResponsePageList(rsp, cnt, param.PageNumber)
}
//UpdateOrderPurpose 意向订单转实发单
func (c *OrderController) OrderPurposeToReal() {
//用与适配前端定义的数据结构
var (
param orderDetail
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
orderSrv := orderService.NewOrderService(nil)
if param.Id > 0 {
err = orderSrv.UpdateOrderPurpose(orderCmd.UpdateOrderCommand{
Id: param.Id,
OrderCode: param.OrderId,
OrderName: param.OrderName,
OrderCount: param.OrderNum,
OrderAmount: param.OrderPrice,
BuyerPhone: param.BuyerPhone,
BuyerAddress: param.Address,
OrderRegion: param.OrderDist,
PartnerBonusPercent: param.PartnerRatio,
SalesmanBonusPercent: param.SalesmanRatio,
OrderStatus: param.OrderStatue,
OrderType: domain.OrderReal,
})
} else {
err = c.addOrderReal(param)
}
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
return
}
//GetOrderReal 获取实发单详情
func (c *OrderController) GetOrderReal() {
type Parameter struct {
Id string `json:"id"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
orderid, _ := strconv.ParseInt(param.Id, 10, 64)
orderSrv := orderService.NewOrderService(nil)
orderinfo, err := orderSrv.GetOrder(orderQuery.GetOrderQuery{
OrderId: orderid,
})
if err != nil {
c.ResponseError(err)
return
}
rsp := map[string]interface{}{
"createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),
"updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),
"buyer": orderinfo.Buyer.BuyerName,
"buyerPhone": orderinfo.Buyer.ContactInfo,
"address": orderinfo.Buyer.ShippingAddress,
"id": orderinfo.Id,
"partner": orderinfo.PartnerInfo.Id,
"partnerRatio": orderinfo.PartnerBonusPercent,
"salesmanRatio": orderinfo.SalesmanBonusPercent,
"orderId": orderinfo.OrderCode,
"orderName": orderinfo.OrderName,
"orderNum": orderinfo.OrderActualCount,
"orderPrice": orderinfo.OrderActualAmount,
"orderDist": orderinfo.OrderRegionInfo.RegionName,
"orderStatue": orderinfo.OrderStatus,
"reason": orderinfo.Reason,
}
c.ResponseData(rsp)
}
//UpdateOrderReal 更新实发订单数据
func (c *OrderController) UpdateOrderReal() {
//用与适配前端定义的数据结构
var (
param orderDetail
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
if param.Id == 0 {
err = c.addOrderReal(param)
} else {
err = c.editOrderReal(param)
}
if err != nil {
c.ResponseError(err)
}
c.ResponseData(nil)
return
}
//addOrderReal 添加实发订单
func (c *OrderController) addOrderReal(param orderDetail) error {
orderSrv := orderService.NewOrderService(nil)
if !(param.OrderStatue == domain.OrderStatusDeliverAll ||
param.OrderStatue == domain.OrderStatusDeliverSome) {
return lib.ThrowError(lib.ARG_ERROR, "订单状态错误")
}
Createcmd := orderCmd.CreateOrderCommand{
//订单区域
OrderRegion: param.OrderDist,
//订单编号
OrderCode: param.OrderId,
//订单名称
OrderName: param.OrderName,
//数量
OrderCount: param.OrderNum,
OrderActualCount: param.OrderNum,
//订单金额
OrderAmount: param.OrderPrice,
OrderActualAmount: param.OrderPrice,
//买家
BuyerName: param.Buyer,
//买家电话
BuyerPhone: param.BuyerPhone,
//地址
BuyerAddress: param.Address,
//合伙人数据
PartnerId: param.Partner,
//合伙人分红百分比
PartnerBonusPercent: param.PartnerRatio,
//业务员分红百分比
SalesmanBonusPercent: param.SalesmanRatio,
//订单类型
OrderType: domain.OrderReal,
//状态
OrderStatus: param.OrderStatue,
}
err := orderSrv.CreateOrder(Createcmd)
return err
}
//editOrderReal 更新实发订单
func (c *OrderController) editOrderReal(param orderDetail) error {
updateCmd := orderCmd.UpdateOrderRealCommand{
Id: param.Id,
//订单区域
OrderRegion: param.OrderDist,
//订单编号
OrderCode: param.OrderId,
//订单名称
OrderName: param.OrderName,
//数量
OrderActualCount: param.OrderNum,
//订单金额
OrderActualAmount: param.OrderPrice,
//买家电话
BuyerPhone: param.BuyerPhone,
//地址
BuyerAddress: param.Address,
//合伙人分红百分比
PartnerBonusPercent: param.PartnerRatio,
//业务员分红百分比
SalesmanBonusPercent: param.SalesmanRatio,
//状态
OrderStatus: param.OrderStatue,
//理由
Reason: param.Reason,
}
orderSrv := orderService.NewOrderService(nil)
err := orderSrv.UpdateOrderReal(updateCmd)
return err
}
package controllers
import (
"errors"
"fmt"
"strconv"
"github.com/astaxie/beego/logs"
orderCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/command"
orderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/query"
orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
//OrderDividendController 订单分红管理
type OrderDividendController struct {
BaseController
}
//Prepare 重写 BaseController 的Prepare方法
func (c *OrderDividendController) Prepare() {
c.BaseController.Prepare()
if ok := c.ValidJWTToken(); !ok {
return
}
if ok := c.ValidAdminPermission(domain.PERMISSION_DIVIDEND); !ok {
return
}
}
//PageListOrderDividend 获取实发订单分红列表
func (c *OrderDividendController) PageListOrderDividend() {
type Parameter struct {
SearchText string `json:"searchText"`
Partner int64 `json:"partner"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
if param.PageNumber == 0 {
param.PageNumber = 1
}
if param.PageSize == 0 {
param.PageSize = 20
}
orderSrv := orderService.NewOrderInfoService(nil)
orderinfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{
PartnerId: param.Partner,
DeliveryCode: param.SearchText,
OrderType: domain.OrderReal,
Limit: param.PageSize,
Offset: (param.PageNumber - 1) * param.PageSize,
})
if err != nil {
c.ResponseError(err)
return
}
rsp := []map[string]interface{}{}
for i := range orderinfos {
orderinfo := orderinfos[i]
m := map[string]interface{}{
"updateTime": orderinfo.UpdateTime.Local().Format("2006-01-02 15:04:05"),
"id": orderinfo.Id,
"shipmentsId": orderinfo.DeliveryCode,
"partner": orderinfo.PartnerInfo.PartnerName,
"dividendsReceivable": orderinfo.OrderCompute.PlanPartnerBonus,
"dividendSpending": orderinfo.OrderCompute.PartnerBonusExpense,
"receiveDividends": orderinfo.OrderCompute.PartnerBonusHas,
"uncollectedDividends": orderinfo.OrderCompute.PartnerBonusNot,
"stateOfPayment": orderinfo.BonusStatus,
}
if orderinfo.OrderCompute.UsePartnerBonus >= 0 {
m["dividendsReceivable"] = orderinfo.OrderCompute.UsePartnerBonus
}
rsp = append(rsp, m)
}
c.ResponsePageList(rsp, cnt, param.PageNumber)
return
}
//OrderDividendDetail 订单的分红详情
func (c *OrderDividendController) OrderDividendDetail() {
type Parameter struct {
Id string `json:"id"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
orderid, _ := strconv.ParseInt(param.Id, 10, 64)
if orderid == 0 {
c.ResponseError(errors.New("参数错误"))
return
}
orderSrv := orderService.NewOrderInfoService(nil)
orderinfo, err := orderSrv.GetOrderDetail(orderQuery.GetOrderQuery{
OrderId: orderid,
})
if err != nil {
c.ResponseError(err)
return
}
if orderinfo.OrderType != domain.OrderReal {
c.ResponseError(errors.New("参数错误"))
return
}
allGoods := []map[string]interface{}{}
for _, v := range orderinfo.Goods {
detail := map[string]interface{}{
"productName": v.GoodName,
"orderNum": v.PlanGoodNumber,
"univalence": v.Price,
"partnerRatio": v.PartnerBonusPercent,
"orderPrice": v.GoodCompute.PlanAmount,
"partnerDividendsReceivable": v.GoodCompute.PlanPartnerBonus,
}
m := map[string]interface{}{
"detail": detail,
"quantityControl": "",
"id": v.Id,
"stateOfPayment": v.BonusStatus,
"remark": v.Remark,
"amountControl": "",
"partnerDividendControl": "",
"receivedDividends": v.GoodCompute.PartnerBonusHas,
"notReceivedDividend": v.GoodCompute.PartnerBonusNot,
"dividendSpending": v.GoodCompute.PartnerBonusExpense,
}
if v.GoodCompute.UseAmount >= 0 {
m["amountControl"] = fmt.Sprint(v.GoodCompute.UseAmount)
}
if v.UseGoodNumber >= 0 {
m["quantityControl"] = fmt.Sprint(v.UseGoodNumber)
}
if v.GoodCompute.UsePartnerBonus >= 0 {
m["partnerDividendControl"] = fmt.Sprint(v.GoodCompute.UsePartnerBonus)
}
allGoods = append(allGoods, m)
}
orderData := map[string]interface{}{
"buyer": orderinfo.Buyer.BuyerName,
"shipmentsId": orderinfo.DeliveryCode,
"orderDist": orderinfo.RegionInfo.RegionName,
"partner": orderinfo.PartnerInfo.PartnerName,
"id": orderinfo.Id,
"orderId": orderinfo.OrderCode,
}
dividendCount := map[string]interface{}{
"orderNum": orderinfo.OrderCompute.PlanOrderCount,
"orderAmountAdjustment": orderinfo.OrderCompute.PlanOrderAmount,
"orderNumControl": "",
"orderAmountAdjustmentControl": "",
"partnerDividends": orderinfo.OrderCompute.PlanPartnerBonus,
"partnerDividendsControl": "",
"receivedDividends": orderinfo.OrderCompute.PartnerBonusHas,
"notReceivedDividend": orderinfo.OrderCompute.PartnerBonusNot,
"dividendSpending": orderinfo.OrderCompute.PartnerBonusExpense,
"commissionProportion": orderinfo.SalesmanBonusPercent,
"expectedCommission": orderinfo.OrderCompute.SalesmanBonus,
}
if orderinfo.OrderCompute.UseOrderAmount >= 0 {
dividendCount["orderAmountAdjustmentControl"] = fmt.Sprint(orderinfo.OrderCompute.UseOrderAmount)
}
if orderinfo.OrderCompute.UsePartnerBonus >= 0 {
dividendCount["partnerDividendsControl"] = fmt.Sprint(orderinfo.OrderCompute.UsePartnerBonus)
}
if orderinfo.OrderCompute.UseOrderCount >= 0 {
dividendCount["orderNumControl"] = fmt.Sprint(orderinfo.OrderCompute.UseOrderCount)
}
rsp := map[string]interface{}{
"order": orderData,
"product": allGoods,
"dividendCount": dividendCount,
"operationTime": orderinfo.UpdateTime.Local().Format("2006-01-02 15:04:06"),
}
if orderinfo.OrderCompute.UseOrderAmount >= 0 {
rsp["orderNumCountControl"] = fmt.Sprint(orderinfo.OrderCompute.UseOrderAmount)
}
if orderinfo.OrderCompute.UseOrderCount >= 0 {
rsp["orderAmountAdjustmentCountControl"] = fmt.Sprint(orderinfo.OrderCompute.UseOrderCount)
}
c.ResponseData(rsp)
return
}
type postOrderDividend struct {
Id int64 `json:"id"`
DividendPayments []postDividendPayment `json:"dividendPayment"`
}
type postDividendPayment struct {
QuantityControl string `json:"quantityControl"`
StateOfPayment int `json:"stateOfPayment"`
ProductId int64 `json:"productId"`
Remark string `json:"remark"`
}
func (c *OrderDividendController) EditOrderDividend() {
var (
param postOrderDividend
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
if param.Id == 0 {
c.ResponseError(errors.New("参数错误"))
return
}
goodbouns := []orderCmd.GoodBouns{}
for _, v := range param.DividendPayments {
if v.ProductId == 0 {
c.ResponseError(errors.New("参数错误"))
return
}
if !(v.StateOfPayment == domain.OrderGoodWaitPay || v.StateOfPayment == domain.OrderGoodHasPay) {
c.ResponseError(errors.New("参数错误"))
return
}
g := orderCmd.GoodBouns{
GoodId: v.ProductId,
Remark: v.Remark,
BounsStatus: v.StateOfPayment,
}
if len(v.QuantityControl) == 0 {
g.UseGoodNumber = -1
} else {
num, err := strconv.Atoi(v.QuantityControl)
if err != nil {
c.ResponseError(errors.New("参数错误"))
return
}
g.UseGoodNumber = num
}
goodbouns = append(goodbouns, g)
}
cmd := orderCmd.UpdateGoodBouns{
Id: param.Id,
GoodBouns: goodbouns,
}
orderSrv := orderService.NewOrderInfoService(nil)
err = orderSrv.UpdateGoodBouns(cmd)
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
return
}
... ...