Goods.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Relations\HasMany;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. /**
  7. * 商品
  8. */
  9. class Goods extends Model
  10. {
  11. use SoftDeletes;
  12. protected $table = 'goods';
  13. protected $dates = ['deleted_at'];
  14. protected $guarded = [];
  15. public function orders(): HasMany
  16. {
  17. return $this->hasMany(Order::class);
  18. }
  19. public function scopeType($query, $type)
  20. {
  21. return $query->whereType($type)->whereStatus(1)->orderByDesc('sort');
  22. }
  23. public function getPriceAttribute($value)
  24. {
  25. return $value / 100;
  26. }
  27. public function setPriceAttribute($value)
  28. {
  29. $this->attributes['price'] = $value * 100;
  30. }
  31. public function getRenewAttribute($value)
  32. {
  33. return $value / 100;
  34. }
  35. public function setRenewAttribute($value)
  36. {
  37. $this->attributes['renew'] = $value * 100;
  38. }
  39. public function getTrafficLabelAttribute()
  40. {
  41. return flowAutoShow($this->attributes['traffic'] * MB);
  42. }
  43. public function getSpeedLimitAttribute($value)
  44. {
  45. return $value / Mbps;
  46. }
  47. public function setSpeedLimitAttribute($value)
  48. {
  49. return $this->attributes['speed_limit'] = $value * Mbps;
  50. }
  51. }