OrderGoods.php 847 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Http\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. /**
  5. * 订单商品
  6. * Class OrderGoods
  7. *
  8. * @package App\Http\Models
  9. */
  10. class OrderGoods extends Model
  11. {
  12. protected $table = 'order_goods';
  13. protected $primaryKey = 'id';
  14. function user()
  15. {
  16. return $this->hasOne(User::class, 'id', 'user_id');
  17. }
  18. function goods()
  19. {
  20. return $this->hasOne(Goods::class, 'id', 'goods_id');
  21. }
  22. function getOriginPriceAttribute($value)
  23. {
  24. return $value / 100;
  25. }
  26. function setOriginPriceAttribute($value)
  27. {
  28. return $this->attributes['origin_price'] = $value * 100;
  29. }
  30. function getPriceAttribute($value)
  31. {
  32. return $value / 100;
  33. }
  34. function setPriceAttribute($value)
  35. {
  36. return $this->attributes['price'] = $value * 100;
  37. }
  38. }