$phoneNumber ]; return $this->where($where)->find(); } /** * 通过id获取用户数据 * @param int $id * @return array|bool|Model|null * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getUserById(int $id) { if (!$id) { return false; } return $this->find($id); } /** * 根据username获取用户数据 * @param string $username * @return array|bool|Model|null * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getUserByUsername(string $username) { if (empty($username)) { return false; } $where = [ 'username' => $username ]; return $this->where($where)->find(); } /** * 根据主键id更新数据表中的数据 * @param $id * @param $data * @return bool */ public function updateById($id, $data) { $id = (int)$id; if (empty($id) || empty($data) || !is_array($data)) { return false; } $where = [ 'id' => $id, ]; return $this->where($where)->save($data); } }