Browse Source

edit cart wx user rules

abiao 5 years ago
parent
commit
54dac670bc

+ 14 - 14
go/gopath/src/fohow.com/apps/controllers/order_controller/cart_controller.go

@@ -125,7 +125,7 @@ func (self *OrderController) ChangeItemState() {
 //批量调整购物车项目是否购买
 func (self *OrderController) MultChangeItemState() {
 
-	uId := self.GetCurrentUserId()
+	//uId := self.GetCurrentUserId()
 	wxUId := self.GetCurrentWxUserId()
 	ids := self.GetString("ids")
 	nums := self.GetString("nums")
@@ -134,7 +134,7 @@ func (self *OrderController) MultChangeItemState() {
 		self.ReturnError(403, apps.ParamsError, "", nil)
 	}
 	//先取消,后设置
-	list := order_model.GetCartItemsByUserId(uId)
+	list := order_model.GetCartItemsByWxUserId(wxUId)
 	for _, item := range list {
 		item.IsBuy = false
 		item.Save()
@@ -174,9 +174,9 @@ func (self *OrderController) MultChangeItemState() {
 func (self *OrderController) ChangeAllState() {
 
 	state, _ := self.GetBool("state", false)
-	uId := self.GetCurrentUserId()
+	//uId := self.GetCurrentUserId()
 	wxUId := self.GetCurrentWxUserId()
-	list := order_model.GetCartItemsByUserId(uId)
+	list := order_model.GetCartItemsByWxUserId(wxUId)
 	for _, item := range list {
 		cartItem := order_model.GetCartById(item.Id)
 		if cartItem == nil {
@@ -201,13 +201,13 @@ func (self *OrderController) ChangeAllState() {
 //获取会员购物车信息
 func (self *OrderController) GetCartList() {
 	cache, _ := self.GetBool("cache", false)
-	uId := self.GetCurrentUserId()
-	list := order_model.GetCartItemsByUserId(uId)
+	wxUserId := self.GetCurrentWxUserId()
+	list := order_model.GetCartItemsByWxUserId(wxUserId)
 
 	for _, item := range list {
 		product := product_model.GetProductById(item.ProductId, cache)
 		if product == nil {
-			go ClearProductCart(uId, item.ProductId)
+			go ClearProductCart(wxUserId, item.ProductId)
 			continue
 		}
 		wxUser := user_model.GetWxUserById(item.WxUserId, cache)
@@ -234,12 +234,12 @@ func (self *OrderController) GetCartList() {
 	}
 	count := int64(0)
 	total := int64(0)
-	buylist := order_model.GetCartItemsByUserIdAndBuy(uId, true)
-	for _, item := range buylist {
-		product := product_model.GetProductById(item.ProductId, cache)
-		count += item.Count
-		total += item.Count * product.Price
-	}
+	/*	buylist := order_model.GetCartItemsByUserIdAndBuy(uId, true)
+		for _, item := range buylist {
+			product := product_model.GetProductById(item.ProductId, cache)
+			count += item.Count
+			total += item.Count * product.Price
+		}*/
 
 	type Ret struct {
 		List  []*order_model.Cart `json:"list"`
@@ -251,7 +251,7 @@ func (self *OrderController) GetCartList() {
 }
 
 func ClearProductCart(userId, productId int64) {
-	cartItem := order_model.GetCartByUidAndPid(userId, productId)
+	cartItem := order_model.GetCartByWxUidAndPid(userId, productId)
 	if cartItem != nil {
 		cartItem.Delete()
 	}

+ 22 - 0
go/gopath/src/fohow.com/apps/models/order_model/cart.go

@@ -101,6 +101,17 @@ func GetCartItemsByUserId(uId int64) (items []*Cart) {
 	return items
 }
 
+//根据会员Id获取所有订单项
+func GetCartItemsByWxUserId(wxUserId int64) (items []*Cart) {
+	item := new(Cart)
+	if _, err := orm.NewOrm().QueryTable(item).
+		Filter("wx_user_id", wxUserId).All(&items); err != nil {
+		beego.BeeLogger.Debug("get cart[%d] items err=[%s]", wxUserId, err)
+		return nil
+	}
+	return items
+}
+
 //根据会员ID及状态项,获取购物车列表
 func GetCartItemsByUserIdAndBuy(uId int64, isBuy bool) (items []*Cart) {
 	item := new(Cart)
@@ -133,3 +144,14 @@ func GetCartByUidAndPid(uId, pId int64) (cart *Cart) {
 	}
 	return cart
 }
+
+// 根据wxUserId,productId获取购物车记录
+func GetCartByWxUidAndPid(wxUserId, pId int64) (cart *Cart) {
+	cart = &Cart{}
+	if err := orm.NewOrm().QueryTable(cart).Filter("wx_user_id", wxUserId).Filter("product_id", pId).Limit(1).
+		One(cart); err != nil {
+		beego.BeeLogger.Error("get cart by uId=%d err=%s", wxUserId, err)
+		cart = nil
+	}
+	return cart
+}