NASER before add Fingerprint
This commit is contained in:
parent
08a344ad5c
commit
6dba441e1a
|
|
@ -341,7 +341,7 @@ class CustomerController extends SuperController
|
|||
// return isset($_COOKIE["is_get_customer"]);
|
||||
$customerSync = [];
|
||||
$message = "لیست مشتریان قبلا دریافت شده";
|
||||
if ($this->Config('finance')=='tahesab'){
|
||||
if ($this->Config('finance') == 'tahesab') {
|
||||
if (isset($_COOKIE["is_get_customer"]) != 1 or $request->is_get_customer) {
|
||||
try {
|
||||
$customerSync = $this->customerSync();
|
||||
|
|
@ -362,6 +362,24 @@ class CustomerController extends SuperController
|
|||
->export($query_table);
|
||||
$query_table["is_get_customer"] = $message;
|
||||
$query_table["is_get_customer_F"] = $customerSync;
|
||||
foreach ($query_table['rows'] as $customer) {
|
||||
$customer->credits = [];
|
||||
$m = $customer->gold_balance ?? 0;
|
||||
if ($gold18 = (int)$this->Config('credit_rial_to_gold_18')) {
|
||||
$credits['cash'] = $customer->rial_balance ?? 0;
|
||||
$credits['gold'] = $customer->gold_balance ?? 0;
|
||||
$credits['cash_to_gold_18'] = $gold18 ?? 0;
|
||||
$m += $credits['cash_to_gold'] = $credits['cash'] / $credits['cash_to_gold_18'];
|
||||
}
|
||||
$credits['mandeh'] = number_format($m, 3, '.', '');
|
||||
$expression = str_replace('m', $m, $customer->credit ?? $credits['mandeh']);
|
||||
if (preg_match('/^[0-9+\-*\/().\s]+$/', $expression)) {
|
||||
$credit = eval("return $expression;");
|
||||
}
|
||||
$credits['credit'] = $credit ?? 0;
|
||||
$customer->credits = $credits;
|
||||
|
||||
}
|
||||
|
||||
return $query_table;
|
||||
$responce["customerSync"] = $customerSync;
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ class OrderController extends Controller
|
|||
|
||||
public function table(Request $request)
|
||||
{
|
||||
|
||||
$records = Order::with(['customer.agent', 'product']);
|
||||
// $records->where('amount','=', (int)$request->input('amount'));
|
||||
|
||||
|
|
@ -133,18 +134,72 @@ class OrderController extends Controller
|
|||
|
||||
public function tableNew(Request $request)
|
||||
{
|
||||
$records = Order::with(['customer.agent', 'product'])->where('sts', 1);
|
||||
|
||||
$records = Order::with(['customer.agent', 'product.price','customer'])->where('sts', 1);
|
||||
TableEngine::create($records, $request->all())
|
||||
->initSearch(['product_id->title'])
|
||||
->select([
|
||||
'*', Order::$SELECT_STS_STR, Order::$SELECT_CAJ
|
||||
])->export($records);
|
||||
foreach ($records['rows'] as &$order) {
|
||||
if ($this->Config('finance') == "tahesab"){
|
||||
// $response = Http::withoutVerifying()
|
||||
// ->withToken($this->Config('tahesab_token'))
|
||||
// ->withHeaders(['DBName' => $this->Config('tahesab_db')])
|
||||
// ->post($this->Config('tahesab_api'), [
|
||||
// 'getmandehesabbycode' => [$order->tahesab_id]
|
||||
// ])->json();
|
||||
// $gold_balance =$response['MandeHesab'][0]['MandeyeVazni']??0;
|
||||
// $rial_balance =$response['MandeHesab'][0]['MandeyeMali']??0 ;
|
||||
// if ($gold_balance != $user->gold_balance or $rial_balance != $user->rial_balance) {
|
||||
// $user->rial_balance = $rial_balance;
|
||||
// $user->gold_balance = $gold_balance;
|
||||
// $user->save();
|
||||
// }
|
||||
}
|
||||
$m = $order->customer->gold_balance ??0;
|
||||
if ($gold18 = $this->Config('credit_rial_to_gold_18')){
|
||||
$m += $order->customer->rial_balance / $gold18;
|
||||
$credits['gold18'] = $gold18 ??0;
|
||||
}
|
||||
$m = number_format($m, 3, '.', '');
|
||||
if (!empty($m)) {
|
||||
$order->rate_price_final_map = "با تراز {$m} گرم";
|
||||
}else{
|
||||
$order->rate_price_final_map = "";
|
||||
}
|
||||
if($this->Config('cancel_order_by_mazaneh') == "activate"){
|
||||
if ($order->direction == 1) {
|
||||
$orderMazaneForAdmin = $order->product_json['price']['price'] + $order->product_json['price']['diff_sell'];
|
||||
$orderMazaneForAdminNew = $order->product->price->price + $order->product->price->diff_sell;
|
||||
} else {
|
||||
$orderMazaneForAdmin = $order->product_json['price']['price'] - $order->product_json['price']['diff_buy'];
|
||||
$orderMazaneForAdminNew = $order->product->price->price - $order->product->price->diff_buy;
|
||||
}
|
||||
if($orderMazaneForAdmin != $orderMazaneForAdminNew){
|
||||
try {
|
||||
$trigerUrl = $this->trigerUrl();
|
||||
|
||||
Http::withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
])->post($trigerUrl . '/prc/api/trigger-update', [
|
||||
'customer_id' => $order->customer_id,
|
||||
'order_id' => $order->id,
|
||||
'trigger' => 'send_order_sts',
|
||||
'description' => 'به علت تغیر مظنه',
|
||||
'status' => "reject ",
|
||||
]);
|
||||
} catch (\Exception $exception) {
|
||||
|
||||
}
|
||||
$order->sts =4;
|
||||
}
|
||||
}
|
||||
|
||||
$order->save();
|
||||
|
||||
$order->direction = ($order->direction == 2) ? 1 : 2;
|
||||
$order->time_at = \Carbon\Carbon::parse($order->pay_at)->format('H:i:s');
|
||||
if ($_SERVER['HTTP_HOST'] == 'emexgold.com' or true) {
|
||||
$order->rate_price_final_map = '';
|
||||
}
|
||||
}
|
||||
return response()->json($records);
|
||||
}
|
||||
|
|
@ -153,8 +208,7 @@ class OrderController extends Controller
|
|||
{
|
||||
$o = Order::with(['customer', 'product'])->select(['*', Order::$SELECT_STS_STR])->findOrFail($id);
|
||||
|
||||
return response()->json($o
|
||||
);
|
||||
return response()->json($o);
|
||||
}
|
||||
|
||||
public function changeStatus(Request $request, $adminCustomDate = null)
|
||||
|
|
|
|||
|
|
@ -1,294 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\DB\Te\TableEngine;
|
||||
use App\DB\User;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Package;
|
||||
use App\Models\PackageProduct;
|
||||
use App\Models\Price;
|
||||
use App\Models\User as UserModel;
|
||||
use App\Models\PriceCandle;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Admin\BasePackageController as BC;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Morilog\Jalali\Jalalian;
|
||||
|
||||
|
||||
class PriceController extends Controller
|
||||
{
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (is_null($request->product_id)) {
|
||||
$this->updateAllProductPrice($request);
|
||||
$this->change_price($request);
|
||||
// return $this->b750();
|
||||
}
|
||||
$basePackage = Package::where('is_base', true)->first();
|
||||
$product = Product::with('price')->where('id', $request->product_id)->first();
|
||||
$mesghal_convert = config('change_mesghal');
|
||||
|
||||
// آپدیت قیمت جدید
|
||||
Price::where('product_id', $product->id)->update([
|
||||
'price' => $request->price,
|
||||
'price_gram' => $request->price / $mesghal_convert,
|
||||
'difference_provider' => 0,
|
||||
'difference' => $request->diff ?? 0,
|
||||
'difference_gram' => ($request->diff ?? 0) / $mesghal_convert,
|
||||
'difference_liman' => $request->diff ?? 0,
|
||||
'date_at' => now()->format('Y-m-d'),
|
||||
'time_at' => now()->format('H:i:s'),
|
||||
]);
|
||||
|
||||
$product->refresh();
|
||||
|
||||
PackageProduct::where('product_id', $product->id)->where('package_id', $basePackage->id)->update([
|
||||
'buy_price' => $product->price->difference,
|
||||
'buy_gram_price' => $product->price->difference / $mesghal_convert,
|
||||
'sell_price' => $product->price->difference,
|
||||
'sell_gram_price' => $product->price->difference / $mesghal_convert,
|
||||
]);
|
||||
|
||||
// آپدیت روش خواندن قیمت
|
||||
$readingMethod = $request->is_auto ? $request->reading_method : 'manual';
|
||||
Product::where('id', $request->product_id)->update(['reading_method' => $readingMethod]);
|
||||
|
||||
// $productName = $product->name ?? 'طلای ۱۸ عیار آبشده';
|
||||
|
||||
|
||||
// $this->b750();
|
||||
$this->change_price();
|
||||
|
||||
|
||||
return response()->json(true);
|
||||
}
|
||||
public function change_price()
|
||||
{
|
||||
|
||||
$trigerUrl = $this->trigerUrl();
|
||||
try {
|
||||
Http::withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
])->post('https://ws.sepidehgold.com/prc/api/trigger-update', [
|
||||
'trigger' => 'price_update',
|
||||
]);
|
||||
} catch (\Exception $exception) {
|
||||
|
||||
}
|
||||
|
||||
$botToken = $this->Config('telegram_bot_token');
|
||||
$chatId = '504951108';
|
||||
$url = 'https://api.wwwapp.ir/telegran_send.php';
|
||||
$list_product = Product::where('active', 1)->get();
|
||||
$message = "";
|
||||
foreach ($list_product as $product) {
|
||||
if($product ->open_buy or $product ->open_sell ){
|
||||
if ($product ->open_buy and $product ->open_sell){
|
||||
$message .= "🛒 " ;
|
||||
$message .= $product->title ;
|
||||
$message .= "\n";
|
||||
$message .= "🟢 ";
|
||||
$message .= number_format( ($product->price->price + $product->price->difference) / 10000, 0);
|
||||
$message .= " 🔴 " ;
|
||||
$message .= number_format( ($product->price->price - $product->price->difference) / 10000, 0);
|
||||
if ($product->unit == 'گرم'){
|
||||
$message .= "\n";
|
||||
$message .= "💰 ";
|
||||
$message .= number_format( (($product->price->price + $product->price->difference)/config('change_mesghal')) / 10000, 0);
|
||||
$message .= str_repeat(" ", 9);
|
||||
$message .= number_format( (($product->price->price - $product->price->difference)/config('change_mesghal')) / 10000, 0);
|
||||
}
|
||||
$message .= "\n\n";
|
||||
}else{
|
||||
$message .= "🛒 " ;
|
||||
$message .= $product->title ;
|
||||
$message .= "\n";
|
||||
$message .= ($product->open_buy)? "🟢 ":"🔴 ";
|
||||
$message .=($product->open_buy)? number_format( ($product->price->price + $product->price->difference) / 10000, 0):
|
||||
number_format( ($product->price->price - $product->price->difference) / 10000, 0);
|
||||
if ($product->unit == 'گرم'){
|
||||
$message .= "\n";
|
||||
$message .= "💰 ";
|
||||
$message .=($product->open_buy)? number_format( (($product->price->price + $product->price->difference)/config('change_mesghal')) / 10000, 0):
|
||||
number_format( (($product->price->price - $product->price->difference)/config('change_mesghal')) / 10000, 0);
|
||||
}
|
||||
$message .= "\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (explode(',',$this->Config('telegram_price_contact_list')) as $contact) {
|
||||
$message .= "\n";
|
||||
$message .= $contact;
|
||||
}
|
||||
$message .= "\n";
|
||||
$message .= $this->Config('user_url');
|
||||
foreach (explode(',',$this->Config('telegram_price_alert_to')) as $contactID) {
|
||||
try {
|
||||
$response = Http::timeout(10)->get($url, [
|
||||
'chatId' => $contactID,
|
||||
'message' => $message,
|
||||
'botToken' => $botToken,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
// dd($list_product);
|
||||
// $message =21;
|
||||
|
||||
|
||||
}
|
||||
public function updateAllProductPrice(Request $request)
|
||||
{
|
||||
|
||||
if ($request->has('reading_method') && $request->has('price')) {
|
||||
return response()->json(['message' => 'Cannot update both reading_method and price at the same time.'], 422);
|
||||
}
|
||||
$doChangePrice = true;
|
||||
// اگر فقط price آمده باشد، reading_method به "manual" تغییر میکند
|
||||
if ($request->has('price')) {
|
||||
$request->merge(['reading_method' => 'manual']);
|
||||
} // اگر فقط reading_method آمده باشد، قیمت تغییر نمیکند
|
||||
else if ($request->has('reading_method')) {
|
||||
$doChangePrice = false;
|
||||
}
|
||||
// اگر product_id نیامده باشد، روی همه محصولات اعمال میشود
|
||||
$products = is_null($request->product_id) ? Product::all() : Product::where('id', $request->product_id)->get();
|
||||
foreach ($products as $product) {
|
||||
// به روز رسانی اطلاعات محصول
|
||||
$product->update(['reading_method' => $request->reading_method]);
|
||||
if ($doChangePrice) {
|
||||
$lastP = Price::where('product_id', $product->id)->update([
|
||||
"price" => $request->price,
|
||||
"price_gram" => $request->price / config('change_mesghal'),
|
||||
"difference_liman" => $request->diff,
|
||||
"difference_gram" => $request->diff / config('change_mesghal'),
|
||||
"date_at" => date("Y-m-d"),
|
||||
"time_at" => now()->format("H:m:s"),
|
||||
"user_id" => auth('user')->id()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return response()->json(true);
|
||||
}
|
||||
|
||||
public function table(Request $request)
|
||||
{
|
||||
$records = Price::with(['user', 'product']);
|
||||
TableEngine::create($records, $request->all())
|
||||
->initSearch(["product.title","user.name",'price','id',"user.id"])
|
||||
->select([
|
||||
'*'
|
||||
])->export($records);
|
||||
return response()->json($records);
|
||||
}
|
||||
public function createLinkPricing(Request $request)
|
||||
{
|
||||
$user = UserModel::find(auth('user')->id());
|
||||
$user->token = md5(auth('user')->user().time());
|
||||
|
||||
// Convert the user object to an array for the HTTP request
|
||||
$requestData = $user->toArray();
|
||||
|
||||
$response = Http::post('https://pricing.liman.gold/auth/create_url_token', $requestData)->json();
|
||||
|
||||
return response()->json($response);
|
||||
|
||||
// $user =auth()->user();
|
||||
//
|
||||
// $keyToken='n2640NBlz%#X*88&470*';
|
||||
// $textToHash=$user->id.$keyToken;
|
||||
// $hash = hash_hmac('sha256', $textToHash, $keyToken);
|
||||
//
|
||||
// return response()->json([
|
||||
// 'user'=>$user,
|
||||
// 'hash'=>$hash,
|
||||
// 'message'=>'success'
|
||||
// ]);
|
||||
}
|
||||
|
||||
public function b750()
|
||||
{
|
||||
return true;
|
||||
$response = Http::get('https://pricing.liman.gold/pricingApi', [])->json();
|
||||
$RPrices = $response;
|
||||
$products = Product::with('price')->where('active', 1)->get();
|
||||
$mesghal_convert = config('change_mesghal');
|
||||
$basePackage = Package::where('is_base', true)->first();
|
||||
|
||||
foreach ($products as $product) {
|
||||
if (!$product->price) {
|
||||
$newPrice = Price::create([
|
||||
'price' => 1,
|
||||
'difference_liman' => 0,
|
||||
'product_id' => $product->id,
|
||||
]);
|
||||
$product->refresh();
|
||||
}
|
||||
$found = false;
|
||||
if (empty($RPrices)) {
|
||||
return true;
|
||||
}
|
||||
foreach ($RPrices as $RPrice) {
|
||||
if ($product->reading_method == $RPrice['name']) {
|
||||
$existingPrice = Price::where('product_id', $product->id)->first();
|
||||
$restData = false;
|
||||
if($product ->open_buy or $product ->open_sell ) {
|
||||
if ($existingPrice && $RPrice['price'] != $existingPrice->price) {$restData = true;}
|
||||
}
|
||||
|
||||
$found = true;
|
||||
Price::where('product_id', $product->id)->update([
|
||||
'price' => $RPrice['price'],
|
||||
'price_gram' => $RPrice['price'] / $mesghal_convert,
|
||||
'difference_provider' => $RPrice['profit'] ,
|
||||
'difference' => $product->price->difference_liman + $RPrice['profit'] ,
|
||||
'difference_gram' => $RPrice['profit'] / $mesghal_convert,
|
||||
'difference_liman' => $product->price->difference_liman,
|
||||
'date_at' => now()->format('Y-m-d'),
|
||||
'time_at' => now()->format('H:i:s'),
|
||||
]);
|
||||
|
||||
$product->refresh();
|
||||
PackageProduct::where('product_id', $product->id)->where('package_id', $basePackage->id)->update([
|
||||
'buy_price' => $product->price->difference,
|
||||
'buy_gram_price' => $product->price->difference / $mesghal_convert,
|
||||
'sell_price' => $product->price->difference,
|
||||
'sell_gram_price' => $product->price->difference / $mesghal_convert,
|
||||
]);
|
||||
if ($restData) {$this->change_price();}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!$found and $product->reading_method != "manual") {
|
||||
Price::where('product_id', $product->id)->update([
|
||||
'price' => 0,
|
||||
'price_gram' => 0,
|
||||
'difference_provider' => 0,
|
||||
'difference' => $product->price->difference_liman??0,
|
||||
'difference_gram' => 0,
|
||||
'difference_liman' => $product->price->difference_liman??0,
|
||||
'date_at' => now()->format('Y-m-d'),
|
||||
'time_at' => now()->format('H:i:s'),
|
||||
]);
|
||||
$product->refresh();
|
||||
PackageProduct::where('product_id', $product->id)->where('package_id', $basePackage->id)->update([
|
||||
'buy_price' => $product->price->difference_liman??0,
|
||||
'buy_gram_price' => $product->price->difference_liman??0,
|
||||
'sell_price' => $product->price->difference_liman??0,
|
||||
'sell_gram_price' => $product->price->difference_liman ?? 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
return response()->json(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ class Order extends Model
|
|||
];
|
||||
public function customer(){
|
||||
return $this->belongsTo(Customer::class)->select([
|
||||
'id','fname','lname','name','agent_id','mobile','avatar_id','type','tahesab_id',Customer::$SELECT_TYPE_STR
|
||||
'id','fname','lname','name','agent_id','mobile','avatar_id','type','tahesab_id','rial_balance','gold_balance',Customer::$SELECT_TYPE_STR
|
||||
]);
|
||||
}
|
||||
public function admin(){
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ Route::post('/customers', function (Request $request) {
|
|||
}
|
||||
return response()->json([
|
||||
'state' => 'true',
|
||||
'msg' =>$cu->pargar_id.":" . $cu->name.$message,
|
||||
'msg' => $cu->pargar_id.":" . $cu->name.$message,
|
||||
'result' => 'OK'
|
||||
]);
|
||||
});
|
||||
|
|
@ -258,7 +258,7 @@ Route::get('/orders', function (Request $request) {
|
|||
'Weight' => $order->amount ?? 0,
|
||||
'Price' => $order->payment_amount ?? 0,
|
||||
'Carat' => 750,
|
||||
'Description' => $order->description ?? '',
|
||||
'Description' => $order-> product_json['title']." ". $order->description ?? '',
|
||||
];
|
||||
});
|
||||
|
||||
|
|
@ -318,12 +318,14 @@ Route::post('/pdf', function (Request $request) {
|
|||
});
|
||||
Route::post('/mande', function (Request $request) {
|
||||
$data = $request->all();
|
||||
$cu = Customer::where("pargar_id", $data['AccountId'])->first();
|
||||
$cu = Customer::where('pargar_id', $data['AccountId'])
|
||||
->orWhere('tahesab_id', $data['AccountId'])
|
||||
->first();
|
||||
if (!($cu)) {
|
||||
return response()->json([
|
||||
'state' => 'true',
|
||||
'msg' => "مشتری وجود ندارد",
|
||||
'data' => null,
|
||||
'msg' => "مشتری یافت نشد.",
|
||||
'data' => [],
|
||||
'result' => 'OK',
|
||||
'duplicated' => [],
|
||||
'documents' => []
|
||||
|
|
@ -336,7 +338,7 @@ Route::post('/mande', function (Request $request) {
|
|||
return response()->json([
|
||||
'state' => 'true',
|
||||
'msg' => "با موفقیت دریافت شد",
|
||||
'data' => null,
|
||||
'data' => [],
|
||||
'result' => 'OK',
|
||||
'duplicated' => [],
|
||||
'documents' => []
|
||||
|
|
|
|||
|
|
@ -168,9 +168,21 @@ Route::get('/12', function () {
|
|||
|
||||
|
||||
});
|
||||
Route::get('/par', function () {
|
||||
Route::get('/par', function (Request $request) {
|
||||
|
||||
Pargar::latest('id')->take(3000)->get()
|
||||
$USER = "24gold.app";
|
||||
$PASS = "b78oBh31Aos*bIdQemiUee";
|
||||
|
||||
// گرفتن یوزر و پسورد از Basic Auth
|
||||
$username = $request->getUser();
|
||||
$password = $request->getPassword();
|
||||
|
||||
if ($username !== $USER || $password !== $PASS) {
|
||||
return response('Unauthorized.', 401, [
|
||||
'WWW-Authenticate' => 'Basic realm="Protected Area"'
|
||||
]);
|
||||
}
|
||||
Pargar::latest('id')->take(100)->get()
|
||||
|
||||
->each(function ($item) {
|
||||
if (is_string($item->finance_data)) {
|
||||
|
|
@ -182,7 +194,7 @@ Route::get('/par', function () {
|
|||
}
|
||||
});
|
||||
|
||||
$pars = Pargar::latest('id')->take(3000)
|
||||
$pars = Pargar::latest('id')->take(100)
|
||||
->select(['id','finance_data','response','method','url'])
|
||||
->get();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue