NASER fix telegram messages and calculte price for products and fix bugs for fee free
This commit is contained in:
@@ -80,32 +80,20 @@ class Controller extends BaseController
|
||||
$send_sms = true;
|
||||
$user = User::where('mobile', $to)->first() ?: Customer::where('mobile', $to)->first();
|
||||
if ($user) {
|
||||
if ($send_sms or $force_method=="sms") {
|
||||
$endpoint = "http://www.0098sms.com/sendsmslink.aspx";
|
||||
$response = Http::get($endpoint, [
|
||||
'FROM' => $credentials['sms']['sender'],
|
||||
'TO' => $to,
|
||||
'TEXT' => trim($msg),
|
||||
'USERNAME' => $credentials['sms']['user_name'],
|
||||
'PASSWORD' => $credentials['sms']['password'],
|
||||
'DOMAIN' => '0098',
|
||||
]);
|
||||
$platforms[] = "0098:{$to}";
|
||||
|
||||
}
|
||||
// Telegram
|
||||
// if (isset($credentials['telegram']) && $user->telegram) {
|
||||
// try {
|
||||
// Http::get("https://api.wwwapp.ir/telegran_send.php", [
|
||||
// 'botToken' => $credentials['telegram']['token'],
|
||||
// 'chatId' => $user->telegram,
|
||||
// 'message' => "جناب {$user->name} {$msg}",
|
||||
// ]);
|
||||
// $platforms[] = "telegram:{$user->telegram}";
|
||||
// $send_sms = false;
|
||||
// } catch (\Exception $e) {
|
||||
// }
|
||||
// }
|
||||
if (isset($credentials['telegram']) && $user->telegram) {
|
||||
try {
|
||||
Http::get("https://api.wwwapp.ir/telegran_send.php", [
|
||||
'botToken' => $credentials['telegram']['token'],
|
||||
'chatId' => $user->telegram,
|
||||
'message' => "جناب {$user->name} {$msg}",
|
||||
]);
|
||||
$platforms[] = "telegram:{$user->telegram}";
|
||||
$send_sms = false;
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
// Bale
|
||||
if (isset($credentials['bale']) && $user->bale) {
|
||||
@@ -122,6 +110,20 @@ class Controller extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
//SMS
|
||||
if ($send_sms or $force_method=="sms") {
|
||||
$endpoint = "http://www.0098sms.com/sendsmslink.aspx";
|
||||
$response = Http::get($endpoint, [
|
||||
'FROM' => $credentials['sms']['sender'],
|
||||
'TO' => $to,
|
||||
'TEXT' => trim($msg),
|
||||
'USERNAME' => $credentials['sms']['user_name'],
|
||||
'PASSWORD' => $credentials['sms']['password'],
|
||||
'DOMAIN' => '0098',
|
||||
]);
|
||||
$platforms[] = "0098:{$to}";
|
||||
|
||||
}
|
||||
|
||||
Message::create([
|
||||
'sms' => $msg,
|
||||
|
||||
@@ -46,7 +46,7 @@ class SingleOrderController extends Controller
|
||||
|
||||
if($fee_free && $this->feeFree($data['customer_id'], $fee_free)){
|
||||
$data['service_charge_percentage'] = 0;
|
||||
$data['difference'] = 0;
|
||||
// $data['difference'] = 0;
|
||||
$data['fee_free'] = true;
|
||||
}
|
||||
|
||||
@@ -70,17 +70,12 @@ class SingleOrderController extends Controller
|
||||
// Check if the user wants to buy
|
||||
if ($data['direction'] == 1) {
|
||||
|
||||
$data['service_charge_percentage'] = ($data['product']['percent_fee_buy']) * $data['number'];
|
||||
$data['service_charge_percentage'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_buy']) * $data['number'];
|
||||
$data['difference'] = $data['fee'] = $data['product']['cash_fee_buy'];
|
||||
$data['total_fee'] = $data['number'] * $data['fee'];
|
||||
$data['price_original'] = $data['product']['price'] + $data['product']['price_profit'];
|
||||
$data['total_price_original'] = $data['product']['amount'] * ($data['price_original'] ?? 0);
|
||||
|
||||
$fee_free = Setting::where('key', 'fee_free')->where('is_active', true)->value('value');
|
||||
|
||||
if($fee_free && $this->feeFree($data['customer_id'], $fee_free)){
|
||||
$data['service_charge_percentage'] = 0;
|
||||
$data['difference'] = 0;
|
||||
}
|
||||
|
||||
// Check if the method is cash
|
||||
if ($data['method'] == "cash") {
|
||||
$response['buy'] = $this->processBuyTransactionProduct($data, $wallet, $wallet_interface);
|
||||
@@ -91,16 +86,12 @@ class SingleOrderController extends Controller
|
||||
}
|
||||
} // Check if the user wants to sell
|
||||
else if ($data['direction'] == 2) {
|
||||
$data['service_charge_percentage'] = ($data['product']['percent_fee_sell']) * $data['number'];
|
||||
$data['service_charge_percentage'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_sell']) * $data['number'];
|
||||
$data['difference'] = $data['fee'] = $data['product']['cash_fee_sell'];
|
||||
$data['total_fee'] = $data['number'] * $data['fee'];
|
||||
$data['price_original'] = $data['product']['price'] + $data['product']['price_profit'];
|
||||
$data['total_price_original'] = $data['product']['amount'] * ($data['price_original'] ?? 0);
|
||||
|
||||
$fee_free = Setting::where('key', 'fee_free')->where('is_active', true)->value('value');
|
||||
|
||||
if($fee_free && $this->feeFree($data['customer_id'], $fee_free)){
|
||||
$data['service_charge_percentage'] = 0;
|
||||
$data['difference'] = 0;
|
||||
}
|
||||
// Check if the method is cash
|
||||
if ($data['method'] == "cash") {
|
||||
$response['sell'] = $this->processSellTransactionProduct($data, $wallet, $wallet_interface);
|
||||
@@ -112,7 +103,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);
|
||||
$data['total_fee'] = $data['amount'] * ($data['difference'] == 0 ? 1 : $data['difference']);
|
||||
$data['total_fee'] = $data['amount'] * $data['difference'];
|
||||
$data['product'] = Product::find(13);
|
||||
// Check if the user wants to buy
|
||||
if ($data['direction'] == 1) {
|
||||
@@ -149,7 +140,7 @@ class SingleOrderController extends Controller
|
||||
$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'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : $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']) {
|
||||
@@ -185,13 +176,13 @@ class SingleOrderController extends Controller
|
||||
|
||||
private function processBuyTransactionProduct(&$data, $wallet, $wallet_interface)
|
||||
{
|
||||
$data['price'] = $data['product']["price"];
|
||||
$data['price'] = $data['product']['price'] + $data['product']['price_profit'];
|
||||
$data['price'] += $data['difference'];
|
||||
$data['amount'] = $data['number'] * $data['product']['amount'];
|
||||
$data['total_amount'] = $data['amount']+($data['product']['percent_fee_buy']*$data['amount']);
|
||||
$data['total_price'] = $data['total_amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$data['service_charge'] = ($data['product']['percent_fee_buy']*$data['amount']);
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_buy']*$data['amount']);
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$data['wallet'] = $wallet;
|
||||
if ($wallet->cash < $data['payment_amount']) {
|
||||
@@ -234,7 +225,7 @@ class SingleOrderController extends Controller
|
||||
$data['total_amount'] = $data['amount']+($data['product']['percent_fee_buy']*$data['amount']);
|
||||
$data['total_price'] = $data['total_amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$data['service_charge'] = ($data['product']['percent_fee_buy']*$data['amount']);
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_buy']*$data['amount']);
|
||||
$data['total_fee'] = 0;
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$data['wallet'] = $wallet;
|
||||
@@ -272,7 +263,7 @@ class SingleOrderController extends Controller
|
||||
{
|
||||
$response = [];
|
||||
$data['price'] -= $data['difference'];
|
||||
$data['service_charge'] = $data['service_charge_percentage'] * $data['amount'];
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : $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'];
|
||||
@@ -292,13 +283,13 @@ class SingleOrderController extends Controller
|
||||
|
||||
private function processSellTransactionProduct(&$data, $wallet, $wallet_interface)
|
||||
{
|
||||
$data['price'] = $data['product']["price"];
|
||||
$data['price'] = $data['product']['price'] + $data['product']['price_profit'];
|
||||
$data['price'] -= $data['difference'];
|
||||
$data['amount'] = $data['number'] * $data['product']['amount'];
|
||||
$data['total_amount'] = $data['amount']-($data['product']['percent_fee_sell']*$data['amount']) ;
|
||||
$data['total_price'] = $data['total_amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$data['service_charge'] = ($data['product']['percent_fee_sell']*$data['amount']);
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_sell']*$data['amount']);
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$wallet_interface_product = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type, null, $data["product_id"]);
|
||||
|
||||
@@ -337,7 +328,7 @@ class SingleOrderController extends Controller
|
||||
$data['total_amount'] = $data['amount']-($data['product']['percent_fee_sell']*$data['amount']) ;
|
||||
$data['total_price'] = $data['total_amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$data['service_charge'] = ($data['product']['percent_fee_sell']*$data['amount']);
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_sell']*$data['amount']);
|
||||
$data['total_fee'] = 0;
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$wallet_interface_product = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type, null, $data["product_id"]);
|
||||
|
||||
Reference in New Issue
Block a user