fix(zarin): post rial deposits without gold conversion and restore shop-side trade korf
Wallet docs were sending mazaneh as fi so Zarin turned cash deposits into خرید فی rows; customer buy/sell used the inverted korf mapping. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1840,6 +1840,36 @@ class ZarinController extends Controller
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* جهت سند معامله در زرین — از دید فروشگاه (نه مشتری).
|
||||
* korf=k در عمل «خرید فی» میسازد: طلا بد + ریال بس (خرید فروشگاه از مشتری).
|
||||
* خرید مشتری = فروش فروشگاه → f / parDar −1 : طلا بس + ریال بد
|
||||
* فروش مشتری = خرید فروشگاه → k / parDar +1 : طلا بد + ریال بس
|
||||
*
|
||||
* @return array{korf: string, parDar: int}
|
||||
*/
|
||||
private function zarinShopSidesForCustomerTrade(bool $customerBuys): array
|
||||
{
|
||||
return $customerBuys
|
||||
? ['korf' => 'f', 'parDar' => -1]
|
||||
: ['korf' => 'k', 'parDar' => 1];
|
||||
}
|
||||
|
||||
/** شرح سند ریالی زرین — همیشه با واریز/برداشت شروع شود تا «خرید فی» دیده نشود */
|
||||
private function zarinRialWalletSharh(bool $isDeposit, ?string $note): string
|
||||
{
|
||||
$base = $isDeposit ? 'واریز' : 'برداشت';
|
||||
$normalized = self::accountingWalletDesc($isDeposit, $note);
|
||||
if ($normalized === '' || $normalized === $base) {
|
||||
return $base;
|
||||
}
|
||||
if (str_starts_with($normalized, $base)) {
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
return $base . ' — ' . $normalized;
|
||||
}
|
||||
|
||||
public function storeTrade($data, ?Zarin $existing = null)
|
||||
{
|
||||
if (empty($data['customer_id']) && $existing && $existing->order_id) {
|
||||
@@ -1901,9 +1931,7 @@ class ZarinController extends Controller
|
||||
$count = $mapper->accountingQty($product, $rawAmount, $data);
|
||||
$vazn = $mapper->accountingWeight($product, $rawAmount, $data);
|
||||
$isBuy = (int) ($data['direction'] ?? 0) === 1;
|
||||
// زرین korf/parDar از دید حساب مشتری است، نه فروشگاه:
|
||||
// خرید مشتری → k / +1 : طلا بستانکار (سوت اضافه) + ریال بدهکار (پول کم)
|
||||
// فروش مشتری → f / −1 : طلا بدهکار + ریال بستانکار
|
||||
$sides = $this->zarinShopSidesForCustomerTrade($isBuy);
|
||||
$orderId = is_object($data['order'] ?? null)
|
||||
? ($data['order']->id ?? null)
|
||||
: ($data['order']['id'] ?? ($existing->order_id ?? null));
|
||||
@@ -1962,7 +1990,7 @@ class ZarinController extends Controller
|
||||
$accountCustomer,
|
||||
$product,
|
||||
$count,
|
||||
$isBuy ? 1 : -1,
|
||||
$sides['parDar'],
|
||||
$fi,
|
||||
$sharh,
|
||||
$this->zarinUid($uidKind, $uidSource ?? $zarin->id)
|
||||
@@ -1973,7 +2001,7 @@ class ZarinController extends Controller
|
||||
$data,
|
||||
$accountCustomer,
|
||||
$vazn,
|
||||
$isBuy ? 'k' : 'f',
|
||||
$sides['korf'],
|
||||
(float) ($data['price'] ?? 0),
|
||||
$sharh,
|
||||
$mapper->jensFelez($product) ?? 0,
|
||||
@@ -2019,7 +2047,7 @@ class ZarinController extends Controller
|
||||
|
||||
$data['handler'] = 'wallet';
|
||||
$isDeposit = (int) ($data['direction'] ?? 0) === 0;
|
||||
$sharh = self::accountingWalletDesc($isDeposit, $data['note'] ?? null);
|
||||
$sharh = $this->zarinRialWalletSharh($isDeposit, $data['note'] ?? null);
|
||||
$zarin = $existing ?? Zarin::create([
|
||||
'customer_id' => $customer->id,
|
||||
'desc' => $sharh,
|
||||
@@ -2035,26 +2063,21 @@ class ZarinController extends Controller
|
||||
$existing->update(['data' => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)]);
|
||||
}
|
||||
|
||||
$prices = $this->lastPriceData();
|
||||
$isWithdraw = (int) ($data['direction'] ?? 0) === 1;
|
||||
$mazaneh = $isWithdraw ? (int) ($prices['sell'] ?? 0) : (int) ($prices['buy'] ?? 0);
|
||||
if ($mazaneh <= 0) {
|
||||
$mazaneh = 1;
|
||||
}
|
||||
|
||||
$uidSource = $data['withdraw_id'] ?? $zarin->id;
|
||||
|
||||
try {
|
||||
// سند ریالی خالص: فی/مظنه نفرست — وگرنه زرین همان مبلغ را به گرم طلا تبدیل میکند («خرید فی»).
|
||||
$http = $this->zarinRequest([
|
||||
'kind' => 'pooli',
|
||||
'radif' => 1,
|
||||
'korf' => $isWithdraw ? 'f' : 'k',
|
||||
'poolorvazn' => 'pool',
|
||||
'meghdar' => $data['value'],
|
||||
'fi' => $mazaneh,
|
||||
'fi' => '',
|
||||
'hesab' => $customer->moshtari_code,
|
||||
'sharh' => $sharh,
|
||||
'ayar' => '750',
|
||||
'ayar' => '',
|
||||
'movaghat' => '',
|
||||
'idFactor' => '',
|
||||
'uid' => $this->zarinUid('20', $uidSource),
|
||||
|
||||
Reference in New Issue
Block a user