OrderRefund.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\common\model\sharing;
  10. use app\common\model\BaseModel;
  11. /**
  12. * 售后单模型
  13. * Class OrderRefund
  14. * @package app\common\model\sharing
  15. */
  16. class OrderRefund extends BaseModel
  17. {
  18. protected $name = 'sharing_order_refund';
  19. /**
  20. * 关联用户表
  21. * @return \think\model\relation\BelongsTo
  22. */
  23. public function user()
  24. {
  25. $module = self::getCalledModule() ?: 'common';
  26. return $this->belongsTo("app\\{$module}\\model\\User");
  27. }
  28. /**
  29. * 关联订单主表
  30. * @return \think\model\relation\BelongsTo
  31. */
  32. public function orderMaster()
  33. {
  34. return $this->belongsTo('Order');
  35. }
  36. /**
  37. * 关联订单商品表
  38. * @return \think\model\relation\BelongsTo
  39. */
  40. public function orderGoods()
  41. {
  42. return $this->belongsTo('OrderGoods');
  43. }
  44. /**
  45. * 关联图片记录表
  46. * @return \think\model\relation\HasMany
  47. */
  48. public function image()
  49. {
  50. return $this->hasMany('OrderRefundImage', 'order_refund_id');
  51. }
  52. /**
  53. * 关联物流公司表
  54. * @return \think\model\relation\BelongsTo
  55. */
  56. public function express()
  57. {
  58. $module = self::getCalledModule() ?: 'common';
  59. return $this->belongsTo("app\\{$module}\\model\\Express");
  60. }
  61. /**
  62. * 关联用户表
  63. * @return \think\model\relation\HasOne
  64. */
  65. public function address()
  66. {
  67. return $this->hasOne('OrderRefundAddress', 'order_refund_id');
  68. }
  69. /**
  70. * 售后类型
  71. * @param $value
  72. * @return array
  73. */
  74. public function getTypeAttr($value)
  75. {
  76. $status = [10 => '退货退款', 20 => '换货'];
  77. return ['text' => $status[$value], 'value' => $value];
  78. }
  79. /**
  80. * 商家是否同意售后
  81. * @param $value
  82. * @return array
  83. */
  84. public function getIsAgreeAttr($value)
  85. {
  86. $status = [0 => '待审核', 10 => '已同意', 20 => '已拒绝'];
  87. return ['text' => $status[$value], 'value' => $value];
  88. }
  89. /**
  90. * 售后单状态
  91. * @param $value
  92. * @return array
  93. */
  94. public function getStatusAttr($value)
  95. {
  96. $status = [0 => '进行中', 10 => '已拒绝', 20 => '已完成', 30 => '已取消'];
  97. return ['text' => $status[$value], 'value' => $value];
  98. }
  99. /**
  100. * 售后单详情
  101. * @param $where
  102. * @return static|null
  103. * @throws \think\exception\DbException
  104. */
  105. public static function detail($where)
  106. {
  107. return static::get($where, ['image.file', 'order_goods.image', 'express', 'address']);
  108. }
  109. }