Add SMS bulk delay configuration and validate coupon phone function
This commit is contained in:
39
database/factories/SmsCampaignFactory.php
Normal file
39
database/factories/SmsCampaignFactory.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\SmsCampaign;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<SmsCampaign>
|
||||
*/
|
||||
class SmsCampaignFactory extends Factory
|
||||
{
|
||||
protected $model = SmsCampaign::class;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'message' => fake()->sentence(),
|
||||
'mode' => 'all',
|
||||
'recipient_count' => 0,
|
||||
'sent_count' => 0,
|
||||
'failed_count' => 0,
|
||||
'skipped_count' => 0,
|
||||
'created_by' => User::factory(),
|
||||
'completed_at' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function completed(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes): array => [
|
||||
'completed_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
36
database/factories/SmsSendLogFactory.php
Normal file
36
database/factories/SmsSendLogFactory.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\SmsSendStatus;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\SmsCampaign;
|
||||
use App\Models\SmsSendLog;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<SmsSendLog>
|
||||
*/
|
||||
class SmsSendLogFactory extends Factory
|
||||
{
|
||||
protected $model = SmsSendLog::class;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$campaign = SmsCampaign::factory()->create();
|
||||
$coupon = Coupon::factory()->create();
|
||||
|
||||
return [
|
||||
'sms_campaign_id' => $campaign->id,
|
||||
'coupon_id' => $coupon->id,
|
||||
'phone' => $coupon->phone,
|
||||
'message' => $campaign->message,
|
||||
'status' => SmsSendStatus::Pending,
|
||||
'error_message' => null,
|
||||
'attempted_at' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('sms_campaigns', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->text('message');
|
||||
$table->string('mode');
|
||||
$table->unsignedInteger('recipient_count')->default(0);
|
||||
$table->unsignedInteger('sent_count')->default(0);
|
||||
$table->unsignedInteger('failed_count')->default(0);
|
||||
$table->unsignedInteger('skipped_count')->default(0);
|
||||
$table->string('laravel_batch_id')->nullable();
|
||||
$table->foreignId('created_by')->constrained('users')->cascadeOnDelete();
|
||||
$table->timestamp('completed_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('sms_campaigns');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('sms_send_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('sms_campaign_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('coupon_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->string('phone');
|
||||
$table->text('message');
|
||||
$table->string('status');
|
||||
$table->text('error_message')->nullable();
|
||||
$table->timestamp('attempted_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['sms_campaign_id', 'status']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('sms_send_logs');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user