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

71 lines
1.8 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 ServicePersonnel extends Model
  7. {
  8. use HasDateTimeFormatter;
  9. use SoftDeletes;
  10. protected $table = 'lanzu_service_personnel';
  11. protected $dateFormat = 'U';
  12. /* 查询记录数 limit */
  13. protected $perPage = 10;
  14. public static $_TYPE= [1=>'普通专员',2=>'市场经理'];
  15. public static $_STATUS = [-1=>'禁用',0=>'禁用',1=>'启用',2=>'删除'];
  16. protected $appends = [
  17. 'type_text',
  18. 'status_text'
  19. ];
  20. public function getTypeTextAttribute($value)
  21. {
  22. $value = $value ? $value : $this->type;
  23. return isset(self::$_TYPE[$value]) ? self::$_TYPE[$value] : '';
  24. }
  25. public function getStatusTextAttribute($value)
  26. {
  27. $value = $value ? $value : $this->status;
  28. return isset(self::$_STATUS[$value]) ? self::$_STATUS[$value] : '';
  29. }
  30. /**
  31. * 获取单条信息
  32. * @param int $id
  33. * @param string $field
  34. * @return string
  35. */
  36. public static function getInfo($id,$field = '*')
  37. {
  38. return self::select($field)->find($id);
  39. }
  40. /**
  41. * 获取二级分类数组
  42. * id为键,title为值
  43. * @return array
  44. */
  45. public static function getArray($where = [],$options = [])
  46. {
  47. $model = self::where('status',1)
  48. ->whereNull('deleted_at');
  49. if(count($where) > 0){
  50. $model->where($where);
  51. }
  52. $list = $model->pluck('id','name')->toArray();
  53. if(!empty($options)){
  54. $new = array_merge($options,$list);
  55. return array_flip($new);
  56. }else{
  57. return array_flip($list);
  58. }
  59. }
  60. }