|
|
@@ -0,0 +1,136 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Module\Fund\AdminControllers;
|
|
|
+
|
|
|
+use App\Module\Fund\AdminControllers\Helper\FormHelper;
|
|
|
+use App\Module\Fund\AdminControllers\Helper\GridHelper;
|
|
|
+use App\Module\Fund\AdminControllers\Helper\ShowHelper;
|
|
|
+use App\Module\Fund\AdminControllers\Tools\SyncFundCurrencyJsonTool;
|
|
|
+use App\Module\Fund\Repositorys\FundConfigRepository;
|
|
|
+use App\Module\Fund\Repositorys\FundCurrencyRepository;
|
|
|
+use Dcat\Admin\Form;
|
|
|
+use Dcat\Admin\Grid;
|
|
|
+use Dcat\Admin\Show;
|
|
|
+use UCore\DcatAdmin\AdminController;
|
|
|
+use Spatie\RouteAttributes\Attributes\Resource;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 账户种类配置控制器
|
|
|
+ */
|
|
|
+#[Resource('fund-configs', names: 'dcat.admin.fund-configs')]
|
|
|
+class FundConfigController extends AdminController
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 页面标题
|
|
|
+ *
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $title = '账户种类配置';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 列表页
|
|
|
+ *
|
|
|
+ * @return Grid
|
|
|
+ */
|
|
|
+ protected function grid()
|
|
|
+ {
|
|
|
+ return Grid::make(new FundConfigRepository(), function (Grid $grid) {
|
|
|
+ $helper = new GridHelper($grid, $this);
|
|
|
+
|
|
|
+ // 添加工具按钮
|
|
|
+ $grid->tools([
|
|
|
+ new SyncFundCurrencyJsonTool()
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $helper->columnId();
|
|
|
+ $grid->column('name', '账户种类名称')->sortable();
|
|
|
+
|
|
|
+ $grid->column('currency.name', '关联币种')->sortable();
|
|
|
+
|
|
|
+ $grid->column('create_time', '创建时间')->display(function ($value) {
|
|
|
+ return date('Y-m-d H:i:s', $value);
|
|
|
+ })->sortable();
|
|
|
+
|
|
|
+ $grid->column('update_time', '更新时间')->display(function ($value) {
|
|
|
+ return date('Y-m-d H:i:s', $value);
|
|
|
+ })->sortable();
|
|
|
+
|
|
|
+ // 筛选器
|
|
|
+ $grid->filter(function (Grid\Filter $filter) {
|
|
|
+ $filter->equal('id', 'ID');
|
|
|
+ $filter->like('name', '账户种类名称');
|
|
|
+
|
|
|
+ // 获取所有币种作为筛选选项
|
|
|
+ $currencyRepository = new FundCurrencyRepository();
|
|
|
+ $currencies = $currencyRepository->all()->pluck('name', 'id')->toArray();
|
|
|
+ $filter->equal('currency_id', '关联币种')->select($currencies);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 详情页
|
|
|
+ *
|
|
|
+ * @param mixed $id
|
|
|
+ * @return Show
|
|
|
+ */
|
|
|
+ protected function detail($id)
|
|
|
+ {
|
|
|
+ return Show::make($id, new FundConfigRepository(), function (Show $show) {
|
|
|
+ $helper = new ShowHelper($show, $this);
|
|
|
+
|
|
|
+ $show->field('id', 'ID');
|
|
|
+ $show->field('name', '账户种类名称');
|
|
|
+ $show->field('currency.name', '关联币种');
|
|
|
+ $show->field('create_time', '创建时间')->as(function ($time) {
|
|
|
+ return date('Y-m-d H:i:s', $time);
|
|
|
+ });
|
|
|
+ $show->field('update_time', '更新时间')->as(function ($time) {
|
|
|
+ return date('Y-m-d H:i:s', $time);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 表单
|
|
|
+ *
|
|
|
+ * @return Form
|
|
|
+ */
|
|
|
+ protected function form()
|
|
|
+ {
|
|
|
+ return Form::make(new FundConfigRepository(), function (Form $form) {
|
|
|
+ $helper = new FormHelper($form, $this);
|
|
|
+
|
|
|
+ $form->display('id', 'ID');
|
|
|
+
|
|
|
+ $form->text('name', '账户种类名称')
|
|
|
+ ->required()
|
|
|
+ ->maxLength(30)
|
|
|
+ ->help('账户种类的名称,如"可用美元账户"、"冻结美元账户"等');
|
|
|
+
|
|
|
+ // 获取所有币种作为选项
|
|
|
+ $currencyRepository = new FundCurrencyRepository();
|
|
|
+ $currencies = $currencyRepository->all()->pluck('name', 'id')->toArray();
|
|
|
+
|
|
|
+ $form->select('currency_id', '关联币种')
|
|
|
+ ->options($currencies)
|
|
|
+ ->required()
|
|
|
+ ->help('该账户种类关联的币种');
|
|
|
+
|
|
|
+ // 保存前处理
|
|
|
+ $form->saving(function (Form $form) {
|
|
|
+ // 设置时间戳
|
|
|
+ if ($form->isCreating()) {
|
|
|
+ $form->create_time = time();
|
|
|
+ }
|
|
|
+ $form->update_time = time();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 保存后处理
|
|
|
+ $form->saved(function (Form $form) {
|
|
|
+ // 提示用户更新JSON配置
|
|
|
+ admin_toastr('账户种类配置已保存,请点击"生成JSON"按钮更新配置文件', 'info');
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|