1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<?php
namespace App\Model\Event;
use App\DB;
use App\Model\Event;
class UpgradeBuilding extends BaseEvent
{
public Event $event;
public string $type;
public function __construct(Event $event, string $type)
{
$this->event = $event;
$this->type = $type;
}
/**
* @return void
*/
public function __invoke(): void
{
DB::query(
<<<SQL
insert into village_buildings (level, type, village_id)
values (1, :type, :village_id)
on conflict (type, village_id)
do update set level = village_buildings.level+1
SQL,
['type' => $this->type, 'village_id' => $this->event->villageId]
);
}
public function sqlInsert(): void
{
DB::query(
'insert into events (time, village_id) values (:time, :village_id)',
['time' => $this->event->time->format('c'), 'village_id' => $this->event->villageId]
);
DB::query(
'insert into events_upgrade_building (event_id, type) values (:event_id, :type)',
['event_id' => DB::$connection->lastInsertId(), $this->type]
);
}
}
|