OrderStatusStepManager.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/12/9
  6. * Time: 15:22
  7. */
  8. namespace app\backend\modules\order\steps;
  9. use app\common\services\steps\interfaces\ElementSteps;
  10. class OrderStatusStepManager
  11. {
  12. public $order;
  13. protected $items;
  14. public function __construct($order)
  15. {
  16. $this->order = $order;
  17. }
  18. /**
  19. * 获取当前订单配置
  20. * @return array|mixed
  21. */
  22. public function getOrderStepSetting()
  23. {
  24. // $configs = \app\common\modules\shop\ShopConfig::current()->get('');
  25. $configs = $this->getBasicStep();
  26. return $configs;
  27. }
  28. protected function getBasicStep()
  29. {
  30. return [
  31. \app\backend\modules\order\steps\Create::class,
  32. \app\backend\modules\order\steps\Pay::class,
  33. \app\backend\modules\order\steps\Send::class,
  34. \app\backend\modules\order\steps\Receive::class,
  35. \app\backend\modules\order\steps\Cancel::class,
  36. ];
  37. }
  38. public function getStepItems()
  39. {
  40. $stepItems = $this->_stepItems()->sortBy(function (OrderStepFactory $step) {
  41. return $step->sort();
  42. })->map(function (OrderStepFactory $step) {
  43. return [
  44. 'title' => $step->getTitle(),
  45. 'desc' => $step->getDescription(),
  46. 'status' => $step->getStatus(),
  47. 'icon' => $step->getIcon(),
  48. ];
  49. })->values()->toArray();
  50. return $stepItems;
  51. }
  52. /**
  53. * @return mixed
  54. */
  55. public function _stepItems()
  56. {
  57. if (isset($this->items)) {
  58. return $this->items;
  59. }
  60. $this->items = collect($this->getOrderStepSetting())->map(function ($step) {
  61. if (class_exists($step)) {
  62. return new $step($this->order);
  63. }
  64. return null;
  65. })->filter(function (ElementSteps $step) {
  66. //开启的
  67. return isset($step) && $step->isShow();
  68. });
  69. return $this->items;
  70. }
  71. }