summaryrefslogtreecommitdiff
path: root/src/Model/Event/TrainUnits.php
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-09-24 13:40:25 +0200
committerDaniel Weipert <code@drogueronin.de>2023-09-24 13:40:25 +0200
commitfa00b957378a393f8edbfc98ef111d35d18ecb09 (patch)
tree654e7dc5414f7f2795dbe996d3e1570793a5b1b8 /src/Model/Event/TrainUnits.php
initial commit
Diffstat (limited to 'src/Model/Event/TrainUnits.php')
-rw-r--r--src/Model/Event/TrainUnits.php27
1 files changed, 27 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]
+ );
+ }
+}