Setting.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\api\service;
  13. use app\api\model\Setting as SettingModel;
  14. use app\common\library\helper;
  15. use app\common\service\BaseService;
  16. use app\common\enum\Setting as SettingEnum;
  17. /**
  18. * 服务类:商城设置
  19. * Class Setting
  20. * @package app\api\service
  21. */
  22. class Setting extends BaseService
  23. {
  24. /**
  25. * 指定的商城公共设置
  26. * @param string $key
  27. * @return array
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\DbException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. */
  32. public static function getPublicItem(string $key): array
  33. {
  34. $setting = (new static)->getPublic();
  35. if (array_key_exists($key, $setting)) {
  36. return $setting[$key];
  37. }
  38. return [];
  39. }
  40. /**
  41. * 商城公共设置
  42. * 这里的商城设置仅暴露可公开的设置项 例如分类页模板、积分名称
  43. * @return array
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\DbException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. */
  48. public function getPublic(): array
  49. {
  50. $data = [];
  51. // 店铺页面风格设置
  52. $data[SettingEnum::APP_THEME] = $this->getAppTheme();
  53. // 分类页模板设置
  54. $data[SettingEnum::PAGE_CATEGORY_TEMPLATE] = $this->getCatTplStyle();
  55. // 积分设置
  56. $data[SettingEnum::POINTS] = $this->getPoints();
  57. // 充值设置
  58. $data[SettingEnum::RECHARGE] = $this->getRecharge();
  59. // 注册设置
  60. $data[SettingEnum::REGISTER] = $this->getRegister();
  61. // 商城客服设置
  62. $data[SettingEnum::CUSTOMER] = $this->getCustomer();
  63. return $data;
  64. }
  65. /**
  66. * 积分设置 (积分名称、积分描述)
  67. * @return array
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\DbException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. */
  72. private function getPoints(): array
  73. {
  74. $values = SettingModel::getItem(SettingEnum::POINTS);
  75. return helper::pick($values, ['points_name', 'describe']);
  76. }
  77. /**
  78. * 积分设置 (积分名称、积分描述)
  79. * @return array
  80. * @throws \think\db\exception\DataNotFoundException
  81. * @throws \think\db\exception\DbException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. */
  84. private function getRecharge(): array
  85. {
  86. $values = SettingModel::getItem(SettingEnum::RECHARGE);
  87. return helper::pick($values, ['is_entrance', 'is_custom', 'describe']);
  88. }
  89. /**
  90. * 注册设置 (默认登录方式、是否开启微信小程序授权登录)
  91. * @return array
  92. * @throws \think\db\exception\DataNotFoundException
  93. * @throws \think\db\exception\DbException
  94. * @throws \think\db\exception\ModelNotFoundException
  95. */
  96. private function getRegister(): array
  97. {
  98. $values = SettingModel::getItem(SettingEnum::REGISTER);
  99. return helper::pick($values, [
  100. 'registerMethod', 'isManualBind',
  101. 'isOauthMpweixin', 'isOauthMobileMpweixin',
  102. ]);
  103. }
  104. /**
  105. * 商城客服设置
  106. * @return array
  107. * @throws \think\db\exception\DataNotFoundException
  108. * @throws \think\db\exception\DbException
  109. * @throws \think\db\exception\ModelNotFoundException
  110. */
  111. private function getCustomer(): array
  112. {
  113. $values = SettingModel::getItem(SettingEnum::CUSTOMER);
  114. return helper::pick($values, ['enabled', 'provider', 'config']);
  115. }
  116. /**
  117. * 获取分类页模板设置
  118. * @return array|mixed
  119. * @throws \think\db\exception\DataNotFoundException
  120. * @throws \think\db\exception\DbException
  121. * @throws \think\db\exception\ModelNotFoundException
  122. */
  123. private function getCatTplStyle()
  124. {
  125. return SettingModel::getItem(SettingEnum::PAGE_CATEGORY_TEMPLATE);
  126. }
  127. /**
  128. * 获取店铺页面风格设置
  129. * @return array|mixed
  130. * @throws \think\db\exception\DataNotFoundException
  131. * @throws \think\db\exception\DbException
  132. * @throws \think\db\exception\ModelNotFoundException
  133. */
  134. private function getAppTheme()
  135. {
  136. return SettingModel::getItem(SettingEnum::APP_THEME)['data'];
  137. }
  138. }