fix : coupon

This commit is contained in:
2025-03-31 16:55:21 +08:00
parent 775b4d8cb2
commit f26160d48d
2 changed files with 25 additions and 3 deletions

View File

@@ -64,4 +64,13 @@ class ApiRedisKey
{ {
return 'lock:pay:user_id:'. $userId; return 'lock:pay:user_id:'. $userId;
} }
/**
* @param int $userId
* @return string
*/
public static function refundLock(int $userId)
{
return 'lock:refund:user_id:'. $userId;
}
} }

View File

@@ -10,6 +10,8 @@ declare(strict_types=1);
namespace App\Service\Api\Order; namespace App\Service\Api\Order;
use App\Cache\Redis\Api\ApiRedisKey;
use App\Cache\Redis\RedisCache;
use App\Constants\Common\OrderCode; use App\Constants\Common\OrderCode;
use App\Constants\Common\RefundCode; use App\Constants\Common\RefundCode;
use App\Exception\ErrException; use App\Exception\ErrException;
@@ -39,6 +41,12 @@ class RefundOrderService extends BaseService
#[Inject] #[Inject]
protected PayOrder $payOrderModel; protected PayOrder $payOrderModel;
/**
* @var RedisCache
*/
#[Inject]
protected RedisCache $redis;
/** /**
* @return array * @return array
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
@@ -46,8 +54,12 @@ class RefundOrderService extends BaseService
*/ */
public function handle(): array public function handle(): array
{ {
//todo 考虑是否枷锁 // 考虑是否枷锁
$orderId = (int)$this->request->input('order_id'); $orderId = (int)$this->request->input('order_id');
$refundLockKey = ApiRedisKey::refundLock($this->userId);
if (0 == ($this->redis->addLock($refundLockKey))){
throw new ErrException('请勿重复点击');
}
$orderInfo = $this->orderModel->getInfoById($orderId); $orderInfo = $this->orderModel->getInfoById($orderId);
@@ -64,10 +76,11 @@ class RefundOrderService extends BaseService
$service->type = RefundCode::FULL_GOOD_REFUND; $service->type = RefundCode::FULL_GOOD_REFUND;
$service->handle(); $service->handle();
return $this->return->success();
}catch (Exception $e) { }catch (Exception $e) {
throw new ErrException($e->getMessage()); throw new ErrException($e->getMessage());
} }
$this->redis->delLock($refundLockKey);
return $this->return->success();
} }
} }