链街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.

72 lines
1.7 KiB

  1. <?php
  2. namespace App\Models\v3;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. use Illuminate\Database\Eloquent\Model;
  6. class LanzuEmployees extends Model
  7. {
  8. use HasDateTimeFormatter;
  9. use SoftDeletes;
  10. protected $table = 'lanzu_employees';
  11. protected $dateFormat = 'U';
  12. /* 查询记录数 limit */
  13. protected $perPage = 10;
  14. protected $casts = [
  15. 'role'=>'array',
  16. ];
  17. public static $_TYPE= [''];
  18. public static $_STATUS = [-1=>'离职',0=>'禁用',1=>'正常'];
  19. protected $appends = [
  20. 'type_text',
  21. 'status_text'
  22. ];
  23. public function getTypeTextAttribute($value)
  24. {
  25. $value = $value ? $value : $this->type;
  26. return isset(self::$_TYPE[$value]) ? self::$_TYPE[$value] : '';
  27. }
  28. public function getStatusTextAttribute($value)
  29. {
  30. $value = $value ? $value : $this->status;
  31. return isset(self::$_STATUS[$value]) ? self::$_STATUS[$value] : '';
  32. }
  33. /**
  34. * 根据id获取单条信息
  35. * @param int $id
  36. * @param string $field
  37. * @return string
  38. */
  39. public static function getInfo($id,$field = '*')
  40. {
  41. return self::select($field)->find($id);
  42. }
  43. /**
  44. * 获取数组
  45. * id为键
  46. * @return array
  47. */
  48. public static function getArray($where = [], $options = [])
  49. {
  50. $model = self::whereNull('deleted_at');
  51. if(!empty($where)){
  52. $model->where($where);
  53. }
  54. $list = $model->pluck('id','user_id')->toArray();
  55. if(!empty($options)){
  56. $new = array_merge($options,$list);
  57. return array_flip($new);
  58. }else{
  59. return array_flip($list);
  60. }
  61. }
  62. }