ChannelUserDao.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Dao\Channel;
  3. use App\Models\Channel\ChannelUser;
  4. class ChannelUserDao
  5. {
  6. /**
  7. * @param $account
  8. * @param $password
  9. * @return array
  10. */
  11. public function getUserByAccountAndPassword($account, $password): array
  12. {
  13. if (strlen($account) < 1 || strlen($password) < 1) {
  14. return [];
  15. }
  16. $result = ChannelUser::where(compact('account', 'password'))->first();
  17. return $result ? $result->toArray() : [];
  18. }
  19. /**
  20. * @param $account
  21. * @return array
  22. */
  23. public function getUserByAccount($account): array
  24. {
  25. if (strlen($account) < 1) {
  26. return [];
  27. }
  28. $result = ChannelUser::where('account', $account)->first();
  29. return $result ? $result->toArray() : [];
  30. }
  31. /**
  32. * @param $token
  33. * @return array
  34. */
  35. public function getUserByToken($token): array
  36. {
  37. if (strlen($token) < 1) {
  38. return [];
  39. }
  40. $result = ChannelUser::where(compact('token'))->first();
  41. return $result ? $result->toArray() : [];
  42. }
  43. /**
  44. * @param $uid
  45. * @return array
  46. */
  47. public function getUserByUid($uid): array
  48. {
  49. if (empty($uid)) {
  50. return [];
  51. }
  52. $result = ChannelUser::where('id', $uid)->first();
  53. return $result ? $result->toArray() : [];
  54. }
  55. /**
  56. * @param $where
  57. * @param $data
  58. * @return bool
  59. */
  60. public function updateUserData($where, $data): bool
  61. {
  62. if (empty($where) || empty($data)) {
  63. return false;
  64. }
  65. return ChannelUser::where($where)->update($data);
  66. }
  67. /**
  68. * @param $account
  69. * @param $password
  70. * @return bool
  71. */
  72. public function createUser($account, $password): bool
  73. {
  74. if (strlen($account) < 1 || strlen($password) < 1) {
  75. return false;
  76. }
  77. // 创建
  78. $user = new ChannelUser();
  79. $user->nickname = $account;
  80. $user->account = $account;
  81. $user->phone = '';
  82. $user->password = $password;
  83. $user->is_enabled = 1;
  84. $user->save();
  85. return (bool)$user->id;
  86. }
  87. }