瀏覽代碼

修复错误的缓存索引

Yahoo 4 年之前
父節點
當前提交
e66deb2722
共有 4 個文件被更改,包括 2 次插入 和 149 次删除
  1. 0 39
      app/api/model/Wxapp.php
  2. 2 2
      app/common/model/h5/Setting.php
  3. 0 25
      app/console/model/Wxapp.php
  4. 0 83
      app/store/model/Wxapp.php

+ 0 - 39
app/api/model/Wxapp.php

@@ -1,39 +0,0 @@
-<?php
-// +----------------------------------------------------------------------
-// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
-// +----------------------------------------------------------------------
-// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
-// +----------------------------------------------------------------------
-// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
-// +----------------------------------------------------------------------
-// | Author: 萤火科技 <admin@yiovo.com>
-// +----------------------------------------------------------------------
-declare (strict_types = 1);
-
-namespace app\api\model;
-
-use app\common\model\Wxapp as WxappModel;
-
-/**
- * 微信小程序模型
- * Class Wxapp
- * @package app\api\model
- */
-class Wxapp extends WxappModel
-{
-    /**
-     * 隐藏字段
-     * @var array
-     */
-    protected $hidden = [
-        'store_id',
-        'app_name',
-        'app_id',
-        'app_secret',
-        'mchid',
-        'apikey',
-        'create_time',
-        'update_time'
-    ];
-
-}

+ 2 - 2
app/common/model/h5/Setting.php

@@ -75,12 +75,12 @@ class Setting extends BaseModel
     {
         is_null($storeId) && $storeId = static::$storeId;
         $model = new static;
-        if (!$data = Cache::get("wxapp_setting_{$storeId}")) {
+        if (!$data = Cache::get("h5_setting_{$storeId}")) {
             // 获取全部设置
             $setting = $model->getList($storeId);
             $data = $setting->isEmpty() ? [] : helper::arrayColumn2Key($setting->toArray(), 'key');
             // 写入缓存中
-            Cache::tag('cache')->set("wxapp_setting_{$storeId}", $data);
+            Cache::tag('cache')->set("h5_setting_{$storeId}", $data);
         }
         // 合并默认设置
         return array_merge_multiple($model->defaultData(), $data);

+ 0 - 25
app/console/model/Wxapp.php

@@ -1,25 +0,0 @@
-<?php
-// +----------------------------------------------------------------------
-// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
-// +----------------------------------------------------------------------
-// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
-// +----------------------------------------------------------------------
-// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
-// +----------------------------------------------------------------------
-// | Author: 萤火科技 <admin@yiovo.com>
-// +----------------------------------------------------------------------
-declare (strict_types = 1);
-
-namespace app\console\model;
-
-use app\common\model\Wxapp as WxappModel;
-
-/**
- * 微信小程序模型
- * Class Wxapp
- * @package app\console\model
- */
-class Wxapp extends WxappModel
-{
-
-}

+ 0 - 83
app/store/model/Wxapp.php

@@ -1,83 +0,0 @@
-<?php
-// +----------------------------------------------------------------------
-// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
-// +----------------------------------------------------------------------
-// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
-// +----------------------------------------------------------------------
-// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
-// +----------------------------------------------------------------------
-// | Author: 萤火科技 <admin@yiovo.com>
-// +----------------------------------------------------------------------
-declare (strict_types=1);
-
-namespace app\store\model;
-
-use think\facade\Cache;
-use app\common\model\Wxapp as WxappModel;
-
-/**
- * 微信小程序模型
- * Class Wxapp
- * @package app\store\model
- */
-class Wxapp extends WxappModel
-{
-    /**
-     * 更新小程序设置
-     * @param $data
-     * @return mixed
-     */
-    public function edit(array $data)
-    {
-        // 默认数据
-        $data['cert_pem'] = $data['cert_pem'] ?? '';
-        $data['key_pem'] = $data['key_pem'] ?? '';
-        // 事务处理
-        return $this->transaction(function () use ($data) {
-            // 删除wxapp缓存
-            self::deleteCache();
-            // 写入微信支付证书文件
-            $this->writeCertPemFiles($data['cert_pem'], $data['key_pem']);
-            // 更新小程序设置
-            return $this->save($data);
-        });
-    }
-
-    /**
-     * 写入cert证书文件
-     * @param string|null $certPem
-     * @param string|null $keyPem
-     * @return bool
-     */
-    private function writeCertPemFiles(string $certPem = '', string $keyPem = '')
-    {
-        if (empty($certPem) && empty($keyPem)) {
-            return false;
-        }
-        // 证书目录
-        $filePath = base_path() . 'common/library/wechat/cert/' . self::$storeId . '/';
-        // 目录不存在则自动创建
-        if (!is_dir($filePath)) {
-            mkdir($filePath, 0755, true);
-        }
-        // 写入cert.pem文件
-        if (!empty($certPem)) {
-            file_put_contents($filePath . 'cert.pem', $certPem);
-        }
-        // 写入key.pem文件
-        if (!empty($keyPem)) {
-            file_put_contents($filePath . 'key.pem', $keyPem);
-        }
-        return true;
-    }
-
-    /**
-     * 删除wxapp缓存
-     * @return bool
-     */
-    public static function deleteCache()
-    {
-        return Cache::delete('wxapp_' . self::$storeId);
-    }
-
-}