CacheDao.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\system;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\BaseModel;
  14. use app\common\model\system\Cache;
  15. use think\db\exception\DbException;
  16. /**
  17. * Class CacheDao
  18. * @package app\common\dao\system
  19. * @author xaboy
  20. * @day 2020-04-24
  21. */
  22. class CacheDao extends BaseDao
  23. {
  24. /**
  25. * @return BaseModel
  26. * @author xaboy
  27. * @day 2020-03-30
  28. */
  29. protected function getModel(): string
  30. {
  31. return Cache::class;
  32. }
  33. /**
  34. * @param $key
  35. * @return mixed
  36. * @author xaboy
  37. * @day 2020-04-24
  38. */
  39. public function getResult($key)
  40. {
  41. $val = Cache::getDB()->where('key', $key)->value('result');
  42. return $val ? json_decode($val, true) : null;
  43. }
  44. /**
  45. * @param string $key
  46. * @param $data
  47. * @throws DbException
  48. * @author xaboy
  49. * @day 2020-04-24
  50. */
  51. public function keyUpdate(string $key, $data)
  52. {
  53. if (isset($data['result']))
  54. $data['result'] = json_encode($data['result'], JSON_UNESCAPED_UNICODE);
  55. Cache::getDB()->where('key', $key)->update($data);
  56. }
  57. }