Explorar o código

Merge branch 'master' of e.coding.net:g-ueau9359/kku/kku_laravel

* 'master' of e.coding.net:g-ueau9359/kku/kku_laravel:
  feat(farm): 添加作物产出物品
  refactor(farm): 精简农作物控制器代码
AI Assistant hai 6 meses
pai
achega
0355332f39

+ 15 - 99
app/Module/Farm/AdminControllers/FarmCropController.php

@@ -43,7 +43,7 @@ class FarmCropController extends AdminController
      */
     protected function grid()
     {
-        return Grid::make(new FarmCropRepository(), function (Grid $grid) {
+        return Grid::make(new FarmCropRepository(['final_output_item']), function (Grid $grid) {
             $helper = new GridHelper($grid, $this);
 
             $helper->columnId();
@@ -67,75 +67,39 @@ class FarmCropController extends AdminController
                 }
                 return "<span class='label label-warning'>未确定</span>";
             });
+            $grid->column('final_output_item.name', '产出物品')->sortable()->display(function ($value) {
+                if ($value) {
+                    return "<span class='label label-success'>{$value}</span>";
+                }
+                return "<span class='label label-warning'>-</span>";
+            });
 
             $grid->column('final_output_amount', '预定产量')->sortable()->display(function ($value) {
                 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 +117,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 +242,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()
-            ]);
-        }
-    }
+
 }

+ 9 - 1
app/Module/Farm/Models/FarmCrop.php

@@ -3,14 +3,16 @@
 namespace App\Module\Farm\Models;
 
 use App\Module\Farm\Enums\GROWTH_STAGE;
+use App\Module\GameItems\Models\Item;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use Illuminate\Database\Eloquent\Relations\HasOne;
 use Illuminate\Database\Eloquent\SoftDeletes;
 
 /**
  * 作物信息模型
  *
- * field start 
+ * field start
  * @property  int  $id  主键ID
  * @property  int  $land_id  土地ID
  * @property  int  $user_id  用户ID
@@ -113,4 +115,10 @@ class FarmCrop extends Model
     {
         return $this->belongsTo(FarmUser::class, 'user_id', 'user_id');
     }
+
+    public function final_output_item():HasOne
+    {
+        return $this->hasOne(Item::class, 'id', 'final_output_item_id');
+
+    }
 }

+ 18 - 0
public/dcat-admin/css/admin.css

@@ -6,3 +6,21 @@
     min-width: 100px;
     max-width: 300px;
 }
+
+.label-success{
+    background-color: #5cb85c;
+}
+.label-danger{
+    background-color: #d9534f;
+}
+.label-warning{
+    background-color: #f0ad4e;
+}
+.label-info{
+    background-color: #5bc0de;
+}
+.label-default{
+    background-color: #777;
+}
+.label{
+}