game2006api/webapp/models/HeroSkin.php
hujiabin 3b9c559854 1
2023-07-14 16:15:45 +08:00

152 lines
3.8 KiB
PHP

<?php
namespace models;
require_once('mt/Hero.php');
use mt;
use phpcommon\SqlHelper;
class HeroSkin extends BaseModel {
const GETED_STATE = 0;
const TRY_USING_STATE = 1;
public static function find($skinId)
{
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_hero_skin',
array(
'account_id' => myself()->_getAccountId(),
'skin_id' => $skinId
)
);
return $row;
}
public static function findBx($heroId)
{
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_hero_skin',
array(
'account_id' => myself()->_getAccountId(),
'hero_id' => $heroId
)
);
return $row;
}
public static function findByAccountId($accountId, $heroId)
{
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_hero_skin',
array(
'account_id' => $accountId,
'hero_id' => $heroId
)
);
return $row;
}
public static function takeonSkin($skinId,$heroId){
$row = self::findBx($heroId);
SqlHelper::update(
myself()->_getSelfMysql(),
't_hero_skin',
array(
'account_id' => myself()->_getAccountId(),
'skin_id' => $row['skin_id']
),
array(
'hero_id'=>0
)
);
SqlHelper::upsert(
myself()->_getSelfMysql(),
't_hero_skin',
array(
'account_id' => myself()->_getAccountId(),
'skin_id' => $skinId
),
array(
'hero_id'=>$heroId
),
array(
'account_id' => myself()->_getAccountId(),
'skin_id' => $skinId,
'skin_state' => 0,
'get_from' => 0,
'consume_num' => 0,
'try_expire_at' => 0,
'hero_id' => $heroId,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
public static function getSkinList($cb){
SqlHelper::ormSelect(
myself()->_getSelfMysql(),
't_hero_skin',
array(
'account_id' => myself()->_getAccountId()
),
function ($row) use($cb) {
$cb($row);
}
);
}
public static function toDto($meta)
{
$row = self::find($meta['id']);
$is_have = 0;
$use_state = 0;
if ($row || $meta['isdefaultskin'] == 1){
$is_have = 1;
}
if ($row && $row['hero_id']){
$use_state = 1;
}
return array(
'skin_id'=>$meta['id'],
'is_have' => $is_have,
'use_state' => $use_state,
);
}
public static function addSkin($itemMeta)
{
$heroId = 0;
if ($itemMeta['isdefaultskin'] == 1){
$heroId = $itemMeta['playerid'];
}
SqlHelper::upsert(
myself()->_getSelfMysql(),
't_hero_skin',
array(
'account_id' => myself()->_getAccountId(),
'skin_id' => $itemMeta['id']
),
array(),
array(
'account_id' => myself()->_getAccountId(),
'skin_id' => $itemMeta['id'],
'skin_state' => 0,
'get_from' => 0,
'consume_num' => 0,
'try_expire_at' => 0,
'hero_id' => $heroId,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
}