OrderGoods.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\common\model;
  13. use app\common\library\helper;
  14. /**
  15. * 订单商品模型
  16. * Class OrderGoods
  17. * @package app\common\model
  18. */
  19. class OrderGoods extends BaseModel
  20. {
  21. // 定义表名
  22. protected $name = 'order_goods';
  23. // 定义主键
  24. protected $pk = 'order_goods_id';
  25. protected $updateTime = false;
  26. /**
  27. * 订单商品图片
  28. * @return \think\model\relation\BelongsTo
  29. */
  30. public function image()
  31. {
  32. $model = "app\\common\\model\\UploadFile";
  33. return $this->belongsTo($model, 'image_id', 'file_id')
  34. ->bind(['goods_image' => 'preview_url']);
  35. }
  36. /**
  37. * 关联商品表
  38. * @return \think\model\relation\BelongsTo
  39. */
  40. public function goods()
  41. {
  42. return $this->belongsTo('Goods');
  43. }
  44. /**
  45. * 关联订单主表
  46. * @return \think\model\relation\BelongsTo
  47. */
  48. public function orderM()
  49. {
  50. return $this->belongsTo('Order');
  51. }
  52. /**
  53. * 售后单记录表
  54. * @return \think\model\relation\HasOne
  55. */
  56. public function refund()
  57. {
  58. return $this->hasOne('OrderRefund');
  59. }
  60. /**
  61. * 获取器:规格属性
  62. * @param $value
  63. * @return array
  64. */
  65. public function getGoodsPropsAttr($value)
  66. {
  67. return helper::jsonDecode($value);
  68. }
  69. /**
  70. * 设置器:规格属性
  71. * @param $value
  72. * @return string
  73. */
  74. public function setGoodsPropsAttr($value)
  75. {
  76. return $value ? helper::jsonEncode($value) : '';
  77. }
  78. /**
  79. * 订单商品详情
  80. * @param $where
  81. * @return OrderGoods|null
  82. */
  83. public static function detail($where)
  84. {
  85. return static::get($where, ['image', 'refund']);
  86. }
  87. }