username = $params["username"]; $this->password = $params["password"]; $this->nickname = $params["nickname"]; $this->icon = $params["icon"]; $this->tel = $params["tel"]; $this->email = $params["email"]; $this->status = "normal"; if ($this->username == "" || $this->password == "") { return "empty username or password"; } // todo 这里需要对密码加密 $this->save(); return "success"; } public function ModifyUser(array $params) { } public function DeleteUser($uid) { } public function ListUser($page, $pageCount) { } } class UserRole extends Model { protected $table = "user_roles"; public $timestamps = false; public function AssignRoles($uid, array $roles) { $checkData = $this->select("id") ->where("user_id", $uid) ->where("is_del", false) ->first; $r = 0; foreach ($roles as $role) { $r = $r & $role; } if (!$checkData) { // 插入新数据 $this->user_id = $uid; $this->roles = $r; $this->save(); } else { // 更新旧角色 $this->roles = $r; $this->save(); } return"success"; } public function LoadRoleByUid($uid) { $role = $this->select("user_id", "role_id", "status") ->where("user_id", $uid) ->where("is_del", false) ->first(); return $role; } }