summaryrefslogtreecommitdiff
path: root/src/Model/Event/SendUnits.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model/Event/SendUnits.php')
-rw-r--r--src/Model/Event/SendUnits.php23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/Model/Event/SendUnits.php b/src/Model/Event/SendUnits.php
index ea94442..ed4d5b6 100644
--- a/src/Model/Event/SendUnits.php
+++ b/src/Model/Event/SendUnits.php
@@ -25,7 +25,7 @@ class SendUnits extends BaseEvent
public function __invoke(): void
{
if ($this->isCanceled) {
- if ($this->type === 'SendBack') {
+ if ($this->type === 'SendBack' || $this->type === 'Recall') {
$this->source = $this->home;
$this->destination = $this->residence;
@@ -54,11 +54,16 @@ class SendUnits extends BaseEvent
<<<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)
+ on conflict (type, home_village_id, residence_village_id, is_traveling)
do update set amount = village_units.amount+:amount
SQL,
['amount' => $this->amount, 'type' => $this->unit, 'id' => $this->destination]
);
+
+ DB::query(
+ 'delete from village_units where type=:type and home_village_id=:home and residence_village_id=:residence and is_traveling=true',
+ ['type' => $this->unit, 'home' => $this->destination, 'residence' => $this->source]
+ );
}
private function borrow(): void
@@ -67,11 +72,16 @@ class SendUnits extends BaseEvent
<<<SQL
insert into village_units (amount, type, is_traveling, home_village_id, residence_village_id)
values (:amount, :type, false, :home, :residence)
- on conflict (type, home_village_id, residence_village_id)
+ on conflict (type, home_village_id, residence_village_id, is_traveling)
do update set amount = village_units.amount+:amount
SQL,
['amount' => $this->amount, 'type' => $this->unit, 'home' => $this->source, 'residence' => $this->destination]
);
+
+ DB::query(
+ 'delete from village_units where type=:type and home_village_id=:home and residence_village_id=:residence and is_traveling=true',
+ ['type' => $this->unit, 'home' => $this->source, 'residence' => $this->source]
+ );
}
private function gift(): void
@@ -80,11 +90,16 @@ class SendUnits extends BaseEvent
<<<SQL
insert into village_units (amount, type, is_traveling, home_village_id, residence_village_id)
values (:amount, :type, false, :home, :residence)
- on conflict (type, home_village_id, residence_village_id)
+ on conflict (type, home_village_id, residence_village_id, is_traveling)
do update set amount = village_units.amount+:amount
SQL,
['amount' => $this->amount, 'type' => $this->unit, 'home' => $this->destination, 'residence' => $this->residence]
);
+
+ DB::query(
+ 'delete from village_units where type=:type and home_village_id=:home and residence_village_id=:residence and is_traveling=true',
+ ['type' => $this->unit, 'home' => $this->source, 'residence' => $this->source]
+ );
}
public function dbInsert(): void