- 将IsMobileFake用IsStringLikeMobile替换

- 添加HandleOrder4Consignee, GetRealMobile4Order和GetAuthType4Vendor
- 添加GoodsOrder.VendorUserID
This commit is contained in:
gazebo
2019-09-04 18:50:25 +08:00
parent f50fdf2bab
commit a0bb7d37f0
10 changed files with 93 additions and 55 deletions

View File

@@ -51,7 +51,7 @@ func (c *OrderManager) LoadPendingOrders() []*model.GoodsOrder {
// OnOrderAdjust也类似而OrderStatus要记录的是消息所以添加这个
func (c *OrderManager) OnOrderNew(order *model.GoodsOrder, orderStatus *model.OrderStatus) (err error) {
globals.SugarLogger.Debugf("OnOrderNew orderID:%s", order.VendorOrderID)
if order.ConsigneeMobile2 == "" && !jxutils.IsMobileFake(order.ConsigneeMobile) {
if order.ConsigneeMobile2 == "" && jxutils.IsStringLikeMobile(order.ConsigneeMobile) {
order.ConsigneeMobile2 = order.ConsigneeMobile
}
@@ -84,7 +84,7 @@ func (c *OrderManager) OnOrderNew(order *model.GoodsOrder, orderStatus *model.Or
// todo 调整单的处理可能还需要再细化一点,当前只是简单的删除重建
func (c *OrderManager) OnOrderAdjust(order *model.GoodsOrder, orderStatus *model.OrderStatus) (err error) {
if order.ConsigneeMobile2 == "" && !jxutils.IsMobileFake(order.ConsigneeMobile) {
if order.ConsigneeMobile2 == "" && jxutils.IsStringLikeMobile(order.ConsigneeMobile) {
order.ConsigneeMobile2 = order.ConsigneeMobile
}

View File

@@ -125,23 +125,61 @@ func RegisterUserWithMobile(ctx *jxcontext.Context, user *model.User, mobileVeri
}
func HandleOrder4Consignee(order *model.GoodsOrder) (err error) {
// user := &model.User{
// Mobile:&order.ConsigneeMobile2
// }
// user.Type = model.UserTypeConsumer
// if err = CreateUser(user, ctx.GetUserName()); err == nil {
// if vendorID >= 0 {
// authBind := &model.AuthBind{
// UserID: user.GetID(),
// BindType: model.AuthBindTypeID,
// AuthID: vendorUserID,
// Type: model.VendorNames[vendorID],
// }
// dao.WrapAddIDCULDEntity(authBind, ctx.GetUserName())
// authBind.Status = model.AuthBindStatusNormal
// err = dao.CreateEntity(nil, authBind)
// }
// }
var user *model.User
authType := jxutils.GetAuthType4Vendor(order.VendorID)
if authType == "" {
msg := fmt.Sprintf("平台ID:%d当前不支持", order.VendorID)
globals.SugarLogger.Warn(msg)
return fmt.Errorf(msg)
}
oeratorName := order.VendorOrderID
mobileNumber := jxutils.GetRealMobile4Order(order)
db := dao.GetDB()
if mobileNumber != "" {
userList, _, err2 := dao.GetUsers(db, 0, "", nil, "", mobileNumber, 0, 0)
if err = err2; err != nil {
return err
}
if len(userList) > 0 {
user = userList[0]
}
}
vendorUserID := order.VendorUserID
if err == nil {
authList, err2 := dao.GetUserBindAuthInfo(db, "", model.AuthBindTypeID, "", []string{authType})
if err = err2; err != nil {
return err
}
if len(authList) > 0 {
if user, err = dao.GetUserByID(db, "UserID", authList[0].UserID); err != nil {
return err
}
}
}
if user == nil {
user = &model.User{
UserID2: mobileNumber,
Name: order.ConsigneeName,
Mobile: &mobileNumber,
Type: model.UserTypeConsumer,
Remark: order.VendorOrderID,
}
user.Type = model.UserTypeConsumer
err = CreateUser(user, oeratorName)
}
if err == nil && vendorUserID != "" {
authBind := &model.AuthBind{
UserID: user.GetID(),
BindType: model.AuthBindTypeID,
AuthID: vendorUserID,
Type: authType,
}
dao.WrapAddIDCULDEntity(authBind, oeratorName)
authBind.Status = model.AuthBindStatusNormal
err = dao.CreateEntity(nil, authBind)
}
return err
}

View File

@@ -152,7 +152,7 @@ func RefreshRealMobile(ctx *jxcontext.Context, vendorID int, fromTime, toTime ti
mobile, err2 := handler.GetOrderRealMobile(ctx, order)
if err = err2; err == nil {
mobile = jxutils.FormalizeMobile(mobile)
if !jxutils.IsMobileFake(mobile) && strings.Index(order.ConsigneeMobile, mobile) == -1 {
if jxutils.IsStringLikeMobile(mobile) && strings.Index(order.ConsigneeMobile, mobile) == -1 {
order.ConsigneeMobile2 = mobile
_, err = dao.UpdateEntity(db, order, "ConsigneeMobile2")
}

View File

@@ -664,13 +664,21 @@ func WriteFile(fileName string, binData []byte) error {
return err
}
// func GetRealMobile4Order(order *model.GoodsOrder) (mobileNumber string) {
// mobileNumber = order.ConsigneeMobile2
// if mobileNumber == "" {
// mobileNumber = order.ConsigneeMobile
// }
// if IsMobileFake(mobileNumber) {
// mobileNumber = ""
// }
// return mobileNumber
// }
func GetRealMobile4Order(order *model.GoodsOrder) (mobileNumber string) {
mobileNumber = order.ConsigneeMobile2
if mobileNumber == "" {
mobileNumber = order.ConsigneeMobile
}
if !IsStringLikeMobile(mobileNumber) {
mobileNumber = ""
}
return mobileNumber
}
func GetAuthType4Vendor(vendorID int) (authType string) {
authType = model.VendorNames[vendorID]
if authType != "" {
authType = "vendor." + authType
}
return authType
}

View File

@@ -370,11 +370,6 @@ func Int2OneZero(value int) int {
return 0
}
// 判断电话号码是否是假的,比如有****号
func IsMobileFake(mobile string) bool {
return len(mobile) >= 13 || mobile == ""
}
func FormalizeMobile(mobile string) string {
mobile = TrimDecorationChar(mobile)
return strings.Replace(strings.Replace(mobile, "-", ",", -1), "_", ",", -1)

View File

@@ -47,17 +47,17 @@ func TestFakeID(t *testing.T) {
}
}
func TestIsMobileFake(t *testing.T) {
if IsMobileFake("13888888888") {
func TestIsStringLikeMobile(t *testing.T) {
if !IsStringLikeMobile("13888888888") {
t.Fatal("wrong 1")
}
if IsMobileFake("13888888888-123") {
if IsStringLikeMobile("13888888888-123") {
t.Fatal("wrong 2")
}
if IsMobileFake("13888888888,123") {
if IsStringLikeMobile("13888888888,123") {
t.Fatal("wrong 3")
}
if !IsMobileFake("138****8888") {
if IsStringLikeMobile("138****8888") {
t.Fatal("wrong 4")
}
}

View File

@@ -60,9 +60,12 @@ type GoodsOrder struct {
StatusTime time.Time `orm:"type(datetime)" json:"statusTime"` // last status time
PickDeadline time.Time `orm:"type(datetime)" json:"pickDeadline"`
ModelTimeInfo `json:"-"`
OriginalData string `orm:"-" json:"-"` // 只是用于传递数据
Skus []*OrderSku `orm:"-" json:"-"`
Flag int `json:"flag"` //非运单调整相关的其它状态
Flag int `json:"flag"` //非运单调整相关的其它状态
// 以下只是用于传递数据
OriginalData string `orm:"-" json:"-"`
Skus []*OrderSku `orm:"-" json:"-"`
VendorUserID string `orm:"-" json:"-"`
}
func (o *GoodsOrder) TableUnique() [][]string {

View File

@@ -171,6 +171,7 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
VendorStoreID: shopMap["baidu_shop_id"].(string),
StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(shopMap["id"]), 0)),
StoreName: shopMap["name"].(string),
VendorUserID: utils.Interface2String(userMap["user_id"]),
ConsigneeName: userMap["name"].(string),
ConsigneeMobile: jxutils.FormalizeMobile(userMap["phone"].(string)),
ConsigneeAddress: userMap["address"].(string),

View File

@@ -138,18 +138,6 @@ func (c *PurchaseHandler) getOrder(orderID string) (order *model.GoodsOrder, ord
if order != nil && orderSettlement != nil {
updateOrderBySettleMent(order, orderSettlement)
}
// if orderMap, err = getAPI("").QuerySingleOrder(orderID); err == nil {
// globals.SugarLogger.Debugf("jd getOrder2 orderID:%s", orderID)
// order = c.Map2Order(orderMap)
// if jxutils.IsMobileFake(order.ConsigneeMobile) {
// if realMobile, err := getAPI("").GetRealMobile4Order(orderID, order.VendorStoreID); err == nil { // 故意强制忽略取不到真实手机号错误
// globals.SugarLogger.Debugf("jd getOrder3 orderID:%s", orderID)
// order.ConsigneeMobile2 = jxutils.FormalizeMobile(realMobile)
// } else {
// // globals.SugarLogger.Warnf("jd GetOrder orderID:%s, GetRealMobile4Order failed with error:%v", orderID, err2)
// }
// }
// }
return order, orderMap, err
}
@@ -174,6 +162,7 @@ func (c *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
VendorStoreID: utils.Interface2String(result["produceStationNo"]),
StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(result["produceStationNoIsv"]), 0)),
StoreName: utils.Interface2String(result["produceStationName"]),
VendorUserID: utils.Interface2String(result["buyerPin"]),
ConsigneeName: utils.Interface2String(result["buyerFullName"]),
ConsigneeMobile: jxutils.FormalizeMobile(utils.Interface2String(result["buyerMobile"])),
ConsigneeAddress: utils.Interface2String(result["buyerFullAddress"]),

View File

@@ -122,6 +122,10 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
OriginalData: string(utils.MustMarshal(result)),
ActualPayPrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(result["total"])),
}
openUID := utils.Interface2Int64WithDefault(result["openUid"], 0)
if openUID > 0 {
order.VendorUserID = utils.Int64ToStr(openUID)
}
if utils.IsTimeZero(order.PickDeadline) && !utils.IsTimeZero(order.StatusTime) {
order.PickDeadline = order.StatusTime.Add(pickupOrderDelay) // 美团外卖要求在5分钟内拣货不然订单会被取消
}