FinanceCache.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace App\Cache;
  3. use App\Consts\BaseConst;
  4. use App\Libs\Utils;
  5. use Illuminate\Support\Facades\Cache;
  6. use Illuminate\Support\Facades\Redis;
  7. class FinanceCache
  8. {
  9. /**
  10. * 获取手机验证码
  11. *
  12. * @param $channelId
  13. * @param $phone
  14. * @return mixed
  15. */
  16. public static function getSmsCode($channelId, $phone)
  17. {
  18. $cacheKey = Utils::getCacheKey('finance.sms_code', [$channelId, $phone]);
  19. return Redis::get($cacheKey);
  20. }
  21. /**
  22. * 设置手机验证码
  23. *
  24. * @param $channelId
  25. * @param $phone
  26. * @param $code
  27. * @return bool
  28. */
  29. public static function setSmsCode($channelId, $phone, $code)
  30. {
  31. $cacheKey = Utils::getCacheKey('finance.sms_code', [$channelId, $phone]);
  32. Redis::set($cacheKey, $code);
  33. $ttl = Redis::ttl($cacheKey);
  34. if ((int)$ttl < 1) {
  35. // 缓存设置10分钟
  36. Redis::expire($cacheKey, 600);
  37. Cache::put($cacheKey, $code, 10);
  38. }
  39. return true;
  40. }
  41. /**
  42. * 删除验证码
  43. *
  44. * @param $channelId
  45. * @param $phone
  46. * @return mixed
  47. */
  48. public static function delSmsCode($channelId, $phone)
  49. {
  50. $cacheKey = Utils::getCacheKey('finance.sms_code', [$channelId, $phone]);
  51. Cache::forget($cacheKey);
  52. return Redis::del($cacheKey);
  53. }
  54. /**
  55. * 添加渠道到当天提现队列
  56. *
  57. * @param $chanelId
  58. * @param $ymd
  59. * @return bool
  60. */
  61. public static function sAddChannelIdToWithDraw($chanelId, $ymd)
  62. {
  63. $cacheKey = Utils::getCacheKey('finance.with_draw', [$ymd]);
  64. Redis::sAdd($cacheKey, $chanelId);
  65. $ttl = Redis::ttl($cacheKey);
  66. if ((int)$ttl < 1) {
  67. Redis::expire($cacheKey, BaseConst::ONE_DAY_SECONDS);
  68. }
  69. return true;
  70. }
  71. /**
  72. * 判别渠道是否在日期提现队列中
  73. *
  74. * @param $chanelId
  75. * @param $ymd
  76. * @return mixed
  77. */
  78. public static function checkChannelIdIsInWithDraw($chanelId, $ymd)
  79. {
  80. $cacheKey = Utils::getCacheKey('finance.with_draw', [$ymd]);
  81. return Redis::sIsmember($cacheKey, $chanelId);
  82. }
  83. }