etehadie removed

This commit is contained in:
2026-06-04 14:19:54 +03:30
parent a643ba58b7
commit f9c5ca109d
13 changed files with 134 additions and 76 deletions
@@ -11,7 +11,6 @@ use App\Models\Product;
use App\Models\TransactionsAdmin;
use App\Models\Withdraw;
use App\Services\ConfigService;
use App\Services\EtehadiePriceService;
use Carbon\Carbon;
use Hekmatinasser\Verta\Verta;
use Illuminate\Http\Request;
@@ -87,13 +86,14 @@ class DashboardController extends Controller
$gramPrice = (int) ($tallaPrice->price ?? 0);
$FPrices = [];
if (app(ConfigService::class)->usesEtehadiePricing()) {
$etehadie = app(EtehadiePriceService::class)->fetchMainGramPrice();
if (($etehadie['price'] ?? 0) > 0) {
$gramPrice = (int) round($etehadie['price'] / 10);
$mainProductId = app(ConfigService::class)->mainProductId();
if ($mainProductId) {
$mainProduct = Product::find($mainProductId);
if ($mainProduct) {
$gramPrice = (int) ($mainProduct->price + ($mainProduct->price_profit ?? 0));
$FPrices[] = [
'id' => 'etehadie',
'name' => 'اتحادیه',
'id' => 'main_product',
'name' => $mainProduct->title ?? 'محصول اصلی',
'price' => $gramPrice,
'profit' => 0,
];
@@ -170,7 +170,7 @@ class ProductController extends SuperController
// }catch (\Exception $e){}
$config = app(ConfigService::class);
$mainProductId = Cnt::where('key', 'main_product')->value('value');
$mainProductId = app(ConfigService::class)->mainProductId();
$hasExtremeKeys = Setting::whereIn('key', ['up_price', 'down_price'])->count() === 2;
$products = Product::with([])->whereNotNull('reading_method')->get();
foreach ($products as $product) {
@@ -10,7 +10,10 @@ use Illuminate\Support\Facades\Artisan;
class SettingsController extends Controller
{
public function index(){
$Setting = Setting::where('can_edit',1)->select('id','title_fa', 'key','value','description','is_active','type')->get();
$Setting = Setting::where('can_edit', 1)
->select(Setting::adminSelectColumns())
->get();
return response()->json($Setting);
}
public function edit(Request $request)
@@ -19,23 +22,25 @@ class SettingsController extends Controller
$setting = Setting::where('key', $request->key)->first();
if ($setting) {
// Update the existing setting
$setting->value = $request->value;
$setting->description = $request->description;
$setting->is_active = $request->is_active;
$setting->type = $request->type??'';
$setting->title_fa = $request->title_fa??'';
$setting->title_fa = $request->title_fa ?? '';
if (Setting::hasTypeColumn()) {
$setting->type = $request->type ?? '';
}
$setting->save();
} else {
// Create a new setting
$setting = new Setting();
$setting->key = $request->key;
$setting->type = $request->type??$request->type??'';
$setting->title_fa = $request->title_fa??$setting->title_fa??'';
$setting->title_fa = $request->title_fa ?? '';
$setting->value = $request->value;
$setting->description = $request->description;
$setting->is_active = $request->is_active;
$setting->can_edit = 1;
if (Setting::hasTypeColumn()) {
$setting->type = $request->type ?? '';
}
$setting->save();
}
@@ -149,7 +149,7 @@ class SingleOrderController extends Controller
} else {
// Calculate total price and fee for non-product (gold) transaction
$data['total_price_original'] = $data['amount'] * ($data['price_original'] ?? 0);
$mainProductId = Cnt::where('key', 'main_product')->value('value');
$mainProductId = app(\App\Services\ConfigService::class)->mainProductId();
$productId = $data['abshode_id'] ?? $data['product_id'] ?? $mainProductId;
$data['product'] = $productId ? Product::find($productId) : null;
if (!$data['product']) {
+12 -39
View File
@@ -10,7 +10,6 @@ use App\Models\Setting;
use App\Models\ConfigStatic;
use App\Models\Customer;
use App\Services\MontzarService;
use App\Services\EtehadiePriceService;
use App\Models\Price;
use App\Models\PriceCandle;
use App\Models\PriceTrigger;
@@ -141,7 +140,6 @@ class ReportController extends Controller
$closed = false;
$montzar_price = 0;
$etehadie_teh = 0;
$tgn = 0;
$pr_price = 0;
@@ -167,7 +165,6 @@ class ReportController extends Controller
'main_product' => 0,
'taban_gohar' => 0,
'montzar' => 0,
'etehadie_teh' => 0,
'closed' => true,
'time' => now(),
]);
@@ -227,18 +224,6 @@ class ReportController extends Controller
$diff_buy = (float) $settingsMap->get('buy_fee', $difference);
$diff_sell = (float) $settingsMap->get('sell_fee', $difference);
/*
|--------------------------------------------------------------------------
| اتحادیه (گلد علی / refPricer) — فقط وقتی price_provider=etehadie
|--------------------------------------------------------------------------
*/
$etehadie_order_price = 0;
if ($priceProvider === 'etehadie' && !$closed) {
$etehadie = app(EtehadiePriceService::class)->fetchMainGramPrice();
$etehadie_teh = (int) ($etehadie['price'] ?? 0);
$etehadie_order_price = (int) ($etehadie['order_price'] ?? 0);
}
/*
|--------------------------------------------------------------------------
| Montzar — فقط وقتی price_provider=montzar
@@ -322,17 +307,16 @@ class ReportController extends Controller
/*
|--------------------------------------------------------------------------
| Main Product
|--------------------------------------------------------------------------
| عمومی است، پس از Cnt خوانده می‌شود.
| Main Product — settings.main_product سپس const
|--------------------------------------------------------------------------
*/
if ($toBool($main_product_price) && !$closed) {
$main_product_id = Cnt::where('key', 'main_product')->value('value');
$pr_product = $main_product_id ? Product::find($main_product_id) : null;
if ($pr_product) {
$pr_price = (float) $pr_product['price'] + (float) $pr_product['price_profit'];
$main_product_id = $config->mainProductId();
if ($main_product_id && !$closed) {
if ($priceProvider === 'main_product' || $toBool($main_product_price)) {
$pr_product = Product::find($main_product_id);
if ($pr_product) {
$pr_price = (float) $pr_product['price'] + (float) $pr_product['price_profit'];
}
}
}
@@ -365,16 +349,13 @@ class ReportController extends Controller
| انتخاب قیمت اصلی (همان price_provider)
|--------------------------------------------------------------------------
*/
if ($priceProvider === 'etehadie' && $etehadie_teh > 0 && !$closed) {
$priceValue = (int) $etehadie_teh;
$priceSource = 'etehadie';
} elseif ($priceProvider === 'montzar' && ($montzar_price ?? 0) !== 0 && !$closed) {
if ($priceProvider === 'montzar' && ($montzar_price ?? 0) !== 0 && !$closed) {
$priceValue = (int) $montzar_price;
$priceSource = 'montzar';
} elseif ($priceProvider === 'taban_gohar' && $toBool($taban_gohar_price) && ($tgn ?? 0) !== 0 && !$closed) {
$priceValue = $tgn;
$priceSource = 'taban_gohar';
} elseif ($priceProvider === 'main_product' && $toBool($main_product_price) && ($pr_price ?? 0) !== 0 && !$closed) {
} elseif ($priceProvider === 'main_product' && ($pr_price ?? 0) !== 0 && !$closed) {
$priceValue = $pr_price;
$priceSource = 'main_product';
} else {
@@ -392,7 +373,6 @@ class ReportController extends Controller
'main_product' => $pr_price ?? 0,
'taban_gohar' => $tgn ?? 0,
'montzar' => $montzar_price ?? 0,
'etehadie_teh' => $etehadie_teh ?? 0,
'closed' => true,
'time' => now(),
]);
@@ -409,7 +389,6 @@ class ReportController extends Controller
'main_product' => $pr_price ?? 0,
'taban_gohar' => $tgn ?? 0,
'montzar' => $montzar_price ?? 0,
'etehadie_teh' => $etehadie_teh ?? 0,
'closed' => true,
'time' => now(),
]);
@@ -425,9 +404,6 @@ class ReportController extends Controller
|--------------------------------------------------------------------------
*/
$priceToStore = $priceValue;
if ($priceProvider === 'etehadie' && $etehadie_order_price > 0) {
$priceToStore = $etehadie_order_price;
}
$lastPrice = Price::latest()->first();
@@ -502,11 +478,9 @@ class ReportController extends Controller
}
/*
| گلد علی (etehadie): سفارش از Price::latest() می‌خواند؛
| buy/sell/price_last هم از همان ردیف (مثل goldAliii قبل از مرج).
| etehadie_teh فقط در فیلد price / etehadie_teh می‌ماند.
| main_product / گلد علی: سفارش از Price::latest() — نمایش buy/sell همان منبع.
*/
if ($priceProvider === 'etehadie' && !$closed) {
if ($priceProvider === 'main_product' && !$closed) {
$storedPrice = $lastPrice ?? Price::latest()->first();
if ($storedPrice && (float) $storedPrice->price > 0) {
$base = (float) $storedPrice->price;
@@ -528,7 +502,6 @@ class ReportController extends Controller
'main_product' => $pr_price ?? 0,
'taban_gohar' => $tgn ?? 0,
'montzar' => $montzar_price ?? 0,
'etehadie_teh' => $etehadie_teh ?? 0,
'closed' => false,
'time' => now(),
]);
+32 -1
View File
@@ -6,19 +6,50 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Schema;
use Rooyesh\Wallet\models\Transaction;
use Tymon\JWTAuth\Contracts\JWTSubject;
class Setting extends Model
{
use HasFactory,Selector;
private static ?bool $typeColumnExists = null;
public static function hasTypeColumn(): bool
{
if (static::$typeColumnExists !== null) {
return static::$typeColumnExists;
}
try {
static::$typeColumnExists = Schema::hasColumn((new static)->getTable(), 'type');
} catch (\Throwable) {
static::$typeColumnExists = false;
}
return static::$typeColumnExists;
}
/** @return array<int, string> */
public static function adminSelectColumns(): array
{
$cols = ['id', 'title_fa', 'key', 'value', 'description', 'is_active'];
if (static::hasTypeColumn()) {
$cols[] = 'type';
}
return $cols;
}
protected $fillable = [
'key',
'title_fa',
'is_active',
'description',
'value',
'value_json'
'value_json',
'type',
];
protected $casts = [
'value_json'=>'array',
+25 -6
View File
@@ -2,6 +2,7 @@
namespace App\Services;
use App\Models\Cnt;
use App\Models\Setting;
class ConfigService
@@ -60,8 +61,7 @@ class ConfigService
* اولویت:
* 1) price_provider (یا price_primary_source قدیمی)
* 2) montzar_price=true → montzar (ابشده خانگی و پروژه‌های فعلی)
* 3) price_method پر و montzar خاموش → etehadie (گلد علی)
* 4) پیش‌فرض فایل: montzar
* 3) پیش‌فرض فایل: montzar
*/
public function priceProvider(): string
{
@@ -76,15 +76,29 @@ class ConfigService
return 'montzar';
}
if ($this->getString('price_method') !== '') {
return 'etehadie';
}
$default = strtolower((string) config('price_providers.price_provider', 'montzar'));
return in_array($default, self::PRICE_PROVIDERS, true) ? $default : 'montzar';
}
/**
* شناسه محصول آبشده پیش‌فرض: اول settings، بعد جدول const.
*/
public function mainProductId(): ?int
{
$fromSettings = $this->getString('main_product', '');
if ($fromSettings !== '' && is_numeric($fromSettings)) {
return (int) $fromSettings;
}
$fromConst = Cnt::where('key', 'main_product')->value('value');
if ($fromConst !== null && $fromConst !== '' && is_numeric($fromConst)) {
return (int) $fromConst;
}
return null;
}
/** @deprecated از priceProvider() استفاده کن */
public function pricePrimarySource(): string
{
@@ -103,6 +117,11 @@ class ConfigService
return $this->priceProvider() === 'etehadie';
}
public function usesMainProductPricing(): bool
{
return $this->priceProvider() === 'main_product';
}
public function UpdateConfig($name, $value)
{
return Setting::updateOrCreate(