6
0
Fork 0
jiqu-library-server/app/Admin/Forms/Settings/Distribution.php

69 lines
1.9 KiB
PHP

<?php
namespace App\Admin\Forms\Settings;
use App\Models\Setting;
use App\Services\{SettingService, DistributeService};
use Dcat\Admin\Widgets\Form;
/**
* 分销设置
*/
class Distribution extends Form
{
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
Setting::where('key', 'distribution')->updateOrCreate([
'key' => 'distribution',
], ['value' => $input]);
//清配置缓存
app(SettingService::class)->cleanCache('distribution');
return $this
->response()
->success('配置更新成功!')
->refresh();
}
/**
* Build a form here.
*/
public function form()
{
$values = Setting::where('key', 'distribution')->value('value');
$levels = DistributeService::$levels;
$favoite = $levels['favoite'];
$agent = $levels['agent'];
$this->fieldset('爱好者-返利', function (Form $form) use ($favoite) {
foreach($favoite as $item) {
$form->number('favoite-profit-' . $item['level'], $item['name'])->min(0)->max(100)->help('例如: 40, 即表示: 40%');
}
});
$this->fieldset('爱好者-升级', function (Form $form) use ($favoite) {
foreach($favoite as $item) {
$form->number('favoite-level-' . $item['level'], $item['name'])->min(0)->help('例如: 1000');
}
})->collapsed();
$this->fieldset('代理-返利', function (Form $form) use ($agent) {
foreach($agent as $item) {
$form->number('agent-profit-' . $item['level'], $item['name'])->min(0)->max(100)->help('例如: 40, 即表示: 40%');
}
})->collapsed();
}
public function default()
{
$values = Setting::where('key', 'distribution')->value('value');
return $values;
}
}