diff options
Diffstat (limited to 'src/Model/Event')
-rw-r--r-- | src/Model/Event/TrainUnits.php | 27 | ||||
-rw-r--r-- | src/Model/Event/UpgradeBuilding.php | 27 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/Model/Event/TrainUnits.php b/src/Model/Event/TrainUnits.php new file mode 100644 index 0000000..0c7e0de --- /dev/null +++ b/src/Model/Event/TrainUnits.php @@ -0,0 +1,27 @@ +<?php + +namespace App\Model\Event; + +use App\DB; +use App\Model\Event; + +class TrainUnits extends Event +{ + /** + * @return void + */ + public function __invoke(): void + { + $payload = json_decode($this->payload, true); + + DB::query( + <<<SQL + insert into village_units (amount, type, is_traveling, home_village_id, residence_village_id) + values (:amount, :type, false, :id, :id) + on conflict (type, home_village_id, residence_village_id) + do update set amount = excluded.amount+:amount + SQL, + ['amount' => $payload['amount'], 'type' => $payload['type'], 'id' => $this->villageId] + ); + } +} diff --git a/src/Model/Event/UpgradeBuilding.php b/src/Model/Event/UpgradeBuilding.php new file mode 100644 index 0000000..c014cfe --- /dev/null +++ b/src/Model/Event/UpgradeBuilding.php @@ -0,0 +1,27 @@ +<?php + +namespace App\Model\Event; + +use App\DB; +use App\Model\Event; + +class UpgradeBuilding extends Event +{ + /** + * @return void + */ + public function __invoke(): void + { + $payload = json_decode($this->payload, true); + + DB::query( + 'update village_buildings set level=level+1 where id=:id', + ['id' => $payload['id']] + ); + + DB::query( + 'delete from events where id=:id', + ['id' => $this->id] + ); + } +} |