aozhiwei 697d845658 1
2021-12-01 11:31:13 +08:00

105 lines
2.7 KiB
PHP

<?php
namespace models;
require_once('mt/Hero.php');
require_once('models/HeroSkin.php');
use mt;
use phpcommon\SqlHelper;
class Hero extends BaseModel {
public static function find($heroId)
{
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_hero',
array(
'account_id' => myself()->_getAccountId(),
'hero_id' => $heroId,
)
);
return $row;
}
public static function toDto($row)
{
return array(
'hero_id' => $row['hero_id'],
'hero_lv' => $row['hero_lv'],
'skin_id' => $row['skin_id'],
'skill_lv1' => $row['skill_lv1'],
'skill_lv2' => $row['skill_lv2'],
'yoke_lv' => $row['yoke_lv'],
'yoke_exp' => $row['yoke_exp'],
);
}
public static function addHero($heroMeta)
{
$defSkin = mt\Hero::getDefaultSkin($heroMeta);
SqlHelper::upsert(
myself()->_getSelfMysql(),
't_hero',
array(
'account_id' => myself()->_getAccountId(),
'hero_id' => $heroMeta['id']
),
array(
),
array(
'account_id' => myself()->_getAccountId(),
'hero_id' => $heroMeta['id'],
'hero_lv' => 1,
'skin_id' => $defSkin,
'skill_lv1' => 1,
'skill_lv2' => 1,
'yoke_lv' => 0,
'yoke_exp' => 0,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
public static function takeonSkin($heroId, $skinId)
{
SqlHelper::update(
myself()->_getSelfMysql(),
't_hero',
array(
'account_id' => myself()->_getAccountId(),
'hero_id' => $heroMeta['id']
),
array(
'skin_id' => $skinId,
'modifytime' => myself()->_getNowTime()
)
);
}
public static function upgradeSkill($heroId, $skillIdx)
{
if (!in_array($skillIdx, array(0, 1))) {
return;
}
$fieldName = 'skill_lv' . ($skillIdx + 1);
SqlHelper::update(
myself()->_getSelfMysql(),
't_hero',
array(
'account_id' => myself()->_getAccountId(),
'hero_id' => $heroId
),
array(
$fieldName => function () use($fieldName) {
return "${fieldName} + 1";
},
'modifytime' => myself()->_getNowTime()
)
);
}
}