Dao.php 4.16 KB
<?php

/**
 * Created by JetBrains PhpStorm.
 * User: liuziyang
 * Date: 12-3-27
 * Time: 下午6:04
 * To change this template use File | Settings | File Templates.
 */
use YHMStore\SqlMap\Store;

class YHMStore_Models_Store_Dao extends YHMStore_Dao {

    private $_tag = 'store_';

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

    /**
     * 通过uid获取店铺id
     * @param integer $uid
     */
    public function getStoreIdByUid($uid) {
        return $this->dao()->tag($this->_tag . $uid)->key('getStoreIdByUid')
                        ->fetchOne(Store\Store::SELECT_STOREID_BY_UID, array('uid' => $uid));
    }

    /**
     * 通过id获取店铺数据
     * @param unknown $id
     */
    public function getById($id) {
        return $this->dao()->cache(false)->fetchRow(Store\Store::SELECT_BY_ID, array('id' => $id));
    }

    /**
     * 通过用户id取出店铺
     * @param int $uid
     * @return type
     */
    public function getByUid($uid) {
        return $this->dao()->tag($this->_tag . $uid)->key('getByUid')->fetchRow(Store\Store::SELECT_BY_UID, array('uid' => $uid));
    }

    /**
     * 添加店铺
     * @param integer $uid
     * @param integer $store_type
     * @param integer $status
     */
    public function addStore($uid, $store_type, $status) {
        $param = array(
            'uid' => $uid,
            'store_type' => $store_type,
            'status' => $status
        );
        return $this->dao()->tag($this->_tag . $uid)->insert(Store\Store::INSERT_STORE, $param)->lastInsertId();
    }

    public function setStoreTypeByUid($uid, $store_type) {
        return $this->dao()->tag($this->_tag . $uid)->key('setStoreTypeByUid')->update(Store\Store::UPDATE_STORE_TYPE_BY_UID, array('uid' => $uid, 'store_type' => $store_type))->status();
    }

    /**
     * 修改用户店铺星级
     * @param int $uid
     * @param int $star
     */
    public function updateStar($uid, $star) {
        return $this->dao()->tag($this->_tag . $uid)->key('setStoreByStar')->update(Store\Store::UPDATE_STORE_STAR_BY_UID, array('uid' => $uid, 'star' => $star))->status();
    }

    /**
     * 根据类型获取店铺总数
     * @param type $store_type
     * @return type
     */
    public function getCountStoreByType($store_type, $type, $keyword) {
        $sqlArr = array();
        $param = array('store_type' => $store_type);
        if ($type == 1 && !empty($keyword)) {
            $sqlArr[] = "uid = '$keyword'";
        }
        if ($type == 2 && !empty($keyword)) {
            $sqlArr[] = "nick_name = '$keyword'";
        }
        $sql = '';
        if (!empty($sqlArr)) {
            $sql = ' and ' . implode(' and ', $sqlArr);
        }
        return $this->dao()->cache(false)->fetchOne(Store\Store::SELECT_COUNT_STORE_BY_TYPE, $param, array('sql' => $sql));
    }

    public function getStoreListByType($store_type, $type, $keyword, $offset, $num) {
        $sqlArr = array();
        $params = array(
            'store_type' => $store_type,
            'offset' => $offset,
            'num' => $num
        );
        if ($type == 1 && !empty($keyword)) {
            $sqlArr[] = "uid = '$keyword'";
        }
        if ($type == 2 && !empty($keyword)) {
            $sqlArr[] = "nick_name = '$keyword' ";
        }
        $sql = '';
        if (!empty($sqlArr)) {
            $sql = ' and ' . implode(' and ', $sqlArr);
        }
        return $this->dao()->cache(false)->fetchAll(Store\Store::SELECT_STORE_LIST_BY_TYPE, $params, array('sql' => $sql));
    }

    /**
     * 修改店铺排序
     * @param type $uid
     * @param type $sort
     * @return type
     */
    public function setStoreSortByUid($uid, $sort) {
        return $this->dao()->tag($this->_tag . $uid)->key('setStoreSortByUid')->update(Store\Store::UPDATE_STORE_SORT_BY_UID, array('uid' => $uid, 'sort' => $sort));
    }

    /**
     * 设置用户为实名制
     * @param type $uid
     * @param type $real
     * @return type
     */
    public function setStoreRealName($uid, $real) {
        return $this->dao()->tag($this->_tag . $uid)->key('setStoreRealName')->update(Store\Store::UPDATE_REAL_BY_UID, array('uid' => $uid, 'is_real' => $real));
    }

}