diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 2a1a615dd..b6cab1841 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -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 } diff --git a/business/jxstore/cms/user2.go b/business/jxstore/cms/user2.go index 869c1f577..f955a3cbe 100644 --- a/business/jxstore/cms/user2.go +++ b/business/jxstore/cms/user2.go @@ -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 } diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 81db2b920..44dbd2029 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -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") } diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index aea8b72ec..70d3e9141 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -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 +} diff --git a/business/jxutils/jxutils_cms.go b/business/jxutils/jxutils_cms.go index b0b365efe..273347ad7 100644 --- a/business/jxutils/jxutils_cms.go +++ b/business/jxutils/jxutils_cms.go @@ -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) diff --git a/business/jxutils/jxutils_cms_test.go b/business/jxutils/jxutils_cms_test.go index 1373a079f..07507520e 100644 --- a/business/jxutils/jxutils_cms_test.go +++ b/business/jxutils/jxutils_cms_test.go @@ -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") } } diff --git a/business/model/order.go b/business/model/order.go index 718a05416..093283ce6 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -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 { diff --git a/business/partner/purchase/ebai/order.go b/business/partner/purchase/ebai/order.go index 64e540018..06fa9f557 100644 --- a/business/partner/purchase/ebai/order.go +++ b/business/partner/purchase/ebai/order.go @@ -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), diff --git a/business/partner/purchase/jd/order.go b/business/partner/purchase/jd/order.go index 63943aff3..8829b8aae 100644 --- a/business/partner/purchase/jd/order.go +++ b/business/partner/purchase/jd/order.go @@ -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"]), diff --git a/business/partner/purchase/mtwm/order.go b/business/partner/purchase/mtwm/order.go index 2b76b85eb..442bd2245 100644 --- a/business/partner/purchase/mtwm/order.go +++ b/business/partner/purchase/mtwm/order.go @@ -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分钟内拣货,不然订单会被取消 }