2026-06-09 20:43:01 +03:30
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Rooyesh\Wallet\models\Transaction;
|
|
|
|
|
|
|
|
|
|
class Withdraw extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory, Selector;
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'customer_id',
|
|
|
|
|
'user_id',
|
|
|
|
|
'cash',
|
|
|
|
|
'gold',
|
|
|
|
|
'note',
|
2026-06-18 19:32:28 +03:30
|
|
|
'extra_note',
|
2026-06-09 20:43:01 +03:30
|
|
|
'tracked_number',
|
|
|
|
|
'bank_account_id',
|
|
|
|
|
'date_at',
|
|
|
|
|
'sts',
|
|
|
|
|
'type',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
static $STS = [
|
|
|
|
|
1 => 'در انتظار واریز',
|
|
|
|
|
2 => 'واریز شد',
|
|
|
|
|
4 => 'واریز توسط ادمین',
|
|
|
|
|
5 => 'پاداش معرفی',
|
|
|
|
|
9 => 'سود زیر مجموعه',
|
|
|
|
|
3 => 'واریز ناموفق',
|
|
|
|
|
50 => 'در انتظار ارسال',
|
|
|
|
|
51 => 'ارسال شده',
|
|
|
|
|
52 => 'لغو شده',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function customer()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo('App\Models\Customer')->select(['id', 'name', 'mobile']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function Address()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo('App\Models\Address');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function Transaction()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Transaction::class, 'withdraw_id', 'id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function bank_account()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasOne('App\Models\BankAccount', 'id', 'bank_account_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function applyFlowFilter($query, ?string $flowType = 'all')
|
|
|
|
|
{
|
|
|
|
|
if (!$flowType || $flowType === 'all') {
|
|
|
|
|
return $query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($flowType === 'withdraw') {
|
2026-06-09 21:01:01 +03:30
|
|
|
return static::scopeWithdrawals($query);
|
2026-06-09 20:43:01 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($flowType === 'deposit') {
|
2026-06-09 21:01:01 +03:30
|
|
|
return static::scopeDeposits($query);
|
2026-06-09 20:43:01 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
|
}
|
2026-06-09 21:01:01 +03:30
|
|
|
|
|
|
|
|
/** برداشت: خروج پول/طلا از کیف (درخواست مشتری، برداشت فیزیکی، کسر ادمین) */
|
|
|
|
|
public static function scopeWithdrawals($query)
|
|
|
|
|
{
|
|
|
|
|
return $query->where(function ($q) {
|
|
|
|
|
$q->where('note', 'like', '%برداشت%')
|
|
|
|
|
->orWhere('type', 2)
|
|
|
|
|
->orWhereBetween('sts', [50, 52])
|
|
|
|
|
->orWhere(function ($pending) {
|
|
|
|
|
$pending->where('sts', 1)
|
|
|
|
|
->whereNotNull('bank_account_id');
|
|
|
|
|
})
|
|
|
|
|
->orWhere(function ($completed) {
|
|
|
|
|
$completed->where('sts', 2)
|
|
|
|
|
->where('note', 'like', '%برداشت%');
|
|
|
|
|
})
|
|
|
|
|
->orWhere(function ($deduct) {
|
|
|
|
|
$deduct->where('cash', '<', 0);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** واریز: ورود پول/طلا به کیف (درگاه، شارژ ادمین، پاداش) */
|
|
|
|
|
public static function scopeDeposits($query)
|
|
|
|
|
{
|
|
|
|
|
return $query->where(function ($q) {
|
|
|
|
|
$q->where(function ($inner) {
|
|
|
|
|
$inner->where('note', 'like', '%واریز%')
|
|
|
|
|
->orWhere('type', 1)
|
|
|
|
|
->orWhereIn('sts', [4, 5, 9]);
|
|
|
|
|
})->where(function ($excludeWithdrawNotes) {
|
|
|
|
|
$excludeWithdrawNotes->whereNull('note')
|
|
|
|
|
->orWhere('note', 'not like', '%برداشت%');
|
|
|
|
|
})->whereNotBetween('sts', [50, 52]);
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-06-09 20:43:01 +03:30
|
|
|
}
|