Browse Source

refactor(farm): 精简农作物控制器代码

- 移除了数据状态列和相关过滤器
- 删除了修复成熟期产量的功能
- 优化了网格过滤器,添加了回收站过滤选项
notfff 6 months ago
parent
commit
743386e75c
1 changed files with 8 additions and 98 deletions
  1. 8 98
      app/Module/Farm/AdminControllers/FarmCropController.php

+ 8 - 98
app/Module/Farm/AdminControllers/FarmCropController.php

@@ -72,70 +72,28 @@ class FarmCropController extends AdminController
                 if ($value) {
                     return "<span class='label label-info'>{$value}</span>";
                 }
-                return "<span class='label label-warning'>未确定</span>";
+                return "<span class='label --warning'>未确定</span>";
             });
 
-            // 添加数据完整性状态列
-            $grid->column('data_status', '数据状态')->display(function () {
-                $hasItemId = !empty($this->final_output_item_id);
-                $hasAmount = !empty($this->final_output_amount);
-                $isMature = $this->growth_stage == GROWTH_STAGE::MATURE->value;
 
-                if ($isMature) {
-                    if ($hasItemId && $hasAmount) {
-                        return "<span class='label label-success'>完整</span>";
-                    } elseif ($hasItemId) {
-                        return "<span class='label label-warning'>缺少产量</span>";
-                    } else {
-                        return "<span class='label label-danger'>缺少产出物品</span>";
-                    }
-                } else {
-                    if ($hasItemId) {
-                        return "<span class='label label-info'>已确定产出物品</span>";
-                    } else {
-                        return "<span class='label label-default'>未确定</span>";
-                    }
-                }
-            });
+
 
             $helper->columnFertilized();
             $helper->columnCreatedAt();
             $helper->columnUpdatedAt();
 
-            // 添加批量操作
-            $grid->tools(function (Grid\Tools $tools) {
-                $tools->append('<a href="javascript:void(0)" class="btn btn-sm btn-warning" onclick="fixMatureCrops()">
-                    <i class="fa fa-wrench"></i> 修复成熟期产量
-                </a>');
-
-                $tools->append('<script>
-                function fixMatureCrops() {
-                    if (confirm("确定要修复所有成熟期作物的产量吗?这将为缺少产量的成熟期作物计算产量。")) {
-                        $.post("/admin/farm-crops/fix-mature-output", {
-                            _token: LA.token
-                        }).done(function(result) {
-                            if (result.status) {
-                                Dcat.success(result.message || "修复完成");
-                                Dcat.reload();
-                            } else {
-                                Dcat.error(result.message || "修复失败");
-                            }
-                        }).fail(function() {
-                            Dcat.error("请求失败");
-                        });
-                    }
-                }
-                </script>');
-            });
+
 
             $grid->filter(function (Grid\Filter $filter) {
                 $filterHelper = new FilterHelper($filter, $this);
-
+                $filter->scope('trashed', '回收站')->onlyTrashed();
                 $filterHelper->equalId();
                 $filter->equal('land_id', '土地ID');
                 $filterHelper->equalUserId();
                 $filter->equal('seed_id', '种子ID');
                 $filterHelper->equalGrowthStage();
+                $filterHelper->equalLandType('land_level'); // land_level
+
                 $filterHelper->betweenDatetime('plant_time', '种植时间');
                 $filterHelper->betweenDatetime('stage_end_time', '阶段结束时间');
 
@@ -153,28 +111,7 @@ class FarmCropController extends AdminController
                     'no_amount' => '未确定产量'
                 ]);
 
-                // 添加数据完整性过滤器
-                $filter->where('data_completeness', function ($query) {
-                    $value = $this->input;
-                    if ($value == 'complete') {
-                        $query->whereNotNull('final_output_item_id')
-                              ->whereNotNull('final_output_amount')
-                              ->where('growth_stage', GROWTH_STAGE::MATURE->value);
-                    } elseif ($value == 'incomplete_mature') {
-                        $query->where('growth_stage', GROWTH_STAGE::MATURE->value)
-                              ->where(function ($q) {
-                                  $q->whereNull('final_output_item_id')
-                                    ->orWhereNull('final_output_amount');
-                              });
-                    } elseif ($value == 'missing_amount') {
-                        $query->whereNotNull('final_output_item_id')
-                              ->whereNull('final_output_amount');
-                    }
-                }, '数据完整性')->select([
-                    'complete' => '数据完整(成熟期)',
-                    'incomplete_mature' => '数据不完整(成熟期)',
-                    'missing_amount' => '缺少产量'
-                ]);
+
 
                 $filterHelper->equalFertilized();
                 $filterHelper->betweenDatetime('created_at', '创建时间');
@@ -299,32 +236,5 @@ class FarmCropController extends AdminController
         });
     }
 
-    /**
-     * 修复成熟期作物产量
-     *
-     * @return \Illuminate\Http\JsonResponse
-     */
-    #[Post('farm-crops/fix-mature-output')]
-    public function fixMatureOutput()
-    {
-        try {
-            // 调用修复命令
-            \Illuminate\Support\Facades\Artisan::call('farm:fix-crop-mature-output', [
-                '--limit' => 100
-            ]);
-
-            $output = \Illuminate\Support\Facades\Artisan::output();
-
-            return response()->json([
-                'status' => true,
-                'message' => '修复完成!' . $output
-            ]);
-
-        } catch (\Exception $e) {
-            return response()->json([
-                'status' => false,
-                'message' => '修复失败:' . $e->getMessage()
-            ]);
-        }
-    }
+
 }