Cache.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\system;
  12. use app\common\repositories\system\CacheRepository;
  13. use app\common\repositories\system\config\ConfigValueRepository;
  14. use crmeb\basic\BaseController;
  15. use crmeb\services\RedisCacheService;
  16. use think\App;
  17. use think\facade\Cache as BaseCache;
  18. class Cache extends BaseController
  19. {
  20. /**
  21. * @var CacheRepository
  22. */
  23. protected $repository;
  24. /**
  25. * CacheRepository constructor.
  26. * @param App $app
  27. */
  28. public function __construct(App $app, CacheRepository $repository)
  29. {
  30. parent::__construct($app);
  31. $this->repository = $repository;
  32. }
  33. /**
  34. * 获取协议列表字段
  35. * @return \think\response\Json
  36. * @author Qinii
  37. */
  38. public function getKeyLst()
  39. {
  40. $type = $this->request->param('type', 0);
  41. $data = $this->repository->getAgreeList($type);
  42. return app('json')->success($data);
  43. }
  44. /**
  45. * 各种协议获取
  46. * @Author:Qinii
  47. * @Date: 2020/9/15
  48. * @return mixed
  49. */
  50. public function getAgree($key)
  51. {
  52. $allow = $this->repository->getAgreeKey();
  53. if (!in_array($key, $allow)) return app('json')->fail('数据不存在');
  54. $data = $this->repository->getResult($key);
  55. return app('json')->success($data);
  56. }
  57. /**
  58. * 协议保存
  59. * @Author:Qinii
  60. * @Date: 2020/9/15
  61. * @return mixed
  62. */
  63. public function saveAgree($key)
  64. {
  65. $allow = $this->repository->getAgreeKey();
  66. if (!in_array($key, $allow)) return app('json')->fail('KEY不存在');
  67. $value = $this->request->param('agree');
  68. $this->repository->save($key, $value);
  69. if ($key == CacheRepository::USER_PRIVACY)
  70. $this->repository->setUserAgreement($value);
  71. if ($key == CacheRepository::USER_AGREE)
  72. $this->repository->setUserRegister($value);
  73. return app('json')->success('保存成功');
  74. }
  75. /**
  76. * 清除缓存
  77. * @return \think\response\Json
  78. * @author Qinii
  79. * @day 12/9/21
  80. */
  81. public function clearCache()
  82. {
  83. $type = $this->request->param('type', 1);
  84. switch ($type) {
  85. case 2:
  86. BaseCache::tag('get_product')->clear();
  87. break;
  88. case 3:
  89. BaseCache::delete('get_api_config');
  90. break;
  91. default:
  92. BaseCache::clear();
  93. break;
  94. }
  95. $configValueRepository = app()->make(ConfigValueRepository::class);
  96. $configValueRepository->syncConfig();
  97. $configValueRepository->special();
  98. return app('json')->success('清除缓存成功');
  99. }
  100. }