fix bug of pargar
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user