config service for show liman price
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Models\Cnt;
|
|||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Models\ConfigStatic;
|
use App\Models\ConfigStatic;
|
||||||
use App\Models\Customer;
|
use App\Models\Customer;
|
||||||
|
use App\Services\LimanService;
|
||||||
use App\Models\Price;
|
use App\Models\Price;
|
||||||
use App\Models\PriceCandle;
|
use App\Models\PriceCandle;
|
||||||
use App\Models\PriceTrigger;
|
use App\Models\PriceTrigger;
|
||||||
@@ -211,16 +212,15 @@ class ReportController extends Controller
|
|||||||
CURLOPT_TCP_FASTOPEN => 1,
|
CURLOPT_TCP_FASTOPEN => 1,
|
||||||
]
|
]
|
||||||
])
|
])
|
||||||
->withToken(Cnt::where('key', 'liman')->value('value'))
|
->withToken(Setting::where('key', 'liman_token')->value('value'))
|
||||||
->get('http://212.23.201.173/server/customer/product/list')
|
->get('http://212.23.201.173/server/customer/product/list')
|
||||||
->json();
|
->json();
|
||||||
|
|
||||||
if ((isset($liman['message']) && $liman['message'] == 'no authorised') || $liman == null) {
|
if ((isset($liman['message']) && $liman['message'] == 'no authorised') || $liman == null) {
|
||||||
$cnt = new Cnt();
|
$newToken = app(LimanService::class)->liman_login();
|
||||||
$cnt->liman_login();
|
|
||||||
|
|
||||||
$liman = Http::timeout(2)
|
$liman = Http::timeout(7)
|
||||||
->withToken(Cnt::where('key', 'liman')->value('value'))
|
->withToken($newToken)
|
||||||
->get('http://212.23.201.173/server/customer/product/list')
|
->get('http://212.23.201.173/server/customer/product/list')
|
||||||
->json();
|
->json();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,17 @@
|
|||||||
|
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Http;
|
use App\Models\Setting;
|
||||||
use League\Flysystem\Config;
|
|
||||||
|
|
||||||
class ConfigService
|
class ConfigService
|
||||||
{
|
{
|
||||||
public static function Config($name)
|
public function Config($name)
|
||||||
{
|
{
|
||||||
return Setting::where('key',$name)->first()->value ?? false;
|
return Setting::where('key', $name)->value('value') ?? false;
|
||||||
}
|
}
|
||||||
public static function UpdateConfig($name,$value)
|
|
||||||
|
public function UpdateConfig($name, $value)
|
||||||
{
|
{
|
||||||
return Setting::where('key',$name)->update(['value'=>$value]);
|
return Setting::where('key', $name)->update(['value' => $value]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,23 +3,31 @@
|
|||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use League\Flysystem\Config;
|
|
||||||
use app\services\ConfigService;
|
|
||||||
|
|
||||||
class LimanService
|
class LimanService
|
||||||
{
|
{
|
||||||
public function liman_login(){
|
public function liman_login()
|
||||||
$mobile = app(ConfigService::class)->Config('liman_mobile');
|
{
|
||||||
$password = app(ConfigService::class)->Config('liman_password');
|
$config = app(ConfigService::class);
|
||||||
|
|
||||||
$liman = Http::post('http://212.23.201.173/server/auth/login', [
|
$mobile = $config->Config('liman_mobile');
|
||||||
'mobile' => $mobile,//شماره اکانت اپلیکیشن هنزا تو لیمان ایدی 1377
|
$password = $config->Config('liman_password');
|
||||||
|
|
||||||
|
$liman = Http::timeout(10)->post('http://212.23.201.173/server/auth/login', [
|
||||||
|
'mobile' => $mobile,
|
||||||
'password' => $password,
|
'password' => $password,
|
||||||
'provider' => 'customer',
|
'provider' => 'customer',
|
||||||
'type_app' => 'client',
|
'type_app' => 'client',
|
||||||
])->json();
|
])->json();
|
||||||
|
|
||||||
app(ConfigService::class)->UpdateConfig('liman_token', $liman['token']);
|
$token = $liman['access_token'] ?? $liman['token'] ?? null;
|
||||||
return $liman['access_token'];
|
|
||||||
|
if (!$token) {
|
||||||
|
throw new \Exception('Liman login failed: ' . json_encode($liman, JSON_UNESCAPED_UNICODE));
|
||||||
|
}
|
||||||
|
|
||||||
|
$config->UpdateConfig('liman_token', $token);
|
||||||
|
|
||||||
|
return $token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user