cache; $config = $cache->get('config'); if ($config == null) { $config = Config::findOne(1); $cache->set('config', $config, 86400); } return $this->outJson(1, $config); } /** * 更新配置 */ public function actionUpdate() { $request = \Yii::$app->request->getBodyParams(); $config = Config::findOne(1); $config->setAttributes($request, false); if ($config->save()) { $cache = \Yii::$app->cache; $cache->set('config', Config::findOne(1)); // 更新我们 redis 中的数据 $cache = \Yii::$app->redis; $cache->set('exchangeRate', $config['exchangerate']); } $configModel = new Config(); // 事件的绑定 $this->on(self::EVENT_CMD_DEL, [$configModel, 'updateEvent']); // 事件的触发 $this->trigger(self::EVENT_CMD_DEL); return $this->outJson(1, $config, '操作成功'); } /** * 清除缓存 */ public function actionClearCache() { $cache = \Yii::$app->cache; $cache->flush(); $config = Config::findOne(1); $cache->set('CacheDepositJob', false); $cache->set('CacheVolumeJob', false); $cache->set('CommissionJobRun', false); $cache->set('CommissionJobRunTime', $config->commission_deal_time); $cache->set('config', $config); return $this->outJson(1, $cache, '操作成功'); } }