Ejemplo n.º 1
0
// 根据指定商品快照
func (this *goodsRep) GetSnapshots(skuIdArr []int) []goods.Snapshot {
	list := []goods.Snapshot{}
	this.Connector.GetOrm().SelectByQuery(&list,
		`SELECT * FROM gs_snapshot WHERE sku_id IN (`+
			format.IdArrJoinStr(skuIdArr)+`)`)
	return list
}
Ejemplo n.º 2
0
// 获取已上架的商品
func (this *goodsRep) GetPagedOnShelvesGoods(mchId int, catIds []int, start, end int, where, orderBy string) (total int, e []*valueobject.Goods) {
	var sql string

	catIdStr := ""
	if catIds != nil && len(catIds) > 0 {
		catIdStr = fmt.Sprintf(" AND gs_category.id IN (%s)",
			format.IdArrJoinStr(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 (?<=0 OR supplier_id=?) %s AND gs_item.state=1
		 AND gs_item.on_shelves=1 %s`, catIdStr, where), &total, mchId, mchId)

	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 (?<=0 OR supplier_id=?) %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, mchId, mchId)
	}

	return total, e
}
Ejemplo n.º 3
0
// 根据编号获取商品
func (this *goodsRep) 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.IdArrJoinStr(ids)+`)`)

	return items, err
}
Ejemplo n.º 4
0
func (this *itemRep) GetItemByIds(ids ...int) ([]*item.Item, error) {
	//todo: merchantId
	var items []*item.Item

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

	return items, err
}
Ejemplo n.º 5
0
func (this *itemRep) GetPagedOnShelvesItem(merchantId int, catIds []int,
	start, end int) (total int, e []*item.Item) {
	var sql string

	var catIdStr string = format.IdArrJoinStr(catIds)
	sql = fmt.Sprintf(`SELECT * FROM gs_item INNER JOIN gs_category ON gs_item.category_id=gs_category.id
		WHERE merchant_id=%d AND gs_category.id IN (%s) AND on_shelves=1 LIMIT %d,%d`, merchantId, 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 merchant_id=%d AND gs_category.id IN (%s) AND on_shelves=1`, merchantId, catIdStr), &total)

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

	return total, e
}