add rahyab notification service

This commit is contained in:
ehsan.moradi
2025-05-01 17:18:14 +03:30
parent 6d108e43c9
commit b573d1bbed
19 changed files with 1112 additions and 2 deletions
+84
View File
@@ -0,0 +1,84 @@
<?php
namespace App\Models;
use App\Exceptions\FieldNotExistsException;
// use App\Scopes\OrderByIdScope;
use Illuminate\Support\Arr;
trait BasicModel
{
private int $pageSizeLimit = 48;
protected static function boot()
{
parent::boot();
// if (! app()->runningInConsole()) {
// static::addGlobalScope( new OrderByIdScope );
// }
}
public function getPerPage()
{
$pageSize = (int) request( 'per_page' , $this->perPage );
return min( $pageSize , $this->pageSizeLimit );
}
public function attributeExists( $attr ): bool
{
return array_key_exists( $attr , $this->attributes );
}
public function getField( $name )
{
$columnName = static::getColumn( $name );
return $this->$columnName;
}
public function setField( $name , $value ): void
{
$columnName = static::getColumn( $name );
$this->$columnName = $value;
}
public static function getColumnTable( $name ): string
{
return static::getTableName() . '.' . static::getColumn( $name );
}
public static function getColumn( $name )
{
$fieldName = Arr::get( static::$maps , $name );
if ( is_null( $fieldName ) ) {
throw new FieldNotExistsException( "field $name not exists" );
}
return $fieldName;
}
public function getTable()
{
return static::getTableName();
}
public function fieldValue( $name )
{
return $this->$name;
}
public function getAttributes()
{
return $this->attributes;
}
public function isLoaded( $relationName ): bool
{
return isset( $this->relations[ $relationName ] ) and $this->$relationName != null;
}
abstract public static function getTableName();
}
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
class Sms extends Model
{
use BasicModel;
protected $fillable = [
'client_id' , 'status_code' , 'status' , 'message' , 'rel_id' , 'rel_type' , 'cell_number' , 'segment_count' ,
];
protected $hidden = [];
public static function getTableName(): string
{
return "sms";
}
public function receiver(): MorphTo
{
return $this->morphTo( null , 'rel_type' , 'rel_id' );
}
public function smsBatch(): BelongsTo
{
return $this->belongsTo( SmsBatch::class );
}
}
+40
View File
@@ -0,0 +1,40 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
class SmsBatch extends Model
{
use SoftDeletes , BasicModel;
protected $fillable = [
'category' , 'operator' , 'code' , 'fee' , 'type' , 'business_id' , 'is_admin' , 'is_systematic' , 'pattern' , 'from'
];
protected $hidden = [];
public static function getTableName(): string
{
return "sms_batch";
}
public function smsList(): HasMany
{
return $this->hasMany( Sms::class );
}
public function scopeSingle( $query )
{
return $query->whereCategory( 'single' );
}
public function scopeBatch( $query )
{
return $query->whereCategory( 'batch' );
}
}