Goods.php 943 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. protected $guarded = [];
  14. public function scopeType($query, $type)
  15. {
  16. return $query->whereType($type)->whereStatus(1)->orderByDesc('sort');
  17. }
  18. public function getPriceAttribute($value)
  19. {
  20. return $value / 100;
  21. }
  22. public function setPriceAttribute($value)
  23. {
  24. $this->attributes['price'] = $value * 100;
  25. }
  26. public function getRenewAttribute($value)
  27. {
  28. return $value / 100;
  29. }
  30. public function setRenewAttribute($value)
  31. {
  32. $this->attributes['renew'] = $value * 100;
  33. }
  34. public function getTrafficLabelAttribute()
  35. {
  36. return flowAutoShow($this->attributes['traffic'] * MB);
  37. }
  38. }