Goods.php 867 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Http\Models;
  3. use Eloquent;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. /**
  7. * 商品
  8. * Class Goods
  9. *
  10. * @package App\Http\Models
  11. * @mixin Eloquent
  12. */
  13. class Goods extends Model
  14. {
  15. use SoftDeletes;
  16. protected $table = 'goods';
  17. protected $primaryKey = 'id';
  18. protected $dates = ['deleted_at'];
  19. function scopeType($query, $type)
  20. {
  21. return $query->where('type', $type)->where('status', 1)->orderBy('sort', 'desc');
  22. }
  23. function label()
  24. {
  25. return $this->hasMany(GoodsLabel::class, 'goods_id', 'id');
  26. }
  27. function getPriceAttribute($value)
  28. {
  29. return $value/100;
  30. }
  31. function setPriceAttribute($value)
  32. {
  33. $this->attributes['price'] = $value*100;
  34. }
  35. function getTrafficLabelAttribute()
  36. {
  37. $traffic_label = flowAutoShow($this->attributes['traffic']*1048576);
  38. return $traffic_label;
  39. }
  40. }