diff --git a/app/AdminAgent/Forms/Setting.php b/app/AdminAgent/Forms/Setting.php index 3a4ff26..bba4d94 100644 --- a/app/AdminAgent/Forms/Setting.php +++ b/app/AdminAgent/Forms/Setting.php @@ -21,7 +21,7 @@ class Setting extends Form AgentSetting::updateOrCreate( ['agent_id' => Admin::user()->id], - ['setting' => json_encode($input), 'agent_id' => Admin::user()->id], + ['setting' => $input, 'agent_id' => Admin::user()->id], ); return $this->response()->success('保存成功')->refresh(); @@ -32,8 +32,10 @@ class Setting extends Form */ public function form() { - $this->text('earnest')->required()->help('用户支付订金、定金、首付款的金额'); - $this->text('earnest_timeout')->required()->help('单位:分钟。当通过订金、定金、首付款支付时,用户超过该时间未支付将关闭订单,且定金不退'); + $this->text('order_timeout')->required()->default(1440) + ->help('订单超时时间,单位:分钟。(订金、定金支付的超时时间将根据产品设定的超时时间)'); + $this->radio('auto_shelves')->options(['否', '是'])->required()->default(1) + ->help('是否自动上架合作供应商的产品,如果选是,当合作供应商发布新产品之后,将自动上架供应商的产品'); } /** @@ -44,6 +46,6 @@ class Setting extends Form public function default() { $setting = AgentSetting::where('agent_id', Admin::user()->id)->value('setting'); - return is_string($setting) ? json_decode($setting, true) : []; + return $setting ?? []; } } diff --git a/app/Http/Controllers/Api/TestController.php b/app/Http/Controllers/Api/TestController.php index 9626a91..337df8d 100644 --- a/app/Http/Controllers/Api/TestController.php +++ b/app/Http/Controllers/Api/TestController.php @@ -16,6 +16,6 @@ class TestController public function index() { //test - return AgentSetting::val(1, 'earnest') ?? 198.88; + return AgentSetting::val(11, 'order_timeout') ?? 188; } } diff --git a/app/Models/AgentSetting.php b/app/Models/AgentSetting.php index 83cded3..1a9fffc 100644 --- a/app/Models/AgentSetting.php +++ b/app/Models/AgentSetting.php @@ -9,6 +9,7 @@ class AgentSetting extends BaseModel use HasFactory; protected $fillable = ['agent_id', 'setting']; + protected $casts = ['setting' => 'json']; public function __construct(array $attributes = []) { @@ -16,9 +17,9 @@ class AgentSetting extends BaseModel $this->timestamps = false; } - public function scopeVal($query, $agent_id, $key) + public static function val($agent_id, $key) { - $setting = json_decode($query->where('agent_id', $agent_id)->value('setting'), true); + $setting = static::query()->where('agent_id', $agent_id)->value('setting'); return $setting[$key] ?? null; } } diff --git a/resources/lang/zh_CN/setting.php b/resources/lang/zh_CN/setting.php index 19a7f60..3c2ab7f 100644 --- a/resources/lang/zh_CN/setting.php +++ b/resources/lang/zh_CN/setting.php @@ -5,8 +5,8 @@ return [ 'setting' => '系统设置', ], 'fields' => [ - 'earnest' => '定金金额', - 'earnest_timeout' => '定金支付超时时间', + 'order_timeout' => '订单超时时间', + 'auto_shelves' => '自动上架', ], 'options' => [ ],