OrderRefund.php 2.6 KB

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