作者 tangxvhui

更新意向订单

@@ -7,16 +7,10 @@ type OrderGoodData struct { @@ -7,16 +7,10 @@ type OrderGoodData struct {
7 GoodName string `json:"goodName"` 7 GoodName string `json:"goodName"`
8 //预计的货品数量 8 //预计的货品数量
9 PlanGoodNumber int `json:"planGoodNumber"` 9 PlanGoodNumber int `json:"planGoodNumber"`
10 - //调整后的货品数量  
11 - //业务判定时0是有效值,  
12 - //所以用空串表示无值,转换到数据库中为负值  
13 - UseGoodNumber int `json:"useGoodNumber"`  
14 //货品单价 10 //货品单价
15 Price float64 `json:"price"` 11 Price float64 `json:"price"`
16 //合伙人分红比例 12 //合伙人分红比例
17 PartnerBonusPercent float64 `json:"partnerBonusPercent"` 13 PartnerBonusPercent float64 `json:"partnerBonusPercent"`
18 - //分红支付状态  
19 - BonusStatus int `json:"bonusStatus"`  
20 //备注信息 14 //备注信息
21 Remark string `json:"remark"` 15 Remark string `json:"remark"`
22 } 16 }
1 package command 1 package command
2 2
  3 +//UpdateOrderPurposeCommand 更新意向单
3 type UpdateOrderCommand struct { 4 type UpdateOrderCommand struct {
4 - //订单类型  
5 - OrderType int `json:"orderType"` 5 + Id int64 `json:"id"`
6 //订单编号 6 //订单编号
7 OrderCode string `json:"orderCode"` 7 OrderCode string `json:"orderCode"`
8 //交货编号 8 //交货编号
@@ -15,6 +15,8 @@ type UpdateOrderCommand struct { @@ -15,6 +15,8 @@ type UpdateOrderCommand struct {
15 PartnerId int64 `json:"partnerId"` 15 PartnerId int64 `json:"partnerId"`
16 //业务员抽成比例 16 //业务员抽成比例
17 SalesmanBonusPercent float64 `json:"salesmanBonusPercent"` 17 SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
  18 + //订单类型
  19 + OrderType int `json:"orderType"`
18 //货品 20 //货品
19 Goods []OrderGoodData `json:"goods"` 21 Goods []OrderGoodData `json:"goods"`
20 } 22 }
1 package query 1 package query
2 2
3 //ListOrderQuery 获取用户列表 3 //ListOrderQuery 获取用户列表
4 -type ListOrderQuery struct { 4 +type ListOrderBaseQuery struct {
5 //合伙人id 5 //合伙人id
6 PartnerId int64 `json:"partnerId" ` 6 PartnerId int64 `json:"partnerId" `
7 //订单编号 7 //订单编号
@@ -20,7 +20,7 @@ func NewOrderInfoService(option map[string]interface{}) *OrderInfoService { @@ -20,7 +20,7 @@ func NewOrderInfoService(option map[string]interface{}) *OrderInfoService {
20 } 20 }
21 21
22 // PageListOrderBase 获取订单列表 22 // PageListOrderBase 获取订单列表
23 -func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrderQuery) ([]domain.OrderBase, int, error) { 23 +func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrderBaseQuery) ([]domain.OrderBase, int, error) {
24 transactionContext, err := factory.CreateTransactionContext(nil) 24 transactionContext, err := factory.CreateTransactionContext(nil)
25 if err != nil { 25 if err != nil {
26 return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 26 return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
@@ -37,7 +37,7 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder @@ -37,7 +37,7 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder
37 } else { 37 } else {
38 orderRepository = value 38 orderRepository = value
39 } 39 }
40 - query := domain.OrderFindQuery{ 40 + query := domain.OrderBaseFindQuery{
41 PartnerId: listOrderQuery.PartnerId, 41 PartnerId: listOrderQuery.PartnerId,
42 OrderCode: listOrderQuery.OrderCode, 42 OrderCode: listOrderQuery.OrderCode,
43 Offset: listOrderQuery.Offset, 43 Offset: listOrderQuery.Offset,
@@ -103,11 +103,11 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery @@ -103,11 +103,11 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery
103 }); err != nil { 103 }); err != nil {
104 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 104 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
105 } 105 }
106 - order, err = orderBaseRepository.FindOne(domain.OrderFindOneQuery{ 106 + order, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
107 OrderId: getOrderQuery.OrderId, 107 OrderId: getOrderQuery.OrderId,
108 }) 108 })
109 if err != nil { 109 if err != nil {
110 - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 110 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取订单数据失败:%s", err))
111 } 111 }
112 var ( 112 var (
113 partnerData *domain.PartnerInfo 113 partnerData *domain.PartnerInfo
@@ -115,7 +115,7 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery @@ -115,7 +115,7 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery
115 ) 115 )
116 partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: order.PartnerInfo.Id}) 116 partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: order.PartnerInfo.Id})
117 if err != nil { 117 if err != nil {
118 - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 118 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("检索合伙人数据失败:%s", err))
119 } 119 }
120 order.PartnerInfo = partnerData.Partner 120 order.PartnerInfo = partnerData.Partner
121 goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{ 121 goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
@@ -193,7 +193,7 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( @@ -193,7 +193,7 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (
193 var orderGoods []domain.OrderGood 193 var orderGoods []domain.OrderGood
194 for _, good := range cmd.Goods { 194 for _, good := range cmd.Goods {
195 m := domain.NewOrderGood() 195 m := domain.NewOrderGood()
196 - m.OrderId = newOrder.Id 196 + m.OrderId = 0
197 m.GoodName = good.GoodName 197 m.GoodName = good.GoodName
198 m.PlanGoodNumber = good.PlanGoodNumber 198 m.PlanGoodNumber = good.PlanGoodNumber
199 m.Price = good.Price 199 m.Price = good.Price
@@ -214,6 +214,9 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( @@ -214,6 +214,9 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (
214 if err != nil { 214 if err != nil {
215 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err)) 215 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
216 } 216 }
  217 + for i := range newOrder.Goods {
  218 + newOrder.Goods[i].OrderId = newOrder.Id
  219 + }
217 err = orderGoodRepository.Save(orderGoods) 220 err = orderGoodRepository.Save(orderGoods)
218 if err != nil { 221 if err != nil {
219 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err)) 222 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
@@ -266,3 +269,135 @@ func (service OrderInfoService) DeleteOrder(orderId int64) error { @@ -266,3 +269,135 @@ func (service OrderInfoService) DeleteOrder(orderId int64) error {
266 } 269 }
267 return nil 270 return nil
268 } 271 }
  272 +
  273 +//发货
  274 +
  275 +//编辑订单
  276 +func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) (*domain.OrderBase, error) {
  277 + var (
  278 + transactionContext, _ = factory.CreateTransactionContext(nil)
  279 + err error
  280 + )
  281 +
  282 + if err = transactionContext.StartTransaction(); err != nil {
  283 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  284 + }
  285 + defer func() {
  286 + transactionContext.RollbackTransaction()
  287 + }()
  288 + // orderDao, _ := factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
  289 + // ok, err := orderDao.OrderCodeIsExist(command.OrderCode, 0)
  290 + // if err != nil {
  291 + // return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  292 + // }
  293 + // if ok {
  294 + // return lib.ThrowError(lib.BUSINESS_ERROR, "订单编号已存在")
  295 + // }
  296 + var PartnerInfoRepository domain.PartnerInfoRepository
  297 + if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
  298 + "transactionContext": transactionContext,
  299 + }); err != nil {
  300 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  301 + }
  302 + var partnerData *domain.PartnerInfo
  303 + partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: cmd.PartnerId})
  304 + if err != nil {
  305 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("检索合伙人数据失败"))
  306 + }
  307 + var (
  308 + orderBaseRepository domain.OrderBaseRepository
  309 + orderGoodRepository domain.OrderGoodRepository
  310 + oldOrderData *domain.OrderBase
  311 + oldOrderGoods []domain.OrderGood
  312 + newOrderGoods []domain.OrderGood
  313 + delGoods []int64
  314 + )
  315 + if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
  316 + "transactionContext": transactionContext,
  317 + }); err != nil {
  318 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  319 + }
  320 + if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
  321 + "transactionContext": transactionContext,
  322 + }); err != nil {
  323 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  324 + }
  325 + //获取旧的订单
  326 + oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
  327 + OrderId: cmd.Id,
  328 + })
  329 + if err != nil {
  330 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
  331 + }
  332 + //获取旧的订单中的商品
  333 + oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
  334 + OrderId: cmd.Id,
  335 + })
  336 + if err != nil {
  337 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
  338 + }
  339 + for _, good := range cmd.Goods {
  340 + m := domain.NewOrderGood()
  341 + m.OrderId = oldOrderData.Id
  342 + m.GoodName = good.GoodName
  343 + m.PlanGoodNumber = good.PlanGoodNumber
  344 + m.Price = good.Price
  345 + m.PartnerBonusPercent = good.PartnerBonusPercent
  346 + m.Remark = good.Remark
  347 + err = m.Compute()
  348 + if err != nil {
  349 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
  350 + }
  351 + newOrderGoods = append(newOrderGoods, m)
  352 + }
  353 + oldOrderData.OrderCode = cmd.OrderCode
  354 + oldOrderData.DeliveryCode = cmd.DeliveryCode
  355 + oldOrderData.Buyer.BuyerName = cmd.BuyerName
  356 + oldOrderData.RegionInfo.RegionName = cmd.OrderRegion
  357 + oldOrderData.PartnerId = cmd.PartnerId
  358 + oldOrderData.PartnerInfo = partnerData.Partner
  359 + oldOrderData.SalesmanBonusPercent = cmd.SalesmanBonusPercent
  360 + oldOrderData.Goods = newOrderGoods
  361 + err = oldOrderData.Compute()
  362 + if err != nil {
  363 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
  364 + }
  365 +
  366 + err = orderBaseRepository.Save(oldOrderData)
  367 + if err != nil {
  368 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
  369 + }
  370 + err = orderGoodRepository.Save(newOrderGoods)
  371 + if err != nil {
  372 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
  373 + }
  374 + oldOrderData.Goods = newOrderGoods
  375 + //删不需要的订单总不需要的商品
  376 + delGoods = service.deleteOldOrderGoods(newOrderGoods, oldOrderGoods)
  377 + err = orderGoodRepository.Remove(oldOrderData.Id, delGoods...)
  378 + if err != nil {
  379 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单中的商品数据失败:%s", err))
  380 + }
  381 + err = transactionContext.CommitTransaction()
  382 + if err != nil {
  383 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  384 + }
  385 + return oldOrderData, nil
  386 +}
  387 +
  388 +//新旧商品列表对比
  389 +func (service OrderInfoService) deleteOldOrderGoods(newGoods []domain.OrderGood, oldGoods []domain.OrderGood) (goodIds []int64) {
  390 + for _, old := range oldGoods {
  391 + var hasIn bool
  392 + for _, new := range newGoods {
  393 + if old.Id == new.Id {
  394 + hasIn = true
  395 + break
  396 + }
  397 + }
  398 + if !hasIn {
  399 + goodIds = append(goodIds, old.Id)
  400 + }
  401 + }
  402 + return
  403 +}
@@ -150,6 +150,7 @@ type OrderBaseFindOneQuery struct { @@ -150,6 +150,7 @@ type OrderBaseFindOneQuery struct {
150 type OrderBaseFindQuery struct { 150 type OrderBaseFindQuery struct {
151 PartnerId int64 151 PartnerId int64
152 OrderCode string 152 OrderCode string
  153 + DeliveryCode string
153 Offset int 154 Offset int
154 Limit int 155 Limit int
155 OrderType int 156 OrderType int
@@ -157,7 +158,7 @@ type OrderBaseFindQuery struct { @@ -157,7 +158,7 @@ type OrderBaseFindQuery struct {
157 158
158 type OrderBaseRepository interface { 159 type OrderBaseRepository interface {
159 Save(order *OrderBase) error 160 Save(order *OrderBase) error
160 - FindOne(qureyOptions OrderFindOneQuery) (*OrderBase, error)  
161 - Find(queryOptions OrderFindQuery) ([]OrderBase, int, error) 161 + FindOne(qureyOptions OrderBaseFindOneQuery) (*OrderBase, error)
  162 + Find(queryOptions OrderBaseFindQuery) ([]OrderBase, int, error)
162 Remove(id int64) error 163 Remove(id int64) error
163 } 164 }
@@ -73,7 +73,7 @@ func (repository OrderBaseRepository) Save(orderInfo *domain.OrderBase) error { @@ -73,7 +73,7 @@ func (repository OrderBaseRepository) Save(orderInfo *domain.OrderBase) error {
73 return err 73 return err
74 } 74 }
75 75
76 -func (repository OrderBaseRepository) Find(queryOption domain.OrderFindQuery) ([]domain.OrderBase, int, error) { 76 +func (repository OrderBaseRepository) Find(queryOption domain.OrderBaseFindQuery) ([]domain.OrderBase, int, error) {
77 db := repository.transactionContext.PgDd 77 db := repository.transactionContext.PgDd
78 orderModels := []models.OrderBase{} 78 orderModels := []models.OrderBase{}
79 query := db.Model(&orderModels) 79 query := db.Model(&orderModels)
@@ -116,7 +116,7 @@ func (repository OrderBaseRepository) Find(queryOption domain.OrderFindQuery) ([ @@ -116,7 +116,7 @@ func (repository OrderBaseRepository) Find(queryOption domain.OrderFindQuery) ([
116 return ordersReturn, count, nil 116 return ordersReturn, count, nil
117 } 117 }
118 118
119 -func (repository OrderBaseRepository) FindOne(qureyOptions domain.OrderFindOneQuery) (*domain.OrderBase, error) { 119 +func (repository OrderBaseRepository) FindOne(qureyOptions domain.OrderBaseFindOneQuery) (*domain.OrderBase, error) {
120 var ( 120 var (
121 err error 121 err error
122 tx = repository.transactionContext.PgDd 122 tx = repository.transactionContext.PgDd
  1 +package controllers
  2 +
  3 +import (
  4 + "errors"
  5 + "strconv"
  6 +
  7 + "github.com/astaxie/beego/logs"
  8 + orderCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/command"
  9 + orderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/query"
  10 + orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/service"
  11 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  12 +)
  13 +
  14 +type OrderInfoController struct {
  15 + BaseController
  16 +}
  17 +
  18 +////Prepare 重写 BaseController 的Prepare方法
  19 +func (c *OrderInfoController) Prepare() {
  20 + c.BaseController.Prepare()
  21 + if ok := c.ValidJWTToken(); !ok {
  22 + return
  23 + }
  24 + if ok := c.ValidAdminPermission(domain.PERMISSION_ORDER); !ok {
  25 + return
  26 + }
  27 +}
  28 +
  29 +//PageListOrderPurpose 分页获取意向订单列表
  30 +func (c *OrderInfoController) PageListOrderPurpose() {
  31 + type Parameter struct {
  32 + SearchText string `json:"searchText"`
  33 + Partner int64 `json:"partner"`
  34 + PageSize int `json:"pageSize"`
  35 + PageNumber int `json:"pageNumber"`
  36 + }
  37 + var (
  38 + param Parameter
  39 + err error
  40 + )
  41 + if err = c.BindJsonData(&param); err != nil {
  42 + logs.Error(err)
  43 + c.ResponseError(errors.New("json数据解析失败"))
  44 + return
  45 + }
  46 + if param.PageNumber == 0 {
  47 + param.PageNumber = 1
  48 + }
  49 + if param.PageSize == 0 {
  50 + param.PageSize = 20
  51 + }
  52 +
  53 + orderSrv := orderService.NewOrderInfoService(nil)
  54 + orderinfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{
  55 + PartnerId: param.Partner,
  56 + OrderCode: param.SearchText,
  57 + OrderType: domain.OrderIntention,
  58 + Limit: param.PageSize,
  59 + Offset: (param.PageNumber - 1) * param.PageSize,
  60 + })
  61 + if err != nil {
  62 + c.ResponseError(err)
  63 + return
  64 + }
  65 + rsp := []map[string]interface{}{}
  66 + for i := range orderinfos {
  67 + orderinfo := orderinfos[i]
  68 + m := map[string]interface{}{
  69 + "createTime": orderinfo.CreateTime.Local().Format("2006-01-02 15:04:05"),
  70 + "updateTime": orderinfo.UpdateTime.Local().Format("2006-01-02 15:04:05"),
  71 + "buyer": orderinfo.Buyer.BuyerName,
  72 + "id": orderinfo.Id,
  73 + "orderId": orderinfo.OrderCode,
  74 + "partner": orderinfo.PartnerInfo.PartnerName,
  75 + "orderNum": orderinfo.OrderCompute.PlanOrderCount,
  76 + "orderPrice": orderinfo.OrderCompute.PlanOrderAmount,
  77 + "orderDist": orderinfo.RegionInfo.RegionName,
  78 + }
  79 + rsp = append(rsp, m)
  80 + }
  81 + c.ResponsePageList(rsp, cnt, param.PageNumber)
  82 +}
  83 +
  84 +//GetOrderPurpose 获取意向订单详情
  85 +func (c *OrderInfoController) GetOrderPurpose() {
  86 + type Parameter struct {
  87 + Id string `json:"id"`
  88 + }
  89 + var (
  90 + param Parameter
  91 + err error
  92 + )
  93 + if err = c.BindJsonData(&param); err != nil {
  94 + logs.Error(err)
  95 + c.ResponseError(errors.New("json数据解析失败"))
  96 + return
  97 + }
  98 + orderid, _ := strconv.ParseInt(param.Id, 10, 64)
  99 + orderSrv := orderService.NewOrderInfoService(nil)
  100 + orderinfo, err := orderSrv.GetOrderDetail(orderQuery.GetOrderQuery{
  101 + OrderId: orderid,
  102 + })
  103 + if err != nil {
  104 + c.ResponseError(err)
  105 + return
  106 + }
  107 + allGoods := []map[string]interface{}{}
  108 + for _, v := range orderinfo.Goods {
  109 + m := map[string]interface{}{
  110 + "productName": v.GoodName,
  111 + "orderNum": v.PlanGoodNumber,
  112 + "univalence": v.Price,
  113 + "partnerRatio": v.PartnerBonusPercent,
  114 + "orderPrice": v.GoodCompute.PlanAmount,
  115 + }
  116 + allGoods = append(allGoods, m)
  117 + }
  118 + rsp := map[string]interface{}{
  119 + "buyer": orderinfo.Buyer.BuyerName,
  120 + "id": orderinfo.Id,
  121 + "partnerID": orderinfo.PartnerInfo.Id,
  122 + "partner": orderinfo.PartnerInfo.PartnerName,
  123 + "orderDist": orderinfo.RegionInfo.RegionName,
  124 + "orderId": orderinfo.OrderCode,
  125 + "product": allGoods,
  126 + "commissionProportion": orderinfo.SalesmanBonusPercent,
  127 + "orderNumCount": orderinfo.OrderCompute.PlanOrderCount,
  128 + "orderAmountAdjustmentCount": orderinfo.OrderCompute.PlanOrderAmount,
  129 + }
  130 + c.ResponseData(rsp)
  131 +}
  132 +
  133 +//RemoveOrderPurpose 删除意向订单
  134 +func (c *OrderInfoController) RemoveOrderPurpose() {
  135 + type Parameter struct {
  136 + Id int64 `json:"id"`
  137 + }
  138 + var (
  139 + param Parameter
  140 + err error
  141 + )
  142 + if err = c.BindJsonData(&param); err != nil {
  143 + logs.Error(err)
  144 + c.ResponseError(errors.New("json数据解析失败"))
  145 + return
  146 + }
  147 + orderSrv := orderService.NewOrderInfoService(nil)
  148 + err = orderSrv.DeleteOrder(param.Id)
  149 + if err != nil {
  150 + c.ResponseError(err)
  151 + return
  152 + }
  153 + c.ResponseData(nil)
  154 +}
  155 +
  156 +//PostPurposeOrderDetail 请求添加/更新的订单数据
  157 +type postPurposeOrderDetail struct {
  158 + Id int64 `json:"id"`
  159 + //订单编号
  160 + OrderId string `json:"orderId"`
  161 + //买家姓名
  162 + BuyerName string `json:"buyerName"`
  163 + //对应合伙人 id
  164 + PartnerId int64 `json:"partnerID"`
  165 + PartnerName string `json:"partnerName"`
  166 + //业务员抽成比例
  167 + CommissionProportion float64 `json:"commissionProportion"`
  168 + //订单区域
  169 + OrderDist string `json:"orderDist"`
  170 + //商品
  171 + Product []postPurposeOrderGood `json:"product"`
  172 +}
  173 +
  174 +//PostPurposeOrderGood 请求添加/更新订单中的货品
  175 +type postPurposeOrderGood struct {
  176 + Id int64 `json:"id"`
  177 + ProductName string `json:"productName"`
  178 + OrderNum int `json:"orderNum"`
  179 + Univalence float64 `json:"univalence"`
  180 + PartnerRatio float64 `json:"partnerRatio"`
  181 +}
  182 +
  183 +//UpdateOrderPurpose 更新意向订单
  184 +func (c *OrderInfoController) UpdateOrderPurpose() {
  185 + //用与适配前端定义的数据结构
  186 + var (
  187 + param postPurposeOrderDetail
  188 + err error
  189 + )
  190 + if err = c.BindJsonData(&param); err != nil {
  191 + logs.Error(err)
  192 + c.ResponseError(errors.New("json数据解析失败"))
  193 + return
  194 + }
  195 + if param.Id == 0 {
  196 + err = c.addOrderPurpose(param)
  197 + } else {
  198 + err = c.editOrderPurpose(param)
  199 + }
  200 + if err != nil {
  201 + c.ResponseError(err)
  202 + }
  203 + c.ResponseData(nil)
  204 + return
  205 +}
  206 +
  207 +func (c *OrderInfoController) addOrderPurpose(param postPurposeOrderDetail) error {
  208 + orderSrv := orderService.NewOrderInfoService(nil)
  209 + newGoods := []orderCmd.OrderGoodData{}
  210 + for _, v := range param.Product {
  211 + g := orderCmd.OrderGoodData{
  212 + GoodName: v.ProductName,
  213 + PlanGoodNumber: v.OrderNum,
  214 + Price: v.Univalence,
  215 + PartnerBonusPercent: v.PartnerRatio,
  216 + }
  217 + newGoods = append(newGoods, g)
  218 + }
  219 + createcmd := orderCmd.CreateOrderCommand{
  220 + OrderType: domain.OrderIntention,
  221 + OrderCode: param.OrderId,
  222 + DeliveryCode: "",
  223 + BuyerName: param.BuyerName,
  224 + OrderRegion: param.OrderDist,
  225 + PartnerId: param.PartnerId,
  226 + SalesmanBonusPercent: param.CommissionProportion,
  227 + Goods: newGoods,
  228 + }
  229 + _, err := orderSrv.CreateNewOrder(createcmd)
  230 + return err
  231 +}
  232 +
  233 +func (c *OrderInfoController) editOrderPurpose(param postPurposeOrderDetail) error {
  234 + orderSrv := orderService.NewOrderInfoService(nil)
  235 + newGoods := []orderCmd.OrderGoodData{}
  236 + for _, v := range param.Product {
  237 + g := orderCmd.OrderGoodData{
  238 + GoodName: v.ProductName,
  239 + PlanGoodNumber: v.OrderNum,
  240 + Price: v.Univalence,
  241 + PartnerBonusPercent: v.PartnerRatio,
  242 + }
  243 + newGoods = append(newGoods, g)
  244 + }
  245 + updatecmd := orderCmd.UpdateOrderCommand{
  246 + Id: param.Id,
  247 + OrderType: domain.OrderIntention,
  248 + OrderCode: param.OrderId,
  249 + DeliveryCode: "",
  250 + BuyerName: param.BuyerName,
  251 + OrderRegion: param.OrderDist,
  252 + PartnerId: param.PartnerId,
  253 + SalesmanBonusPercent: param.CommissionProportion,
  254 + Goods: newGoods,
  255 + }
  256 + _, err := orderSrv.UpdateOrderData(updatecmd)
  257 + return err
  258 +}
@@ -46,5 +46,15 @@ func init() { @@ -46,5 +46,15 @@ func init() {
46 beego.NSRouter("/partner", &controllers.CommonController{}, "POST:GetPartnerList"), 46 beego.NSRouter("/partner", &controllers.CommonController{}, "POST:GetPartnerList"),
47 ), 47 ),
48 ) 48 )
  49 + adminRouterV2 := beego.NewNamespace("/v2",
  50 + beego.NSNamespace("/order",
  51 + beego.NSRouter("/purpose/list", &controllers.OrderInfoController{}, "POST:PageListOrderPurpose"),
  52 + beego.NSRouter("/purpose/update", &controllers.OrderInfoController{}, "POST:UpdateOrderPurpose"),
  53 + beego.NSRouter("/purpose/detail", &controllers.OrderInfoController{}, "POST:GetOrderPurpose"),
  54 + beego.NSRouter("/purpose/del", &controllers.OrderInfoController{}, "POST:RemoveOrderPurpose"),
  55 + ),
  56 + )
  57 +
49 beego.AddNamespace(adminRouter) 58 beego.AddNamespace(adminRouter)
  59 + beego.AddNamespace(adminRouterV2)
50 } 60 }