NASER fix conflicts
This commit is contained in:
@@ -21,6 +21,7 @@ use Rooyesh\Wallet\models\Wallet;
|
||||
use App\Models\TransactionsAdmin;
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Models\Setting;
|
||||
|
||||
|
||||
class SingleOrderController extends Controller
|
||||
@@ -36,8 +37,19 @@ class SingleOrderController extends Controller
|
||||
$data['all_price'] = $latestPrice;
|
||||
$data['price'] = $latestPrice->price;
|
||||
$data['price_id'] = $latestPrice->id;
|
||||
$data['difference'] = config('fee.cash');
|
||||
$data['service_charge_percentage'] = config('fee.service_charge_percentage');
|
||||
// $data['difference'] = config('fee.cash');
|
||||
$data['difference'] = Setting::where('key', 'fee_cash')->first()->value;
|
||||
// $data['service_charge_percentage'] = config('fee.service_charge_percentage');
|
||||
$data['service_charge_percentage'] = Setting::where('key', 'fee_service_charge_percentage')->first()->value;
|
||||
|
||||
$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;
|
||||
$data['fee_free'] = true;
|
||||
}
|
||||
|
||||
$data['pay_at'] = (new \DateTime())->format('Y-m-d H:i:s');
|
||||
} else if (auth('user')->id()) {//admin
|
||||
$data['service_charge_percentage'] = 0;
|
||||
@@ -62,6 +74,13 @@ class SingleOrderController extends Controller
|
||||
$data['difference'] = $data['fee'] = $data['product']['cash_fee_buy'];
|
||||
$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);
|
||||
@@ -76,6 +95,12 @@ class SingleOrderController extends Controller
|
||||
$data['difference'] = $data['fee'] = $data['product']['cash_fee_sell'];
|
||||
$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);
|
||||
@@ -87,7 +112,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'];
|
||||
$data['total_fee'] = $data['amount'] * ($data['difference'] == 0 ? 1 : $data['difference']);
|
||||
$data['product'] = Product::find(13);
|
||||
// Check if the user wants to buy
|
||||
if ($data['direction'] == 1) {
|
||||
@@ -103,13 +128,14 @@ class SingleOrderController extends Controller
|
||||
$response['sell'] = $this->processSellTransaction($data, $wallet, $wallet_interface);
|
||||
}
|
||||
}
|
||||
// try {
|
||||
// $tahesab = new TahesabController();
|
||||
// $data['tahesab'] = $tahesab->storeTrade($data);
|
||||
// }catch (\Exception $e){
|
||||
// return response($e->getMessage(), 500);
|
||||
// }
|
||||
|
||||
if(Setting::where('key', 'send_to_tahesab')->first()->value == "true"){
|
||||
try {
|
||||
$tahesab = new TahesabController();
|
||||
$data['tahesab'] = $tahesab->storeTrade($data);
|
||||
}catch (\Exception $e){
|
||||
return response($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
// $response['reward'] = $this->give_order_reward($data, $wallet, $wallet_interface);
|
||||
$response['Notifications'] = $this->sendTransactionNotifications($data, $transactionType);
|
||||
return response()->json([$response, $data]);
|
||||
@@ -159,7 +185,7 @@ class SingleOrderController extends Controller
|
||||
|
||||
private function processBuyTransactionProduct(&$data, $wallet, $wallet_interface)
|
||||
{
|
||||
|
||||
$data['price'] = $data['product']["price"];
|
||||
$data['price'] += $data['difference'];
|
||||
$data['amount'] = $data['number'] * $data['product']['amount'];
|
||||
$data['total_amount'] = $data['amount']+($data['product']['percent_fee_buy']*$data['amount']);
|
||||
@@ -266,6 +292,7 @@ class SingleOrderController extends Controller
|
||||
|
||||
private function processSellTransactionProduct(&$data, $wallet, $wallet_interface)
|
||||
{
|
||||
$data['price'] = $data['product']["price"];
|
||||
$data['price'] -= $data['difference'];
|
||||
$data['amount'] = $data['number'] * $data['product']['amount'];
|
||||
$data['total_amount'] = $data['amount']-($data['product']['percent_fee_sell']*$data['amount']) ;
|
||||
@@ -538,4 +565,13 @@ class SingleOrderController extends Controller
|
||||
])->export($records);
|
||||
return response()->json($records);
|
||||
}
|
||||
|
||||
private function feeFree($customer_id, $count)
|
||||
{
|
||||
return Order::where('customer_id', $customer_id)
|
||||
->where('type', 2)
|
||||
->where('sts', 2)
|
||||
->where('payment_sts', 4)
|
||||
->count() < (int)$count;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user