47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package controllers
|
|
|
|
import (
|
|
"git.rosy.net.cn/jx-callback/business/legacymodel"
|
|
"git.rosy.net.cn/jx-callback/globals"
|
|
"github.com/astaxie/beego/orm"
|
|
)
|
|
|
|
const (
|
|
JD_VENDORID = 0
|
|
ELM_VENDORID = 2
|
|
)
|
|
|
|
func OnNewOrder(orderID string, vendorID int, userMobile string, jxStoreID int, db orm.Ormer, handler func(accepted bool)) int {
|
|
handleType := 0
|
|
if userMobile != "" {
|
|
if db == nil {
|
|
db = orm.NewOrm()
|
|
}
|
|
user := &legacymodel.BlackClient{
|
|
Mobile: userMobile,
|
|
}
|
|
if err := db.Read(user, "Mobile"); err != nil {
|
|
if err != orm.ErrNoRows {
|
|
globals.SugarLogger.Errorf("read data error:%v, data:%v, vendorID:%d", err, user, vendorID)
|
|
}
|
|
// 在访问数据库出错的情况下,也需要自动接单
|
|
handleType = 1
|
|
} else {
|
|
// 强制拒单
|
|
globals.SugarLogger.Infof("force reject order:%s, vendorID:%d", orderID, vendorID)
|
|
handleType = -1
|
|
}
|
|
} else {
|
|
globals.SugarLogger.Infof("order:%s, vendorID:%d, mobile is empty, should accept it", orderID, vendorID)
|
|
handleType = 1
|
|
}
|
|
|
|
if handleType == 1 {
|
|
handler(true)
|
|
} else if handleType == -1 {
|
|
handler(false)
|
|
}
|
|
|
|
return handleType
|
|
}
|