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

102 lines
2.5 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. const TABLE_NAME = 'lanzu_employees';
  11. protected $table = 'lanzu_employees';
  12. protected $dateFormat = 'U';
  13. /* 查询记录数 limit */
  14. protected $perPage = 10;
  15. protected $casts = [
  16. 'position'=>'array',
  17. ];
  18. public static $_TYPE= [''];
  19. public static $_STATUS = [-1=>'离职',0=>'禁用',1=>'正常'];
  20. protected $appends = [
  21. 'type_text',
  22. 'status_text'
  23. ];
  24. public function getTypeTextAttribute($value)
  25. {
  26. $value = $value ? $value : $this->type;
  27. return isset(self::$_TYPE[$value]) ? self::$_TYPE[$value] : '';
  28. }
  29. public function getStatusTextAttribute($value)
  30. {
  31. $value = $value ? $value : $this->status;
  32. return isset(self::$_STATUS[$value]) ? self::$_STATUS[$value] : '';
  33. }
  34. /**
  35. * 根据id获取单条信息
  36. * @param int $id
  37. * @param string $field
  38. * @return string
  39. */
  40. public static function getInfo($id,$field = '*')
  41. {
  42. return self::select($field)->find($id);
  43. }
  44. /**
  45. * 获取数组
  46. * id为键
  47. * @return array
  48. */
  49. public static function getArray($where = [], $options = [])
  50. {
  51. $model = self::whereNull('deleted_at');
  52. if(!empty($where)){
  53. $model->where($where);
  54. }
  55. $list = $model->pluck('id','user_id')->toArray();
  56. if(!empty($options)){
  57. $new = array_merge($options,$list);
  58. return array_flip($new);
  59. }else{
  60. return array_flip($list);
  61. }
  62. }
  63. public static function getHorseman($marketId=null)
  64. {
  65. if ($marketId){
  66. $rows = self::where('market_id',$marketId)
  67. ->where('position','REGEXP','"29"')
  68. ->where('status',1)
  69. ->get();
  70. }else{
  71. $rows = self::where('position','REGEXP','"29"')->where('status',1)->get();
  72. }
  73. $item = [];
  74. if ($rows){
  75. foreach ($rows as $row) {
  76. $item[$row->id] = $row->name;
  77. }
  78. }
  79. return $item;
  80. }
  81. public static function getName($hid=null)
  82. {
  83. //获取骑手名称
  84. if ($hid){
  85. $horseman = self::find($hid);
  86. if ($horseman){
  87. return $horseman->name;
  88. }
  89. }
  90. return '--';
  91. }
  92. }