| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace App\Module\Farm\Commands;
- use App\Module\Farm\Services\PickService;
- use App\Module\Farm\Models\FarmCrop;
- use App\Module\Farm\Models\FarmSeed;
- use App\Module\Farm\Models\FarmLand;
- use App\Module\Farm\Models\FarmUser;
- use App\Module\Farm\Enums\GROWTH_STAGE;
- use Illuminate\Console\Command;
- /**
- * 测试摘取功能命令
- */
- class TestPickFunctionCommand extends Command
- {
- /**
- * 命令签名
- *
- * @var string
- */
- protected $signature = 'farm:test-pick-function';
- /**
- * 命令描述
- *
- * @var string
- */
- protected $description = '测试农场摘取功能';
- /**
- * 执行命令
- *
- * @return int
- */
- public function handle(): int
- {
- $this->info('开始测试农场摘取功能...');
- try {
- // 测试获取摘取信息
- $this->testGetPickInfo();
- // 测试检查摘取条件
- $this->testCanPickCrop();
- $this->info('所有测试通过!');
- return 0;
- } catch (\Exception $e) {
- $this->error('测试失败: ' . $e->getMessage());
- $this->error('堆栈跟踪: ' . $e->getTraceAsString());
- return 1;
- }
- }
- /**
- * 测试获取摘取信息
- */
- private function testGetPickInfo(): void
- {
- $this->info('测试获取摘取信息...');
- // 查找一个成熟的作物
- $crop = FarmCrop::where('growth_stage', GROWTH_STAGE::MATURE)
- ->where('final_output_amount', '>', 0)
- ->first();
- if (!$crop) {
- $this->warn('没有找到成熟的作物,跳过测试');
- return;
- }
- $pickInfo = PickService::getPickInfo($crop->id);
- if ($pickInfo) {
- $this->info("作物ID: {$pickInfo->cropId}");
- $this->info("总产量: {$pickInfo->totalAmount}");
- $this->info("已摘取: {$pickInfo->pickedAmount}");
- $this->info("可摘取: {$pickInfo->pickableAmount}");
- $this->info("是否可摘取: " . ($pickInfo->canPick ? '是' : '否'));
- } else {
- $this->warn('获取摘取信息失败');
- }
- }
- /**
- * 测试检查摘取条件
- */
- private function testCanPickCrop(): void
- {
- $this->info('测试检查摘取条件...');
- // 查找一个作物
- $crop = FarmCrop::first();
- if (!$crop) {
- $this->warn('没有找到作物,跳过测试');
- return;
- }
- $result = PickService::canPickCrop($crop->id);
- $this->info("作物ID: {$crop->id}");
- $this->info("是否可摘取: " . ($result['can_pick'] ? '是' : '否'));
- $this->info("原因: {$result['reason']}");
-
- if (isset($result['pickable_amount'])) {
- $this->info("可摘取数量: {$result['pickable_amount']}");
- }
- }
- }
|