129 lines
4.1 KiB
PHP
129 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Forms\Settings;
|
|
|
|
use App\Models\Setting;
|
|
use App\Services\SettingService;
|
|
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()
|
|
{
|
|
$appSettings = (array) Setting::where('key', 'distribution')->value('value');
|
|
|
|
// dd(config('distribution'), app_settings('distribution'));
|
|
|
|
$this->text('settle_days', '订单结算时间(天)')
|
|
->value($appSettings['settle_days'] ?? 0)
|
|
->rules('required|numeric|min:0')
|
|
->help('从订单完成到结算收益的间隔天数');
|
|
|
|
$this->text('price_diff_fee_rate', '会员差价手续费')
|
|
->prepend('%')
|
|
->value($appSettings['price_diff_fee_rate'] ?? 0)
|
|
->rules('required|int|min:0|max:100')
|
|
->saving(function ($value) {
|
|
return $value/100;
|
|
})
|
|
->customFormat(function ($value) {
|
|
return $value*100;
|
|
});
|
|
|
|
$this->text('lvl_same_bonus_fee_rate', '平级奖励手续费')
|
|
->prepend('%')
|
|
->value($appSettings['lvl_same_bonus_fee_rate'] ?? 0)
|
|
->rules('required|int|min:0|max:100')
|
|
->saving(function ($value) {
|
|
return $value/100;
|
|
})
|
|
->customFormat(function ($value) {
|
|
return $value*100;
|
|
});
|
|
|
|
$this->text('lvl_diff_bonus_fee_rate', '级差奖励手续费')
|
|
->prepend('%')
|
|
->value($appSettings['lvl_diff_bonus_fee_rate'] ?? 0)
|
|
->rules('required|int|min:0|max:100')
|
|
->saving(function ($value) {
|
|
return $value/100;
|
|
})
|
|
->customFormat(function ($value) {
|
|
return $value*100;
|
|
});
|
|
|
|
$this->text('quota_v2_rate', '获得配额比例')
|
|
->prepend('%')
|
|
->value($appSettings['quota_v2_rate'] ?? 0)
|
|
->rules('required|int|min:0|max:100')
|
|
->saving(function ($value) {
|
|
return $value/100;
|
|
})
|
|
->customFormat(function ($value) {
|
|
return $value*100;
|
|
});
|
|
|
|
// $this->divider();
|
|
$this->table('rules', '规则', function ($table) {
|
|
$table->hidden('lv_key');
|
|
$table->text('lv_name_show', '等级名称')->disable();
|
|
$table->hidden('lv_name');
|
|
$table->text('lvl_same_bonus_rate', '平级奖励比例')
|
|
->prepend('%')
|
|
->rules('required|int|min:0|max:100')
|
|
->saving(function ($value) {
|
|
return $value/100;
|
|
})
|
|
->customFormat(function ($value) {
|
|
return $value*100;
|
|
});
|
|
|
|
$table->text('lvl_diff_bonus_rate', '级差奖励比例')
|
|
->prepend('%')
|
|
->rules('required|int|min:0|max:100')
|
|
->saving(function ($value) {
|
|
return $value/100;
|
|
})
|
|
->customFormat(function ($value) {
|
|
return $value*100;
|
|
});
|
|
})->customFormat(function ($v) use ($appSettings) {
|
|
$_rules = $appSettings['rules'] ?? [];
|
|
if ($_rules) {
|
|
foreach ($_rules as $key => &$rule) {
|
|
$rule['lv_key'] = $key;
|
|
$rule['lv_name_show'] = $rule['lv_name'];
|
|
}
|
|
}
|
|
return $_rules;
|
|
})->saving(function ($v) {
|
|
return collect($v)->keyBy('lv_key')->toArray();
|
|
})->disableCreate()->disableDelete();
|
|
}
|
|
}
|