fix : coupon
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user