| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?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', 'logistic_number', 'logistic_id', 'amount', 'price',];
- 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 logistic(): BelongsTo
- {
- return $this->belongsTo(Logistic::class);
- }
- public function scopeFilter($query, $filters)
- {
- return $filters->apply($query);
- }
- }
|