AdminUser.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Created by PhpStorm
  4. * User:林志杰
  5. * Email:[email protected]
  6. * Motto:纵有疾风起,人生不言弃!
  7. * Time:2020/1/3 0:29
  8. */
  9. namespace app\common\model\mysql;
  10. use think\Model;
  11. class AdminUser extends Model
  12. {
  13. /**
  14. * 根据用户名获取后端用户表的数据
  15. * @param $username
  16. * @return array|bool|Model|null
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\DbException
  19. * @throws \think\db\exception\ModelNotFoundException
  20. */
  21. public function getAdminUserByUsername($username)
  22. {
  23. if (empty($username)) {
  24. return false;
  25. }
  26. $where = [
  27. 'username' => trim($username),
  28. ];
  29. return $this->where($where)->find();
  30. }
  31. /**
  32. * 根据主键id更新数据表中的数据
  33. * @param $id
  34. * @param $data
  35. * @return bool
  36. */
  37. public function updateById($id, $data)
  38. {
  39. $id = (int)$id;
  40. if (empty($id) || empty($data) || !is_array($data)) {
  41. return false;
  42. }
  43. $where = [
  44. 'id' => $id,
  45. ];
  46. return $this->where($where)->save($data);
  47. }
  48. }