Add SMS bulk delay configuration and validate coupon phone function
This commit is contained in:
66
app/Models/SmsCampaign.php
Normal file
66
app/Models/SmsCampaign.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\SmsCampaignFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class SmsCampaign extends Model
|
||||
{
|
||||
/** @use HasFactory<SmsCampaignFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'message',
|
||||
'mode',
|
||||
'recipient_count',
|
||||
'sent_count',
|
||||
'failed_count',
|
||||
'skipped_count',
|
||||
'laravel_batch_id',
|
||||
'created_by',
|
||||
'completed_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'completed_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
public function sendLogs(): HasMany
|
||||
{
|
||||
return $this->hasMany(SmsSendLog::class);
|
||||
}
|
||||
|
||||
public function isComplete(): bool
|
||||
{
|
||||
return $this->completed_at !== null;
|
||||
}
|
||||
|
||||
public function processedCount(): int
|
||||
{
|
||||
return $this->sent_count + $this->failed_count + $this->skipped_count;
|
||||
}
|
||||
|
||||
public function progressPercent(): int
|
||||
{
|
||||
if ($this->recipient_count === 0) {
|
||||
return 100;
|
||||
}
|
||||
|
||||
return (int) min(100, round(($this->processedCount() / $this->recipient_count) * 100));
|
||||
}
|
||||
}
|
||||
46
app/Models/SmsSendLog.php
Normal file
46
app/Models/SmsSendLog.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\SmsSendStatus;
|
||||
use Database\Factories\SmsSendLogFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class SmsSendLog extends Model
|
||||
{
|
||||
/** @use HasFactory<SmsSendLogFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'sms_campaign_id',
|
||||
'coupon_id',
|
||||
'phone',
|
||||
'message',
|
||||
'status',
|
||||
'error_message',
|
||||
'attempted_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'status' => SmsSendStatus::class,
|
||||
'attempted_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function campaign(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(SmsCampaign::class, 'sms_campaign_id');
|
||||
}
|
||||
|
||||
public function coupon(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Coupon::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user