|
|
@@ -22,61 +22,26 @@ class Table_reader extends Table
|
|
|
{
|
|
|
$attr = array();
|
|
|
|
|
|
- $attr['id'] = 'reader_id';
|
|
|
- $attr['phone'] = 'reader_phone';
|
|
|
- $attr['wxopenid'] = 'reader_wxopenid';
|
|
|
- $attr['name'] = 'reader_name';
|
|
|
- $attr['sex'] = 'reader_sex';
|
|
|
- $attr['addtime'] = 'reader_addtime';
|
|
|
- $attr['count'] = 'reader_count';
|
|
|
+ $attr['id'] = 'reader_id';
|
|
|
+ $attr['country'] = 'reader_country';
|
|
|
+ $attr['province'] = 'reader_province';
|
|
|
+ $attr['city'] = 'reader_city';
|
|
|
+ $attr['headimgurl'] = 'reader_headimgurl';
|
|
|
+ $attr['openid'] = 'reader_openid';
|
|
|
+ $attr['nickname'] = 'reader_nickname';
|
|
|
+ $attr['sex'] = 'reader_sex';
|
|
|
+ $attr['addtime'] = 'reader_addtime';
|
|
|
+ $attr['count'] = 'reader_count';
|
|
|
|
|
|
return $attr;
|
|
|
}
|
|
|
|
|
|
- public function getInfoById($id)
|
|
|
- {
|
|
|
-
|
|
|
- $id = $this->pdo->sql_check_input(array('number', $id));
|
|
|
-
|
|
|
- $sql = "select * from " . $this->table_fullname . " where reader_id = $id limit 1";
|
|
|
-
|
|
|
- $rs = $this->pdo->sqlQuery($sql);
|
|
|
- $r = array();
|
|
|
- if ($rs) {
|
|
|
- foreach ($rs as $key => $val) {
|
|
|
- $r[$key] = $this->dataToAttr($val);
|
|
|
- }
|
|
|
- return $r[0];
|
|
|
- } else {
|
|
|
- return $r;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public function getInfoByPhone($phone)
|
|
|
- {
|
|
|
-
|
|
|
- $phone = $this->pdo->sql_check_input(array('string', $phone));
|
|
|
-
|
|
|
- $sql = "select * from " . $this->table_fullname . " where reader_phone = $phone limit 1";
|
|
|
-
|
|
|
- $rs = $this->pdo->sqlQuery($sql);
|
|
|
- $r = array();
|
|
|
- if ($rs) {
|
|
|
- foreach ($rs as $key => $val) {
|
|
|
- $r[$key] = $this->dataToAttr($val);
|
|
|
- }
|
|
|
- return $r[0];
|
|
|
- } else {
|
|
|
- return $r;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public function getInfoByOpenId($openId)
|
|
|
{
|
|
|
|
|
|
$openId = $this->pdo->sql_check_input(array('string', $openId));
|
|
|
|
|
|
- $sql = "select * from " . $this->table_fullname . " where reader_wxopenid = $openId limit 1";
|
|
|
+ $sql = "select * from " . $this->table_fullname . " where reader_openid = $openId limit 1";
|
|
|
|
|
|
$rs = $this->pdo->sqlQuery($sql);
|
|
|
$r = array();
|
|
|
@@ -93,21 +58,32 @@ class Table_reader extends Table
|
|
|
public function add($attr)
|
|
|
{
|
|
|
$param = array(
|
|
|
- 'reader_phone' => array('string', $attr['phone']),
|
|
|
- 'reader_wxopenid' => array('string', $attr['wxopenid']),
|
|
|
- 'reader_name' => array('string', $attr['name']),
|
|
|
- 'reader_sex' => array('number', $attr['sex']),
|
|
|
- 'reader_addtime' => array('number', time()),
|
|
|
- 'reader_count' => array('number', 0),
|
|
|
+ 'reader_country' => array('string', $attr['country']),
|
|
|
+ 'reader_province' => array('string', $attr['province']),
|
|
|
+ 'reader_city' => array('string', $attr['city']),
|
|
|
+ 'reader_headimgurl' => array('string', $attr['headimgurl']),
|
|
|
+ 'reader_openid' => array('string', $attr['openid']),
|
|
|
+ 'reader_nickname' => array('string', $attr['nickname']),
|
|
|
+ 'reader_sex' => array('number', $attr['sex']),
|
|
|
+ 'reader_addtime' => array('number', time()),
|
|
|
+ 'reader_count' => array('number', 0),
|
|
|
);
|
|
|
|
|
|
return $this->pdo->sqlinsert($this->table_fullname, $param);
|
|
|
}
|
|
|
|
|
|
- public function edit($id, $attr)
|
|
|
+ public function update($id, $attr)
|
|
|
{
|
|
|
$param = array(
|
|
|
- //
|
|
|
+ 'reader_country' => array('string', $attr['country']),
|
|
|
+ 'reader_province' => array('string', $attr['province']),
|
|
|
+ 'reader_city' => array('string', $attr['city']),
|
|
|
+ 'reader_headimgurl' => array('string', $attr['headimgurl']),
|
|
|
+ 'reader_openid' => array('string', $attr['openid']),
|
|
|
+ 'reader_nickname' => array('string', $attr['nickname']),
|
|
|
+ 'reader_sex' => array('number', $attr['sex']),
|
|
|
+ 'reader_addtime' => array('number', time()),
|
|
|
+ //'reader_count' => array('number', 0),
|
|
|
);
|
|
|
|
|
|
$where = array(
|
|
|
@@ -117,50 +93,18 @@ class Table_reader extends Table
|
|
|
return $this->pdo->sqlupdate($this->table_fullname, $param, $where);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- //获取列表(分页)
|
|
|
- //$count、$page和$pagesize都为0时,返回全部结果(适用于无需分页的情况)
|
|
|
- //
|
|
|
- //@param $filter array -- 过滤条件,格式见Table::filterToWhere
|
|
|
- //@param $count -- 0:返回列表 1:返回结果数量
|
|
|
- //@param $page -- 当前第几页
|
|
|
- //@param $pagesize -- 每页数量
|
|
|
- public function getList($filter = array(), $count = 0, $page = 0, $pagesize = 0)
|
|
|
+ public function addCount($id)
|
|
|
{
|
|
|
+ $param = array(
|
|
|
+ 'reader_addtime' => array('number', time()),
|
|
|
+ 'reader_count' => array('string', 'reader_count+1'),
|
|
|
+ );
|
|
|
|
|
|
- $where = $this->filterToWhere($filter);
|
|
|
-
|
|
|
- if ($count == 0) {//列表
|
|
|
-
|
|
|
- $sql = "select * from " . $this->table_fullname . " $where order by reader_addtime desc, reader_id desc";
|
|
|
-
|
|
|
- if ($page > 0) {//分页
|
|
|
- $startrow = ($page - 1) * $pagesize;
|
|
|
- $sql_limit = " limit $startrow, $pagesize";
|
|
|
- $sql .= $sql_limit;
|
|
|
- }
|
|
|
-
|
|
|
- $rs = $this->pdo->sqlQuery($sql);
|
|
|
- $r = array();
|
|
|
- if ($rs) {
|
|
|
- foreach ($rs as $key => $val) {
|
|
|
- $r[$key] = $this->dataToAttr($val);
|
|
|
- }
|
|
|
- return $r;
|
|
|
- } else {
|
|
|
- return $r;
|
|
|
- }
|
|
|
-
|
|
|
- } else {//统计
|
|
|
+ $where = array(
|
|
|
+ 'reader_id' => array('number', $id)
|
|
|
+ );
|
|
|
|
|
|
- $sql = "select count(*) as c from " . $this->table_fullname . " $where ";
|
|
|
- $rs = $this->pdo->sqlQuery($sql);
|
|
|
- if ($rs) {
|
|
|
- return $rs[0]['c'];
|
|
|
- } else {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- }
|
|
|
+ return $this->pdo->sqlupdate($this->table_fullname, $param, $where);
|
|
|
}
|
|
|
|
|
|
}
|