findOneByWhere($where, $fields); } /** * 获取指定账户记录By用户名 * * @param string $username * @param array $fields * @return Model|null * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function infoByUsername(string $username, array $fields = []): ?Model { $where[] = ['username', '=', $username]; return $this->findOneByWhere($where, $fields); } /** * 通过微信小程序的openID查询 * * @param string $openID * @return array|Model|null * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function findByOpenID(string $openID) { return $this->model->where('open_id', $openID)->find(); } /** * 修改密码 * * @param int $accountId * @param string $oldPwd * @param string $newPwd * @return bool * @throws RepositoryException */ public function modifyPwd(int $accountId, string $oldPwd, string $newPwd): bool { if (!$user = $this->findById($accountId)) { throw new RepositoryException('用户不存在'); } if ($user['password'] != md5($oldPwd)) { throw new RepositoryException('原密码错误'); } $user->password = md5($newPwd); return $user->save(); } }