From c534d35bf4f645d7841825a25070f0cb9837ba5f Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Mon, 11 Sep 2023 18:05:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=85=E5=80=BC=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/AdminUser.php | 4 +++ app/controller/Setting.php | 69 ++++++++++++++++++++++++++++++++++++ app/model/Setting.php | 65 +++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 app/controller/Setting.php create mode 100644 app/model/Setting.php diff --git a/app/controller/AdminUser.php b/app/controller/AdminUser.php index 4948627..4cc890b 100644 --- a/app/controller/AdminUser.php +++ b/app/controller/AdminUser.php @@ -129,6 +129,10 @@ class AdminUser extends BaseController if ($login_agent_user_data) Cache::store('redis')->delete('login_agent_user_data'); $login_admin_user_data = Cache::store('redis')->get('login_admin_user_data'); if ($login_admin_user_data) Cache::store('redis')->delete('login_admin_user_data'); + $login_admin_user_data = Cache::store('redis')->get('user_recharge_set'); + if ($login_admin_user_data) Cache::store('redis')->delete('user_recharge_set'); + $login_admin_user_data = Cache::store('redis')->get('agent_recharge_set'); + if ($login_admin_user_data) Cache::store('redis')->delete('agent_recharge_set'); return $this->renderSuccess('已清除成功'); diff --git a/app/controller/Setting.php b/app/controller/Setting.php new file mode 100644 index 0000000..4e1aebb --- /dev/null +++ b/app/controller/Setting.php @@ -0,0 +1,69 @@ +renderSuccess('数据返回成功',[ + [ + 'title' => '用户端充值接口', + 'type' => 1, + 'is_open' => $user_recharge_set + ], + [ + 'title' => '代理端充值接口', + 'type' => 2, + 'is_open' => $agent_recharge_set + ] + ]); + } + + /** + * 充值设置接口 + * @return array|void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function openRecharge() + { + $param = Request::param(); + + try { + + validate()->rule([ + 'is_open|开关状态' => 'require|in:0,1', + 'type|开关类型' => 'require|in:1,2' + ])->check($param); + + $typeArr = [ 1 => 'user_recharge_set', 2 => 'agent_recharge_set']; + + SettingModel::settingSave($typeArr[$param['type']],$param['is_open']); + + return $this->renderSuccess('设置成功'); + } catch (ValidateException $validateException) { + return $this->renderError($validateException['msg']); + } + } +} diff --git a/app/model/Setting.php b/app/model/Setting.php new file mode 100644 index 0000000..a0e2197 --- /dev/null +++ b/app/model/Setting.php @@ -0,0 +1,65 @@ +where('key',$key)->find(); + $value = serialize($value); + if ($edit) { + $edit->value = $value; + $Setting = $edit->save(); + } else { + $Setting = $Setting->save(['key' => $key, 'value' => $value]); + } + + # 添加缓存 + Cache::store('redis')->set($key,$value); + + return true; + } + + /** + * 获取缓存 + * @param $key + * @return array|string + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function settingLoad($key) + { + # 获取缓存 + $catch = Cache::store('redis')->get($key); + + if (empty($catch)) { + $Setting = new Setting(); + $Setting = $Setting->where('key',$key)->find(); + if (!$Setting) return ''; + $catch = $Setting->value; + # 添加缓存 + Cache::store('redis')->set($key,$catch); + } + + return unserialize($catch); + } + + +} \ No newline at end of file