public function update_my_level($player_id) { $player_id = intval($player_id); $vip_special_info = $this->get_data('VipSpecial')->get_vip_special_info($player_id); $now = strtotime(date('Y-m-d')); $del_exp = 50; if (empty($vip_special_info)) { #非vip特权 return 0; } #判断是否存在临时vip特权 if (isset($vip_special_info['temp_level']) && $vip_special_info['temp_level'] >= $vip_special_info['vip_special_level'] && $vip_special_info['temp_end'] > $now) { $this->get_data('Player')->update_player_info($player_id, array('privilege_level' => $vip_special_info['temp_level'])); $left_time = $vip_special_info['temp_end'] - time(); $left_date = ceil($left_time / (3600 * 24)); $this->get_data('VipSpecial')->update_vip_special_info($player_id, array('temp_date' => $left_date)); $this->add_player_attr($vip_special_info['temp_level'], $player_id); return 0; } else { $this->get_data('VipSpecial')->update_vip_special_info($player_id, array('temp_date' => 0, 'temp_level' => 0)); $left_time = $vip_special_info['end_time'] - time(); } $vip_level = $this->get_level_for_exp($vip_special_info['vip_special_exp']); #确保2个地方的数据一致 $this->get_data('Player')->update_player_info($player_id, array('privilege_level' => $vip_level)); $this->get_data('VipSpecial')->update_vip_special_info($player_id, array('vip_special_level' => $vip_level)); if (!isset($vip_special_info['update_time'])) { $vip_special_info['update_time'] = time(); } #已经计算过经验 if ($vip_special_info['update_time'] >= $now) { $this->add_player_attr($vip_level, $player_id); if ($left_time < 0) { $left_time = 0; } Protocol_Player::p2c_part_update($player_id, array('privilege_level' => $vip_level, 'privilege_left_time' => $left_time)); return 0; } else { $card_id = $vip_special_info['special_sell_card_id']; $card_info = Cache_VipSpecial::getInstance()->get_special_card($card_id); #根据购买的最高卡获取加经验信息 $left_date = intval($vip_special_info['left_date']); #剩余天数 $num = ceil((time() - $vip_special_info['update_time']) / (24 * 3600)); #计算间隔天数 $min = Cache_VipSpecial::getInstance()->get_special_level(1); #获取最低等级的配置 $sum_exp = $vip_special_info['vip_special_exp']; if ($left_date > 0) { #超过使用天数 if ($num >= $left_date) { $vip_special_info['left_date'] = 0; $add_exp = $left_date * $card_info['perday_exp'] - ($num - $left_date) * $del_exp; #扣除不能低于1级 if ($vip_special_info['vip_special_exp'] + $add_exp < $min['special_exp']) { $vip_special_info['vip_special_exp'] = $min['special_exp']; $sum_exp = $min['special_exp']; } else { if ($add_exp >= 0) { $vip_special_info['vip_special_exp'] = '+' . $add_exp; } else { $vip_special_info['vip_special_exp'] = '-' . abs($add_exp); } $sum_exp += $add_exp; } $vip_special_info['vip_special_level'] = $this->get_level_for_exp($sum_exp); } else { $sum_exp += $num * $card_info['perday_exp']; $vip_special_info['left_date'] = $left_date - $num; $vip_special_info['vip_special_exp'] = '+' . $num * $card_info['perday_exp']; $vip_special_info['vip_special_level'] = $this->get_level_for_exp($sum_exp); } } else { $sum_exp -= $del_exp * $num; $vip_special_info['vip_special_exp'] = '-' . $num * $del_exp; #扣除不能低于1级 if ($sum_exp < $min['special_exp']) { $sum_exp = $min['special_exp']; } $vip_special_info['vip_special_level'] = $this->get_level_for_exp($sum_exp); $vip_special_info['left_date'] = 0; } #更新 $update_vip_data = array('vip_special_exp' => $vip_special_info['vip_special_exp'], 'left_date' => $vip_special_info['left_date'], 'vip_special_level' => $vip_special_info['vip_special_level'], 'update_time' => time()); if ($this->get_data('VipSpecial')->update_vip_special_info($player_id, $update_vip_data)) { $this->get_data('Player')->update_player_info($player_id, array('privilege_level' => $vip_special_info['vip_special_level'])); $left_time = $vip_special_info['end_time'] - time(); if ($left_time < 0) { $left_time = 0; } Protocol_Player::p2c_part_update($player_id, array('privilege_level' => $vip_special_info['vip_special_level'], 'privilege_left_time' => $left_time)); $this->add_player_attr($vip_special_info['vip_special_level'], $player_id); } return true; } return true; }
/** * 获取vip特权信息 * @param int player_id 玩家id * @return array */ public function get_vip_special($player_id) { $player_id = intval($player_id); //获取奖励配置 if (!($set_vip = Cache_VipSpecial::getInstance()->get_special_card())) { $this->throw_error(10222, 6010097); } $career_type = $this->get_data('Player')->get_player_info($player_id, 'career_type'); $ret = array(); foreach ($set_vip as $vip) { $ret[$vip['card_id']] = $vip['cost_gold_num']; } return array(0 => $ret); }