📄 buy_horse.php
字号:
<?php
require_once("configs/Configs.php");//加载配置文件
require_once("functions/login_flag.php");//是否已经登录
require_once("functions/func_common.php");//加载函数文件
require_once("functions/class_mysql.php");//加载数据库类文件
//读取马匹基础表
$query=$db->query("select * from horse_attribute");
while($row=$db->fetch_array($query)) $horse_list[]=$row;
//读取建筑表 - 牧场等级
if($_COOKIE['city_type']=="1"){
$query=$db->query("select r.rices,r.golds,b.b_horse,r.free_stores from building b,city c,resource as r where b.`u_id`=c.`u_id` and c.`u_id`=r.`u_id` and b.`c_id`=c.`c_id` and r.`u_id`='".$_COOKIE['UserId']."' and b.`c_id`='".$_COOKIE['CityId']."'");
}elseif($_COOKIE['city_type']=="0"){
$query=$db->query("select r.rices,r.golds,b.b_horse,r.free_stores from building b,city c,resource as r where b.`u_id`=c.`u_id` and c.`u_id`=r.`u_id` and b.`c_id`=c.`c_id` and r.`u_id`='".$_COOKIE['UserId']."' and b.`c_id`=(select c_id from city where `u_id`='".$_COOKIE['UserId']."' and `c_type`='1')");
}
$building_result=$db->fetch_array($query);
//读取研究表study
$query=$db->query("select s_gee from study where `u_id`='".$_COOKIE['UserId']."'");
$study_result=$db->fetch_array($query);
//购买马匹
if($_POST['action']=="buy_horse"){
if(!is_numeric(trim($_POST['h_num']))) echomsg("马匹数量输入不规范!");
$h_type=$_POST['h_type'];
$h_num=trim($_POST['h_num']);
if(($h_num<1 or strlen($h_num)<1)) echomsg("");
//判断牧场等级、研究技术等级及资源
if($building_result['b_horse']<=0 or $building_result['b_horse']=="") echomsg("购买马匹需先建造牧场!");
if($study_result['s_gee']<1 and $h_type=="1") echomsg("需研究养马技术1级!");
if($study_result['s_gee']<2 and $h_type=="2") echomsg("需研究养马技术2级!");
if($study_result['s_gee']<3 and $h_type=="3") echomsg("需研究养马技术3级!");
if($horse_list<>"") foreach ($horse_list as $j=>$row) {
if($row['h_type']=="1" and $h_type=="1"){
$need_golds = $h_num * $row['h_price'];
break;
}
if($row['h_type']=="2" and $h_type=="2"){
$need_golds = $h_num * $row['h_price'];
break;
}
if($row['h_type']=="3" and $h_type=="3"){
$need_golds = $h_num * $row['h_price'];
break;
}
}
if($need_golds > $building_result['golds']) echomsg("黄金不足!");
//扣除黄金,同时减少仓库空间大小
$query=$db->query("update resource set `golds`=(`golds` - '".$need_golds."'),`free_stores`=(`free_stores`-'".$need_golds."') where `u_id`='".$_COOKIE['UserId']."'");
//购买马匹成功处理
$query1=$db->query("select h_id from horse where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."' and `h_type`='".$h_type."'");
$rn=$db->num_rows($query1);
if($query){
if($rn>0) $info=$db->query("update horse set `h_num`=(`h_num` + '".$h_num."') where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."' and `h_type`='".$h_type."'");
else $info=$db->query("insert into horse(`h_id`,`u_id`,`c_id`,`h_type`,`h_num`) values('','".$_COOKIE['UserId']."','".$_COOKIE['CityId']."','".$h_type."','".$h_num."')");
}
update_resource();
if($info) echomsg("购买马匹成功!","?");
}
$db->close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>购买马匹</title>
<link href="css/id.css" rel="stylesheet" type="text/css">
<link href="css/css.css" rel="stylesheet" type="text/css">
<link type="text/css" href="css/build.css" rel="stylesheet">
<link type="text/css" href="css/box.css" rel="stylesheet">
<style>
body{
margin-top:0px;
}
</style>
</head>
<body>
<!--导航-->
<?php require_once("army_daohang.htm");?>
<div id="mb_01">
<div class="page_build_title">购买马匹</div>
</div>
<div id="mb_04">
<!--替换区域开始-->
<div style="margin-top:35px;"> </div>
<?php if($building_result['b_horse']>0 and $building_result['b_horse']<>"") { ?>
<!--------循环----------->
<?php if($horse_list <> "") foreach ($horse_list as $i=>$m) { ?>
<div>
<div class="d1f_06">
<img src="img/soldier/<?php echo $m['h_image'];?>" width="42" height="42" border="0" />
</div>
</div>
<div class="d1f_03">
<strong style="margin-right:5px "><?php echo $horse_type_name[$m['h_type']];?></strong><span class="wy_06"><strong>(<?php
//当前拥有马匹
$query=$db->query("select h_num from horse where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."' and `h_type`='".$m['h_type']."'");
$horse=$db->fetch_array($query);
if($horse['h_num']>0) echo $horse['h_num'];
else echo "0";
?>)
</strong></span></div>
<div class="d1f_001" style="margin-top:5px "> 黄金 <span class="wy_05"><?php echo $m['h_price'];?></span> </div>
<?php if(($m['h_type']=="1" and $study_result['s_gee']<1) or ($m['h_type']=="2" and $study_result['s_gee']<2) or ($m['h_type']=="3" and $study_result['s_gee']<3)) { ?>
<div class="d1f_001" style="margin-top:5px ">
<span class="wy_06" style="color:red;">科技研究需达到:<?php echo $m['h_need_study'];?></span>
</div>
<?php } ?>
<div class="d1f_02" style="margin-left:50px; margin-top:5px ">
<?php if($m['h_type']=="1" and $study_result['s_gee']>=1 or $m['h_type']=="2" and $study_result['s_gee']>=2 or $m['h_type']=="3" and $study_result['s_gee']>=3) { ?>
<form action="" method="post" name="buy_horse_form<?php echo $i;?>">
<input type="hidden" name="action" value="buy_horse">
<input type="hidden" name="h_type" value="<?php echo $m['h_type'];?>">
<input type="Text" name="h_num" value="" size="5" tabindex="9">
<a href="javascript:this.buy_horse_form<?php echo $i;?>.submit();" class="d" style="margin-left:10px ">【购买】</a>
</form>
<?php }else { ?>
<span class="wy_05">条件不足</span>
<?php } ?>
</div>
<?php if($i<>"2") { ?>
<div id="d1_00" class="wy_04">------------------------------------------------------------------------------------------</div>
<?php }else{ ?>
<div style="padding-bottom:90px;"></div>
<?php }?>
<?php }}else{ ?>
<div id="building_description" class="task_title" style="padding-bottom:280px;">购买马匹需先建造<a href="build.php?build_page=military_affairs" target="main" class="f">【牧场】</a>军事设施!</div>
<?php } ?>
<!--替换区域结束-->
</div>
<div id="mb_03"></div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -