- add black user .
This commit is contained in:
24
business/controllers/business.go
Normal file
24
business/controllers/business.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.rosy.net.cn/jx-callback/business/models"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
|
"github.com/astaxie/beego/orm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func IsAutoAcceptOrder(userMobile string, db orm.Ormer) bool {
|
||||||
|
if db == nil {
|
||||||
|
db = orm.NewOrm()
|
||||||
|
}
|
||||||
|
user := &models.BlackClient{
|
||||||
|
Mobile: userMobile,
|
||||||
|
}
|
||||||
|
if err := db.Read(user, "Mobile"); err != nil {
|
||||||
|
if err != orm.ErrNoRows {
|
||||||
|
globals.SugarLogger.Errorf("read data error:%v, data:%v", err, user)
|
||||||
|
}
|
||||||
|
// 在访问数据库出错的情况下,也需要自动接单
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.rosy.net.cn/baseapi"
|
||||||
"git.rosy.net.cn/baseapi/platformapi/elmapi"
|
"git.rosy.net.cn/baseapi/platformapi/elmapi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/controllers"
|
||||||
"git.rosy.net.cn/jx-callback/business/elm/models"
|
"git.rosy.net.cn/jx-callback/business/elm/models"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/globals2"
|
"git.rosy.net.cn/jx-callback/globals/globals2"
|
||||||
@@ -30,7 +32,13 @@ func (o *OrderController) OrderMessage(msg *elmapi.CallbackMsg) (retVal *elmapi.
|
|||||||
orderID := innerMsg["orderId"].(string)
|
orderID := innerMsg["orderId"].(string)
|
||||||
globals2.RoutinePool.CallFun(func() {
|
globals2.RoutinePool.CallFun(func() {
|
||||||
if msg.Type == elmapi.MsgTypeOrderValid {
|
if msg.Type == elmapi.MsgTypeOrderValid {
|
||||||
retVal = o.NewOrder(msg, orderID)
|
userMobile := ""
|
||||||
|
if phoneList, ok := innerMsg["phoneList"].([]interface{}); ok && len(phoneList) > 1 {
|
||||||
|
userMobile = phoneList[0].(string)
|
||||||
|
} else {
|
||||||
|
baseapi.SugarLogger.Warnf("can not get mobile info from %v, error:%v", msg, err)
|
||||||
|
}
|
||||||
|
retVal = o.NewOrder(msg, orderID, userMobile)
|
||||||
} else if msg.Type >= elmapi.MsgTypeMerchantValid && msg.Type <= elmapi.MsgTypeOrderFinished {
|
} else if msg.Type >= elmapi.MsgTypeMerchantValid && msg.Type <= elmapi.MsgTypeOrderFinished {
|
||||||
retVal = o.OrderStatusChanged(msg, orderID)
|
retVal = o.OrderStatusChanged(msg, orderID)
|
||||||
}
|
}
|
||||||
@@ -38,32 +46,46 @@ func (o *OrderController) OrderMessage(msg *elmapi.CallbackMsg) (retVal *elmapi.
|
|||||||
|
|
||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
func (o *OrderController) acceptOrder(orderID string, userMobile string) {
|
||||||
|
if controllers.IsAutoAcceptOrder(userMobile, nil) {
|
||||||
|
globals2.ElmAPI.ConfirmOrder(orderID)
|
||||||
|
if userMobile == "" {
|
||||||
|
globals.SugarLogger.Infof("elm order:%v force accepted, because userMobile is empty", orderID)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
globals.SugarLogger.Infof("elm order:%v refused, userMobile:%s", orderID, userMobile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (o *OrderController) NewOrder(msg *elmapi.CallbackMsg, orderId string) *elmapi.CallbackResponse {
|
func (o *OrderController) NewOrder(msg *elmapi.CallbackMsg, orderId string, userMobile string) *elmapi.CallbackResponse {
|
||||||
db := orm.NewOrm()
|
db := orm.NewOrm()
|
||||||
rec := &models.ELMOrder{
|
rec := &models.ELMOrder{
|
||||||
OrderId: orderId,
|
OrderId: orderId,
|
||||||
Type: msg.Type,
|
Type: msg.Type,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retVal := elmapi.SuccessResponse
|
||||||
created, _, err := db.ReadOrCreate(rec, "OrderId")
|
created, _, err := db.ReadOrCreate(rec, "OrderId")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
globals.SugarLogger.Warnf("error when calling ReadOrCreate, error:%v, rec:%v", err, rec)
|
globals.SugarLogger.Warnf("error when calling ReadOrCreate, error:%v, rec:%v", err, rec)
|
||||||
return errResponseDBError
|
retVal = errResponseDBError
|
||||||
}
|
} else {
|
||||||
if created || rec.Type != msg.Type {
|
if created || rec.Type != msg.Type {
|
||||||
result, err := globals2.ElmAPI.GetOrder(orderId)
|
result, err := globals2.ElmAPI.GetOrder(orderId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errResponseCallELMAPIError
|
retVal = errResponseCallELMAPIError
|
||||||
}
|
} else {
|
||||||
err = globals2.FreshFoodAPI.NewELMOrder(result)
|
err = globals2.FreshFoodAPI.NewELMOrder(result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errResponseInternal
|
retVal = errResponseInternal
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
globals.SugarLogger.Infof("duplicate elm msg received:%v", msg)
|
globals.SugarLogger.Infof("duplicate elm msg received:%v", msg)
|
||||||
}
|
}
|
||||||
return elmapi.SuccessResponse
|
}
|
||||||
|
o.acceptOrder(orderId, userMobile)
|
||||||
|
return retVal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OrderController) OrderStatusChanged(msg *elmapi.CallbackMsg, orderId string) *elmapi.CallbackResponse {
|
func (o *OrderController) OrderStatusChanged(msg *elmapi.CallbackMsg, orderId string) *elmapi.CallbackResponse {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/controllers"
|
||||||
"git.rosy.net.cn/jx-callback/business/jd/models"
|
"git.rosy.net.cn/jx-callback/business/jd/models"
|
||||||
"git.rosy.net.cn/jx-callback/compat/corm"
|
"git.rosy.net.cn/jx-callback/compat/corm"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
@@ -143,13 +144,21 @@ func (c *OrderController) OrderDeliveryStatus(jdOrderDeliveryStatusMsg *jdapi.Ca
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-----------
|
//-----------
|
||||||
func acceptOrder(msg *jdapi.CallbackOrderMsg) {
|
func acceptOrder(msg *jdapi.CallbackOrderMsg, userMobile string, db orm.Ormer) {
|
||||||
|
if controllers.IsAutoAcceptOrder(userMobile, db) {
|
||||||
globals2.Jdapi.OrderAcceptOperate(msg.BillID, true)
|
globals2.Jdapi.OrderAcceptOperate(msg.BillID, true)
|
||||||
|
if userMobile == "" {
|
||||||
|
globals.SugarLogger.Infof("jd order:%v force accepted, because userMobile is empty", msg)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
globals.SugarLogger.Infof("jd order:%v refused, userMobile:%s", msg, userMobile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newOrder(msg *jdapi.CallbackOrderMsg) error {
|
func newOrder(msg *jdapi.CallbackOrderMsg) error {
|
||||||
result, err := globals2.Jdapi.LegacyQuerySingleOrder(msg.BillID)
|
result, err := globals2.Jdapi.LegacyQuerySingleOrder(msg.BillID)
|
||||||
acceptOrder(msg)
|
userMobile := ""
|
||||||
|
var db orm.Ormer
|
||||||
if err == nil {
|
if err == nil {
|
||||||
rec := &models.Jdorder{
|
rec := &models.Jdorder{
|
||||||
ID: msg.ID,
|
ID: msg.ID,
|
||||||
@@ -175,8 +184,9 @@ func newOrder(msg *jdapi.CallbackOrderMsg) error {
|
|||||||
resultByteArr := utils.MustMarshal(data)
|
resultByteArr := utils.MustMarshal(data)
|
||||||
rec.Data = string(resultByteArr)
|
rec.Data = string(resultByteArr)
|
||||||
rec.Data4Json = data
|
rec.Data4Json = data
|
||||||
|
userMobile = rec.Data4Json["buyerMobile"].(string)
|
||||||
err = utils.CallFuncLogError(func() error {
|
err = utils.CallFuncLogError(func() error {
|
||||||
db := orm.NewOrm()
|
db = orm.NewOrm()
|
||||||
_, err := db.Update(rec, "Data", "Code", "Msg", "Success", "CityName", "OrderStatus", "OrderStatusTime")
|
_, err := db.Update(rec, "Data", "Code", "Msg", "Success", "CityName", "OrderStatus", "OrderStatusTime")
|
||||||
return err
|
return err
|
||||||
}, globals2.ErrStrAccessDB)
|
}, globals2.ErrStrAccessDB)
|
||||||
@@ -187,6 +197,7 @@ func newOrder(msg *jdapi.CallbackOrderMsg) error {
|
|||||||
globals.SugarLogger.Errorf("can not get jdorder info:%v", msg.BillID)
|
globals.SugarLogger.Errorf("can not get jdorder info:%v", msg.BillID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
acceptOrder(msg, userMobile, db)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
business/models/models.go
Normal file
12
business/models/models.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BlackClient struct {
|
||||||
|
ID int `orm:"column(id)"`
|
||||||
|
Mobile string `orm:"size(16);unique"`
|
||||||
|
CreatedAt time.Time `orm:"auto_now_add;type(datetime)`
|
||||||
|
UpdatedAt time.Time `orm:"auto_now;type(datetime)`
|
||||||
|
}
|
||||||
@@ -72,6 +72,7 @@ func initDB() {
|
|||||||
orm.RegisterModel(new(jdmodels.Jdorder))
|
orm.RegisterModel(new(jdmodels.Jdorder))
|
||||||
orm.RegisterModel(new(elmmodels.ELMOrder))
|
orm.RegisterModel(new(elmmodels.ELMOrder))
|
||||||
orm.RegisterModel(new(models.Config))
|
orm.RegisterModel(new(models.Config))
|
||||||
|
orm.RegisterModel(new(models.BlackClient))
|
||||||
|
|
||||||
// create table
|
// create table
|
||||||
orm.RunSyncdb("default", false, true)
|
orm.RunSyncdb("default", false, true)
|
||||||
|
|||||||
Reference in New Issue
Block a user