BackendRefundButtonService.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/12/10
  6. * Time: 16:22
  7. */
  8. namespace app\backend\modules\refund\services;
  9. use app\backend\modules\refund\services\button\RefundButtonBase;
  10. use app\common\models\refund\RefundApply;
  11. class BackendRefundButtonService
  12. {
  13. protected $refund;
  14. public function __construct(RefundApply $refund)
  15. {
  16. $this->refund = $refund;
  17. }
  18. public function getButtonModels()
  19. {
  20. $operationsSettings = $this->getGroupBy();
  21. $operations = array_map(function ($operationName) {
  22. /**
  23. * @var RefundButtonBase $operation
  24. */
  25. $operation = new $operationName($this->refund);
  26. if (!$operation->enable()) {
  27. return null;
  28. }
  29. $result['name'] = $operation->getName();
  30. $result['value'] = $operation->getValue();
  31. $result['api'] = $operation->getApi();
  32. $result['type'] = $operation->getType();
  33. $result['desc'] = $operation->getDesc();
  34. return $result;
  35. }, $operationsSettings);
  36. $operations = array_filter($operations);
  37. // dd($operations);
  38. return array_values($operations) ?: [];
  39. }
  40. //根据退款申请类型返回按钮
  41. protected function getGroupBy()
  42. {
  43. return $this->buttonGroupBy()[$this->refund->refund_type];
  44. }
  45. protected function buttonGroupBy()
  46. {
  47. return [
  48. RefundApply::REFUND_TYPE_REFUND_MONEY => [
  49. \app\backend\modules\refund\services\button\Reject::class,
  50. \app\backend\modules\refund\services\button\Pay::class,
  51. \app\backend\modules\refund\services\button\Consensus::class,
  52. ],
  53. RefundApply::REFUND_TYPE_RETURN_GOODS => [
  54. \app\backend\modules\refund\services\button\Reject::class,
  55. \app\backend\modules\refund\services\button\Pass::class,
  56. \app\backend\modules\refund\services\button\Pay::class,
  57. \app\backend\modules\refund\services\button\Consensus::class,
  58. ],
  59. RefundApply::REFUND_TYPE_EXCHANGE_GOODS => [
  60. \app\backend\modules\refund\services\button\Reject::class,
  61. \app\backend\modules\refund\services\button\Pass::class,
  62. \app\backend\modules\refund\services\button\BatchResend::class,
  63. \app\backend\modules\refund\services\button\Resend::class,
  64. \app\backend\modules\refund\services\button\Close::class,
  65. ],
  66. ];
  67. }
  68. protected function getAllOperationButton()
  69. {
  70. $button = collect([
  71. [
  72. 'name' => '同意退款',
  73. 'value' => 1,
  74. 'api' => 'refund.pay',
  75. 'type' => '',
  76. ],
  77. [
  78. 'name' => '手动退款',
  79. 'value' => 2,
  80. 'api' => 'refund.operation.consensus',
  81. 'type' => '',
  82. ],
  83. [
  84. 'name' => '通过申请(需客户寄回商品)',
  85. 'value' => 3,
  86. 'api' => 'refund.operation.pass',
  87. 'type' => '',
  88. ],
  89. [
  90. 'name' => '确认发货',
  91. 'value' => 5,
  92. 'api' => 'refund.operation.resend',
  93. 'type' => '',
  94. ],
  95. [
  96. 'name' => '关闭申请(换货完成)',
  97. 'value' => 10,
  98. 'api' => 'refund.operation.close',
  99. 'type' => '',
  100. ],
  101. [
  102. 'name' => '驳回申请',
  103. 'value' => -1,
  104. 'api' => 'refund.operation.reject',
  105. 'type' => '',
  106. ],
  107. ]);
  108. return $button;
  109. }
  110. }