Dao.php 3.14 KB
<?php

/**
 * Created by JetBrains PhpStorm.
 * User: elkan
 * Date: 14-8-18
 * Time: 下午6:04
 * To change this template use File | Settings | File Templates.
 */
use YHMSupport\SqlMap\Choicegoods;

class YHMSupport_Models_Choicegoods_Dao extends YHMSupport_Dao {

    private $_tag = 'support_choice_goods';

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

    /**
     * 精选商品列表
     * @return type
     */
    function getList($offset, $num) {
        return $this->dao()->tag($this->_tag)->key('getList' . $offset . '_' . $num)->fetchAll(Choicegoods\Choicegoods::SELECT_CHOICE_LIST, array('offset' => $offset, 'num' => $num));
    }

    /**
     * 添加精选商品关联
     * @param number $product_skc
     * @param number $order_by
     * @param number $create_uid
     */
    function setChoice($product_skc, $order_by = 1, $create_uid = 0) {
        $params = array(
            'product_skc' => $product_skc,
            'order_by' => $order_by,
            'create_uid' => $create_uid
        );
        return $this->dao()->tag($this->_tag)->insert(Choicegoods\Choicegoods::SET_CHOICE, $params)->status();
    }

    function delChoice($product_skc) {
        return $this->dao()->tag($this->_tag)->delete(Choicegoods\Choicegoods::DELETE_CHOICE, array('product_skc' => $product_skc))->status();
    }

    /**
     * 获取所有精选
     * @return type
     */
    function getCount() {
        return $this->dao()->cache(false)->fetchOne(Choicegoods\Choicegoods::SELECT_COUNT_CHOICE);
    }

    function setSortBySkc($skc, $sort) {
        return $this->dao()->cache(false)->update(Choicegoods\Choicegoods::UPDATE_SORT_BY_SKC, array('product_skc' => $skc, 'order_by' => $sort));
    }

    /**
     * 根据类型获取所有精选
     * @return type
     */
    function getCountByType($type, $keyword) {
        $sqlArr = array();
        $param = array();
        if ($type == 1 && !empty($keyword)) {
            $sqlArr[] = "id = '$keyword'";
        }
        $sql = '1=1';
        if (!empty($sqlArr)) {
            $sql = implode(' and ', $sqlArr);
        }
        return $this->dao()->cache(false)->fetchOne(Choicegoods\Choicegoods::SELECT_COUNT_CHOICE_BY_TYPE, $param, array('sql' => $sql));
    }

    /**
     * 根据类型获精选商品列表
     * @return type
     */
    function getListByType($type, $keyword, $offset, $num) {
        $sqlArr = array();
        $params = array(
            'offset' => $offset,
            'num' => $num
        );
        if ($type == 1 && !empty($keyword)) {
            $sqlArr[] = "id = '$keyword'";
        }
        $sql = '1=1';
        if (!empty($sqlArr)) {
            $sql = implode(' and ', $sqlArr);
        }
        return $this->dao()->cache(false)->fetchAll(Choicegoods\Choicegoods::SELECT_CHOICE_LIST_BY_TYPE, $params, array('sql' => $sql));
    }
     /**
     * 精选商品列表
     * @return type
     */
    function getGoodsList($offset, $num) {
        return $this->dao()->tag($this->_tag)->key('getGoodsList' . $offset . '_' . $num)->fetchAll(Choicegoods\Choicegoods::SELECT_CHOICE_GOODS_LIST, array('offset' => $offset, 'num' => $num));
    }

  

}