Dao.php 4.32 KB
<?php

/**
 * User: elkan
 * Date: 14-7-29
 * Time: 下午3:49
 * To change this template use File | Settings | File Templates.
 */
use YHMComment\SqlMap\Comment;

class YHMComment_Models_Comment_Dao extends YHMComment_Dao {

    private $_tag = 'comment_';

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

    /**
     * 通过ID获取一条评论
     * @param integer $id
     */
    function getOneById($id) {
        return $this->dao()->cache(false)->fetchRow(Comment\Comment::SELECT_ONE_BY_ID, array('id' => $id));
    }

    /**
     * 获取商品评论总数
     * @param int $product_skc
     * @return int
     */
    function getCountBySkc($store_id, $product_skc) {
        return $this->dao()->tag($this->_tag . $store_id)->key('getCountBySkc_' . $product_skc)
                        ->fetchOne(Comment\Comment::COUNT_LIST_BYSKC, array("product_skc" => $product_skc));
    }

    /**
     * 获取商品评论列表
     * @param integer $store_id
     * @param integer $product_skc
     * @param integer $offset
     * @param integer $num
     * @return Ambigous <multitype:, Mixed, multitype:unknown >
     */
    function getListBySkc($store_id, $product_skc, $offset, $num) {
        return $this->dao()->tag($this->_tag . $store_id)->key('getListBySkc_' . $product_skc . '_' . $offset . '_' . $num)
                        ->fetchAssoc(Comment\Comment::SELECT_COMMENT_BYSKC, array("product_skc" => $product_skc, "offset" => $offset, "num" => $num));
    }

    /**
     * 获取评论内容
     * @param int $id
     * @return string
     */
    function getContentById($store_id, $id) {
        return $this->dao()->tag($this->_tag . $store_id)->key('getContentById_' . $id)
                        ->fetchRow(Comment\Comment::SELECT_COMMENT_CONTENT_BYID, array("id" => $id));
    }

    /**
     * 添加评论
     * @param int $store_id
     * @param int $product_skc
     * @param string $content
     * @param int $star
     * @param int $uid
     * @return int
     */
    function add($uid, $order_code, $store_id, $product_skc, $star) {
        return $this->dao()->tag($this->_tag . $store_id)->insert(Comment\Comment::INSERT_COMMENT, array(
                    "uid" => $uid,
                    "order_code" => $order_code,
                    "store_id" => $store_id,
                    "product_skc" => $product_skc,
                    "star" => $star
                ))->lastInsertId();
    }

    /**
     * 添加评论内容
     * @param int $id
     * @param string $content
     * @return type
     */
    function addContent($store_id, $id, $content) {
        return $this->dao()->tag($this->_tag . $store_id)->insert(Comment\Comment::INSERT_COMMENT_CONTENT, array(
                    "id" => $id,
                    "content" => $content
                ))->status();
    }

    /**
     * 取出店铺评论总数
     * @param int $product_id
     * @return type
     */
    function getCountByStoreId($store_id) {
        return $this->dao()->tag($this->_tag . $store_id)->key('getCountByStoreId')
                        ->fetchOne(Comment\Comment::SELECT_COUNT_BY_STORE_ID, array("store_id" => $store_id));
    }

    /**
     * 取出店铺总得分
     * @param int $store_id
     * @return type
     */
    function getSumStarByStoreId($store_id) {
        return $this->dao()->tag($this->_tag . $store_id)->key('getSumStarByStoreId')
                        ->fetchOne(Comment\Comment::SELECT_SUMSTAR_BY_STORE_ID, array("store_id" => $store_id));
    }

    /**
     * 删除评论信息
     * @param int $id
     * @param int $uid
     * @return type
     */
    function del($store_id, $id) {
        return $this->dao()->tag($this->_tag . $store_id)->delete(Comment\Comment::DELETE_COMMENT_BYID, array("id" => $id))->status();
    }

    /**
     * 删除评论内容
     * @param int $id
     * @return type
     */
    function delContent($store_id, $id) {
        return $this->dao()->tag($this->_tag . $store_id)->delete(Comment\Comment::DELETE_COMMENT_CONTENT_BYID, ARRAY("id" => $id))->status();
    }

    /**
     * 查看该订单是否评价
     * @param type $order_code
     */
    function checkUserCommentByOrderCode($order_code, $uid) {
        return $this->dao()->cache(false)->fetchRow(Comment\Comment::SELECT_COMMENT_BY_ORDER_CODE, array('order_code' => $order_code, 'uid' => $uid));
    }

}