作者 tangxvhui

校验订单编号的唯一性

@@ -132,6 +132,14 @@ func (service OrderService) CreateOrder(command command.CreateOrderCommand) erro @@ -132,6 +132,14 @@ func (service OrderService) CreateOrder(command command.CreateOrderCommand) erro
132 transactionContext.RollbackTransaction() 132 transactionContext.RollbackTransaction()
133 }() 133 }()
134 134
  135 + orderDao, _ := factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
  136 + ok, err := orderDao.OrderCodeIsExist(command.OrderCode, 0)
  137 + if err != nil {
  138 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  139 + }
  140 + if ok {
  141 + return lib.ThrowError(lib.BUSINESS_ERROR, "订单编号已存在")
  142 + }
135 var PartnerInfoRepository domain.PartnerInfoRepository 143 var PartnerInfoRepository domain.PartnerInfoRepository
136 if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ 144 if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
137 "transactionContext": transactionContext, 145 "transactionContext": transactionContext,
@@ -210,6 +218,14 @@ func (service OrderService) UpdateOrderPurpose(command command.UpdateOrderComman @@ -210,6 +218,14 @@ func (service OrderService) UpdateOrderPurpose(command command.UpdateOrderComman
210 defer func() { 218 defer func() {
211 transactionContext.RollbackTransaction() 219 transactionContext.RollbackTransaction()
212 }() 220 }()
  221 + orderDao, _ := factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
  222 + ok, err := orderDao.OrderCodeIsExist(command.OrderCode, command.Id)
  223 + if err != nil {
  224 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  225 + }
  226 + if ok {
  227 + return lib.ThrowError(lib.BUSINESS_ERROR, "订单编号已存在")
  228 + }
213 var ( 229 var (
214 orderRepository domain.OrderRepository 230 orderRepository domain.OrderRepository
215 orderData *domain.Order 231 orderData *domain.Order
@@ -318,6 +334,14 @@ func (service OrderService) UpdateOrderReal(command command.UpdateOrderRealComma @@ -318,6 +334,14 @@ func (service OrderService) UpdateOrderReal(command command.UpdateOrderRealComma
318 defer func() { 334 defer func() {
319 transactionContext.RollbackTransaction() 335 transactionContext.RollbackTransaction()
320 }() 336 }()
  337 + orderDao, _ := factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
  338 + ok, err := orderDao.OrderCodeIsExist(command.OrderCode, command.Id)
  339 + if err != nil {
  340 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  341 + }
  342 + if ok {
  343 + return lib.ThrowError(lib.BUSINESS_ERROR, "订单编号已存在")
  344 + }
321 var ( 345 var (
322 orderRepository domain.OrderRepository 346 orderRepository domain.OrderRepository
323 orderData *domain.Order 347 orderData *domain.Order
@@ -28,11 +28,11 @@ func (dao *OrderDao) Update(options map[string]interface{}) (err error) { @@ -28,11 +28,11 @@ func (dao *OrderDao) Update(options map[string]interface{}) (err error) {
28 return 28 return
29 } 29 }
30 30
31 -func (dao *OrderDao) OrderCodeIsExist(code string, orderType int) (bool, error) { 31 +func (dao *OrderDao) OrderCodeIsExist(code string, notId int64) (bool, error) {
32 tx := dao.transactionContext.PgDd 32 tx := dao.transactionContext.PgDd
33 ok, err := tx.Model(new(models.Order)). 33 ok, err := tx.Model(new(models.Order)).
34 Where("order_code=?", code). 34 Where("order_code=?", code).
35 - Where("order_type=?", orderType). 35 + Where("id<>?", notId).
36 Exists() 36 Exists()
37 return ok, err 37 return ok, err
38 } 38 }
@@ -70,9 +70,6 @@ func (repository OrderRepository) Save(orderInfo *domain.Order) error { @@ -70,9 +70,6 @@ func (repository OrderRepository) Save(orderInfo *domain.Order) error {
70 PartnerId: orderInfo.PartnerInfo.Id, 70 PartnerId: orderInfo.PartnerInfo.Id,
71 PartnerBonusPercent: orderInfo.PartnerBonusPercent, 71 PartnerBonusPercent: orderInfo.PartnerBonusPercent,
72 SalesmanBonusPercent: orderInfo.SalesmanBonusPercent, 72 SalesmanBonusPercent: orderInfo.SalesmanBonusPercent,
73 - // CreateAt: orderInfo.CreateAt,  
74 - // UpdateAt: orderInfo.UpdateAt,  
75 - // LastViewTime: orderInfo.LastViewTime,  
76 } 73 }
77 if m.Id == 0 { 74 if m.Id == 0 {
78 err = tx.Insert(m) 75 err = tx.Insert(m)