'普通专员',2=>'市场经理']; public static $_STATUS = [-1=>'禁用',0=>'禁用',1=>'启用',2=>'删除']; protected $appends = [ 'type_text', 'status_text' ]; public function getTypeTextAttribute($value) { $value = $value ? $value : $this->type; return isset(self::$_TYPE[$value]) ? self::$_TYPE[$value] : ''; } public function getStatusTextAttribute($value) { $value = $value ? $value : $this->status; return isset(self::$_STATUS[$value]) ? self::$_STATUS[$value] : ''; } /** * 获取单条信息 * @param int $id * @param string $field * @return string */ public static function getInfo($id,$field = '*') { return self::select($field)->find($id); } /** * 获取二级分类数组 * id为键,title为值 * @return array */ public static function getArray($where = [],$options = []) { $model = self::where('status',1) ->whereNull('deleted_at'); if(count($where) > 0){ $model->where($where); } $list = $model->pluck('id','name')->toArray(); if(!empty($options)){ $new = array_merge($options,$list); return array_flip($new); }else{ return array_flip($list); } } }