162 lines
5.0 KiB
PHP
162 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace models;
|
|
|
|
require_once('mt/Item.php');
|
|
|
|
use mt;
|
|
use phpcommon;
|
|
use phpcommon\SqlHelper;
|
|
|
|
class User extends BaseModel {
|
|
|
|
public static function find($targetId)
|
|
{
|
|
$row = SqlHelper::ormSelectOne
|
|
(myself()->_getMysql($targetId),
|
|
't_user',
|
|
array(
|
|
'account_id' => $targetId
|
|
)
|
|
);
|
|
return $row ? $row : null;
|
|
}
|
|
|
|
public static function show($row)
|
|
{
|
|
return array(
|
|
'activated' => $row['activated'],
|
|
'rename_count' => $row['rename_count'],
|
|
'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'],
|
|
'already_guide' => $row['already_guide'],
|
|
'pve_instance_id' => $row['pve_instance_id'],
|
|
'like_count' => $row['like_count'],
|
|
'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'],
|
|
'rename_count' => $row['rename_count'],
|
|
'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'],
|
|
'already_guide' => $row['already_guide'],
|
|
'head_list' => self::getHeadList($row),
|
|
'pve_instance_id' => $row['pve_instance_id'],
|
|
'like_count' => $row['like_count'],
|
|
'head_frame_list' => emptyReplace(json_decode($row['head_frame_list'], true), array()),
|
|
'is_leader' => 0
|
|
);
|
|
}
|
|
|
|
public static function toSimple($row)
|
|
{
|
|
return array(
|
|
'account_id' => $row['account_id'],
|
|
'address' => phpcommon\extractOpenId($row['account_id']),
|
|
'name' => $row['name'],
|
|
'sex' => $row['sex'],
|
|
'head_id' => $row['hero_id'],
|
|
'head_frame' => $row['head_frame'],
|
|
'level' => $row['level'],
|
|
'exp' => $row['exp'],
|
|
'rank' => $row['rank'],
|
|
'score' => $row['score'],
|
|
'gold' => $row['gold'],
|
|
'diamond' => $row['diamond'],
|
|
'hero_id' => $row['hero_id'],
|
|
'pve_instance_id' => $row['pve_instance_id'],
|
|
'like_count' => $row['like_count'],
|
|
'first_fight' => $row['first_fight'],
|
|
);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public static function update( $fieldsKv){
|
|
SqlHelper::update
|
|
(myself()->_getSelfMysql(),
|
|
't_user',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
),
|
|
$fieldsKv
|
|
);
|
|
}
|
|
|
|
public static function updateLikeCount($targetId){
|
|
SqlHelper::update
|
|
(myself()->_getSelfMysql(),
|
|
't_user',
|
|
array(
|
|
'account_id' => $targetId,
|
|
),
|
|
array(
|
|
'like_count' => function(){
|
|
return "like_count + 1";
|
|
}
|
|
)
|
|
);
|
|
}
|
|
|
|
}
|