- fixed new order msg bug.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user