Files
boursecu_server/app/Services/AccountingWalletPush.php
T

64 lines
1.8 KiB
PHP

<?php
namespace App\Services;
use App\Http\Controllers\Admin\TahesabController;
use App\Http\Controllers\Admin\ZarinController;
use App\Models\Customer;
use App\Models\Product;
/**
* ارسال سند کیف محصول به ته‌حساب/زرین (بدون پرگار).
*/
class AccountingWalletPush
{
public function pushProductWalletGold(
Customer $customer,
Product $product,
float $value,
bool $isDeposit,
?int $withdrawId = null,
?string $note = null
): void {
$mapper = app(AccountingProductDocMapper::class);
if ($mapper->shouldSkip($product)) {
return;
}
$config = app(ConfigService::class);
$payload = [
'customer_id' => $customer->id,
'value' => abs($value),
'direction' => $isDeposit ? 1 : 0,
'withdraw_id' => $withdrawId,
'note' => $note,
'product_id' => (int) $product->id,
'product' => [
'id' => $product->id,
'title' => $product->title,
'group_type' => $product->group_type,
'metal_id' => $product->metal_id,
'amount' => $product->amount,
'unit' => $product->unit,
'trade_by_quantity' => $product->trade_by_quantity,
],
];
if ($config->isTahesabAccounting()) {
try {
app(TahesabController::class)->walletGold($payload);
} catch (\Throwable $e) {
report($e);
}
}
if ($config->isZarinAccounting()) {
try {
app(ZarinController::class)->walletGold($payload);
} catch (\Throwable $e) {
report($e);
}
}
}
}