shoppingcart

package
v0.0.0-...-f5e7097 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

README

购物车业务组件实现

  • 使用set和hash实现

  • set用于储存每个用户的购物车商品id信息

  • hash储存每一个用户-商品的信息

提供以下接口

type ICart interface {
	Create(userId string, item Item) (err error)                  //添加一个商品
	Remove(userId string, itemId string) (err error)              //删除一个商品
	Removes(userId string, itemId []string) (err error)           //删除多个商品
	Incr(userId string, itemId string) (err error)                //商品加1
	Decr(userId string, itemId string) (err error)                //商品减1
	Clear(userId string) (err error)                              //清除购物车
	List(userId string) (item []*Item, err error)                 //购物车列表
	GetItem(userId string, itemId string) (item *Item, err error) //获取一个购物车详情
	Count(userId string) (count int64, err error)                 //购物车合计数量
	HasItem(userId string, itemId string) (flag bool, err error)  //是否已经加入了购物车
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ICart

type ICart interface {
	Create(userId string, item Item) (err error)                  //添加一个商品
	Remove(userId string, itemId string) (err error)              //删除一个商品
	Removes(userId string, itemId []string) (err error)           //删除多个商品
	Incr(userId string, itemId string) (err error)                //商品加1
	Decr(userId string, itemId string) (err error)                //商品减1
	Clear(userId string) (err error)                              //清除购物车
	List(userId string) (item []*Item, err error)                 //购物车列表
	GetItem(userId string, itemId string) (item *Item, err error) //获取一个购物车详情
	Count(userId string) (count int64, err error)                 //购物车合计数量
	HasItem(userId string, itemId string) (flag bool, err error)  //是否已经加入了购物车
}

func New

func New(redis ...*gredis.Redis) ICart

type Item

type Item struct {
	ItemId     string      `json:"item_id"`
	Sku        string      `json:"sku"`
	Spu        string      `json:"spu"`
	Num        int64       `json:"num"`
	SalePrice  float64     `json:"sale_price"` // 记录加车时候的销售价格
	CreateTime int64       `json:"create_time"`
	CustomAttr g.MapStrAny `json:"custom_attr"` //自定义数据
}

单个商品item元素

type ItemActivity

type ItemActivity struct {
	ActID    string `json:"act_id"`    //活动id
	ActType  string `json:"act_type"`  //活动类型
	ActTitle string `json:"act_title"` //活动标题
}

活动

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL