Wire outbound Invoice/Document sync after confirmed ops, store sync status with timeout lock, and keep SQL credentials out of frontend responses. Co-authored-by: Cursor <cursoragent@cursor.com>
72 lines
2.0 KiB
PHP
72 lines
2.0 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);
|
|
}
|
|
}
|
|
|
|
if ($config->isShayeganAccounting()) {
|
|
try {
|
|
app(\App\Http\Controllers\Admin\ShayeganController::class)->walletGold($payload);
|
|
} catch (\Throwable $e) {
|
|
report($e);
|
|
}
|
|
}
|
|
}
|
|
}
|