NASER fix conflicts
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class SettingsController extends Controller
|
||||
{
|
||||
public function index(){
|
||||
$Setting = Setting::where('can_edit',1)->select('id','title_fa', 'key','value','description','is_active')->get();
|
||||
return response()->json($Setting);
|
||||
}
|
||||
public function edit(Request $request)
|
||||
{
|
||||
// Check if the setting exists
|
||||
$setting = Setting::where('key', $request->key)->first();
|
||||
|
||||
if ($setting) {
|
||||
// Update the existing setting
|
||||
$setting->value = $request->value;
|
||||
$setting->description = $request->description;
|
||||
$setting->is_active = $request->is_active;
|
||||
$setting->save();
|
||||
} else {
|
||||
// Create a new setting
|
||||
$setting = new Setting();
|
||||
$setting->key = $request->key;
|
||||
$setting->value = $request->value;
|
||||
$setting->description = $request->description;
|
||||
$setting->is_active = $request->is_active;
|
||||
$setting->save();
|
||||
}
|
||||
|
||||
// Return the setting as a JSON response
|
||||
return response()->json($setting);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,52 +8,80 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Models\Tahesab;
|
||||
use App\Models\Customer;
|
||||
use Morilog\Jalali\Jalalian;
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
|
||||
|
||||
class TahesabController extends Controller
|
||||
{
|
||||
public function store()
|
||||
public function create_user($customer_id)
|
||||
{
|
||||
$customer = auth()->user();
|
||||
if (!$customer) {
|
||||
throw new UnprocessableEntityHttpException("Auth needed");
|
||||
}
|
||||
$customer = Customer::where('id', $customer->id)->first();
|
||||
|
||||
if ($customer && ($customer->moshtari_code !== null)) {
|
||||
return "customer exists";
|
||||
}
|
||||
try {
|
||||
$response = Http::withoutVerifying()->timeout(10)->withHeaders([
|
||||
'DBName' => $this->Config('tahesab_db'),
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Bearer " . $this->Config('tahesab_token'),
|
||||
])->post('https://185.252.86.194:8081', [
|
||||
"DoNewMoshtari" => [
|
||||
$customer->name,
|
||||
$this->Config('name_fa'),
|
||||
$customer->mobile,
|
||||
"",
|
||||
$customer->n_code ?? "",
|
||||
$customer->birth_date ?? "", // !== null ? jalalian::fromCarbon(Carbon::parse($customer->birth_date))->format('Y/m/d') : null,
|
||||
"",
|
||||
"",
|
||||
-1,
|
||||
0 // tala
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
$customer = Customer::findOrFail($customer_id);
|
||||
|
||||
if ($customer && ($customer->moshtari_code == null)) {
|
||||
try {
|
||||
$response = Http::withoutVerifying()->timeout(10)->withHeaders([
|
||||
'DBName' => $this->Config('tahesab_db'),
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Bearer " . $this->Config('tahesab_token'),
|
||||
])->post((string)env('TAHESAB'), [
|
||||
"DoNewMoshtari" => [
|
||||
(string)$customer->name,
|
||||
$this->Config('name_fa'),
|
||||
(string)$customer->mobile,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
-1,
|
||||
0
|
||||
]
|
||||
//{"DoNewMoshtari":["Name", "GroupName", "Tel", "Address", "CodeMeli", "Tarikh_Tavalod", "Moaref", "Code_Moaref", Moshtari_Code, Jens_Felez]}
|
||||
]);
|
||||
if (!empty($response['OK'])) {
|
||||
$customer->moshtari_code = $response['OK'];
|
||||
$customer->save();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}else {
|
||||
if($customer && $customer->birth_date !== null){
|
||||
$birth_date = Verta::instance(Carbon::parse($customer->birth_date))->format('Y-m-d');
|
||||
}
|
||||
try {
|
||||
$response = Http::withoutVerifying()->timeout(10)->withHeaders([
|
||||
'DBName' => $this->Config('tahesab_db'),
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Bearer " . $this->Config('tahesab_token'),
|
||||
])->post((string)env('TAHESAB'), [
|
||||
"DoEditMoshtari" => [
|
||||
$customer->name,
|
||||
$this->Config('name_fa'),
|
||||
$customer->mobile,
|
||||
"",
|
||||
$customer->n_code ?? "",
|
||||
$birth_date ?? "",
|
||||
"",
|
||||
"",
|
||||
(int)$customer->moshtari_code,
|
||||
0 // tala
|
||||
]
|
||||
//{"DoEditMoshtari":["Name","GroupName", "Tel", "Address", "CodeMeli", "Tarikh_Tavalod", "Moaref", "Code_Moaref", Moshtari_Code]}
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response($e->getMessage(), 500);
|
||||
}
|
||||
|
||||
}
|
||||
if (empty($response['OK'])) {
|
||||
return "tahesab api error!!!";
|
||||
}
|
||||
|
||||
$customer->moshtari_code = $response['OK'];
|
||||
$customer->save();
|
||||
|
||||
return true;
|
||||
|
||||
@@ -87,7 +115,7 @@ class TahesabController extends Controller
|
||||
}
|
||||
$date = Verta::instance(Carbon::parse($data['pay_at']))->format('Y-m-d');
|
||||
[$year, $month, $day] = explode('-', $date);
|
||||
|
||||
|
||||
$amount = $data['amount'];
|
||||
|
||||
$tahesab = Tahesab::create([
|
||||
@@ -104,7 +132,7 @@ class TahesabController extends Controller
|
||||
'DBName' => $this->Config('tahesab_db'),
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Bearer " . $this->Config('tahesab_token'),
|
||||
])->post('https://185.252.86.194:8081', [
|
||||
])->post((string)env('TAHESAB'), [
|
||||
"DoNewSanadBuySaleGOLD" => [
|
||||
1,//Sabte_Kol_Or_Movaghat_1_0
|
||||
(int)$customer->moshtari_code, //Moshtari_Code
|
||||
@@ -187,7 +215,7 @@ class TahesabController extends Controller
|
||||
'DBName' => $this->Config('tahesab_db'),
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Bearer " . $this->Config('tahesab_token'),
|
||||
])->post('https://185.252.86.194:8081', [
|
||||
])->post((string)env('TAHESAB'), [
|
||||
"DoNewSanadVKHBank" => [
|
||||
1,//Sabte_Kol_Or_Movaghat_1_0
|
||||
$customer->moshtari_code,//Moshtari_Code
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Http\Controllers\SuperController;
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Setting;
|
||||
|
||||
class UserController extends SuperController
|
||||
{
|
||||
@@ -29,6 +30,9 @@ class UserController extends SuperController
|
||||
->findOrFail(auth()->id());
|
||||
// $permission = Permission::where('user_type',$user->user_type)->select('rid')->distinct('rid')->get()->pluck('rid')->toArray();
|
||||
// $user['permission'] = $permission;
|
||||
$query = Setting::query();
|
||||
$settings = $query->get();
|
||||
$user->settings= $settings;
|
||||
return response()->json($user);
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ use Rooyesh\Wallet\models\Transaction;
|
||||
use Rooyesh\Wallet\models\Wallet;
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
use App\Http\Controllers\Admin\TahesabController;
|
||||
use App\Models\Setting;
|
||||
|
||||
|
||||
class WalletController extends Controller
|
||||
@@ -117,9 +118,16 @@ class WalletController extends Controller
|
||||
'active' => true
|
||||
], 7, true, $deposit, $gold_block);
|
||||
|
||||
$data['direction'] = 0;
|
||||
// $tahesab = new TahesabController();
|
||||
// $tahesab->wallet($data);
|
||||
if(Setting::where('key', 'send_to_tahesab')->first()->value == "true"){
|
||||
try {
|
||||
$data['direction'] = 0;
|
||||
$tahesab = new TahesabController();
|
||||
$tahesab->wallet($data);
|
||||
}catch (\Exception $e){
|
||||
return response($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
$status = $data['value'] > 0 ?" شارژ شد ": " کسر شد ";
|
||||
$message = 'کیف پول شما به اندازه ' . number_format(abs($data['value'])) . " ریال در تاریخ " . verta()->format('Y/n/j H:i:s') .$status . "بابت" . "\n"
|
||||
. $data['note']
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Admin\TahesabController;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cnt;
|
||||
use App\Models\Customer;
|
||||
@@ -160,6 +161,12 @@ class AuthController extends Controller
|
||||
$data['active'] = true;
|
||||
// Create customer
|
||||
$customer = Customer::create($data);
|
||||
|
||||
// $tah = new TahesabController();
|
||||
// return $tah->store([
|
||||
// 'customer_id' => $customer->id,
|
||||
// ]);
|
||||
|
||||
$message = "{$data['name']} عزیز، اکانت شما در پلتفرم {$this->Config('name_fa')} ایجاد شد.\nنام کاربری: {$data['mobile']}\n\nورود به نرم افزار:\n{$this->Config('app_url')}";
|
||||
$this->Send($data['mobile'], $message);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ use Rooyesh\Wallet\models\Transaction;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Models\Setting;
|
||||
use App\Http\Controllers\Admin\TahesabController;
|
||||
|
||||
|
||||
//use App\Models\Price;
|
||||
@@ -102,6 +103,9 @@ class CustomerController extends Controller
|
||||
$updateData['credential_id'] = $request->credential_id;
|
||||
}
|
||||
$customer->update($updateData);
|
||||
|
||||
// $tah = new TahesabController();
|
||||
// $tah->store(["customer_id" => $customer->id]);
|
||||
if (!$customer->is_legal) {
|
||||
|
||||
$response = Http::withHeaders([
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Http\Controllers\Admin\PriceController;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\YourMailableClass;
|
||||
use App\Models\Cnt;
|
||||
use App\Models\Setting;
|
||||
use App\Models\ConfigStatic;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Price;
|
||||
@@ -18,6 +19,7 @@ use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Morilog\Jalali\Jalalian;
|
||||
use App\Http\Controllers\Admin\ProductController;
|
||||
|
||||
class ReportController extends Controller
|
||||
{
|
||||
@@ -43,7 +45,8 @@ class ReportController extends Controller
|
||||
|
||||
public function updatePrise()
|
||||
{
|
||||
$difference = config('fee.single');
|
||||
// $difference = config('fee.single');
|
||||
$difference = Setting::where('key', 'fee_single')->first()->value;
|
||||
$lastPrice = Price::latest()->first();
|
||||
$PriceTriggers = PriceTrigger::where("is_active", true)->get();
|
||||
foreach ($PriceTriggers as $PriceTrigger) {
|
||||
@@ -71,7 +74,8 @@ class ReportController extends Controller
|
||||
|
||||
public function upDownPrice()
|
||||
{
|
||||
$difference = config('fee.single');
|
||||
// $difference = config('fee.single');
|
||||
$difference = Setting::where('key', 'fee_single')->first()->value;
|
||||
$today = Carbon::now()->format("Y-m-d");
|
||||
$prises = Price::where('date_at', $today)->get("price");
|
||||
|
||||
@@ -119,7 +123,8 @@ class ReportController extends Controller
|
||||
|
||||
public function lastPrice()
|
||||
{
|
||||
$difference = config('fee.single');
|
||||
// $difference = config('fee.single');
|
||||
$difference = Setting::where('key', 'fee_single')->first()->value;
|
||||
|
||||
|
||||
// try {
|
||||
@@ -127,9 +132,20 @@ class ReportController extends Controller
|
||||
// } catch (\Exception $e) {$tala_ir = 0;}
|
||||
|
||||
$main_product_id = Cnt::where('key', 'main_product')->first()['value'];
|
||||
$refpricer = new ProductController();
|
||||
if ($refpricer->getPrice()) {
|
||||
$ref = true;
|
||||
} else {
|
||||
$ref = false;
|
||||
}
|
||||
$pr_product = Product::find($main_product_id);
|
||||
|
||||
$priceValue = $pr_product['price'] + $pr_product['price_profit'];//$tala_ir;//4000
|
||||
|
||||
try {
|
||||
$taban_gohar = Http::timeout(2)->get('https://tabangohar.com/GheymatKhan/prices_in_table.html')->json();
|
||||
$tgn = (int)$taban_gohar['c']*10;
|
||||
}catch (\Exception $e){$tgn = 0;}
|
||||
|
||||
$priceValue = $tgn !== 0 ? $tgn : $pr_product['price'] + $pr_product['price_profit'];//$tala_ir;//4000
|
||||
$lastPrice = Price::latest()->first();
|
||||
if (!$lastPrice || $lastPrice->price != $priceValue and $priceValue > 30000000) {
|
||||
$price = new Price();
|
||||
@@ -167,7 +183,9 @@ class ReportController extends Controller
|
||||
// 'henzagold' => $henzagold_18,
|
||||
// 'Ounce' => $henzagold_ons_gold,
|
||||
// 'milli' => $milli,
|
||||
'main_product' => $pr_product['price'] + $pr_product['price_profit']
|
||||
'main_product' => $pr_product['price'] + $pr_product['price_profit'],
|
||||
'taban_gohar' => $tgn,
|
||||
'refpricer' => $ref
|
||||
];
|
||||
} else {
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user