CacheDao.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-04-24
  7. *
  8. *
  9. */
  10. namespace app\common\dao\system;
  11. use app\common\dao\BaseDao;
  12. use app\common\model\BaseModel;
  13. use app\common\model\system\Cache;
  14. use think\db\exception\DbException;
  15. /**
  16. * Class CacheDao
  17. * @package app\common\dao\system
  18. * @author xaboy
  19. * @day 2020-04-24
  20. */
  21. class CacheDao extends BaseDao
  22. {
  23. /**
  24. * @return BaseModel
  25. * @author xaboy
  26. * @day 2020-03-30
  27. */
  28. protected function getModel(): string
  29. {
  30. return Cache::class;
  31. }
  32. /**
  33. * @param $key
  34. * @return mixed
  35. * @author xaboy
  36. * @day 2020-04-24
  37. */
  38. public function getResult($key)
  39. {
  40. $val = Cache::getDB()->where('key', $key)->value('result');
  41. return $val ? json_decode($val, true) : null;
  42. }
  43. /**
  44. * @param string $key
  45. * @param $data
  46. * @throws DbException
  47. * @author xaboy
  48. * @day 2020-04-24
  49. */
  50. public function keyUpdate(string $key, $data)
  51. {
  52. if (isset($data['result']))
  53. $data['result'] = json_encode($data['result']);
  54. Cache::getDB()->where('key', $key)->update($data);
  55. }
  56. }