48 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Utils;
use Hyperf\Context\ApplicationContext;
use Hyperf\Redis\Redis;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/**
* @property $container
*/
class Utils
{
/**
* 检测执行次数
* @param string $redis_key
* @return bool
*/
public function checkHandleNumber(string $redis_key): bool
{
try {
$redis = ApplicationContext::getContainer()->get(Redis::class);
$redis_value = $redis->get($redis_key);
if (empty($redis_value)) {
$redis->set($redis_key, 1, 60 * 60 * 24 * 1);
return true;
}
// 问诊订单执行退款次数过多
if ($redis_value > 3) {
// 加入短信队列,通知管理员
// 返回false删除掉缓存
$redis->del($redis_key);
return false;
}
$redis->incr($redis_key);
} catch (\Throwable $e) {
Log::getInstance("Utils-checkHandleNumber")->error($e->getMessage());
return false;
}
return true;
}
}