config service for show liman price
This commit is contained in:
@@ -2,17 +2,17 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use League\Flysystem\Config;
|
||||
use App\Models\Setting;
|
||||
|
||||
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;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use League\Flysystem\Config;
|
||||
use app\services\ConfigService;
|
||||
|
||||
class LimanService
|
||||
{
|
||||
public function liman_login(){
|
||||
$mobile = app(ConfigService::class)->Config('liman_mobile');
|
||||
$password = app(ConfigService::class)->Config('liman_password');
|
||||
public function liman_login()
|
||||
{
|
||||
$config = app(ConfigService::class);
|
||||
|
||||
$liman = Http::post('http://212.23.201.173/server/auth/login', [
|
||||
'mobile' => $mobile,//شماره اکانت اپلیکیشن هنزا تو لیمان ایدی 1377
|
||||
$mobile = $config->Config('liman_mobile');
|
||||
$password = $config->Config('liman_password');
|
||||
|
||||
$liman = Http::timeout(10)->post('http://212.23.201.173/server/auth/login', [
|
||||
'mobile' => $mobile,
|
||||
'password' => $password,
|
||||
'provider' => 'customer',
|
||||
'type_app' => 'client',
|
||||
])->json();
|
||||
|
||||
app(ConfigService::class)->UpdateConfig('liman_token', $liman['token']);
|
||||
return $liman['access_token'];
|
||||
$token = $liman['access_token'] ?? $liman['token'] ?? null;
|
||||
|
||||
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