Setting.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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['_other'] = $this->getOtherSetting();
  44. return $data;
  45. }
  46. /**
  47. * 获取其他设置
  48. * @return array
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\DbException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. */
  53. public function getOtherSetting(): array
  54. {
  55. // H5端访问地址
  56. $data['h5Url'] = H5SettingModel::getH5Url();
  57. return $data;
  58. }
  59. /**
  60. * 积分设置 (积分名称、积分描述)
  61. * @return array
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\DbException
  64. * @throws \think\db\exception\ModelNotFoundException
  65. */
  66. private function getPoints(): array
  67. {
  68. $values = SettingModel::getItem(SettingEnum::POINTS);
  69. return helper::pick($values, ['points_name', 'describe']);
  70. }
  71. /**
  72. * 积分设置 (积分名称、积分描述)
  73. * @return array
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\DbException
  76. * @throws \think\db\exception\ModelNotFoundException
  77. */
  78. private function getRecharge(): array
  79. {
  80. $values = SettingModel::getItem(SettingEnum::RECHARGE);
  81. return helper::pick($values, ['is_entrance', 'is_custom', 'describe']);
  82. }
  83. /**
  84. * 获取分类页模板设置
  85. * @return array|mixed
  86. * @throws \think\db\exception\DataNotFoundException
  87. * @throws \think\db\exception\DbException
  88. * @throws \think\db\exception\ModelNotFoundException
  89. */
  90. private function getCatTplStyle()
  91. {
  92. return SettingModel::getItem(SettingEnum::PAGE_CATEGORY_TEMPLATE);
  93. }
  94. }