Goods.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 getRenewAttribute($value)
  36. {
  37. return $value/100;
  38. }
  39. function setRenewAttribute($value)
  40. {
  41. return $this->attributes['renew'] = $value*100;
  42. }
  43. function getTrafficLabelAttribute()
  44. {
  45. $traffic_label = flowAutoShow($this->attributes['traffic']*1048576);
  46. return $traffic_label;
  47. }
  48. }