历史记录功能
This commit is contained in:
parent
ca9d697a6a
commit
367db36c7a
@ -14,6 +14,9 @@ type ItemController struct {
|
|||||||
|
|
||||||
func (c *ItemController) BeforeActivation(b mvc.BeforeActivation) {
|
func (c *ItemController) BeforeActivation(b mvc.BeforeActivation) {
|
||||||
b.Handle("GET", "/detail/{id:uint}", "Detail")
|
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", "/list/type/{ttype:int}", "GetListByType")
|
||||||
b.Handle("GET", "/search", "Search")
|
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
|
// @Summary get item list api
|
||||||
// @Description 通过类型获取相关商品列表
|
// @Description 通过类型获取相关商品列表
|
||||||
// @Tags item api
|
// @Tags item api
|
||||||
|
8
model/history_model.go
Normal file
8
model/history_model.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
type HistoryModel struct {
|
||||||
|
BaseModel
|
||||||
|
UserId uint
|
||||||
|
ItemId uint
|
||||||
|
Count int
|
||||||
|
}
|
@ -60,6 +60,21 @@ func (s *ItemService) Search(keyword string, page int, page_size int) (items []m
|
|||||||
return
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
// 类型服务模块
|
// 类型服务模块
|
||||||
/*********************************************************************************/
|
/*********************************************************************************/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user