/** * 出售道具 * @param $player_id * @param $player_prop_ids 用户道具的id 多个用:号隔开 * @return array|string */ public function item_sell($player_id, $player_prop_ids) { if (empty($player_prop_ids)) { $this->throw_error('10107', '101800243'); } $arr_player_prop_id = array(); foreach ($player_prop_ids as $val) { if ($val[1] <= 0) { $this->throw_error('10107', "101800242{$val[0]}"); } $arr_player_prop_id[$val[0]] = $val[1]; } if (empty($arr_player_prop_id)) { $this->throw_error('10107', '101800243'); } $objPlayerPropGame = $this->get_game('Prop'); $objPlayerPropData = $this->get_data('PlayerProp'); //获取所有出售道具 $arrPlayerPropList = $objPlayerPropData->get_player_prop_detail_multi($player_id, array_keys($arr_player_prop_id)); if (empty($arrPlayerPropList)) { $this->throw_error('10107', '101800244'); } $arr_prop_id = array(); foreach ($arrPlayerPropList as $key => $value) { $arr_prop_id[] = $value['prop_id']; } $arrPropConfigList = Cache_Prop::getInstance()->get_prop_info(array_values($arr_prop_id)); $msg_param = array(); //提示参数 $get_silver = 0; foreach ($arrPlayerPropList as $key => $value) { // if(intval($arrPropConfigList[$value['prop_id']]['can_sell']) == 0){ // $this->throw_error('ERROR_PROP_8'); // } if ($arrPropConfigList[$value['prop_id']]['sale_price'] <= 0) { $this->throw_error('80003', "101800244{$value['prop_id']}"); //游戏配置出错,请联系客服! } if ($arr_player_prop_id[$key] > $value['item_num']) { $arr_player_prop_id[$key] = $value['item_num']; } $msg_param[$value['prop_id']] += $arr_player_prop_id[$key]; $get_silver += $arrPropConfigList[$value['prop_id']]['sale_price'] * $arr_player_prop_id[$key]; } if (!$get_silver) { $this->throw_error('80003', "101800244{$value['prop_id']}"); } $player_info = $this->get_data('Player')->get_player_info($player_id, array('level', 'vip', 'silver', 'privilege_level')); $this->get_data('Player')->check_player_resource($player_id, $player_info, "+", 'silver', $get_silver); $result = true; $objPlayerPropData->start_watch($player_id); $this->start_trans(); if ($result) { // $result = $objPlayerPropData->delete_player_prop($player_id, $arrPlayerPropList,false); $log_param = array('level' => $player_info['level'], 'vip' => $player_info['vip'], 'cmd_id' => 804); foreach ($arr_player_prop_id as $key => $val) { $result = $objPlayerPropData->update_prop_num($player_id, $arrPlayerPropList[$key], $val, "-", $log_param); $arrPlayerPropList[$key]['item_num'] -= $val; if (!$result) { $this->throw_error('80003', "101800245 {$arrPlayerPropList[$key]} {$val}"); } } } if ($result) { // $result = $this->get_data('Player')->update_player_silver($player_id, '+'.$get_silver); $result = $this->get_data('Player')->update_player_resource($player_id, $player_info, 804); } if ($result) { Com_AdCache::set_pipe(false); $this->commit(); if (!empty($msg_param)) { $param = array(); foreach ($msg_param as $prop_id => $num) { // $param[0][] = array( // 'rep_type'=>2, // 'rep_val'=>$prop_id, // 'rep_num'=>$num // ); // Game_GainMsg::add($player_id,1,$prop_id,$num,2); 道具消失不提示 } $param[0] = array('rep_type' => 2, 'rep_val' => Cache_Currency::getInstance()->get_index('silver'), 'rep_num' => $get_silver); Game_GainMsg::add($player_id, 1, Cache_Currency::getInstance()->get_index('silver'), $get_silver); Game_GainMsg::out($player_id); $this->out_error($player_id, '80020', $param); } // Protocol_Player::p2c_part_update($player_id,array('silver'=>'')); $out['result'] = 1; $out['item'] = array('pos' => 1, 'index' => array()); $asyData = array(); foreach ($arrPlayerPropList as $arr_prop_detail) { $out['item']['index'][] = $arr_prop_detail['grid']; // $box = array(); // $box['pos'] = $arr_prop_detail['item_position']; // $box['from_grid'] = $arr_prop_detail['grid']; // $box['item_position'] = $arr_prop_detail['item_position']; // $box['grid'] = $arr_prop_detail['grid']; // $out[2][] = Struct_Prop::get_item_box_operate_struct($box); } $out['silver'] = Cache_Currency::getInstance()->get_index('silver') . ":" . $get_silver; Protocol_Prop::prop_806($player_id, $arrPlayerPropList); return $out; } else { $this->throw_error('80003', '101800246'); //数据库更新失败 } }
/** * 加日志 在整个业务Commit后调用这个函数增加日志 * @param bool $reward_flag true的时候输出 一种奖励框 */ public function add_reward_log($reward_flag = false, $func_id = 0, $show_msg = 1, $upgrade_async = true) { if (!empty($this->arrPlayerReward)) { $this->add_player_reward_log($upgrade_async); } if (!empty($this->arrPropLogs)) { $this->add_prop_reward_log($func_id); } if ($show_msg) { Game_GainMsg::out($this->player_id); } if ($reward_flag) { Protocol_Reward::out($func_id); } else { Protocol_Reward::clear(); } if (!empty($this->protocol)) { Game_AsyncProtocol::getInstance()->rsync_protocol($this->player_id, $this->protocol); } }