|
|
@@ -76,16 +76,33 @@ class GiftCards extends Model implements GiftCardsContract
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
- public static function addGiftCard($customerId, $giftcardAmount, $num = 0, $channel = 'activity_26_04_21', $notes = '拉新活动添加')
|
|
|
+ /**
|
|
|
+ * Add a new gift card for a customer.
|
|
|
+ *
|
|
|
+ * @param int $customerId The ID of the customer to receive the gift card.
|
|
|
+ * @param float $giftcardAmount The initial amount/balance of the gift card.
|
|
|
+ * @param int $num Maximum number of gift cards allowed for this channel (0 means unlimited).
|
|
|
+ * @param int $expirationdate Number of days until the gift card expires (default: 30 days).
|
|
|
+ * @param string $channel The source channel or campaign identifier (default: 'activity_26_04_21').
|
|
|
+ * @param string $notes Additional notes or description for the gift card creation.
|
|
|
+ * @return void
|
|
|
+ * @throws \Exception If customerId is empty, giftcardAmount is empty, or gift card limit exceeded.
|
|
|
+ */
|
|
|
+ public static function addGiftCard($customerId, $giftcardAmount, $num = 0, $expirationdate = 30, $channel = 'activity_26_04_21', $notes = '拉新活动添加')
|
|
|
{
|
|
|
+ if (empty($customerId)) {
|
|
|
+ throw new \Exception('customerId is empty');
|
|
|
+ }
|
|
|
+ if (empty($giftcardAmount)) {
|
|
|
+ throw new \Exception('giftcardAmount is empty');
|
|
|
+ }
|
|
|
$data = GiftCards::where('customer_id', $customerId)
|
|
|
->where('channel', $channel)
|
|
|
->count();
|
|
|
if ($num != 0) {
|
|
|
$giftNum =count($data);
|
|
|
if($giftNum <= $num){
|
|
|
- return -1; // 超出
|
|
|
+ throw new \Exception('gift num is not enough');
|
|
|
}
|
|
|
}
|
|
|
static::create([
|
|
|
@@ -94,7 +111,7 @@ class GiftCards extends Model implements GiftCardsContract
|
|
|
'used_giftcard_amount' => 0,
|
|
|
'remaining_giftcard_amount' => $giftcardAmount,
|
|
|
'customer_id' => $customerId,
|
|
|
- 'expirationdate' => ,
|
|
|
+ 'expirationdate' => now()->addDays($expirationdate),
|
|
|
'giftcard_status' => 1,
|
|
|
'channel' => $channel,
|
|
|
'notes' => $notes
|