Goods.php 929 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. /**
  6. * 商品
  7. */
  8. class Goods extends Model
  9. {
  10. use SoftDeletes;
  11. protected $table = 'goods';
  12. protected $dates = ['deleted_at'];
  13. public function scopeType($query, $type)
  14. {
  15. return $query->whereType($type)->whereStatus(1)->orderByDesc('sort');
  16. }
  17. public function getPriceAttribute($value)
  18. {
  19. return $value / 100;
  20. }
  21. public function setPriceAttribute($value): void
  22. {
  23. $this->attributes['price'] = $value * 100;
  24. }
  25. public function getRenewAttribute($value)
  26. {
  27. return $value / 100;
  28. }
  29. public function setRenewAttribute($value)
  30. {
  31. return $this->attributes['renew'] = $value * 100;
  32. }
  33. public function getTrafficLabelAttribute()
  34. {
  35. return flowAutoShow($this->attributes['traffic'] * MB);
  36. }
  37. }