OrderGoods.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Http\Models;
  3. use Eloquent;
  4. use Illuminate\Database\Eloquent\Builder;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Support\Carbon;
  7. /**
  8. * 订单商品
  9. * Class OrderGoods
  10. *
  11. * @package App\Http\Models
  12. * @mixin Eloquent
  13. * @property int $id
  14. * @property int $oid 订单ID
  15. * @property string $order_sn 订单编号
  16. * @property int $user_id 用户ID
  17. * @property int $goods_id 商品ID
  18. * @property int $num 商品数量
  19. * @property int $origin_price 商品原价,单位分
  20. * @property int $price 商品实际价格,单位分
  21. * @property int $is_expire 是否已过期:0-未过期、1-已过期
  22. * @property Carbon|null $created_at 创建时间
  23. * @property Carbon|null $updated_at 最后更新时间
  24. * @property-read Goods $goods
  25. * @property-read User $user
  26. * @method static Builder|OrderGoods newModelQuery()
  27. * @method static Builder|OrderGoods newQuery()
  28. * @method static Builder|OrderGoods query()
  29. * @method static Builder|OrderGoods whereCreatedAt($value)
  30. * @method static Builder|OrderGoods whereGoodsId($value)
  31. * @method static Builder|OrderGoods whereId($value)
  32. * @method static Builder|OrderGoods whereIsExpire($value)
  33. * @method static Builder|OrderGoods whereNum($value)
  34. * @method static Builder|OrderGoods whereOid($value)
  35. * @method static Builder|OrderGoods whereOrderSn($value)
  36. * @method static Builder|OrderGoods whereOriginPrice($value)
  37. * @method static Builder|OrderGoods wherePrice($value)
  38. * @method static Builder|OrderGoods whereUpdatedAt($value)
  39. * @method static Builder|OrderGoods whereUserId($value)
  40. */
  41. class OrderGoods extends Model
  42. {
  43. protected $table = 'order_goods';
  44. protected $primaryKey = 'id';
  45. function user()
  46. {
  47. return $this->hasOne(User::class, 'id', 'user_id');
  48. }
  49. function goods()
  50. {
  51. return $this->hasOne(Goods::class, 'id', 'goods_id');
  52. }
  53. function getOriginPriceAttribute($value)
  54. {
  55. return $value/100;
  56. }
  57. function setOriginPriceAttribute($value)
  58. {
  59. return $this->attributes['origin_price'] = $value*100;
  60. }
  61. function getPriceAttribute($value)
  62. {
  63. return $value/100;
  64. }
  65. function setPriceAttribute($value)
  66. {
  67. return $this->attributes['price'] = $value*100;
  68. }
  69. }