- refactor.

This commit is contained in:
gazebo
2018-06-28 10:13:17 +08:00
parent acfb2512f5
commit b496b751bc
2 changed files with 34 additions and 39 deletions

View File

@@ -69,21 +69,22 @@ func (o *OrderController) OrderStatusChanged(msg *elmapi.CallbackMsg, orderId st
err := db.Read(rec, "OrderId")
if err != nil {
globals.SugarLogger.Warnf("error when calling ReadOrCreate, error:%v", err)
return errResponseDBError
}
if rec.Type != msg.Type {
err = globals2.FreshFoodAPI.ELMOrderStatus(orderId, msg.Type, utils.GetCurTimeStr())
if err != nil {
return errResponseInternal
} else {
rec.Type = msg.Type
utils.CallFuncLogError(func() error {
_, err := db.Update(rec, "Type")
return err
}, globals2.ErrStrAccessDB)
}
} else {
globals.SugarLogger.Infof("duplicate elm msg received:%v", msg)
if rec.Type != msg.Type {
err = globals2.FreshFoodAPI.ELMOrderStatus(orderId, msg.Type, utils.GetCurTimeStr())
if err == nil {
rec.Type = msg.Type
err = utils.CallFuncLogError(func() error {
_, err := db.Update(rec, "Type")
return err
}, globals2.ErrStrAccessDB)
}
} else {
globals.SugarLogger.Infof("duplicate elm msg received:%v", msg)
}
}
if err != nil {
return errResponseInternal
}
return elmapi.SuccessResponse
}