From f933fcac69ffd4f70704bedfa829fa4638c16aa9 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Sun, 8 Oct 2023 10:31:42 +0800 Subject: [PATCH 01/14] fix --- .../logic/getrecommandproductlistlogic.go | 18 ++---------------- server/product/internal/types/types.go | 2 +- server_api/product.api | 2 +- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/server/product/internal/logic/getrecommandproductlistlogic.go b/server/product/internal/logic/getrecommandproductlistlogic.go index 24721e95..bd050416 100644 --- a/server/product/internal/logic/getrecommandproductlistlogic.go +++ b/server/product/internal/logic/getrecommandproductlistlogic.go @@ -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) + isRecommend := false if _, ok := mapRecommend[v.Id]; ok { - isRecommend = 1 + isRecommend = true } minPrice := int64(0) if minVal, ok := mapProductMinPrice[v.Id]; ok { diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 201907ce..c6ff15a6 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -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"` + IsRecommend bool `json:"is_recommend"` MinPrice int64 `json:"min_price"` IsCustomization int64 `json:"is_customization"` } diff --git a/server_api/product.api b/server_api/product.api index e4f1b65f..3e3a4422 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -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"` + IsRecommend bool `json:"is_recommend"` MinPrice int64 `json:"min_price"` IsCustomization int64 `json:"is_customization"` } From 0fde3c8d9147a4bdc4bb12aa527fe749054c2cdb Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Sun, 8 Oct 2023 10:33:25 +0800 Subject: [PATCH 02/14] fix --- .../product/internal/logic/getrecommandproductlistlogic.go | 6 +++--- server/product/internal/types/types.go | 2 +- server_api/product.api | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/server/product/internal/logic/getrecommandproductlistlogic.go b/server/product/internal/logic/getrecommandproductlistlogic.go index bd050416..2877ef95 100644 --- a/server/product/internal/logic/getrecommandproductlistlogic.go +++ b/server/product/internal/logic/getrecommandproductlistlogic.go @@ -130,9 +130,9 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec } list := make([]types.GetRecommandProductListRsp, 0, len(recommendProductList)) for _, v := range recommendProductList { - isRecommend := false + recommend := false if _, ok := mapRecommend[v.Id]; ok { - isRecommend = true + recommend = true } minPrice := int64(0) if minVal, ok := mapProductMinPrice[v.Id]; ok { @@ -149,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, } diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index c6ff15a6..05455455 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -22,7 +22,7 @@ type GetRecommandProductListRsp struct { CoverImgMetadata interface{} `json:"cover_img_metadata"` CoverDefault []CoverDefaultItem `json:"cover_default"` Intro string `json:"intro"` - IsRecommend bool `json:"is_recommend"` + Recommend bool `json:"recommend"` MinPrice int64 `json:"min_price"` IsCustomization int64 `json:"is_customization"` } diff --git a/server_api/product.api b/server_api/product.api index 3e3a4422..a2a371bb 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -65,7 +65,7 @@ type GetRecommandProductListRsp { CoverImgMetadata interface{} `json:"cover_img_metadata"` CoverDefault []CoverDefaultItem `json:"cover_default"` Intro string `json:"intro"` - IsRecommend bool `json:"is_recommend"` + Recommend bool `json:"recommend"` MinPrice int64 `json:"min_price"` IsCustomization int64 `json:"is_customization"` } From 04106851382f78670bcccc64ac1ed84533bfc518 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Sun, 8 Oct 2023 11:23:22 +0800 Subject: [PATCH 03/14] info address default --- model/gmodel/fs_address_logic.go | 53 ++++++++++++-------------------- 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 154c9d88..83ff4e7c 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -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) { - err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1", userId).Order("`ctime` 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 { return nil, err } @@ -65,44 +65,31 @@ 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 + + if isDefault == 1 { + err = tx.Where("`user_id` = ? and `status` = 1 and `ltime` > ? and `address_id` != ?", userId, now.AddDate(10, 0, 0), addressId). + UpdateColumn("ltime", now). + UpdateColumn("utime", now).Error + if err != nil { + return err + } + } + + tr := tx.Where("`address_id` = ? and `user_id` = ? and `status` = 1", addressId, userId). + UpdateColumn("utime", now) + if isDefault == 1 { + tr.UpdateColumn("ltime", now.AddDate(250, 0, 0)) + } else { + tr.UpdateColumn("ltime", now) + } + + err = tr.Error if err != nil { return err } From 32b8ceeb960ff509919bd78816833b80fb63851b Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Sun, 8 Oct 2023 11:29:04 +0800 Subject: [PATCH 04/14] info address default --- model/gmodel/fs_address_gen.go | 1 - model/gmodel/fs_address_logic.go | 1 - model/gmodel/fs_admin_menu_gen.go | 1 + model/gmodel/fs_admin_role_gen.go | 1 - 4 files changed, 1 insertion(+), 3 deletions(-) diff --git a/model/gmodel/fs_address_gen.go b/model/gmodel/fs_address_gen.go index 902d869f..cb740a7c 100644 --- a/model/gmodel/fs_address_gen.go +++ b/model/gmodel/fs_address_gen.go @@ -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 diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 83ff4e7c..863ec21d 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -37,7 +37,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, diff --git a/model/gmodel/fs_admin_menu_gen.go b/model/gmodel/fs_admin_menu_gen.go index 22bd67f9..06841189 100644 --- a/model/gmodel/fs_admin_menu_gen.go +++ b/model/gmodel/fs_admin_menu_gen.go @@ -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 diff --git a/model/gmodel/fs_admin_role_gen.go b/model/gmodel/fs_admin_role_gen.go index 15dfeb91..498a4a09 100644 --- a/model/gmodel/fs_admin_role_gen.go +++ b/model/gmodel/fs_admin_role_gen.go @@ -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 From 24304b0c851c3b8f762d56118ce1f8b7600e1140 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Sun, 8 Oct 2023 11:38:10 +0800 Subject: [PATCH 05/14] info address default --- model/gmodel/fs_address_logic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 863ec21d..387d4108 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -80,7 +80,7 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i } } - tr := tx.Where("`address_id` = ? and `user_id` = ? and `status` = 1", addressId, userId). + tr := tx.Model(&FsAddress{}).Where("`address_id` = ? and `user_id` = ? and `status` = 1", addressId, userId). UpdateColumn("utime", now) if isDefault == 1 { tr.UpdateColumn("ltime", now.AddDate(250, 0, 0)) From f8c8c634cb93a4b25c4cc976b93279ad0ae5eaf9 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Sun, 8 Oct 2023 11:46:51 +0800 Subject: [PATCH 06/14] info address default --- model/gmodel/fs_address_logic.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 387d4108..9d045ed0 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -70,23 +70,22 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i logx.Info("address_id:", addressId, " set default ", isDefault) now := time.Now().UTC() + 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). - UpdateColumn("ltime", now). - UpdateColumn("utime", now).Error + 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). - UpdateColumn("utime", now) - if isDefault == 1 { - tr.UpdateColumn("ltime", now.AddDate(250, 0, 0)) - } else { - tr.UpdateColumn("ltime", now) - } + UpdateColumns(updates) err = tr.Error if err != nil { @@ -100,6 +99,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 @@ -111,9 +111,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 } From bfeacad5f00fac3a67088e056f8149dea4a85a24 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Sun, 8 Oct 2023 11:55:06 +0800 Subject: [PATCH 07/14] info address default --- model/gmodel/fs_address_logic.go | 12 +++++++++++- model/gmodel/var.go | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 9d045ed0..be53c4e0 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -13,11 +13,21 @@ 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) { +func (a *FsAddressModel) GetUserAllAddress(ctx context.Context, userId int64) (resp []*FsAddressWithDefault, err error) { err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1", userId).Order("`ltime` DESC").Find(&resp).Error if err != nil { return nil, err } + + now := time.Now().UTC().AddDate(10, 0, 0).Unix() + for _, r := range resp { + if r.Ltime.UTC().Unix() > now { + r.IsDefault = 1 + } else { + r.IsDefault = 0 + } + } + return } diff --git a/model/gmodel/var.go b/model/gmodel/var.go index 59559d8e..447d1329 100644 --- a/model/gmodel/var.go +++ b/model/gmodel/var.go @@ -63,3 +63,8 @@ type UserProfileBase struct { Resetaurant string `json:"resetaurant"` // 不知道干什么 Company string `json:"company"` // 公司 } + +type FsAddressWithDefault struct { + FsAddress + IsDefault int64 `json:"is_default"` +} From b93691a0bfdc81f88214952883d1b9dd4dfbea17 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Sun, 8 Oct 2023 12:04:00 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=94=B6=E8=97=8F?= =?UTF-8?q?=E9=A1=B5=E7=9A=84=E6=B7=BB=E5=8A=A0=E5=92=8C=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/gmodel/fs_product_collection_logic.go | 37 +++++++++++- .../handler/deletecollectproducthandler.go | 35 ++++++++++++ .../handler/getcollectproductlisthandler.go | 35 ++++++++++++ server/collection/internal/handler/routes.go | 10 ++++ .../internal/logic/collectproductlogic.go | 57 +++++++++++++++++-- .../logic/deletecollectproductlogic.go | 50 ++++++++++++++++ .../logic/getcollectproductlistlogic.go | 43 ++++++++++++++ server/collection/internal/types/types.go | 19 +++++++ server_api/collection.api | 24 ++++++++ 9 files changed, 305 insertions(+), 5 deletions(-) create mode 100644 server/collection/internal/handler/deletecollectproducthandler.go create mode 100644 server/collection/internal/handler/getcollectproductlisthandler.go create mode 100644 server/collection/internal/logic/deletecollectproductlogic.go create mode 100644 server/collection/internal/logic/getcollectproductlistlogic.go diff --git a/model/gmodel/fs_product_collection_logic.go b/model/gmodel/fs_product_collection_logic.go index e68225aa..1db33376 100644 --- a/model/gmodel/fs_product_collection_logic.go +++ b/model/gmodel/fs_product_collection_logic.go @@ -1,2 +1,37 @@ package gmodel -// TODO: 使用model的属性做你想做的 \ No newline at end of file + +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 +} diff --git a/server/collection/internal/handler/deletecollectproducthandler.go b/server/collection/internal/handler/deletecollectproducthandler.go new file mode 100644 index 00000000..ade28468 --- /dev/null +++ b/server/collection/internal/handler/deletecollectproducthandler.go @@ -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) + } + } +} diff --git a/server/collection/internal/handler/getcollectproductlisthandler.go b/server/collection/internal/handler/getcollectproductlisthandler.go new file mode 100644 index 00000000..a3998d7d --- /dev/null +++ b/server/collection/internal/handler/getcollectproductlisthandler.go @@ -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) + } + } +} diff --git a/server/collection/internal/handler/routes.go b/server/collection/internal/handler/routes.go index e2b230b6..1d8b59a5 100644 --- a/server/collection/internal/handler/routes.go +++ b/server/collection/internal/handler/routes.go @@ -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), + }, }, ) } diff --git a/server/collection/internal/logic/collectproductlogic.go b/server/collection/internal/logic/collectproductlogic.go index b421949c..c006d877 100644 --- a/server/collection/internal/logic/collectproductlogic.go +++ b/server/collection/internal/logic/collectproductlogic.go @@ -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 必须重新处理 diff --git a/server/collection/internal/logic/deletecollectproductlogic.go b/server/collection/internal/logic/deletecollectproductlogic.go new file mode 100644 index 00000000..cdf1900e --- /dev/null +++ b/server/collection/internal/logic/deletecollectproductlogic.go @@ -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) +// } diff --git a/server/collection/internal/logic/getcollectproductlistlogic.go b/server/collection/internal/logic/getcollectproductlistlogic.go new file mode 100644 index 00000000..ca91aef1 --- /dev/null +++ b/server/collection/internal/logic/getcollectproductlistlogic.go @@ -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) +// } diff --git a/server/collection/internal/types/types.go b/server/collection/internal/types/types.go index bf094d09..d67837ac 100644 --- a/server/collection/internal/types/types.go +++ b/server/collection/internal/types/types.go @@ -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 { } diff --git a/server_api/collection.api b/server_api/collection.api index 9fc2de66..0e24e0f2 100644 --- a/server_api/collection.api +++ b/server_api/collection.api @@ -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"` } \ No newline at end of file From 8bc1607f009d363ef454fc76b32264e57f79525f Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Sun, 8 Oct 2023 12:04:02 +0800 Subject: [PATCH 09/14] info address default --- model/gmodel/fs_address_logic.go | 20 ++++++++++++++------ model/gmodel/var.go | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index be53c4e0..ff3b16dc 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -14,18 +14,26 @@ func (a *FsAddressModel) GetOne(ctx context.Context, addressId int64, userId int } func (a *FsAddressModel) GetUserAllAddress(ctx context.Context, userId int64) (resp []*FsAddressWithDefault, err error) { - err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1", userId).Order("`ltime` DESC").Find(&resp).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 resp { - if r.Ltime.UTC().Unix() > now { - r.IsDefault = 1 - } else { - r.IsDefault = 0 + 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 diff --git a/model/gmodel/var.go b/model/gmodel/var.go index 447d1329..9f603ae5 100644 --- a/model/gmodel/var.go +++ b/model/gmodel/var.go @@ -65,6 +65,6 @@ type UserProfileBase struct { } type FsAddressWithDefault struct { - FsAddress + *FsAddress IsDefault int64 `json:"is_default"` } From 243fd29a608ddafb98f39c5b149228ca5c0f3e97 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Sun, 8 Oct 2023 12:06:48 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=94=B6=E8=97=8F?= =?UTF-8?q?=E9=A1=B5=E7=9A=84=E6=B7=BB=E5=8A=A0=E5=92=8C=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/websocket/internal/logic/ws_render_image.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index a9a7b005..d8100706 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -24,7 +24,7 @@ var ( //每个websocket渲染任务缓冲队列长度默认值 renderChanLen = 500 //每个websocket渲染并发数 - renderChanConcurrency = 10 + renderChanConcurrency = 100 ) // 渲染处理器 From 0f7d35ea003061ec78c143c6e03a48f2ed404263 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Sun, 8 Oct 2023 12:09:46 +0800 Subject: [PATCH 11/14] info address default --- server/info/internal/logic/addressdefaultlogic.go | 1 + server/info/internal/logic/addressupdatelogic.go | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/server/info/internal/logic/addressdefaultlogic.go b/server/info/internal/logic/addressdefaultlogic.go index 6df93f27..90a798ab 100644 --- a/server/info/internal/logic/addressdefaultlogic.go +++ b/server/info/internal/logic/addressdefaultlogic.go @@ -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 } diff --git a/server/info/internal/logic/addressupdatelogic.go b/server/info/internal/logic/addressupdatelogic.go index d6ef1953..e70d377b 100644 --- a/server/info/internal/logic/addressupdatelogic.go +++ b/server/info/internal/logic/addressupdatelogic.go @@ -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 { From 23094b2427b806779f0bcfbdeff46c144d1c8670 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Sun, 8 Oct 2023 12:11:19 +0800 Subject: [PATCH 12/14] 11 --- server/websocket/internal/logic/ws_render_image.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index d8100706..f05108fe 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -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) From bdf0dd7605e09eae3c21f85fe8924d06a4532342 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Sun, 8 Oct 2023 12:18:58 +0800 Subject: [PATCH 13/14] info address default --- .../internal/handler/restaurantlisthandler.go | 35 +++++++++ server/info/internal/handler/routes.go | 5 ++ .../internal/logic/restaurantlistlogic.go | 71 +++++++++++++++++++ server_api/info.api | 3 + 4 files changed, 114 insertions(+) create mode 100644 server/info/internal/handler/restaurantlisthandler.go create mode 100644 server/info/internal/logic/restaurantlistlogic.go diff --git a/server/info/internal/handler/restaurantlisthandler.go b/server/info/internal/handler/restaurantlisthandler.go new file mode 100644 index 00000000..f6dd9afc --- /dev/null +++ b/server/info/internal/handler/restaurantlisthandler.go @@ -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) + } + } +} diff --git a/server/info/internal/handler/routes.go b/server/info/internal/handler/routes.go index f35abb84..69e3e7e8 100644 --- a/server/info/internal/handler/routes.go +++ b/server/info/internal/handler/routes.go @@ -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), + }, }, ) } diff --git a/server/info/internal/logic/restaurantlistlogic.go b/server/info/internal/logic/restaurantlistlogic.go new file mode 100644 index 00000000..ecd26341 --- /dev/null +++ b/server/info/internal/logic/restaurantlistlogic.go @@ -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) +// } diff --git a/server_api/info.api b/server_api/info.api index f467dce8..a4048595 100644 --- a/server_api/info.api +++ b/server_api/info.api @@ -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 ( From 385540937eeb3ec542d81a0a96af9f9eb4b4ac0d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Sun, 8 Oct 2023 12:31:06 +0800 Subject: [PATCH 14/14] 11 --- server/collection/etc/collection.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/collection/etc/collection.yaml b/server/collection/etc/collection.yaml index 0cffe614..439fbc1c 100644 --- a/server/collection/etc/collection.yaml +++ b/server/collection/etc/collection.yaml @@ -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: ""