Ver código fonte

更改部门显示

abiao 3 anos atrás
pai
commit
abde37545b

+ 6 - 1
go/gopath/src/fohow.com/apps/controllers/product_controller/product_controller.go

@@ -213,7 +213,12 @@ func (self *ProductController) Get() {
 			pd.DeliverState = product_model.DELIVER_STATE_2
 		}
 	}
-
+	wxUId := self.GetCurrentWxUserIdByToken()
+	wxUser := user_model.GetWxUserById(wxUId, true)
+	if wxUser == nil {
+		self.ReturnError(403, apps.NoExist, "", nil)
+	}
+	pd.CanBuy = product_model.DecideCanBuy(pd.Id, wxUser.Depart)
 	// ret.Product = pd
 	self.Data["json"] = pd
 	self.ServeResultJSON()

+ 24 - 0
go/gopath/src/fohow.com/apps/models/product_model/product.go

@@ -124,6 +124,7 @@ type Product struct {
 	Silver           int64           `orm:"column(silver)"                 json:"silver"`            // varchar(255)
 	SaleZone         int64           `orm:"column(sale_zone)"              json:"sale_zone"`         // 销售区
 	SaleZoneName     string          `orm:"-"                              json:"sale_zone_name"`    // 销售区名称
+	CanBuy           bool            `orm:"-"                              json:"can_buy"`           // bool
 }
 
 //获取最新推荐商品
@@ -676,3 +677,26 @@ func DepartGetProductCountByCatId(cId, saleZone, depart int64, words string, use
 	cache.Cache.Put(k, ret.Count, 10*time.Minute)
 	return ret.Count
 }
+
+func DecideCanBuy(pid, depart int64) bool {
+
+	type Ret struct {
+		Count int64 `json:"count"` //总数
+	}
+	ret := &Ret{}
+	o := orm.NewOrm()
+	sql := `
+		 select count(DISTINCT a.id) as count from products a left join depart_records_products b on a.id=b.product_id
+			where a.id = ? and (b.depart_record_id=? or b.depart_record_id is null )
+			
+	`
+	err := o.Raw(sql, pid, depart).QueryRow(ret)
+	if err != nil {
+		beego.BeeLogger.Error("GetLatestCount, depart:%d, err=[%s]", depart, err)
+		return false
+	}
+	if ret.Count <= 0 {
+		return false
+	}
+	return true
+}