12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace App\Cache;
- use App\Consts\BaseConst;
- use App\Libs\Utils;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\Redis;
- class FinanceCache
- {
- /**
- * 获取手机验证码
- *
- * @param $channelId
- * @param $phone
- * @return mixed
- */
- public static function getSmsCode($channelId, $phone)
- {
- $cacheKey = Utils::getCacheKey('finance.sms_code', [$channelId, $phone]);
- return Redis::get($cacheKey);
- }
- /**
- * 设置手机验证码
- *
- * @param $channelId
- * @param $phone
- * @param $code
- * @return bool
- */
- public static function setSmsCode($channelId, $phone, $code)
- {
- $cacheKey = Utils::getCacheKey('finance.sms_code', [$channelId, $phone]);
- Redis::set($cacheKey, $code);
- $ttl = Redis::ttl($cacheKey);
- if ((int)$ttl < 1) {
- // 缓存设置10分钟
- Redis::expire($cacheKey, 600);
- Cache::put($cacheKey, $code, 10);
- }
- return true;
- }
- /**
- * 删除验证码
- *
- * @param $channelId
- * @param $phone
- * @return mixed
- */
- public static function delSmsCode($channelId, $phone)
- {
- $cacheKey = Utils::getCacheKey('finance.sms_code', [$channelId, $phone]);
- Cache::forget($cacheKey);
- return Redis::del($cacheKey);
- }
- /**
- * 添加渠道到当天提现队列
- *
- * @param $chanelId
- * @param $ymd
- * @return bool
- */
- public static function sAddChannelIdToWithDraw($chanelId, $ymd)
- {
- $cacheKey = Utils::getCacheKey('finance.with_draw', [$ymd]);
- Redis::sAdd($cacheKey, $chanelId);
- $ttl = Redis::ttl($cacheKey);
- if ((int)$ttl < 1) {
- Redis::expire($cacheKey, BaseConst::ONE_DAY_SECONDS);
- }
- return true;
- }
- /**
- * 判别渠道是否在日期提现队列中
- *
- * @param $chanelId
- * @param $ymd
- * @return mixed
- */
- public static function checkChannelIdIsInWithDraw($chanelId, $ymd)
- {
- $cacheKey = Utils::getCacheKey('finance.with_draw', [$ymd]);
- return Redis::sIsmember($cacheKey, $chanelId);
- }
- }
|