ConfigServices.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\system\config;
  12. use app\dao\store\StoreConfigDao;
  13. use app\services\BaseServices;
  14. use crmeb\services\SystemConfigService;
  15. /**
  16. * Class ConfigServices
  17. * @package app\services\system\config
  18. * @mixin StoreConfigDao
  19. */
  20. class ConfigServices extends BaseServices
  21. {
  22. //打印机类型
  23. const PRINTER_NAME = [
  24. 1 => 'yi_lian_yun',
  25. 2 => 'fei_e_yun',
  26. ];
  27. //平台打印机配置
  28. const PRINTER_KEY = [
  29. 'switch' => 'pay_success_printing_switch',
  30. 'print_type' => 'print_type',
  31. 'printing_client_id', 'printing_api_key', 'develop_id', 'terminal_number',
  32. 'fey_user', 'fey_ukey', 'fey_sn',
  33. ];
  34. //配置字段对应
  35. const PRINTER_CONFIG_KEY = [
  36. 'yi_lian_yun' => ['printing_client_id' => 'clientId', 'printing_api_key' => 'apiKey', 'develop_id' => 'partner', 'terminal_number' => 'terminal'],
  37. 'fei_e_yun' => ['fey_user' => 'feyUser', 'fey_ukey' => 'feyUkey', 'fey_sn' => 'feySn'],
  38. ];
  39. //门店打印机配置
  40. const STORE_PRINTER_KEY = [
  41. 'switch' => 'store_pay_success_printing_switch',
  42. 'print_type' => 'store_print_type',
  43. 'store_printing_client_id', 'store_printing_api_key', 'store_develop_id', 'store_terminal_number',
  44. 'store_fey_user', 'store_fey_ukey', 'store_fey_sn',
  45. ];
  46. //门店配置字段对应
  47. const STORE_PRINTER_CONFIG_KEY = [
  48. 'yi_lian_yun' => ['store_printing_client_id' => 'clientId', 'store_printing_api_key' => 'apiKey', 'store_develop_id' => 'partner', 'store_terminal_number' => 'terminal'],
  49. 'fei_e_yun' => ['store_fey_user' => 'feyUser', 'store_fey_ukey' => 'feyUkey', 'store_fey_sn' => 'feySn'],
  50. ];
  51. //供应商打印机配置
  52. const SUPPLIER_PRINTER_KEY = [
  53. 'switch' => 'store_pay_success_printing_switch',
  54. 'print_type' => 'store_print_type',
  55. 'store_printing_client_id', 'store_printing_api_key', 'store_develop_id', 'store_terminal_number',
  56. 'store_fey_user', 'store_fey_ukey', 'store_fey_sn',
  57. ];
  58. //供应商配置字段对应
  59. const SUPPLIER_PRINTER_CONFIG_KEY = [
  60. 'yi_lian_yun' => ['store_printing_client_id' => 'clientId', 'store_printing_api_key' => 'apiKey', 'store_develop_id' => 'partner', 'store_terminal_number' => 'terminal'],
  61. 'fei_e_yun' => ['store_fey_user' => 'feyUser', 'store_fey_ukey' => 'feyUkey', 'store_fey_sn' => 'feySn'],
  62. ];
  63. const CONFIG_TYPE = [
  64. 'printing_deploy' => self::PRINTER_KEY,
  65. 'store_printing_deploy' => self::STORE_PRINTER_KEY,
  66. 'supplier_printing_deploy' => self::SUPPLIER_PRINTER_KEY
  67. ];
  68. /**
  69. * StoreConfigServices constructor.
  70. * @param StoreConfigDao $dao
  71. */
  72. public function __construct(StoreConfigDao $dao)
  73. {
  74. $this->dao = $dao;
  75. }
  76. /**
  77. * 获取小票打印配置
  78. * @param int $type
  79. * @param int $relation_id
  80. * @return array
  81. */
  82. public function getPrintingConfig(int $type = 0, int $relation_id = 0) : array
  83. {
  84. /** @var SystemConfigService $configService */
  85. $configService = app('sysConfig');
  86. switch ($type) {
  87. case 0://平台
  88. $keys = self::PRINTER_KEY;
  89. $configKey = self::PRINTER_CONFIG_KEY;
  90. break;
  91. case 1://门店
  92. $keys = self::STORE_PRINTER_KEY;
  93. $configKey = self::STORE_PRINTER_CONFIG_KEY;
  94. $configService->setStore($relation_id);
  95. break;
  96. case 2://供应商
  97. $keys = self::SUPPLIER_PRINTER_KEY;
  98. $configKey = self::SUPPLIER_PRINTER_CONFIG_KEY;
  99. $configService->setSupplier($relation_id);
  100. break;
  101. default:
  102. $keys = self::PRINTER_KEY;
  103. $configKey = self::PRINTER_CONFIG_KEY;
  104. break;
  105. }
  106. $key = array_values($keys);
  107. $config = $configService->more($key);
  108. $switch = $config[$keys['switch']] ?? 0;
  109. $printType = $config[$keys['print_type']] ?? 1;
  110. $name = self::PRINTER_NAME[$printType] ?? 'yi_lian_yun';
  111. $configKey = $configKey[$name];
  112. $configData = [];
  113. foreach ($config as $key => $value) {
  114. if (isset($configKey[$key])) {
  115. $configData[$configKey[$key]] = $value;
  116. }
  117. }
  118. return [$switch, $name, $configData];
  119. }
  120. }