...
|
...
|
@@ -11,6 +11,7 @@ import ( |
|
|
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"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
|
|
|
)
|
|
|
|
|
|
type OrderInfoController struct {
|
...
|
...
|
@@ -160,7 +161,7 @@ func (c *OrderInfoController) RemoveOrderPurpose() { |
|
|
c.ResponseData(nil)
|
|
|
}
|
|
|
|
|
|
//PostPurposeOrderDetail 请求添加/更新的订单数据
|
|
|
//postPurposeOrderDetail 请求添加/更新的订单数据
|
|
|
type postPurposeOrderDetail struct {
|
|
|
Id int64 `json:"id"`
|
|
|
//订单编号
|
...
|
...
|
@@ -168,18 +169,39 @@ type postPurposeOrderDetail struct { |
|
|
//买家姓名
|
|
|
BuyerName string `json:"buyer"`
|
|
|
//对应合伙人 id
|
|
|
PartnerId int64 `json:"partnerID"`
|
|
|
PartnerName string `json:"partnerName"`
|
|
|
PartnerId int64 `json:"partnerID"`
|
|
|
|
|
|
//业务员抽成比例
|
|
|
CommissionProportion float64 `json:"commissionProportion"`
|
|
|
//订单区域
|
|
|
OrderDist string `json:"orderDist"`
|
|
|
//商品
|
|
|
Product []postPurposeOrderGood `json:"product"`
|
|
|
Product []postOrderGood `json:"product"`
|
|
|
}
|
|
|
|
|
|
func (postData postPurposeOrderDetail) Valid() error {
|
|
|
if len(postData.OrderId) == 0 {
|
|
|
return lib.ThrowError(lib.ARG_ERROR, "订单编号必填")
|
|
|
}
|
|
|
if len(postData.BuyerName) == 0 {
|
|
|
return lib.ThrowError(lib.ARG_ERROR, "买家信息必填")
|
|
|
}
|
|
|
if postData.PartnerId == 0 {
|
|
|
return lib.ThrowError(lib.ARG_ERROR, "合伙人信息必填")
|
|
|
}
|
|
|
if len(postData.OrderDist) == 0 {
|
|
|
return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
|
|
|
}
|
|
|
for i := range postData.Product {
|
|
|
if err := postData.Product[i].Valid(); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//PostPurposeOrderGood 请求添加/更新订单中的货品
|
|
|
type postPurposeOrderGood struct {
|
|
|
type postOrderGood struct {
|
|
|
Id int64 `json:"id"`
|
|
|
ProductName string `json:"productName"`
|
|
|
OrderNum int `json:"orderNum"`
|
...
|
...
|
@@ -187,6 +209,13 @@ type postPurposeOrderGood struct { |
|
|
PartnerRatio float64 `json:"partnerRatio"`
|
|
|
}
|
|
|
|
|
|
func (postData postOrderGood) Valid() error {
|
|
|
if len(postData.ProductName) == 0 {
|
|
|
return lib.ThrowError(lib.ARG_ERROR, "商品名称必填")
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//UpdateOrderPurpose 更新意向订单
|
|
|
func (c *OrderInfoController) UpdateOrderPurpose() {
|
|
|
//用与适配前端定义的数据结构
|
...
|
...
|
@@ -199,6 +228,10 @@ func (c *OrderInfoController) UpdateOrderPurpose() { |
|
|
c.ResponseError(errors.New("json数据解析失败"))
|
|
|
return
|
|
|
}
|
|
|
if err := param.Valid(); err != nil {
|
|
|
c.ResponseError(err)
|
|
|
return
|
|
|
}
|
|
|
if param.Id == 0 {
|
|
|
err = c.addOrderPurpose(param)
|
|
|
} else {
|
...
|
...
|
@@ -212,7 +245,7 @@ func (c *OrderInfoController) UpdateOrderPurpose() { |
|
|
}
|
|
|
|
|
|
func (c *OrderInfoController) addOrderPurpose(param postPurposeOrderDetail) error {
|
|
|
orderSrv := orderService.NewOrderInfoService(nil)
|
|
|
|
|
|
newGoods := []orderCmd.OrderGoodData{}
|
|
|
for _, v := range param.Product {
|
|
|
g := orderCmd.OrderGoodData{
|
...
|
...
|
@@ -233,6 +266,7 @@ func (c *OrderInfoController) addOrderPurpose(param postPurposeOrderDetail) erro |
|
|
SalesmanBonusPercent: param.CommissionProportion,
|
|
|
Goods: newGoods,
|
|
|
}
|
|
|
orderSrv := orderService.NewOrderInfoService(nil)
|
|
|
_, err := orderSrv.CreateNewOrder(createcmd)
|
|
|
return err
|
|
|
}
|
...
|
...
|
@@ -268,9 +302,9 @@ func (c *OrderInfoController) editOrderPurpose(param postPurposeOrderDetail) err |
|
|
func (c *OrderInfoController) OrderPurposeDelivery() {
|
|
|
//用与适配前端定义的数据结构
|
|
|
type PostParameter struct {
|
|
|
ShipmentsId string `json:"shipmentsId"` //发货单号
|
|
|
Id string `json:"id"` //订单id
|
|
|
ProductDetail []postPurposeOrderGood `json:"productDetail"`
|
|
|
ShipmentsId string `json:"shipmentsId"` //发货单号
|
|
|
Id string `json:"id"` //订单id
|
|
|
ProductDetail []postOrderGood `json:"productDetail"`
|
|
|
}
|
|
|
var (
|
|
|
param PostParameter
|
...
|
...
|
@@ -443,3 +477,100 @@ func (c *OrderInfoController) GetOrderReal() { |
|
|
c.ResponseData(rsp)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//实际订单
|
|
|
type postRealOrderDetail struct {
|
|
|
postPurposeOrderDetail
|
|
|
ShipmentsId string //发货单号
|
|
|
}
|
|
|
|
|
|
func (postData postRealOrderDetail) Valid() error {
|
|
|
if len(postData.ShipmentsId) == 0 {
|
|
|
return lib.ThrowError(lib.ARG_ERROR, "订单的发货单号必填")
|
|
|
}
|
|
|
if err := postData.postPurposeOrderDetail.Valid(); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//UpdateOrderReal 编辑实际订单
|
|
|
func (c *OrderInfoController) UpdateOrderReal() {
|
|
|
//用与适配前端定义的数据结构
|
|
|
var (
|
|
|
param postRealOrderDetail
|
|
|
err error
|
|
|
)
|
|
|
if err = c.BindJsonData(¶m); err != nil {
|
|
|
logs.Error(err)
|
|
|
c.ResponseError(errors.New("json数据解析失败"))
|
|
|
return
|
|
|
}
|
|
|
if err := param.Valid(); err != nil {
|
|
|
c.ResponseError(err)
|
|
|
return
|
|
|
}
|
|
|
if param.Id == 0 {
|
|
|
err = c.addOrderReal(param)
|
|
|
} else {
|
|
|
err = c.editOrderReal(param)
|
|
|
}
|
|
|
if err != nil {
|
|
|
c.ResponseError(err)
|
|
|
}
|
|
|
c.ResponseData(nil)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (c *OrderInfoController) addOrderReal(param postRealOrderDetail) error {
|
|
|
orderSrv := orderService.NewOrderInfoService(nil)
|
|
|
newGoods := []orderCmd.OrderGoodData{}
|
|
|
for _, v := range param.Product {
|
|
|
g := orderCmd.OrderGoodData{
|
|
|
GoodName: v.ProductName,
|
|
|
PlanGoodNumber: v.OrderNum,
|
|
|
Price: v.Univalence,
|
|
|
PartnerBonusPercent: v.PartnerRatio,
|
|
|
}
|
|
|
newGoods = append(newGoods, g)
|
|
|
}
|
|
|
createcmd := orderCmd.CreateOrderCommand{
|
|
|
OrderType: domain.OrderIntention,
|
|
|
OrderCode: param.OrderId,
|
|
|
DeliveryCode: param.ShipmentsId,
|
|
|
BuyerName: param.BuyerName,
|
|
|
OrderRegion: param.OrderDist,
|
|
|
PartnerId: param.PartnerId,
|
|
|
SalesmanBonusPercent: param.CommissionProportion,
|
|
|
Goods: newGoods,
|
|
|
}
|
|
|
_, err := orderSrv.CreateNewOrder(createcmd)
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
func (c *OrderInfoController) editOrderReal(param postRealOrderDetail) error {
|
|
|
orderSrv := orderService.NewOrderInfoService(nil)
|
|
|
newGoods := []orderCmd.OrderGoodData{}
|
|
|
for _, v := range param.Product {
|
|
|
g := orderCmd.OrderGoodData{
|
|
|
GoodName: v.ProductName,
|
|
|
PlanGoodNumber: v.OrderNum,
|
|
|
Price: v.Univalence,
|
|
|
PartnerBonusPercent: v.PartnerRatio,
|
|
|
}
|
|
|
newGoods = append(newGoods, g)
|
|
|
}
|
|
|
updatecmd := orderCmd.UpdateOrderCommand{
|
|
|
Id: param.Id,
|
|
|
OrderType: domain.OrderIntention,
|
|
|
OrderCode: param.OrderId,
|
|
|
DeliveryCode: param.ShipmentsId,
|
|
|
BuyerName: param.BuyerName,
|
|
|
OrderRegion: param.OrderDist,
|
|
|
PartnerId: param.PartnerId,
|
|
|
SalesmanBonusPercent: param.CommissionProportion,
|
|
|
Goods: newGoods,
|
|
|
}
|
|
|
_, err := orderSrv.UpdateOrderData(updatecmd)
|
|
|
return err
|
|
|
} |
...
|
...
|
|