fix bug of pargar

This commit is contained in:
2026-07-26 14:15:26 +03:30
parent 667e3736fb
commit 06b3113b98
17 changed files with 561 additions and 26 deletions
@@ -142,6 +142,21 @@ class GiftCardController extends Controller
'withdraw_id' => $Withdraw->id,
'active' => true
], 3, false, true);
try {
app(\App\Services\PargarSyncService::class)->queueWalletDocument(
$user,
'cash',
(float) $giftcode->amount,
[
'withdraw_id' => $Withdraw->id,
'note' => 'کارت هدیه',
'source' => 'gift_card',
]
);
} catch (\Throwable $e) {
report($e);
}
}
//set text for sms to customer
@@ -666,6 +666,13 @@ class ProductController extends SuperController
unset($data['inventory']);
}
if (!Product::hasDescriptionColumn()) {
unset($data['description']);
} elseif (array_key_exists('description', $data)) {
$desc = is_string($data['description']) ? trim($data['description']) : '';
$data['description'] = $desc === '' ? null : $desc;
}
if (!Product::hasOverrideTradingHoursColumn()) {
unset($data['override_trading_hours']);
} elseif (array_key_exists('override_trading_hours', $data)) {
@@ -33,6 +33,40 @@ use Hekmatinasser\Verta\Verta;
class WalletController extends Controller
{
/** موجودی طلا با سه رقم اعشار نمایش داده می‌شود؛ نصف پلهٔ نمایش = بیشترین اختلاف ممکن با مقدار واقعی */
private const GOLD_DISPLAY_STEP = 0.0005;
/** پنجرهٔ تشخیص سند تکراری — دوبار کلیک یا ارسال مجدد فرم */
private const DUPLICATE_CHARGE_WINDOW_SECONDS = 60;
/**
* جلوگیری از ثبت دوبارهٔ همان سند دستی. فقط روی کسر اعمال می‌شود تا شارژهای
* مثبتِ پشت‌سرهم (مثلاً دو واریز یکسان) بسته نشوند.
*/
private function assertNotDuplicateCharge(int $customerId, float $value, string $column): void
{
if ($value >= 0) {
return;
}
$recent = Withdraw::query()
->where('customer_id', $customerId)
->where('sts', 4)
->where('created_at', '>=', now()->subSeconds(self::DUPLICATE_CHARGE_WINDOW_SECONDS));
if ($column === 'cash') {
$recent->where('cash', (int) $value);
} else {
$recent->whereBetween('gold', [$value - 1e-6, $value + 1e-6]);
}
if ($recent->exists()) {
throw new UnprocessableEntityHttpException(
'همین سند لحظاتی پیش برای این مشتری ثبت شده است. اگر تکرارش عمدی است یک دقیقه صبر کنید.'
);
}
}
public function charge2(Request $request)
{
$data = $request->all();
@@ -121,6 +155,7 @@ class WalletController extends Controller
if (!is_null($wallet) && $wallet->cash < abs($data['value']) && !$deposit) {
throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست');
}
$this->assertNotDuplicateCharge((int) $customer->id, (float) $data['value'], 'cash');
$orders = Order::where('customer_id', $data['customer_id'])->where('sts', 1)->get();
$gold_block = 0;
@@ -213,12 +248,20 @@ class WalletController extends Controller
}
$wallet_interface = new WalletInterface($data['customer_id'], (int) $customer->type);
$wallet = $wallet_interface->wallet;
// if (is_null($wallet) && !$deposit) {
// throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست');
// }
// if (!is_null($wallet) && $wallet->cash < abs($data['value']) && !$deposit) {
// throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست');
// }
// کسر دستی نباید موجودی طلا را منفی کند؛ شارژ مثبت بدون هیچ شرطی باز است
if (!$deposit) {
$available = is_null($wallet) ? 0.0 : (float) $wallet->gold;
$requested = abs((float) $data['value']);
// ادمین عدد را از نمایش سه‌رقمی می‌خواند؛ اختلاف تا نصف پلهٔ نمایش یعنی «کل موجودی»
if ($requested > $available && $requested - $available <= self::GOLD_DISPLAY_STEP) {
$requested = $available;
$data['value'] = -$available;
}
if ($requested <= 0 || $requested > $available) {
throw new UnprocessableEntityHttpException('مقدار موجودی طلا کمتر از درخواست شماست');
}
}
$this->assertNotDuplicateCharge((int) $customer->id, (float) $data['value'], 'gold');
$gold_block = 0;
$user = auth()->user();
$customer = Customer::findOrFail($data["customer_id"]);
@@ -386,6 +429,7 @@ class WalletController extends Controller
if (!$deposit && $wallet !== null && (float) $wallet->gold < abs((float) $data['value'])) {
throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست');
}
$this->assertNotDuplicateCharge((int) $customer->id, (float) $data['value'], 'gold');
$goldBlock = 0;
$user = auth()->user();
@@ -391,6 +391,22 @@ class WalletController extends Controller
'withdraw_id' => $Withdraw->id,
'active' => true
], 4, false, false);
try {
app(\App\Services\PargarSyncService::class)->queueWalletDocument(
$customer,
'cash',
-1 * (float) $data['value'],
[
'withdraw_id' => $Withdraw->id,
'note' => 'برداشت ریالی',
'source' => 'customer_withdraw',
]
);
} catch (\Throwable $e) {
report($e);
}
$userMobile = $customer->mobile; // User's mobile number
$userName = $customer->name; // User's name
$withdrawAmount = $data['value']; // amount
@@ -195,6 +195,21 @@ class FinanceController extends Controller
'active' => true
], 3, false, true);
try {
app(\App\Services\PargarSyncService::class)->queueWalletDocument(
$User,
'cash',
(float) ($decodedResponse['data']['amount'] * 10),
[
'withdraw_id' => (int) $_GET['clientrefid'],
'note' => 'واریز درگاه',
'source' => 'gateway',
]
);
} catch (\Throwable $e) {
report($e);
}
//----------sms
// User information
$userMobile = $Withdraw->customer->mobile; // User's mobile number
@@ -1589,6 +1589,22 @@ class SingleOrderController extends Controller
'withdraw_id' => $Withdraw->id,
'active' => true,
], 3, true, true, 0);
try {
app(\App\Services\PargarSyncService::class)->queueWalletDocument(
$customer,
'cash',
(float) $customer_bonus,
[
'withdraw_id' => $Withdraw->id,
'note' => 'پاداش اولین سفارش',
'source' => 'bonus_first_order',
]
);
} catch (\Throwable $e) {
report($e);
}
$message = 'کیف پول شما به اندازه ' . number_format($customer_bonus) . ' ریال در تاریخ ' . verta()->format('Y/n/j H:i:s') . " شارژ شد بابت\n"
. 'پاداش اولین سفارش'
. ' '
@@ -1626,6 +1642,22 @@ class SingleOrderController extends Controller
'withdraw_id' => $Withdraw->id,
'active' => true,
], 3, true, true, 0);
try {
app(\App\Services\PargarSyncService::class)->queueWalletDocument(
$referrer,
'cash',
(float) $referrer_bonus,
[
'withdraw_id' => $Withdraw->id,
'note' => 'پاداش اولین سفارش زیرمجموعه',
'source' => 'bonus_referrer',
]
);
} catch (\Throwable $e) {
report($e);
}
$message = 'کیف پول شما به اندازه ' . number_format($referrer_bonus) . ' ریال در تاریخ ' . verta()->format('Y/n/j H:i:s') . " شارژ شد بابت\n"
. 'بابت پاداش اولین سفارش زیرمجموعه'
. ' '