From 861326c4eb6a0d6343e41f3bb168eedf5522ff20 Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 18 Jun 2018 16:00:03 +0800 Subject: [PATCH] - fixed new order msg bug. --- business/freshfood/freshfood.go | 7 ++++-- business/jd/controller/order.go | 41 ++++++++++++++++----------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/business/freshfood/freshfood.go b/business/freshfood/freshfood.go index 39dd53147..eb7b011ba 100644 --- a/business/freshfood/freshfood.go +++ b/business/freshfood/freshfood.go @@ -91,10 +91,13 @@ func (f *FreshFoodAPI) AccessFreshFood(apiStr string, params url.Values) error { // _, err := f.client.PostForm(fullURL, params) err = error(nil) f.sugarLogger.Debug(fullURL) - if err != nil { - f.sugarLogger.Warnf("Call %s error:%v", fullURL, err) + if err == nil { + break } } + if err != nil { + f.sugarLogger.Warnf("Call %s error:%v", fullURL, err) + } return err } diff --git a/business/jd/controller/order.go b/business/jd/controller/order.go index b69c28373..e596671e5 100644 --- a/business/jd/controller/order.go +++ b/business/jd/controller/order.go @@ -17,7 +17,7 @@ const ( var ( errChecker corm.DBErrorChecker - orderMsgChan chan *jdapi.JDOrderMsg + orderMsgChan chan jdapi.JDOrderMsg ) type OrderController struct { @@ -26,7 +26,7 @@ type OrderController struct { func InitOrder() { errChecker = new(corm.MysqlErrorChecker) - orderMsgChan = make(chan *jdapi.JDOrderMsg, 128) + orderMsgChan = make(chan jdapi.JDOrderMsg, 128) go orderMsgHandlerRoutinue() // todo 这样操作在有多个进程时,会有问题 @@ -58,13 +58,13 @@ func orderMsgHandlerRoutinue() { for { msg := <-orderMsgChan globals.SugarLogger.Debugf("OrderMsgHandlerRoutinue:%v", msg) - go handleOrderMsg(msg) + go handleOrderMsg(&msg) } } func addOrderMsg(orderMsg *jdapi.JDOrderMsg) { globals.SugarLogger.Debugf("addOrderMsg:%v", orderMsg) - orderMsgChan <- orderMsg + orderMsgChan <- *orderMsg } func handleOrderMsg(orderMsg *jdapi.JDOrderMsg) { @@ -100,27 +100,26 @@ func (c *OrderController) OrderStatus(order *jdapi.JDOrderMsg) *jdapi.JDCallback if created, _, err := db.ReadOrCreate(rec, "Jdorderid"); err == nil { order.Id = rec.Id if created { - isStatusSame := order.StatusId == jdapi.JdOrderStatusNew - if !isStatusSame { - order.StatusId = jdapi.JdOrderStatusNew + if order.StatusId != jdapi.JdOrderStatusNew { globals.SugarLogger.Warnf("order:%s get %s before create", order.BillId, order.StatusId) + oldStatusId := order.StatusId + order.StatusId = jdapi.JdOrderStatusNew + addOrderMsg(order) + order.StatusId = oldStatusId } addOrderMsg(order) - - if !isStatusSame { - order.StatusId = utils.Int2Str(status) - } - } - if rec.OrderStatus != status { - rec.OrderStatus = status - rec.OrderStatusTime = order.Timestamp - rec.Code = MsgNotHandledCode - db.Update(rec, "OrderStatus", "OrderStatusTime", "Code") - - addOrderMsg(order) } else { - globals.SugarLogger.Warnf("duplicated jd orderid:%s", order.BillId) - globals.SugarLogger.Debug(rec) + if rec.OrderStatus != status { + rec.OrderStatus = status + rec.OrderStatusTime = order.Timestamp + rec.Code = MsgNotHandledCode + db.Update(rec, "OrderStatus", "OrderStatusTime", "Code") + + addOrderMsg(order) + } else { + globals.SugarLogger.Warnf("duplicated jd orderid:%s", order.BillId) + globals.SugarLogger.Debug(rec) + } } } else { globals.SugarLogger.Errorf("error when calling ReadOrCreate:%v", err)