gift added to tahesab

This commit is contained in:
2026-05-28 11:53:27 +03:30
parent 98d62dd5d3
commit abdfff6281
4 changed files with 203 additions and 69 deletions
+53
View File
@@ -0,0 +1,53 @@
#!/usr/bin/env php
<?php
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any of our classes manually. It's great to relax.
|
*/
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Artisan Application
|--------------------------------------------------------------------------
|
| When we run the console application, the current CLI command will be
| executed in this console and the response sent back to a terminal
| or another output device for the developers. Here goes nothing!
|
*/
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$status = $kernel->handle(
$input = new Symfony\Component\Console\Input\ArgvInput,
new Symfony\Component\Console\Output\ConsoleOutput
);
/*
|--------------------------------------------------------------------------
| Shutdown The Application
|--------------------------------------------------------------------------
|
| Once Artisan has finished running, we will fire off the shutdown events
| so that any final work may be done by the application before we shut
| down the process. This is the last thing to happen to the request.
|
*/
$kernel->terminate($input, $status);
exit($status);
@@ -168,26 +168,37 @@ class CustomerController extends SuperController
$customer->is_legal = 2; $customer->is_legal = 2;
$customer->save(); $customer->save();
if ($this->Config('has_page_earn_money') == true && Customer::where('referral_to_id', $customer->referral->referral_id)->where('is_legal', "!=",0)->count() < 4) { if ($this->Config('has_page_earn_money') == 'true' && Customer::where('referral_to_id', $customer->referral->referral_id)->where('is_legal', "!=",0)->count() < 4) {
$gift_for_inviter = 0.002;
$gift_for_invited = 0.003; $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->referral;
$total_referrals = Customer::where('referral_to_id', $referrer->referral_id)->where('is_legal', '!=', 0)->get()->count();
$referral_limit = Setting::where('key', 'referral_limit')->first();
$gift_permision = $referral_limit->is_active ? $total_referrals < $referral_limit->value ? true : false : true ;
if ($gift_permision && $gift_for_inviter > 0) {
// dd($gift_for_inviter > 0, $gift_for_invited > 0);
$Withdraw = Withdraw::create([ $Withdraw = Withdraw::create([
'user_id' => $customer->id, 'user_id' => $customer->id,
'customer_id' => $customer->referral->id, 'customer_id' => $customer->referral->id,
"cash" => 0, "cash" => 0,
"gold" => $gift_for_invited, "gold" => $gift_for_inviter,
'sts' => 5, 'sts' => 5,
]); ]);
$wallet_interface = new WalletInterface($customer->referral->id, 2); $wallet_interface = new WalletInterface($customer->referral->id, 2);
new TransactionInterface($wallet_interface, $_inp = [ new TransactionInterface($wallet_interface, $_inp = [
"cash" => 0, "cash" => 0,
"gold"=> $gift_for_invited, "gold" => $gift_for_inviter,
'expire_at' => now(), 'expire_at' => now(),
'active' => true, 'active' => true,
'title' => 'پاداش بابت معرفی',
'withdraw_id' => $Withdraw->id, 'withdraw_id' => $Withdraw->id,
'start_at' => now(), 'start_at' => now(),
], 8, true, false); ], 8, true, false);
$transaction = Transaction::where('customer_id', $customer->referral->id)->latest()->first(); $transaction = Transaction::where('customer_id', $customer->referral->id)->latest()->first();
TransactionsAdmin::create([ TransactionsAdmin::create([
'customer_id' => $customer->id, 'customer_id' => $customer->id,
@@ -198,23 +209,41 @@ class CustomerController extends SuperController
'cash' => 0, 'cash' => 0,
'note' => 'پاداش بابت معرفی', 'note' => 'پاداش بابت معرفی',
'type' => 1, // یا مقدار مناسب دیگری 'type' => 1, // یا مقدار مناسب دیگری
'gold' => $gift_for_invited, 'gold' => $gift_for_inviter,
'balance_cash' => 0, // یا مقدار مناسب دیگری 'balance_cash' => 0, // یا مقدار مناسب دیگری
'withdraw_id' => $Withdraw->id, 'withdraw_id' => $Withdraw->id,
]); ]);
$referrerWallet = Wallet::where('owner', $customer->referral->id)->first();
if($this->Config('send_to_tahesab') == "true"){
try {
$tahesab = new TahesabController();
$tahesab->walletGold([
'customer_id'=> $customer->id,
'value'=> $gift_for_inviter,
'direction'=> 0
]);
}catch (\Exception $e){
return response($e->getMessage(), 500);
}
}
$message = "سلام {$referrer->name} عزیز،\n\n{$gift_for_inviter} گرم طلا بابت معرفی {$customer->name} به حساب شما واریز شد.\nموجودی فعلی: {$referrerWallet->gold} گرم.\n\nاطلاعات بیشتر: $companyurl\n\nبا احترام،\n$companyName";
$this->Send($referrer->mobile, $message);
}
if($gift_for_invited > 0 ){
$Withdraw = Withdraw::create([ $Withdraw = Withdraw::create([
'user_id' => $customer->id, 'user_id' => $customer->id,
'customer_id' => $customer->id, 'customer_id' => $customer->id,
"cash" => 0, "cash" => 0,
"gold" => $gift_for_inviter, "gold" => $gift_for_invited,
'sts' => 5, 'sts' => 5,
]); ]);
$wallet_interface = new WalletInterface($customer->id, 2); $wallet_interface = new WalletInterface($customer->id, 2);
new TransactionInterface($wallet_interface, $_inp = [ new TransactionInterface($wallet_interface, $_inp = [
"cash" => 0, "cash" => 0,
"gold"=> $gift_for_inviter, "gold" => $gift_for_invited,
'expire_at' => now(), 'expire_at' => now(),
'active' => true, 'active' => true,
'title' => 'پاداش بابت ثبت نام',
'withdraw_id' => $Withdraw->id, 'withdraw_id' => $Withdraw->id,
'start_at' => now(), 'start_at' => now(),
], 8, true, false); ], 8, true, false);
@@ -222,19 +251,35 @@ class CustomerController extends SuperController
$transaction = Transaction::where('customer_id', $customer->id)->latest()->first(); $transaction = Transaction::where('customer_id', $customer->id)->latest()->first();
TransactionsAdmin::create([ TransactionsAdmin::create([
'customer_id' => $customer->id, 'customer_id' => $customer->id,
'customer_to_id' => $customer->id, 'customer_to_id' => $customer->referal->id,
'user_id' => $customer->id, 'user_id' => $customer->id,
'wallet' => null, // یا مقدار مناسب دیگری 'wallet' => null, // یا مقدار مناسب دیگری
'transaction_id' => $transaction->id, 'transaction_id' => $transaction->id,
'cash' => 0, 'cash' => 0,
'note' => 'پاداش بابت معرفی', 'note' => 'پاداش بابت ثبت نام',
'type' => 1, // یا مقدار مناسب دیگری 'type' => 1, // یا مقدار مناسب دیگری
'gold' => $gift_for_inviter, 'gold' => (float)$gift_for_invited,
'balance_cash' => 0, // یا مقدار مناسب دیگری 'balance_cash' => 0, // یا مقدار مناسب دیگری
'withdraw_id' => $Withdraw->id, 'withdraw_id' => $Withdraw->id,
]); ]);
$referrerWallet = Wallet::where('owner', $customer->id)->first();
if($this->Config('send_to_tahesab') == "true"){
try {
$tahesab = new TahesabController();
$tahesab->walletGold([
'customer_id'=> $customer->id,
'value'=> $gift_for_inviter,
'direction'=> 0
]);
}catch (\Exception $e){
return response($e->getMessage(), 500);
}
}
$message = "سلام " . $customer->name . " عزیز،\n\n" . $gift_for_invited . " گرم طلا بابت ثبت نام " . " به حساب شما واریز شد.\n" . "موجودی فعلی: " . $referrerWallet->gold . " گرم.\n\n" . "اطلاعات بیشتر: " . $companyurl . "\n\n" . "با احترام،\n" . $companyName;
$this->Send($customer->mobile, $message);
} }
}
$companyName = $this->Config('name_fa'); $companyName = $this->Config('name_fa');
@@ -235,6 +235,18 @@ class CustomerController extends Controller
'withdraw_id' => $Withdraw->id, 'withdraw_id' => $Withdraw->id,
]); ]);
$referrerWallet = Wallet::where('owner', $customer->referral->id)->first(); $referrerWallet = Wallet::where('owner', $customer->referral->id)->first();
if($this->Config('send_to_tahesab') == "true"){
try {
$tahesab = new TahesabController();
$tahesab->walletGold([
'customer_id'=> $customer->id,
'value'=> $gift_for_inviter,
'direction'=> 0
]);
}catch (\Exception $e){
return response($e->getMessage(), 500);
}
}
$message = "سلام {$referrer->name} عزیز،\n\n{$gift_for_inviter} گرم طلا بابت معرفی {$customer->name} به حساب شما واریز شد.\nموجودی فعلی: {$referrerWallet->gold} گرم.\n\nاطلاعات بیشتر: $companyurl\n\nبا احترام،\n$companyName"; $message = "سلام {$referrer->name} عزیز،\n\n{$gift_for_inviter} گرم طلا بابت معرفی {$customer->name} به حساب شما واریز شد.\nموجودی فعلی: {$referrerWallet->gold} گرم.\n\nاطلاعات بیشتر: $companyurl\n\nبا احترام،\n$companyName";
$this->Send($referrer->mobile, $message); $this->Send($referrer->mobile, $message);
} }
@@ -272,6 +284,18 @@ class CustomerController extends Controller
'withdraw_id' => $Withdraw->id, 'withdraw_id' => $Withdraw->id,
]); ]);
$referrerWallet = Wallet::where('owner', $customer->id)->first(); $referrerWallet = Wallet::where('owner', $customer->id)->first();
if($this->Config('send_to_tahesab') == "true"){
try {
$tahesab = new TahesabController();
$tahesab->walletGold([
'customer_id'=> $customer->id,
'value'=> $gift_for_inviter,
'direction'=> 0
]);
}catch (\Exception $e){
return response($e->getMessage(), 500);
}
}
$message = "سلام " . $customer->name . " عزیز،\n\n" . $gift_for_invited . " گرم طلا بابت ثبت نام " . " به حساب شما واریز شد.\n" . "موجودی فعلی: " . $referrerWallet->gold . " گرم.\n\n" . "اطلاعات بیشتر: " . $companyurl . "\n\n" . "با احترام،\n" . $companyName; $message = "سلام " . $customer->name . " عزیز،\n\n" . $gift_for_invited . " گرم طلا بابت ثبت نام " . " به حساب شما واریز شد.\n" . "موجودی فعلی: " . $referrerWallet->gold . " گرم.\n\n" . "اطلاعات بیشتر: " . $companyurl . "\n\n" . "با احترام،\n" . $companyName;
$this->Send($customer->mobile, $message); $this->Send($customer->mobile, $message);
} }
@@ -286,7 +310,6 @@ class CustomerController extends Controller
// return response()->json(['response' => $response], 422); // return response()->json(['response' => $response], 422);
// } // }
return response()->json(['message' => "کد ملی ثبت شد، اما در حال حاضر سیستم نتوانست آن را تأیید کند. لطفاً منتظر بررسی و تأیید مدیر بمانید.",'response' =>$response], 422); return response()->json(['message' => "کد ملی ثبت شد، اما در حال حاضر سیستم نتوانست آن را تأیید کند. لطفاً منتظر بررسی و تأیید مدیر بمانید.",'response' =>$response], 422);
} }
@@ -60,16 +60,21 @@ class SingleOrderController extends Controller
$data['customer_id'] = auth('customer')->id(); $data['customer_id'] = auth('customer')->id();
$latestPrice = Price::latest()->first(); $latestPrice = Price::latest()->first();
if($latestPrice->price == 0){ if (!$latestPrice || $latestPrice->price == 0) {
throw new UnprocessableEntityHttpException('عدم ارائه سرویس.'); throw new UnprocessableEntityHttpException('عدم ارائه سرویس.');
} }
$data['all_price'] = $latestPrice; $data['all_price'] = $latestPrice;
$data['price'] = $latestPrice->price; $data['price'] = $latestPrice->price;
$data['price_id'] = $latestPrice->id; $data['price_id'] = $latestPrice->id;
// $data['difference'] = config('fee.cash'); // $data['difference'] = config('fee.cash');
$data['difference'] = Setting::where('key', 'fee_cash')->first()->value; $feeCash = Setting::where('key', 'fee_cash')->first();
$feeServiceCharge = Setting::where('key', 'fee_service_charge_percentage')->first();
if (!$feeCash || !$feeServiceCharge) {
throw new UnprocessableEntityHttpException('تنظیمات کارمزد یافت نشد.');
}
$data['difference'] = $feeCash->value;
// $data['service_charge_percentage'] = config('fee.service_charge_percentage'); // $data['service_charge_percentage'] = config('fee.service_charge_percentage');
$data['service_charge_percentage'] = Setting::where('key', 'fee_service_charge_percentage')->first()->value; $data['service_charge_percentage'] = $feeServiceCharge->value;
$fee_free = Setting::where('key', 'fee_free')->where('is_active', true)->value('value'); $fee_free = Setting::where('key', 'fee_free')->where('is_active', true)->value('value');
@@ -94,6 +99,9 @@ class SingleOrderController extends Controller
$data['fee'] = $data['difference']; $data['fee'] = $data['difference'];
$wallet_interface = new WalletInterface($data['customer_id'], 2); $wallet_interface = new WalletInterface($data['customer_id'], 2);
$wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first(); $wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
if (!$wallet) {
throw new UnprocessableEntityHttpException('کیف پول یافت نشد.');
}
$response = []; $response = [];
@@ -136,7 +144,12 @@ class SingleOrderController extends Controller
// Calculate total price and fee for non-product (gold) transaction // Calculate total price and fee for non-product (gold) transaction
$data['total_price_original'] = $data['amount'] * ($data['price_original'] ?? 0); $data['total_price_original'] = $data['amount'] * ($data['price_original'] ?? 0);
$data['total_fee'] = $data['amount'] * $data['difference']; $data['total_fee'] = $data['amount'] * $data['difference'];
$data['product'] = Product::find(13); $mainProductId = Cnt::where('key', 'main_product')->value('value');
$data['product'] = $mainProductId ? Product::find($mainProductId) : null;
if (!$data['product']) {
throw new UnprocessableEntityHttpException('محصول آبشده یافت نشد.');
}
$data['product_id'] = $data['product']->id;
// Check if the user wants to buy // Check if the user wants to buy
if ($data['direction'] == 1) { if ($data['direction'] == 1) {
if (!$data['product']['open_buy']) { if (!$data['product']['open_buy']) {