Dao.php
4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?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));
}
}