merge goldali with abshode_khanegi branch
This commit is contained in:
@@ -10,6 +10,7 @@ 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;
|
||||
@@ -140,6 +141,7 @@ class ReportController extends Controller
|
||||
$closed = false;
|
||||
|
||||
$montzar_price = 0;
|
||||
$etehadie_teh = 0;
|
||||
$tgn = 0;
|
||||
$pr_price = 0;
|
||||
|
||||
@@ -165,11 +167,14 @@ class ReportController extends Controller
|
||||
'main_product' => 0,
|
||||
'taban_gohar' => 0,
|
||||
'montzar' => 0,
|
||||
'etehadie_teh' => 0,
|
||||
'closed' => true,
|
||||
'time' => now(),
|
||||
]);
|
||||
};
|
||||
|
||||
$priceProvider = $config->priceProvider();
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| بستن قیمت طبق منطق قبلی
|
||||
@@ -222,14 +227,22 @@ class ReportController extends Controller
|
||||
$diff_buy = (float) $settingsMap->get('buy_fee', $difference);
|
||||
$diff_sell = (float) $settingsMap->get('sell_fee', $difference);
|
||||
|
||||
$montzar_price_enabled = $toBool($config->Config('montzar_price'));
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| اتحادیه (گلد علی / refPricer) — فقط وقتی price_provider=etehadie
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
if ($priceProvider === 'etehadie' && !$closed) {
|
||||
$etehadie = app(EtehadiePriceService::class)->fetchMainGramPrice();
|
||||
$etehadie_teh = (int) ($etehadie['price'] ?? 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Montzar - اولویت اول
|
||||
| Montzar — فقط وقتی price_provider=montzar
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
if ($montzar_price_enabled && !$closed) {
|
||||
if ($priceProvider === 'montzar' && !$closed) {
|
||||
try {
|
||||
$montzarBaseUrl = rtrim($config->Config('montzar_base_url') ?: 'https://montpar.ir', '/');
|
||||
$montzarProductId = (int) ($config->Config('montzar_product_id') ?: 25);
|
||||
@@ -347,18 +360,19 @@ class ReportController extends Controller
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| انتخاب قیمت اصلی
|
||||
| اولویت:
|
||||
| Montzar -> Taban Gohar -> Main Product
|
||||
| انتخاب قیمت اصلی (همان price_provider)
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
if ($montzar_price_enabled && ($montzar_price ?? 0) !== 0 && !$closed) {
|
||||
if ($priceProvider === 'etehadie' && $etehadie_teh > 0 && !$closed) {
|
||||
$priceValue = (int) $etehadie_teh;
|
||||
$priceSource = 'etehadie';
|
||||
} elseif ($priceProvider === 'montzar' && ($montzar_price ?? 0) !== 0 && !$closed) {
|
||||
$priceValue = (int) $montzar_price;
|
||||
$priceSource = 'montzar';
|
||||
} elseif ($toBool($taban_gohar_price) && ($tgn ?? 0) !== 0 && !$closed) {
|
||||
} elseif ($priceProvider === 'taban_gohar' && $toBool($taban_gohar_price) && ($tgn ?? 0) !== 0 && !$closed) {
|
||||
$priceValue = $tgn;
|
||||
$priceSource = 'taban_gohar';
|
||||
} elseif ($toBool($main_product_price) && ($pr_price ?? 0) !== 0 && !$closed) {
|
||||
} elseif ($priceProvider === 'main_product' && $toBool($main_product_price) && ($pr_price ?? 0) !== 0 && !$closed) {
|
||||
$priceValue = $pr_price;
|
||||
$priceSource = 'main_product';
|
||||
} else {
|
||||
@@ -376,6 +390,7 @@ 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(),
|
||||
]);
|
||||
@@ -392,6 +407,7 @@ 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(),
|
||||
]);
|
||||
@@ -488,6 +504,7 @@ 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(),
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Site;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cnt;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Order;
|
||||
use App\Models\Price;
|
||||
use App\Models\TransactionsAdmin;
|
||||
use App\Models\User;
|
||||
use App\Models\Withdraw;
|
||||
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 Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
|
||||
class RequestsController extends Controller
|
||||
{
|
||||
public function order(Request $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
$transactionType = $data['method'] == 'cash' ? 'ریالی' : 'طلایی';
|
||||
|
||||
$customer_id = Customer::where('mobile', $request->mobile)->first()?->id;
|
||||
if (!$customer_id) {
|
||||
throw new UnprocessableEntityHttpException('کاربری با این شماره موبایل یافت نشد.');
|
||||
}
|
||||
|
||||
$data['customer_id'] = $customer_id;
|
||||
$latestPrice = Price::latest()->first();
|
||||
$data['price'] = $latestPrice->price;
|
||||
$data['price_id'] = $latestPrice->id;
|
||||
$data['difference'] = 0;
|
||||
$data['service_charge_percentage'] = 0;
|
||||
$data['pay_at'] = now();
|
||||
$data['sts'] = 2;
|
||||
$data['type'] = 2;
|
||||
$data['payment_sts'] = 4;
|
||||
$data['price_original'] = $data['price'];
|
||||
$data['total_price_original'] = $data['amount'] * ($data['price_original'] ?? 0);
|
||||
$data['payment_remind'] = 0;
|
||||
$data['fee'] = $data['difference'];
|
||||
$data['total_fee'] = $data['amount'] * $data['difference'];
|
||||
|
||||
$myCustomer = Customer::find($customer_id);
|
||||
$wallet_interface = new WalletInterface($customer_id, 2);
|
||||
$wallet = Wallet::where('owner', $customer_id)->whereNull('fund_id')->first();
|
||||
|
||||
$response = [];
|
||||
|
||||
// === اینجا قبلاً return بود و همه چیز قطع میشد ===
|
||||
if ($data['method'] == 'cash') {
|
||||
$response['cash'] = $this->processCashTransaction($data, $wallet, $wallet_interface, $myCustomer);
|
||||
} else if ($data['method'] == 'gold') {
|
||||
$response['gold'] = $this->processGoldTransaction($data, $wallet, $wallet_interface, $myCustomer);
|
||||
}
|
||||
|
||||
$response['Notifications'] = $this->sendTransactionNotifications($data, $transactionType);
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
public function getWallet(Request $request)
|
||||
{
|
||||
$customer_id = Customer::where('mobile', $request->mobile)->first()?->id;
|
||||
if($customer_id && $customer_id !== null){
|
||||
$wallet = Wallet::select(['owner','gold','cash'])->where('owner',$customer_id)->first();
|
||||
}else{
|
||||
throw new UnprocessableEntityHttpException('کاربری با این شماره موبایل یافت نشد.');
|
||||
}
|
||||
return $wallet;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//for orders
|
||||
private function processCashTransaction(&$data, $wallet, $wallet_interface,$myCustomer)
|
||||
{
|
||||
$response = [];
|
||||
// $data['price'] += $data['difference'];
|
||||
$data['total_price'] = $data['amount'] /** $data['price']*/;
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
|
||||
// $data['service_charge'] = $data['service_charge_percentage'] * $data['amount'];
|
||||
// $data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
// $data['amount'] -= $data['service_charge'];
|
||||
if ($wallet->cash < $data['payment_amount']) {
|
||||
throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است');
|
||||
}
|
||||
|
||||
// $data['order'] = $order = Order::create($data);
|
||||
new TransactionInterface($wallet_interface, [
|
||||
"cash" => $data['payment_amount'],
|
||||
"gold" => 0,
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
// 'order_id' => $order->id,
|
||||
'start_at' => now(),
|
||||
], 4, true, false);
|
||||
$response['1'] = 2;
|
||||
|
||||
return $response;
|
||||
}
|
||||
private function processGoldTransaction(&$data, $wallet, $wallet_interface,$myCustomer)
|
||||
{
|
||||
// if ($data['amount'] < 0.06){
|
||||
// throw new UnprocessableEntityHttpException('کمترین مقدار مجاز برای فروش 60 سوت است.');
|
||||
//
|
||||
// }
|
||||
|
||||
// $data['price'] -= $data['difference'];
|
||||
$montifyCompanyName = $this->Config('montify_name');
|
||||
$data['total_price'] = $data['amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
|
||||
$data['service_charge'] = $data['service_charge_percentage'] * $data['amount'];
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$data['total_price'] = $data['amount'] * $data['price'] -$data['service_charge_price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$data['payment_amount'] -= $data['service_charge_price'];
|
||||
|
||||
if ($wallet->gold < $data['amount']) {
|
||||
throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است');
|
||||
}
|
||||
$data['direction'] = 2;
|
||||
$data['description'] = "فروش {$data['amount']} گرم طلا برای $montifyCompanyName توسط کاربر {$myCustomer->name} با شماره موبایل {$myCustomer->mobile}";
|
||||
$data['order'] = $order = Order::create($data);
|
||||
new TransactionInterface($wallet_interface, [
|
||||
"gold" => $data['amount'],
|
||||
"cash" => 0,
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
'order_id' => $order->id
|
||||
], 10, false, true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function sendTransactionNotifications(array $data, string $transactionType)
|
||||
{
|
||||
$customer = Customer::findOrFail($data['customer_id']);
|
||||
$companyName = $this->Config('name_fa');
|
||||
$montifyCompanyName = $this->Config('montify_name');
|
||||
if($data['method'] == 'cash') {
|
||||
$message = "کاربر {$customer->name} با شماره موبایل {$customer->mobile} اقدام به برداشت موجودی از طرف $montifyCompanyName به مقدار " .
|
||||
"{$data['amount']} ریال " . " کرد. با تشکر، $companyName";
|
||||
}elseif ($data['method'] == 'gold') {
|
||||
$message = "کاربر {$customer->name} با شماره موبایل {$customer->mobile} اقدام به $transactionType طلا به مقدار " .
|
||||
"{$data['amount']} گرم به مبلغ " . number_format($data['total_price']) .
|
||||
" ریال کرد. با تشکر، $companyName";
|
||||
}
|
||||
User::where('send_sms', 1)->get()->each(function ($admin) use ($message, $data, $transactionType, $companyName) {
|
||||
$this->send($admin->mobile, $message);
|
||||
});
|
||||
// User::whereNotNull('telegram')->get()->each(function ($admin) use ($message, $data, $transactionType, $companyName) {
|
||||
// $this->SendTelegram($admin->telegram, $message);
|
||||
// });
|
||||
// $messageold = "کاربر {$customer->name} با شماره موبایل {$customer->mobile} اقدام به $transactionType طلا به مقدار " .
|
||||
// "{$data['amount']} گرم به مبلغ " . number_format($data['total_price']) .
|
||||
// " ریال کرد. با تشکر، $companyName";
|
||||
// $azOrTa = $data['direction'] == 1 ? 'از' : 'به';
|
||||
// $messageExam = "
|
||||
// {$transactionType} قلک طلا $azOrTa شما
|
||||
// {$data['amount']} گرم
|
||||
// در مظنه
|
||||
// " . number_format($data['price_original']) . " ریال";
|
||||
//
|
||||
//
|
||||
//// User::whereNotNull('telegram')->get()->each(function ($admin) use ($messageExam) {
|
||||
//// $this->SendTelegram($admin->telegram, $messageExam);
|
||||
//// });
|
||||
// User::where('send_sms', 1)->get()->each(function ($admin) use ($messageExam) {
|
||||
// $this->send($admin->mobile, $messageExam);
|
||||
// });
|
||||
|
||||
$wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
|
||||
if($data['method'] == 'cash') {
|
||||
$pricePerGram = $data['total_price'];
|
||||
}elseif ($data['method'] == 'gold') {
|
||||
$pricePerGram = $data['total_price'] / $data['amount'];
|
||||
}
|
||||
|
||||
if($data['method'] == 'cash') {
|
||||
$customerMessage = "$companyName\nبرداشت ریالی \nمبلغ: {$data['amount']}\n" .
|
||||
"\nموجودی طلایی: {$wallet->gold}\n" .
|
||||
"مانده ریالی: " . number_format($wallet->cash) . "\n" . $this->Config('app_url');
|
||||
}elseif ($data['method'] == 'gold') {
|
||||
$customerMessage = "$companyName\nبرداشت طلایی \nگرم: {$data['amount']}\nقیمت گرم: " . number_format($pricePerGram) .
|
||||
"\nمبلغ کل: " . number_format($data['total_price']) . "\nموجودی طلایی: {$wallet->gold}\n" .
|
||||
"مانده ریالی: " . number_format($wallet->cash) . "\n" . $this->Config('app_url');
|
||||
}
|
||||
|
||||
|
||||
// $customerMessage = "$companyName\n$transactionType آبشده\nگرم: {$data['amount']}\nقیمت گرم: " . number_format($pricePerGram) .
|
||||
// "\nمبلغ کل: " . number_format($data['total_price']) . "\n\nموجودی طلایی: {$wallet->gold}\n" .
|
||||
// "مانده ریالی: " . number_format($wallet->cash) . "\n" . $this->Config('app_url');
|
||||
|
||||
// ارسال SMS به مشتری
|
||||
$this->send($customer->mobile, $customerMessage);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user