Setting.php 4.1 KB

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