48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?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;
|
|
}
|
|
} |