You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StoreConfigServices.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\services\store;
  3. use app\dao\store\StoreConfigDao;
  4. use app\services\BaseServices;
  5. /**
  6. * Class StoreConfigServices
  7. * @package app\services\store
  8. */
  9. class StoreConfigServices extends BaseServices
  10. {
  11. //打印机配置
  12. const PRINTER_KEY = [
  13. 'store_terminal_number', 'store_printing_client_id',
  14. 'store_printing_api_key', 'store_develop_id', 'store_pay_success_printing_switch'
  15. ];
  16. //快递发货配置
  17. const EXPRESS_KEY = [
  18. 'store_config_export_id', 'store_config_export_temp_id', 'store_config_export_to_name',
  19. 'store_config_export_to_tel', 'store_config_export_to_address', 'store_config_export_siid', 'store_config_export_open'
  20. ];
  21. const CONFIG_TYPE = [
  22. 'store_printing_deploy' => self::PRINTER_KEY,
  23. 'store_electronic_sheet' => self::EXPRESS_KEY
  24. ];
  25. /**
  26. * StoreConfigServices constructor.
  27. * @param StoreConfigDao $dao
  28. */
  29. public function __construct(StoreConfigDao $dao)
  30. {
  31. $this->dao = $dao;
  32. }
  33. /**
  34. * 保存或者更新门店配置
  35. * @param array $data
  36. * @param int $storeId
  37. */
  38. public function saveConfig(array $data, int $storeId)
  39. {
  40. $config = [];
  41. foreach ($data as $key => $value) {
  42. if ($this->dao->count(['key_name' => $key, 'store_id' => $storeId])) {
  43. $this->dao->update(['key_name' => $key, 'store_id' => $storeId], ['value' => json_encode($value)]);
  44. } else {
  45. $config[] = [
  46. 'key_name' => $key,
  47. 'store_id' => $storeId,
  48. 'value' => json_encode($value)
  49. ];
  50. }
  51. }
  52. if ($config) {
  53. $this->dao->saveAll($config);
  54. }
  55. }
  56. /**
  57. * 获取配置
  58. * @param int $storeId
  59. * @param string $key
  60. * @param null $default
  61. * @return mixed|null
  62. */
  63. public function getConfig(int $storeId, string $key, $default = null)
  64. {
  65. $value = $this->dao->value(['key_name' => $key, 'store_id' => $storeId], 'value');
  66. return is_null($value) ? $default : json_decode($value, true);
  67. }
  68. /**
  69. * @param int $storeId
  70. * @param array $key
  71. */
  72. // public function getConfigAll(int $storeId, array $key)
  73. // {
  74. // $confing = $this->dao->search()->whereIn('key_name', $key)->where('store_id', $storeId)->column('value', 'key_name');
  75. // return array_map(function ($item) {
  76. // return json_decode($item, true);
  77. // }, $confing);
  78. // }
  79. }