链街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. protected $table = 'lanzu_employees';
  11. protected $dateFormat = 'U';
  12. /* 查询记录数 limit */
  13. protected $perPage = 10;
  14. protected $casts = [
  15. 'position'=>'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. public static function getHorseman($marketId=null)
  63. {
  64. if ($marketId){
  65. $rows = self::where('market_id',$marketId)
  66. ->where('position','REGEXP','"29"')
  67. ->where('status',1)
  68. ->get();
  69. }else{
  70. $rows = self::where('position','REGEXP','"29"')->where('status',1)->get();
  71. }
  72. $item = [];
  73. if ($rows){
  74. foreach ($rows as $row) {
  75. $item[$row->id] = $row->name;
  76. }
  77. }
  78. return $item;
  79. }
  80. public static function getName($hid=null)
  81. {
  82. //获取骑手名称
  83. if ($hid){
  84. $horseman = self::find($hid);
  85. if ($horseman){
  86. return $horseman->name;
  87. }
  88. }
  89. return '--';
  90. }
  91. }