Setting.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 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\common\library\helper;
  14. use app\common\service\BaseService;
  15. use app\api\model\Setting as SettingModel;
  16. use app\api\model\h5\Setting as H5SettingModel;
  17. use app\common\enum\Setting as SettingEnum;
  18. /**
  19. * 服务类:商城设置
  20. * Class Setting
  21. * @package app\api\service
  22. */
  23. class Setting extends BaseService
  24. {
  25. /**
  26. * 商城公共设置
  27. * 这里的商城设置仅暴露可公开的设置项 例如分类页模板、积分名称
  28. * @return array
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. */
  33. public function getPublic(): array
  34. {
  35. $data = [];
  36. //分类页模板设置
  37. $data[SettingEnum::PAGE_CATEGORY_TEMPLATE] = $this->getCatTplStyle();
  38. // 积分设置
  39. $data[SettingEnum::POINTS] = $this->getPoints();
  40. // 充值设置
  41. $data[SettingEnum::RECHARGE] = $this->getRecharge();
  42. // 注册设置
  43. $data[SettingEnum::REGISTER] = $this->getRegister();
  44. // 其他设置
  45. $data['_other'] = $this->getOtherSetting();
  46. return $data;
  47. }
  48. /**
  49. * 获取其他设置
  50. * @return array
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\DbException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. */
  55. public function getOtherSetting(): array
  56. {
  57. // H5端访问地址
  58. $data['h5Url'] = H5SettingModel::getH5Url();
  59. return $data;
  60. }
  61. /**
  62. * 积分设置 (积分名称、积分描述)
  63. * @return array
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\DbException
  66. * @throws \think\db\exception\ModelNotFoundException
  67. */
  68. private function getPoints(): array
  69. {
  70. $values = SettingModel::getItem(SettingEnum::POINTS);
  71. return helper::pick($values, ['points_name', 'describe']);
  72. }
  73. /**
  74. * 积分设置 (积分名称、积分描述)
  75. * @return array
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\DbException
  78. * @throws \think\db\exception\ModelNotFoundException
  79. */
  80. private function getRecharge(): array
  81. {
  82. $values = SettingModel::getItem(SettingEnum::RECHARGE);
  83. return helper::pick($values, ['is_entrance', 'is_custom', 'describe']);
  84. }
  85. /**
  86. * 注册设置 (默认登录方式、是否开启微信小程序授权登录)
  87. * @return array
  88. * @throws \think\db\exception\DataNotFoundException
  89. * @throws \think\db\exception\DbException
  90. * @throws \think\db\exception\ModelNotFoundException
  91. */
  92. private function getRegister(): array
  93. {
  94. $values = SettingModel::getItem(SettingEnum::REGISTER);
  95. return helper::pick($values, ['registerMethod', 'isOauthMpweixin', 'isManualBind']);
  96. }
  97. /**
  98. * 获取分类页模板设置
  99. * @return array|mixed
  100. * @throws \think\db\exception\DataNotFoundException
  101. * @throws \think\db\exception\DbException
  102. * @throws \think\db\exception\ModelNotFoundException
  103. */
  104. private function getCatTplStyle()
  105. {
  106. return SettingModel::getItem(SettingEnum::PAGE_CATEGORY_TEMPLATE);
  107. }
  108. }