handle some performance for app
This commit is contained in:
@@ -262,6 +262,47 @@ class Controller extends BaseController
|
|||||||
return 'برداشت ' . self::meltedGoldLabel();
|
return 'برداشت ' . self::meltedGoldLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function isCountBasedProduct(?array $product): bool
|
||||||
|
{
|
||||||
|
if (!$product) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($product['direct_price']) && (int) $product['direct_price'] !== 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$group = trim((string) ($product['group_type'] ?? ''));
|
||||||
|
if (in_array($group, ['مفتول مس', 'کاتد مس'], true)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return in_array($group, ['سکه', 'گوی', 'مکعب', 'شمش', 'سکه پارسیان'], true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function productQuantityUnit(?array $product): string
|
||||||
|
{
|
||||||
|
if (self::isCountBasedProduct($product)) {
|
||||||
|
return 'عدد';
|
||||||
|
}
|
||||||
|
|
||||||
|
$unit = trim((string) ($product['unit'] ?? ''));
|
||||||
|
|
||||||
|
return $unit !== '' ? $unit : 'گرم';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** مطابق ادمین: وزن «دارد» => amount != 1 ؛ «ندارد» => amount = 1 */
|
||||||
|
public static function hasProductUnitWeight(?array $product): bool
|
||||||
|
{
|
||||||
|
if (!$product || !isset($product['amount'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$amount = (float) $product['amount'];
|
||||||
|
|
||||||
|
return $amount > 0 && $amount !== 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
public static function jibit($method, $p1 = null, $p2 = null, $p3 = null)
|
public static function jibit($method, $p1 = null, $p2 = null, $p3 = null)
|
||||||
{
|
{
|
||||||
$counter = Cnt::where('key', 'jibit_counter')->first();
|
$counter = Cnt::where('key', 'jibit_counter')->first();
|
||||||
|
|||||||
@@ -39,7 +39,15 @@ class ProductController extends SuperController
|
|||||||
}])->get();
|
}])->get();
|
||||||
|
|
||||||
// Prepare the response
|
// Prepare the response
|
||||||
$user['rows'] = $products;
|
$user['rows'] = $products->map(function ($product) {
|
||||||
|
$product->unit = self::productQuantityUnit([
|
||||||
|
'unit' => $product->unit ?? null,
|
||||||
|
'direct_price' => $product->direct_price ?? null,
|
||||||
|
'group_type' => $product->group_type ?? null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $product;
|
||||||
|
});
|
||||||
|
|
||||||
return response()->json($user);
|
return response()->json($user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ class WalletController extends Controller
|
|||||||
$this->applyMetalTypeTransactionTitle($record);
|
$this->applyMetalTypeTransactionTitle($record);
|
||||||
$this->applyProductTransactionTitle($record);
|
$this->applyProductTransactionTitle($record);
|
||||||
$this->applyProductOrderDisplayFields($record);
|
$this->applyProductOrderDisplayFields($record);
|
||||||
|
$this->applyProductTransactionUnit($record);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json($records);
|
return response()->json($records);
|
||||||
@@ -454,10 +455,28 @@ class WalletController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($record->wallet?->product)) {
|
if (!empty($record->wallet?->product)) {
|
||||||
$record->unit = $record->wallet->product->unit ?: 'عدد';
|
$record->unit = self::productQuantityUnit([
|
||||||
|
'unit' => $record->wallet->product->unit ?? null,
|
||||||
|
'direct_price' => $record->wallet->product->direct_price ?? null,
|
||||||
|
'group_type' => $record->wallet->product->group_type ?? null,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function applyProductTransactionUnit($record): void
|
||||||
|
{
|
||||||
|
$product = $record->wallet->product ?? $record->product ?? null;
|
||||||
|
if (!$product) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$record->unit = self::productQuantityUnit([
|
||||||
|
'unit' => $product->unit ?? null,
|
||||||
|
'direct_price' => $product->direct_price ?? null,
|
||||||
|
'group_type' => $product->group_type ?? null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
private function isProductWalletTransaction($record): bool
|
private function isProductWalletTransaction($record): bool
|
||||||
{
|
{
|
||||||
return !empty($record->wallet?->product);
|
return !empty($record->wallet?->product);
|
||||||
|
|||||||
@@ -74,6 +74,11 @@ class ReportController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function upDownPrice()
|
public function upDownPrice()
|
||||||
|
{
|
||||||
|
return $this->buildUpDownPrices();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildUpDownPrices(): array
|
||||||
{
|
{
|
||||||
$feeSettings = Setting::whereIn('key', ['fee_single', 'buy_fee', 'sell_fee'])
|
$feeSettings = Setting::whereIn('key', ['fee_single', 'buy_fee', 'sell_fee'])
|
||||||
->pluck('value', 'key');
|
->pluck('value', 'key');
|
||||||
@@ -121,6 +126,13 @@ class ReportController extends Controller
|
|||||||
return ['sell' => $minP - $diffSell, 'buy' => $maxP + $diffBuy];
|
return ['sell' => $minP - $diffSell, 'buy' => $maxP + $diffBuy];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function appendUpPrices(array $payload): array
|
||||||
|
{
|
||||||
|
$payload['up'] = $this->buildUpDownPrices();
|
||||||
|
|
||||||
|
return $payload;
|
||||||
|
}
|
||||||
|
|
||||||
public function lastPrice()
|
public function lastPrice()
|
||||||
{
|
{
|
||||||
$config = app(ConfigService::class);
|
$config = app(ConfigService::class);
|
||||||
@@ -145,7 +157,7 @@ class ReportController extends Controller
|
|||||||
};
|
};
|
||||||
|
|
||||||
$zeroResponse = function () {
|
$zeroResponse = function () {
|
||||||
return [
|
return $this->appendUpPrices([
|
||||||
'sell' => 0,
|
'sell' => 0,
|
||||||
'buy' => 0,
|
'buy' => 0,
|
||||||
'price_last' => 0,
|
'price_last' => 0,
|
||||||
@@ -155,7 +167,7 @@ class ReportController extends Controller
|
|||||||
'montzar' => 0,
|
'montzar' => 0,
|
||||||
'closed' => true,
|
'closed' => true,
|
||||||
'time' => now(),
|
'time' => now(),
|
||||||
];
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -356,7 +368,7 @@ class ReportController extends Controller
|
|||||||
|
|
||||||
if ($priceValue <= 0) {
|
if ($priceValue <= 0) {
|
||||||
if (!$show_last_price) {
|
if (!$show_last_price) {
|
||||||
return [
|
return $this->appendUpPrices([
|
||||||
'sell' => 0,
|
'sell' => 0,
|
||||||
'buy' => 0,
|
'buy' => 0,
|
||||||
'price_last' => 0,
|
'price_last' => 0,
|
||||||
@@ -366,13 +378,13 @@ class ReportController extends Controller
|
|||||||
'montzar' => $montzar_price ?? 0,
|
'montzar' => $montzar_price ?? 0,
|
||||||
'closed' => true,
|
'closed' => true,
|
||||||
'time' => now(),
|
'time' => now(),
|
||||||
];
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$lastPrice = Price::latest()->first();
|
$lastPrice = Price::latest()->first();
|
||||||
|
|
||||||
if (!$lastPrice || (float) $lastPrice->price <= 0) {
|
if (!$lastPrice || (float) $lastPrice->price <= 0) {
|
||||||
return [
|
return $this->appendUpPrices([
|
||||||
'sell' => 0,
|
'sell' => 0,
|
||||||
'buy' => 0,
|
'buy' => 0,
|
||||||
'price_last' => 0,
|
'price_last' => 0,
|
||||||
@@ -382,7 +394,7 @@ class ReportController extends Controller
|
|||||||
'montzar' => $montzar_price ?? 0,
|
'montzar' => $montzar_price ?? 0,
|
||||||
'closed' => true,
|
'closed' => true,
|
||||||
'time' => now(),
|
'time' => now(),
|
||||||
];
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$priceValue = (float) $lastPrice->price;
|
$priceValue = (float) $lastPrice->price;
|
||||||
@@ -468,7 +480,7 @@ class ReportController extends Controller
|
|||||||
$config->trackDailyPriceExtreme((float) $priceValue);
|
$config->trackDailyPriceExtreme((float) $priceValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return $this->appendUpPrices([
|
||||||
'sell' => $sell,
|
'sell' => $sell,
|
||||||
'buy' => $buy,
|
'buy' => $buy,
|
||||||
'price_last' => $priceLast,
|
'price_last' => $priceLast,
|
||||||
@@ -478,7 +490,7 @@ class ReportController extends Controller
|
|||||||
'montzar' => $montzar_price ?? 0,
|
'montzar' => $montzar_price ?? 0,
|
||||||
'closed' => false,
|
'closed' => false,
|
||||||
'time' => now(),
|
'time' => now(),
|
||||||
];
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function check()
|
public function check()
|
||||||
|
|||||||
Reference in New Issue
Block a user