OrderViewService.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/12/3
  6. * Time: 14:13
  7. */
  8. namespace app\backend\modules\order\services;
  9. use app\backend\modules\order\services\type\OrderViewBase;
  10. use app\common\models\PayType;
  11. use app\common\models\PayTypeGroup;
  12. use app\common\services\PayFactory;
  13. class OrderViewService
  14. {
  15. protected $viewSet;
  16. public function __construct()
  17. {
  18. }
  19. public function getViewSet()
  20. {
  21. if (!isset($this->viewSet)) {
  22. $this->viewSet = $this->_getViewSet();
  23. }
  24. return $this->viewSet;
  25. }
  26. protected function _getViewSet()
  27. {
  28. $viewSet= collect([]);
  29. $configs = \app\common\modules\shop\ShopConfig::current()->get('shop-foundation.order-list.type');
  30. // 从配置文件中载入,按优先级排序
  31. $viewConfigs = collect($configs)->sortBy('priority');
  32. //遍历取到第一个通过验证的订单类型返回
  33. foreach ($viewConfigs as $configItem) {
  34. //通过验证返回
  35. if (class_exists($configItem['view'])) {
  36. $viewSet->push((new $configItem['view']));
  37. }
  38. }
  39. return $viewSet;
  40. }
  41. public function getOrderType()
  42. {
  43. $items = $this->getViewSet()->map(function(OrderViewBase $view) {
  44. $result['name'] = $view->getName();
  45. $result['need_display'] = $view->needDisplay();
  46. $result['route'] = $view->getRoute();
  47. $result['plugin_id'] = $view->getPluginId();
  48. $result['code'] = $view->getcode();
  49. return $result;
  50. })->toArray();
  51. return $items;
  52. }
  53. public function importVue()
  54. {
  55. $routes = $this->getViewSet()->filter(function (OrderViewBase $view) {
  56. return $view->getVueFilePath() && $view->getVuePrimaryName();
  57. })->map(function(OrderViewBase $view) {
  58. return [
  59. 'path'=> $view->getVueFilePath(),
  60. 'primary' => $view->getVuePrimaryName()
  61. ];
  62. })->values()->toArray();
  63. return $routes;
  64. }
  65. //搜索组件引用
  66. public function searchImport($key)
  67. {
  68. $array = ['path'=> 'order.template.search', 'name' => 'shop-order-search'];
  69. $route = request()->input('route');
  70. $viewElement = $this->getViewSet()->first(function (OrderViewBase $view) use ($route) {
  71. return $view->getRoute() == $route;
  72. });
  73. if ($viewElement && $viewElement->getSearchElementPath() && $viewElement->getSearchElementName()) {
  74. $array = ['path'=> $viewElement->getSearchElementPath(), 'name' => $viewElement->getSearchElementName()];
  75. }
  76. return $array[$key];
  77. }
  78. /**
  79. * 可以搜索的支付方式
  80. */
  81. public static function searchablePayType()
  82. {
  83. $payType = [
  84. ['name' => '微信小程序支付', 'value' => 55],
  85. ['name' => '微信H5', 'value' => 50],
  86. ['name' => '确认支付', 'value' => 54],
  87. ['name' => '货到付款', 'value' => 17],
  88. ['name' => '汇聚快捷支付', 'value' => 59],
  89. ['name' => '汇聚微信', 'value' => PayFactory::PAY_WECHAT_HJ],
  90. ['name' => '汇聚支付宝', 'value' => PayFactory::PAY_ALIPAY_HJ],
  91. ['name' => '通证支付', 'value' => PayFactory::LSP_PAY],
  92. ];
  93. return $payType;
  94. }
  95. public static function payTypeGroup()
  96. {
  97. return PayTypeGroup::select('id', 'name')->get()->toArray();
  98. }
  99. }