|
|
@@ -7,6 +7,8 @@ use Longyi\Gift\Models\GiftCardUsageLog;
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
use Longyi\Gift\Contracts\GiftCards as GiftCardsContract;
|
|
|
+use Longyi\RewardPoints\Config\TransactionType;
|
|
|
+use Longyi\RewardPoints\Repositories\RewardPointRepository;
|
|
|
|
|
|
class GiftCards extends Model implements GiftCardsContract
|
|
|
{
|
|
|
@@ -210,7 +212,7 @@ class GiftCards extends Model implements GiftCardsContract
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- public function add($id)
|
|
|
+ public function add($id, $customerId)
|
|
|
{
|
|
|
$gifts = $this->giftcards();
|
|
|
$giftInfo = $gifts[$id] ?? null;
|
|
|
@@ -219,11 +221,18 @@ class GiftCards extends Model implements GiftCardsContract
|
|
|
}
|
|
|
try {
|
|
|
DB::beginTransaction();
|
|
|
- self::addGiftCard($id, $giftInfo['amount'], $giftInfo['num'], $giftInfo['expirationdate'], $giftInfo['channel'], $giftInfo['notes']);
|
|
|
+ self::addGiftCard($customerId, $giftInfo['amount'], $giftInfo['num'], $giftInfo['expirationdate'], $giftInfo['channel'], $giftInfo['notes']);
|
|
|
+ $rewardPointRepository = app(RewardPointRepository::class);//积分兑换
|
|
|
+ $rewardPointRepository->deductPoints(
|
|
|
+ $customerId,
|
|
|
+ TransactionType::GIFT_CARD_REDEEM,
|
|
|
+ $giftInfo['points'],
|
|
|
+ '积分兑换礼品卡'
|
|
|
+ );
|
|
|
DB::commit();
|
|
|
} catch (\Exception $e) {
|
|
|
DB::rollBack();
|
|
|
- throw $e;
|
|
|
+ return $e->getMessage();
|
|
|
}
|
|
|
return true;
|
|
|
}
|