Cache.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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 crmeb\basic\BaseController;
  14. use think\App;
  15. class Cache extends BaseController
  16. {
  17. /**
  18. * @var CacheRepository
  19. */
  20. protected $repository;
  21. /**
  22. * CacheRepository constructor.
  23. * @param App $app
  24. */
  25. public function __construct(App $app, CacheRepository $repository)
  26. {
  27. parent::__construct($app);
  28. $this->repository = $repository;
  29. }
  30. public function getKeyLst()
  31. {
  32. $type = $this->request->param('type',0);
  33. $data = $this->repository->getAgreeList($type);
  34. return app('json')->success($data);
  35. }
  36. /**
  37. * @Author:Qinii
  38. * @Date: 2020/9/15
  39. * @return mixed
  40. */
  41. public function getAgree($key)
  42. {
  43. $allow = $this->repository->getAgreeKey();
  44. if (!in_array($key, $allow)) return app('json')->fail('数据不存在');
  45. $data = $this->repository->getResult($key);
  46. return app('json')->success($data);
  47. }
  48. /**
  49. * @Author:Qinii
  50. * @Date: 2020/9/15
  51. * @return mixed
  52. */
  53. public function saveAgree($key)
  54. {
  55. $allow = $this->repository->getAgreeKey();
  56. if (!in_array($key, $allow)) return app('json')->fail('KEY不存在');
  57. $value = $this->request->param('agree');
  58. $this->repository->save($key, $value);
  59. if ($key == CacheRepository::USER_PRIVACY)
  60. $this->repository->setUserAgreement($value);
  61. if ($key == CacheRepository::USER_AGREE)
  62. $this->repository->setUserRegister($value);
  63. return app('json')->success('保存成功');
  64. }
  65. /**
  66. * TODO 清除缓存
  67. * @return \think\response\Json
  68. * @author Qinii
  69. * @day 12/9/21
  70. */
  71. public function clearCache()
  72. {
  73. return app('json')->success('清除缓存成功');
  74. }
  75. }