Example #1
0
 /**
  * @Purpose:
  * 副本抽奖
  * @Method Name: draw()
  * @Parameter: $player_id 玩家ID
  * @Parameter: $fb_id 副本ID
  * @Return: 返回奖励道具
  */
 public function draw($player_id, $fb_id)
 {
     $player_id = intval($player_id);
     $fb_id = intval($fb_id);
     //是否有抽卡次数
     $draw_data = $this->is_draw($player_id, $fb_id);
     if ($draw_data === false) {
         $this->throw_error('50201');
         //没有抽奖次数
     }
     $data = array();
     //抽奖道具
     $get_draw_res = $this->get_draw_item($fb_id, $draw_data, $data, $player_id);
     if (!$get_draw_res) {
         $this->throw_error('80018');
         //获取掉落库道具失败
     }
     $this->start_trans();
     //扣除抽卡次数
     $draw_data['over_num']--;
     $update_res = $this->deduct_fb_draw_num($player_id, 'over_num', '-1');
     if (!$update_res) {
         $this->throw_error('10102');
     }
     //加入背包
     $result = $this->get_game('Reward')->send_reward($player_id, $data, array('cmd_id' => '812'), 1);
     if ($result !== true) {
         $this->throw_error('80002');
         //道具放入背包失败
     }
     //剩余抽卡次数为0时,删除redis中的临时副本抽奖记录
     if ($draw_data['over_num'] <= 0) {
         $del_res = $this->del_fb_draw_info($player_id);
         if (!$del_res) {
             $this->throw_error('10104');
         }
     }
     $this->commit();
     $this->get_game('Reward')->add_reward_log();
     return Struct_PlayerAttr::get_fb_draw_struct($data[0]);
 }