作者 tangxvhui

更新

1 package command 1 package command
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
  5 +)
  6 +
  7 +type CreateOrderCommand struct {
  8 + //订单区域
  9 + OrderRegion string
  10 + //订单编号
  11 + OrderCode string `json:"orderCode"`
  12 + //订单名称
  13 + OrderName string `json:"oderName"`
  14 + //数量
  15 + OrderCount int `json:"orderCount"`
  16 + //实际订单数量
  17 + OrderActualCount int `json:"orderActualCount"`
  18 + //订单金额
  19 + OrderAmount float64 `json:"orderAmount"`
  20 + //订单实际金额
  21 + OrderActualAmount float64 `json:"orderActualAmount"`
  22 + //订单状态
  23 + OrderStatus int `json:"orderStatus"`
  24 + //买家
  25 + BuyerName string `json:"buyerName"`
  26 + //买家电话
  27 + BuyerPhone string `json:"buyerPhone"`
  28 + //地址
  29 + BuyerAddress string `json:"address"`
  30 + //合伙人数据
  31 + PartnerId int64 `json:"partId"`
  32 + //合伙人分红百分比
  33 + PartnerBonusPercent float64 `json:"partnerBonusPercent"`
  34 + //业务员分红百分比
  35 + SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
  36 + OrderType int `json:"orderType"`
  37 +}
  38 +
  39 +func (command CreateOrderCommand) ValidateCommand() error {
  40 + if len(command.BuyerName) == 0 || len(command.BuyerPhone) == 0 {
  41 + return lib.ThrowError(lib.ARG_ERROR, "买家信息必填")
  42 + }
  43 + if len(command.BuyerAddress) == 0 {
  44 + return lib.ThrowError(lib.ARG_ERROR, "买家地址必填")
  45 + }
  46 + if len(command.OrderCode) == 0 {
  47 + return lib.ThrowError(lib.ARG_ERROR, "订单编号必填")
  48 + }
  49 + if len(command.OrderRegion) == 0 {
  50 + return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
  51 + }
  52 + return nil
  53 +}
1 package command 1 package command
  2 +
  3 +import "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
  4 +
  5 +type UpdateOrderCommand struct {
  6 + //id
  7 + Id int64 `json:"id"`
  8 + //订单编号
  9 + OrderCode string `json:"orderCode"`
  10 + //订单名称
  11 + OrderName string `json:"oderName"`
  12 + //数量
  13 + OrderCount int `json:"orderCount"`
  14 + //订单金额
  15 + OrderAmount float64 `json:"orderAmount"`
  16 + //买家
  17 + BuyerPhone string `json:"buyerPhone"`
  18 + //地址
  19 + BuyerAddress string `json:"address"`
  20 + //订单区域
  21 + OrderRegion string `json:"orderRegion"`
  22 + //合伙人分红百分比
  23 + PartnerBonusPercent float64 `json:"partnerBonusPercent"`
  24 + //业务员分红百分比
  25 + SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
  26 +}
  27 +
  28 +func (command UpdateOrderCommand) ValidateCommand() error {
  29 + if command.Id == 0 {
  30 + return lib.ThrowError(lib.ARG_ERROR, "订单id错误")
  31 + }
  32 + if len(command.BuyerPhone) == 0 {
  33 + return lib.ThrowError(lib.ARG_ERROR, "买家信息必填")
  34 + }
  35 + if len(command.BuyerAddress) == 0 {
  36 + return lib.ThrowError(lib.ARG_ERROR, "买家地址必填")
  37 + }
  38 + if len(command.OrderCode) == 0 {
  39 + return lib.ThrowError(lib.ARG_ERROR, "订单编号必填")
  40 + }
  41 + if len(command.OrderRegion) == 0 {
  42 + return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
  43 + }
  44 + return nil
  45 +}
  1 +package command
  2 +
  3 +import "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
  4 +
  5 +type UpdateOrderRealCommand struct {
  6 + //id
  7 + Id int64 `json:"id"`
  8 + //订单编号
  9 + OrderCode string `json:"orderCode"`
  10 + //订单名称
  11 + OrderName string `json:"oderName"`
  12 + //数量
  13 + OrderActualCount int `json:"orderActualCount"`
  14 + //订单金额
  15 + OrderActualAmount float64 `json:"orderActualAmount"`
  16 + //买家
  17 + BuyerPhone string `json:"buyerPhone"`
  18 + //地址
  19 + BuyerAddress string `json:"address"`
  20 + //订单区域
  21 + OrderRegion string `json:"orderRegion"`
  22 + //合伙人分红百分比
  23 + PartnerBonusPercent float64 `json:"partnerBonusPercent"`
  24 + //业务员分红百分比
  25 + SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
  26 + //状态
  27 + OrderStatus int `json:"orderStatus"`
  28 +}
  29 +
  30 +func (command UpdateOrderRealCommand) ValidateCommand() error {
  31 + if command.Id == 0 {
  32 + return lib.ThrowError(lib.ARG_ERROR, "订单id错误")
  33 + }
  34 + if len(command.BuyerPhone) == 0 {
  35 + return lib.ThrowError(lib.ARG_ERROR, "买家信息必填")
  36 + }
  37 + if len(command.BuyerAddress) == 0 {
  38 + return lib.ThrowError(lib.ARG_ERROR, "买家地址必填")
  39 + }
  40 + if len(command.OrderCode) == 0 {
  41 + return lib.ThrowError(lib.ARG_ERROR, "订单编号必填")
  42 + }
  43 + if len(command.OrderRegion) == 0 {
  44 + return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
  45 + }
  46 + return nil
  47 +}
@@ -9,5 +9,6 @@ type ListOrderQuery struct { @@ -9,5 +9,6 @@ type ListOrderQuery struct {
9 // 查询偏离量 9 // 查询偏离量
10 Offset int `json:"offset" ` 10 Offset int `json:"offset" `
11 // 查询限制 11 // 查询限制
12 - Limit int `json:"limit"` 12 + Limit int `json:"limit"`
  13 + OrderType int `json:"orderType"`
13 } 14 }
@@ -2,6 +2,7 @@ package service @@ -2,6 +2,7 @@ package service
2 2
3 import ( 3 import (
4 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" 4 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/command"
5 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/query" 6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/query"
6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" 7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" 8 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
@@ -43,10 +44,25 @@ func (service OrderService) PageListOrder(listOrderQuery query.ListOrderQuery) ( @@ -43,10 +44,25 @@ func (service OrderService) PageListOrder(listOrderQuery query.ListOrderQuery) (
43 if err != nil { 44 if err != nil {
44 return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 45 return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
45 } 46 }
  47 +
46 cnt, err = orderRepository.CountAll(query) 48 cnt, err = orderRepository.CountAll(query)
47 if err != nil { 49 if err != nil {
48 return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 50 return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
49 } 51 }
  52 + var PartnerInfoRepository domain.PartnerInfoRepository
  53 + if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
  54 + "transactionContext": transactionContext,
  55 + }); err != nil {
  56 + return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  57 + }
  58 + for i := range orders {
  59 + var partnerData *domain.PartnerInfo
  60 + partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: orders[i].PartnerInfo.Id})
  61 + if err != nil {
  62 + return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  63 + }
  64 + orders[i].PartnerInfo = partnerData.Partner
  65 + }
50 return orders, cnt, nil 66 return orders, cnt, nil
51 } 67 }
52 68
@@ -74,9 +90,251 @@ func (service OrderService) GetOrder(getOrderQuery query.GetOrderQuery) (*domain @@ -74,9 +90,251 @@ func (service OrderService) GetOrder(getOrderQuery query.GetOrderQuery) (*domain
74 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 90 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
75 } 91 }
76 92
  93 + var PartnerInfoRepository domain.PartnerInfoRepository
  94 + if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
  95 + "transactionContext": transactionContext,
  96 + }); err != nil {
  97 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  98 + }
  99 + var partnerData *domain.PartnerInfo
  100 + partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: order.PartnerInfo.Id})
  101 + if err != nil {
  102 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  103 + }
  104 + order.PartnerInfo = partnerData.Partner
  105 +
77 return order, nil 106 return order, nil
78 } 107 }
79 108
80 -func (service OrderService) CreateOrde() error { 109 +//CreateOrderPurpose 创建意向单
  110 +func (service OrderService) CreateOrderPurpose(command command.CreateOrderCommand) error {
  111 + var (
  112 + transactionContext, _ = factory.CreateTransactionContext(nil)
  113 + err error
  114 + )
  115 + if err = command.ValidateCommand(); err != nil {
  116 + return lib.ThrowError(lib.ARG_ERROR, err.Error())
  117 + }
  118 + if err = transactionContext.StartTransaction(); err != nil {
  119 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  120 + }
  121 + defer func() {
  122 + transactionContext.RollbackTransaction()
  123 + }()
  124 +
  125 + var PartnerInfoRepository domain.PartnerInfoRepository
  126 + if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
  127 + "transactionContext": transactionContext,
  128 + }); err != nil {
  129 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  130 + }
  131 + var partnerData *domain.PartnerInfo
  132 + partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: command.PartnerId})
  133 + if err != nil {
  134 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  135 + }
  136 + var orderRepository domain.OrderRepository
  137 + if orderRepository, err = factory.CreateOrderRepository(map[string]interface{}{
  138 + "transactionContext": transactionContext,
  139 + }); err != nil {
  140 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  141 + }
  142 + newOrder := &domain.Order{
  143 + //订单类型
  144 + OrderType: domain.OrderIntention,
  145 + //订单编号
  146 + OrderCode: command.OrderCode,
  147 + //订单名称
  148 + OrderName: command.OrderName,
  149 + //订单状态
  150 + OrderStatus: domain.OrderStatusReserve,
  151 + //数量
  152 + OrderCount: command.OrderCount,
  153 + //实际数量
  154 + OrderActualCount: 0,
  155 + //订单金额
  156 + OrderAmount: command.OrderAmount,
  157 + //实际订单金额
  158 + OrderActualAmount: 0,
  159 + //订单已支付分红金额(货款)
  160 + OrderPaymentAmount: 0,
  161 + //订单区域信息
  162 + OrderRegionInfo: domain.RegionInfo{
  163 + RegionName: command.OrderRegion,
  164 + },
  165 + //买家
  166 + Buyer: domain.Buyer{
  167 + BuyerName: command.BuyerName,
  168 + ShippingAddress: command.BuyerAddress,
  169 + ContactInfo: command.BuyerPhone,
  170 + },
  171 + PartnerInfo: partnerData.Partner,
  172 + //合伙人分红百分比
  173 + PartnerBonusPercent: command.PartnerBonusPercent,
  174 + //业务员分红百分比
  175 + SalesmanBonusPercent: command.SalesmanBonusPercent,
  176 + }
  177 + err = orderRepository.Save(newOrder)
  178 + if err != nil {
  179 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  180 + }
  181 + err = transactionContext.CommitTransaction()
  182 + if err != nil {
  183 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  184 + }
  185 + return nil
  186 +}
  187 +
  188 +//UpdateOrderPurpose 更新意向单
  189 +func (service OrderService) UpdateOrderPurpose(command command.UpdateOrderCommand) error {
  190 + var (
  191 + transactionContext, _ = factory.CreateTransactionContext(nil)
  192 + err error
  193 + )
  194 + if err = command.ValidateCommand(); err != nil {
  195 + return lib.ThrowError(lib.ARG_ERROR, err.Error())
  196 + }
  197 + if err = transactionContext.StartTransaction(); err != nil {
  198 + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  199 + }
  200 + defer func() {
  201 + transactionContext.RollbackTransaction()
  202 + }()
  203 + var (
  204 + orderRepository domain.OrderRepository
  205 + orderData *domain.Order
  206 + )
  207 + if orderRepository, err = factory.CreateOrderRepository(map[string]interface{}{
  208 + "transactionContext": transactionContext,
  209 + }); err != nil {
  210 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  211 + }
  212 + orderData, err = orderRepository.FindOne(domain.OrderFindOneQuery{
  213 + OrderId: command.Id,
  214 + })
  215 + if err != nil {
  216 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  217 + }
  218 + err = orderData.Update(map[string]interface{}{
  219 + //订单编号
  220 + "orderCode": command.OrderCode,
  221 + "oderName": command.OrderName,
  222 + "orderCount": command.OrderCount,
  223 + "orderAmount": command.OrderAmount,
  224 + "buyer": domain.Buyer{
  225 + BuyerName: orderData.Buyer.BuyerName,
  226 + ContactInfo: command.BuyerPhone,
  227 + ShippingAddress: command.BuyerAddress,
  228 + },
  229 + "orderRegion": domain.RegionInfo{
  230 + RegionName: command.OrderRegion,
  231 + },
  232 + "partnerBonusPercent": command.PartnerBonusPercent,
  233 + "salesmanBonusPercent": command.SalesmanBonusPercent,
  234 + })
  235 + if err != nil {
  236 + return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
  237 + }
  238 + err = orderRepository.Save(orderData)
  239 + if err != nil {
  240 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  241 + }
  242 + err = transactionContext.CommitTransaction()
  243 + if err != nil {
  244 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  245 + }
  246 + return nil
  247 +}
  248 +
  249 +//RemoveOrder 删除意向单
  250 +func (service OrderService) RemoveOrder(id int64) error {
  251 + //实际业务
  252 + transactionContext, err := factory.CreateTransactionContext(nil)
  253 + if err != nil {
  254 + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  255 + }
  256 + var (
  257 + orderRepository domain.OrderRepository
  258 + order *domain.Order
  259 + )
  260 + if value, err := factory.CreateOrderRepository(map[string]interface{}{
  261 + "transactionContext": transactionContext,
  262 + }); err != nil {
  263 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  264 + } else {
  265 + orderRepository = value
  266 + }
  267 + order, err = orderRepository.FindOne(domain.OrderFindOneQuery{
  268 + OrderId: id,
  269 + })
  270 + if err != nil {
  271 + return lib.ThrowError(lib.RES_NO_FIND_ERROR, err.Error())
  272 + }
  273 + err = orderRepository.Remove(order.Id)
  274 + if err != nil {
  275 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  276 + }
  277 + return nil
  278 +}
  279 +
  280 +//UpdateOrderReal 更新实发单
  281 +func (service OrderService) UpdateOrderReal(command command.UpdateOrderRealCommand) error {
  282 + var (
  283 + transactionContext, _ = factory.CreateTransactionContext(nil)
  284 + err error
  285 + )
  286 + if err = command.ValidateCommand(); err != nil {
  287 + return lib.ThrowError(lib.ARG_ERROR, err.Error())
  288 + }
  289 + if err = transactionContext.StartTransaction(); err != nil {
  290 + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  291 + }
  292 + defer func() {
  293 + transactionContext.RollbackTransaction()
  294 + }()
  295 + var (
  296 + orderRepository domain.OrderRepository
  297 + orderData *domain.Order
  298 + )
  299 + if orderRepository, err = factory.CreateOrderRepository(map[string]interface{}{
  300 + "transactionContext": transactionContext,
  301 + }); err != nil {
  302 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  303 + }
  304 + orderData, err = orderRepository.FindOne(domain.OrderFindOneQuery{
  305 + OrderId: command.Id,
  306 + })
  307 + if err != nil {
  308 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  309 + }
  310 + err = orderData.Update(map[string]interface{}{
  311 + //订单编号
  312 + "orderCode": command.OrderCode,
  313 + "oderName": command.OrderName,
  314 + "orderActualCount": command.OrderActualCount,
  315 + "orderActualAmount": command.OrderActualAmount,
  316 + "buyer": domain.Buyer{
  317 + BuyerName: orderData.Buyer.BuyerName,
  318 + ContactInfo: command.BuyerPhone,
  319 + ShippingAddress: command.BuyerAddress,
  320 + },
  321 + "orderRegion": domain.RegionInfo{
  322 + RegionName: command.OrderRegion,
  323 + },
  324 + "partnerBonusPercent": command.PartnerBonusPercent,
  325 + "salesmanBonusPercent": command.SalesmanBonusPercent,
  326 + "orderStatus": command.OrderStatus,
  327 + })
  328 + if err != nil {
  329 + return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
  330 + }
  331 + err = orderRepository.Save(orderData)
  332 + if err != nil {
  333 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  334 + }
  335 + err = transactionContext.CommitTransaction()
  336 + if err != nil {
  337 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  338 + }
81 return nil 339 return nil
82 } 340 }
1 package domain 1 package domain
2 2
3 -import "time" 3 +import (
  4 + "time"
  5 +)
4 6
5 const ( 7 const (
6 OrderStatusReserve = iota + 1 //预定中 8 OrderStatusReserve = iota + 1 //预定中
@@ -44,11 +46,11 @@ type Order struct { @@ -44,11 +46,11 @@ type Order struct {
44 //订单已支付分红金额(货款) 46 //订单已支付分红金额(货款)
45 OrderPaymentAmount float64 `json:"orderPaymentAmount"` 47 OrderPaymentAmount float64 `json:"orderPaymentAmount"`
46 //订单区域信息 48 //订单区域信息
47 - OrderRegionInfo *RegionInfo `json:"orderRegionInfo"` 49 + OrderRegionInfo RegionInfo `json:"orderRegionInfo"`
48 //买家 50 //买家
49 - Buyer *Buyer `json:"buyer"` 51 + Buyer Buyer `json:"buyer"`
50 //合伙人数据 52 //合伙人数据
51 - PartnerInfo *Partner `json:"partnerInfo"` 53 + PartnerInfo Partner `json:"partnerInfo"`
52 //合伙人分红百分比 54 //合伙人分红百分比
53 PartnerBonusPercent float64 `json:"partnerBonusPercent"` 55 PartnerBonusPercent float64 `json:"partnerBonusPercent"`
54 //业务员分红百分比 56 //业务员分红百分比
@@ -61,7 +63,49 @@ type Order struct { @@ -61,7 +63,49 @@ type Order struct {
61 } 63 }
62 64
63 //TODO 65 //TODO
64 -func (order Order) Update(data map[string]interface{}) error { 66 +func (order *Order) Update(data map[string]interface{}) error {
  67 + if v, ok := data["orderType"]; ok {
  68 + order.OrderType = v.(int)
  69 + }
  70 + if v, ok := data["orderCode"]; ok {
  71 + order.OrderCode = v.(string)
  72 + }
  73 + if v, ok := data["oderName"]; ok {
  74 + order.OrderName = v.(string)
  75 + }
  76 + if v, ok := data["orderStatus"]; ok {
  77 + order.OrderStatus = v.(int)
  78 + }
  79 + if v, ok := data["orderCount"]; ok {
  80 + order.OrderCount = v.(int)
  81 + }
  82 + if v, ok := data["orderActualCount"]; ok {
  83 + order.OrderActualCount = v.(int)
  84 + }
  85 + if v, ok := data["orderAmount"]; ok {
  86 + order.OrderAmount = v.(float64)
  87 + }
  88 + if v, ok := data["orderActualAmount"]; ok {
  89 + order.OrderActualAmount = v.(float64)
  90 + }
  91 + if v, ok := data["orderPaymentAmount"]; ok {
  92 + order.OrderPaymentAmount = v.(float64)
  93 + }
  94 + if v, ok := data["orderRegion"]; ok {
  95 + order.OrderRegionInfo = v.(RegionInfo)
  96 + }
  97 + if v, ok := data["buyer"]; ok {
  98 + order.Buyer = v.(Buyer)
  99 + }
  100 + if v, ok := data["partnerInfo"]; ok {
  101 + order.PartnerInfo = v.(Partner)
  102 + }
  103 + if v, ok := data["partnerBonusPercent"]; ok {
  104 + order.PartnerBonusPercent = v.(float64)
  105 + }
  106 + if v, ok := data["salesmanBonusPercent"]; ok {
  107 + order.SalesmanBonusPercent = v.(float64)
  108 + }
65 return nil 109 return nil
66 } 110 }
67 111
@@ -74,6 +118,7 @@ type OrderFindQuery struct { @@ -74,6 +118,7 @@ type OrderFindQuery struct {
74 OrderCode string 118 OrderCode string
75 Offset int 119 Offset int
76 Limit int 120 Limit int
  121 + OrderType int
77 } 122 }
78 123
79 type OrderRepository interface { 124 type OrderRepository interface {
@@ -81,4 +126,5 @@ type OrderRepository interface { @@ -81,4 +126,5 @@ type OrderRepository interface {
81 FindOne(qureyOptions OrderFindOneQuery) (*Order, error) 126 FindOne(qureyOptions OrderFindOneQuery) (*Order, error)
82 Find(queryOptions OrderFindQuery) ([]Order, error) 127 Find(queryOptions OrderFindQuery) ([]Order, error)
83 CountAll(queryOption OrderFindQuery) (int, error) 128 CountAll(queryOption OrderFindQuery) (int, error)
  129 + Remove(id int64) error
84 } 130 }
@@ -2,6 +2,7 @@ package dao @@ -2,6 +2,7 @@ package dao
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 +
5 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" 6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" 7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
7 ) 8 )
@@ -27,6 +28,15 @@ func (dao *OrderDao) Update(options map[string]interface{}) (err error) { @@ -27,6 +28,15 @@ func (dao *OrderDao) Update(options map[string]interface{}) (err error) {
27 return 28 return
28 } 29 }
29 30
  31 +func (dao *OrderDao) OrderCodeIsExist(code string, orderType int) (bool, error) {
  32 + tx := dao.transactionContext.PgDd
  33 + ok, err := tx.Model(new(models.Order)).
  34 + Where("order_code=?", code).
  35 + Where("order_type=?", orderType).
  36 + Exists()
  37 + return ok, err
  38 +}
  39 +
30 func (dao *OrderDao) GetOrderBaseInfo(id int64) (data map[string]interface{}, err error) { 40 func (dao *OrderDao) GetOrderBaseInfo(id int64) (data map[string]interface{}, err error) {
31 tx := dao.transactionContext.PgTx 41 tx := dao.transactionContext.PgTx
32 order := new(models.Order) 42 order := new(models.Order)
@@ -33,9 +33,9 @@ type Order struct { @@ -33,9 +33,9 @@ type Order struct {
33 //最后分红状态 33 //最后分红状态
34 BonusStatus int 34 BonusStatus int
35 //订单区域信息 35 //订单区域信息
36 - OrderRegionInfo *domain.RegionInfo 36 + OrderRegionInfo domain.RegionInfo
37 37
38 - Buyer *domain.Buyer 38 + Buyer domain.Buyer
39 //合伙人编号 39 //合伙人编号
40 PartnerId int64 40 PartnerId int64
41 PartnerInfo PartnerInfo `pg:"fk:partner_id"` 41 PartnerInfo PartnerInfo `pg:"fk:partner_id"`
@@ -37,7 +37,7 @@ func (reponsitory OrderRepository) transformPgModelToDomainModel(orderModel *mod @@ -37,7 +37,7 @@ func (reponsitory OrderRepository) transformPgModelToDomainModel(orderModel *mod
37 OrderPaymentAmount: orderModel.OrderPaymentAmount, 37 OrderPaymentAmount: orderModel.OrderPaymentAmount,
38 OrderRegionInfo: orderModel.OrderRegionInfo, 38 OrderRegionInfo: orderModel.OrderRegionInfo,
39 Buyer: orderModel.Buyer, 39 Buyer: orderModel.Buyer,
40 - PartnerInfo: &domain.Partner{ 40 + PartnerInfo: domain.Partner{
41 Id: orderModel.PartnerId, 41 Id: orderModel.PartnerId,
42 }, 42 },
43 PartnerBonusPercent: orderModel.PartnerBonusPercent, 43 PartnerBonusPercent: orderModel.PartnerBonusPercent,
@@ -87,13 +87,15 @@ func (repository OrderRepository) Find(queryOption domain.OrderFindQuery) ([]dom @@ -87,13 +87,15 @@ func (repository OrderRepository) Find(queryOption domain.OrderFindQuery) ([]dom
87 db := repository.transactionContext.PgDd 87 db := repository.transactionContext.PgDd
88 orderModels := []models.Order{} 88 orderModels := []models.Order{}
89 query := db.Model(&orderModels) 89 query := db.Model(&orderModels)
90 -  
91 if queryOption.PartnerId > 0 { 90 if queryOption.PartnerId > 0 {
92 query = query.Where("order.partner_id=?", queryOption.PartnerId) 91 query = query.Where("order.partner_id=?", queryOption.PartnerId)
93 } 92 }
94 if len(queryOption.OrderCode) > 0 { 93 if len(queryOption.OrderCode) > 0 {
95 query = query.Where("order.order_code like ?", "%"+queryOption.OrderCode+"%") 94 query = query.Where("order.order_code like ?", "%"+queryOption.OrderCode+"%")
96 } 95 }
  96 + if queryOption.OrderType > 0 {
  97 + query = query.Where("order.order_type=?", queryOption.OrderType)
  98 + }
97 if queryOption.Offset > -1 { 99 if queryOption.Offset > -1 {
98 query = query.Offset(queryOption.Offset) 100 query = query.Offset(queryOption.Offset)
99 } 101 }
@@ -156,3 +158,15 @@ func (repository OrderRepository) FindOne(qureyOptions domain.OrderFindOneQuery) @@ -156,3 +158,15 @@ func (repository OrderRepository) FindOne(qureyOptions domain.OrderFindOneQuery)
156 result, err := repository.transformPgModelToDomainModel(m) 158 result, err := repository.transformPgModelToDomainModel(m)
157 return &result, err 159 return &result, err
158 } 160 }
  161 +
  162 +func (repository OrderRepository) Remove(id int64) error {
  163 + var (
  164 + err error
  165 + tx = repository.transactionContext.PgTx
  166 + )
  167 + m := &models.Order{
  168 + Id: id,
  169 + }
  170 + _, err = tx.Model(m).WherePK().Delete()
  171 + return err
  172 +}
  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/order/command"
  9 + orderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/query"
  10 + orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/service"
  11 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  12 +)
  13 +
  14 +type OrderController struct {
  15 + BaseController
  16 +}
  17 +
  18 +////Prepare 重写 BaseController 的Prepare方法
  19 +func (c *OrderController) Prepare() {
  20 + c.BaseController.Prepare()
  21 + if ok := c.ValidJWTToken(); !ok {
  22 + return
  23 + }
  24 + if ok := c.ValidAdminPermission(domain.PERMINSSION_ADMIN_USER); !ok {
  25 + return
  26 + }
  27 +}
  28 +
  29 +type orderDetail struct {
  30 + //买家姓名
  31 + Buyer string `json:"buyer"`
  32 + //买家联系方式
  33 + BuyerPhone string `json:"buyerPhone"`
  34 + //收货地址
  35 + Address string `json:"address"`
  36 + //对应合伙人 id
  37 + Partner int64 `json:"partner"`
  38 + //合伙人抽成比例
  39 + PartnerRatio float64 `json:"partnerRatio"`
  40 + //业务员抽成比例
  41 + SalesmanRatio float64 `json:"salesmanRatio"`
  42 + //订单号
  43 + OrderId string `json:"orderId"`
  44 + //订单名称
  45 + OrderName string `json:"orderName"`
  46 + //订单数量
  47 + OrderNum int `json:"orderNum"`
  48 + //订单金额
  49 + OrderPrice float64 `json:"orderPrice"`
  50 + //订单区域
  51 + OrderDist string `json:"orderDist"`
  52 + //id
  53 + Id int64 `json:"id"`
  54 +}
  55 +
  56 +//UpdateOrderPurpose 更新意向订单
  57 +func (c *OrderController) UpdateOrderPurpose() {
  58 + //用与适配前端定义的数据结构
  59 + var (
  60 + param orderDetail
  61 + err error
  62 + )
  63 + if err = c.BindJsonData(&param); err != nil {
  64 + logs.Error(err)
  65 + c.ResponseError(errors.New("json数据解析失败"))
  66 + return
  67 + }
  68 + if param.Id == 0 {
  69 + err = c.addOrderPurpose(param)
  70 + } else {
  71 + err = c.editOrderPurpose(param)
  72 + }
  73 + if err != nil {
  74 + c.ResponseError(err)
  75 + }
  76 + c.ResponseData(nil)
  77 + return
  78 +}
  79 +
  80 +func (c *OrderController) addOrderPurpose(param orderDetail) error {
  81 + orderSrv := orderService.NewOrderService(nil)
  82 + Createcmd := orderCmd.CreateOrderCommand{
  83 + //订单区域
  84 + OrderRegion: param.OrderDist,
  85 + //订单编号
  86 + OrderCode: param.OrderId,
  87 + //订单名称
  88 + OrderName: param.OrderName,
  89 + //数量
  90 + OrderCount: param.OrderNum,
  91 + //订单金额
  92 + OrderAmount: param.OrderPrice,
  93 + //买家
  94 + BuyerName: param.Buyer,
  95 + //买家电话
  96 + BuyerPhone: param.BuyerPhone,
  97 + //地址
  98 + BuyerAddress: param.Address,
  99 + //合伙人数据
  100 + PartnerId: param.Partner,
  101 + //合伙人分红百分比
  102 + PartnerBonusPercent: param.PartnerRatio,
  103 + //业务员分红百分比
  104 + SalesmanBonusPercent: param.SalesmanRatio,
  105 + }
  106 + err := orderSrv.CreateOrderPurpose(Createcmd)
  107 + return err
  108 +}
  109 +
  110 +func (c *OrderController) editOrderPurpose(param orderDetail) error {
  111 + updateCmd := orderCmd.UpdateOrderCommand{
  112 + Id: param.Id,
  113 + //订单区域
  114 + OrderRegion: param.OrderDist,
  115 + //订单编号
  116 + OrderCode: param.OrderId,
  117 + //订单名称
  118 + OrderName: param.OrderName,
  119 + //数量
  120 + OrderCount: param.OrderNum,
  121 + //订单金额
  122 + OrderAmount: param.OrderPrice,
  123 + //买家电话
  124 + BuyerPhone: param.BuyerPhone,
  125 + //地址
  126 + BuyerAddress: param.Address,
  127 + //合伙人分红百分比
  128 + PartnerBonusPercent: param.PartnerRatio,
  129 + //业务员分红百分比
  130 + SalesmanBonusPercent: param.SalesmanRatio,
  131 + }
  132 + orderSrv := orderService.NewOrderService(nil)
  133 + err := orderSrv.UpdateOrderPurpose(updateCmd)
  134 + return err
  135 +}
  136 +
  137 +//GetOrderPurpose 获取意向订单
  138 +func (c *OrderController) GetOrderPurpose() {
  139 + type Parameter struct {
  140 + Id string `json:"id"`
  141 + }
  142 + var (
  143 + param Parameter
  144 + err error
  145 + )
  146 + if err = c.BindJsonData(&param); err != nil {
  147 + logs.Error(err)
  148 + c.ResponseError(errors.New("json数据解析失败"))
  149 + return
  150 + }
  151 + orderid, _ := strconv.ParseInt(param.Id, 10, 64)
  152 + orderSrv := orderService.NewOrderService(nil)
  153 + orderinfo, err := orderSrv.GetOrder(orderQuery.GetOrderQuery{
  154 + OrderId: orderid,
  155 + })
  156 + if err != nil {
  157 + c.ResponseError(err)
  158 + return
  159 + }
  160 + rsp := map[string]interface{}{
  161 + "createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),
  162 + "updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),
  163 + "buyer": orderinfo.Buyer.BuyerName,
  164 + "buyerPhone": orderinfo.Buyer.ContactInfo,
  165 + "Address": orderinfo.Buyer.ShippingAddress,
  166 + "id": orderinfo.Id,
  167 + "partner": orderinfo.PartnerInfo.Id,
  168 + "partnerRatio": orderinfo.PartnerBonusPercent,
  169 + "salesmanRatio": orderinfo.SalesmanBonusPercent,
  170 + "orderId": orderinfo.OrderCode,
  171 + "orderName": orderinfo.OrderName,
  172 + "OrderNum": orderinfo.OrderCount,
  173 + "orderPrice": orderinfo.OrderAmount,
  174 + "orderDist": orderinfo.OrderRegionInfo.RegionName,
  175 + "orderStatue": orderinfo.OrderStatus,
  176 + }
  177 + c.ResponseData(rsp)
  178 +}
  179 +
  180 +//PageListOrderPurpose 分页获取意向订单列表
  181 +func (c *OrderController) PageListOrderPurpose() {
  182 + type Parameter struct {
  183 + SearchText string `json:"searchText"`
  184 + Partner int64 `json:"parter"`
  185 + PageSize int `json:"pageSize"`
  186 + PageNumber int `json:"pageNumber"`
  187 + }
  188 + var (
  189 + param Parameter
  190 + err error
  191 + )
  192 + if err = c.BindJsonData(&param); err != nil {
  193 + logs.Error(err)
  194 + c.ResponseError(errors.New("json数据解析失败"))
  195 + return
  196 + }
  197 + if param.PageNumber == 0 {
  198 + param.PageNumber = 1
  199 + }
  200 + if param.PageSize == 0 {
  201 + param.PageSize = 20
  202 + }
  203 +
  204 + orderSrv := orderService.NewOrderService(nil)
  205 + orderinfos, cnt, err := orderSrv.PageListOrder(orderQuery.ListOrderQuery{
  206 + PartnerId: param.Partner,
  207 + OrderCode: param.SearchText,
  208 + OrderType: domain.OrderIntention,
  209 + Limit: param.PageSize,
  210 + Offset: (param.PageNumber - 1) * param.PageSize,
  211 + })
  212 + if err != nil {
  213 + c.ResponseError(err)
  214 + return
  215 + }
  216 + rsp := []map[string]interface{}{}
  217 + for i := range orderinfos {
  218 + orderinfo := orderinfos[i]
  219 + m := map[string]interface{}{
  220 + "createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),
  221 + "updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),
  222 + "buyer": orderinfo.Buyer.BuyerName,
  223 + "id": orderinfo.Id,
  224 + "orderId": orderinfo.OrderCode,
  225 + "partner": orderinfo.PartnerInfo.PartnerName,
  226 + "partnerRatio": orderinfo.PartnerBonusPercent,
  227 + "orderName": orderinfo.OrderName,
  228 + "OrderNum": orderinfo.OrderCount,
  229 + "orderPrice": orderinfo.OrderAmount,
  230 + "orderDist": orderinfo.OrderRegionInfo.RegionName,
  231 + "orderStatue": orderinfo.OrderStatus,
  232 + }
  233 + rsp = append(rsp, m)
  234 + }
  235 + c.ResponsePageList(rsp, cnt, param.PageNumber)
  236 +}
  237 +
  238 +//RemoveOrderPurpose 删除意向订单
  239 +func (c *OrderController) RemoveOrderPurpose() {
  240 + type Parameter struct {
  241 + Id int64 `json:"id"`
  242 + }
  243 + var (
  244 + param Parameter
  245 + err error
  246 + )
  247 + if err = c.BindJsonData(&param); err != nil {
  248 + logs.Error(err)
  249 + c.ResponseError(errors.New("json数据解析失败"))
  250 + return
  251 + }
  252 + orderSrv := orderService.NewOrderService(nil)
  253 + err = orderSrv.RemoveOrder(param.Id)
  254 + if err != nil {
  255 + c.ResponseError(err)
  256 + return
  257 + }
  258 + c.ResponseData(nil)
  259 +}
  260 +
  261 +//PageListOrderReal 分页获取实发订单列表
  262 +func (c *OrderController) PageListOrderReal() {
  263 + type Parameter struct {
  264 + SearchText string `json:"searchText"`
  265 + Partner int64 `json:"parter"`
  266 + PageSize int `json:"pageSize"`
  267 + PageNumber int `json:"pageNumber"`
  268 + }
  269 + var (
  270 + param Parameter
  271 + err error
  272 + )
  273 + if err = c.BindJsonData(&param); err != nil {
  274 + logs.Error(err)
  275 + c.ResponseError(errors.New("json数据解析失败"))
  276 + return
  277 + }
  278 + if param.PageNumber == 0 {
  279 + param.PageNumber = 1
  280 + }
  281 + if param.PageSize == 0 {
  282 + param.PageSize = 20
  283 + }
  284 +
  285 + orderSrv := orderService.NewOrderService(nil)
  286 + orderinfos, cnt, err := orderSrv.PageListOrder(orderQuery.ListOrderQuery{
  287 + PartnerId: param.Partner,
  288 + OrderCode: param.SearchText,
  289 + OrderType: domain.OrderReal,
  290 + Limit: param.PageSize,
  291 + Offset: (param.PageNumber - 1) * param.PageSize,
  292 + })
  293 + if err != nil {
  294 + c.ResponseError(err)
  295 + return
  296 + }
  297 + rsp := []map[string]interface{}{}
  298 + for i := range orderinfos {
  299 + orderinfo := orderinfos[i]
  300 + m := map[string]interface{}{
  301 + "createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),
  302 + "updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),
  303 + "buyer": orderinfo.Buyer.BuyerName,
  304 + "id": orderinfo.Id,
  305 + "orderId": orderinfo.OrderCode,
  306 + "partner": orderinfo.PartnerInfo.PartnerName,
  307 + "partnerRatio": orderinfo.PartnerBonusPercent,
  308 + "orderName": orderinfo.OrderName,
  309 + "OrderNum": orderinfo.OrderCount,
  310 + "orderPrice": orderinfo.OrderAmount,
  311 + "orderDist": orderinfo.OrderRegionInfo.RegionName,
  312 + "orderStatue": orderinfo.OrderStatus,
  313 + }
  314 + rsp = append(rsp, m)
  315 + }
  316 + c.ResponsePageList(rsp, cnt, param.PageNumber)
  317 +}
  318 +
  319 +//UpdateOrderPurpose 意向订单转实发单
  320 +func (c *OrderController) OrderPurposeToReal() {
  321 + //用与适配前端定义的数据结构
  322 + var (
  323 + param orderDetail
  324 + err error
  325 + )
  326 + if err = c.BindJsonData(&param); err != nil {
  327 + logs.Error(err)
  328 + c.ResponseError(errors.New("json数据解析失败"))
  329 + return
  330 + }
  331 +
  332 + c.ResponseData(nil)
  333 + return
  334 +}
@@ -32,6 +32,16 @@ func init() { @@ -32,6 +32,16 @@ func init() {
32 beego.NSRouter("/detail", &controllers.DividendsController{}, "POST:Detail"), 32 beego.NSRouter("/detail", &controllers.DividendsController{}, "POST:Detail"),
33 beego.NSRouter("/list", &controllers.DividendsController{}, "POST:List"), 33 beego.NSRouter("/list", &controllers.DividendsController{}, "POST:List"),
34 ), 34 ),
  35 + beego.NSNamespace("/order",
  36 + beego.NSRouter("/purpose/list", &controllers.OrderController{}, "POST:PageListOrderPurpose"),
  37 + beego.NSRouter("/purpose/update", &controllers.OrderController{}, "POST:UpdateOrderPurpose"),
  38 + beego.NSRouter("/purpose/detail", &controllers.OrderController{}, "POST:GetOrderPurpose"),
  39 + beego.NSRouter("/purpose/del", &controllers.OrderController{}, "POST:RemoveOrderPurpose"),
  40 +
  41 + beego.NSRouter("/actual/list", &controllers.OrderController{}, "POST:PageListOrderReal"),
  42 + beego.NSRouter("/actual/update", &controllers.OrderController{}, "POST:UpdateOrderPurpose"),
  43 + beego.NSRouter("/actual/detail", &controllers.OrderController{}, "POST:GetOrderPurpose"),
  44 + ),
35 ) 45 )
36 beego.AddNamespace(adminRouter) 46 beego.AddNamespace(adminRouter)
37 } 47 }