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
);
}
}