Exemplo n.º 1
0
// 获取在货架上的商品
func (this *goodsRep) GetPagedOnShelvesGoods(partnerId int, catIds []int, start, end int, where, orderBy string) (total int, e []*valueobject.Goods) {
	var sql string

	var catIdStr string = format.GetCategoryIdStr(catIds)

	if len(where) != 0 {
		where = " AND " + where
	}
	if len(orderBy) != 0 {
		orderBy += ","
	}

	this.Connector.ExecScalar(fmt.Sprintf(`SELECT COUNT(0) FROM gs_goods INNER JOIN gs_item ON gs_item.id = gs_goods.item_id
		 INNER JOIN gs_category ON gs_item.category_id=gs_category.id
		 WHERE gs_category.partner_id=? AND gs_category.id IN (%s) AND gs_item.state=1
		 AND gs_item.on_shelves=1 %s`, catIdStr, where), &total, partnerId)

	e = []*valueobject.Goods{}
	if total > 0 {
		sql = fmt.Sprintf(`SELECT * FROM gs_goods INNER JOIN gs_item ON gs_item.id = gs_goods.item_id
		 INNER JOIN gs_category ON gs_item.category_id=gs_category.id
		 WHERE gs_category.partner_id=? AND gs_category.id IN (%s) AND gs_item.state=1
		 AND gs_item.on_shelves=1 %s ORDER BY %s update_time DESC LIMIT %d,%d`, catIdStr,
			where, orderBy, start, (end - start))

		this.Connector.GetOrm().SelectByQuery(&e, sql, partnerId)
	}

	return total, e
}
Exemplo n.º 2
0
// 根据编号获取商品
func (this *saleRep) GetGoodsByIds(ids ...int) ([]*valueobject.Goods, error) {
	var items []*valueobject.Goods
	err := this.Connector.GetOrm().SelectByQuery(&items,
		`SELECT * FROM gs_goods INNER JOIN gs_item ON gs_goods.item_id=gs_item.id
	 WHERE gs_goods.id IN (`+format.GetCategoryIdStr(ids)+`)`)

	return items, err
}
Exemplo n.º 3
0
func (this *saleRep) GetItemByIds(ids ...int) ([]*sale.ValueItem, error) {
	//todo: partnerId
	var items []*sale.ValueItem

	//todo:改成database/sql方式,不使用orm
	err := this.Connector.GetOrm().SelectByQuery(&items,
		`SELECT * FROM gs_item WHERE id IN (`+format.GetCategoryIdStr(ids)+`)`)

	return items, err
}
Exemplo n.º 4
0
func (this *saleRep) GetPagedOnShelvesItem(partnerId int, catIds []int, start, end int) (total int, e []*sale.ValueItem) {
	var sql string

	var catIdStr string = format.GetCategoryIdStr(catIds)
	sql = fmt.Sprintf(`SELECT * FROM gs_item INNER JOIN gs_category ON gs_item.category_id=gs_category.id
		WHERE partner_id=%d AND gs_category.id IN (%s) AND on_shelves=1 LIMIT %d,%d`, partnerId, catIdStr, start, (end - start))

	this.Connector.ExecScalar(fmt.Sprintf(`SELECT COUNT(0) FROM gs_item INNER JOIN gs_category ON gs_item.category_id=gs_category.id
		WHERE partner_id=%d AND gs_category.id IN (%s) AND on_shelves=1`, partnerId, catIdStr), &total)

	e = []*sale.ValueItem{}
	this.Connector.GetOrm().SelectByQuery(&e, sql)

	return total, e
}
Exemplo n.º 5
0
// 获取在货架上的商品
func (this *saleRep) GetPagedOnShelvesGoods(partnerId int, catIds []int, start, end int) (total int, e []*valueobject.Goods) {
	var sql string

	var catIdStr string = format.GetCategoryIdStr(catIds)

	this.Connector.ExecScalar(fmt.Sprintf(`SELECT COUNT(0) FROM gs_goods INNER JOIN gs_item ON gs_item.id = gs_goods.item_id
		 INNER JOIN gs_category ON gs_item.category_id=gs_category.id
		 WHERE gs_category.partner_id=? AND gs_category.id IN (%s) AND gs_item.state=1
		 AND gs_item.on_shelves=1`, catIdStr), &total, partnerId)

	e = []*valueobject.Goods{}
	if total > 0 {
		sql = fmt.Sprintf(`SELECT * FROM gs_goods INNER JOIN gs_item ON gs_item.id = gs_goods.item_id
		 INNER JOIN gs_category ON gs_item.category_id=gs_category.id
		 WHERE gs_category.partner_id=? AND gs_category.id IN (%s) AND gs_item.state=1
		 AND gs_item.on_shelves=1 LIMIT %d,%d`, catIdStr, start, (end - start))

		this.Connector.GetOrm().SelectByQuery(&e, sql, partnerId)
	}

	return total, e
}