added tahesab options 3

This commit is contained in:
2026-06-25 23:06:29 +03:30
parent 1f93408c7b
commit 44733aabdb
2 changed files with 76 additions and 0 deletions
@@ -9,6 +9,8 @@ use App\Models\Price;
use App\Models\TransactionsAdmin;
use App\Models\User;
use App\Models\Withdraw;
use App\Models\Tahesab;
use App\Services\TahesabSyncService;
use App\DB\Te\TableEngine;
use Illuminate\Http\Request;
@@ -27,6 +29,41 @@ class FinanceController extends Controller
->initSearch(['price'])
->select(['*'])
->export($transactions_admins);
if (isset($transactions_admins['rows']) && is_array($transactions_admins['rows']) && $this->Config('send_to_tahesab') === 'true') {
$withdrawIds = collect($transactions_admins['rows'])
->pluck('withdraw_id')
->filter()
->unique()
->values()
->all();
if ($withdrawIds !== []) {
$tahesabByWithdraw = Tahesab::query()
->whereIn('withdraw_id', $withdrawIds)
->orderByDesc('id')
->get()
->unique('withdraw_id')
->keyBy('withdraw_id');
foreach ($transactions_admins['rows'] as &$row) {
$tahesab = $tahesabByWithdraw->get($row['withdraw_id'] ?? null);
if (! $tahesab) {
continue;
}
$row['tahesab_record_id'] = $tahesab->id;
$row['tahesab_sync_status'] = $tahesab->sync_status
?? (empty($tahesab->tahesab_id) ? TahesabSyncService::STATUS_PENDING : TahesabSyncService::STATUS_SUCCESS);
if (empty($tahesab->tahesab_id) || $row['tahesab_sync_status'] === TahesabSyncService::STATUS_FAILED) {
$row['tahesab_failed_id'] = $tahesab->id;
}
}
unset($row);
}
}
return response()->json($transactions_admins);
}
public function index()