예제 #1
0
 public function fund_income($player_id, $fund_id, $income_offset)
 {
     $this->param_check_numeric(array($player_id, $fund_id));
     $player_info = $this->get_data('Player')->get_player_info($player_id, array('level', 'vip', 'privilege_level'));
     # 获取基金配置信息
     $fund_conf = Cache_Finance::getInstance()->get_fund_conf($fund_id);
     if (empty($fund_conf)) {
         $this->throw_error(110001);
         # 获取基金信息失败
     }
     # 获取玩家某种类型基金的投资情况
     list($invest_acc, $invest_lvl, $invest_time) = $this->get_data('Finance')->get_player_fund_invest_log_by_type($player_id, $fund_conf['fund_type']);
     # 获取玩家某种类型基金的收益情况
     list($income_log_hash_1, $income_log_hash_2) = $this->get_data('Finance')->get_player_fund_income_log_by_type($player_id, $fund_conf['fund_type']);
     # 获取基金收益配置信息
     switch ($fund_conf['fund_type']) {
         case 1:
             # 时间基金
             $income_conf_list = Cache_Finance::getInstance()->get_fund_income_conf_list_time($fund_conf['fund_id']);
             $current_income_offset = $this->_cal_income_offset($invest_time);
             break;
         case 2:
             # 等级基金
             if (!empty($invest_lvl)) {
                 $income_conf_list = Cache_Finance::getInstance()->get_fund_income_conf_list_level_2($fund_conf['fund_id'], $invest_lvl);
             } else {
                 $income_conf_list = Cache_Finance::getInstance()->get_fund_income_conf_list_level_2($fund_conf['fund_id'], $player_info['level']);
             }
             $current_income_offset = $player_info['level'];
             break;
         default:
             $income_conf_list = array();
             break;
     }
     # 判断达成条件
     if ($current_income_offset < $income_offset) {
         $this->throw_error(110002);
         # 未达成该档基金收益领取条件
     }
     # 判断是否已领取过
     if (isset($income_log_hash_1[$fund_id][$income_offset])) {
         $this->throw_error(110003);
         # 已领取过该档基金收益
     }
     # 判断是发直接收益,还是补差收益
     $income_type = 0;
     $income_num = 0;
     if (isset($income_log_hash_2[$income_offset])) {
         $income_type = 1;
         # 按价格由高到低排序
         Com_Array::multisort($income_log_hash_2[$income_offset], array('fund_price' => 'desc'));
         $income_log_info = reset($income_log_hash_2[$income_offset]);
         $income_num = $income_conf_list[$income_offset]['income'] - $income_log_info['income_num'];
     } else {
         $income_num = $income_conf_list[$income_offset]['income'];
     }
     $this->start_trans();
     # 发放免费奖励
     $reward = array(array('type' => 'ticket', 'item_id' => $this->fund_income_cur_id, 'item_num' => $income_num));
     if (!empty($reward)) {
         $re = $this->get_game('Reward')->send_reward($player_id, $reward, array('cmd_id' => '2704'), 1);
         $this->write_check_strict($re, 3010411);
     }
     # 记录收益领取日志
     $income_log = array('player_id' => $player_id, 'fund_id' => $fund_id, 'income_offset' => $income_offset, 'fund_type' => $fund_conf['fund_type'], 'fund_price' => $fund_conf['fund_price'], 'income_time' => $this->current_time, 'income_num' => $income_num, 'income_type' => $income_type);
     $re = $this->get_data('Finance')->insert_fund_income_log($income_log);
     $this->write_check($re, 3010277);
     $this->commit();
     # 刷新基金列表
     $out_2701 = $this->get_fund_list($player_id, $fund_conf['fund_type']);
     Protocol::input($player_id, 3, 27, 2701, $out_2701);
     # 记录行为
     Com_Log::debug_write('xgame.finance', "{$player_id}\t" . "fund_income\t" . "{$fund_id}\t" . "{$income_offset}\t");
     $out_2704 = array('fund_type' => $fund_conf['fund_type']);
     return $out_2704;
 }
예제 #2
0
 public function fund_income($player_id, $fund_id, $income_offset)
 {
     $this->param_check_numeric(array($player_id, $fund_id));
     $player_info = $this->get_data('Player')->get_player_info($player_id, array('level', 'vip', 'privilege_level'));
     # 获取基金配置信息
     $fund_conf = Cache_Finance::getInstance()->get_fund_conf($fund_id);
     if (empty($fund_conf)) {
         $this->throw_error(110001);
         # 获取基金信息失败
     }
     # 获取玩家某种类型基金的交易日志
     $deal_log = $this->get_data('Finance')->get_player_fund_deal_log($player_id, $fund_conf['fund_type']);
     if (empty($deal_log)) {
         $this->throw_error(110007);
         # 未购买此种类型基金,不能领取收益
     }
     # 获取玩家某种类型基金的收益情况
     list($income_log_hash_1, $income_log_hash_2, $income_acc) = $this->get_data('Finance')->get_player_fund_income_log_by_type($player_id, $fund_conf['fund_type']);
     # 获取基金收益配置信息
     switch ($fund_conf['fund_type']) {
         case 1:
             # 时间基金
             $income_conf_list = Cache_Finance::getInstance()->get_fund_income_conf_list_time($fund_conf['fund_id']);
             $current_income_offset = $this->_cal_income_offset($deal_log['deal_time']);
             break;
         case 2:
             # 等级基金
             $income_conf_list = Cache_Finance::getInstance()->get_fund_income_conf_list_level_2($fund_conf['fund_id'], $deal_log['invest_level']);
             $current_income_offset = $player_info['level'];
             break;
         default:
             $income_conf_list = array();
             break;
     }
     if (empty($income_conf_list)) {
         $this->throw_error(110008);
         # 获取基金收益配置信息失败
     }
     # 判断达成条件
     if ($current_income_offset < $income_offset) {
         $this->throw_error(110002);
         # 未达成该档基金收益领取条件
     }
     # 判断是否已领取过
     if (isset($income_log_hash_1[$fund_id][$income_offset])) {
         $this->throw_error(110003);
         # 已领取过该档基金收益
     }
     $this->start_trans();
     # 发放免费奖励
     $reward = array(array('type' => 'ticket', 'item_id' => $this->fund_income_cur_id, 'item_num' => $income_conf_list[$income_offset]['income']));
     if (!empty($reward)) {
         $re = $this->get_game('Reward')->send_reward($player_id, $reward, array('cmd_id' => '2704'), 1);
         $this->write_check_strict($re, 3010411);
     }
     # 记录收益领取日志
     $income_log = array('player_id' => $player_id, 'fund_id' => $fund_id, 'income_offset' => $income_offset, 'fund_type' => $fund_conf['fund_type'], 'income_time' => $this->current_time, 'income_num' => $income_conf_list[$income_offset]['income']);
     $re = $this->get_data('Finance')->insert_fund_income_log($income_log);
     $this->write_check($re, 3010277);
     $this->commit();
     # 该方法会自动推送843协议告知前端显示奖励信息,会调用prop_806协议通知道具变更,调用p2c_part_update通知人物信息变更
     $ret = $this->get_game('Reward')->add_reward_log(true);
     # 可领收益档次刷新埋点
     $this->get_game('PlayerFunc')->sync_func_tips($player_id, $this->func_id);
     # 刷新基金列表
     $out_2701 = $this->get_fund_list($player_id, $fund_conf['fund_type']);
     Protocol::input($player_id, 3, 27, 2701, $out_2701);
     # 记录行为
     Com_Log::debug_write('xgame.finance', "{$player_id}\t" . "fund_income\t" . "{$fund_id}\t" . "{$income_offset}\t");
     $out_2704 = array('fund_type' => $fund_conf['fund_type']);
     return $out_2704;
 }