作者 tangxvhui

更新:新增分红编辑

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"`
}
... ...
... ... @@ -528,3 +528,97 @@ func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand)
}
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("货品的支付状态错误"))
}
}
}
//变更订单类型
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
}
... ...
... ... @@ -106,8 +106,14 @@ func (order *OrderBase) Compute() error {
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
... ...
... ... @@ -92,6 +92,7 @@ func (waitPay OrderGoodBonusWaitPay) WartPayPartnerBonus(good *OrderGood) error
//数量有调整,未收等于调整后的应收分红
good.GoodCompute.PartnerBonusNot = good.GoodCompute.UsePartnerBonus
}
good.CurrentBonusStatus = OrderGoodBonusWaitPay{}
return nil
}
... ... @@ -108,6 +109,7 @@ func (waitPay OrderGoodBonusWaitPay) PayPartnerBonus(good *OrderGood) error {
}
good.GoodCompute.PartnerBonusExpense = 0
good.GoodCompute.PartnerBonusNot = 0
good.CurrentBonusStatus = OrderGoodBonusHasPay{}
return nil
}
... ... @@ -120,6 +122,7 @@ func (hasPay OrderGoodBonusHasPay) PayPartnerBonus(good *OrderGood) error {
//有数量调整,分红支出等于 已支付分红-调整后的已收分红
good.GoodCompute.PartnerBonusExpense = good.GoodCompute.PartnerBonusHas - good.GoodCompute.UsePartnerBonus
}
good.CurrentBonusStatus = OrderGoodBonusHasPay{}
return nil
}
... ...
... ... @@ -6,6 +6,7 @@ import (
"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"
... ... @@ -76,6 +77,7 @@ func (c *OrderDividendController) PageListOrderDividend() {
"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
... ... @@ -135,6 +137,7 @@ func (c *OrderDividendController) OrderDividendDetail() {
"stateOfPayment": v.BonusStatus,
"remark": v.Remark,
"amountControl": "",
"partnerDividendControl": "",
}
if v.GoodCompute.UseAmount >= 0 {
m["amountControl"] = fmt.Sprint(v.GoodCompute.UseAmount)
... ... @@ -142,6 +145,9 @@ func (c *OrderDividendController) OrderDividendDetail() {
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{}{
... ... @@ -194,8 +200,12 @@ type postOrderDividend struct {
Id string `json:"id"`
DividendPayments []postDividendPayment `json:"dividendPayment"`
}
type postDividendPayment struct {
QuantityControl string `json:"quantityControl"`
StateOfPayment string `json:"stateOfPayment"`
ProductId string `json:"productId"`
Remark string `json:"remark"`
}
func (c *OrderDividendController) EditOrderDividend() {
... ... @@ -208,5 +218,50 @@ func (c *OrderDividendController) EditOrderDividend() {
c.ResponseError(errors.New("json数据解析失败"))
return
}
orderId, _ := strconv.ParseInt(param.Id, 10, 64)
if orderId == 0 {
c.ResponseError(errors.New("参数错误"))
return
}
goodbouns := []orderCmd.GoodBouns{}
for _, v := range param.DividendPayments {
goodId, _ := strconv.ParseInt(v.ProductId, 10, 64)
if goodId == 0 {
c.ResponseError(errors.New("参数错误"))
return
}
bounsStatus, _ := strconv.Atoi(v.StateOfPayment)
if !(bounsStatus == domain.OrderGoodWaitPay || bounsStatus == domain.OrderGoodHasPay) {
c.ResponseError(errors.New("参数错误"))
return
}
g := orderCmd.GoodBouns{
GoodId: goodId,
Remark: v.Remark,
BounsStatus: bounsStatus,
}
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: orderId,
GoodBouns: goodbouns,
}
orderSrv := orderService.NewOrderInfoService(nil)
err = orderSrv.UpdateGoodBouns(cmd)
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
return
}
... ...
... ... @@ -170,7 +170,6 @@ type postPurposeOrderDetail struct {
BuyerName string `json:"buyer"`
//对应合伙人 id
PartnerId int64 `json:"partnerID"`
//业务员抽成比例
CommissionProportion float64 `json:"commissionProportion"`
//订单区域
... ...
... ... @@ -29,7 +29,7 @@ func init() {
),
beego.NSNamespace("/dividends",
beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"),
// beego.NSRouter("/edit", &controllers.DividendsController{}, "POST:Edit"),
beego.NSRouter("/edit", &controllers.OrderDividendController{}, "POST:EditOrderDividend"),
beego.NSRouter("/detail", &controllers.OrderDividendController{}, "POST:OrderDividendDetail"),
),
beego.NSNamespace("/order",
... ...