Преглед изворни кода

refactor(fund): 重构资金模块

- 修改资金操作标题为"操作资金"
- 优化资金操作表单逻辑
- 添加金额范围筛选功能
- 重构资金流通、资金、资金日志、资金订单控制器
- 更新资金类型枚举
- 优化日志类型枚举
- 重构资金服务类
- 新增基础日志类
- 优化表单组件
Your Name пре 8 месеци
родитељ
комит
3f67ba6641

+ 41 - 0
UCore/DcatAdmin/ActionLog/BaseLog.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace UCore\DcatAdmin\ActionLog;
+
+use App\Module\System\Models\AdminActionlog;
+
+
+abstract class BaseLog implements InterfaceLog
+{
+
+    public $objectClass;
+    public $admin_id;
+    public $before;
+    public $after;
+    public $url;
+    public $unid   = RUN_UNIQID;
+    public $status = 0;
+    public $p1 = null;
+
+    public function __destruct()
+    {
+
+        $model               = new AdminActionlog();
+        $model->object_class = $this->objectClass;
+        $model->admin_id     = $this->admin_id;
+        $model->before       = $this->before??[];
+        if(!$this->after){
+            $this->after = 'is null or empty ';
+        }
+        $model->after        = $this->after;
+        $model->url          = $this->url;
+        $model->unid         = $this->unid;
+        $model->type1        = static::TYPE;
+        $model->status       = $this->status;
+        $model->p1        = serialize($this->p1);
+
+        $model->save();
+
+    }
+
+}

+ 5 - 0
UCore/DcatAdmin/Widgets/Form.php

@@ -106,5 +106,10 @@ class Form extends BaseForm
     }
 
 
+    protected function getAdminId()
+    {
+        return Admin::user()->id;
+
+    }
 
 }

+ 1 - 1
app/Module/Fund/Admin/Actions/FundAdminAction.php

@@ -13,7 +13,7 @@ use UCore\DcatAdmin\RowAction;
 class FundAdminAction extends RowAction
 {
 
-    protected $title = '管理员';
+    protected $title = '操作资金';
 
 
 

+ 12 - 6
app/Module/Fund/Admin/Actions/FundAdminForm.php

@@ -5,9 +5,12 @@ namespace App\Module\Fund\Admin\Actions;
 
 
 use App\Module\Fund\Models\FundModel;
+use App\Module\Fund\Services\FundService;
+use Dcat\Admin\Admin;
 use Dcat\Admin\Traits\LazyWidget;
 use Dcat\Admin\Contracts\LazyRenderable;
 use UCore\DcatAdmin\Widgets\Form;
+use UCore\Helper\Logger;
 
 
 /**
@@ -18,25 +21,28 @@ class FundAdminForm extends Form implements LazyRenderable
 {
 
     use LazyWidget;
+
     protected string $trans_path = 'fund.form';
 
 
     public function run($input)
     {
-        $id = $this->payload['id'] ?? null;
-        $add = $input['add'];
+        $id     = $this->payload['id'] ?? null;
+        $add    = $input['add'];
         $remark = $input['remark'];
         if (!$id) {
             return $this->error('input-error');
         }
-
+        $admin_id = $this->getAdminId();
         $funddata = FundModel::query()->find($id);
-        $admin = new AdminS();
-        $re18  = $admin->operate(1, $funddata->user_id, $funddata->fund_id, $add * 1000, $remark);
-        if(is_string($re18)){
+        $admin    = new FundService($funddata->user_id, $funddata->fund_id);
+        $re18     = $admin->admin_operate($admin_id, $funddata->fund_id, $add, $remark, '');
+        if (is_string($re18)) {
             Logger::error($re18);
+
             return $this->_error('fundadmin-error')->refresh();
         }
+
         return $this->_success('fundadmin-ok')->refresh();
 
     }

+ 6 - 7
app/Module/Fund/AdminControllers/FundCirculationController.php

@@ -67,13 +67,12 @@ class FundCirculationController extends AdminController
 
             $grid->filter(function (Grid\Filter $filter) {
                 $helper= new FilterHelper($filter,$this);
-                $filter->equal('user_id');
-                $filter->equal('id',"ID");
-                $helper->equalRadio('fund_id',AccountService::getFundsDesc(),"来源账户");
-                $helper->equalRadio('to_fund_id',AccountService::getFundsDesc(),"目标账户");
-
-                $filter->expand();
-                $filter->panel();
+                $filter->equal('id', 'ID');
+                $filter->equal('user_id', '用户ID');
+                $helper->equalRadio('fund_id', AccountService::getFundsDesc(), '来源账户');
+                $helper->equalRadio('to_fund_id', AccountService::getFundsDesc(), '目标账户');
+                $helper->betweenAmount('total_fee', '金额范围'); // 添加金额范围筛选
+                $helper->betweenTimestamp('create_time', '创建时间');
             });
             $grid->disableCreateButton();
             $grid->actions(function (Grid\Displayers\Actions $actions) {

+ 16 - 4
app/Module/Fund/AdminControllers/FundController.php

@@ -76,9 +76,11 @@ class FundController extends AdminController
                 // 使用FilterHelper
                 $helper = new FilterHelper($filter, $this);
 
-                // 使用高复用价值的筛选方法组
-                $helper->equalId(); // 添加完整的资金筛选组
+                // 直接实现资金筛选组
+                $helper->equalId(); // 添加ID筛选
+                $filter->equal('user_id', '用户ID');
                 $helper->equalFundId();
+
                 $helper->betweenAmount('balance', '余额范围');
                 $helper->betweenTimestamp('create_time', '创建时间');
             });
@@ -103,8 +105,18 @@ class FundController extends AdminController
             // 使用ShowHelper
             $helper = new ShowHelper($show, $this);
 
-            // 使用高复用价值的面板方法
-            $helper->addFundAccountPanel(); // 添加完整的资金账户详情面板
+            // 直接实现资金账户详情面板
+            $show->divider('账户信息');
+
+            $show->field('user_id', '用户ID');
+            $helper->fieldFundId();
+            $helper->fieldBalance();
+            $helper->fieldStatus();
+            $show->field('fund_type', '资金类型')->as(function ($value) {
+                return \App\Module\Fund\Enums\FUND_TYPE::getName($value);
+            });
+            $helper->fieldTimestamp('create_time', '创建时间');
+            $helper->fieldTimestamp('update_time', '更新时间');
 
             // todo 显示关联的资金日志
 

+ 36 - 6
app/Module/Fund/AdminControllers/FundLogController.php

@@ -97,9 +97,12 @@ class FundLogController extends AdminController
                 // 使用FilterHelper
                 $helper = new FilterHelper($filter, $this);
 
-                // 使用高复用价值的筛选方法组
+                // 直接实现资金日志筛选组
+                $filter->equal('user_id', '用户ID');
                 $helper->equalFundId();
                 $helper->equalOperateType();
+                $helper->betweenAmount();
+                $filter->like('remark', '备注');
                 $helper->betweenTimestamp('create_time', '创建时间');
             });
 
@@ -123,11 +126,38 @@ class FundLogController extends AdminController
             // 使用ShowHelper
             $helper = new ShowHelper($show, $this);
 
-            // 使用高复用价值的面板方法
-            $helper->addFundLogPanel(); // 添加完整的资金日志详情面板
-
-            //todo 显示关联的资金账户
-
+            // 直接实现资金日志详情面板
+            $show->divider('操作信息');
+
+            $show->field('user_id', '用户ID');
+            $helper->fieldFundId();
+            $helper->fieldAmount();
+            $helper->fieldOperateType();
+            $show->field('remark', '备注');
+            $helper->fieldTimestamp('create_time', '创建时间');
+
+            // 显示关联的资金账户
+            $show->relation('account', '资金账户', function ($model) {
+                $show = Show::make($model, new \App\Module\Fund\Models\FundAccount());
+
+                // 在关联显示中也使用ShowHelper
+                $helper = new ShowHelper($show, $this);
+
+                // 直接实现资金账户详情面板
+                $show->divider('账户信息');
+
+                $show->field('user_id', '用户ID');
+                $helper->fieldFundId();
+                $helper->fieldBalance();
+                $helper->fieldStatus();
+                $show->field('fund_type', '资金类型')->as(function ($value) {
+                    return \App\Module\Fund\Enums\FUND_TYPE::getName($value);
+                });
+                $helper->fieldTimestamp('create_time', '创建时间');
+                $helper->fieldTimestamp('update_time', '更新时间');
+
+                return $show;
+            });
 
         });
     }

+ 6 - 4
app/Module/Fund/AdminControllers/FundOrderController.php

@@ -35,10 +35,12 @@ class FundOrderController extends AdminController
 
 
             $grid->filter(function (Grid\Filter $filter) {
-                $filter->equal('user_id');
-
-                $filter->expand();
-                $filter->panel();
+                $helper = new FilterHelper($filter, $this);
+                $filter->equal('id', 'ID');
+                $filter->equal('user_id', '用户ID');
+                $helper->equalFundId();
+                $helper->betweenAmount('amount', '金额范围'); // 添加金额范围筛选
+                $helper->betweenTimestamp('create_time', '创建时间');
             });
             $grid->disableCreateButton();
             $grid->actions(function (Grid\Displayers\Actions $actions) {

+ 18 - 14
app/Module/Fund/AdminControllers/Helper/FilterHelperTrait.php

@@ -45,13 +45,27 @@ trait FilterHelperTrait
      */
     public function equalOperateType(string $field = 'operate_type', string $label = '操作类型'): Presenter
     {
-        return $this->filter->equal($field, $label)->select(LOG_TYPE::getNames());
+        return $this->filter->equal($field, $label)->select(OPERATE_TYPE::getValueDescription());
     }
 
 
 
 
 
+    /**
+     * 添加金额范围筛选
+     *
+     * 复用价值:高 - 统一处理金额范围的筛选,包括单位转换
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Filter\AbstractFilter
+     */
+    public function betweenAmount(string $field = 'amount', string $label = '金额范围'): Filter\AbstractFilter
+    {
+        return $this->filter->between($field, $label);
+    }
+
     /**
      * 添加时间戳范围筛选
      *
@@ -64,21 +78,11 @@ trait FilterHelperTrait
     public function betweenTimestamp(string $field, string $label): Filter\AbstractFilter
     {
         return $this->filter->between($field, $label)
-            ->datetime()
-            ->valueSerializeUsing(function ($value) {
-                // 将日期时间转换为时间戳
-                if (is_array($value)) {
-                    if (isset($value['start'])) {
-                        $value['start'] = strtotime($value['start']);
-                    }
-                    if (isset($value['end'])) {
-                        $value['end'] = strtotime($value['end']);
-                    }
-                }
-                return $value;
-            });
+            ->datetime();
     }
 
 
 
+
+
 }

+ 6 - 1
app/Module/Fund/AdminControllers/Helper/GridHelperTrait.php

@@ -156,7 +156,12 @@ trait GridHelperTrait
         return $this->grid->column($userIdField, $label)->display(function ($userId) use ($fundIdField) {
             $fundId = $this->{$fundIdField};
             $fundsDesc = AccountService::getFundsDesc();
-            $fundName = $fundsDesc[$fundId] ?? $fundId;
+            if(is_int($fundId)){
+                $fundName = $fundsDesc[$fundId] ?? $fundId;
+            }else{
+                $fundName = $fundsDesc[$fundId->value] ?? $fundId;
+            }
+
             return "ID: {$userId}<br>账户: {$fundName}";
         });
     }

+ 1 - 50
app/Module/Fund/AdminControllers/Helper/ShowHelperTrait.php

@@ -105,21 +105,7 @@ trait ShowHelperTrait
         });
     }
 
-    /**
-     * 显示资金类型
-     *
-     * 复用价值:高 - 统一处理资金类型的显示,使用枚举类型
-     *
-     * @param string $field 字段名
-     * @param string $label 标签名
-     * @return Show\Field
-     */
-    public function fieldFundType(string $field = 'fund_type', string $label = '资金类型'): Show\Field
-    {
-        return $this->show->field($field, $label)->as(function ($value) {
-            return FUND_TYPE::getName($value);
-        });
-    }
+
 
     /**
      * 显示时间戳
@@ -155,42 +141,7 @@ trait ShowHelperTrait
         });
     }
 
-    /**
-     * 添加资金账户详情面板
-     *
-     * 复用价值:高 - 提供完整的资金账户详情面板
-     *
-     * @return void
-     */
-    public function addFundAccountPanel(): void
-    {
-        $this->show->divider('账户信息');
 
-        $this->show->field('user_id', '用户ID');
-        $this->fieldFundId();
-        $this->fieldBalance();
-        $this->fieldStatus();
-        $this->fieldFundType();
-        $this->fieldTimestamp('create_time', '创建时间');
-        $this->fieldTimestamp('update_time', '更新时间');
-    }
 
-    /**
-     * 添加资金日志详情面板
-     *
-     * 复用价值:高 - 提供完整的资金日志详情面板
-     *
-     * @return void
-     */
-    public function addFundLogPanel(): void
-    {
-        $this->show->divider('操作信息');
 
-        $this->show->field('user_id', '用户ID');
-        $this->fieldFundId();
-        $this->fieldAmount();
-        $this->fieldOperateType();
-        $this->show->field('remark', '备注');
-        $this->fieldTimestamp('create_time', '创建时间');
-    }
 }

+ 4 - 0
app/Module/Fund/Enums/FUND_TYPE.php

@@ -14,5 +14,9 @@ enum FUND_TYPE: int
      * 代币1
      */
     case FUND1 = 1;
+    /**
+     * 代币1
+     */
+    case FUND2 = 2;
 
 }

+ 4 - 1
app/Module/Fund/Enums/LOG_TYPE.php

@@ -2,14 +2,17 @@
 
 namespace App\Module\Fund\Enums;
 
+use UCore\Enum\EnumCore;
+use UCore\Enum\EnumExpression;
 use UCore\Enum\EnumName;
+use UCore\Enum\EnumToInt;
 
 /**
  * 资金日志类型枚举
  */
 enum LOG_TYPE: int
 {
-    use EnumName;
+    use EnumExpression,EnumToInt,EnumCore;
 
 
     /**

+ 7 - 2
app/Module/Fund/Services/FundService.php

@@ -22,10 +22,15 @@ class FundService
     private int $fundId;
     private FundModel $fundModel;
 
-    public function __construct(int $userId, int $fundId)
+    public function __construct(int $userId,  $fundId)
     {
         $this->userId = $userId;
-        $this->fundId = $fundId;
+        if(is_int($fundId)){
+            $this->fundId = $fundId;
+        }else{
+            $this->fundId = $fundId->valueInt();
+        }
+
         $this->fundModel = FundModel::query()
             ->where('user_id', $userId)
             ->where('fund_id', $fundId)