change copperConvertPage
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\CopperConvertRequestService;
|
||||
|
||||
class CopperConvertRequestController extends Controller
|
||||
{
|
||||
public function index(CopperConvertRequestService $service)
|
||||
{
|
||||
return response()->json($service->listForAdmin());
|
||||
}
|
||||
|
||||
public function approve(int $id, CopperConvertRequestService $service)
|
||||
{
|
||||
$row = $service->approve($id, (int) auth('user')->id());
|
||||
|
||||
return response()->json($row);
|
||||
}
|
||||
|
||||
public function reject(int $id, CopperConvertRequestService $service)
|
||||
{
|
||||
$row = $service->reject($id, (int) auth('user')->id());
|
||||
|
||||
return response()->json($row);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Customer;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Customer;
|
||||
use App\Services\CopperConvertRequestService;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
|
||||
class CopperConvertRequestController extends Controller
|
||||
{
|
||||
public function store(Request $request, CopperConvertRequestService $service)
|
||||
{
|
||||
$customer = auth('customer')->user();
|
||||
if (!$customer instanceof Customer) {
|
||||
throw new UnprocessableEntityHttpException('مشتری یافت نشد.');
|
||||
}
|
||||
self::assertCustomerIdentityVerified($customer);
|
||||
if (!$customer->trade_active) {
|
||||
throw new UnprocessableEntityHttpException('امکان سفارش برای شما غیرفعال است.');
|
||||
}
|
||||
|
||||
$source = (string) $request->input('source');
|
||||
if (!in_array($source, ['katod', 'maftoul', 'shamsh'], true)) {
|
||||
throw new UnprocessableEntityHttpException('نوع دارایی نامعتبر است.');
|
||||
}
|
||||
|
||||
$row = $service->submit(
|
||||
$customer,
|
||||
$source,
|
||||
max(0, (int) $request->input('rings15')),
|
||||
max(0, (int) $request->input('rings25'))
|
||||
);
|
||||
|
||||
return response()->json($row);
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,9 @@ class SingleOrderController extends Controller
|
||||
|
||||
// Check if the user wants to transact with a product or non-product (gold)
|
||||
if (isset($data['product_id']) and $data['product'] = Product::find($data['product_id'])) {
|
||||
$config->assertProductTradingOpen($data['product']);
|
||||
if (empty($data['quote_unit_price'])) {
|
||||
$config->assertProductTradingOpen($data['product']);
|
||||
}
|
||||
|
||||
// Check if the user wants to buy
|
||||
if ($data['direction'] == 1) {
|
||||
@@ -353,6 +355,7 @@ class SingleOrderController extends Controller
|
||||
$data['total_price'] = $data['amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'] + $data['service_charge_price'];
|
||||
$data['fee_asset'] = 'rial';
|
||||
$this->applyConvertQuote($data);
|
||||
|
||||
$this->enforceProductOrderLimits($data, (float) $data['total_price']);
|
||||
|
||||
@@ -366,7 +369,7 @@ class SingleOrderController extends Controller
|
||||
if ($wallet->cash < $data['payment_amount']) {
|
||||
throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است');
|
||||
}
|
||||
if (!$data['product']['open_buy']) {
|
||||
if (empty($data['quote_unit_price']) && !$data['product']['open_buy']) {
|
||||
throw new UnprocessableEntityHttpException('خرید این محصول در این لحظه مقدور نمیباشد');
|
||||
}
|
||||
$this->syncOrderProfitFields($data);
|
||||
@@ -647,6 +650,7 @@ class SingleOrderController extends Controller
|
||||
$data['total_price'] = $data['amount'] * $data['price'] - $data['service_charge_price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$data['fee_asset'] = 'rial';
|
||||
$this->applyConvertQuote($data);
|
||||
if ($data['total_price'] < 0) {
|
||||
throw new UnprocessableEntityHttpException(
|
||||
'مبلغ دریافتی فروش پس از کارمزد منفی شد. درصد کارمزد سفارش را بررسی کنید (باید اعشاری باشد؛ مثلاً ۰٫۰۱ برای ۱٪).'
|
||||
@@ -659,7 +663,7 @@ class SingleOrderController extends Controller
|
||||
if ($wallet_interface_product->wallet->gold < $data['number']) {
|
||||
throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است');
|
||||
}
|
||||
if (!$data['product']['open_sell']) {
|
||||
if (empty($data['quote_unit_price']) && !$data['product']['open_sell']) {
|
||||
throw new UnprocessableEntityHttpException('فروش این محصول در این لحظه مقدور نمیباشد');
|
||||
}
|
||||
$this->syncOrderProfitFields($data);
|
||||
@@ -1403,6 +1407,32 @@ class SingleOrderController extends Controller
|
||||
* اگر قیمت واحد سفارش حدود قیمت مثقال باشد، به قیمت هر گرم برگردان.
|
||||
* جلوگیری از ۱۰ میلیون تومان → ۱۰۵ سوت وقتی مثقال در فیلد «هر گرم» نشسته.
|
||||
*/
|
||||
/** قیمت قفلشدهٔ تبدیل: تعداد × قیمت واحد، بدون کارمزد و بدون ضرب در وزن واحد. */
|
||||
private function applyConvertQuote(array &$data): void
|
||||
{
|
||||
$quote = (float) ($data['quote_unit_price'] ?? 0);
|
||||
if ($quote <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$number = (float) ($data['number'] ?? 0);
|
||||
$data['amount'] = $number;
|
||||
$data['price'] = $quote;
|
||||
$data['price_original'] = $quote;
|
||||
$data['difference'] = 0;
|
||||
$data['fee'] = 0;
|
||||
$data['total_fee'] = 0;
|
||||
$data['service_charge'] = 0;
|
||||
$data['service_charge_price'] = 0;
|
||||
$data['service_charge_percentage'] = 0;
|
||||
$data['total_amount'] = $number;
|
||||
$data['total_price'] = $number * $quote;
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$data['fee_asset'] = 'rial';
|
||||
$data['fee_free'] = true;
|
||||
$data['first_buy'] = false;
|
||||
}
|
||||
|
||||
private function ensureOrderUnitPriceIsPerGram(array &$data): void
|
||||
{
|
||||
$live = $this->liveGramQuoteRial();
|
||||
|
||||
Reference in New Issue
Block a user