fix some bug
This commit is contained in:
@@ -500,7 +500,13 @@ class WalletController extends Controller
|
||||
TableEngine::create($sumQuery, $request->all())
|
||||
->initSearch(['customer.name']);
|
||||
|
||||
$sumRows = (clone $sumQuery)->with('product:id,metal_id,unit,amount,group_type,trade_by_quantity,direct_price,title')->get();
|
||||
$walletTableWith = [
|
||||
'customer:id,name,mobile',
|
||||
'fund:id,title',
|
||||
'product:id,metal_id,unit,amount,group_type,trade_by_quantity,direct_price,title',
|
||||
];
|
||||
|
||||
$sumRows = (clone $sumQuery)->with($walletTableWith)->get();
|
||||
$metalBalances = $balanceService->buildWalletMetalSums($sumRows, $catalogMetalIds);
|
||||
$totalGold = array_sum(array_column($metalBalances, 'gold'));
|
||||
$totalGoldToCash = array_sum(array_column($metalBalances, 'goldToCash'));
|
||||
@@ -514,9 +520,9 @@ class WalletController extends Controller
|
||||
'metalBalances' => $metalBalances,
|
||||
];
|
||||
|
||||
$records = Wallet::with(['customer', 'product:id,metal_id,unit,amount,group_type,trade_by_quantity,direct_price,title']);
|
||||
$records = Wallet::with($walletTableWith);
|
||||
TableEngine::create($records, $request->all())
|
||||
->initSearch(['customer.name'])
|
||||
->initSearch(['customer.name', 'customer.mobile', 'product.title', 'fund.title'])
|
||||
->select(['*'])
|
||||
->export($records);
|
||||
|
||||
|
||||
@@ -234,9 +234,10 @@ class SingleOrderController extends Controller
|
||||
{
|
||||
|
||||
$response = [];
|
||||
$config = app(ConfigService::class);
|
||||
$feeFromGold = $config->feeDeductFromGold();
|
||||
$data['price'] += $data['difference'];
|
||||
$data['total_price'] = $data['amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
|
||||
$this->enforceProductOrderLimits($data, (float) $data['total_price']);
|
||||
|
||||
@@ -248,7 +249,12 @@ class SingleOrderController extends Controller
|
||||
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : $data['service_charge_percentage'] * $data['amount'];
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$data['amount'] -= $data['service_charge'];
|
||||
if ($feeFromGold) {
|
||||
$data['payment_amount'] = $data['total_price'] + $data['service_charge_price'];
|
||||
} else {
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$data['amount'] -= $data['service_charge'];
|
||||
}
|
||||
if ($wallet->cash < $data['payment_amount']) {
|
||||
throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است');
|
||||
}
|
||||
@@ -420,22 +426,30 @@ class SingleOrderController extends Controller
|
||||
private function processSellTransaction(&$data, $wallet, $wallet_interface)
|
||||
{
|
||||
$response = [];
|
||||
$config = app(ConfigService::class);
|
||||
$feeFromGold = $config->feeDeductFromGold();
|
||||
$data['price'] -= $data['difference'];
|
||||
$grossTotal = $data['amount'] * $data['price'];
|
||||
$this->enforceProductOrderLimits($data, (float) $grossTotal);
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : $data['service_charge_percentage'] * $data['amount'];
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$data['total_price'] = $data['amount'] * $data['price'] - $data['service_charge_price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$data['payment_amount'] -= $data['service_charge_price'];
|
||||
if ($wallet->gold < $data['amount']) {
|
||||
if ($feeFromGold) {
|
||||
$data['total_price'] = $data['amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$goldDebit = $data['amount'] + $data['service_charge'];
|
||||
} else {
|
||||
$data['total_price'] = $data['amount'] * $data['price'] - $data['service_charge_price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$goldDebit = $data['amount'];
|
||||
}
|
||||
if ($wallet->gold < $goldDebit) {
|
||||
throw new UnprocessableEntityHttpException($this->insufficientGoldBalanceMessage($data));
|
||||
}
|
||||
$data['order'] = $order = Order::create($data);
|
||||
$abshode = $this->resolveAbshodeProductContext($data);
|
||||
$productId = (int) ($data['product_id'] ?? $abshode['id'] ?? 0);
|
||||
$sellTransaction = [
|
||||
"gold" => $data['amount'],
|
||||
"gold" => $goldDebit,
|
||||
"cash" => $data['total_price'],
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
|
||||
Reference in New Issue
Block a user