1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: if ( ! defined( 'ABSPATH' ) ) {
14: exit;
15: }
16:
17: 18: 19:
20: class WxRobot_Table_Reply{
21:
22: 23: 24:
25: public $table_prefix = 'midoks_';
26:
27: 28: 29:
30: public static $_instance = null;
31:
32:
33: 34: 35: 36: 37:
38: public static function instance(){
39: if( is_null (self::$_instance)){
40: self::$_instance = new self();
41: }
42: return self::$_instance;
43: }
44:
45: 46: 47: 48: 49:
50: private function get_table_name(){
51: return $this->table_prefix.'weixin_robot_reply';
52: }
53:
54: 55: 56: 57: 58: 59: 60: 61: 62: 63:
64: public function insert_relpy($keyword, $relpy, $status, $type, $sort=1){
65:
66: global $wpdb;
67: $table_name = $this->get_table_name();
68: $time = date('Y-m-d H:i:s');
69:
70: $sql = " INSERT INTO `{$table_name}` (`id`, `keyword`, `relpy`, `status`, `time`, `type`, `sort`)".
71: " VALUES(null,'{$keyword}','{$relpy}','{$status}', '{$time}', '{$type}', '{$sort}') ";
72:
73: return $wpdb->query($sql);
74: }
75:
76: 77: 78: 79: 80: 81:
82: public function weixin_get_relpy_data($kw=''){
83: global $wpdb;
84: $table_name = $this->get_table_name();
85: if(!empty($kw)){
86: $sql = "select `id`,`keyword`,`relpy`,`status`,`time`,`type`"
87: ." from `{$table_name}` where `status`='1' and `keyword` like '%{$kw}%' order by `id` desc";
88: }else{
89: $sql = "select `id`,`keyword`,`relpy`,`status`,`time`,`type`"
90: ." from `{$table_name}` where `status`='1' order by `id` desc";
91: }
92: $data = $wpdb->get_results($sql);
93: if(empty($data)){
94: return false;
95: }else{
96: $arrs = array();
97: foreach($data as $k=>$v){
98: $arr['id'] = $v->id;
99: $arr['keyword'] = $v->keyword;
100: $arr['relpy'] = $v->relpy;
101: $arr['status'] = $v->status;
102: $arr['time'] = $v->time;
103: $arr['type'] = $v->type;
104: $arrs[] = $arr;
105: }
106: return $arrs;
107: }
108: }
109:
110:
111: 112: 113: 114: 115: 116:
117: public function delete_relpy_id($id){
118: global $wpdb;
119: $table_name = $this->get_table_name();
120: $sql = 'delete from `'.$table_name."` where `id`='{$id}'";
121: return $wpdb->query($sql);
122: }
123:
124: 125: 126: 127: 128: 129: 130:
131: public function change_relpy_status($id, $status){
132: global $wpdb;
133: $table_name = $this->get_table_name();
134: $sql = "UPDATE `{$table_name}` SET `status`='{$status}' WHERE `id`='{$id}'";
135: return $wpdb->query($sql);
136: }
137:
138: 139: 140: 141: 142: 143: 144: 145:
146: public function change_reply($id, $keyword, $relpy, $type){
147: global $wpdb;
148: $table_name = $this->get_table_name();
149: $sql = "UPDATE `{$table_name}` SET `keyword`='{$keyword}',`relpy`='{$relpy}',`type`='{$type}' WHERE `id`='{$id}'";
150: return $wpdb->query($sql);
151: }
152:
153: }
154: ?>
155: