OrderGoodsTaocan.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. use app\common\model\Provider;
  15. use think\facade\Db;
  16. /**
  17. * 订单商品模型
  18. * Class OrderGoods
  19. * @package app\common\model
  20. */
  21. class OrderGoodsTaocan extends BaseModel
  22. {
  23. // 定义表名
  24. protected $name = 'order_goods_taocan';
  25. // 定义主键
  26. protected $pk = 'order_goods_taocan_id';
  27. protected $updateTime = false;
  28. /**
  29. * 订单商品图片
  30. * @return \think\model\relation\BelongsTo
  31. */
  32. public function image()
  33. {
  34. $model = "app\\common\\model\\UploadFile";
  35. return $this->belongsTo($model, 'image_id', 'file_id')
  36. ->bind(['goods_image' => 'preview_url']);
  37. }
  38. /**
  39. * 关联商品表
  40. * @return \think\model\relation\BelongsTo
  41. */
  42. public function goods()
  43. {
  44. return $this->belongsTo('Goods');
  45. }
  46. /**
  47. * 获取器:规格属性
  48. * @param $value
  49. * @return array
  50. */
  51. public function getGoodsPropsAttr($value)
  52. {
  53. return helper::jsonDecode($value);
  54. }
  55. /**
  56. * 设置器:规格属性
  57. * @param $value
  58. * @return string
  59. */
  60. public function setGoodsPropsAttr($value)
  61. {
  62. return $value ? helper::jsonEncode($value) : '';
  63. }
  64. /**
  65. * 发货时间
  66. * @param $value
  67. * @return false|string
  68. */
  69. public function getDeliveryTimeAttr($value)
  70. {
  71. return format_time($value);
  72. }
  73. /**
  74. * 收货时间
  75. * @param $value
  76. * @return false|string
  77. */
  78. public function getReceiptTimeAttr($value)
  79. {
  80. return format_time($value);
  81. }
  82. /**
  83. * 订单商品详情
  84. * @param $where
  85. * @return OrderGoods|null
  86. */
  87. public static function detail($where)
  88. {
  89. return static::get($where, ['image']);
  90. }
  91. /**
  92. * 关联订单主表
  93. * @return \think\model\relation\BelongsTo
  94. */
  95. public function orderM()
  96. {
  97. return $this->belongsTo('Order');
  98. }
  99. /**
  100. * 关联门店
  101. * @return \think\model\relation\BelongsTo
  102. */
  103. public function shop()
  104. {
  105. return $this->belongsTo('Shops','shop_id','shop_id');
  106. }
  107. /**
  108. * 关联拆分包裹表
  109. * @return \think\model\relation\hasMany
  110. */
  111. public function package()
  112. {
  113. return $this->hasMany('OrderGoodsPackage');
  114. }
  115. }