作者 tangxvhui

更新:新增实际订单编辑

@@ -334,6 +334,10 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) @@ -334,6 +334,10 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
334 if err != nil { 334 if err != nil {
335 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err)) 335 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
336 } 336 }
  337 + //判定要求的更新的订单类型
  338 + if oldOrderData.OrderType != cmd.OrderType {
  339 + return nil, lib.ThrowError(lib.BUSINESS_ERROR, fmt.Sprintf("待更新的订单的类型已变更"))
  340 + }
337 //获取旧的订单中的商品 341 //获取旧的订单中的商品
338 oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{ 342 oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
339 OrderId: cmd.Id, 343 OrderId: cmd.Id,
@@ -11,6 +11,7 @@ import ( @@ -11,6 +11,7 @@ import (
11 orderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/query" 11 orderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/query"
12 orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/service" 12 orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/service"
13 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" 13 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  14 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
14 ) 15 )
15 16
16 type OrderInfoController struct { 17 type OrderInfoController struct {
@@ -160,7 +161,7 @@ func (c *OrderInfoController) RemoveOrderPurpose() { @@ -160,7 +161,7 @@ func (c *OrderInfoController) RemoveOrderPurpose() {
160 c.ResponseData(nil) 161 c.ResponseData(nil)
161 } 162 }
162 163
163 -//PostPurposeOrderDetail 请求添加/更新的订单数据 164 +//postPurposeOrderDetail 请求添加/更新的订单数据
164 type postPurposeOrderDetail struct { 165 type postPurposeOrderDetail struct {
165 Id int64 `json:"id"` 166 Id int64 `json:"id"`
166 //订单编号 167 //订单编号
@@ -168,18 +169,39 @@ type postPurposeOrderDetail struct { @@ -168,18 +169,39 @@ type postPurposeOrderDetail struct {
168 //买家姓名 169 //买家姓名
169 BuyerName string `json:"buyer"` 170 BuyerName string `json:"buyer"`
170 //对应合伙人 id 171 //对应合伙人 id
171 - PartnerId int64 `json:"partnerID"`  
172 - PartnerName string `json:"partnerName"` 172 + PartnerId int64 `json:"partnerID"`
  173 +
173 //业务员抽成比例 174 //业务员抽成比例
174 CommissionProportion float64 `json:"commissionProportion"` 175 CommissionProportion float64 `json:"commissionProportion"`
175 //订单区域 176 //订单区域
176 OrderDist string `json:"orderDist"` 177 OrderDist string `json:"orderDist"`
177 //商品 178 //商品
178 - Product []postPurposeOrderGood `json:"product"` 179 + Product []postOrderGood `json:"product"`
  180 +}
  181 +
  182 +func (postData postPurposeOrderDetail) Valid() error {
  183 + if len(postData.OrderId) == 0 {
  184 + return lib.ThrowError(lib.ARG_ERROR, "订单编号必填")
  185 + }
  186 + if len(postData.BuyerName) == 0 {
  187 + return lib.ThrowError(lib.ARG_ERROR, "买家信息必填")
  188 + }
  189 + if postData.PartnerId == 0 {
  190 + return lib.ThrowError(lib.ARG_ERROR, "合伙人信息必填")
  191 + }
  192 + if len(postData.OrderDist) == 0 {
  193 + return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
  194 + }
  195 + for i := range postData.Product {
  196 + if err := postData.Product[i].Valid(); err != nil {
  197 + return err
  198 + }
  199 + }
  200 + return nil
179 } 201 }
180 202
181 //PostPurposeOrderGood 请求添加/更新订单中的货品 203 //PostPurposeOrderGood 请求添加/更新订单中的货品
182 -type postPurposeOrderGood struct { 204 +type postOrderGood struct {
183 Id int64 `json:"id"` 205 Id int64 `json:"id"`
184 ProductName string `json:"productName"` 206 ProductName string `json:"productName"`
185 OrderNum int `json:"orderNum"` 207 OrderNum int `json:"orderNum"`
@@ -187,6 +209,13 @@ type postPurposeOrderGood struct { @@ -187,6 +209,13 @@ type postPurposeOrderGood struct {
187 PartnerRatio float64 `json:"partnerRatio"` 209 PartnerRatio float64 `json:"partnerRatio"`
188 } 210 }
189 211
  212 +func (postData postOrderGood) Valid() error {
  213 + if len(postData.ProductName) == 0 {
  214 + return lib.ThrowError(lib.ARG_ERROR, "商品名称必填")
  215 + }
  216 + return nil
  217 +}
  218 +
190 //UpdateOrderPurpose 更新意向订单 219 //UpdateOrderPurpose 更新意向订单
191 func (c *OrderInfoController) UpdateOrderPurpose() { 220 func (c *OrderInfoController) UpdateOrderPurpose() {
192 //用与适配前端定义的数据结构 221 //用与适配前端定义的数据结构
@@ -199,6 +228,10 @@ func (c *OrderInfoController) UpdateOrderPurpose() { @@ -199,6 +228,10 @@ func (c *OrderInfoController) UpdateOrderPurpose() {
199 c.ResponseError(errors.New("json数据解析失败")) 228 c.ResponseError(errors.New("json数据解析失败"))
200 return 229 return
201 } 230 }
  231 + if err := param.Valid(); err != nil {
  232 + c.ResponseError(err)
  233 + return
  234 + }
202 if param.Id == 0 { 235 if param.Id == 0 {
203 err = c.addOrderPurpose(param) 236 err = c.addOrderPurpose(param)
204 } else { 237 } else {
@@ -212,7 +245,7 @@ func (c *OrderInfoController) UpdateOrderPurpose() { @@ -212,7 +245,7 @@ func (c *OrderInfoController) UpdateOrderPurpose() {
212 } 245 }
213 246
214 func (c *OrderInfoController) addOrderPurpose(param postPurposeOrderDetail) error { 247 func (c *OrderInfoController) addOrderPurpose(param postPurposeOrderDetail) error {
215 - orderSrv := orderService.NewOrderInfoService(nil) 248 +
216 newGoods := []orderCmd.OrderGoodData{} 249 newGoods := []orderCmd.OrderGoodData{}
217 for _, v := range param.Product { 250 for _, v := range param.Product {
218 g := orderCmd.OrderGoodData{ 251 g := orderCmd.OrderGoodData{
@@ -233,6 +266,7 @@ func (c *OrderInfoController) addOrderPurpose(param postPurposeOrderDetail) erro @@ -233,6 +266,7 @@ func (c *OrderInfoController) addOrderPurpose(param postPurposeOrderDetail) erro
233 SalesmanBonusPercent: param.CommissionProportion, 266 SalesmanBonusPercent: param.CommissionProportion,
234 Goods: newGoods, 267 Goods: newGoods,
235 } 268 }
  269 + orderSrv := orderService.NewOrderInfoService(nil)
236 _, err := orderSrv.CreateNewOrder(createcmd) 270 _, err := orderSrv.CreateNewOrder(createcmd)
237 return err 271 return err
238 } 272 }
@@ -268,9 +302,9 @@ func (c *OrderInfoController) editOrderPurpose(param postPurposeOrderDetail) err @@ -268,9 +302,9 @@ func (c *OrderInfoController) editOrderPurpose(param postPurposeOrderDetail) err
268 func (c *OrderInfoController) OrderPurposeDelivery() { 302 func (c *OrderInfoController) OrderPurposeDelivery() {
269 //用与适配前端定义的数据结构 303 //用与适配前端定义的数据结构
270 type PostParameter struct { 304 type PostParameter struct {
271 - ShipmentsId string `json:"shipmentsId"` //发货单号  
272 - Id string `json:"id"` //订单id  
273 - ProductDetail []postPurposeOrderGood `json:"productDetail"` 305 + ShipmentsId string `json:"shipmentsId"` //发货单号
  306 + Id string `json:"id"` //订单id
  307 + ProductDetail []postOrderGood `json:"productDetail"`
274 } 308 }
275 var ( 309 var (
276 param PostParameter 310 param PostParameter
@@ -443,3 +477,100 @@ func (c *OrderInfoController) GetOrderReal() { @@ -443,3 +477,100 @@ func (c *OrderInfoController) GetOrderReal() {
443 c.ResponseData(rsp) 477 c.ResponseData(rsp)
444 return 478 return
445 } 479 }
  480 +
  481 +//实际订单
  482 +type postRealOrderDetail struct {
  483 + postPurposeOrderDetail
  484 + ShipmentsId string //发货单号
  485 +}
  486 +
  487 +func (postData postRealOrderDetail) Valid() error {
  488 + if len(postData.ShipmentsId) == 0 {
  489 + return lib.ThrowError(lib.ARG_ERROR, "订单的发货单号必填")
  490 + }
  491 + if err := postData.postPurposeOrderDetail.Valid(); err != nil {
  492 + return err
  493 + }
  494 + return nil
  495 +}
  496 +
  497 +//UpdateOrderReal 编辑实际订单
  498 +func (c *OrderInfoController) UpdateOrderReal() {
  499 + //用与适配前端定义的数据结构
  500 + var (
  501 + param postRealOrderDetail
  502 + err error
  503 + )
  504 + if err = c.BindJsonData(&param); err != nil {
  505 + logs.Error(err)
  506 + c.ResponseError(errors.New("json数据解析失败"))
  507 + return
  508 + }
  509 + if err := param.Valid(); err != nil {
  510 + c.ResponseError(err)
  511 + return
  512 + }
  513 + if param.Id == 0 {
  514 + err = c.addOrderReal(param)
  515 + } else {
  516 + err = c.editOrderReal(param)
  517 + }
  518 + if err != nil {
  519 + c.ResponseError(err)
  520 + }
  521 + c.ResponseData(nil)
  522 + return
  523 +}
  524 +
  525 +func (c *OrderInfoController) addOrderReal(param postRealOrderDetail) error {
  526 + orderSrv := orderService.NewOrderInfoService(nil)
  527 + newGoods := []orderCmd.OrderGoodData{}
  528 + for _, v := range param.Product {
  529 + g := orderCmd.OrderGoodData{
  530 + GoodName: v.ProductName,
  531 + PlanGoodNumber: v.OrderNum,
  532 + Price: v.Univalence,
  533 + PartnerBonusPercent: v.PartnerRatio,
  534 + }
  535 + newGoods = append(newGoods, g)
  536 + }
  537 + createcmd := orderCmd.CreateOrderCommand{
  538 + OrderType: domain.OrderIntention,
  539 + OrderCode: param.OrderId,
  540 + DeliveryCode: param.ShipmentsId,
  541 + BuyerName: param.BuyerName,
  542 + OrderRegion: param.OrderDist,
  543 + PartnerId: param.PartnerId,
  544 + SalesmanBonusPercent: param.CommissionProportion,
  545 + Goods: newGoods,
  546 + }
  547 + _, err := orderSrv.CreateNewOrder(createcmd)
  548 + return err
  549 +}
  550 +
  551 +func (c *OrderInfoController) editOrderReal(param postRealOrderDetail) error {
  552 + orderSrv := orderService.NewOrderInfoService(nil)
  553 + newGoods := []orderCmd.OrderGoodData{}
  554 + for _, v := range param.Product {
  555 + g := orderCmd.OrderGoodData{
  556 + GoodName: v.ProductName,
  557 + PlanGoodNumber: v.OrderNum,
  558 + Price: v.Univalence,
  559 + PartnerBonusPercent: v.PartnerRatio,
  560 + }
  561 + newGoods = append(newGoods, g)
  562 + }
  563 + updatecmd := orderCmd.UpdateOrderCommand{
  564 + Id: param.Id,
  565 + OrderType: domain.OrderIntention,
  566 + OrderCode: param.OrderId,
  567 + DeliveryCode: param.ShipmentsId,
  568 + BuyerName: param.BuyerName,
  569 + OrderRegion: param.OrderDist,
  570 + PartnerId: param.PartnerId,
  571 + SalesmanBonusPercent: param.CommissionProportion,
  572 + Goods: newGoods,
  573 + }
  574 + _, err := orderSrv.UpdateOrderData(updatecmd)
  575 + return err
  576 +}
@@ -46,8 +46,7 @@ func init() { @@ -46,8 +46,7 @@ func init() {
46 beego.NSRouter("/purpose/sendout", &controllers.OrderInfoController{}, "POST:OrderPurposeDelivery"), 46 beego.NSRouter("/purpose/sendout", &controllers.OrderInfoController{}, "POST:OrderPurposeDelivery"),
47 beego.NSRouter("/actual/list", &controllers.OrderInfoController{}, "POST:PageListOrderReal"), 47 beego.NSRouter("/actual/list", &controllers.OrderInfoController{}, "POST:PageListOrderReal"),
48 beego.NSRouter("/actual/detail", &controllers.OrderInfoController{}, "POST:GetOrderReal"), 48 beego.NSRouter("/actual/detail", &controllers.OrderInfoController{}, "POST:GetOrderReal"),
49 -  
50 - beego.NSRouter("/actual/update", &controllers.OrderController{}, "POST:UpdateOrderReal"), 49 + beego.NSRouter("/actual/update", &controllers.OrderInfoController{}, "POST:UpdateOrderReal"),
51 ), 50 ),
52 51
53 beego.NSNamespace("/common", 52 beego.NSNamespace("/common",