Dao.php 2.48 KB
<?php

/**
 * 商品图片
 * @author tongdesheng
 *
 */
use YHMProduct\SqlMap\Goodsimages;

class YHMProduct_Models_Goodsimages_Dao extends YHMProduct_Dao
{

    private $_tag = 'yhm_goods_images_';

    public function __construct()
    {
        $this->router = 'goods.yhm_shops';
    }

    /**
     * 通过skc获取所有商品图片
     * @param integer $product_skc
     */
    public function getByProductSkc($product_skc)
    {
        return $this->dao()->tag($this->_tag . $product_skc)->key('getByProductSkc')->fetchAll(Goodsimages\Goodsimages::SELECT_IMAGES_BY_SKC, array('product_skc' => $product_skc));
    }

    /**
     * 通过skc获取默认展示图片
     * @param int $product_skc
     */
    public function getDefaultImageBySkc($product_skc)
    {
        return $this->dao()->tag($this->_tag . $product_skc)->key('getDefaultImageBySkc')->fetchOne(Goodsimages\Goodsimages::SELECT_DEFAULT_IMAGES_BY_SKC, array('product_skc' => $product_skc));
    }

    /**
     * 通过skc获取一个
     * @param $product_skc
     * @param $size
     * @return Array
     */
    public function getOneImagesBySkc($product_skc)
    {
        return $this->dao()->tag($this->_tag . $product_skc)->fetchOne(Goodsimages\Goodsimages::SELECT_ONE_IMAGES, array(
            'product_skc' => $product_skc,
            'size' => 1
        ));
    }

    /**
     * 获取最新的一张图片,用于没有默认图时
     * @param int $product_skc
     * @return type
     */
    public function getOneImageBySkc($product_skc)
    {
        return $this->dao()->tag($this->_tag . $product_skc)->key('getOneImageBySkc')->fetchOne(Goodsimages\Goodsimages::SELECT_ONE_IMAGES_BY_SKC, array('product_skc' => $product_skc));
    }

    /**
     * 添加商品图片
     * @param intger $product_skc
     * @param string $image_path
     * @param enum $is_default
     */
    public function setGoodsImage($product_skc, $image_path, $is_default)
    {
        return $this->dao()->tag($this->_tag . $product_skc)->insert(Goodsimages\Goodsimages::INSERT_IMAGES, array(
            'product_skc' => $product_skc,
            'image_path' => $image_path,
            'is_default' => $is_default
        ));
    }

    /**
     * 删除指定skc下所有图片
     * @param integer $product_skc
     */
    public function delByProductSkc($product_skc)
    {
        return $this->dao()->tag($this->_tag . $product_skc)->delete(Goodsimages\Goodsimages::DELETE_IMAGES_BY_SKC, array(
            'product_skc' => $product_skc
        ));
    }

}