From 367db36c7ad7636cfdd07c7cc6e5eff9578ca17d Mon Sep 17 00:00:00 2001 From: wzj Date: Sun, 12 Jan 2025 13:50:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/item_controller.go | 18 ++++++++++++++++++ model/history_model.go | 8 ++++++++ service/item_service.go | 15 +++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 model/history_model.go diff --git a/controller/item_controller.go b/controller/item_controller.go index 1218c68..9222589 100644 --- a/controller/item_controller.go +++ b/controller/item_controller.go @@ -14,6 +14,9 @@ type ItemController struct { func (c *ItemController) BeforeActivation(b mvc.BeforeActivation) { b.Handle("GET", "/detail/{id:uint}", "Detail") + + b.Handle("PUT", "/history/{id:uint}", "PutHistory") + b.Handle("GET", "/list/type/{ttype:int}", "GetListByType") b.Handle("GET", "/search", "Search") @@ -48,6 +51,21 @@ func (c *ItemController) Detail(id uint) mvc.Result { } } +// @Summary 上传用户浏览历史记录 +// @Description 上传用户浏览历史记录 +// @Tags item api +// @Accept json +// @Produce json +// @Param id path uint true "商品ID" +// @Success 200 {object} map[string]interface{} "{"msg": "历史记录统计成功"}" +// @Failure 400 {object} map[string]interface{} "{"msg": "错误信息","code":0}" +// @Router /api/item/history/{id} [put] +func (c *ItemController) DetailHistory(id uint) mvc.Result { + uid := GetUidFromCtx(c.Ctx) + e := c.Service.Item.PutHistory(uid, id) + return e.Response() +} + // @Summary get item list api // @Description 通过类型获取相关商品列表 // @Tags item api diff --git a/model/history_model.go b/model/history_model.go new file mode 100644 index 0000000..530d8fa --- /dev/null +++ b/model/history_model.go @@ -0,0 +1,8 @@ +package model + +type HistoryModel struct { + BaseModel + UserId uint + ItemId uint + Count int +} diff --git a/service/item_service.go b/service/item_service.go index 325609c..c4e944e 100644 --- a/service/item_service.go +++ b/service/item_service.go @@ -60,6 +60,21 @@ func (s *ItemService) Search(keyword string, page int, page_size int) (items []m return } +// 历史记录模块 +/*********************************************************************************/ + +func (s *ItemService) PutHistory(uid uint, item_id uint) *ecode.Ecode { + h := new(model.HistoryModel) + // 查看以前共有几条纪录 + var c int64 + model.DB.Model(h).Where("uid=? and item_id=?", uid, item_id).Count(&c) + h.UserId = uid + h.ItemId = item_id + h.Count = int(c) + 1 + model.DB.Create(h) + return ecode.OK() +} + // 类型服务模块 /*********************************************************************************/