Goods.php 692 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Http\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. /**
  5. * 商品
  6. * Class Goods
  7. *
  8. * @package App\Http\Models
  9. */
  10. class Goods extends Model
  11. {
  12. protected $table = 'goods';
  13. protected $primaryKey = 'id';
  14. function label()
  15. {
  16. return $this->hasMany(GoodsLabel::class, 'goods_id', 'id');
  17. }
  18. function getPriceAttribute($value)
  19. {
  20. return $value / 100;
  21. }
  22. function setPriceAttribute($value)
  23. {
  24. $this->attributes['price'] = $value * 100;
  25. }
  26. public function getTrafficLabelAttribute()
  27. {
  28. $traffic_label = flowAutoShow($this->attributes['traffic'] * 1048576);
  29. return $traffic_label;
  30. }
  31. }