194 lines
7.7 KiB
PHP
194 lines
7.7 KiB
PHP
<?php
|
||
/**仓库操作
|
||
* Created by PhpStorm.
|
||
* User: ddcai
|
||
* Date: 2018/11/29
|
||
* Time: 16:13
|
||
*/
|
||
class ajax_store extends ajax_base{
|
||
|
||
//获取仓库信息的协议
|
||
public function store_info(){
|
||
$uid = $this->arr['token']['uid'];
|
||
//用户属性
|
||
$store_data = get_store_data($uid,true,$GLOBALS["conn"],$GLOBALS['myredis']);
|
||
$return_arr = array(
|
||
"ga" => 'store_info_bak',
|
||
"code" => 1,
|
||
"gd" => $store_data
|
||
);
|
||
die(return_ajax($return_arr));
|
||
}
|
||
|
||
//从仓库出售物品的协议
|
||
public function store_good_del(){
|
||
//获取上传的数据
|
||
$uid = $this->arr['token']['uid'];
|
||
$good_id = $this->arr['d']['good_id'];
|
||
$num = intval($this->arr['d']['num']);
|
||
|
||
$return_arr = array(
|
||
'ga' => 'HTTP_ERROR_BAK',
|
||
"code" => 2,//1成功,2失败,3停服维护
|
||
"msg" => '删出物品出错' //登陆信息提示
|
||
);
|
||
//判断上传的物品是否正确
|
||
if( empty($uid) || empty($good_id) || $num<1){
|
||
$return_arr['msg']="物品ID不正确";
|
||
die(return_ajax($return_arr));
|
||
}
|
||
//用户的物品
|
||
$info = get_info($GLOBALS["conn"],'game_member_goods',array()," and uid=".$uid." and good_id='".$good_id."'");
|
||
|
||
if($info && isset($info['sysid'])){//如果有找到物品
|
||
if($info['num']>=$num){//如果物品数据足够
|
||
//把物品移出仓库
|
||
$arr = array(
|
||
'good_id'=>$good_id,//"物品ID",
|
||
'num'=>$num,//"物品数量",
|
||
'ip'=>$this->arr['ip']//"移出时的IP地址"
|
||
);
|
||
$tmp_del = store_good_data_del($uid,$arr,$GLOBALS["conn"],$GLOBALS['myredis']);
|
||
if($tmp_del){
|
||
|
||
//物品数据
|
||
$good_info = $GLOBALS["SYS_GOOD_INFO"][$good_id];
|
||
//宝石增加
|
||
$good_gold = $good_info['num']*$num;
|
||
if($good_gold>0){
|
||
$u_gold = $good_gold; //改变的宝石数
|
||
$u_type = 1; //改变类型(1增加宝石,2减少宝石)
|
||
$u_info = '出售'.$good_info['name'].'获得,出售数量为:'.$num; // 说明
|
||
update_user_have_gold( $uid, $u_gold, $u_type, $u_info, $this->arr['ip'], $GLOBALS["conn"],$GLOBALS['myredis'] );
|
||
}
|
||
|
||
$new_user_goods = get_game_user_goods_info($uid,$good_id,'',$GLOBALS["conn"],$GLOBALS['myredis']);
|
||
$return_arr = array(
|
||
"ga"=>"store_good_del_bak",
|
||
"gd"=>array(
|
||
'store_id' => $new_user_goods?$new_user_goods['store_id']:0,
|
||
'good_id' => $good_id,
|
||
'pos' => $new_user_goods?$new_user_goods['pos']:0,
|
||
'num' => $new_user_goods?$new_user_goods['num']:0,
|
||
'msg' => '出售成功!'
|
||
),
|
||
"code"=>1 //如果失败返回2
|
||
);
|
||
die(return_ajax($return_arr));
|
||
}
|
||
}
|
||
}
|
||
$return_arr = array(
|
||
"ga"=>"store_good_del_bak",
|
||
"gd"=>array(
|
||
'good_id'=>$good_id,//'物品ID',
|
||
'num'=>$num,//'物品数量',
|
||
'msg'=>'出售失败,物品不足!'
|
||
),
|
||
"code"=>2 //如果失败返回2
|
||
);
|
||
die(return_ajax($return_arr));
|
||
}
|
||
|
||
//仓库出升级的协议
|
||
public function store_up_gread(){
|
||
//获取上传的数据
|
||
$uid = $this->arr['token']['uid'];
|
||
$store_id = $this->arr['d']['store_id'];//仓库ID
|
||
|
||
$return_arr = array(
|
||
'ga' => 'HTTP_ERROR_BAK',
|
||
"code" => 2,//1成功,2失败,3停服维护
|
||
"msg" => '操作出错' //登陆信息提示
|
||
);
|
||
//判断上传的物品是否正确
|
||
if( empty($uid) || empty($store_id)){
|
||
$return_arr['msg']="仓库ID不正确";
|
||
die(return_ajax($return_arr));
|
||
}
|
||
|
||
//查一下用户当前仓库的等级
|
||
$tmp_store = get_store_data($uid,false,$GLOBALS['conn'],$GLOBALS['myredis']);
|
||
if($tmp_store && $tmp_store['store_id']==$store_id){//如果这个库真的属于这个用户的,则执行
|
||
$store_gread_new = $tmp_store['grade']+1;
|
||
if(isset($GLOBALS["SYS_STORE_INFO"][$store_gread_new])){
|
||
//新等级的仓库数据
|
||
$tmp_store_new = $GLOBALS["SYS_STORE_INFO"][$store_gread_new];
|
||
//获取用户的属性信息
|
||
$tmp_user_prop = get_game_user_prop($uid,$GLOBALS['conn'],$GLOBALS['myredis']);
|
||
|
||
//如果要求的等级高于用户的实际等级,则不能升
|
||
if($tmp_store_new['grade2']>$tmp_user_prop['grade']){
|
||
|
||
$return_arr['msg']="用户等级不够,不能升级";
|
||
die(return_ajax($return_arr));
|
||
}
|
||
//判断需要的物品是否足够
|
||
$is_ok = check_user_good($uid,$tmp_store_new['good'],$GLOBALS['conn'],$GLOBALS['myredis']);
|
||
if($is_ok){//如果物品足够,则扣物物品,完成升级
|
||
$is_ok = del_user_good($uid,$this->arr['ip'],$tmp_store_new['good'],$GLOBALS['conn'],$GLOBALS['myredis']);
|
||
if($is_ok){//如果移除物品成功
|
||
//处理仓库升级的操作
|
||
$tmp_arr = array(
|
||
'grade'=>$tmp_store_new['grade'],//'仓库等级',
|
||
'num'=>$tmp_store_new['num'],//'仓库总大小',
|
||
'num3'=>$tmp_store_new['num2'],//'每格的大小',
|
||
'up_time'=>date("Y-m-d H:i:s",time())//'修改时间',
|
||
);
|
||
$is_ok = update_game_member_store($uid,$store_id,$tmp_arr,$conn=false,$myredis=false);
|
||
if($is_ok){//升级成功
|
||
|
||
$new_store_info = get_store_data($uid,false,$GLOBALS['conn'],$GLOBALS['myredis']);
|
||
$return_arr = array(
|
||
"ga"=>"store_up_gread_bak",
|
||
"gd"=>array(
|
||
'store_id'=>$new_store_info['store_id'],//'仓库系统ID',
|
||
'grade'=>$new_store_info['grade'],//'仓库等级',
|
||
'num'=>$new_store_info['num'],//'仓库总大小',
|
||
'num2'=>$new_store_info['num2'],//'仓库已使用数量',
|
||
'num3'=>$new_store_info['num3'],//'每格的大小',
|
||
'name'=>$new_store_info['name'],//'仓库名称'
|
||
),
|
||
"code"=>1
|
||
);
|
||
die(return_ajax($return_arr));
|
||
|
||
}else{
|
||
$return_arr['msg']="升级失败";
|
||
}
|
||
}else{
|
||
//$return_arr['msg']="物品不足,升级失败";
|
||
$return_arr = array(
|
||
"ga"=>"game_txt_tip",
|
||
"gd"=>array(
|
||
'msg'=>"金币不足!"
|
||
),
|
||
"code"=>1
|
||
);
|
||
}
|
||
}else{//物品不足
|
||
//$return_arr['msg']="物品不足,升级失败";
|
||
$return_arr = array(
|
||
"ga"=>"game_txt_tip",
|
||
"gd"=>array(
|
||
'msg'=>"金币不足!"
|
||
),
|
||
"code"=>1
|
||
);
|
||
}
|
||
}else{
|
||
$return_arr['msg']="不存在的仓库等级";
|
||
}
|
||
}
|
||
die(return_ajax($return_arr));
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} |