|
|
|
@ -790,4 +790,75 @@ class ConsoleController extends Think {
|
|
|
|
|
M('spend', 'tab_')->where(['promote_id' => ['in', $ids], 'spend_time' => ['egt', $orderTime]])->save(['market_admin_id' => $toPromote['admin_id']]);
|
|
|
|
|
} */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function roleHash()
|
|
|
|
|
{
|
|
|
|
|
$lastId = 0;
|
|
|
|
|
do {
|
|
|
|
|
$records = M('user_play_info', 'tab_')->field(['id', 'role_id', 'user_id', 'base_game_id'])->where(['id' => ['gt', $lastId]])->limit(1000)->select();
|
|
|
|
|
$count = 0;
|
|
|
|
|
foreach ($records as $record) {
|
|
|
|
|
$lastId = $record['id'];
|
|
|
|
|
$salt = 0;
|
|
|
|
|
$count ++;
|
|
|
|
|
$value = $record['base_game_id'] . '#' . $record['user_id'] . '#' . 0 . '#' . $record['role_id'] . '#' . $salt;
|
|
|
|
|
$hashCode = $this->hashCode64($value);
|
|
|
|
|
$key = 'role_key:' . $hashCode;
|
|
|
|
|
if ($existRecord = Redis::get($key)) {
|
|
|
|
|
$existRecord = json_decode($existRecord, true);
|
|
|
|
|
if ($record['base_game_id'] == $existRecord['base_game_id'] && $record['user_id'] == $existRecord['user_id'] && $record['role_id'] == $existRecord['role_id']) {
|
|
|
|
|
} else {
|
|
|
|
|
[$salt, $hashCode] = $this->getNewSalt($record);
|
|
|
|
|
M('user_play_info', 'tab_')->where(['id' => $record['id']])->save([
|
|
|
|
|
'role_key' => $hashCode,
|
|
|
|
|
'role_key_salt' => $salt,
|
|
|
|
|
]);
|
|
|
|
|
$key = 'role_key:' . $hashCode;
|
|
|
|
|
Redis::set($key, json_encode($record));
|
|
|
|
|
echo 'UPDATE: ' . $record['id'];
|
|
|
|
|
echo "\n";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Redis::set($key, json_encode($record));
|
|
|
|
|
}
|
|
|
|
|
/* M('user_play_info', 'tab_')->where(['id' => $record['id']])->save([
|
|
|
|
|
'role_key' => $hashCode,
|
|
|
|
|
'role_key_salt' => $salt,
|
|
|
|
|
]); */
|
|
|
|
|
}
|
|
|
|
|
echo 'SUCCESS_COUNT: ' . $count . ' LAST_ID:' . $lastId;
|
|
|
|
|
echo "\n";
|
|
|
|
|
} while ($count > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getNewSalt($record)
|
|
|
|
|
{
|
|
|
|
|
$salt = 0;
|
|
|
|
|
$hashCode = 0;
|
|
|
|
|
do {
|
|
|
|
|
$salt += 1;
|
|
|
|
|
$value = $record['game_id'] . '#' . $record['user_id'] . '#' . 0 . '#' . $record['role_id'] . '#' . $salt;
|
|
|
|
|
$hashCode = $this->hashCode64($value);
|
|
|
|
|
$key = 'role_key:' . $hashCode;
|
|
|
|
|
$existRecord = Redis::get($key);
|
|
|
|
|
} while ($existRecord);
|
|
|
|
|
|
|
|
|
|
return [$salt, $hashCode];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function hashCode64($str) {
|
|
|
|
|
$str = (string)$str;
|
|
|
|
|
$hash = 0;
|
|
|
|
|
$len = strlen($str);
|
|
|
|
|
if ($len == 0 )
|
|
|
|
|
return $hash;
|
|
|
|
|
for ($i = 0; $i < $len; $i++) {
|
|
|
|
|
$h = $hash << 5;
|
|
|
|
|
$h -= $hash;
|
|
|
|
|
$h += ord($str[$i]);
|
|
|
|
|
$hash = $h;
|
|
|
|
|
$hash &= 0x7FFFFFFF;
|
|
|
|
|
}
|
|
|
|
|
return $hash;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|