RefundApply.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace app\backend\modules\refund\models;
  3. use Illuminate\Http\Request;
  4. use app\backend\modules\order\models\Order;
  5. use app\backend\modules\refund\models\type\RefundMoney;
  6. use app\backend\modules\refund\models\type\ExchangeGoods;
  7. use app\backend\modules\refund\models\type\ReturnGoods;
  8. use app\common\exceptions\AdminException;
  9. /**
  10. * Class RefundApply
  11. * @package app\backend\modules\refund\models
  12. * @property Order order
  13. */
  14. class RefundApply extends \app\common\models\refund\RefundApply
  15. {
  16. static protected $needLog = true;
  17. protected $typeInstance;
  18. protected $request;
  19. //确认退款
  20. public function refundMoney()
  21. {
  22. return $this->getTypeInstance()->refundMoney();
  23. }
  24. //驳回
  25. public function reject()
  26. {
  27. return $this->getTypeInstance()->reject();
  28. }
  29. //同意申请
  30. public function pass()
  31. {
  32. return $this->getTypeInstance()->pass();
  33. }
  34. //手动退款
  35. public function consensus()
  36. {
  37. return $this->getTypeInstance()->consensus();
  38. }
  39. //没用
  40. public function receiveReturnGoods()
  41. {
  42. //todo 补充当退款类型实例请求 收货请求时的提示
  43. return $this->getTypeInstance()->receiveReturnGoods();
  44. }
  45. //换货完成
  46. public function close()
  47. {
  48. return $this->getTypeInstance()->close();
  49. }
  50. //商家发货
  51. public function resend()
  52. {
  53. return $this->getTypeInstance()->resend();
  54. }
  55. /**
  56. * @return ExchangeGoods|RefundMoney|ReturnGoods
  57. * @throws AdminException
  58. */
  59. protected function getTypeInstance()
  60. {
  61. if (!isset($this->typeInstance)) {
  62. switch ($this->refund_type) {
  63. case self::REFUND_TYPE_REFUND_MONEY:
  64. $this->typeInstance = new RefundMoney($this);
  65. break;
  66. case self::REFUND_TYPE_RETURN_GOODS:
  67. $this->typeInstance = new ReturnGoods($this);
  68. break;
  69. case self::REFUND_TYPE_EXCHANGE_GOODS:
  70. $this->typeInstance = new ExchangeGoods($this);
  71. break;
  72. default:
  73. throw new AdminException('退款类型不存在');
  74. break;
  75. }
  76. }
  77. return $this->typeInstance;
  78. }
  79. /**
  80. * @param $request
  81. */
  82. public function setRequest($request)
  83. {
  84. if ($request instanceof Request) {
  85. $this->request = $request;
  86. }
  87. if (is_array($request)) {
  88. $this->request = request()->merge($request);
  89. }
  90. }
  91. public function getRequest()
  92. {
  93. if (!isset($this->request)) {
  94. $this->request = request();
  95. }
  96. return $this->request;
  97. }
  98. }