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(
+2 -1
View File
@@ -8,7 +8,8 @@
*
* سازگاری قدیمی (بدون price_provider):
* montzar_price=true → montzar
* price_method پر و montzar خاموش → etehadie
*
* main_product: شناسه محصول در settings (کلید main_product)، وگرنه const
*/
return [
'price_provider' => 'montzar',
+1 -1
View File
@@ -1,4 +1,4 @@
-- گلد علی — حذف کلیدهای legacy که سرور Abshode_Khanegi (etehadie) دیگر نمی‌خواند
-- گلد علی — حذف کلیدهای legacy (لیمان/منت‌زر/اتحادیه)
-- قبل از اجرا: بکاپ. جدول const یا cnt بسته به اسکیمای شما.
START TRANSACTION;
+15
View File
@@ -3,6 +3,16 @@
START TRANSACTION;
-- قیمت: محصول اصلی (نه اتحادیه)
UPDATE `settings` SET `value` = 'main_product' WHERE `key` = 'price_provider';
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'price_provider', 'main_product', 'منبع قیمت', 1, 1, 'main_product برای گلد علی'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'price_provider' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'main_product', '13', 'شناسه محصول آبشده', 1, 1, 'اول settings، بعد const'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'main_product' LIMIT 1);
UPDATE `settings` SET `value` = '13' WHERE `key` = 'main_product';
-- درگاه (اگر قبلاً نزده‌اید)
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'payping_start_url', 'https://payment.goldaliii.com/payment/start', 'آدرس شروع درگاه', 1, 1, NULL
@@ -84,4 +94,9 @@ WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'fee_service_charge_per
UPDATE `settings` SET `value` = '0' WHERE `key` = 'fee_cash';
UPDATE `settings` SET `value` = '0.02' WHERE `key` = 'fee_service_charge_percentage';
-- ستون type (ادمین Abshode — اختیاری؛ کد بدون آن هم کار می‌کند)
-- اگر خطای Duplicate column name گرفتید، یعنی قبلاً اضافه شده — رد کنید.
ALTER TABLE `settings`
ADD COLUMN `type` VARCHAR(64) NULL DEFAULT NULL COMMENT 'نوع فیلد در پنل ادمین' AFTER `description`;
COMMIT;
+18 -7
View File
@@ -8,13 +8,17 @@
START TRANSACTION;
-- -----------------------------------------------------------------------------
-- ۱) قیمت — منبع اتحادیه (مثل goldAliii + price_method قبلی)
-- ۱) قیمت — محصول اصلی (نه اتحادیه)؛ main_product اول settings بعد const
-- -----------------------------------------------------------------------------
UPDATE `settings` SET `value` = 'etehadie' WHERE `key` = 'price_provider';
UPDATE `settings` SET `value` = 'main_product' WHERE `key` = 'price_provider';
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'price_provider', 'etehadie', 'منبع قیمت', 1, 1, 'montzar|etehadie|...'
SELECT 'price_provider', 'main_product', 'منبع قیمت', 1, 1, 'montzar|main_product|taban_gohar'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'price_provider' LIMIT 1);
-- price_method را عوض نکنید (همان estjt_... گلد علی)
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'main_product', '13', 'شناسه محصول آبشده پیش‌فرض', 1, 1, 'اولویت بر const'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'main_product' LIMIT 1);
UPDATE `settings` SET `value` = '13' WHERE `key` = 'main_product';
-- نمایش buy/sell در /api/price/last (ریال — جدا از کارمزد سفارش)
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
@@ -95,10 +99,10 @@ UPDATE `settings` SET `value` = 'sDsB,gp1Q,GPH4,AMAX,TbQl,AAQl' WHERE `key` = 'p
UPDATE `settings` SET `value` = 'true' WHERE `key` IN ('payping_round_toman', 'payping_strict_failed_withdraw');
-- -----------------------------------------------------------------------------
-- ۵) const — محصول آبشده پیش‌فرض (قبلاً abshode_id=13 در کد بود)
-- ۵) const — fallback اگر settings.main_product نبود
-- -----------------------------------------------------------------------------
INSERT INTO `const` (`key`, `value`, `title_fa`)
SELECT 'main_product', '13', 'محصول آبشده پیش‌فرض'
SELECT 'main_product', '13', 'محصول آبشده پیش‌فرض (fallback)'
WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'main_product' LIMIT 1);
UPDATE `const` SET `value` = '13' WHERE `key` = 'main_product';
@@ -123,6 +127,13 @@ WHERE NOT EXISTS (SELECT 1 FROM `const` WHERE `key` = 'first_customer_wallet_val
COMMIT;
-- -----------------------------------------------------------------------------
-- ۵b) اسکیما — ستون type در settings (اختیاری؛ کد بدون آن هم کار می‌کند)
-- اگر Duplicate column name → قبلاً اضافه شده.
-- -----------------------------------------------------------------------------
-- ALTER TABLE `settings`
-- ADD COLUMN `type` VARCHAR(64) NULL DEFAULT NULL COMMENT 'نوع فیلد در پنل ادمین' AFTER `description`;
-- -----------------------------------------------------------------------------
-- ۶) اختیاری — حذف کلیدهای legacy (بعد از تست)
-- فایل جدا: goldali_cleanup_legacy_keys.sql
@@ -134,7 +145,7 @@ COMMIT;
-- بررسی:
-- SELECT `key`, `value` FROM `settings` WHERE `key` IN (
-- 'price_provider','price_method','fee_cash','fee_service_charge_percentage',
-- 'price_provider','main_product','fee_cash','fee_service_charge_percentage',
-- 'fee_single','payping_start_url','profit_gold_api_enabled'
-- );
-- SELECT `key`, `value` FROM `const` WHERE `key` IN ('main_product','is_gateway_open');
+7 -4
View File
@@ -56,9 +56,12 @@ UPDATE `const` SET `title_fa` = 'بنر بالای صفحه' WHERE `key` = 'head
-- منبع قیمت: اتحادیه (تنها منبع فعال در کد مرج‌شده)
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'price_provider', 'etehadie', 'منبع قیمت',
1, 1, 'فقط یکی: montzar | etehadie | taban_gohar | main_product'
SELECT 'price_provider', 'main_product', 'منبع قیمت',
1, 1, 'گلد علی: main_product — montzar | taban_gohar | main_product'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'price_provider' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'main_product', '13', 'شناسه محصول آبشده', 1, 1, 'اول settings، بعد const'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'main_product' LIMIT 1);
-- کارمزد نمایش buy/sell در /api/price/last — کد fee_single می‌خواند (نه fee)
-- مقدار 500000 = پیش‌فرض config/fee.php؛ اگر برای گلد علی عدد دیگری دارید بعداً در پنل عوض کنید
@@ -95,9 +98,9 @@ WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'balance_report_exclude
-- بخش ۳ — فقط چند UPDATE مطمئن (کلیدهای مربوط به کد جدید)
-- =============================================================================
-- price_provider حتماً اتحادیه (ردیف بخش ۲ ساخته یا از قبل بوده)
UPDATE `settings` SET `value` = 'etehadie', `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'منبع قیمت')
UPDATE `settings` SET `value` = 'main_product', `title_fa` = COALESCE(NULLIF(TRIM(`title_fa`), ''), 'منبع قیمت')
WHERE `key` = 'price_provider';
UPDATE `settings` SET `value` = '13' WHERE `key` = 'main_product';
UPDATE `settings` SET `value` = 'true' WHERE `key` = 'profit_gold_api_enabled';
UPDATE `settings` SET `is_active` = 1 WHERE `key` = 'open_register';
UPDATE `settings` SET `value` = '12' WHERE `key` = 'balance_report_exclude_customer_id';
+1 -1
View File
@@ -33,7 +33,7 @@ Route::middleware('auth:customer')->group(function () {
//---------PriceTrigger
Route::resource('price_triggers', PriceTriggerController::class);
$cfg = app(ConfigService::class);
if ($cfg->getBool('profit_gold_api_enabled', false) || $cfg->usesEtehadiePricing()) {
if ($cfg->getBool('profit_gold_api_enabled', false)) {
Route::get('profit_gold', [OrderController::class, 'profit_gold']);
}