| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace App;
- use App\Traits\ModelLogChanging;
- use App\Traits\ModelTimeFormat;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasOne;
- use Illuminate\Database\Eloquent\SoftDeletes;
- class OwnerSundryFeeDetail extends Model
- {
- use ModelLogChanging;
- use ModelTimeFormat;
- use SoftDeletes;
- protected $fillable = ['type', 'fee_explain', 'remark', 'fee', 'changable','owner_id'];
- static public $enums = [
- 'type' => [
- '' => 0,
- '材料' => 1,
- '垫付' => 2,
- '人工' => 3,
- '其他' => 4,
- ],
- 'changable' => [
- '' => 0,
- '未冻结' => 1,
- '已冻结' => 2,
- ],
- ];
- function __construct(array $attributes = [])
- {
- foreach (self::$enums as &$enum) {
- $enum = $enum + array_flip($enum);
- }
- parent::__construct($attributes);
- }
- public function getTypeAttribute($value)
- {
- if (!$value) return '';
- return self::$enums['type'][$value];
- }
- public function setTypeAttribute($value)
- {
- if (!$value) return 0;
- $this->attributes['type'] = self::$enums['type'][$value];
- }
- public function getRouteKey()
- {
- return 'id';
- }
- public function owner(): BelongsTo
- {
- return $this->belongsTo(Owner::class);
- }
- public function scopeFilter($query, $filters)
- {
- return $filters->apply($query);
- }
- }
|