作者 唐旭辉

更新

... ... @@ -202,11 +202,11 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
//检查order_code是否重复
// if ok, err := orderBaseDao.OrderCodeExist(cmd.OrderCode); err != nil {
// return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
// } else if ok {
// return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在")
// }
if ok, err := orderBaseDao.OrderCodeExist(cmd.OrderCode, cmd.PartnerCategory, cmd.PartnerId); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在")
}
//检查delivery_code是否重复
if len(cmd.DeliveryCode) > 0 {
if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId); err != nil {
... ... @@ -388,11 +388,13 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
//检查order_code是否重复
// if ok, err := orderBaseDao.OrderCodeExist(cmd.OrderCode, cmd.Id); err != nil {
// return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
// } else if ok {
// return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在")
// }
if oldOrderData.OrderCode != cmd.OrderCode || cmd.PartnerCategory != oldOrderData.PartnerCategory.Id {
if ok, err := orderBaseDao.OrderCodeExist(cmd.OrderCode, cmd.PartnerCategory, cmd.PartnerId); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在")
}
}
//检查delivery_code是否重复
if cmd.DeliveryCode != oldOrderData.DeliveryCode {
if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId, cmd.Id); err != nil {
... ...
... ... @@ -23,13 +23,15 @@ func NewOrderBaseDao(transactionContext *transaction.TransactionContext) (*Order
}
}
func (dao OrderBaseDao) OrderCodeExist(code string, notId ...int64) (bool, error) {
//OrderCodeExist 检查order_code是否重复
//
func (dao OrderBaseDao) OrderCodeExist(code string, partnerCategory int64, partnerId int64) (bool, error) {
tx := dao.transactionContext.GetDB()
m := &models.OrderBase{}
query := tx.Model(m).Where("order_code=?", code)
if len(notId) > 0 {
query = query.WhereIn("id not in(?)", notId)
}
query := tx.Model(m).
Where("order_code=?", code).
Where("partner_id=?", partnerId).
Where(`partner_category @>'{"id":?}'`, partnerCategory)
ok, err := query.Exists()
return ok, err
}
... ...