- HandleOrder4Consignee
This commit is contained in:
@@ -177,6 +177,8 @@ func (c *OrderManager) SaveOrder(order *model.GoodsOrder, isAdjust bool, db *dao
|
|||||||
order.WaybillVendorID = model.VendorIDUnknown
|
order.WaybillVendorID = model.VendorIDUnknown
|
||||||
order.OrderFinishedAt = utils.DefaultTimeValue
|
order.OrderFinishedAt = utils.DefaultTimeValue
|
||||||
|
|
||||||
|
// cms.HandleOrder4Consignee(order)
|
||||||
|
|
||||||
dao.Begin(db)
|
dao.Begin(db)
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil || err != nil {
|
if r := recover(); r != nil || err != nil {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrUserIDAndNameMustGiven = errors.New("用户ID2,用户名及手机号必须不为空")
|
ErrUserIDAndNameMustGiven = errors.New("用户ID2和用户名必须不为空")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -128,7 +128,7 @@ func HandleOrder4Consignee(order *model.GoodsOrder) (err error) {
|
|||||||
var user *model.User
|
var user *model.User
|
||||||
authType := jxutils.GetAuthType4Vendor(order.VendorID)
|
authType := jxutils.GetAuthType4Vendor(order.VendorID)
|
||||||
if authType == "" {
|
if authType == "" {
|
||||||
msg := fmt.Sprintf("平台ID:%d当前不支持", order.VendorID)
|
msg := fmt.Sprintf("平台ID:%d当前不被支持,请联系开发", order.VendorID)
|
||||||
globals.SugarLogger.Warn(msg)
|
globals.SugarLogger.Warn(msg)
|
||||||
return fmt.Errorf(msg)
|
return fmt.Errorf(msg)
|
||||||
}
|
}
|
||||||
@@ -147,42 +147,85 @@ func HandleOrder4Consignee(order *model.GoodsOrder) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vendorUserID := order.VendorUserID
|
vendorUserID := order.VendorUserID
|
||||||
if err == nil {
|
if err == nil && vendorUserID != "" {
|
||||||
authList, err2 := dao.GetUserBindAuthInfo(db, "", model.AuthBindTypeID, "", []string{authType})
|
authInfo, err2 := dao.GetAuthBind(db, "", model.AuthBindTypeID, authType, vendorUserID)
|
||||||
if err = err2; err != nil {
|
if err = err2; err != nil && !dao.IsNoRowsError(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(authList) > 0 {
|
if err == nil {
|
||||||
if user, err = dao.GetUserByID(db, "UserID", authList[0].UserID); err != nil {
|
vendorUserID = ""
|
||||||
return err
|
if user == nil {
|
||||||
|
if user, err = dao.GetUserByID(db, "UserID", authInfo.UserID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
err = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if user == nil {
|
if user == nil {
|
||||||
user = &model.User{
|
user = &model.User{
|
||||||
UserID2: mobileNumber,
|
UserID2: mobileNumber,
|
||||||
Name: order.ConsigneeName,
|
Name: order.ConsigneeName,
|
||||||
Mobile: &mobileNumber,
|
Mobile: &mobileNumber,
|
||||||
Type: model.UserTypeConsumer,
|
Type: model.UserTypeConsumer,
|
||||||
|
Address: order.ConsigneeAddress,
|
||||||
Remark: order.VendorOrderID,
|
Remark: order.VendorOrderID,
|
||||||
}
|
}
|
||||||
|
setUserAddress(db, user, order)
|
||||||
|
|
||||||
|
if user.GetID2() == "" {
|
||||||
|
user.UserID2 = vendorUserID
|
||||||
|
}
|
||||||
|
if user.GetID2() == "" {
|
||||||
|
user.UserID2 = order.VendorUserID
|
||||||
|
}
|
||||||
|
|
||||||
user.Type = model.UserTypeConsumer
|
user.Type = model.UserTypeConsumer
|
||||||
err = CreateUser(user, oeratorName)
|
err = CreateUser(user, oeratorName)
|
||||||
}
|
globals.SugarLogger.Debug(err)
|
||||||
if err == nil && vendorUserID != "" {
|
} else {
|
||||||
authBind := &model.AuthBind{
|
if user.GetMobile() == "" && mobileNumber != "" {
|
||||||
UserID: user.GetID(),
|
user.Mobile = &mobileNumber
|
||||||
BindType: model.AuthBindTypeID,
|
dao.UpdateEntity(db, user, "Mobile")
|
||||||
AuthID: vendorUserID,
|
}
|
||||||
Type: authType,
|
}
|
||||||
|
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
|
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) {
|
func GetUserBindAuthInfo(ctx *jxcontext.Context) (authList []*model.AuthBind, err error) {
|
||||||
authInfo, err := ctx.GetV2AuthInfo()
|
authInfo, err := ctx.GetV2AuthInfo()
|
||||||
if err == nil {
|
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) {
|
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
|
return ErrUserIDAndNameMustGiven
|
||||||
}
|
}
|
||||||
|
if user.GetMobile() == "" {
|
||||||
|
user.Mobile = nil
|
||||||
|
}
|
||||||
|
if user.GetEmail() == "" {
|
||||||
|
user.Email = nil
|
||||||
|
}
|
||||||
dao.WrapAddIDCULDEntity(user, creatorName)
|
dao.WrapAddIDCULDEntity(user, creatorName)
|
||||||
user.UserID = utils.GetUUID()
|
user.UserID = utils.GetUUID()
|
||||||
user.Status = model.UserStatusNormal
|
user.Status = model.UserStatusNormal
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ type GoodsOrder struct {
|
|||||||
WaybillTipMoney int64 `json:"waybillTipMoney"` // 京西加的平台配送小费
|
WaybillTipMoney int64 `json:"waybillTipMoney"` // 京西加的平台配送小费
|
||||||
EarningPrice int64 `json:"earningPrice"` // 结算给门店老板的钱(未扣除可能的三方配送费)
|
EarningPrice int64 `json:"earningPrice"` // 结算给门店老板的钱(未扣除可能的三方配送费)
|
||||||
Weight int `json:"weight"` // 单位为克
|
Weight int `json:"weight"` // 单位为克
|
||||||
|
VendorUserID string `orm:"column(vendor_user_id);size(48)" json:"vendorUserID"`
|
||||||
|
UserID string `orm:"column(user_id);size(48)" json:"userID"`
|
||||||
ConsigneeName string `orm:"size(32)" json:"consigneeName"`
|
ConsigneeName string `orm:"size(32)" json:"consigneeName"`
|
||||||
ConsigneeMobile string `orm:"size(32)" json:"consigneeMobile"`
|
ConsigneeMobile string `orm:"size(32)" json:"consigneeMobile"`
|
||||||
ConsigneeMobile2 string `orm:"size(32)" json:"consigneeMobile2"`
|
ConsigneeMobile2 string `orm:"size(32)" json:"consigneeMobile2"`
|
||||||
@@ -65,7 +67,6 @@ type GoodsOrder struct {
|
|||||||
// 以下只是用于传递数据
|
// 以下只是用于传递数据
|
||||||
OriginalData string `orm:"-" json:"-"`
|
OriginalData string `orm:"-" json:"-"`
|
||||||
Skus []*OrderSku `orm:"-" json:"-"`
|
Skus []*OrderSku `orm:"-" json:"-"`
|
||||||
VendorUserID string `orm:"-" json:"-"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *GoodsOrder) TableUnique() [][]string {
|
func (o *GoodsOrder) TableUnique() [][]string {
|
||||||
|
|||||||
@@ -26,15 +26,20 @@ var (
|
|||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ModelIDCULD
|
ModelIDCULD
|
||||||
UserID string `orm:"size(48);column(user_id)" json:"userID" compact:"userID"` // 内部唯一标识
|
UserID string `orm:"size(48);column(user_id)" json:"userID" compact:"userID"` // 内部唯一标识
|
||||||
UserID2 string `orm:"size(48);column(user_id2)" json:"userID2" compact:"userID2"` // 外部唯一标识(一般用于登录)
|
UserID2 string `orm:"size(48);column(user_id2)" json:"userID2" compact:"userID2"` // 外部唯一标识(一般用于登录)
|
||||||
Name string `orm:"size(48);index" json:"name" compact:"name"` // 外部显示标识(当前可以重复)
|
Name string `orm:"size(48);index" json:"name" compact:"name"` // 外部显示标识(当前可以重复)
|
||||||
Mobile *string `orm:"size(32);null" json:"mobile" compact:"mobile"`
|
Mobile *string `orm:"size(32);null" json:"mobile" compact:"mobile"`
|
||||||
Email *string `orm:"size(32);null" json:"email" compact:"email"`
|
Email *string `orm:"size(32);null" json:"email" compact:"email"`
|
||||||
Status int8 `json:"status" compact:"status"`
|
Status int8 `json:"status" compact:"status"`
|
||||||
Type int8 `json:"type" compact:"type"` // 用户类型
|
Type int8 `json:"type" compact:"type"` // 用户类型
|
||||||
IDCardNo string `orm:"size(18);column(id_card_no)" json:"idCardNo" compact:"idCardNo"` // 身份证号
|
|
||||||
Remark string `orm:"size(255)" json:"remark"`
|
CityCode int `orm:"default(0)" json:"cityCode"`
|
||||||
|
DistrictCode int `orm:"default(0);index" json:"districtCode"`
|
||||||
|
Address string `orm:"size(255)" json:"address"`
|
||||||
|
|
||||||
|
IDCardNo string `orm:"size(18);column(id_card_no)" json:"idCardNo" compact:"idCardNo"` // 身份证号
|
||||||
|
Remark string `orm:"size(255)" json:"remark"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*User) TableUnique() [][]string {
|
func (*User) TableUnique() [][]string {
|
||||||
|
|||||||
Reference in New Issue
Block a user