|
|
@@ -32,9 +32,9 @@ class GiftController extends Controller
|
|
|
public function lists(): JsonResponse
|
|
|
{
|
|
|
$customerId = auth()->user()->id;
|
|
|
- // 获取用户拥有的所有礼品卡
|
|
|
+ // 获取用户拥有的所有礼品卡(已过期的也算领过,避免重复兑换同一渠道)
|
|
|
$userGiftCards = GiftCards::where('customer_id', $customerId)
|
|
|
- ->where('giftcard_status', 1)
|
|
|
+ ->whereIn('giftcard_status', GiftCards::CLAIMED_STATUSES)
|
|
|
->get()
|
|
|
->keyBy('channel');
|
|
|
$gifts = $this->giftCardsModel->giftcards();
|
|
|
@@ -60,6 +60,15 @@ class GiftController extends Controller
|
|
|
}
|
|
|
$customerId = auth()->user()->id;
|
|
|
try {
|
|
|
+ // 该渠道已经领过(含已过期)的卡,不允许再拿积分重复兑换
|
|
|
+ $gift = $this->giftCardsModel->giftcards()[$id] ?? null;
|
|
|
+ $alreadyClaimed = $gift && GiftCards::where('customer_id', $customerId)
|
|
|
+ ->where('channel', $gift['channel'])
|
|
|
+ ->whereIn('giftcard_status', GiftCards::CLAIMED_STATUSES)
|
|
|
+ ->exists();
|
|
|
+ if ($alreadyClaimed) {
|
|
|
+ return ApiResponse::error('Gift card already claimed.');
|
|
|
+ }
|
|
|
$this->giftCardsModel->add($id, $customerId);
|
|
|
} catch (\Exception $e) {
|
|
|
return ApiResponse::error($e->getMessage());
|
|
|
@@ -116,6 +125,10 @@ class GiftController extends Controller
|
|
|
if (!$giftCard) {
|
|
|
return ApiResponse::error('giftcard not found.');
|
|
|
}
|
|
|
+ // 已过期的礼品卡不能再用
|
|
|
+ if ($giftCard->isExpired()) {
|
|
|
+ return ApiResponse::error('Gift card has expired.');
|
|
|
+ }
|
|
|
$remainingGiftcardAmount = core()->convertPrice($giftCard->remaining_giftcard_amount);
|
|
|
if ($remainingGiftcardAmount <= 0) {
|
|
|
return ApiResponse::error('Gift card already used.');
|