SystemSettingController.php
8.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
* 管理端控制层: SystemSetting 控制类
+-----------------------------------------------------------------------------------------------------------------------
*
* PHP version 7
*
* @category App\Admin\Controllers\System
* @package App\Admin\Controllers\System
* @author Richer <yangzi1028@163.com>
* @date 2021年1月27日10:57:55
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
namespace App\Admin\Controllers\System;
use App\Admin\Controllers\BaseController;
use App\Admin\Rewrite\Form;
use App\Models\System\SystemSetting;
use Encore\Admin\Form\Tools;
use Encore\Admin\Layout\Content;
use Illuminate\Http\Response;
/**
* Class SystemSettingController.
*
* @category App\Admin\Controllers\System
* @package App\Admin\Controllers\System
* @author Richer <yangzi1028@163.com>
* @date 2021年1月27日10:57:55
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
class SystemSettingController extends BaseController
{
/**
* SystemSettingController constructor.
*
* @param SystemSetting $model 注入model
*/
public function __construct(SystemSetting $model)
{
// 资源显示的中名称
$this ->title = $model::OBJ_NAME;
// 是否可查看
$this->can_view = false;
// 是否可新增
$this->can_create = true;
// 是否可编辑
$this->can_edit = true;
// 是否可删除
$this->can_delete = true;
// 是否开启下拉菜单
$this->dropdownActions = false;
// 执行父类构造方法
parent::__construct($model);
}
/**
* User setting page.
*
* @param Content $content
*
* @return Content
*/
public function getSetting(Content $content)
{
// 获取 boss
$boss = $this->model->first();
$form = $this->settingForm();
$form->tools(
function (Tools $tools) {
$tools->disableList();
$tools->disableDelete();
$tools->disableView();
}
);
if ($boss) {
return $content
->title(trans('admin.user_setting'))
->body($form->edit(optional($boss)->id));
} else {
return $content
->title(trans('admin.user_setting'))
->body($form);
}
}
/**
* Update setting.
*
* @return bool|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function postSetting()
{
return $this->settingForm()->store();
}
/**
* Update user setting.
*
* @return array|bool|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Routing\Redirector|mixed|\Symfony\Component\HttpFoundation\Response|null
*/
public function putSetting()
{
return $this->settingForm()->update(1);
}
/**
* Model-form for user setting.
*
* @return Form
*/
protected function settingForm()
{
$this->form = new Form($this->model);
$this->formNumberField('consumption_times', '每次提问消耗次数');
$this->formNumberField('context_timeout', '上下文超时时间')->help('单位,分钟,提问后超过该时间,上下文自动清空,下次提问不会携带上下文信息');
// $this->formTextField('start_statement', '提问起始语', 255, 1);
$this->formSliderField('primary_distribution_rate', '', 1)->help('一级分销用户返现比例');
$this->formSliderField('secondary_distribution_rate', '', 1)->help('二级分销用户返现比例');
$this->form->setAction(admin_url('system-setting'));
$this->form->saved(function () {
admin_toastr(trans('admin.update_succeeded'));
return redirect(admin_url('system-setting'));
});
return $this->form;
}
/**
* Model-form for user setting.
*
* @return Form
*/
protected function settingForm1()
{
$form = new Form($this->model);
$this->form = $form;
// $form->radio('type', __('self_purchase_cashback_rate'))
// ->options(User::ROLE_TYPE_OPTIONS)->when(1, function (Form $form) {
//
// $form->text('name', '姓名');
// $form->text('idcard', '身份证');
//
// })->when(2, function (Form $form) {
//
// $form->text('name', '姓名');
// $form->text('passport', '护照');
//
// });
$options = [
'max' => 100, 'min' => 0, 'step' => 1, 'postfix' => ' %',
'lineFillStyle' => '#0094ff', 'lineFillStyleGray' => '#cac7c7'
];
// $this->formSliderField('points_exchange_rate', '', 1);
$this->formNumberField('points_deduct_rate', '', 1, 1, 1, 1, 1000)->help('多少积分可抵扣 1 元;例如10积分抵扣1元');
$this->formSliderField('points_deduct_limit', '', 1)->help(__('每笔订单总金额的抵扣积分上限!'));
// $this->form->rate('withdrawal_fee',__('withdrawal_fee'));
// $this->formRateField('withdrawal_fee', '', 1);
$this->formSliderField('withdrawal_fee', '', 1, 1, 1, 1000, 1, '‰')->help(__('用户提现平台收取手续费比例!'));
$this->formSliderField('goods_discount_rate', '', 1)->help(__('犒劳自己或转赠他人,不想要商品话,用户实际付款进行折现比例!'));
$this->form->embeds('cash_recharge_card_discount_rate', __('cash_recharge_card_discount_rate'), function ($form) use ($options) {
$form->slider('general', '普通用户')->options($options)->rules('required')->setGroupClass('col-sm-12 clear-both')->setWidth(10, 1);
$form->slider('enterprise', '企业用户')->options($options)->rules('required')->setGroupClass('col-sm-12 clear-both')->setWidth(10, 1);
// $form->currency('general', '普通用户')->rules('required');
// $form->currency('enterprise', '企业用户')->rules('required');
});//->setGroupClass('col-sm-12 clear-both')->setWidth('1', 10);
$this->form->embeds('fixed_gift_card_discount_rate', __('fixed_gift_card_discount_rate'), function ($form) use ($options) {
$form->slider('general', '普通用户')->options($options)->rules('required')->setGroupClass('col-sm-12 clear-both')->setWidth(10, 1);
$form->slider('enterprise', '企业用户')->options($options)->rules('required')->setGroupClass('col-sm-12 clear-both')->setWidth(10, 1);
});
$this->form->embeds('package_gift_card_discount_rate', __('package_gift_card_discount_rate'), function ($form) use ($options) {
$form->slider('general', '普通用户')->options($options)->rules('required')->setGroupClass('col-sm-12 clear-both')->setWidth(10, 1);
$form->slider('enterprise', '企业用户')->options($options)->rules('required')->setGroupClass('col-sm-12 clear-both')->setWidth(10, 1);
});
$this->formNumberField('share_link_limit', '', 1)->help(__('礼包分享链接有效性设置,单位:分钟'));
$this->formNumberField('invitation_points', '', 1)->help('邀请人获得积分');
$this->formNumberField('invited_points', '', 1)->help('被邀请人获得积分');
$this->formSliderField('self_purchase_cashback_rate', '', 1)->help('购买商品用户返现比例');
$this->formSliderField('primary_distribution_rate', '', 1)->help('购买商品一级分销用户返现比例');
$this->formSliderField('secondary_distribution_rate', '', 1)->help('购买商品二级分销用户返现比例');
$this->form->setAction(admin_url('system-setting'));
$this->form->saving(function () {
// dd(request()->all());
});
$this->form->saved(function () {
admin_toastr(trans('admin.update_succeeded'));
return redirect(admin_url('system-setting'));
});
return $this->form;
}
}