Browse Source

ProductNotAllow

abiao 1 year ago
parent
commit
a5409dffce

+ 9 - 0
go/gopath/src/fohow.com/apps/controllers/product_controller/product_controller.go

@@ -222,6 +222,15 @@ func (self *ProductController) Get() {
 	if wxUser == nil {
 		self.ReturnError(403, apps.NoExist, "", nil)
 	}
+
+	user := self.GetCurrentUser(false)
+	if user != nil && user.Tel != "" {
+		empploy := user_model.GetEmployer(user.Tel, false)
+		if empploy == nil && pd.CategoryId == product_model.ProdutEmploySort {
+			self.ReturnError(403, apps.ProductNotAllow, "", nil)
+		}
+	}
+
 	pd.CanBuy = product_model.DecideCanBuy(pd.RelateProductId, wxUser.Depart)
 	// ret.Product = pd
 	self.Data["json"] = pd

+ 1 - 0
go/gopath/src/fohow.com/apps/init.go

@@ -42,6 +42,7 @@ var (
 	ShopNoRepit           = []string{"shopNoRepit", "请勿重复申请"}
 	NoCart                = []string{"noCart", "请选择您需要结算的产品"}
 	NoExist               = []string{"noExist", "该记录不存在"}
+	ProductNotAllow       = []string{"productNotAllow", "该商品无法购买"}
 	TokenError            = []string{"tokenError", "生成令牌出错"}
 	HasOver               = []string{"hasOver", "已结束"}
 	NoShopSale            = []string{"noShopSale", "该商品非专区商品"}

+ 10 - 8
go/gopath/src/fohow.com/apps/models/product_model/product.go

@@ -41,6 +41,8 @@ const (
 	DELIVER_STATE_2 = int64(2) //进行中
 	DELIVER_STATE_3 = int64(3) //已结束
 
+	//Employ Sort
+	ProdutEmploySort = 25
 )
 
 func (self *Product) TableName() string {
@@ -127,7 +129,7 @@ type Product struct {
 	CanBuy           bool            `orm:"-"                              json:"can_buy"`           // bool
 }
 
-//获取最新推荐商品
+// 获取最新推荐商品
 func GetLatest(page, perPage, recommend, priceSort, saleSort, saleZone, depart int64, ptype string, useCache bool) (products []*Product) {
 	k := fmt.Sprintf("product_model.GetLatest.page(%d).perPage(%d).recommend(%d)", page, perPage, recommend)
 	if useCache {
@@ -238,7 +240,7 @@ func GetLatestCount(recommend, saleZone int64, ptype string, useCache bool) int6
 	return count
 }
 
-//根据商品Id,获取商品信息
+// 根据商品Id,获取商品信息
 func GetProductById(id int64, useCache bool) *Product {
 	//k := fmt.Sprintf("product_model.GetProductById[%d]", id)
 	k := cache.GetKey(cache.GetProductByPId, id)
@@ -257,7 +259,7 @@ func GetProductById(id int64, useCache bool) *Product {
 	return item
 }
 
-//判断商品是否在当前省可发货
+// 判断商品是否在当前省可发货
 func GetProductByIdAndProvince(id int64, province string, useCache bool) *Product {
 	//k := fmt.Sprintf("product_model.GetProductById[%d]", id)
 	k := cache.GetKey(cache.GetProductByPIdAndProvince, id, province)
@@ -281,7 +283,7 @@ func GetProductByIdAndProvince(id int64, province string, useCache bool) *Produc
 	return item
 }
 
-//判断商品是否在当前省受限
+// 判断商品是否在当前省受限
 func GetNoDeliveryPrd(id int64, province string, useCache bool) *Product {
 	//k := fmt.Sprintf("product_model.GetProductById[%d]", id)
 	k := cache.GetKey(cache.GetNoDeliveryPrd, id, province)
@@ -490,7 +492,7 @@ func (self *Product) Save() error {
 	return nil
 }
 
-//根据关联商品Id,sizeId,colorId,获取商品信息
+// 根据关联商品Id,sizeId,colorId,获取商品信息
 func GetProductByIdAndSizeAndColor(id, sizeId, colorId int64, useCache bool) *Product {
 	k := fmt.Sprintf("product_model.GetProductByIdAndSizeAndColor[%d]", id)
 	if useCache {
@@ -508,7 +510,7 @@ func GetProductByIdAndSizeAndColor(id, sizeId, colorId int64, useCache bool) *Pr
 	return item
 }
 
-//根据商品 relate_Id 跟 sizeId,获取商品信息
+// 根据商品 relate_Id 跟 sizeId,获取商品信息
 func GetProductByIdAndSizeId(relateId, sizeId int64, useCache bool) *Product {
 	k := fmt.Sprintf("product_model.GetProductByRelateId[%d]SizeId[%d]", relateId, sizeId)
 	if useCache {
@@ -527,7 +529,7 @@ func GetProductByIdAndSizeId(relateId, sizeId int64, useCache bool) *Product {
 	return item
 }
 
-//根据商品 relate_Id 跟 colorId,获取商品信息
+// 根据商品 relate_Id 跟 colorId,获取商品信息
 func GetProductByIdAndColorId(relateId, colorId int64, useCache bool) *Product {
 	k := fmt.Sprintf("product_model.GetProductByRelateId[%d]ColorId[%d]", relateId, colorId)
 	if useCache {
@@ -545,7 +547,7 @@ func GetProductByIdAndColorId(relateId, colorId int64, useCache bool) *Product {
 	return item
 }
 
-//获取某主商品销售总量
+// 获取某主商品销售总量
 func GetProductCountByRelateId(relateId int64, useCache bool) int64 {
 	type Ret struct {
 		Count int64

+ 1 - 1
go/gopath/src/fohow.com/apps/models/product_model/product_cat.go

@@ -62,7 +62,7 @@ func GetProductCatsByAncestry(ancestry string, employ bool) (cats []*ProductCat)
 			OrderBy("-position")
 	}
 	if !employ {
-		qs = qs.Exclude("id", 25)
+		qs = qs.Exclude("id", ProdutEmploySort)
 	}
 	qs.All(&cats)
 	return cats