table_reader.class.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. $attr['subscribe'] = 'reader_subscribe';
  29. $attr['subscribe_time'] = 'reader_subscribe_time';
  30. return $attr;
  31. }
  32. public function getInfoByOpenId($openId)
  33. {
  34. $openId = $this->pdo->sql_check_input(array('string', $openId));
  35. $sql = "select * from " . $this->table_fullname . " where reader_openid = $openId limit 1";
  36. $rs = $this->pdo->sqlQuery($sql);
  37. $r = array();
  38. if ($rs) {
  39. foreach ($rs as $key => $val) {
  40. $r[$key] = $this->dataToAttr($val);
  41. }
  42. return $r[0];
  43. } else {
  44. return $r;
  45. }
  46. }
  47. public function add($attr)
  48. {
  49. $param = array(
  50. 'reader_country' => array('string', $attr['country']),
  51. 'reader_province' => array('string', $attr['province']),
  52. 'reader_city' => array('string', $attr['city']),
  53. 'reader_headimgurl' => array('string', $attr['headimgurl']),
  54. 'reader_openid' => array('string', $attr['openid']),
  55. 'reader_nickname' => array('string', $attr['nickname']),
  56. 'reader_sex' => array('number', $attr['sex']),
  57. 'reader_subscribe' => array('number', $attr['subscribe']),
  58. 'reader_subscribe_time' => array('number', $attr['subscribe_time']),
  59. 'reader_addtime' => array('number', time()),
  60. 'reader_count' => array('number', 0),
  61. );
  62. return $this->pdo->sqlinsert($this->table_fullname, $param);
  63. }
  64. public function update($id, $attr)
  65. {
  66. $param = array(
  67. 'reader_country' => array('string', $attr['country']),
  68. 'reader_province' => array('string', $attr['province']),
  69. 'reader_city' => array('string', $attr['city']),
  70. 'reader_headimgurl' => array('string', $attr['headimgurl']),
  71. 'reader_openid' => array('string', $attr['openid']),
  72. 'reader_nickname' => array('string', $attr['nickname']),
  73. 'reader_sex' => array('number', $attr['sex']),
  74. 'reader_subscribe' => array('number', $attr['subscribe']),
  75. 'reader_subscribe_time' => array('number', $attr['subscribe_time']),
  76. 'reader_addtime' => array('number', time()),
  77. //'reader_count' => array('number', 0),
  78. );
  79. $where = array(
  80. 'reader_id' => array('number', $id)
  81. );
  82. return $this->pdo->sqlupdate($this->table_fullname, $param, $where);
  83. }
  84. public function addCountByOpenId($openId)
  85. {
  86. $param = array(
  87. 'reader_addtime' => array('number', time()),
  88. 'reader_count' => array('string', 'reader_count+1'),
  89. );
  90. $where = array(
  91. 'reader_openid' => array('string', $openId)
  92. );
  93. return $this->pdo->sqlupdate($this->table_fullname, $param, $where);
  94. }
  95. }