118 lines
2.9 KiB
PHP
118 lines
2.9 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 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::update(
|
|
myself()->_getSelfMysql(),
|
|
't_hero_skin',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'skin_id' => $skinId
|
|
),
|
|
array(
|
|
'hero_id'=>$heroId
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
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']);
|
|
$array = array(
|
|
'skin_id'=>$meta['id'],
|
|
'is_have' => $row?1:0,
|
|
'use_state' => $row['hero_id']?1:0,
|
|
);
|
|
return $array;
|
|
}
|
|
|
|
public static function addSkin($itemMeta)
|
|
{
|
|
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' => $itemMeta['isdefaultskin']?$itemMeta['playerid']:0,
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime()
|
|
)
|
|
);
|
|
}
|
|
|
|
}
|