- fixed new order msg bug.

This commit is contained in:
gazebo
2018-06-18 16:00:03 +08:00
parent c6c14b1037
commit 861326c4eb
2 changed files with 25 additions and 23 deletions

View File

@@ -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
}

View File

@@ -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)