/
home
/
pay
/
server
/
app
/
Http
/
Controllers
/
Site
/
File Upload :
llllll
Current File: /home/pay/server/app/Http/Controllers/Site/ReportController.php
<?php namespace App\Http\Controllers\Site; use App\Http\Controllers\Admin\PriceController; use App\Http\Controllers\Controller; use App\Mail\YourMailableClass; use App\Models\Cnt; use App\Models\ConfigStatic; use App\Models\Customer; use App\Models\Price; use App\Models\PriceCandle; use App\Models\PriceTrigger; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Mail; use Morilog\Jalali\Jalalian; class ReportController extends Controller { public function candleChart() { $candle = PriceCandle::select(["start", "high", "low", "end", "date_at"])->whereDate('date_at', '<=', date("Y-m-d")) ->whereDate('date_at', '>', Carbon::now()->subDays(30)->format("Y-m-d")) ->get()->toArray(); $a = []; foreach ($candle as $c) { $create['date'] = $c["date_at"]; unset($c["date_at"]); $create['candle'] = array_values($c); $a[] = array_values($create); } return response()->json($a); } public function updatePrise() { $difference = config('fee.single'); $lastPrice = Price::latest()->first(); $PriceTriggers = PriceTrigger::where("is_active", true)->get(); foreach ($PriceTriggers as $PriceTrigger) { $priseGold = $PriceTrigger->dirction == 1 ? $lastPrice->price - $difference : ($PriceTrigger->dirction == 2 ? $lastPrice->price + $difference : $lastPrice->price); if (eval('return $priseGold ' . $PriceTrigger->price_condition . ' $PriceTrigger->target_price;')) { $customer = Customer::find($PriceTrigger->customer_id); $message = "قیمت طلا به " . number_format($priseGold, -1) . " در هر گرم رسید\n" .$this->Config('name_fa'); if ($PriceTrigger->action == 'email') { Mail::to("$customer->email")->send(new YourMailableClass($message, '', '', '', '')); } elseif ($PriceTrigger->action == 'sms') { $this->send($customer->mobile, $message); } $PriceTrigger->is_active = false; $PriceTrigger->triggered_at = Carbon::now(); $PriceTrigger->save(); } } return response()->json(); } public function upDownPrice() { $difference = config('fee.single'); $today = Carbon::now()->format("Y-m-d"); $prises = Price::where('date_at', $today)->get("price"); $minP = 0; // Initialize to the highest possible value $maxP = 0; // Initialize to the lowest possible value foreach ($prises as $p) { // Initialize $minP to the first price if it's null if ($minP == 0 || $p->price < $minP) { $minP = $p->price; } // Initialize $maxP to the first price if it's null if ($maxP == 0 || $p->price > $maxP) { $maxP = $p->price; } } if (count($prises) === 0) { // Fetching the current gold price from the API $response = Http::get('https://www.tala.ir/ajax/price'); $data = $response->json(); // Clean the price value retrieved from API $data['gold']['gold_18k']['v'] = str_replace(',', '', $data['gold']['gold_18k']['v']); $priceValue = $data['gold']['gold_18k']['v'] * 10; // Assuming the multiplication by 10 is needed // Create and save the new Price instance $price = new Price(); $price->price = $priceValue; // Assign the cleaned and calculated price value $price->time_at = Carbon::now()->toTimeString(); // Set current time $price->date_at = Carbon::now()->toDateString(); // Set current date $price->save(); // Save to the database return ['sell' => $price->price - $difference, 'buy' => $price->price + $difference]; } else { // Assuming $minP and $maxP are defined elsewhere in your code return ['sell' => $minP - $difference, 'buy' => $maxP + $difference]; } // return $prises; // $add_sell_price = config('add_sell_price.major'); // $price = PriceCandle::whereDate('date_at',)->first(); // $price_price = Price::orderBy('id','desc')->first(); } public function lastPrice() { $difference = config('fee.single'); try { $henzagold = Http::timeout(2)->get('https://henzagold.com/oapi/api/price')->json(); $henzagold_18 = (int)str_replace(',', '', collect($henzagold)->firstWhere('slug', 'gold18')['p']); $henzagold_ons_gold = (int)str_replace(',', '', collect($henzagold)->firstWhere('slug', 'ons_gold')['p']); } catch (\Exception $e) {$henzagold_18 = $henzagold_ons_gold = 0;} $henzagold_18 = $henzagold_ons_gold = 0; try { $tala_ir = (int)str_replace(',', '', Http::timeout(2)->get('https://www.tala.ir/ajax/price')->json()['gold']['gold_18k']['v']) * 10; } catch (\Exception $e) {$tala_ir = 0;} try { $milli = Http::timeout(2)->get('https://milli.gold/api/v1/public/milli-price/detail')->json()['price18'] * 1000 ; } catch (\Exception $e) {$milli = 0;} $priceValue = $milli-210000;//4000 $lastPrice = Price::latest()->first(); if (!$lastPrice || $lastPrice->price != $priceValue and $priceValue > 30000000) { $price = new Price(); $price->price = $priceValue; // Assign the cleaned price value $price->time_at = Carbon::now()->toTimeString(); $price->date_at = Carbon::now()->toDateString(); $price->save(); $this->updatePrise(); $candle = PriceCandle::whereDate('date_at',date("Y-m-d"))->first(); if (!is_null($candle)){ $candle->end = $priceValue; if ($priceValue < $candle->low){ $candle->low = $priceValue;} elseif ($priceValue > $candle->high){ $candle->high = $priceValue;}$candle->save(); }else{ PriceCandle::create([ "start"=>$priceValue, "end"=>$priceValue, "high"=>$priceValue, "low"=>$priceValue, "date_at"=>date("Y-m-d") ]); } } $price = Price::orderBy('id', 'desc')->first(); if ($price) { return [ 'sell' => $price->price - $difference, 'buy' => $price->price + $difference, 'price_last' => $price->price + $difference, 'tala_ir' => $tala_ir, 'henzagold' => $henzagold_18, 'Ounce' => $henzagold_ons_gold, 'milli' => $milli, ]; } else { return []; } } public function check() { $service = Http:: withHeaders([ 'accept' => 'application/json', 'Authorization' => 'Bearer ohxsrbjagqvbt0glaygt' ])->get('https://studio.persianapi.com/index.php/web-service/common/gold-currency-coin?format=json&limit=30&page=1') ->json(); $list = []; if (isset($service['result'])) { foreach ($service['result'] as $item) { if ($item['key'] == 137120 || $item['key'] == 137119) { $list[] = $item; if ($item['key'] == 137120) { (new PriceController())->store(new Request(["price" => $item['price']])); } } } Cnt::where('key', 'price')->update(['value_json' => $list]); } } public function test() { $a = '{{12, 23, {4, 0, {1}, {1}}}, 0, {1}}'; $b = str_split($a); $c = []; $str = ""; foreach ($b as $item) { if ($item != " ") { print_r($item); print_r('++'); if ($item == ',' || $item == '}') { if (!in_array($c[count($c) - 1], ['{', '}'])) { $c[count($c) - 1] += (int)$str; print_r((int)$str); print_r('^^'); } else { $c[] = $str; print_r($c); print_r('&&'); } $str = ""; } elseif (in_array($item, ['{', '}'])) { $c[] = $item; print_r($c); print_r('**'); } else { $str .= $item; print_r($str); print_r('@@'); } } } dd($c); $d = []; $e = []; foreach ($c as $item) { if ($item == '}') { print_r($d[count($d) - 1]); print_r('***'); $e[] = $d[count($d) - 1]; } else { $d[] = $item; print_r($d); print_r('-----'); } } dd($e); } }
Copyright ©2k19 -
Hexid
|
Tex7ure