Goods.php 811 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Http\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. /**
  6. * 商品
  7. * Class Goods
  8. *
  9. * @package App\Http\Models
  10. * @mixin \Eloquent
  11. */
  12. class Goods extends Model
  13. {
  14. use SoftDeletes;
  15. protected $table = 'goods';
  16. protected $primaryKey = 'id';
  17. protected $dates = ['deleted_at'];
  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. function getTrafficLabelAttribute()
  31. {
  32. $traffic_label = flowAutoShow($this->attributes['traffic'] * 1048576);
  33. return $traffic_label;
  34. }
  35. }