OrderGoods.php 1020 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. * @property mixed $origin_price
  10. * @property mixed $price
  11. * @property-read \App\Http\Models\Goods $goods
  12. * @property-read \App\Http\Models\User $user
  13. * @mixin \Eloquent
  14. */
  15. class OrderGoods extends Model
  16. {
  17. protected $table = 'order_goods';
  18. protected $primaryKey = 'id';
  19. function user()
  20. {
  21. return $this->hasOne(User::class, 'id', 'user_id');
  22. }
  23. function goods()
  24. {
  25. return $this->hasOne(Goods::class, 'id', 'goods_id');
  26. }
  27. function getOriginPriceAttribute($value)
  28. {
  29. return $value / 100;
  30. }
  31. function setOriginPriceAttribute($value)
  32. {
  33. return $this->attributes['origin_price'] = $value * 100;
  34. }
  35. function getPriceAttribute($value)
  36. {
  37. return $value / 100;
  38. }
  39. function setPriceAttribute($value)
  40. {
  41. return $this->attributes['price'] = $value * 100;
  42. }
  43. }