作者 唐旭辉

更新

@@ -202,11 +202,11 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( @@ -202,11 +202,11 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (
202 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 202 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
203 } 203 }
204 //检查order_code是否重复 204 //检查order_code是否重复
205 - // if ok, err := orderBaseDao.OrderCodeExist(cmd.OrderCode); err != nil {  
206 - // return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
207 - // } else if ok {  
208 - // return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在")  
209 - // } 205 + if ok, err := orderBaseDao.OrderCodeExist(cmd.OrderCode, cmd.PartnerCategory, cmd.PartnerId); err != nil {
  206 + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  207 + } else if ok {
  208 + return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在")
  209 + }
210 //检查delivery_code是否重复 210 //检查delivery_code是否重复
211 if len(cmd.DeliveryCode) > 0 { 211 if len(cmd.DeliveryCode) > 0 {
212 if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId); err != nil { 212 if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId); err != nil {
@@ -388,11 +388,13 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) @@ -388,11 +388,13 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
388 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 388 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
389 } 389 }
390 //检查order_code是否重复 390 //检查order_code是否重复
391 - // if ok, err := orderBaseDao.OrderCodeExist(cmd.OrderCode, cmd.Id); err != nil {  
392 - // return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
393 - // } else if ok {  
394 - // return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在")  
395 - // } 391 + if oldOrderData.OrderCode != cmd.OrderCode || cmd.PartnerCategory != oldOrderData.PartnerCategory.Id {
  392 + if ok, err := orderBaseDao.OrderCodeExist(cmd.OrderCode, cmd.PartnerCategory, cmd.PartnerId); err != nil {
  393 + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  394 + } else if ok {
  395 + return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在")
  396 + }
  397 + }
396 //检查delivery_code是否重复 398 //检查delivery_code是否重复
397 if cmd.DeliveryCode != oldOrderData.DeliveryCode { 399 if cmd.DeliveryCode != oldOrderData.DeliveryCode {
398 if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId, cmd.Id); err != nil { 400 if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId, cmd.Id); err != nil {
@@ -23,13 +23,15 @@ func NewOrderBaseDao(transactionContext *transaction.TransactionContext) (*Order @@ -23,13 +23,15 @@ func NewOrderBaseDao(transactionContext *transaction.TransactionContext) (*Order
23 } 23 }
24 } 24 }
25 25
26 -func (dao OrderBaseDao) OrderCodeExist(code string, notId ...int64) (bool, error) { 26 +//OrderCodeExist 检查order_code是否重复
  27 +//
  28 +func (dao OrderBaseDao) OrderCodeExist(code string, partnerCategory int64, partnerId int64) (bool, error) {
27 tx := dao.transactionContext.GetDB() 29 tx := dao.transactionContext.GetDB()
28 m := &models.OrderBase{} 30 m := &models.OrderBase{}
29 - query := tx.Model(m).Where("order_code=?", code)  
30 - if len(notId) > 0 {  
31 - query = query.WhereIn("id not in(?)", notId)  
32 - } 31 + query := tx.Model(m).
  32 + Where("order_code=?", code).
  33 + Where("partner_id=?", partnerId).
  34 + Where(`partner_category @>'{"id":?}'`, partnerCategory)
33 ok, err := query.Exists() 35 ok, err := query.Exists()
34 return ok, err 36 return ok, err
35 } 37 }