table_reader.class.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wangming
  5. * Date: 2019/1/22
  6. * Time: 20:54
  7. */
  8. class Table_reader extends Table
  9. {
  10. protected $table_name = 'reader';//表名
  11. protected $table_id = 'reader_id';//指定ID字段名称,必须
  12. protected $table_status = '';//指定状态字段名称,如果有
  13. protected $table_order = '';//指定排序字段名称,如果有
  14. //数据库结构
  15. protected function struct()
  16. {
  17. $attr = array();
  18. $attr['id'] = 'reader_id';
  19. $attr['country'] = 'reader_country';
  20. $attr['province'] = 'reader_province';
  21. $attr['city'] = 'reader_city';
  22. $attr['headimgurl'] = 'reader_headimgurl';
  23. $attr['openid'] = 'reader_openid';
  24. $attr['nickname'] = 'reader_nickname';
  25. $attr['sex'] = 'reader_sex';
  26. $attr['addtime'] = 'reader_addtime';
  27. $attr['count'] = 'reader_count';
  28. return $attr;
  29. }
  30. public function getInfoByOpenId($openId)
  31. {
  32. $openId = $this->pdo->sql_check_input(array('string', $openId));
  33. $sql = "select * from " . $this->table_fullname . " where reader_openid = $openId limit 1";
  34. $rs = $this->pdo->sqlQuery($sql);
  35. $r = array();
  36. if ($rs) {
  37. foreach ($rs as $key => $val) {
  38. $r[$key] = $this->dataToAttr($val);
  39. }
  40. return $r[0];
  41. } else {
  42. return $r;
  43. }
  44. }
  45. public function add($attr)
  46. {
  47. $param = array(
  48. 'reader_country' => array('string', $attr['country']),
  49. 'reader_province' => array('string', $attr['province']),
  50. 'reader_city' => array('string', $attr['city']),
  51. 'reader_headimgurl' => array('string', $attr['headimgurl']),
  52. 'reader_openid' => array('string', $attr['openid']),
  53. 'reader_nickname' => array('string', $attr['nickname']),
  54. 'reader_sex' => array('number', $attr['sex']),
  55. 'reader_addtime' => array('number', time()),
  56. 'reader_count' => array('number', 0),
  57. );
  58. return $this->pdo->sqlinsert($this->table_fullname, $param);
  59. }
  60. public function update($id, $attr)
  61. {
  62. $param = array(
  63. 'reader_country' => array('string', $attr['country']),
  64. 'reader_province' => array('string', $attr['province']),
  65. 'reader_city' => array('string', $attr['city']),
  66. 'reader_headimgurl' => array('string', $attr['headimgurl']),
  67. 'reader_openid' => array('string', $attr['openid']),
  68. 'reader_nickname' => array('string', $attr['nickname']),
  69. 'reader_sex' => array('number', $attr['sex']),
  70. 'reader_addtime' => array('number', time()),
  71. //'reader_count' => array('number', 0),
  72. );
  73. $where = array(
  74. 'reader_id' => array('number', $id)
  75. );
  76. return $this->pdo->sqlupdate($this->table_fullname, $param, $where);
  77. }
  78. public function addCountByOpenId($openId)
  79. {
  80. $param = array(
  81. 'reader_addtime' => array('number', time()),
  82. 'reader_count' => array('string', 'reader_count+1'),
  83. );
  84. $where = array(
  85. 'reader_openid' => array('string', $openId)
  86. );
  87. return $this->pdo->sqlupdate($this->table_fullname, $param, $where);
  88. }
  89. }