package dao

import "git.rosy.net.cn/jx-callback/business/model"

func GetVendorImg(skuId, vendorId int) (*model.TaoSkuImg, error) {
	result := &model.TaoSkuImg{}

	sql := ` SELECT * FROM tao_sku_img WHERE sku_id = ? AND vendor_id = ?`
	parma := []interface{}{skuId, vendorId}

	if err := GetRow(GetDB(), result, sql, parma); err != nil {
		return nil, err
	}

	return result, nil
}

func GetCopyInfo(fromVendorStoreId string, fromVendorId int, toVendorStoreID string, toVendorId int) (map[string]*model.CopyVendorSku, error) {
	result := make([]*model.CopyVendorSku, 0, 0)
	sql := ` SELECT * FROM copy_vendor_sku WHERE from_store_id = ? AND from_vendor_id = ? AND to_store_id = ? AND to_vendor_id = ?`

	if err := GetRows(GetDB(), &result, sql, []interface{}{fromVendorStoreId, fromVendorId, toVendorStoreID, toVendorId}); err != nil {
		return nil, err
	}

	data := make(map[string]*model.CopyVendorSku, len(result))
	for _, v := range result {
		data[v.FromSkuID] = v
	}

	return data, nil
}
