Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
e991ee3966
|
@ -14,7 +14,7 @@ func (a *FsAddressModel) GetOne(ctx context.Context, addressId int64, userId int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *FsAddressModel) GetUserAllAddress(ctx context.Context, userId int64) (resp []FsAddress, err error) {
|
func (a *FsAddressModel) GetUserAllAddress(ctx context.Context, userId int64) (resp []FsAddress, err error) {
|
||||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = ?", userId, 1).Order("`ltime` DESC").Find(&resp).Error
|
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1", userId).Order("`ltime` DESC").Find(&resp).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (res
|
||||||
func (a *FsAddressModel) UpdateAddress(ctx context.Context, address *FsAddress) (err error) {
|
func (a *FsAddressModel) UpdateAddress(ctx context.Context, address *FsAddress) (err error) {
|
||||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error {
|
err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error {
|
||||||
err = tx.
|
err = tx.
|
||||||
Where("user_id = ? and address_id = ? and status = 1 ", address.UserId, address.AddressId).
|
Where("address_id = ? and user_id = ? and status = 1 ", address.AddressId, address.UserId).
|
||||||
Updates(address).Error
|
Updates(address).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -88,19 +88,19 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i
|
||||||
|
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
|
|
||||||
err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` = ? ", userId, addressId).Take(nil).Error
|
err = tx.Where("`address_id` = ? and `user_id` = ? and `status` = 1 ", addressId, userId).Take(nil).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` = ?", userId, addressId).
|
err = tx.Where("`address_id` = ? and `user_id` = ? and `status` = 1 ", addressId, userId).
|
||||||
UpdateColumn("ltime", now.AddDate(250, 0, 0)).
|
UpdateColumn("ltime", now.AddDate(250, 0, 0)).
|
||||||
UpdateColumn("utime", now).Error
|
UpdateColumn("utime", now).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tx.Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > ?", userId, addressId, now.AddDate(10, 0, 0)).
|
err = tx.Model(&FsAddress{}).Where("`address_id` != ? and `user_id` = ? and `status` = 1 and `ltime` > ?", addressId, userId, now.AddDate(10, 0, 0)).
|
||||||
UpdateColumn("ltime", now).Error
|
UpdateColumn("ltime", now).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
|
@ -109,12 +109,27 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *FsAddressModel) DeleteOne(ctx context.Context, addressId int64, userId int64) (err error) {
|
func (a *FsAddressModel) DeleteOne(ctx context.Context, addressId int64, userId int64) (err error) {
|
||||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).
|
err = a.db.WithContext(ctx).Model(&FsAddress{}).
|
||||||
Where("`address_id` = ? and `user_id` = ? and `status` = ? ", addressId, userId, 1).
|
Where("`address_id` = ? and `user_id` = ? and `status` = 1 ", addressId, userId).
|
||||||
UpdateColumn("status", 0).Error
|
UpdateColumn("status", 0).Error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateUsedAddress 当每次订单成功后, 更新一次地址使用时间
|
||||||
|
func (a *FsAddressModel) UpdateUsedAddress(ctx context.Context, addressId int64, userId int64) (err error) {
|
||||||
|
err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error {
|
||||||
|
logx.Info("address_id:", addressId, " update used")
|
||||||
|
now := time.Now().UTC()
|
||||||
|
err = tx.Where("`address_id` = ? and `user_id` = ? and `status` = 1 and `ltime` < ?", addressId, userId, now).
|
||||||
|
UpdateColumn("ltime", now).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
|
@ -47,9 +47,7 @@ func (p *FsUserInfoModel) CreateOrUpdate(gormDB *gorm.DB, req *FsUserInfo) (resp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *FsUserInfoModel) MergeMetadata(userId int64, meta any) error {
|
func (m *FsUserInfoModel) MergeMetadata(userId int64, meta any) error {
|
||||||
return fssql.MetadataModulePATCH(m.db, "profile", FsUserInfo{}, map[string]any{
|
return fssql.MetadataModulePATCH(m.db, "profile", FsUserInfo{}, meta, "user_id = ?", userId)
|
||||||
"base": meta,
|
|
||||||
}, "user_id = ?", userId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId int64) (map[string]any, error) {
|
func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId int64) (map[string]any, error) {
|
||||||
|
|
|
@ -121,13 +121,58 @@ func (u *FsUserModel) RegisterByGoogleOAuth(ctx context.Context, token *auth.Reg
|
||||||
user.GoogleId = &googleId
|
user.GoogleId = &googleId
|
||||||
user.PasswordHash = &token.Password
|
user.PasswordHash = &token.Password
|
||||||
user.FirstName = &firstName
|
user.FirstName = &firstName
|
||||||
user.FirstName = &lastName
|
user.LastName = &lastName
|
||||||
err = tx.Model(&FsUser{}).Create(user).Error
|
err = tx.Model(&FsUser{}).Create(user).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// 继承guest_id的资源表
|
// 继承guest_id的资源表
|
||||||
return InheritGuestIdResource(tx, user.Id, token.GuestId, nil)
|
return InheritGuestIdResource(tx, user.Id, token.GuestId, func(txResouce, txUserMaterial, txUserInfo *gorm.DB) error {
|
||||||
|
userProfileBase := UserProfileBase{
|
||||||
|
FirstName: *user.FirstName,
|
||||||
|
LastName: *user.LastName,
|
||||||
|
Email: *user.Email,
|
||||||
|
}
|
||||||
|
|
||||||
|
userProfile := &UserProfile{
|
||||||
|
ProfileBase: userProfileBase,
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata, err := json.Marshal(userProfile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
now := time.Now().UTC()
|
||||||
|
uinfo := &FsUserInfo{
|
||||||
|
Module: FsString("profile"),
|
||||||
|
UserId: &user.Id,
|
||||||
|
GuestId: &token.GuestId,
|
||||||
|
Metadata: &metadata,
|
||||||
|
Ctime: &now,
|
||||||
|
Utime: &now,
|
||||||
|
}
|
||||||
|
|
||||||
|
// logx.Error(metadata)
|
||||||
|
|
||||||
|
err = txUserInfo.Where("module = 'profile' and user_id = ?", *uinfo.UserId).Take(nil).Error
|
||||||
|
if err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
err = tx.Model(&FsUserInfo{}).Create(uinfo).Error
|
||||||
|
// logx.Info(err, "*uinfo.UserId:", *uinfo.UserId, " ", uinfo.Id)
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = fssql.MetadataModulePATCH(txUserInfo, "profile", FsUserInfo{}, metadata, "user_id = ?", *uinfo.UserId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -178,6 +223,7 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT
|
||||||
FirstName: FirstName,
|
FirstName: FirstName,
|
||||||
LastName: LastName,
|
LastName: LastName,
|
||||||
Resetaurant: Resetaurant,
|
Resetaurant: Resetaurant,
|
||||||
|
Email: *user.Email,
|
||||||
}
|
}
|
||||||
|
|
||||||
userProfile := &UserProfile{
|
userProfile := &UserProfile{
|
||||||
|
|
|
@ -38,9 +38,15 @@ func FsBool(v bool) *bool {
|
||||||
|
|
||||||
// SubscriptionStatus 订阅状态
|
// SubscriptionStatus 订阅状态
|
||||||
type SubscriptionStatus struct {
|
type SubscriptionStatus struct {
|
||||||
SubEmail bool `json:"all_emails"`
|
NotificationEmail *struct {
|
||||||
ItemMap *struct {
|
OrderUpdate bool `json:"order_update"`
|
||||||
} `json:"item_map"`
|
Newseleter bool `json:"newseleter"`
|
||||||
|
} `json:"notification_email"`
|
||||||
|
|
||||||
|
NotificationPhone *struct {
|
||||||
|
OrderUpdate bool `json:"order_update"`
|
||||||
|
Newseleter bool `json:"newseleter"`
|
||||||
|
} `json:"notification_phone"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserProfile struct {
|
type UserProfile struct {
|
||||||
|
@ -52,7 +58,7 @@ type UserProfile struct {
|
||||||
type UserProfileBase struct {
|
type UserProfileBase struct {
|
||||||
FirstName string `json:"first_name"` // 首名
|
FirstName string `json:"first_name"` // 首名
|
||||||
LastName string `json:"last_name"` // 后名
|
LastName string `json:"last_name"` // 后名
|
||||||
UserName string `json:"user_name"` // 用户名
|
Email string `json:"email"` // email
|
||||||
Mobile string `json:"mobile"` // 电话
|
Mobile string `json:"mobile"` // 电话
|
||||||
Resetaurant string `json:"resetaurant"` // 不知道干什么
|
Resetaurant string `json:"resetaurant"` // 不知道干什么
|
||||||
Company string `json:"company"` // 公司
|
Company string `json:"company"` // 公司
|
||||||
|
|
|
@ -17,36 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/api/user/fonts",
|
Path: "/api/user/fonts",
|
||||||
Handler: UserFontsHandler(serverCtx),
|
Handler: UserFontsHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Method: http.MethodGet,
|
|
||||||
Path: "/api/user/get-type",
|
|
||||||
Handler: UserGetTypeHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/api/user/basic-info",
|
|
||||||
Handler: UserSaveBasicInfoHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/api/user/status-config",
|
Path: "/api/user/status-config",
|
||||||
Handler: UserStatusConfigHandler(serverCtx),
|
Handler: UserStatusConfigHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Method: http.MethodGet,
|
|
||||||
Path: "/api/user/basic-info",
|
|
||||||
Handler: UserBasicInfoHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Method: http.MethodGet,
|
|
||||||
Path: "/api/user/address-list",
|
|
||||||
Handler: UserAddressListHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/api/user/add-address",
|
|
||||||
Handler: UserAddAddressHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/api/user/contact-service",
|
Path: "/api/user/contact-service",
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"fusenapi/server/home-user-auth/internal/logic"
|
|
||||||
"fusenapi/server/home-user-auth/internal/svc"
|
|
||||||
"fusenapi/server/home-user-auth/internal/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func UserAddAddressHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
var req types.RequestAddAddress
|
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
|
||||||
l := logic.NewUserAddAddressLogic(r.Context(), svcCtx)
|
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
|
||||||
basic.BeforeLogic(w, r, rl)
|
|
||||||
|
|
||||||
resp := l.UserAddAddress(&req, userinfo)
|
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,93 +0,0 @@
|
||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fusenapi/model/gmodel"
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/home-user-auth/internal/svc"
|
|
||||||
"fusenapi/server/home-user-auth/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type UserAddAddressLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewUserAddAddressLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAddAddressLogic {
|
|
||||||
return &UserAddAddressLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *UserAddAddressLogic) UserAddAddress(req *types.RequestAddAddress, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
|
||||||
// userinfo 传入值时, 一定不为null
|
|
||||||
if !userinfo.IsUser() {
|
|
||||||
return resp.SetStatus(basic.CodeUnAuth) // 如果不是用户信息, 返回未授权错误
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确认这个IsDefault的值范围
|
|
||||||
if !auth.CheckValueRange(req.IsDefault, 0, 1) {
|
|
||||||
return resp.SetStatus(basic.CodeSafeValueRangeErr) // IsDefault值超出范围, 返回安全值范围错误
|
|
||||||
}
|
|
||||||
|
|
||||||
m := l.svcCtx.AllModels.FsAddress // 创建地址模型
|
|
||||||
var status int64 = 1 // 默认地址状态为1(正常)
|
|
||||||
|
|
||||||
// 如果ID为0, 表示新增地址
|
|
||||||
if req.Id == 0 {
|
|
||||||
var (
|
|
||||||
country string = "USA" // 国家默认为美国
|
|
||||||
)
|
|
||||||
createOne := &gmodel.FsAddress{ // 构建FsAddress结构体
|
|
||||||
FirstName: &req.FirstName,
|
|
||||||
LastName: &req.LastName,
|
|
||||||
Mobile: &req.Mobile,
|
|
||||||
Street: &req.Street,
|
|
||||||
Suite: &req.Suite,
|
|
||||||
City: &req.City,
|
|
||||||
State: &req.State,
|
|
||||||
Country: &country,
|
|
||||||
Status: &status,
|
|
||||||
UserId: &userinfo.UserId,
|
|
||||||
ZipCode: &req.ZipCode,
|
|
||||||
}
|
|
||||||
created, err := m.CreateOne(l.ctx, createOne) // 新增地址
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err) // 日志记录错误
|
|
||||||
return resp.SetStatus(basic.CodeDbCreateErr) // 返回数据库创建错误
|
|
||||||
}
|
|
||||||
return resp.SetStatus(basic.CodeOK, map[string]int64{"id": created.AddressId}) // 返回成功并返回地址ID
|
|
||||||
}
|
|
||||||
|
|
||||||
address := &gmodel.FsAddress{
|
|
||||||
AddressId: req.Id,
|
|
||||||
FirstName: &req.FirstName,
|
|
||||||
LastName: &req.LastName,
|
|
||||||
Mobile: &req.Mobile,
|
|
||||||
Street: &req.Street,
|
|
||||||
Suite: &req.Suite,
|
|
||||||
City: &req.City,
|
|
||||||
State: &req.State,
|
|
||||||
Status: &status,
|
|
||||||
UserId: &userinfo.UserId,
|
|
||||||
ZipCode: &req.ZipCode,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 插入数据库 更新地址
|
|
||||||
err := m.UpdateAddress(l.ctx, address)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatus(basic.CodeDbUpdateErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK, map[string]int64{"id": address.AddressId})
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/home-user-auth/internal/svc"
|
|
||||||
"fusenapi/server/home-user-auth/internal/types"
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type UserAddressListLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewUserAddressListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAddressListLogic {
|
|
||||||
return &UserAddressListLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *UserAddressListLogic) UserAddressList(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
|
||||||
if !userinfo.IsUser() {
|
|
||||||
return resp.SetStatus(basic.CodeUnAuth)
|
|
||||||
}
|
|
||||||
|
|
||||||
m := l.svcCtx.AllModels.FsAddress
|
|
||||||
|
|
||||||
data, err := m.GetUserAllAddress(l.ctx, userinfo.UserId)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
|
||||||
}
|
|
||||||
return resp.SetStatus(basic.CodeOK, data)
|
|
||||||
}
|
|
|
@ -6,27 +6,27 @@ import (
|
||||||
|
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
"fusenapi/server/home-user-auth/internal/logic"
|
"fusenapi/server/info/internal/logic"
|
||||||
"fusenapi/server/home-user-auth/internal/svc"
|
"fusenapi/server/info/internal/svc"
|
||||||
"fusenapi/server/home-user-auth/internal/types"
|
"fusenapi/server/info/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UserAddressListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func AddressUsedUpdateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
var req types.Request
|
var req types.AddressIdRequest
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
// 创建一个业务逻辑层实例
|
||||||
l := logic.NewUserAddressListLogic(r.Context(), svcCtx)
|
l := logic.NewAddressUsedUpdateLogic(r.Context(), svcCtx)
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
rl := reflect.ValueOf(l)
|
||||||
basic.BeforeLogic(w, r, rl)
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
resp := l.UserAddressList(&req, userinfo)
|
resp := l.AddressUsedUpdate(&req, userinfo)
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
if !basic.AfterLogic(w, r, rl, resp) {
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
basic.NormalAfterLogic(w, r, resp)
|
|
@ -42,6 +42,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/api/info/address/update",
|
Path: "/api/info/address/update",
|
||||||
Handler: AddressUpdateHandler(serverCtx),
|
Handler: AddressUpdateHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/api/info/address/update/used",
|
||||||
|
Handler: AddressUsedUpdateHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/api/info/address/delete",
|
Path: "/api/info/address/delete",
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
func UpdateProfileBaseHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func UpdateProfileBaseHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
var req types.ProfileBaseRequest
|
var req types.ProfileRequest
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -40,6 +40,11 @@ func (l *AddressUpdateLogic) AddressUpdate(req *types.AddressRequest, userinfo *
|
||||||
return resp.SetStatus(basic.CodeUnAuth)
|
return resp.SetStatus(basic.CodeUnAuth)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 确认这个IsDefault的值范围
|
||||||
|
if !auth.CheckValueRange(req.IsDefault, 0, 1) {
|
||||||
|
return resp.SetStatus(basic.CodeSafeValueRangeErr) // IsDefault值超出范围, 返回安全值范围错误
|
||||||
|
}
|
||||||
|
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
|
|
||||||
if req.AddressId == 0 {
|
if req.AddressId == 0 {
|
||||||
|
@ -65,6 +70,10 @@ func (l *AddressUpdateLogic) AddressUpdate(req *types.AddressRequest, userinfo *
|
||||||
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
|
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if req.IsDefault > 0 {
|
||||||
|
l.svcCtx.AllModels.FsAddress.SettingUserDefaultAddress(l.ctx, userinfo.UserId, address.AddressId)
|
||||||
|
}
|
||||||
|
|
||||||
addresses, err := l.svcCtx.AllModels.FsAddress.GetUserAllAddress(l.ctx, userinfo.UserId)
|
addresses, err := l.svcCtx.AllModels.FsAddress.GetUserAllAddress(l.ctx, userinfo.UserId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
|
|
54
server/info/internal/logic/addressusedupdatelogic.go
Normal file
54
server/info/internal/logic/addressusedupdatelogic.go
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"fusenapi/server/info/internal/svc"
|
||||||
|
"fusenapi/server/info/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AddressUsedUpdateLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAddressUsedUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddressUsedUpdateLogic {
|
||||||
|
return &AddressUsedUpdateLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理进入前逻辑w,r
|
||||||
|
// func (l *AddressUsedUpdateLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
func (l *AddressUsedUpdateLogic) AddressUsedUpdate(req *types.AddressIdRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
|
// userinfo 传入值时, 一定不为null
|
||||||
|
if !userinfo.IsUser() {
|
||||||
|
return resp.SetStatus(basic.CodeUnAuth)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := l.svcCtx.AllModels.FsAddress.UpdateUsedAddress(l.ctx, req.AddressId, userinfo.UserId)
|
||||||
|
if err != nil {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp.SetStatus(basic.CodeOK, map[string]any{
|
||||||
|
"address_id": req.AddressId,
|
||||||
|
}) // 返回成功并返回地址ID
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
// func (l *AddressUsedUpdateLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||||
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
// }
|
|
@ -30,13 +30,15 @@ func NewUpdateProfileBaseLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||||
// func (l *UpdateProfileBaseLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
// func (l *UpdateProfileBaseLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func (l *UpdateProfileBaseLogic) UpdateProfileBase(req *types.ProfileBaseRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *UpdateProfileBaseLogic) UpdateProfileBase(req *types.ProfileRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
// userinfo 传入值时, 一定不为null
|
// userinfo 传入值时, 一定不为null
|
||||||
if !userinfo.IsUser() {
|
if !userinfo.IsUser() {
|
||||||
return resp.SetStatus(basic.CodeUnAuth)
|
return resp.SetStatus(basic.CodeUnAuth)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.ProfileBase.Email = nil
|
||||||
|
|
||||||
err := l.svcCtx.AllModels.FsUserInfo.MergeMetadata(userinfo.UserId, req)
|
err := l.svcCtx.AllModels.FsUserInfo.MergeMetadata(userinfo.UserId, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err) // 日志记录错误
|
logx.Error(err) // 日志记录错误
|
||||||
|
|
|
@ -31,15 +31,35 @@ type AddressRequest struct {
|
||||||
State string `json:"state"` //州
|
State string `json:"state"` //州
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProfileBaseRequest struct {
|
type ProfileRequest struct {
|
||||||
|
ProfileBase *ProfileBase `json:"base,optional,omitempty"` // 基础的个人消息, 姓名 公司等
|
||||||
|
SubscriptionStatus *SubscriptionStatus `json:"sub_status,optional,omitempty"` // 订阅的通知状态
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProfileBase struct {
|
||||||
FirstName *string `json:"first_name,optional,omitempty"` // 首名
|
FirstName *string `json:"first_name,optional,omitempty"` // 首名
|
||||||
LastName *string `json:"last_name,optional,omitempty"` // 后名
|
LastName *string `json:"last_name,optional,omitempty"` // 后名
|
||||||
UserName *string `json:"user_name,optional,omitempty"` // 用户名
|
Email *string `json:"email,optional,omitempty"` // email
|
||||||
Mobile *string `json:"mobile,optional,omitempty"` // 电话
|
Mobile *string `json:"mobile,optional,omitempty"` // 电话
|
||||||
Resetaurant *string `json:"resetaurant,optional,omitempty"` // 不知道干什么
|
Resetaurant *string `json:"resetaurant,optional,omitempty"` // 不知道干什么
|
||||||
Company *string `json:"company,optional,omitempty"` // 公司
|
Company *string `json:"company,optional,omitempty"` // 公司
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SubscriptionStatus struct {
|
||||||
|
NotificationEmail NotificationEmail `json:"notification_email,optional,omitempty"`
|
||||||
|
NotificationPhone NotificationPhone `json:"notification_phone,optional,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type NotificationEmail struct {
|
||||||
|
OrderUpdate bool `json:"order_update,optional,omitempty"`
|
||||||
|
Newseleter bool `json:"newseleter,optional,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type NotificationPhone struct {
|
||||||
|
OrderUpdate bool `json:"order_update,optional,omitempty"`
|
||||||
|
Newseleter bool `json:"newseleter,optional,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type QueryProfileRequest struct {
|
type QueryProfileRequest struct {
|
||||||
TopKey string `json:"top_key"` // 首名
|
TopKey string `json:"top_key"` // 首名
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,68 +10,55 @@ info (
|
||||||
import "basic.api"
|
import "basic.api"
|
||||||
|
|
||||||
service home-user-auth {
|
service home-user-auth {
|
||||||
|
|
||||||
// @handler UserRegisterHandler
|
// @handler UserRegisterHandler
|
||||||
// post /api/user/register(RequestUserRegister) returns (response);
|
// post /api/user/register(RequestUserRegister) returns (response);
|
||||||
//用户字体
|
//用户字体
|
||||||
@handler UserFontsHandler
|
@handler UserFontsHandler
|
||||||
get /api/user/fonts(request) returns (response);
|
get /api/user/fonts(request) returns (response);
|
||||||
//获取用户类型
|
|
||||||
@handler UserGetTypeHandler
|
|
||||||
get /api/user/get-type(request) returns (response);
|
|
||||||
//保存用户基础信息
|
|
||||||
@handler UserSaveBasicInfoHandler
|
|
||||||
post /api/user/basic-info(RequestBasicInfoForm) returns (response);
|
|
||||||
//状态配置
|
//状态配置
|
||||||
@handler UserStatusConfigHandler
|
@handler UserStatusConfigHandler
|
||||||
get /api/user/status-config(request) returns (response);
|
get /api/user/status-config(request) returns (response);
|
||||||
//基础信息
|
|
||||||
@handler UserBasicInfoHandler
|
|
||||||
get /api/user/basic-info(request) returns (response);
|
|
||||||
//地址列表
|
|
||||||
@handler UserAddressListHandler
|
|
||||||
get /api/user/address-list(request) returns (response);
|
|
||||||
//添加地址
|
|
||||||
@handler UserAddAddressHandler
|
|
||||||
post /api/user/add-address(RequestAddAddress) returns (response);
|
|
||||||
//联系服务
|
//联系服务
|
||||||
@handler UserContactServiceHandler
|
@handler UserContactServiceHandler
|
||||||
post /api/user/contact-service (RequestContactService) returns (response);
|
post /api/user/contact-service (RequestContactService) returns (response);
|
||||||
|
|
||||||
// @handler UserOderListHandler
|
// @handler UserOderListHandler
|
||||||
// get /api/user/order-list(RequestOrderId) returns (response);
|
// get /api/user/order-list(RequestOrderId) returns (response);
|
||||||
//删除订单
|
//删除订单
|
||||||
@handler UserOderDeleteHandler
|
@handler UserOderDeleteHandler
|
||||||
post /api/user/order-delete(RequestOrderId) returns (response);
|
post /api/user/order-delete(RequestOrderId) returns (response);
|
||||||
|
|
||||||
//订单列表
|
//订单列表
|
||||||
@handler UserOrderListHandler
|
@handler UserOrderListHandler
|
||||||
get /api/user/order-list (UserOrderListReq) returns (response);
|
get /api/user/order-list (UserOrderListReq) returns (response);
|
||||||
|
|
||||||
//删除订单
|
//删除订单
|
||||||
@handler UserOrderDeleteHandler
|
@handler UserOrderDeleteHandler
|
||||||
get /api/user/order-delete (UserOrderDeleteReq) returns (response);
|
get /api/user/order-delete (UserOrderDeleteReq) returns (response);
|
||||||
|
|
||||||
//取消订单
|
//取消订单
|
||||||
@handler UserOrderCancelHandler
|
@handler UserOrderCancelHandler
|
||||||
get /api/user/order-cancel (UserOrderCancelReq) returns (response);
|
get /api/user/order-cancel (UserOrderCancelReq) returns (response);
|
||||||
|
|
||||||
// 用户logo列表
|
// 用户logo列表
|
||||||
@handler UserLogoListHandler
|
@handler UserLogoListHandler
|
||||||
get /api/user/logo-list (UserLogoListReq) returns (response);
|
get /api/user/logo-list (UserLogoListReq) returns (response);
|
||||||
|
|
||||||
// 再来一单
|
// 再来一单
|
||||||
@handler UserAgainOrderHandler
|
@handler UserAgainOrderHandler
|
||||||
get /api/user/one-more-order (UserAgainOrderReq) returns (response);
|
get /api/user/one-more-order (UserAgainOrderReq) returns (response);
|
||||||
|
|
||||||
// 保存商户信息
|
// 保存商户信息
|
||||||
@handler UserInfoSetHandler
|
@handler UserInfoSetHandler
|
||||||
post /api/user/set_user_info (UserInfoSetReq) returns (response);
|
post /api/user/set_user_info (UserInfoSetReq) returns (response);
|
||||||
|
|
||||||
// 用户logo设置当前
|
// 用户logo设置当前
|
||||||
@handler UserLogoSetHandler
|
@handler UserLogoSetHandler
|
||||||
post /api/user/logo-set (UserLogoSetReq) returns (response);
|
post /api/user/logo-set (UserLogoSetReq) returns (response);
|
||||||
|
|
||||||
// 用户logo模版信息
|
// 用户logo模版信息
|
||||||
@handler UserLogoTemplateTagSetHandler
|
@handler UserLogoTemplateTagSetHandler
|
||||||
post /api/user/logo-templatetag-set (UserLogoTemplateTagSetReq) returns (response);
|
post /api/user/logo-templatetag-set (UserLogoTemplateTagSetReq) returns (response);
|
||||||
|
|
|
@ -17,7 +17,7 @@ service info {
|
||||||
post /api/info/user/profile(QueryProfileRequest) returns (response);
|
post /api/info/user/profile(QueryProfileRequest) returns (response);
|
||||||
|
|
||||||
@handler UpdateProfileBaseHandler
|
@handler UpdateProfileBaseHandler
|
||||||
post /api/info/user/profile/base/update(ProfileBaseRequest) returns (response);
|
post /api/info/user/profile/base/update(ProfileRequest) returns (response);
|
||||||
|
|
||||||
@handler AddressDefaultHandler
|
@handler AddressDefaultHandler
|
||||||
post /api/info/address/default(AddressIdRequest) returns (response);
|
post /api/info/address/default(AddressIdRequest) returns (response);
|
||||||
|
@ -28,6 +28,9 @@ service info {
|
||||||
@handler AddressUpdateHandler
|
@handler AddressUpdateHandler
|
||||||
post /api/info/address/update(AddressRequest) returns (response);
|
post /api/info/address/update(AddressRequest) returns (response);
|
||||||
|
|
||||||
|
@handler AddressUsedUpdateHandler
|
||||||
|
post /api/info/address/update/used(AddressIdRequest) returns (response);
|
||||||
|
|
||||||
@handler AddressDeleteHandler
|
@handler AddressDeleteHandler
|
||||||
post /api/info/address/delete(AddressIdRequest) returns (response);
|
post /api/info/address/delete(AddressIdRequest) returns (response);
|
||||||
|
|
||||||
|
@ -62,15 +65,38 @@ type (
|
||||||
State string `json:"state"` //州
|
State string `json:"state"` //州
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileBaseRequest {
|
ProfileRequest {
|
||||||
FirstName *string `json:"first_name,optional,omitempty"` // 首名
|
ProfileBase *ProfileBase `json:"base,optional,omitempty"` // 基础的个人消息, 姓名 公司等
|
||||||
LastName *string `json:"last_name,optional,omitempty"` // 后名
|
SubscriptionStatus *SubscriptionStatus `json:"sub_status,optional,omitempty"` // 订阅的通知状态
|
||||||
UserName *string `json:"user_name,optional,omitempty"` // 用户名
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ProfileBase {
|
||||||
|
FirstName *string `json:"first_name,optional,omitempty"` // 首名
|
||||||
|
LastName *string `json:"last_name,optional,omitempty"` // 后名
|
||||||
|
// UserName *string `json:"user_name,optional,omitempty"` // 用户名
|
||||||
|
Email *string `json:"email,optional,omitempty"` // email
|
||||||
Mobile *string `json:"mobile,optional,omitempty"` // 电话
|
Mobile *string `json:"mobile,optional,omitempty"` // 电话
|
||||||
Resetaurant *string `json:"resetaurant,optional,omitempty"` // 不知道干什么
|
Resetaurant *string `json:"resetaurant,optional,omitempty"` // 不知道干什么
|
||||||
Company *string `json:"company,optional,omitempty"` // 公司
|
Company *string `json:"company,optional,omitempty"` // 公司
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SubscriptionStatus {
|
||||||
|
NotificationEmail NotificationEmail `json:"notification_email,optional,omitempty"`
|
||||||
|
NotificationPhone NotificationPhone `json:"notification_phone,optional,omitempty"`
|
||||||
|
} // 订阅的通知状态
|
||||||
|
|
||||||
|
NotificationEmail {
|
||||||
|
OrderUpdate bool `json:"order_update,optional,omitempty"`
|
||||||
|
Newseleter bool `json:"newseleter,optional,omitempty"`
|
||||||
|
} // 邮件通知设置
|
||||||
|
|
||||||
|
NotificationPhone {
|
||||||
|
OrderUpdate bool `json:"order_update,optional,omitempty"`
|
||||||
|
Newseleter bool `json:"newseleter,optional,omitempty"`
|
||||||
|
} // 电话通知设置
|
||||||
|
|
||||||
QueryProfileRequest {
|
QueryProfileRequest {
|
||||||
TopKey string `json:"top_key"` // 首名
|
TopKey string `json:"top_key"` // 首名
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user