Goods.php 953 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 scopeType($query, $type)
  19. {
  20. return $query->where('type', $type)->where('status', 1)->orderBy('sort', 'desc');
  21. }
  22. function label()
  23. {
  24. return $this->hasMany(GoodsLabel::class, 'goods_id', 'id');
  25. }
  26. function getPriceAttribute($value)
  27. {
  28. return $value / 100;
  29. }
  30. function setPriceAttribute($value)
  31. {
  32. $this->attributes['price'] = $value * 100;
  33. }
  34. function getTrafficLabelAttribute()
  35. {
  36. $traffic_label = flowAutoShow($this->attributes['traffic'] * 1048576);
  37. return $traffic_label;
  38. }
  39. }