Goods.php 822 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. use SoftDeletes;
  10. protected $table = 'goods';
  11. protected $dates = ['deleted_at'];
  12. public function scopeType($query, $type) {
  13. return $query->whereType($type)->whereStatus(1)->orderByDesc('sort');
  14. }
  15. public function getPriceAttribute($value) {
  16. return $value / 100;
  17. }
  18. public function setPriceAttribute($value): void {
  19. $this->attributes['price'] = $value * 100;
  20. }
  21. public function getRenewAttribute($value) {
  22. return $value / 100;
  23. }
  24. public function setRenewAttribute($value) {
  25. return $this->attributes['renew'] = $value * 100;
  26. }
  27. public function getTrafficLabelAttribute() {
  28. return flowAutoShow($this->attributes['traffic'] * MB);
  29. }
  30. }