Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user