UserModel.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Model\Arts;
  4. use App\Master\Enum\PassportEnum;
  5. use App\Model\Model;
  6. use Hyperf\Cache\Annotation\Cacheable;
  7. class UserModel extends Model
  8. {
  9. /**
  10. * The table associated with the model.
  11. *
  12. * @var ?string
  13. */
  14. protected ?string $table = 'user';
  15. protected ?string $dateFormat = 'U';
  16. public bool $timestamps = false;
  17. /**
  18. * 默认查询字段
  19. *
  20. * @var array|string[]
  21. */
  22. public array $select = [
  23. '*'
  24. ];
  25. protected int $is_status_search = 1;// 默认使用 status = 1 筛选
  26. protected int $is_delete_search = 0;// 默认使用 is_delete = 0 筛选
  27. /**
  28. * 中间件中获取用户信息
  29. * @param int $user_id
  30. * @return array
  31. */
  32. public function searchUserIdAttribute($query, $value, array $params): mixed
  33. {
  34. if (!isset($value)) {
  35. return $query;
  36. }
  37. return $query->where('user_id', $value);
  38. }
  39. public function authUserInfo(int $user_id)
  40. {
  41. return (new UserModel())->getDetail(params: ['id' => $user_id]);
  42. }
  43. }