handle some performance for app
This commit is contained in:
@@ -262,6 +262,47 @@ class Controller extends BaseController
|
||||
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)
|
||||
{
|
||||
$counter = Cnt::where('key', 'jibit_counter')->first();
|
||||
|
||||
Reference in New Issue
Block a user