正在显示
7 个修改的文件
包含
180 行增加
和
8 行删除
1 | +package command | ||
2 | + | ||
3 | +//更新订单的商品数字并更新分红的数据 | ||
4 | +type UpdateGoodBouns struct { | ||
5 | + Id int64 `json:"id"` //订单id | ||
6 | + GoodBouns []GoodBouns `json:"goodBouns"` | ||
7 | +} | ||
8 | + | ||
9 | +//GoodBoun 商品数量调整 | ||
10 | +type GoodBouns struct { | ||
11 | + GoodId int64 `json:"goodId"` //货品id | ||
12 | + UseGoodNumber int `json:"useGoodNumber"` //货品数量调整的数值 | ||
13 | + Remark string `json:"remark"` //原因 | ||
14 | + BounsStatus int `json:"BounsStatus"` | ||
15 | +} |
@@ -528,3 +528,97 @@ func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand) | @@ -528,3 +528,97 @@ func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand) | ||
528 | } | 528 | } |
529 | return nil | 529 | return nil |
530 | } | 530 | } |
531 | + | ||
532 | +//UpdateGoodBouns 更新货品的分红相关的数值 | ||
533 | +func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) error { | ||
534 | + var ( | ||
535 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
536 | + err error | ||
537 | + ) | ||
538 | + if err = transactionContext.StartTransaction(); err != nil { | ||
539 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
540 | + } | ||
541 | + defer func() { | ||
542 | + transactionContext.RollbackTransaction() | ||
543 | + }() | ||
544 | + var ( | ||
545 | + orderBaseRepository domain.OrderBaseRepository | ||
546 | + orderGoodRepository domain.OrderGoodRepository | ||
547 | + oldOrderData *domain.OrderBase | ||
548 | + oldOrderGoods []domain.OrderGood | ||
549 | + ) | ||
550 | + if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{ | ||
551 | + "transactionContext": transactionContext, | ||
552 | + }); err != nil { | ||
553 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
554 | + } | ||
555 | + if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{ | ||
556 | + "transactionContext": transactionContext, | ||
557 | + }); err != nil { | ||
558 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
559 | + } | ||
560 | + //获取旧的订单 | ||
561 | + oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{ | ||
562 | + OrderId: cmd.Id, | ||
563 | + }) | ||
564 | + if err != nil { | ||
565 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err)) | ||
566 | + } | ||
567 | + if oldOrderData.OrderType != domain.OrderReal { | ||
568 | + return lib.ThrowError(lib.BUSINESS_ERROR, fmt.Sprintf("指定的订单的订单类型发生变更")) | ||
569 | + } | ||
570 | + //获取旧的订单中的商品 | ||
571 | + oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{ | ||
572 | + OrderId: cmd.Id, | ||
573 | + }) | ||
574 | + if err != nil { | ||
575 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err)) | ||
576 | + } | ||
577 | + for _, newGood := range cmd.GoodBouns { | ||
578 | + for i := range oldOrderGoods { | ||
579 | + if newGood.GoodId != oldOrderGoods[i].Id { | ||
580 | + continue | ||
581 | + } | ||
582 | + oldOrderGoods[i].UseGoodNumber = newGood.UseGoodNumber | ||
583 | + oldOrderGoods[i].Remark = newGood.Remark | ||
584 | + oldOrderGoods[i].BonusStatus = newGood.BounsStatus | ||
585 | + err = oldOrderGoods[i].Compute() | ||
586 | + if err != nil { | ||
587 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err)) | ||
588 | + } | ||
589 | + switch newGood.BounsStatus { | ||
590 | + case domain.OrderGoodWaitPay: | ||
591 | + err = oldOrderGoods[i].CurrentBonusStatus.WartPayPartnerBonus(&oldOrderGoods[i]) | ||
592 | + if err != nil { | ||
593 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err)) | ||
594 | + } | ||
595 | + case domain.OrderGoodHasPay: | ||
596 | + err = oldOrderGoods[i].CurrentBonusStatus.PayPartnerBonus(&oldOrderGoods[i]) | ||
597 | + if err != nil { | ||
598 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err)) | ||
599 | + } | ||
600 | + default: | ||
601 | + return lib.ThrowError(lib.ARG_ERROR, fmt.Sprintf("货品的支付状态错误")) | ||
602 | + } | ||
603 | + } | ||
604 | + } | ||
605 | + //变更订单类型 | ||
606 | + err = oldOrderData.Compute() | ||
607 | + if err != nil { | ||
608 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err)) | ||
609 | + } | ||
610 | + err = orderBaseRepository.Save(oldOrderData) | ||
611 | + if err != nil { | ||
612 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err)) | ||
613 | + } | ||
614 | + err = orderGoodRepository.Save(oldOrderGoods) | ||
615 | + if err != nil { | ||
616 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err)) | ||
617 | + } | ||
618 | + err = transactionContext.CommitTransaction() | ||
619 | + if err != nil { | ||
620 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
621 | + } | ||
622 | + return nil | ||
623 | + | ||
624 | +} |
@@ -106,8 +106,14 @@ func (order *OrderBase) Compute() error { | @@ -106,8 +106,14 @@ func (order *OrderBase) Compute() error { | ||
106 | partnerBonusHas := decimal.NewFromFloat(0) | 106 | partnerBonusHas := decimal.NewFromFloat(0) |
107 | partnerBonusNot := decimal.NewFromFloat(0) | 107 | partnerBonusNot := decimal.NewFromFloat(0) |
108 | partnerBonusExpense := decimal.NewFromFloat(0) | 108 | partnerBonusExpense := decimal.NewFromFloat(0) |
109 | + //初始订单的支付状态 | ||
110 | + order.BonusStatus = OrderGoodWaitPay | ||
109 | //统计所以货品的值 | 111 | //统计所以货品的值 |
110 | for i := range order.Goods { | 112 | for i := range order.Goods { |
113 | + if order.Goods[i].BonusStatus == OrderGoodHasPay { | ||
114 | + //确定订单的支付状态 | ||
115 | + order.BonusStatus = OrderGoodHasPay | ||
116 | + } | ||
111 | planPartnerBonus = planPartnerBonus.Add(decimal.NewFromFloat(order.Goods[i].GoodCompute.PlanPartnerBonus)) | 117 | planPartnerBonus = planPartnerBonus.Add(decimal.NewFromFloat(order.Goods[i].GoodCompute.PlanPartnerBonus)) |
112 | planOrderAmount = planOrderAmount.Add(decimal.NewFromFloat(order.Goods[i].GoodCompute.PlanAmount)) | 118 | planOrderAmount = planOrderAmount.Add(decimal.NewFromFloat(order.Goods[i].GoodCompute.PlanAmount)) |
113 | planOrderCount += order.Goods[i].PlanGoodNumber | 119 | planOrderCount += order.Goods[i].PlanGoodNumber |
@@ -92,6 +92,7 @@ func (waitPay OrderGoodBonusWaitPay) WartPayPartnerBonus(good *OrderGood) error | @@ -92,6 +92,7 @@ func (waitPay OrderGoodBonusWaitPay) WartPayPartnerBonus(good *OrderGood) error | ||
92 | //数量有调整,未收等于调整后的应收分红 | 92 | //数量有调整,未收等于调整后的应收分红 |
93 | good.GoodCompute.PartnerBonusNot = good.GoodCompute.UsePartnerBonus | 93 | good.GoodCompute.PartnerBonusNot = good.GoodCompute.UsePartnerBonus |
94 | } | 94 | } |
95 | + good.CurrentBonusStatus = OrderGoodBonusWaitPay{} | ||
95 | return nil | 96 | return nil |
96 | } | 97 | } |
97 | 98 | ||
@@ -108,6 +109,7 @@ func (waitPay OrderGoodBonusWaitPay) PayPartnerBonus(good *OrderGood) error { | @@ -108,6 +109,7 @@ func (waitPay OrderGoodBonusWaitPay) PayPartnerBonus(good *OrderGood) error { | ||
108 | } | 109 | } |
109 | good.GoodCompute.PartnerBonusExpense = 0 | 110 | good.GoodCompute.PartnerBonusExpense = 0 |
110 | good.GoodCompute.PartnerBonusNot = 0 | 111 | good.GoodCompute.PartnerBonusNot = 0 |
112 | + good.CurrentBonusStatus = OrderGoodBonusHasPay{} | ||
111 | return nil | 113 | return nil |
112 | } | 114 | } |
113 | 115 | ||
@@ -120,6 +122,7 @@ func (hasPay OrderGoodBonusHasPay) PayPartnerBonus(good *OrderGood) error { | @@ -120,6 +122,7 @@ func (hasPay OrderGoodBonusHasPay) PayPartnerBonus(good *OrderGood) error { | ||
120 | //有数量调整,分红支出等于 已支付分红-调整后的已收分红 | 122 | //有数量调整,分红支出等于 已支付分红-调整后的已收分红 |
121 | good.GoodCompute.PartnerBonusExpense = good.GoodCompute.PartnerBonusHas - good.GoodCompute.UsePartnerBonus | 123 | good.GoodCompute.PartnerBonusExpense = good.GoodCompute.PartnerBonusHas - good.GoodCompute.UsePartnerBonus |
122 | } | 124 | } |
125 | + good.CurrentBonusStatus = OrderGoodBonusHasPay{} | ||
123 | return nil | 126 | return nil |
124 | } | 127 | } |
125 | 128 |
@@ -6,6 +6,7 @@ import ( | @@ -6,6 +6,7 @@ import ( | ||
6 | "strconv" | 6 | "strconv" |
7 | 7 | ||
8 | "github.com/astaxie/beego/logs" | 8 | "github.com/astaxie/beego/logs" |
9 | + orderCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/command" | ||
9 | orderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/query" | 10 | orderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/query" |
10 | orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/service" | 11 | orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/service" |
11 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | 12 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" |
@@ -76,6 +77,7 @@ func (c *OrderDividendController) PageListOrderDividend() { | @@ -76,6 +77,7 @@ func (c *OrderDividendController) PageListOrderDividend() { | ||
76 | "dividendSpending": orderinfo.OrderCompute.PartnerBonusExpense, | 77 | "dividendSpending": orderinfo.OrderCompute.PartnerBonusExpense, |
77 | "receiveDividends": orderinfo.OrderCompute.PartnerBonusHas, | 78 | "receiveDividends": orderinfo.OrderCompute.PartnerBonusHas, |
78 | "uncollectedDividends": orderinfo.OrderCompute.PartnerBonusNot, | 79 | "uncollectedDividends": orderinfo.OrderCompute.PartnerBonusNot, |
80 | + "stateOfPayment": orderinfo.BonusStatus, | ||
79 | } | 81 | } |
80 | if orderinfo.OrderCompute.UsePartnerBonus >= 0 { | 82 | if orderinfo.OrderCompute.UsePartnerBonus >= 0 { |
81 | m["dividendsReceivable"] = orderinfo.OrderCompute.UsePartnerBonus | 83 | m["dividendsReceivable"] = orderinfo.OrderCompute.UsePartnerBonus |
@@ -129,12 +131,13 @@ func (c *OrderDividendController) OrderDividendDetail() { | @@ -129,12 +131,13 @@ func (c *OrderDividendController) OrderDividendDetail() { | ||
129 | "partnerDividendsReceivable": v.GoodCompute.PlanPartnerBonus, | 131 | "partnerDividendsReceivable": v.GoodCompute.PlanPartnerBonus, |
130 | } | 132 | } |
131 | m := map[string]interface{}{ | 133 | m := map[string]interface{}{ |
132 | - "detail": detail, | ||
133 | - "quantityControl": "", | ||
134 | - "id": v.Id, | ||
135 | - "stateOfPayment": v.BonusStatus, | ||
136 | - "remark": v.Remark, | ||
137 | - "amountControl": "", | 134 | + "detail": detail, |
135 | + "quantityControl": "", | ||
136 | + "id": v.Id, | ||
137 | + "stateOfPayment": v.BonusStatus, | ||
138 | + "remark": v.Remark, | ||
139 | + "amountControl": "", | ||
140 | + "partnerDividendControl": "", | ||
138 | } | 141 | } |
139 | if v.GoodCompute.UseAmount >= 0 { | 142 | if v.GoodCompute.UseAmount >= 0 { |
140 | m["amountControl"] = fmt.Sprint(v.GoodCompute.UseAmount) | 143 | m["amountControl"] = fmt.Sprint(v.GoodCompute.UseAmount) |
@@ -142,6 +145,9 @@ func (c *OrderDividendController) OrderDividendDetail() { | @@ -142,6 +145,9 @@ func (c *OrderDividendController) OrderDividendDetail() { | ||
142 | if v.UseGoodNumber >= 0 { | 145 | if v.UseGoodNumber >= 0 { |
143 | m["quantityControl"] = fmt.Sprint(v.UseGoodNumber) | 146 | m["quantityControl"] = fmt.Sprint(v.UseGoodNumber) |
144 | } | 147 | } |
148 | + if v.GoodCompute.UsePartnerBonus >= 0 { | ||
149 | + m["partnerDividendControl"] = fmt.Sprint(v.GoodCompute.UsePartnerBonus) | ||
150 | + } | ||
145 | allGoods = append(allGoods, m) | 151 | allGoods = append(allGoods, m) |
146 | } | 152 | } |
147 | orderData := map[string]interface{}{ | 153 | orderData := map[string]interface{}{ |
@@ -194,8 +200,12 @@ type postOrderDividend struct { | @@ -194,8 +200,12 @@ type postOrderDividend struct { | ||
194 | Id string `json:"id"` | 200 | Id string `json:"id"` |
195 | DividendPayments []postDividendPayment `json:"dividendPayment"` | 201 | DividendPayments []postDividendPayment `json:"dividendPayment"` |
196 | } | 202 | } |
203 | + | ||
197 | type postDividendPayment struct { | 204 | type postDividendPayment struct { |
198 | QuantityControl string `json:"quantityControl"` | 205 | QuantityControl string `json:"quantityControl"` |
206 | + StateOfPayment string `json:"stateOfPayment"` | ||
207 | + ProductId string `json:"productId"` | ||
208 | + Remark string `json:"remark"` | ||
199 | } | 209 | } |
200 | 210 | ||
201 | func (c *OrderDividendController) EditOrderDividend() { | 211 | func (c *OrderDividendController) EditOrderDividend() { |
@@ -208,5 +218,50 @@ func (c *OrderDividendController) EditOrderDividend() { | @@ -208,5 +218,50 @@ func (c *OrderDividendController) EditOrderDividend() { | ||
208 | c.ResponseError(errors.New("json数据解析失败")) | 218 | c.ResponseError(errors.New("json数据解析失败")) |
209 | return | 219 | return |
210 | } | 220 | } |
221 | + orderId, _ := strconv.ParseInt(param.Id, 10, 64) | ||
222 | + if orderId == 0 { | ||
223 | + c.ResponseError(errors.New("参数错误")) | ||
224 | + return | ||
225 | + } | ||
226 | + goodbouns := []orderCmd.GoodBouns{} | ||
227 | + for _, v := range param.DividendPayments { | ||
228 | + goodId, _ := strconv.ParseInt(v.ProductId, 10, 64) | ||
229 | + if goodId == 0 { | ||
230 | + c.ResponseError(errors.New("参数错误")) | ||
231 | + return | ||
232 | + } | ||
233 | + bounsStatus, _ := strconv.Atoi(v.StateOfPayment) | ||
234 | + if !(bounsStatus == domain.OrderGoodWaitPay || bounsStatus == domain.OrderGoodHasPay) { | ||
235 | + c.ResponseError(errors.New("参数错误")) | ||
236 | + return | ||
237 | + } | ||
238 | + g := orderCmd.GoodBouns{ | ||
239 | + GoodId: goodId, | ||
240 | + Remark: v.Remark, | ||
241 | + BounsStatus: bounsStatus, | ||
242 | + } | ||
243 | + if len(v.QuantityControl) == 0 { | ||
244 | + g.UseGoodNumber = -1 | ||
245 | + } else { | ||
246 | + num, err := strconv.Atoi(v.QuantityControl) | ||
247 | + if err != nil { | ||
248 | + c.ResponseError(errors.New("参数错误")) | ||
249 | + return | ||
250 | + } | ||
251 | + g.UseGoodNumber = num | ||
252 | + } | ||
253 | + goodbouns = append(goodbouns, g) | ||
254 | + } | ||
255 | + cmd := orderCmd.UpdateGoodBouns{ | ||
256 | + Id: orderId, | ||
257 | + GoodBouns: goodbouns, | ||
258 | + } | ||
259 | + orderSrv := orderService.NewOrderInfoService(nil) | ||
260 | + err = orderSrv.UpdateGoodBouns(cmd) | ||
261 | + if err != nil { | ||
262 | + c.ResponseError(err) | ||
263 | + return | ||
264 | + } | ||
265 | + c.ResponseData(nil) | ||
211 | return | 266 | return |
212 | } | 267 | } |
@@ -170,7 +170,6 @@ type postPurposeOrderDetail struct { | @@ -170,7 +170,6 @@ type postPurposeOrderDetail struct { | ||
170 | BuyerName string `json:"buyer"` | 170 | BuyerName string `json:"buyer"` |
171 | //对应合伙人 id | 171 | //对应合伙人 id |
172 | PartnerId int64 `json:"partnerID"` | 172 | PartnerId int64 `json:"partnerID"` |
173 | - | ||
174 | //业务员抽成比例 | 173 | //业务员抽成比例 |
175 | CommissionProportion float64 `json:"commissionProportion"` | 174 | CommissionProportion float64 `json:"commissionProportion"` |
176 | //订单区域 | 175 | //订单区域 |
@@ -29,7 +29,7 @@ func init() { | @@ -29,7 +29,7 @@ func init() { | ||
29 | ), | 29 | ), |
30 | beego.NSNamespace("/dividends", | 30 | beego.NSNamespace("/dividends", |
31 | beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"), | 31 | beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"), |
32 | - // beego.NSRouter("/edit", &controllers.DividendsController{}, "POST:Edit"), | 32 | + beego.NSRouter("/edit", &controllers.OrderDividendController{}, "POST:EditOrderDividend"), |
33 | beego.NSRouter("/detail", &controllers.OrderDividendController{}, "POST:OrderDividendDetail"), | 33 | beego.NSRouter("/detail", &controllers.OrderDividendController{}, "POST:OrderDividendDetail"), |
34 | ), | 34 | ), |
35 | beego.NSNamespace("/order", | 35 | beego.NSNamespace("/order", |
-
请 注册 或 登录 后发表评论