Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
8c69e4d2d3
|
@ -22,7 +22,6 @@ type FsAddress struct {
|
|||
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // 创建时间
|
||||
Utime *time.Time `gorm:"index;default:'0000-00-00 00:00:00';" json:"utime"` // 更新时间
|
||||
Ltime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ltime"` // 上次被使用的时间
|
||||
IsDefault *int64 `gorm:"default:0;" json:"is_default"` // 1默认值,0非默认值
|
||||
}
|
||||
type FsAddressModel struct {
|
||||
db *gorm.DB
|
||||
|
|
|
@ -13,11 +13,29 @@ func (a *FsAddressModel) GetOne(ctx context.Context, addressId int64, userId int
|
|||
return resp, err
|
||||
}
|
||||
|
||||
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` = 1", userId).Order("`ctime` DESC").Find(&resp).Error
|
||||
func (a *FsAddressModel) GetUserAllAddress(ctx context.Context, userId int64) (resp []*FsAddressWithDefault, err error) {
|
||||
|
||||
var dbresp []*FsAddress
|
||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1", userId).Order("`ltime` DESC").Find(&dbresp).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
now := time.Now().UTC().AddDate(10, 0, 0).Unix()
|
||||
for _, r := range dbresp {
|
||||
rd := &FsAddressWithDefault{
|
||||
FsAddress: r,
|
||||
}
|
||||
|
||||
if r.Ltime.UTC().Unix() > now {
|
||||
rd.IsDefault = 1
|
||||
} else {
|
||||
rd.IsDefault = 0
|
||||
}
|
||||
|
||||
resp = append(resp, rd)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -37,7 +55,6 @@ func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (res
|
|||
Country: address.Country,
|
||||
ZipCode: address.ZipCode,
|
||||
Status: address.Status,
|
||||
IsDefault: address.IsDefault,
|
||||
Ctime: &now,
|
||||
Utime: &now,
|
||||
Ltime: &now,
|
||||
|
@ -65,44 +82,30 @@ func (a *FsAddressModel) UpdateAddress(ctx context.Context, address *FsAddress)
|
|||
return err
|
||||
}
|
||||
|
||||
func (a *FsAddressModel) SettingUserDefaultAddressMutex(ctx context.Context, userId int64, addressId int64, isDefault int64) (err error) {
|
||||
|
||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
logx.Info("address_id:", addressId, " set default ", isDefault)
|
||||
now := time.Now().UTC()
|
||||
|
||||
err = tx.Where("`user_id` = ? and `status` = 1 and `is_default` = 1", userId).
|
||||
UpdateColumn("is_default", 0).
|
||||
UpdateColumn("utime", now).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Where("`address_id` = ? and `user_id` = ? and `status` = 1", addressId, userId).
|
||||
UpdateColumn("is_default", isDefault).
|
||||
UpdateColumn("ltime", now).
|
||||
UpdateColumn("utime", now).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId int64, addressId int64, isDefault int64) (err error) {
|
||||
|
||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
logx.Info("address_id:", addressId, " set default ", isDefault)
|
||||
now := time.Now().UTC()
|
||||
err = tx.Where("`address_id` = ? and `user_id` = ? and `status` = 1", addressId, userId).
|
||||
UpdateColumn("is_default", isDefault).
|
||||
UpdateColumn("ltime", now).
|
||||
UpdateColumn("utime", now).Error
|
||||
var updates = map[string]interface{}{
|
||||
"ltime": now,
|
||||
"utime": now,
|
||||
}
|
||||
|
||||
if isDefault == 1 {
|
||||
err = tx.Where("`user_id` = ? and `status` = 1 and `ltime` > ? and `address_id` != ?", userId, now.AddDate(10, 0, 0), addressId).
|
||||
UpdateColumns(updates).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updates["ltime"] = now.AddDate(250, 0, 0)
|
||||
}
|
||||
|
||||
tr := tx.Model(&FsAddress{}).Where("`address_id` = ? and `user_id` = ? and `status` = 1", addressId, userId).
|
||||
UpdateColumns(updates)
|
||||
|
||||
err = tr.Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -114,6 +117,7 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i
|
|||
}
|
||||
|
||||
func (a *FsAddressModel) DeleteOne(ctx context.Context, addressId int64, userId int64) (err error) {
|
||||
|
||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).
|
||||
Where("`address_id` = ? and `user_id` = ? and `status` = 1 ", addressId, userId).
|
||||
UpdateColumn("status", 0).Error
|
||||
|
@ -125,9 +129,13 @@ func (a *FsAddressModel) UpdateUsedAddress(ctx context.Context, addressId int64,
|
|||
err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error {
|
||||
logx.Info("address_id:", addressId, " update used")
|
||||
now := time.Now().UTC()
|
||||
var updates = map[string]interface{}{
|
||||
"ltime": now,
|
||||
"utime": now,
|
||||
}
|
||||
|
||||
err = tx.Where("`address_id` = ? and `user_id` = ? and `status` = 1", addressId, userId).
|
||||
UpdateColumn("utime", now).
|
||||
UpdateColumn("ltime", now).Error
|
||||
UpdateColumns(updates).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ type FsAdminMenu struct {
|
|||
UpdateUid *int64 `gorm:"default:0;" json:"update_uid"` // 更新人
|
||||
DeleteUid *int64 `gorm:"default:0;" json:"delete_uid"` // 删除人
|
||||
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除:1=是 0=否
|
||||
ApiAuth *[]byte `gorm:"default:'';" json:"api_auth"` //
|
||||
}
|
||||
type FsAdminMenuModel struct {
|
||||
db *gorm.DB
|
||||
|
|
|
@ -23,7 +23,6 @@ type FsAdminRole struct {
|
|||
DeleteUid *int64 `gorm:"default:0;" json:"delete_uid"` // 删除人
|
||||
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除:1=是 0=否
|
||||
MenuAuth *[]byte `gorm:"default:'';" json:"menu_auth"` //
|
||||
ApiAuth *[]byte `gorm:"default:'';" json:"api_auth"` //
|
||||
}
|
||||
type FsAdminRoleModel struct {
|
||||
db *gorm.DB
|
||||
|
|
|
@ -1,2 +1,37 @@
|
|||
package gmodel
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
import "context"
|
||||
|
||||
// 查询
|
||||
func (c *FsProductCollectionModel) FindOne(ctx context.Context, userId, guestId, productId int64) (resp *FsProductCollection, err error) {
|
||||
err = c.db.WithContext(ctx).Model(&FsProductCollection{}).
|
||||
Where("user_id = ? and guest_id = ? and product_id = ?", userId, guestId, productId).
|
||||
Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// 创建
|
||||
func (c *FsProductCollectionModel) Create(ctx context.Context, data *FsProductCollection) error {
|
||||
return c.db.WithContext(ctx).Model(&FsProductCollection{}).Create(&data).Error
|
||||
}
|
||||
|
||||
// 更新
|
||||
func (c *FsProductCollectionModel) Update(ctx context.Context, userId, guestId, productId int64, data *FsProductCollection) error {
|
||||
return c.db.WithContext(ctx).Model(&FsProductCollection{}).
|
||||
Where("user_id = ? and guest_id = ? and product_id = ?", userId, guestId, productId).
|
||||
Updates(&data).Error
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (c *FsProductCollectionModel) Delete(ctx context.Context, userId, guestId, productId int64) error {
|
||||
return c.db.WithContext(ctx).Model(&FsProductCollection{}).
|
||||
Where("user_id = ? and guest_id = ? and product_id = ?", userId, guestId, productId).
|
||||
Delete(&FsProductCollection{}).Error
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (c *FsProductCollectionModel) Delete2(ctx context.Context, userId, guestId, id int64) error {
|
||||
return c.db.WithContext(ctx).Model(&FsProductCollection{}).
|
||||
Where("user_id = ? and guest_id = ? and id = ?", userId, guestId, id).
|
||||
Delete(&FsProductCollection{}).Error
|
||||
}
|
||||
|
|
|
@ -63,3 +63,8 @@ type UserProfileBase struct {
|
|||
Resetaurant string `json:"resetaurant"` // 不知道干什么
|
||||
Company string `json:"company"` // 公司
|
||||
}
|
||||
|
||||
type FsAddressWithDefault struct {
|
||||
*FsAddress
|
||||
IsDefault int64 `json:"is_default"`
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Name: collection
|
||||
Host: 0.0.0.0
|
||||
Port: 8888
|
||||
Port: 9922
|
||||
Timeout: 15000 #服务超时时间(毫秒)
|
||||
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
|
||||
SourceRabbitMq: ""
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/collection/internal/logic"
|
||||
"fusenapi/server/collection/internal/svc"
|
||||
"fusenapi/server/collection/internal/types"
|
||||
)
|
||||
|
||||
func DeleteCollectProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.DeleteCollectProductReq
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewDeleteCollectProductLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.DeleteCollectProduct(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/collection/internal/logic"
|
||||
"fusenapi/server/collection/internal/svc"
|
||||
"fusenapi/server/collection/internal/types"
|
||||
)
|
||||
|
||||
func GetCollectProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.GetCollectProductListReq
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewGetCollectProductListLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.GetCollectProductList(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,6 +17,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/api/collection/collect_product",
|
||||
Handler: CollectProductHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/collection/delete_collect_product",
|
||||
Handler: DeleteCollectProductHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/collection/get_collect_product_list",
|
||||
Handler: GetCollectProductListHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
|
@ -31,10 +35,55 @@ func NewCollectProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Co
|
|||
// }
|
||||
|
||||
func (l *CollectProductLogic) CollectProduct(req *types.CollectProductReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
if !userinfo.IsUser() && !userinfo.IsGuest() {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in before to collect product")
|
||||
}
|
||||
//查询产品
|
||||
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOne(l.ctx, req.ProductId, "id,is_shelf")
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not found")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "faile to get product info")
|
||||
}
|
||||
//校验下状态
|
||||
if *productInfo.Status != 1 {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "the product status is unNormal")
|
||||
}
|
||||
//下架了
|
||||
if *productInfo.IsShelf == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "the product is off shelf")
|
||||
}
|
||||
if *productInfo.IsDel == 1 {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "the product is deleted")
|
||||
}
|
||||
//查询收藏
|
||||
_, err = l.svcCtx.AllModels.FsProductCollection.FindOne(l.ctx, userinfo.UserId, userinfo.GuestId, req.ProductId)
|
||||
if err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to check repeat of collection")
|
||||
}
|
||||
//创建
|
||||
now := time.Now().UTC()
|
||||
err = l.svcCtx.AllModels.FsProductCollection.Create(l.ctx, &gmodel.FsProductCollection{
|
||||
UserId: &userinfo.UserId,
|
||||
GuestId: &userinfo.GuestId,
|
||||
ProductId: &req.ProductId,
|
||||
TemplateTag: &req.TemplateTag,
|
||||
SelectColorIndex: &req.SelectColorIndex,
|
||||
Logo: &req.Logo,
|
||||
Ctime: &now,
|
||||
Utime: &now,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to collect product")
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
return resp.SetStatusAddMessage(basic.CodeOK, "you have collect this product and don`t need to repeat again")
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/collection/internal/svc"
|
||||
"fusenapi/server/collection/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeleteCollectProductLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewDeleteCollectProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteCollectProductLogic {
|
||||
return &DeleteCollectProductLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *DeleteCollectProductLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *DeleteCollectProductLogic) DeleteCollectProduct(req *types.DeleteCollectProductReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if !userinfo.IsUser() && !userinfo.IsGuest() {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in before to collect product")
|
||||
}
|
||||
for _, id := range req.Ids {
|
||||
err := l.svcCtx.AllModels.FsProductCollection.Delete2(l.ctx, userinfo.UserId, userinfo.GuestId, id)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to remove product collection")
|
||||
}
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *DeleteCollectProductLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
|
@ -0,0 +1,43 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/collection/internal/svc"
|
||||
"fusenapi/server/collection/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetCollectProductListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetCollectProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCollectProductListLogic {
|
||||
return &GetCollectProductListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *GetCollectProductListLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *GetCollectProductListLogic) GetCollectProductList(req *types.GetCollectProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *GetCollectProductListLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
|
@ -12,6 +12,25 @@ type CollectProductReq struct {
|
|||
TemplateTag string `json:"template_tag"`
|
||||
}
|
||||
|
||||
type DeleteCollectProductReq struct {
|
||||
Ids []int64 `json:"ids"`
|
||||
}
|
||||
|
||||
type GetCollectProductListReq struct {
|
||||
CurrentPage int `form:"current_page"`
|
||||
}
|
||||
|
||||
type GetCollectProductListRspItem struct {
|
||||
Id int64 `json:"id"`
|
||||
ProductId int64 `json:"product_id"`
|
||||
ProductName string `json:"product_name"`
|
||||
Logo string `json:"logo"`
|
||||
SelectColorIndex int64 `json:"select_color_index"`
|
||||
TemplateTag string `json:"template_tag"`
|
||||
SizeCount int64 `json:"size_count"`
|
||||
MinPrice string `json:"min_price"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
|
|
35
server/info/internal/handler/restaurantlisthandler.go
Normal file
35
server/info/internal/handler/restaurantlisthandler.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/info/internal/logic"
|
||||
"fusenapi/server/info/internal/svc"
|
||||
"fusenapi/server/info/internal/types"
|
||||
)
|
||||
|
||||
func RestaurantListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.Request
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewRestaurantListLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.RestaurantList(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -57,6 +57,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/api/info/address/list",
|
||||
Handler: AddressListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/info/restaurant/list",
|
||||
Handler: RestaurantListHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ func (l *AddressDefaultLogic) AddressDefault(req *types.AddressDefaultRequest, u
|
|||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, map[string]any{
|
||||
"address_id": req.AddressId,
|
||||
"address_list": addresses,
|
||||
}) // 返回成功并返回地址ID
|
||||
}
|
||||
|
|
|
@ -70,9 +70,7 @@ func (l *AddressUpdateLogic) AddressUpdate(req *types.AddressRequest, userinfo *
|
|||
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
|
||||
}
|
||||
|
||||
if req.IsDefault > 0 {
|
||||
l.svcCtx.AllModels.FsAddress.SettingUserDefaultAddress(l.ctx, userinfo.UserId, address.AddressId, req.IsDefault)
|
||||
}
|
||||
l.svcCtx.AllModels.FsAddress.SettingUserDefaultAddress(l.ctx, userinfo.UserId, address.AddressId, req.IsDefault)
|
||||
|
||||
addresses, err := l.svcCtx.AllModels.FsAddress.GetUserAllAddress(l.ctx, userinfo.UserId)
|
||||
if err != nil {
|
||||
|
|
71
server/info/internal/logic/restaurantlistlogic.go
Normal file
71
server/info/internal/logic/restaurantlistlogic.go
Normal file
|
@ -0,0 +1,71 @@
|
|||
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 RestaurantListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewRestaurantListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RestaurantListLogic {
|
||||
return &RestaurantListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *RestaurantListLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *RestaurantListLogic) RestaurantList(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
values := []string{
|
||||
"Pizza Shop",
|
||||
"Coffee Shop",
|
||||
"Salad Shop",
|
||||
"Other Non-Asian Restaurants",
|
||||
"Fried Chicken / Burger / Sandwich Restaurant",
|
||||
"Other Restaurants",
|
||||
"Bakery / Dessert Shop",
|
||||
"Ramen /Vietnamese / Thai / Korean / Chinese",
|
||||
"Breakfast & Brunch",
|
||||
"Moxican",
|
||||
"Pho",
|
||||
"Ramen",
|
||||
"Chinese",
|
||||
"Burgers",
|
||||
"Sushi Restaurant",
|
||||
"Indian",
|
||||
"Vegan",
|
||||
"Smoothie",
|
||||
"Healthy",
|
||||
"Soup",
|
||||
"Italian",
|
||||
"Boba Tea Shop",
|
||||
"Other",
|
||||
"Korean / Thai",
|
||||
"Bar",
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, values)
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *RestaurantListLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
|
@ -130,23 +130,9 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
|
|||
}
|
||||
list := make([]types.GetRecommandProductListRsp, 0, len(recommendProductList))
|
||||
for _, v := range recommendProductList {
|
||||
/*r := image.ThousandFaceImageFormatReq{
|
||||
Size: int(req.Size),
|
||||
IsThousandFace: 0,
|
||||
Cover: *v.Cover,
|
||||
CoverImg: *v.CoverImg,
|
||||
CoverDefault: *v.Cover,
|
||||
ProductId: v.Id,
|
||||
UserId: userinfo.UserId,
|
||||
}
|
||||
if user.Id != 0 {
|
||||
r.IsThousandFace = int(*user.IsThousandFace)
|
||||
}
|
||||
//千人前面处理
|
||||
image.ThousandFaceImageFormat(&r)*/
|
||||
isRecommend := int64(0)
|
||||
recommend := false
|
||||
if _, ok := mapRecommend[v.Id]; ok {
|
||||
isRecommend = 1
|
||||
recommend = true
|
||||
}
|
||||
minPrice := int64(0)
|
||||
if minVal, ok := mapProductMinPrice[v.Id]; ok {
|
||||
|
@ -163,7 +149,7 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
|
|||
CoverImgMetadata: mapResourceMetadata[*v.CoverImg],
|
||||
CoverDefault: []types.CoverDefaultItem{},
|
||||
Intro: *v.Intro,
|
||||
IsRecommend: isRecommend,
|
||||
Recommend: recommend,
|
||||
MinPrice: minPrice,
|
||||
IsCustomization: *v.IsCustomization,
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ type GetRecommandProductListRsp struct {
|
|||
CoverImgMetadata interface{} `json:"cover_img_metadata"`
|
||||
CoverDefault []CoverDefaultItem `json:"cover_default"`
|
||||
Intro string `json:"intro"`
|
||||
IsRecommend int64 `json:"is_recommend"`
|
||||
Recommend bool `json:"recommend"`
|
||||
MinPrice int64 `json:"min_price"`
|
||||
IsCustomization int64 `json:"is_customization"`
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ var (
|
|||
//每个websocket渲染任务缓冲队列长度默认值
|
||||
renderChanLen = 500
|
||||
//每个websocket渲染并发数
|
||||
renderChanConcurrency = 10
|
||||
renderChanConcurrency = 100
|
||||
)
|
||||
|
||||
// 渲染处理器
|
||||
|
@ -133,7 +133,7 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
|
|||
return
|
||||
}
|
||||
if !strings.Contains(renderImageData.RenderData.Logo, "storage.fusenpack.com") {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "logo不是属于fusen的资源", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "非法的logo", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
return
|
||||
}
|
||||
lenColor := len(renderImageData.RenderData.TemplateTagColor.Colors)
|
||||
|
|
|
@ -12,6 +12,12 @@ service collection {
|
|||
//收藏产品
|
||||
@handler CollectProductHandler
|
||||
post /api/collection/collect_product(CollectProductReq) returns (response);
|
||||
//删除收藏
|
||||
@handler DeleteCollectProductHandler
|
||||
post /api/collection/delete_collect_product(DeleteCollectProductReq) returns (response);
|
||||
//获取收藏列表
|
||||
@handler GetCollectProductListHandler
|
||||
get /api/collection/get_collect_product_list(GetCollectProductListReq) returns (response);
|
||||
}
|
||||
|
||||
//收藏产品
|
||||
|
@ -20,4 +26,22 @@ type CollectProductReq {
|
|||
Logo string `json:"logo"`
|
||||
SelectColorIndex int64 `json:"select_color_index"`
|
||||
TemplateTag string `json:"template_tag"`
|
||||
}
|
||||
//删除收藏
|
||||
type DeleteCollectProductReq {
|
||||
Ids []int64 `json:"ids"`
|
||||
}
|
||||
//获取收藏列表
|
||||
type GetCollectProductListReq {
|
||||
CurrentPage int `form:"current_page"`
|
||||
}
|
||||
type GetCollectProductListRspItem {
|
||||
Id int64 `json:"id"`
|
||||
ProductId int64 `json:"product_id"`
|
||||
ProductName string `json:"product_name"`
|
||||
Logo string `json:"logo"`
|
||||
SelectColorIndex int64 `json:"select_color_index"`
|
||||
TemplateTag string `json:"template_tag"`
|
||||
SizeCount int64 `json:"size_count"`
|
||||
MinPrice string `json:"min_price"`
|
||||
}
|
|
@ -36,6 +36,9 @@ service info {
|
|||
|
||||
@handler AddressListHandler
|
||||
get /api/info/address/list(request) returns (response);
|
||||
|
||||
@handler RestaurantListHandler
|
||||
get /api/info/restaurant/list(request) returns (response);
|
||||
}
|
||||
|
||||
type (
|
||||
|
|
|
@ -65,7 +65,7 @@ type GetRecommandProductListRsp {
|
|||
CoverImgMetadata interface{} `json:"cover_img_metadata"`
|
||||
CoverDefault []CoverDefaultItem `json:"cover_default"`
|
||||
Intro string `json:"intro"`
|
||||
IsRecommend int64 `json:"is_recommend"`
|
||||
Recommend bool `json:"recommend"`
|
||||
MinPrice int64 `json:"min_price"`
|
||||
IsCustomization int64 `json:"is_customization"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user