| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wangming
- * Date: 2019/1/22
- * Time: 20:54
- */
- class Table_reader extends Table
- {
- protected $table_name = 'reader';//表名
- protected $table_id = 'reader_id';//指定ID字段名称,必须
- protected $table_status = '';//指定状态字段名称,如果有
- protected $table_order = '';//指定排序字段名称,如果有
- //数据库结构
- protected function struct()
- {
- $attr = array();
- $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';
- $attr['subscribe'] = 'reader_subscribe';
- $attr['subscribe_time'] = 'reader_subscribe_time';
- return $attr;
- }
- public function getInfoByOpenId($openId)
- {
- $openId = $this->pdo->sql_check_input(array('string', $openId));
- $sql = "select * from " . $this->table_fullname . " where reader_openid = $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_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_subscribe' => array('number', $attr['subscribe']),
- 'reader_subscribe_time' => array('number', $attr['subscribe_time']),
- 'reader_addtime' => array('number', time()),
- 'reader_count' => array('number', 0),
- );
- return $this->pdo->sqlinsert($this->table_fullname, $param);
- }
- 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_subscribe' => array('number', $attr['subscribe']),
- 'reader_subscribe_time' => array('number', $attr['subscribe_time']),
- 'reader_addtime' => array('number', time()),
- //'reader_count' => array('number', 0),
- );
- $where = array(
- 'reader_id' => array('number', $id)
- );
- return $this->pdo->sqlupdate($this->table_fullname, $param, $where);
- }
- public function addCountByOpenId($openId)
- {
- $param = array(
- 'reader_addtime' => array('number', time()),
- 'reader_count' => array('string', 'reader_count+1'),
- );
- $where = array(
- 'reader_openid' => array('string', $openId)
- );
- return $this->pdo->sqlupdate($this->table_fullname, $param, $where);
- }
- }
|