game2006api/webapp/models/HeroPreset.php
hujiabin 951034c457 1
2023-07-04 11:24:45 +08:00

96 lines
2.8 KiB
PHP

<?php
namespace models;
require_once('mt/Skill.php');
use mt;
use phpcommon;
use phpcommon\SqlHelper;
class HeroPreset extends BaseModel {
public static function getByGunUid($weapon_uid){
$rows = SqlHelper::ormSelect(
myself()->_getSelfMysql(),
't_hero_preset',
array(
'account_id' => myself()->_getAccountId(),
'weapon_uid1' => $weapon_uid,
)
);
if (!$rows){
return null;
}
return $rows;
}
public static function getHeroPreset($heroUid){
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_hero_preset',
array(
'account_id' => myself()->_getAccountId(),
'hero_uid' => $heroUid,
)
);
if ($row){
$data = array(
'skill_id' => $row['skill_id'],
'weapon_uid1' => $row['weapon_uid1'],
'weapon_uid2' => $row['weapon_uid2'],
'chip_page' => $row['chip_page'],
'gun_id1'=>0,
'gun_id2'=>0,
);
$gunDb1 = Gun::find($row['weapon_uid1']);
$gunDb2 = Gun::find($row['weapon_uid2']);
if ($gunDb1){
$data['gun_id1'] = $gunDb1['gun_id'];
$data['gun_lv1'] = $gunDb1['gun_lv'];
}
if ($gunDb2){
$data['gun_id2'] = $gunDb2['gun_id'];
$data['gun_lv2'] = $gunDb2['gun_lv'];
}
}else{
$data = array(
'skill_id' => mt\Skill::getDefSkill(),
'weapon_uid1' => 0,
'weapon_uid2' => 0,
'gun_id1'=>0,
'gun_id2'=>0,
'chip_page' => 1,
);
}
return $data;
}
public static function upsertPreset($heroId,$skillId,$chipPageId,$weaponUid1,$weaponUid2){
SqlHelper::upsert
(myself()->_getSelfMysql(),
't_hero_preset',
array(
'account_id' => myself()->_getAccountId(),
'hero_uid' => $heroId,
),
array(
'skill_id' => $skillId,
'weapon_uid1' => $weaponUid1,
'weapon_uid2' => $weaponUid2,
'chip_page' => $chipPageId,
'modifytime' => myself()->_getNowTime(),
),
array(
'account_id' => myself()->_getAccountId(),
'hero_uid' => $heroId,
'skill_id' => $skillId,
'weapon_uid1' => $weaponUid1,
'weapon_uid2' => $weaponUid2,
'chip_page' => $chipPageId,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
)
);
}
}