db = new Pdo; $this->config = Config::get(); $this->table = new Table; $this->opt = new \stdClass(); $this->opt->sort = "DESC"; $this->opt->logic = "AND"; } public function fetchAll() { $wheresql = array(); if(isset($this->opt->where) && !empty($this->opt->where)) $wheresql = array_merge($wheresql,$this->opt->where); if(count($wheresql)>0) { $wheresql = " WHERE \r\n ".join($wheresql," ".$this->opt->logic." \r\n "); }else{ $wheresql = ''; } if(!empty($this->opt->order)) { $order = $this->opt->order; }else{ $order = "m.id"; } $sql = "SELECT m.* FROM {$this->table->member} m $wheresql ORDER BY $order {$this->opt->sort}"; if(!empty($this->opt->start)) { $sql .= " START {$this->opt->start} "; } if(!empty($this->opt->limit)){ $sql .= " LIMIT {$this->opt->limit} "; } $rs = $this->db->query($sql); return $rs->fetchAll(); } public function fetch($id) { if(is_numeric($id)) { $sql = "SELECT * FROM {$this->table->member} WHERE id=$id"; }else if(\Sookon\Helpers\Uuid::test($id)){ $sql = "SELECT * FROM {$this->table->member} WHERE uuid='$id'"; }else{ return false; } $rs = $this->db->query($sql); return $rs->fetch(); } public function resetPassword($id) { $user = $this->fetch($id); if(empty($user)) { return "参数错误"; } $activetion = uniqid(); $sql = "UPDATE {$this->table->member} SET activation='$activetion' WHERE id=$id"; $state = $this->db->exec($sql); $name = empty($user['realname']) ? $user['username'] : $user['realname']; if($state) { $data = array( 'user' => $name, 'username' => $user['username'], 'url' => view::getHostLink()."/account/fetchpwd/".$user['username']."/".$activetion ); $mail = new Mail(); $mail->loadTemplate("user-password-reset-by-admin",$data); $mail->addTo($user['email'],$name); $mail->send(); return true; }else{ return false; } } }