104 lines
3.2 KiB
PHP
104 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace models;
|
|
|
|
require_once('mt/Item.php');
|
|
|
|
use mt;
|
|
use phpcommon\SqlHelper;
|
|
|
|
class User extends BaseModel {
|
|
|
|
public function find($targetId)
|
|
{
|
|
$row = SqlHelper::ormSelectOne
|
|
($this->_getMysql($targetId),
|
|
't_user',
|
|
array(
|
|
'account_id' => $targetId
|
|
)
|
|
);
|
|
return $row ? $row : null;
|
|
}
|
|
|
|
public static function show($row)
|
|
{
|
|
return array(
|
|
'activated' => $row['activated'],
|
|
'account_id' => $row['account_id'],
|
|
'name' => $row['name'],
|
|
'sex' => $row['sex'],
|
|
'head_id' => $row['head_id'],
|
|
'head_frame' => $row['head_frame'],
|
|
'level' => $row['level'],
|
|
'exp' => $row['exp'],
|
|
'max_exp' => $row['exp'] + 1000,
|
|
'rank' => $row['rank'],
|
|
'history_best_rank' => $row['history_best_rank'],
|
|
'score' => $row['score'],
|
|
'gold' => $row['gold'],
|
|
'diamond' => $row['diamond'],
|
|
'hero_id' => $row['hero_id'],
|
|
'first_fight' => $row['first_fight'],
|
|
'head_list' => self::getHeadList($row),
|
|
'head_frame_list' => emptyReplace(json_decode($row['head_frame_list'], true), array()),
|
|
);
|
|
}
|
|
|
|
public static function info($row)
|
|
{
|
|
return array(
|
|
'activated' => $row['activated'],
|
|
'account_id' => $row['account_id'],
|
|
'name' => $row['name'],
|
|
'sex' => $row['sex'],
|
|
'head_id' => $row['head_id'],
|
|
'head_frame' => $row['head_frame'],
|
|
'level' => $row['level'],
|
|
'exp' => $row['exp'],
|
|
'max_exp' => $row['exp'] + 1000,
|
|
'rank' => $row['rank'],
|
|
'history_best_rank' => $row['history_best_rank'],
|
|
'score' => $row['score'],
|
|
'gold' => $row['gold'],
|
|
'diamond' => $row['diamond'],
|
|
'hero_id' => $row['hero_id'],
|
|
'first_fight' => $row['first_fight'],
|
|
'head_list' => self::getHeadList($row),
|
|
'head_frame_list' => emptyReplace(json_decode($row['head_frame_list'], true), array()),
|
|
);
|
|
}
|
|
|
|
public static function isValidHeadId($userInfo, $headId)
|
|
{
|
|
$headList = self::getHeadList($userInfo);
|
|
return in_array($headId, $headList);
|
|
}
|
|
|
|
public static function isValidHeadFrame($userInfo, $headFrame)
|
|
{
|
|
$headFrameList = emptyReplace(json_decode($userInfo['head_frame_list'], true), array());
|
|
return in_array($headFrame, $headFrameList);
|
|
}
|
|
|
|
private static function getHeadList($userInfo)
|
|
{
|
|
$headList = emptyReplace(json_decode($userInfo['head_list'], true), array());
|
|
$rows = SqlHelper::ormSelect(
|
|
myself()->_getSelfMysql(),
|
|
't_hero',
|
|
array(
|
|
'account_id' => $userInfo['account_id'],
|
|
)
|
|
);
|
|
foreach ($rows as $row) {
|
|
$itemMeta = mt\Item::get($row['hero_id']);
|
|
if ($itemMeta && $itemMeta['hero_head']) {
|
|
array_push($headList, $itemMeta['hero_head']);
|
|
}
|
|
}
|
|
return $headList;
|
|
}
|
|
|
|
}
|