链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4 KiB

  1. <?php
  2. namespace App\Models\v3;
  3. use Illuminate\Database\Eloquent\Model;
  4. class User extends Model
  5. {
  6. protected $table = 'lanzu_user';
  7. protected $dateFormat = 'U';
  8. public static $_GENDER = ['保密','男','女'];
  9. public static $_STATUS = [0=>'禁用',1=>'正常'];
  10. protected $appends = [
  11. 'gender_text',
  12. 'status_text'
  13. ];
  14. public function getGenderTextAttribute($value)
  15. {
  16. $value = $value ? $value : $this->gender;
  17. return isset(self::$_GENDER[$value]) ? self::$_GENDER[$value] : '';
  18. }
  19. public function getStatusTextAttribute($value)
  20. {
  21. $value = $value ? $value : $this->status;
  22. return isset(self::$_STATUS[$value]) ? self::$_STATUS[$value] : '';
  23. }
  24. /**
  25. * 获取单个用户信息
  26. * @param int $id
  27. * @param string $field
  28. * @return object
  29. */
  30. public static function getUserInfo($id,$field = '*')
  31. {
  32. return self::select($field)->find($id);
  33. }
  34. /**
  35. * 获取用户数组
  36. * id为键,name为值
  37. * @return array
  38. */
  39. public static function getUserArray()
  40. {
  41. $list = self::select('id','nick_name')
  42. ->where('status',1)
  43. ->whereNull('deleted_at')
  44. ->get();
  45. $array = [];
  46. if(count($list) > 0){
  47. foreach ($list as $value) {
  48. $array[$value->id] = $value->nick_name;
  49. }
  50. }
  51. return $array;
  52. }
  53. }