Goods.php 873 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. * @property mixed $price
  10. * @property-read mixed $traffic_label
  11. * @property-read \Illuminate\Database\Eloquent\Collection|\App\Http\Models\GoodsLabel[] $label
  12. * @mixin \Eloquent
  13. */
  14. class Goods extends Model
  15. {
  16. protected $table = 'goods';
  17. protected $primaryKey = 'id';
  18. function label()
  19. {
  20. return $this->hasMany(GoodsLabel::class, 'goods_id', 'id');
  21. }
  22. function getPriceAttribute($value)
  23. {
  24. return $value / 100;
  25. }
  26. function setPriceAttribute($value)
  27. {
  28. $this->attributes['price'] = $value * 100;
  29. }
  30. public function getTrafficLabelAttribute()
  31. {
  32. $traffic_label = flowAutoShow($this->attributes['traffic'] * 1048576);
  33. return $traffic_label;
  34. }
  35. }