123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace App\Http\Models;
- use Eloquent;
- use Illuminate\Database\Eloquent\Collection;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\SoftDeletes;
- use Illuminate\Database\Query\Builder;
- use Illuminate\Support\Carbon;
- class Goods extends Model
- {
- use SoftDeletes;
- protected $table = 'goods';
- protected $primaryKey = 'id';
- protected $dates = ['deleted_at'];
- function scopeType($query, $type)
- {
- return $query->whereType($type)->whereStatus(1)->orderBy('sort', 'desc');
- }
- function label()
- {
- return $this->hasMany(GoodsLabel::class, 'goods_id', 'id');
- }
- function getPriceAttribute($value)
- {
- return $value/100;
- }
- function setPriceAttribute($value)
- {
- $this->attributes['price'] = $value*100;
- }
- function getRenewAttribute($value)
- {
- return $value/100;
- }
- function setRenewAttribute($value)
- {
- return $this->attributes['renew'] = $value*100;
- }
- function getTrafficLabelAttribute()
- {
- return flowAutoShow($this->attributes['traffic']*1048576);
- }
- }
|