ConfigController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2017/12/5/005
  6. * Time: 9:50
  7. */
  8. namespace backend\controllers;
  9. use backend\models\Config;
  10. class ConfigController extends BaseController
  11. {
  12. const EVENT_CMD_DEL = 'del';
  13. /**
  14. * 获取配置详情
  15. */
  16. public function actionGetConfig()
  17. {
  18. $cache = \Yii::$app->cache;
  19. $config = $cache->get('config');
  20. if ($config == null) {
  21. $config = Config::findOne(1);
  22. $cache->set('config', $config, 86400);
  23. }
  24. return $this->outJson(1, $config);
  25. }
  26. /**
  27. * 更新配置
  28. */
  29. public function actionUpdate()
  30. {
  31. $request = \Yii::$app->request->getBodyParams();
  32. $config = Config::findOne(1);
  33. $config->setAttributes($request, false);
  34. if ($config->save()) {
  35. $cache = \Yii::$app->cache;
  36. $cache->set('config', Config::findOne(1));
  37. }
  38. $configModel = new Config();
  39. // 事件的绑定
  40. $this->on(self::EVENT_CMD_DEL, [$configModel, 'updateEvent']);
  41. // 事件的触发
  42. $this->trigger(self::EVENT_CMD_DEL);
  43. return $this->outJson(1, $config, '操作成功');
  44. }
  45. /**
  46. * 清除缓存
  47. */
  48. public function actionClearCache()
  49. {
  50. $cache = \Yii::$app->cache;
  51. $cache->flush();
  52. $config = Config::findOne(1);
  53. $cache->set('CacheDepositJob', false);
  54. $cache->set('CacheVolumeJob', false);
  55. $cache->set('CommissionJobRun', false);
  56. $cache->set('CommissionJobRunTime', $config->commission_deal_time);
  57. $cache->set('config', $config);
  58. return $this->outJson(1, $cache, '操作成功');
  59. }
  60. }