OrderGoods.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 cores\BaseModel;
  14. use app\common\library\helper;
  15. /**
  16. * 订单商品模型
  17. * Class OrderGoods
  18. * @package app\common\model
  19. */
  20. class OrderGoods extends BaseModel
  21. {
  22. // 定义表名
  23. protected $name = 'order_goods';
  24. // 定义主键
  25. protected $pk = 'order_goods_id';
  26. protected $updateTime = false;
  27. /**
  28. * 订单商品图片
  29. * @return \think\model\relation\BelongsTo
  30. */
  31. public function image()
  32. {
  33. $model = "app\\common\\model\\UploadFile";
  34. return $this->belongsTo($model, 'image_id', 'file_id')
  35. ->bind(['goods_image' => 'preview_url']);
  36. }
  37. /**
  38. * 关联商品表
  39. * @return \think\model\relation\BelongsTo
  40. */
  41. public function goods()
  42. {
  43. return $this->belongsTo('Goods');
  44. }
  45. /**
  46. * 关联订单主表
  47. * @return \think\model\relation\BelongsTo
  48. */
  49. public function orderM()
  50. {
  51. return $this->belongsTo('Order');
  52. }
  53. /**
  54. * 售后单记录表
  55. * @return \think\model\relation\HasOne
  56. */
  57. public function refund()
  58. {
  59. return $this->hasOne('OrderRefund');
  60. }
  61. /**
  62. * 获取器:规格属性
  63. * @param $value
  64. * @return array
  65. */
  66. public function getGoodsPropsAttr($value)
  67. {
  68. return helper::jsonDecode($value);
  69. }
  70. /**
  71. * 设置器:规格属性
  72. * @param $value
  73. * @return string
  74. */
  75. public function setGoodsPropsAttr($value)
  76. {
  77. return $value ? helper::jsonEncode($value) : '';
  78. }
  79. /**
  80. * 订单商品详情
  81. * @param $where
  82. * @return OrderGoods|null
  83. */
  84. public static function detail($where)
  85. {
  86. return static::get($where, ['image', 'refund']);
  87. }
  88. }