Setting.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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\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::POINTS] = $this->getPoints();
  41. // 充值设置
  42. $data[SettingEnum::RECHARGE] = $this->getRecharge();
  43. // 注册设置
  44. $data[SettingEnum::REGISTER] = $this->getRegister();
  45. // 店铺设置
  46. $data['store'] = StoreModel::getInfo();
  47. // 其他设置
  48. $data['_other'] = $this->getOtherSetting();
  49. return $data;
  50. }
  51. /**
  52. * 获取其他设置
  53. * @return array
  54. * @throws \think\db\exception\DataNotFoundException
  55. * @throws \think\db\exception\DbException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. */
  58. public function getOtherSetting(): array
  59. {
  60. // H5端访问地址
  61. $data['h5Url'] = H5SettingModel::getH5Url();
  62. return $data;
  63. }
  64. /**
  65. * 积分设置 (积分名称、积分描述)
  66. * @return array
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\DbException
  69. * @throws \think\db\exception\ModelNotFoundException
  70. */
  71. private function getPoints(): array
  72. {
  73. $values = SettingModel::getItem(SettingEnum::POINTS);
  74. return helper::pick($values, ['points_name', 'describe']);
  75. }
  76. /**
  77. * 积分设置 (积分名称、积分描述)
  78. * @return array
  79. * @throws \think\db\exception\DataNotFoundException
  80. * @throws \think\db\exception\DbException
  81. * @throws \think\db\exception\ModelNotFoundException
  82. */
  83. private function getRecharge(): array
  84. {
  85. $values = SettingModel::getItem(SettingEnum::RECHARGE);
  86. return helper::pick($values, ['is_entrance', 'is_custom', 'describe']);
  87. }
  88. /**
  89. * 注册设置 (默认登录方式、是否开启微信小程序授权登录)
  90. * @return array
  91. * @throws \think\db\exception\DataNotFoundException
  92. * @throws \think\db\exception\DbException
  93. * @throws \think\db\exception\ModelNotFoundException
  94. */
  95. private function getRegister(): array
  96. {
  97. $values = SettingModel::getItem(SettingEnum::REGISTER);
  98. return helper::pick($values, ['registerMethod', 'isOauthMpweixin', 'isManualBind']);
  99. }
  100. /**
  101. * 获取分类页模板设置
  102. * @return array|mixed
  103. * @throws \think\db\exception\DataNotFoundException
  104. * @throws \think\db\exception\DbException
  105. * @throws \think\db\exception\ModelNotFoundException
  106. */
  107. private function getCatTplStyle()
  108. {
  109. return SettingModel::getItem(SettingEnum::PAGE_CATEGORY_TEMPLATE);
  110. }
  111. }