fix some bugs 2
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class ConditionalOrder extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
public const STATUS_PENDING = 'pending';
|
||||
public const STATUS_EXECUTED = 'executed';
|
||||
public const STATUS_FAILED = 'failed';
|
||||
public const STATUS_EXPIRED = 'expired';
|
||||
|
||||
public const CONDITION_GTE = 'gte';
|
||||
public const CONDITION_LTE = 'lte';
|
||||
|
||||
protected $fillable = [
|
||||
'customer_id',
|
||||
'product_id',
|
||||
'direction',
|
||||
'price_condition',
|
||||
'trigger_price',
|
||||
'amount',
|
||||
'number',
|
||||
'expires_at',
|
||||
'description',
|
||||
'is_active',
|
||||
'status',
|
||||
'fail_reason',
|
||||
'order_id',
|
||||
'fee_charged',
|
||||
'triggered_price',
|
||||
'executed_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'direction' => 'integer',
|
||||
'trigger_price' => 'integer',
|
||||
'amount' => 'float',
|
||||
'number' => 'float',
|
||||
'fee_charged' => 'integer',
|
||||
'triggered_price' => 'integer',
|
||||
'expires_at' => 'datetime',
|
||||
'executed_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(Customer::class);
|
||||
}
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(Order::class);
|
||||
}
|
||||
|
||||
public function isPending(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_PENDING;
|
||||
}
|
||||
|
||||
public function conditionMet(int $currentPrice): bool
|
||||
{
|
||||
if ($currentPrice <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$target = (int) $this->trigger_price;
|
||||
|
||||
return match ($this->price_condition) {
|
||||
self::CONDITION_GTE => $currentPrice >= $target,
|
||||
self::CONDITION_LTE => $currentPrice <= $target,
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,8 @@ class Customer extends Authenticatable implements JWTSubject
|
||||
'is_archive',
|
||||
'gram',
|
||||
'trade_active',//آیا امکان معامله دارد؟
|
||||
'conditional_order_active',//آیا سفارش شرطی مجاز است؟
|
||||
'conditional_order_limit',//سقف تعداد pending (null = نامحدود)
|
||||
'type',
|
||||
'referral_id',
|
||||
'referral_to_id',
|
||||
@@ -69,6 +71,8 @@ class Customer extends Authenticatable implements JWTSubject
|
||||
"gold" => "float",
|
||||
"is_archive" => "boolean",
|
||||
"finger_print" => "boolean",
|
||||
"conditional_order_active" => "boolean",
|
||||
"conditional_order_limit" => "integer",
|
||||
];
|
||||
static $TYPE = [
|
||||
1=>'همکار',
|
||||
|
||||
Reference in New Issue
Block a user