Setting.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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\store\model\wxapp;
  13. use think\facade\Cache;
  14. use app\common\library\helper;
  15. use app\common\model\wxapp\Setting as SettingModel;
  16. /**
  17. * 微信小程序设置模型
  18. * Class Setting
  19. * @package app\store\model\wxapp
  20. */
  21. class Setting extends SettingModel
  22. {
  23. /**
  24. * 设置项描述
  25. * @var array
  26. */
  27. private array $describe = ['basic' => '基础设置'];
  28. /**
  29. * 更新系统设置
  30. * @param string $key
  31. * @param array $values
  32. * @return bool
  33. */
  34. public function edit(string $key, array $values): bool
  35. {
  36. $model = self::detail($key) ?: $this;
  37. // 删除小程序设置缓存
  38. Cache::delete('wxapp_setting_' . self::$storeId);
  39. // 保存设置
  40. return $model->save([
  41. 'key' => $key,
  42. 'describe' => $this->describe[$key],
  43. 'values' => helper::pick($values, ['enabled', 'app_id', 'app_secret']),
  44. 'update_time' => time(),
  45. 'store_id' => self::$storeId,
  46. ]);
  47. }
  48. }