RefundStatusStepManager.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/12/14
  6. * Time: 16:59
  7. */
  8. namespace app\backend\modules\refund\services\steps;
  9. use app\common\models\refund\RefundApply;
  10. use app\common\services\steps\interfaces\ElementSteps;
  11. class RefundStatusStepManager
  12. {
  13. public $refund;
  14. protected $items;
  15. public function __construct($refundApply)
  16. {
  17. $this->refund = $refundApply;
  18. }
  19. /**
  20. * 获取当前订单配置
  21. * @return array|mixed
  22. */
  23. public function getRefundStepSetting()
  24. {
  25. // $configs = \app\common\modules\shop\ShopConfig::current()->get('');
  26. $configs = $this->getGroupBy();
  27. return $configs;
  28. }
  29. //根据退款申请类型返回按钮
  30. protected function getGroupBy()
  31. {
  32. return $this->buttonGroupBy()[$this->refund->refund_type];
  33. }
  34. protected function buttonGroupBy()
  35. {
  36. return [
  37. RefundApply::REFUND_TYPE_REFUND_MONEY => [
  38. \app\backend\modules\refund\services\steps\Create::class,
  39. \app\backend\modules\refund\services\steps\Agree::class,
  40. ],
  41. RefundApply::REFUND_TYPE_RETURN_GOODS => [
  42. \app\backend\modules\refund\services\steps\Create::class,
  43. \app\backend\modules\refund\services\steps\Agree::class,
  44. \app\backend\modules\refund\services\steps\UserReturn::class,
  45. ],
  46. RefundApply::REFUND_TYPE_EXCHANGE_GOODS => [
  47. \app\backend\modules\refund\services\steps\Create::class,
  48. \app\backend\modules\refund\services\steps\Agree::class,
  49. \app\backend\modules\refund\services\steps\UserReturn::class,
  50. \app\backend\modules\refund\services\steps\Resend::class,
  51. ],
  52. ];
  53. }
  54. public function getStepItems()
  55. {
  56. $stepItems = $this->_stepItems()->sortBy(function (ElementSteps $step) {
  57. return $step->sort();
  58. })->map(function (ElementSteps $step) {
  59. return [
  60. 'title' => $step->getTitle(),
  61. 'desc' => $step->getDescription(),
  62. 'status' => $step->getStatus(),
  63. 'icon' => $step->getIcon(),
  64. 'value' => $step->getValue(),
  65. ];
  66. })->values()->toArray();
  67. return $stepItems;
  68. }
  69. /**
  70. * @return mixed
  71. */
  72. public function _stepItems()
  73. {
  74. if (isset($this->items)) {
  75. return $this->items;
  76. }
  77. $this->items = collect($this->getRefundStepSetting())->map(function ($step) {
  78. if (class_exists($step)) {
  79. return new $step($this->refund);
  80. }
  81. return null;
  82. })->filter(function (ElementSteps $step) {
  83. //开启的
  84. return isset($step) && $step->isShow();
  85. });
  86. return $this->items;
  87. }
  88. }