作者 唐旭辉

更新

... ... @@ -901,76 +901,6 @@ func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrde
return resp, cnt, nil
}
//UpdateBounsWithGoodNumber 分红时,因修改订单中商品的数量发生分红变动
func (service OrderInfoService) UpdateBonusByGoodNumber(orderId int64, goodId int64, adminId int64, goodNumber int, reason string) error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var (
orderBonuSrv domainService.OrderBonusService
)
orderBonuSrv, err = factory.CreateOrderBonusService(map[string]interface{}{
"transactionContext": transactionContext,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
orderBonuSrv.Subscribe(&subscriber.OrderLogSubscriber{
TransactionContext: transactionContext.(*transaction.TransactionContext),
})
err = orderBonuSrv.UpdateBounsByGoodNumber(orderId, adminId, goodId, goodNumber, reason)
if err != nil {
return err
}
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
//UpdateBounsByPartnerBonusPercent 分红时,因修改订单中商品的合伙人分行比例发生分红变动
func (service OrderInfoService) UpdateBonusByPartnerBonusPercent(orderId int64, goodId int64, adminId int64, percent float64, reason string) error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var (
orderBonuSrv domainService.OrderBonusService
)
orderBonuSrv, err = factory.CreateOrderBonusService(map[string]interface{}{
"transactionContext": transactionContext,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
orderBonuSrv.Subscribe(&subscriber.OrderLogSubscriber{
TransactionContext: transactionContext.(*transaction.TransactionContext),
})
err = orderBonuSrv.UpdateBounsByPartnerBonusPercent(orderId, adminId, goodId, percent, reason)
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
}
//PayPartnerBonusWithOrderBestshop 支付分红,海鲜干货的订单 (orderType=domain.OrderTypeBestShop)
func (service OrderInfoService) PayPartnerBonusWithOrderBestshop(orderId int64, goodId int64, adminId int64) error {
var (
... ...
... ... @@ -5,8 +5,11 @@ import (
"strings"
"github.com/astaxie/beego/logs"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/event/subscriber"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
domainService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
... ... @@ -431,3 +434,73 @@ func (service OrderInfoService) buildOrderBestshopInfoData(orderBase *domain.Ord
}
return result
}
//UpdateBounsWithGoodNumber 分红时,因修改订单中商品的数量发生分红变动
func (service OrderInfoService) UpdateBonusByGoodNumber(orderId int64, goodId int64, adminId int64, goodNumber int, reason string) error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var (
orderBonuSrv domainService.OrderBonusService
)
orderBonuSrv, err = factory.CreateOrderBonusService(map[string]interface{}{
"transactionContext": transactionContext,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
orderBonuSrv.Subscribe(&subscriber.OrderLogSubscriber{
TransactionContext: transactionContext.(*transaction.TransactionContext),
})
err = orderBonuSrv.UpdateBounsByGoodNumber(orderId, adminId, goodId, goodNumber, reason)
if err != nil {
return err
}
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
//UpdateBounsByPartnerBonusPercent 分红时,因修改订单中商品的合伙人分行比例发生分红变动
func (service OrderInfoService) UpdateBonusByPartnerBonusPercent(orderId int64, goodId int64, adminId int64, percent float64, reason string) error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var (
orderBonuSrv domainService.OrderBonusService
)
orderBonuSrv, err = factory.CreateOrderBonusService(map[string]interface{}{
"transactionContext": transactionContext,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
orderBonuSrv.Subscribe(&subscriber.OrderLogSubscriber{
TransactionContext: transactionContext.(*transaction.TransactionContext),
})
err = orderBonuSrv.UpdateBounsByPartnerBonusPercent(orderId, adminId, goodId, percent, reason)
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
}
... ...
... ... @@ -182,18 +182,16 @@ func (order *OrderBase) AddGoods(goods []OrderGood) {
order.Compute()
}
// func (order *OrderBase) DeleteGoods(goodIds []int64) {
// var newGoods []OrderGood
// for i := range order.Goods {
// for _, goodId := range goodIds {
// order.Goods[i].Id = goodId
// continue
// }
// newGoods = append(newGoods, order.Goods[i])
// }
// order.Goods = newGoods
// order.Compute()
// }
func (order *OrderBase) ModifyGoodNumber(goodid int64, number int64) {
for i := range order.Goods {
if order.Goods[i].Id != goodid {
continue
}
// thisGood := order.Goods[i]
}
order.Compute()
}
//Compute 数据汇总核算
func (order *OrderBase) Compute() error {
... ...
... ... @@ -13,9 +13,9 @@ type OrderGoodBonusStatus interface {
//状态变更为已支付
PayPartnerBonus(orderGood *OrderGood) error
//变更货品数量
/// UpdateOrderGoodNumber(good *OrderGood, number int, orderType int) error
ModifyOrderGoodNumber(good *OrderGood, number int, orderType int) error
//变更合伙人分红比例
//UpdatePertnerBonusPercent(good *OrderGood, percent float64, orderType int) error
ModifyPertnerBonusPercent(good *OrderGood, percent float64, orderType int) error
}
//货单的支付状态
... ... @@ -110,6 +110,17 @@ func (good OrderGood) GetCurrentPartnerBonus() float64 {
return good.GoodCompute.PlanPartnerBonus
}
//GetCurrentAmount 获取当前的商品合伙人分红
func (good *OrderGood) ModifyOrderGoodNumber(number int, orderType int) error {
err := good.CurrentBonusStatus.ModifyOrderGoodNumber(good, number, orderType)
return err
}
func (good *OrderGood) ModifyPertnerBonusPercent(percent float64, orderType int) error {
err := good.CurrentBonusStatus.ModifyPertnerBonusPercent(good, percent, orderType)
return err
}
//Update 更新商品相关的数据
func (good *OrderGood) Update(m map[string]interface{}) error {
if v, ok := m["GoodName"]; ok {
... ... @@ -199,6 +210,68 @@ func (hasPay OrderGoodBonusHasPay) WartPayPartnerBonus(good *OrderGood) error {
return errors.New("已支付的货单不能将状态回退为待支付")
}
func (hasPay OrderGoodBonusHasPay) ModifyOrderGoodNumber(good *OrderGood, number int, orderType int) error {
//规则描述:
//实际自建订单(orderType==1),已支付分红状态下“可以”修改货品数量
//香米小程序订单(orderType==3),已支付分红状态下“不可以”修改货品数量
switch orderType {
case OrderReal:
good.UseGoodNumber = number
//待支付状态计算
err := good.Compute()
if err != nil {
return errors.New("核算商品数据失败" + err.Error())
}
case OrderTypeBestShop:
return errors.New("小程序订单里已支付分红的货品订单,不能修改货品数量")
}
good.CurrentBonusStatus.PayPartnerBonus(good)
return nil
}
func (waitPay OrderGoodBonusWaitPay) ModifyOrderGoodNumber(good *OrderGood, number int, orderType int) error {
//规则描述:
//实际自建订单(orderType==1),未支付分红状态下“可以”修改货品数量
//香米小程序订单(orderType==3),未支付分红状态下“可以”修改货品数量
good.UseGoodNumber = number
//待支付状态计算
err := good.Compute()
if err != nil {
return errors.New("核算商品数据失败" + err.Error())
}
good.CurrentBonusStatus.WartPayPartnerBonus(good)
return nil
}
func (waitPay OrderGoodBonusWaitPay) ModifyPertnerBonusPercent(good *OrderGood, percent float64, orderType int) error {
//规则描述:
//实际自建订单(orderType==1),未支付分红状态下“不可以”修改合伙人分红比例
//香米小程序订单(orderType==3),未支付分红状态下“可以”修改合伙人分红比例
switch orderType {
case OrderReal:
return errors.New("自建订单不能修改合伙人分红比例")
case OrderTypeBestShop:
good.PartnerBonusPercent = percent
//待支付状态计算
err := good.Compute()
if err != nil {
return errors.New("核算商品数据失败" + err.Error())
}
err = good.CurrentBonusStatus.WartPayPartnerBonus(good)
if err != nil {
return errors.New("核算商品数据失败" + err.Error())
}
}
return nil
}
func (hasPay OrderGoodBonusHasPay) ModifyPertnerBonusPercent(good *OrderGood, percent float64, orderType int) error {
//规则描述:
//实际自建订单(orderType==1),已支付分红状态下“不可以”修改合伙人分红比例
//香米小程序订单(orderType==3),已支付分红状态下“不可以”修改合伙人分红比例
return errors.New("已支付分红的货品订单,不能修改合伙人分红比例")
}
//NewOrderGood 初始值设定
func NewOrderGood() OrderGood {
return OrderGood{
... ...
... ... @@ -28,7 +28,6 @@ func NewOrderBonusService(tcx *transaction.TransactionContext) *OrderBonusServic
}
//UpdateBounsWithGoodNumber 分红时,因修改订单中商品的数量发生分红变动
//目前只处理 xiangmi的订单 即 order_type = OrderTypeBestShop (3)
func (serve *OrderBonusService) UpdateBounsByGoodNumber(orderId int64, adminId int64, goodId int64, goodWithNumber int, reason string) error {
var (
userRepository domain.UsersRepository
... ... @@ -52,9 +51,6 @@ func (serve *OrderBonusService) UpdateBounsByGoodNumber(orderId int64, adminId i
e := fmt.Sprintf("获取订单(id=%d)数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
if oldOrder.OrderType != domain.OrderTypeBestShop {
return lib.ThrowError(lib.BUSINESS_ERROR, "订单类型错误")
}
oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单(id=%d)中的货品数据失败,%s", orderId, err)
... ... @@ -82,8 +78,13 @@ func (serve *OrderBonusService) UpdateBounsByGoodNumber(orderId int64, adminId i
updateGood = oldOrder.Goods[i]
formerNumber = updateGood.GetCurrentGoodNumber()
formerAmount = updateGood.GetCurrentAmount()
err := new(domain.OrderGoodWithBestshop).
UpdateBonusByGoodNumber(&updateGood, goodWithNumber)
//TODO
// err := new(domain.OrderGoodWithBestshop).
// UpdateBonusByGoodNumber(&updateGood, goodWithNumber)
// if err != nil {
// return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
// }
err = updateGood.ModifyOrderGoodNumber(goodWithNumber, oldOrder.OrderType)
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
... ... @@ -128,7 +129,6 @@ func (serve *OrderBonusService) UpdateBounsByGoodNumber(orderId int64, adminId i
}
//UpdateBounsByPartnerBonusPercent 分红时,因修改订单中商品的合伙人分行比例发生分红变动
////目前只处理 xiangmi的订单 即 order_type = OrderTypeBestShop (3)
func (serve *OrderBonusService) UpdateBounsByPartnerBonusPercent(orderId int64, adminId int64, goodId int64, partnerPercent float64, reason string) error {
var (
userRepository domain.UsersRepository
... ... @@ -152,9 +152,7 @@ func (serve *OrderBonusService) UpdateBounsByPartnerBonusPercent(orderId int64,
e := fmt.Sprintf("获取订单(id=%d)数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
if oldOrder.OrderType != domain.OrderTypeBestShop {
return lib.ThrowError(lib.BUSINESS_ERROR, "订单类型错误")
}
oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单中(id=%d)的货品数据失败,%s", orderId, err)
... ... @@ -182,8 +180,10 @@ func (serve *OrderBonusService) UpdateBounsByPartnerBonusPercent(orderId int64,
updateGood = oldOrder.Goods[i]
formerPartnerBonusPercent = updateGood.PartnerBonusPercent
formerPartnerBonus = updateGood.GetCurrentPartnerBonus()
err := new(domain.OrderGoodWithBestshop).
UpdateBonusByPertnerBonusPercent(&updateGood, partnerPercent)
// err := new(domain.OrderGoodWithBestshop).
// UpdateBonusByPertnerBonusPercent(&updateGood, partnerPercent)
err = updateGood.ModifyPertnerBonusPercent(partnerPercent, oldOrder.OrderType)
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
... ...
... ... @@ -6,7 +6,6 @@ import (
"time"
"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"
... ... @@ -262,63 +261,63 @@ type postDividendPayment struct {
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
}
// 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)
}
companyId := c.GetUserCompany()
cmd := orderCmd.UpdateGoodBouns{
Id: param.Id,
GoodBouns: goodbouns,
CompanyId: companyId,
}
orderSrv := orderService.NewOrderInfoService(nil)
err = orderSrv.UpdateGoodBouns(cmd)
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
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)
// }
// companyId := c.GetUserCompany()
// cmd := orderCmd.UpdateGoodBouns{
// Id: param.Id,
// GoodBouns: goodbouns,
// CompanyId: companyId,
// }
// orderSrv := orderService.NewOrderInfoService(nil)
// err = orderSrv.UpdateGoodBouns(cmd)
// if err != nil {
// c.ResponseError(err)
// return
// }
// c.ResponseData(nil)
// return
// }
//OrderDividendDetailForBestshop 海鲜干货的订单分红详情
func (c *OrderDividendController) OrderDividendDetailForBestshop() {
... ... @@ -350,8 +349,8 @@ func (c *OrderDividendController) OrderDividendDetailForBestshop() {
return
}
//EditOrderForBestshop 编辑海鲜干货的订单 中的 货品数量和分红比例
func (c *OrderDividendController) EditOrderDividendForBestshop() {
//EditOrderForBestshop 编辑订单分红详情中的 货品数量和分红比例
func (c *OrderDividendController) EditOrderDividend() {
type Parameter struct {
State int `json:"state"`
OrderId string `json:"orderId"`
... ...
... ... @@ -27,10 +27,10 @@ func init() {
),
beego.NSNamespace("/dividends",
beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"),
beego.NSRouter("/edit", &controllers.OrderDividendController{}, "POST:EditOrderDividend"),
beego.NSRouter("/modify", &controllers.OrderDividendController{}, "POST:EditOrderDividend"),
beego.NSRouter("/detail", &controllers.OrderDividendController{}, "POST:OrderDividendDetail"),
// beego.NSRouter("/mini-program/detail", &controllers.OrderDividendController{}, "POST:OrderDividendDetailForBestshop"),
beego.NSRouter("/mini-program/modify", &controllers.OrderDividendController{}, "POST:EditOrderDividendForBestshop"),
//beego.NSRouter("/mini-program/modify", &controllers.OrderDividendController{}, "POST:EditOrderDividendForBestshop"),
beego.NSRouter("/mini-program/payDividends", &controllers.OrderDividendController{}, "POST:PayOrderGoodBonusForBestshop"),
beego.NSRouter("/mini-program/remarks", &controllers.OrderDividendController{}, "POST:EditOrderRemarkBonusForBestshop"),
beego.NSRouter("/list/excel", &controllers.OrderDividendController{}, "POST:ListOrderBonusForExcel"),
... ...