| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wangming
- * Date: 2019/1/22
- * Time: 20:54
- */
- class Table_reader extends Table
- {
- protected $table_name = 'fission';//表名
- protected $table_id = 'fission_id';//指定ID字段名称,必须
- protected $table_status = '';//指定状态字段名称,如果有
- protected $table_order = '';//指定排序字段名称,如果有
- //数据库结构
- protected function struct()
- {
- $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';
- 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";
- $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 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),
- );
- return $this->pdo->sqlinsert($this->table_fullname, $param);
- }
- public function edit($id, $attr)
- {
- $param = array(
- //
- );
- $where = array(
- 'reader_id' => array('number', $id)
- );
- 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)
- {
- $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 {//统计
- $sql = "select count(*) as c from " . $this->table_fullname . " $where ";
- $rs = $this->pdo->sqlQuery($sql);
- if ($rs) {
- return $rs[0]['c'];
- } else {
- return 0;
- }
- }
- }
- }
|