- HandleOrder4Consignee
This commit is contained in:
@@ -23,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUserIDAndNameMustGiven = errors.New("用户ID2,用户名及手机号必须不为空")
|
||||
ErrUserIDAndNameMustGiven = errors.New("用户ID2和用户名必须不为空")
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -128,7 +128,7 @@ func HandleOrder4Consignee(order *model.GoodsOrder) (err error) {
|
||||
var user *model.User
|
||||
authType := jxutils.GetAuthType4Vendor(order.VendorID)
|
||||
if authType == "" {
|
||||
msg := fmt.Sprintf("平台ID:%d当前不支持", order.VendorID)
|
||||
msg := fmt.Sprintf("平台ID:%d当前不被支持,请联系开发", order.VendorID)
|
||||
globals.SugarLogger.Warn(msg)
|
||||
return fmt.Errorf(msg)
|
||||
}
|
||||
@@ -147,42 +147,85 @@ func HandleOrder4Consignee(order *model.GoodsOrder) (err error) {
|
||||
}
|
||||
|
||||
vendorUserID := order.VendorUserID
|
||||
if err == nil {
|
||||
authList, err2 := dao.GetUserBindAuthInfo(db, "", model.AuthBindTypeID, "", []string{authType})
|
||||
if err = err2; err != nil {
|
||||
if err == nil && vendorUserID != "" {
|
||||
authInfo, err2 := dao.GetAuthBind(db, "", model.AuthBindTypeID, authType, vendorUserID)
|
||||
if err = err2; err != nil && !dao.IsNoRowsError(err) {
|
||||
return err
|
||||
}
|
||||
if len(authList) > 0 {
|
||||
if user, err = dao.GetUserByID(db, "UserID", authList[0].UserID); err != nil {
|
||||
return err
|
||||
if err == nil {
|
||||
vendorUserID = ""
|
||||
if user == nil {
|
||||
if user, err = dao.GetUserByID(db, "UserID", authInfo.UserID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
|
||||
if user == nil {
|
||||
user = &model.User{
|
||||
UserID2: mobileNumber,
|
||||
Name: order.ConsigneeName,
|
||||
Mobile: &mobileNumber,
|
||||
Type: model.UserTypeConsumer,
|
||||
Address: order.ConsigneeAddress,
|
||||
Remark: order.VendorOrderID,
|
||||
}
|
||||
setUserAddress(db, user, order)
|
||||
|
||||
if user.GetID2() == "" {
|
||||
user.UserID2 = vendorUserID
|
||||
}
|
||||
if user.GetID2() == "" {
|
||||
user.UserID2 = order.VendorUserID
|
||||
}
|
||||
|
||||
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,
|
||||
globals.SugarLogger.Debug(err)
|
||||
} else {
|
||||
if user.GetMobile() == "" && mobileNumber != "" {
|
||||
user.Mobile = &mobileNumber
|
||||
dao.UpdateEntity(db, user, "Mobile")
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
order.UserID = user.GetID()
|
||||
if 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)
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(authBind, oeratorName)
|
||||
authBind.Status = model.AuthBindStatusNormal
|
||||
err = dao.CreateEntity(nil, authBind)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func setUserAddress(db *dao.DaoDB, user *model.User, order *model.GoodsOrder) {
|
||||
user.Address = order.ConsigneeAddress
|
||||
store := &model.Store{}
|
||||
store.ID = jxutils.GetSaleStoreIDFromOrder(order)
|
||||
if err := dao.GetEntity(db, store); err == nil {
|
||||
user.CityCode = store.CityCode
|
||||
user.DistrictCode = store.DistrictCode
|
||||
} else if dao.IsNoRowsError(err) {
|
||||
if order.ConsigneeLng != 0 && order.ConsigneeLat != 0 {
|
||||
if user.DistrictCode = api.AutonaviAPI.GetCoordinateDistrictCode(jxutils.IntCoordinate2Standard(order.ConsigneeLng), jxutils.IntCoordinate2Standard(order.ConsigneeLat)); user.DistrictCode > 0 {
|
||||
if placeInfo, err := dao.GetPlaceByCode(db, user.DistrictCode); err == nil {
|
||||
user.CityCode = placeInfo.ParentCode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetUserBindAuthInfo(ctx *jxcontext.Context) (authList []*model.AuthBind, err error) {
|
||||
authInfo, err := ctx.GetV2AuthInfo()
|
||||
if err == nil {
|
||||
@@ -192,9 +235,17 @@ func GetUserBindAuthInfo(ctx *jxcontext.Context) (authList []*model.AuthBind, er
|
||||
}
|
||||
|
||||
func CreateUser(user *model.User, creatorName string) (err error) {
|
||||
if user == nil || user.UserID2 == "" || user.Name == "" || user.GetMobile() == "" {
|
||||
globals.SugarLogger.Debugf("CreateUser user:%s, creatorName:%s", utils.Format4Output(user, true), creatorName)
|
||||
|
||||
if user == nil || user.UserID2 == "" || user.Name == "" {
|
||||
return ErrUserIDAndNameMustGiven
|
||||
}
|
||||
if user.GetMobile() == "" {
|
||||
user.Mobile = nil
|
||||
}
|
||||
if user.GetEmail() == "" {
|
||||
user.Email = nil
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(user, creatorName)
|
||||
user.UserID = utils.GetUUID()
|
||||
user.Status = model.UserStatusNormal
|
||||
|
||||
Reference in New Issue
Block a user