From 771c3cf7ff22c0977ee8569794813eb9abb23aa2 Mon Sep 17 00:00:00 2001 From: liapples Date: Fri, 27 Aug 2021 00:56:13 +0800 Subject: [PATCH] =?UTF-8?q?AgentSetting=E5=A2=9E=E5=8A=A0scopeVal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/TestController.php | 4 +++- app/Models/AgentSetting.php | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/TestController.php b/app/Http/Controllers/Api/TestController.php index 5eeeada..9626a91 100644 --- a/app/Http/Controllers/Api/TestController.php +++ b/app/Http/Controllers/Api/TestController.php @@ -3,6 +3,8 @@ namespace App\Http\Controllers\Api; use App\Models\Agent; +use App\Models\AgentSetting; +use Illuminate\Support\Facades\DB; /** * 仅用于测试 @@ -14,6 +16,6 @@ class TestController public function index() { //test - return Agent::query()->where(['appid' => 'wxb35ef055a4dd8ad4', 'status' => 1])->value('id'); + return AgentSetting::val(1, 'earnest') ?? 198.88; } } diff --git a/app/Models/AgentSetting.php b/app/Models/AgentSetting.php index 0e9ed1e..83cded3 100644 --- a/app/Models/AgentSetting.php +++ b/app/Models/AgentSetting.php @@ -15,4 +15,10 @@ class AgentSetting extends BaseModel parent::__construct($attributes); $this->timestamps = false; } + + public function scopeVal($query, $agent_id, $key) + { + $setting = json_decode($query->where('agent_id', $agent_id)->value('setting'), true); + return $setting[$key] ?? null; + } }