fix some bug

This commit is contained in:
2026-07-01 22:27:51 +03:30
parent a69316e0de
commit e738d44667
8 changed files with 301 additions and 260 deletions
@@ -6,19 +6,15 @@ use App\DB\Te\TableEngine;
use App\Http\Controllers\SuperController;
use App\Models\Cnt;
use App\Models\Customer;
use App\Models\TransactionsAdmin;
use App\Models\Withdraw;
use Carbon\Carbon;
use Hekmatinasser\Verta\Verta;
use Illuminate\Http\Request;
use Rooyesh\Wallet\interfaces\TransactionInterface;
use Rooyesh\Wallet\interfaces\WalletInterface;
use Rooyesh\Wallet\models\Transaction;
use Rooyesh\Wallet\models\Wallet;
use App\Models\Setting;
use App\Services\AssetSummaryService;
use App\Services\BalanceReportService;
use App\Services\ConfigService;
use App\Services\ReferralGiftService;
use App\Services\WalletBalanceService;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
@@ -257,125 +253,13 @@ class CustomerController extends SuperController
$referrer
&& Customer::where('referral_to_id', $referrer->referral_id)->where('is_legal', '!=', 0)->count() < 4
) {
$gift_for_inviter = $this->Config('gift_for_referrer');
$gift_for_invited = $this->Config('gift_for_referral');
$companyName = $this->Config('name_fa');
$companyurl = $this->Config('app_url');
$referral_limit = Setting::where('key', 'referral_limit')->first();
$limitValue = $referral_limit->value ?? null;
$gift_permision = true;
if (
$referral_limit
&& $referral_limit->is_active
&& $limitValue !== null
&& $limitValue !== ''
&& is_numeric($limitValue)
) {
$total_referrals = Customer::where('referral_to_id', $referrer->referral_id)
->where('is_legal', '!=', 0)
->count();
$gift_permision = $total_referrals < (int) $limitValue;
}
if ($gift_permision && $gift_for_inviter > 0) {
// dd($gift_for_inviter > 0, $gift_for_invited > 0);
$Withdraw = Withdraw::create([
'user_id' => $customer->id,
'customer_id' => $referrer->id,
"cash" => 0,
"gold" => $gift_for_inviter,
'sts' => 5,
]);
$wallet_interface = new WalletInterface($referrer->id, 2);
new TransactionInterface($wallet_interface, $_inp = [
"cash" => 0,
"gold" => $gift_for_inviter,
'expire_at' => now(),
'active' => true,
'title' => 'پاداش بابت معرفی',
'withdraw_id' => $Withdraw->id,
'start_at' => now(),
], 8, true, false);
$transaction = Transaction::where('customer_id', $referrer->id)->latest()->first();
TransactionsAdmin::create([
'customer_id' => $customer->id,
'customer_to_id' => $referrer->id,
'user_id' => $customer->id,
'wallet' => null, // یا مقدار مناسب دیگری
'transaction_id' => $transaction->id,
'cash' => 0,
'note' => 'پاداش بابت معرفی',
'type' => 1, // یا مقدار مناسب دیگری
'gold' => $gift_for_inviter,
'balance_cash' => 0, // یا مقدار مناسب دیگری
'withdraw_id' => $Withdraw->id,
]);
if($this->Config('send_to_tahesab') == "true"){
try {
app(TahesabController::class)->referrerGoldReward(
$customer,
(float) $gift_for_inviter,
'پاداش بابت معرفی'
);
} catch (\Exception $e) {
report($e);
}
}
$currentGold = self::formatSmsGoldWeight((float) $wallet_interface->wallet->refresh()->gold);
$message = "سلام {$referrer->name} عزیز،\n\n{$gift_for_inviter} گرم طلا بابت معرفی {$customer->name} به حساب شما واریز شد.\nموجودی فعلی: {$currentGold} گرم.\n\nاطلاعات بیشتر: $companyurl\n\nبا احترام،\n$companyName";
$this->Send($referrer->mobile, $message);
}
if($gift_for_invited > 0 ){
$Withdraw = Withdraw::create([
'user_id' => $customer->id,
'customer_id' => $customer->id,
"cash" => 0,
"gold" => $gift_for_invited,
'sts' => 5,
]);
$wallet_interface = new WalletInterface($customer->id, 2);
new TransactionInterface($wallet_interface, $_inp = [
"cash" => 0,
"gold" => $gift_for_invited,
'expire_at' => now(),
'active' => true,
'title' => 'پاداش بابت ثبت نام',
'withdraw_id' => $Withdraw->id,
'start_at' => now(),
], 8, true, false);
$transaction = Transaction::where('customer_id', $customer->id)->latest()->first();
TransactionsAdmin::create([
'customer_id' => $customer->id,
'customer_to_id' => $customer->referal->id,
'user_id' => $customer->id,
'wallet' => null, // یا مقدار مناسب دیگری
'transaction_id' => $transaction->id,
'cash' => 0,
'note' => 'پاداش بابت ثبت نام',
'type' => 1, // یا مقدار مناسب دیگری
'gold' => (float)$gift_for_invited,
'balance_cash' => 0, // یا مقدار مناسب دیگری
'withdraw_id' => $Withdraw->id,
]);
if($this->Config('send_to_tahesab') == "true"){
try {
app(TahesabController::class)->goldReward([
'customer_id' => $customer->id,
'value' => $gift_for_invited,
'desc' => 'پاداش بابت ثبت نام',
]);
} catch (\Exception $e) {
report($e);
}
}
$currentGold = self::formatSmsGoldWeight((float) $wallet_interface->wallet->refresh()->gold);
$message = "سلام " . $customer->name . " عزیز،\n\n" . $gift_for_invited . " گرم طلا بابت ثبت نام " . " به حساب شما واریز شد.\n" . "موجودی فعلی: " . $currentGold . " گرم.\n\n" . "اطلاعات بیشتر: " . $companyurl . "\n\n" . "با احترام،\n" . $companyName;
$this->Send($customer->mobile, $message);
}
$gift_permision = app(ReferralGiftService::class)->resolveReferrerGiftPermission($referrer);
app(ReferralGiftService::class)->tryGiveOnRegistration(
$customer,
$referrer,
$gift_permision,
false
);
}
}
@@ -339,7 +339,8 @@ class DashboardController extends Controller
$response['fullPriceSood'] += $ord->total_fee;
$response['fullPriceKarmozd'] += $ord->service_charge_price;
}
$response['sumAll'] = $response['fullPriceM1']-$response['GiftsPrise'];
$response['totalTradingProfit'] = $response['fullPriceSood'] + $response['fullPriceKarmozd'];
$response['sumAll'] = $response['fullPriceM1'] - $response['GiftsPrise'];
return $response;
}
@@ -18,6 +18,7 @@ use Rooyesh\Wallet\models\Transaction;
use App\Models\Setting;
use App\Http\Controllers\Admin\TahesabController;
use App\Services\ConfigService;
use App\Services\ReferralGiftService;
use Illuminate\Support\Facades\Schema;
@@ -196,128 +197,14 @@ class CustomerController extends Controller
$customer->is_legal = 1;
$customer->save();
if ($this->Config('has_page_earn_money') == 'true') {
$gift_for_inviter = $this->Config('gift_for_referrer');
$gift_for_invited = $this->Config('gift_for_referral');
$companyName = $this->Config('name_fa');
$companyurl = $this->Config('app_url');
$referrer = $customer->referrer();
$gift_permision = true;
if ($referrer) {
$referral_limit = Setting::where('key', 'referral_limit')->first();
$limitValue = $referral_limit->value ?? null;
if (
$referral_limit
&& $referral_limit->is_active
&& $limitValue !== null
&& $limitValue !== ''
&& is_numeric($limitValue)
) {
$total_referrals = Customer::where('referral_to_id', $referrer->referral_id)
->where('is_legal', '!=', 0)
->count();
$gift_permision = $total_referrals < (int) $limitValue;
}
}
if ($referrer && $gift_permision && $gift_for_inviter > 0) {
// dd($gift_for_inviter > 0, $gift_for_invited > 0);
$Withdraw = Withdraw::create([
'user_id' => $customer->id,
'customer_id' => $referrer->id,
"cash" => 0,
"gold" => $gift_for_inviter,
'sts' => 5,
]);
$wallet_interface = new WalletInterface($referrer->id, 2);
new TransactionInterface($wallet_interface, $_inp = [
"cash" => 0,
"gold" => $gift_for_inviter,
'expire_at' => now(),
'active' => true,
'title' => 'پاداش بابت معرفی',
'withdraw_id' => $Withdraw->id,
'start_at' => now(),
], 8, true, false);
$transaction = Transaction::where('customer_id', $referrer->id)->latest()->first();
TransactionsAdmin::create([
'customer_id' => $customer->id,
'customer_to_id' => $referrer->id,
'user_id' => $customer->id,
'wallet' => null, // یا مقدار مناسب دیگری
'transaction_id' => $transaction->id,
'cash' => 0,
'note' => 'پاداش بابت معرفی',
'type' => 1, // یا مقدار مناسب دیگری
'gold' => $gift_for_inviter,
'balance_cash' => 0, // یا مقدار مناسب دیگری
'withdraw_id' => $Withdraw->id,
]);
if($this->Config('send_to_tahesab') == "true"){
try {
app(TahesabController::class)->referrerGoldReward(
$customer,
(float) $gift_for_inviter,
'پاداش بابت معرفی'
);
} catch (\Exception $e) {
report($e);
}
}
$currentGold = self::formatSmsGoldWeight((float) $wallet_interface->wallet->refresh()->gold);
$message = "سلام {$referrer->name} عزیز،\n\n{$gift_for_inviter} گرم طلا بابت معرفی {$customer->name} به حساب شما واریز شد.\nموجودی فعلی: {$currentGold} گرم.\n\nاطلاعات بیشتر: $companyurl\n\nبا احترام،\n$companyName";
$this->Send($referrer->mobile, $message);
}
if($gift_for_invited > 0 ){
$Withdraw = Withdraw::create([
'user_id' => $customer->id,
'customer_id' => $customer->id,
"cash" => 0,
"gold" => $gift_for_invited,
'sts' => 5,
]);
$wallet_interface = new WalletInterface($customer->id, 2);
new TransactionInterface($wallet_interface, $_inp = [
"cash" => 0,
"gold" => $gift_for_invited,
'expire_at' => now(),
'active' => true,
'title' => 'پاداش بابت ثبت نام',
'withdraw_id' => $Withdraw->id,
'start_at' => now(),
], 8, true, false);
$transaction = Transaction::where('customer_id', $customer->id)->latest()->first();
TransactionsAdmin::create([
'customer_id' => $customer->id,
'customer_to_id' => $customer->id,
'user_id' => $customer->id,
'wallet' => null, // یا مقدار مناسب دیگری
'transaction_id' => $transaction->id,
'cash' => 0,
'note' => 'پاداش بابت ثبت نام',
'type' => 1, // یا مقدار مناسب دیگری
'gold' => (float)$gift_for_invited,
'balance_cash' => 0, // یا مقدار مناسب دیگری
'withdraw_id' => $Withdraw->id,
]);
if($this->Config('send_to_tahesab') == "true"){
try {
app(TahesabController::class)->goldReward([
'customer_id' => $customer->id,
'value' => $gift_for_invited,
'desc' => 'پاداش بابت ثبت نام',
]);
} catch (\Exception $e) {
report($e);
}
}
$currentGold = self::formatSmsGoldWeight((float) $wallet_interface->wallet->refresh()->gold);
$message = "سلام " . $customer->name . " عزیز،\n\n" . $gift_for_invited . " گرم طلا بابت ثبت نام " . " به حساب شما واریز شد.\n" . "موجودی فعلی: " . $currentGold . " گرم.\n\n" . "اطلاعات بیشتر: " . $companyurl . "\n\n" . "با احترام،\n" . $companyName;
$this->Send($customer->mobile, $message);
}
$gift_permision = app(ReferralGiftService::class)->resolveReferrerGiftPermission($referrer);
app(ReferralGiftService::class)->tryGiveOnRegistration(
$customer,
$referrer,
$gift_permision,
true
);
}
} else {
if (isset($response['matched']) && $response['matched'] === false) {
@@ -26,6 +26,7 @@ use App\Models\Cnt;
use App\Services\MontzarService;
use App\Services\ConfigService;
use App\Services\ProductDisplayPriceService;
use App\Services\ReferralGiftService;
use App\Services\WalletBroadcastService;
+245
View File
@@ -0,0 +1,245 @@
<?php
namespace App\Services;
use App\Http\Controllers\Admin\TahesabController;
use App\Http\Controllers\Controller;
use App\Models\Customer;
use App\Models\Order;
use App\Models\Setting;
use App\Models\TransactionsAdmin;
use App\Models\Withdraw;
use Rooyesh\Wallet\interfaces\TransactionInterface;
use Rooyesh\Wallet\interfaces\WalletInterface;
use Rooyesh\Wallet\models\Transaction;
class ReferralGiftService
{
public function isDeferredToFirstOrder(): bool
{
return app(ConfigService::class)->getBool('referral_gift_on_first_order', false);
}
/**
* پاداش معرف/معرف‌شونده هنگام ثبت‌نام یا تأیید احراز — مگر اینکه به اولین سفارش موکول شده باشد.
*/
public function tryGiveOnRegistration(
Customer $customer,
?Customer $referrer,
bool $referrerGiftAllowed,
bool $allowInvitedGiftWithoutReferrer = true
): void {
if ($this->isDeferredToFirstOrder()) {
return;
}
$this->depositGifts($customer, $referrer, $referrerGiftAllowed, $allowInvitedGiftWithoutReferrer);
}
/**
* پاداش معرف/معرف‌شونده پس از اولین سفارش — فقط وقتی تنظیم referral_gift_on_first_order روشن است.
*/
public function tryGiveOnFirstOrder(Customer $customer): void
{
if (!$this->isDeferredToFirstOrder()) {
return;
}
$config = app(ConfigService::class);
if ($config->getString('has_page_earn_money', 'false') !== 'true') {
return;
}
if (Order::where('customer_id', $customer->id)->count() !== 1) {
return;
}
$referrer = $customer->referrer();
$referrerGiftAllowed = $this->resolveReferrerGiftPermission($referrer);
$this->depositGifts($customer, $referrer, $referrerGiftAllowed, true);
}
public function resolveReferrerGiftPermission(?Customer $referrer): bool
{
if ($referrer === null) {
return false;
}
$referralLimit = Setting::where('key', 'referral_limit')->first();
$limitValue = $referralLimit->value ?? null;
if (
$referralLimit
&& $referralLimit->is_active
&& $limitValue !== null
&& $limitValue !== ''
&& is_numeric($limitValue)
) {
$totalReferrals = Customer::where('referral_to_id', $referrer->referral_id)
->where('is_legal', '!=', 0)
->count();
return $totalReferrals < (int) $limitValue;
}
return true;
}
private function depositGifts(
Customer $customer,
?Customer $referrer,
bool $referrerGiftAllowed,
bool $allowInvitedGiftWithoutReferrer
): void {
$config = app(ConfigService::class);
$giftForInviter = (float) $config->get('gift_for_referrer', 0);
$giftForInvited = (float) $config->get('gift_for_referral', 0);
$companyName = $config->getString('name_fa');
$companyUrl = $config->getString('app_url');
if ($referrer && $referrerGiftAllowed && $giftForInviter > 0 && !$this->referrerGiftAlreadyGiven($customer, $referrer)) {
$this->giveReferrerGift($customer, $referrer, $giftForInviter, $companyName, $companyUrl, $config);
}
$canGiveInvited = $giftForInvited > 0
&& !$this->invitedGiftAlreadyGiven($customer)
&& ($allowInvitedGiftWithoutReferrer || $referrer !== null);
if ($canGiveInvited) {
$this->giveInvitedGift($customer, $giftForInvited, $companyName, $companyUrl, $config);
}
}
private function referrerGiftAlreadyGiven(Customer $invited, Customer $referrer): bool
{
return TransactionsAdmin::where('customer_id', $invited->id)
->where('customer_to_id', $referrer->id)
->where('note', 'پاداش بابت معرفی')
->exists();
}
private function invitedGiftAlreadyGiven(Customer $customer): bool
{
return TransactionsAdmin::where('customer_id', $customer->id)
->where('note', 'پاداش بابت ثبت نام')
->exists();
}
private function giveReferrerGift(
Customer $customer,
Customer $referrer,
float $giftForInviter,
string $companyName,
string $companyUrl,
ConfigService $config
): void {
$withdraw = Withdraw::create([
'user_id' => $customer->id,
'customer_id' => $referrer->id,
'cash' => 0,
'gold' => $giftForInviter,
'sts' => 5,
]);
$walletInterface = new WalletInterface($referrer->id, 2);
new TransactionInterface($walletInterface, [
'cash' => 0,
'gold' => $giftForInviter,
'expire_at' => now(),
'active' => true,
'title' => 'پاداش بابت معرفی',
'withdraw_id' => $withdraw->id,
'start_at' => now(),
], 8, true, false);
$transaction = Transaction::where('customer_id', $referrer->id)->latest()->first();
TransactionsAdmin::create([
'customer_id' => $customer->id,
'customer_to_id' => $referrer->id,
'user_id' => $customer->id,
'wallet' => null,
'transaction_id' => $transaction->id,
'cash' => 0,
'note' => 'پاداش بابت معرفی',
'type' => 1,
'gold' => $giftForInviter,
'balance_cash' => 0,
'withdraw_id' => $withdraw->id,
]);
if ($config->getString('send_to_tahesab', 'false') === 'true') {
try {
app(TahesabController::class)->referrerGoldReward(
$customer,
$giftForInviter,
'پاداش بابت معرفی'
);
} catch (\Exception $e) {
report($e);
}
}
$currentGold = Controller::formatSmsGoldWeight((float) $walletInterface->wallet->refresh()->gold);
$message = "سلام {$referrer->name} عزیز،\n\n{$giftForInviter} گرم طلا بابت معرفی {$customer->name} به حساب شما واریز شد.\nموجودی فعلی: {$currentGold} گرم.\n\nاطلاعات بیشتر: {$companyUrl}\n\nبا احترام،\n{$companyName}";
Controller::Send($referrer->mobile, $message);
}
private function giveInvitedGift(
Customer $customer,
float $giftForInvited,
string $companyName,
string $companyUrl,
ConfigService $config
): void {
$withdraw = Withdraw::create([
'user_id' => $customer->id,
'customer_id' => $customer->id,
'cash' => 0,
'gold' => $giftForInvited,
'sts' => 5,
]);
$walletInterface = new WalletInterface($customer->id, 2);
new TransactionInterface($walletInterface, [
'cash' => 0,
'gold' => $giftForInvited,
'expire_at' => now(),
'active' => true,
'title' => 'پاداش بابت ثبت نام',
'withdraw_id' => $withdraw->id,
'start_at' => now(),
], 8, true, false);
$transaction = Transaction::where('customer_id', $customer->id)->latest()->first();
TransactionsAdmin::create([
'customer_id' => $customer->id,
'customer_to_id' => $customer->id,
'user_id' => $customer->id,
'wallet' => null,
'transaction_id' => $transaction->id,
'cash' => 0,
'note' => 'پاداش بابت ثبت نام',
'type' => 1,
'gold' => $giftForInvited,
'balance_cash' => 0,
'withdraw_id' => $withdraw->id,
]);
if ($config->getString('send_to_tahesab', 'false') === 'true') {
try {
app(TahesabController::class)->goldReward([
'customer_id' => $customer->id,
'value' => $giftForInvited,
'desc' => 'پاداش بابت ثبت نام',
]);
} catch (\Exception $e) {
report($e);
}
}
$currentGold = Controller::formatSmsGoldWeight((float) $walletInterface->wallet->refresh()->gold);
$message = "سلام {$customer->name} عزیز،\n\n{$giftForInvited} گرم طلا بابت ثبت نام به حساب شما واریز شد.\nموجودی فعلی: {$currentGold} گرم.\n\nاطلاعات بیشتر: {$companyUrl}\n\nبا احترام،\n{$companyName}";
Controller::Send($customer->mobile, $message);
}
}
+20 -8
View File
@@ -274,6 +274,11 @@ INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `de
SELECT 'register_referral_bonus_message', 'false', 'پیام پاداش در SMS ثبت‌نام', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'register_referral_bonus_message' LIMIT 1);
-- default: false — value ردیف موجود در deploy عوض نمی‌شود (فقط INSERT اگر کلید نبود)
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'referral_gift_on_first_order', 'false', 'پاداش معرف پس از اولین سفارش', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'referral_gift_on_first_order' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'referral_limit', '', 'محدودیت دعوت', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'referral_limit' LIMIT 1);
@@ -421,6 +426,7 @@ INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `de
SELECT 'fee_service_charge_percentage', '0.005', 'درصد کارمزد سفارش', 1, 1, NULL, 'number'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'fee_service_charge_percentage' LIMIT 1);
-- fee_deduct_from_gold: value پیش‌فرض false فقط در INSERT اولیه؛ اجرای مجدد value/is_active را overwrite نمی‌کند
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`, `type`)
SELECT 'fee_deduct_from_gold', 'false', 'کارمزد از مقدار طلا', 1, 1, NULL, 'switch'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'fee_deduct_from_gold' LIMIT 1);
@@ -598,11 +604,13 @@ UPDATE `settings` SET `type` = 'switch' WHERE `key` IN (
'chart_use_local_data',
'jibit_verification', 'register_jibit_verify', 'open_register', 'auto_active_customer',
'close_price', 'show_last_price',
'fee_deduct_from_gold',
'send_to_tahesab', 'profit_gold_api_enabled', 'payping_round_toman', 'payping_strict_failed_withdraw',
'has_page_earn_money', 'charge_notif', 'group_sms',
'montzar_closed', 'montzar_open_buy', 'montzar_open_sell',
'payping_fin_sync_enabled', 'external_order_api_enabled', 'is_store', 'wss_enabled',
'register_referral_sms_to_referrer', 'register_referral_bonus_message',
'referral_gift_on_first_order',
'banner_enabled'
);
@@ -695,7 +703,7 @@ SELECT 'unit', '', 'واحد وزن دارایی و معاملات', 1, 1,
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'unit' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'main_wallet_products', '13', 'محصولات متصل به کیف اصلی', 1, 1,
SELECT 'main_wallet_products', '13', 'محصولات متصل به کیف اصلی', 0, 1,
'محصولاتی که موجودی‌شان از کیف طلای اصلی خوانده می‌شود. چند محصول با کاما. پیش‌فرض: 13'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'main_wallet_products' LIMIT 1);
@@ -775,7 +783,7 @@ UPDATE `settings` SET
WHERE `key` = 'referral_id';
UPDATE `settings` SET `type` = 'switch'
WHERE `key` IN ('register_referral_sms_to_referrer', 'register_referral_bonus_message');
WHERE `key` IN ('register_referral_sms_to_referrer', 'register_referral_bonus_message', 'referral_gift_on_first_order');
UPDATE `settings` SET
`type` = 'switch',
@@ -892,7 +900,10 @@ UPDATE `settings` SET `description` = 'اختلاف پایه (ریال) بین
UPDATE `settings` SET `description` = 'مبلغ اضافه (ریال) روی قیمت پایه برای سمت خرید. خالی = استفاده از «اختلاف پایه».' WHERE `key` = 'buy_fee';
UPDATE `settings` SET `description` = 'مبلغ کسر (ریال) از قیمت پایه برای سمت فروش. خالی = استفاده از «اختلاف پایه».' WHERE `key` = 'sell_fee';
UPDATE `settings` SET `description` = 'درصد کارمزد هر سفارش از مبلغ معامله (اعشاری؛ مثلاً ۰٫۰۰۵ یعنی نیم در هزار).' WHERE `key` = 'fee_service_charge_percentage';
UPDATE `settings` SET `description` = 'روشن: کارمزد از مقدار طلا کسر می‌شود — در فروش مبلغ ریالی دقیق واریز می‌شود. خاموش: کارمزد از ریال فروش کم می‌شود (رفتار قبلی).' WHERE `key` = 'fee_deduct_from_gold';
UPDATE `settings` SET
`type` = 'switch',
`description` = 'روشن: کارمزد از مقدار طلا کسر می‌شود — در فروش مبلغ ریالی دقیق واریز می‌شود. خاموش: کارمزد از ریال فروش کم می‌شود (رفتار قبلی).'
WHERE `key` = 'fee_deduct_from_gold';
UPDATE `settings` SET `description` = 'تعداد اولین سفارش‌های هر کاربر که از کارمزد معاف می‌شوند. ۰ = غیرفعال.' WHERE `key` = 'fee_free';
UPDATE `settings` SET `description` = 'حداقل مبلغ درخواست برداشت وجه (ریال). درخواست‌های کمتر رد می‌شوند.' WHERE `key` = 'min_withdraw';
UPDATE `settings` SET `description` = 'حداقل مبلغ اولین خرید هر کاربر (ریال). برای فعال‌سازی کیف یا احراز سطح اول استفاده می‌شود.' WHERE `key` = 'min_first_buy';
@@ -912,6 +923,7 @@ UPDATE `settings` SET `description` = 'مقدار پاداش (معمولاً و
UPDATE `settings` SET `description` = 'مقدار پاداش (معمولاً وزن فلز) که به کاربر تازه‌ثبت‌نام‌شده (معرف‌شونده) داده می‌شود. ۰ = بدون پاداش.' WHERE `key` = 'gift_for_referral';
UPDATE `settings` SET `description` = 'روشن: پس از ثبت‌نام کاربر جدید، پیامک اطلاع‌رسانی برای معرف ارسال می‌شود.' WHERE `key` = 'register_referral_sms_to_referrer';
UPDATE `settings` SET `description` = 'روشن: متن پاداش معرف در پیامک خوش‌آمد ثبت‌نام گنجانده می‌شود.' WHERE `key` = 'register_referral_bonus_message';
UPDATE `settings` SET `description` = 'روشن: پاداش معرف (gift_for_referrer) و پاداش معرف‌شونده (gift_for_referral) پس از اولین سفارش معرف‌شونده واریز می‌شود؛ خاموش = واریز هنگام ثبت‌نام/تأیید احراز (رفتار قبلی).' WHERE `key` = 'referral_gift_on_first_order';
UPDATE `settings` SET `description` = 'حداکثر تعداد دعوت‌های مجاز برای هر کاربر. خالی = بدون محدودیت.' WHERE `key` = 'referral_limit';
UPDATE `settings` SET `description` = 'مبلغ یا مقدار پاداش معرف (متن آزاد — بسته به پیاده‌سازی پیامک/اعتبار). برای نمایش در پیام‌ها.' WHERE `key` = 'referral_bonus_amount';
UPDATE `settings` SET `description` = 'روشن: تطبیق شماره کارت بانکی کاربر با سرویس احراز هویت جیبیت هنگام ثبت/ویرایش کارت.' WHERE `key` = 'jibit_verification';
@@ -975,7 +987,7 @@ UPDATE `settings` SET `description` = 'روشن: امکان ارسال پیام
UPDATE `settings` SET `description` = 'محصولاتی که موجودی‌شان از کیف طلای اصلی خوانده می‌شود. چند محصول با کاما. پیش‌فرض: 13' WHERE `key` = 'main_wallet_products';
UPDATE `settings` SET `value` = '13' WHERE `key` = 'main_wallet_products' AND TRIM(COALESCE(`value`, '')) = '';
UPDATE `settings` SET `can_edit` = 1 WHERE `key` = 'main_wallet_products';
UPDATE `settings` SET `can_edit` = 0 WHERE `key` = 'main_wallet_products';
UPDATE `settings` SET `description` = 'روشن: API محاسبه سود طلا فعال است. در اکثر نصب‌ها خاموش می‌ماند.' WHERE `key` = 'profit_gold_api_enabled';
-- ---------------------------------------------------------------------------
@@ -1090,6 +1102,7 @@ UPDATE `settings` SET `title_fa` = 'محدودیت دعوت' WHERE `key` = 'refe
UPDATE `settings` SET `title_fa` = 'تأیید کدملی/موبایل در ثبت‌نام' WHERE `key` = 'register_jibit_verify';
UPDATE `settings` SET `title_fa` = 'پیام پاداش در SMS ثبت‌نام' WHERE `key` = 'register_referral_bonus_message';
UPDATE `settings` SET `title_fa` = 'SMS به معرف هنگام ثبت‌نام' WHERE `key` = 'register_referral_sms_to_referrer';
UPDATE `settings` SET `title_fa` = 'پاداش معرف پس از اولین سفارش' WHERE `key` = 'referral_gift_on_first_order';
UPDATE `settings` SET `title_fa` = 'سود فروش نمایش' WHERE `key` = 'sell_fee';
UPDATE `settings` SET `title_fa` = 'ارسال به ته‌حساب' WHERE `key` = 'send_to_tahesab';
UPDATE `settings` SET `title_fa` = 'آدرس API سرور' WHERE `key` = 'server_url';
@@ -1131,7 +1144,7 @@ UPDATE `settings` SET `can_edit` = 0 WHERE `key` IN (
'has_page_earn_money',
'is_store',
'logo_login', 'logo_register', 'title_pwa', 'title_fav',
'main_product', 'metal_type', 'main_metal',
'main_product', 'main_wallet_products', 'metal_type', 'main_metal',
'montify_name',
'montzar_base_url', 'montzar_closed',
'montzar_diff', 'montzar_last_product_log', 'montzar_live_price', 'montzar_mazaneh',
@@ -1158,17 +1171,16 @@ UPDATE `settings` SET `can_edit` = 1 WHERE `key` IN (
'auto_active_customer', 'balance_report_exclude_customer_id',
'buy_fee', 'charge_notif', 'close_price',
'deposit_sms_support_number', 'endDay',
'fee_free', 'fee_service_charge_percentage', 'fee_single',
'fee_deduct_from_gold', 'fee_free', 'fee_service_charge_percentage', 'fee_single',
'gift_for_referral', 'gift_for_referrer',
'invite_link_text',
'jibit_verification',
'main_product_price',
'main_wallet_products',
'min_first_buy', 'min_withdraw', 'minimum_sell',
'montzar_mobile', 'montzar_open_buy', 'montzar_open_sell',
'montzar_password', 'montzar_price', 'montzar_product_id',
'open_register',
'referral_bonus_amount', 'referral_id', 'referral_limit',
'referral_bonus_amount', 'referral_id', 'referral_limit', 'referral_gift_on_first_order',
'register_jibit_verify', 'register_referral_bonus_message', 'register_referral_sms_to_referrer',
'sell_fee', 'show_last_price', 'startDay',
'support_messenger', 'support_messenger_id', 'support_messenger_text',
@@ -270,6 +270,11 @@ INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `de
SELECT 'register_referral_bonus_message', 'false', 'پیام پاداش در SMS ثبت‌نام', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'register_referral_bonus_message' LIMIT 1);
-- default: false — value ردیف موجود در deploy عوض نمی‌شود (فقط INSERT اگر کلید نبود)
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'referral_gift_on_first_order', 'false', 'پاداش معرف پس از اولین سفارش', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'referral_gift_on_first_order' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'referral_limit', '', 'محدودیت دعوت', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'referral_limit' LIMIT 1);
@@ -419,6 +424,7 @@ INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `de
SELECT 'fee_service_charge_percentage', '0.005', 'درصد کارمزد سفارش', 1, 1, NULL, 'number'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'fee_service_charge_percentage' LIMIT 1);
-- fee_deduct_from_gold: value پیش‌فرض false فقط در INSERT اولیه؛ اجرای مجدد value/is_active را overwrite نمی‌کند
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`, `type`)
SELECT 'fee_deduct_from_gold', 'false', 'کارمزد از مقدار طلا', 1, 1, NULL, 'switch'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'fee_deduct_from_gold' LIMIT 1);
@@ -595,11 +601,13 @@ UPDATE `settings` SET `type` = 'switch' WHERE `key` IN (
'chart_use_local_data',
'jibit_verification', 'register_jibit_verify', 'open_register', 'auto_active_customer',
'close_price', 'show_last_price',
'fee_deduct_from_gold',
'send_to_tahesab', 'profit_gold_api_enabled', 'payping_round_toman', 'payping_strict_failed_withdraw',
'has_page_earn_money', 'charge_notif', 'group_sms',
'montzar_closed', 'montzar_open_buy', 'montzar_open_sell',
'payping_fin_sync_enabled', 'external_order_api_enabled', 'is_store', 'wss_enabled',
'register_referral_sms_to_referrer', 'register_referral_bonus_message'
'register_referral_sms_to_referrer', 'register_referral_bonus_message',
'referral_gift_on_first_order'
);
-- price (مبالغ ریالی)
@@ -690,7 +698,7 @@ SELECT 'unit', '', 'واحد وزن دارایی و معاملات', 1, 1,
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'unit' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'main_wallet_products', '13', 'محصولات متصل به کیف اصلی', 1, 1,
SELECT 'main_wallet_products', '13', 'محصولات متصل به کیف اصلی', 0, 1,
'محصولاتی که موجودی‌شان از کیف طلای اصلی خوانده می‌شود. چند محصول با کاما. پیش‌فرض: 13'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'main_wallet_products' LIMIT 1);
@@ -768,7 +776,7 @@ UPDATE `settings` SET
WHERE `key` = 'referral_id';
UPDATE `settings` SET `type` = 'switch'
WHERE `key` IN ('register_referral_sms_to_referrer', 'register_referral_bonus_message');
WHERE `key` IN ('register_referral_sms_to_referrer', 'register_referral_bonus_message', 'referral_gift_on_first_order');
UPDATE `settings` SET
`type` = 'switch',
@@ -939,6 +947,7 @@ UPDATE `settings` SET `description` = 'مقدار پاداش (معمولاً و
UPDATE `settings` SET `description` = 'مقدار پاداش (معمولاً وزن فلز) که به کاربر تازه‌ثبت‌نام‌شده (معرف‌شونده) داده می‌شود. ۰ = بدون پاداش.' WHERE `key` = 'gift_for_referral';
UPDATE `settings` SET `description` = 'روشن: پس از ثبت‌نام کاربر جدید، پیامک اطلاع‌رسانی برای معرف ارسال می‌شود.' WHERE `key` = 'register_referral_sms_to_referrer';
UPDATE `settings` SET `description` = 'روشن: متن پاداش معرف در پیامک خوش‌آمد ثبت‌نام گنجانده می‌شود.' WHERE `key` = 'register_referral_bonus_message';
UPDATE `settings` SET `description` = 'روشن: پاداش معرف (gift_for_referrer) و پاداش معرف‌شونده (gift_for_referral) پس از اولین سفارش معرف‌شونده واریز می‌شود؛ خاموش = واریز هنگام ثبت‌نام/تأیید احراز (رفتار قبلی).' WHERE `key` = 'referral_gift_on_first_order';
UPDATE `settings` SET `description` = 'حداکثر تعداد دعوت‌های مجاز برای هر کاربر. خالی = بدون محدودیت.' WHERE `key` = 'referral_limit';
UPDATE `settings` SET `description` = 'مبلغ یا مقدار پاداش معرف (متن آزاد — بسته به پیاده‌سازی پیامک/اعتبار). برای نمایش در پیام‌ها.' WHERE `key` = 'referral_bonus_amount';
UPDATE `settings` SET `description` = 'روشن: تطبیق شماره کارت بانکی کاربر با سرویس احراز هویت جیبیت هنگام ثبت/ویرایش کارت.' WHERE `key` = 'jibit_verification';
@@ -999,7 +1008,7 @@ UPDATE `settings` SET `description` = 'روشن: امکان ارسال پیام
UPDATE `settings` SET `description` = 'محصولاتی که موجودی‌شان از کیف طلای اصلی خوانده می‌شود. چند محصول با کاما. پیش‌فرض: 13' WHERE `key` = 'main_wallet_products';
UPDATE `settings` SET `value` = '13' WHERE `key` = 'main_wallet_products' AND TRIM(COALESCE(`value`, '')) = '';
UPDATE `settings` SET `can_edit` = 1 WHERE `key` = 'main_wallet_products';
UPDATE `settings` SET `can_edit` = 0 WHERE `key` = 'main_wallet_products';
UPDATE `settings` SET `description` = 'روشن: API محاسبه سود طلا فعال است. در اکثر نصب‌ها خاموش می‌ماند.' WHERE `key` = 'profit_gold_api_enabled';
-- ---------------------------------------------------------------------------
+4 -2
View File
@@ -1,5 +1,7 @@
-- سوییچ «کارمزد از مقدار طلا» — برای نصب‌های موجود (مثلاً abshodehrahimi)
-- پس از deploy کد، این فایل را یک‌بار روی DB اجرا کنید؛ سپس در ادمین > تنظیمات > کارمزد روشن کنید.
-- idempotent: چند بار قابل اجرا
-- • اولین بار: INSERT با value='false' (پیش‌فرض خاموش)
-- • اجرای مجدد: value و is_active دست نمی‌خورند — فقط title_fa / description / type / can_edit
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`, `type`)
SELECT 'fee_deduct_from_gold', 'false', 'کارمزد از مقدار طلا', 1, 1,
@@ -9,7 +11,7 @@ WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'fee_deduct_from_gold'
UPDATE `settings`
SET `title_fa` = 'کارمزد از مقدار طلا',
`description` = 'روشن: کارمزد از مقدار طلا کسر می‌شود — در فروش مبلغ ریالی دقیق واریز می‌شود. خاموش: کارمزد از ریال فروش کم می‌شود (رفتار قبلی).',
`description` = 'روشن: مبالغ رند — فروش = دریافت دقیق ریال (کارمزد از طلا)؛ خرید = دریافت دقیق وزن (کارمزد از ریال). خاموش: کارمزد از طرف مقابل — رفتار قبلی.',
`type` = 'switch',
`can_edit` = 1
WHERE `key` = 'fee_deduct_from_gold';