286 lines
9.4 KiB
PHP
286 lines
9.4 KiB
PHP
<?php
|
|
|
|
namespace models;
|
|
|
|
require_once('mt/Item.php');
|
|
require_once('models/UserSeasonRing.php');
|
|
|
|
use mt;
|
|
use phpcommon;
|
|
use phpcommon\SqlHelper;
|
|
use models\UserSeasonRing;
|
|
|
|
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'],
|
|
'history_best_score' => $row['history_best_score'],
|
|
'bceg' => cegFormat($row['bceg']),
|
|
'gold' => cegFormat($row['gold']),
|
|
'diamond' => cecFormat($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_list' => self::exportHeadList($row)['head_list'],
|
|
'hero_list' => self::exportHeadList($row)['hero_list'],
|
|
'head_frame_list' => emptyReplace(json_decode($row['head_frame_list'], true), array()),
|
|
'is_gain_item' => $row['is_gain_item'],
|
|
'guild_id' => $row['guild_id'],
|
|
'guild_job' => $row['guild_job'],
|
|
'guild_name' => $row['guild_name'],
|
|
);
|
|
}
|
|
|
|
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'],
|
|
'history_best_score' => $row['history_best_score'],
|
|
'bceg' => cegFormat($row['bceg']),
|
|
'gold' => cegFormat($row['gold']),
|
|
'diamond' => cecFormat($row['diamond']),
|
|
'hero_id' => $row['hero_id'],
|
|
'first_fight' => $row['first_fight'],
|
|
'already_guide' => $row['already_guide'],
|
|
// 'head_list' => self::getHeadList($row),
|
|
'head_list' => self::exportHeadList($row)['head_list'],
|
|
'hero_list' => self::exportHeadList($row)['hero_list'],
|
|
'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_gain_item' => $row['is_gain_item'],
|
|
'is_leader' => 0,
|
|
'guild_id' => $row['guild_id'],
|
|
'guild_job' => $row['guild_job'],
|
|
'guild_name' => $row['guild_name'],
|
|
'ring_list' => UserSeasonRing::ringList($row['account_id'])
|
|
);
|
|
}
|
|
|
|
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['head_id'],
|
|
'head_frame' => $row['head_frame'],
|
|
'level' => $row['level'],
|
|
'exp' => $row['exp'],
|
|
'rank' => $row['rank'],
|
|
'score' => $row['score'],
|
|
'gold' => cegFormat($row['gold']),
|
|
'diamond' => cecFormat($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::exportHeadList($userInfo);
|
|
return in_array($headId, $headList['head_list']);
|
|
}
|
|
|
|
public static function isValidHeroId($userInfo, $heroId)
|
|
{
|
|
$heroList = self::exportHeadList($userInfo);
|
|
return in_array($heroId, $heroList['hero_list']);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
private static function exportHeadList($userInfo){
|
|
$list = emptyReplace(json_decode($userInfo['head_list'], true), array());
|
|
$head_list = array();
|
|
$hero_list = array();
|
|
foreach ($list as $value){
|
|
$temp = explode('|',$value);
|
|
array_push($head_list,$temp[0]);
|
|
array_push($hero_list,$temp[1]);
|
|
}
|
|
return array(
|
|
'head_list'=>$head_list,
|
|
'hero_list'=>$hero_list,
|
|
);
|
|
}
|
|
|
|
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";
|
|
}
|
|
)
|
|
);
|
|
}
|
|
|
|
public static function getUserByRank($rank){
|
|
|
|
$list = SqlHelper::ormSelect(
|
|
myself()->_getSelfMysql(),
|
|
't_user',
|
|
array(
|
|
'rank'=> $rank
|
|
)
|
|
);
|
|
return $list ? $list: array();
|
|
}
|
|
|
|
public static function getUserByRankMess($row){
|
|
$currSeasonMeta = mt\RankSeason::getCurrentSeason();
|
|
$gameTimes = 0;
|
|
if ($currSeasonMeta){
|
|
$season = Season::findByAccount($row['account_id'],$currSeasonMeta['id']);
|
|
if ($season){
|
|
$battleData = json_decode($season['battle_data'], true);
|
|
$seasonBattleData = isset($battleData) ? getXVal($battleData, 'season_data', array()) : array();
|
|
$gameTimes = getXVal($seasonBattleData, 'total_battle_times', 0);
|
|
}
|
|
}
|
|
$toDto =array(
|
|
'idx' => $row['idx'],
|
|
'account_id' => $row['account_id'],
|
|
'channel' => $row['channel'],
|
|
'name' => $row['name'],
|
|
'head_id' => $row['head_id'],
|
|
'head_frame' => $row['head_frame'],
|
|
'rank' => $row['rank'],
|
|
'history_best_rank' => $row['history_best_rank'],
|
|
'score' => $row['score'],
|
|
'history_best_score' => $row['history_best_score'],
|
|
//排位场数
|
|
'rank_num' => $gameTimes,
|
|
);
|
|
return $toDto;
|
|
}
|
|
|
|
public static function orderBy($users){
|
|
$len = count($users);
|
|
if ($len<=1){
|
|
return $users;
|
|
}
|
|
for ($i = 0; $i < $len - 1; $i++) {
|
|
for ($j = $i + 1; $j < $len; $j++) {
|
|
if ($users[$i]['score'] < $users[$j]['score']) {
|
|
$tmp = $users[$i];
|
|
$users[$i] = $users[$j];
|
|
$users[$j] = $tmp;
|
|
}
|
|
}
|
|
}
|
|
return $users;
|
|
}
|
|
|
|
public static function allUser(){
|
|
$list = SqlHelper::ormSelect(
|
|
myself()->_getSelfMysql(),
|
|
't_user',
|
|
array(
|
|
)
|
|
);
|
|
return $list ? $list: array();
|
|
}
|
|
|
|
public static function upsertHeadList($itemMeta){
|
|
$head = $itemMeta?$itemMeta['normal_gift']:'';
|
|
if (!$head){
|
|
return;
|
|
}
|
|
$userInfo = myself()->_getOrmUserInfo();
|
|
$head_list = emptyReplace(json_decode($userInfo['head_list'], true), array());
|
|
if (in_array($head,$head_list)){
|
|
return;
|
|
}
|
|
array_push($head_list,$head);
|
|
$fields = array(
|
|
'head_list' => json_encode($head_list),
|
|
);
|
|
self::update($fields);
|
|
}
|
|
|
|
}
|