Setting.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2025 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\model\wxapp\Setting as SettingModel;
  15. use app\common\library\helper;
  16. use app\common\library\wechat\Shipping as WechatShippingApi;
  17. use cores\exception\BaseException;
  18. /**
  19. * 微信小程序设置模型
  20. * Class Setting
  21. * @package app\store\model\wxapp
  22. */
  23. class Setting extends SettingModel
  24. {
  25. /**
  26. * 设置项描述
  27. * @var array
  28. */
  29. private array $describe = ['basic' => '基础设置'];
  30. /**
  31. * 更新系统设置
  32. * @param string $key
  33. * @param array $values
  34. * @return bool
  35. * @throws BaseException
  36. */
  37. public function edit(string $key, array $values): bool
  38. {
  39. $model = self::detail($key) ?: $this;
  40. // 删除小程序设置缓存
  41. Cache::delete('wxapp_setting_' . self::$storeId);
  42. // 设置消息跳转路径
  43. $values['enableShipping'] && $this->setMsgJumpPath($values);
  44. // 保存设置
  45. return $model->save([
  46. 'key' => $key,
  47. 'describe' => $this->describe[$key],
  48. 'values' => helper::pick($values, ['enabled', 'app_id', 'app_secret', 'enableShipping']),
  49. 'update_time' => time(),
  50. 'store_id' => self::$storeId,
  51. ]);
  52. }
  53. /**
  54. * 微信小程序 -> 发货信息管理 -> 消息跳转路径设置接口
  55. * @param array $values
  56. * @return true
  57. * @throws BaseException
  58. */
  59. private function setMsgJumpPath(array $values): bool
  60. {
  61. // 请求API数据
  62. $WechatShippingApi = new WechatShippingApi($values['app_id'], $values['app_secret']);
  63. // 处理返回结果
  64. $response = $WechatShippingApi->setMsgJumpPath([
  65. 'path' => 'pages/order/index?dataType=received'
  66. ]);
  67. empty($response) && throwError('微信API请求失败:' . $WechatShippingApi->getError());
  68. return true;
  69. }
  70. }