array(//用户信息 "uid"=>"用户UID", "name"=>"用户微信名称", "nickname"=>"用户呢称", "pic"=>"用户头像", "sex"=>"用户性别", "sid"=>"渠道ID", "sid2"=>"渠道ID2" ), */ function get_game_user_info($uid,$conn,$myredis){ if(empty($uid)){ return false; } $info = get_info($conn,'game_member',array('uid','user_name as name','user_nickname as nickname','user_avatar as pic','sex','source_id as sid','source_id2 as sid2'),' and uid='.$uid); if($info){ $info['name'] = emoji_decode($info['name']); return $info; }else{ return false; } } //获取用户的属性 /* 'prop'=>array(//用户的属性 'uid'=>用户ID 'have_gold'=>可用宝石数 'used_gold'=>已用宝石数 'grade'=>当前等级 'exp'=>当前等级经验 'up_time'=>升级时间 ) */ function get_game_user_prop($uid,$conn,$myredis){ if(empty($uid)){ return false; } $info = get_info($conn,'game_member_prop',array('uid','have_gold','used_gold','grade','exp','up_time'),' and uid='.$uid); if($info){ return $info; }else{ return false; } } //更新用户的属性 /* $arr=>array(//用户的属性 'have_gold'=>可用宝石数 'used_gold'=>已用宝石数 'grade'=>当前等级 'exp'=>当前等级经验 'up_time'=>升级时间 ) $conn=>mysql连接, $myredis=>redis连接, */ function update_game_user_prop($uid,$arr,$conn,$myredis){ if(empty($uid)){ return false; } $prop = array(//用户的属性 'have_gold'=>'可用宝石数', 'used_gold'=>'已用宝石数', 'grade'=>'当前等级', 'exp'=>'当前等级经验', 'up_time'=>'升级时间' ); $arr_up = array(); foreach($arr as $key=>$val){ if(isset($prop[$key])){ $arr_up[$key] = $val; }else{ return false; } } if(empty($arr_up)){ return false; } $info = update_record($conn,'game_member_prop',$arr_up,'',' and uid='.$uid); if($info){ unset($arr_up,$info); //=====begin 进行用户通知 $tmp_send_data = array( 'uid'=>$uid,//http请求的用户UID, 'do_a'=>"do_act",//http要执行的动作(在ajax_user_msg.class.php里制定的动作), 'a'=>"init_info",//需要执行的websocket端动作 'm'=>"gzhq_game",//需要执行的websocket端模块, 'd'=>array("uid"=>$uid),//websocket端执行时自动提交的数据参数(数组) 't'=>time(),//生成消息的时间, ); $tmp_send_data = set_login_token($tmp_send_data); do_act_post_websocket($uid,$tmp_send_data,$myredis); //=====end 进行用户通知 return true; }else{ sys_log_write_content( 'game_member_prop:'.json_encode($arr_up) ,"error_log","game_member_prop_sql"); unset($arr_up,$info); return false; } } //更新用户的花田数据 /* $arr=>array(//用户的花田 'ff_vip' => '花田等级', 'ff_exp' => '花田的经验值', //花田的经验值 'w_uid' => 0, //浇水ID 'w_time' => 0, //浇水总节省时间 'w_produce' => 0, //浇水增加的产量 'w_rate' => 0, //浇水增加的产量百份比 'fat_uid' => strtotime($user_field_info['fat_time'])-time()>0?$user_field_info['fat_uid']:0,//施肥ID 'fat_time' => strtotime($user_field_info['fat_time'])-time()>0?$user_field_info['fat_time']:'0000-00-00 00:00:00',//施肥时间 'fat_produce' => strtotime($user_field_info['fat_time'])-time()>0?$user_field_info['fat_produce']:0,//施肥增加的产量 'fat_rate' => strtotime($user_field_info['fat_time'])-time()>0?$user_field_info['fat_rate']:0,//施肥增加的产量百份 'seed_num' => 0,//种子编号 'ger_time' => '0000-00-00 00:00:00',//发芽时间 'grow_time' => '0000-00-00 00:00:00',//生长时间 'bud_time' => '0000-00-00 00:00:00',//花苞时间 'mature_time' => '0000-00-00 00:00:00',//成熟时间 'grow_static' => 0 //生长状态 ) */ function update_game_user_field($uid,$ff_id,$arr,$conn=false,$myredis=false){ if(empty($uid)){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } $prop = array(//用户的属性 'ff_vip' => 1, //花田等级 'ff_exp' => 0, //花田的经验值 'w_uid' => 0, //浇水ID 'w_time' => 0, //浇水总节省时间 'w_js_time' => '0000-00-00 00:00:00', //可浇水时间 'w_produce' => 0, //浇水增加的产量 'w_rate' => 0, //浇水增加的产量百份比 'fat_uid' => 0,//施肥ID 'fat_time' => '0000-00-00 00:00:00',//施肥时间 'fat_produce' => 0,//施肥增加的产量 'fat_rate' => 0,//施肥增加的产量百份 'seed_num' => 0,//种子编号 'ger_time' => '0000-00-00 00:00:00',//发芽时间 'grow_time' => '0000-00-00 00:00:00',//生长时间 'bud_time' => '0000-00-00 00:00:00',//花苞时间 'mature_time' => '0000-00-00 00:00:00',//成熟时间 'grow_static' => 0 //生长状态 ); $arr_up = array(); foreach($arr as $key=>$val){ if(isset($prop[$key])){ $arr_up[$key] = $val; }else{ return false; } } if(empty($arr_up)){ return false; } $info = update_record($conn,'game_flower_field',$arr_up,''," and uid='".$uid."' and ff_id='".$ff_id."'"); if($info){ unset($arr_up,$info); return true; }else{ sys_log_write_content( 'game_flower_field:'.json_encode($arr_up) ,"error_log","game_flower_field_sql"); unset($arr_up,$info); return false; } } //更新用户数据统计 /* $arr=>array(//用户的花田 'flower_num' => 0, //种植的花卉总数 'order_num' => 0, //完成的订单总数 'goods_num' => 0, //制造的商品总数 'up_time' => date("Y-m-d H:i:s",time()) //数据更新时间 ) */ function update_game_num($uid,$arr,$conn=false,$myredis=false){ if(empty($uid)){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } $prop = array(//用户的属性 'flower_num' => 0, //种植的花卉总数 'order_num' => 0, //完成的订单总数 'goods_num' => 0, //制造的商品总数 'up_time' => date("Y-m-d H:i:s",time()) //数据更新时间 ); $arr_up = array(); foreach($arr as $key=>$val){ if(isset($prop[$key])){ $arr_up[$key] = $val; }else{ return false; } } if(empty($arr_up)){ return false; } $info = update_record($conn,'game_num',$arr_up,''," and uid='".$uid."'"); if($info){ unset($arr_up,$info); return true; }else{ sys_log_write_content( 'game_num:'.json_encode($arr_up) ,"error_log","up_game_num_sql"); unset($arr_up,$info); return false; } } //更新用户的工厂数据 /* $arr=>array(//用户的花田 'grade' => '工厂等级', 'exp' => '当前经验数', //当前经验数 'open_seat_num' => 0, //已开放生产位数量 'max_seat_num' => 0, //最大生产位数量 'used_seat_num' => 0, //已用生产位数量 'goods_num' => 0, //已经生产的物品总数量 'being_goods' => 0, //正在生产的物品 'queue_goods' => 0, //准备生产的物品队列 'succ_goods' => 0 //已完成生产的物品 ) */ function update_game_user_factory($uid,$mf_id,$arr,$conn=false,$myredis=false){ if(empty($uid)){ return false; } $prop = array(//用户的属性 'grade' => 1, 'exp' => 0, //当前经验数 'open_seat_num' => 0, //已开放生产位数量 'max_seat_num' => 0, //最大生产位数量 'used_seat_num' => 0, //已用生产位数量 'goods_num' => 0, //已经生产的物品总数量 'being_goods' => '', //正在生产的物品 'queue_goods' => '', //准备生产的物品队列 'succ_goods' => '' //已完成生产的物品 ); $arr_up = array(); foreach($arr as $key=>$val){ if(isset($prop[$key])){ $arr_up[$key] = $val; }else{ return false; } } if(empty($arr_up)){ return false; } $info = update_record($conn,'game_member_factory',$arr_up,''," and uid='".$uid."' and mf_id='".$mf_id."'"); if($info){ unset($arr_up,$info); return true; }else{ sys_log_write_content( 'game_member_factory:'.json_encode($arr_up) ,"error_log","game_flower_field_sql"); unset($arr_up,$info); return false; } } //获取用户单个花田数据 /* $uid 用户ID $ff_id 花田id $arr 需返回的字段 */ function get_game_user_field_info($uid,$ff_id,$arr=array(),$conn=false,$myredis=false){ if(empty($uid)){ return false; } if(empty($ff_id)){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } $info = get_info($conn,'game_flower_field',$arr," and uid=".$uid." and ff_id='".$ff_id."' "); if($info){ return $info; }else{ return false; } } //获取用户的所有花田数据 /* $uid 用户ID 'field'=>array(//用户的花田 array( 'ff_id'=>花田编号 'ff_vip'=>花田等级 'ff_exp'=>花田的经验值 'seed_data'=>array(//种子数据 'grow_time_tol' => '生长总时间', //生长总时间 'mature_time' => '距离成熟时间', //距离成熟时间 'next_mature_time' => '当前阶段成长时间',//当前阶段成长时间 'grow_static' => '当前生长状态', //1发芽期、2生长期、3花苞期、4成熟期 'water_time' => '可以浇水时间', //可以浇水时间 'id' => '花卉ID', //'花卉ID', 'name' => '花卉名称', //'花卉名称', 'grade' => '花卉等级', //'花卉等级', 'pic' => '当前花卉图片', //'当前花卉图片', 'ain' => '当前花卉动画', //'当前花卉动画', ) ), ) */ function get_game_user_field($uid,$conn=false,$myredis=false){ if(empty($uid)){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } //已解锁的花田总数 $field_tol = $conn->NumRows( $conn->Query("SELECT * FROM ".get_table("game_flower_field")." WHERE `uid`='".$uid."' and `ff_vip`>1 ") ); $next_tmp_ht = $field_tol+1;//下一块花田id $tmp_ht_name = $next_tmp_ht>=10?("ht".$next_tmp_ht):("ht0".$next_tmp_ht); $sql = "SELECT `ff_id`,`ff_vip`,`ff_exp`,`seed_num`,`w_js_time`,`ger_time`,`grow_time`,`bud_time`,`mature_time`,`grow_static`,`fat_time` FROM ".get_table("game_flower_field")." where `uid`=$uid"; $query = $conn->Query($sql); $info = array(); while($value = $conn -> FetchArray($query)) { $tol_field = count($GLOBALS["SYS_FLOWER_FIELD"][$value['ff_id']]);//统计当前花田的所有等级 $flower_field = $GLOBALS["SYS_FLOWER_FIELD"][$value['ff_id']][$value['ff_vip']];//下一级花田数据 //当前生长加速 $seed = 100 + $GLOBALS["SYS_FLOWER_FIELD"][$value['ff_id']][$value['ff_vip']-1]['speed']; $value['ff_exp'] = round($value['ff_exp']);// $value['ff_vip'] = round($value['ff_vip']);// $value['max_grade'] = ($tol_field);//花田的最高等级 $value['next_exp'] = $value['ff_vip']>1?round($flower_field['exp']):0;//花田的升下一级经验值 $value['ff_id_unlocknum'] = $value['ff_vip']>1 ? 0 : round($flower_field['unlocknum']);//解锁所需宝石 $value['next_ff_id_glod'] = $value['ff_vip']>1?round($flower_field['num2']):0;//下一级升级所需宝石 $value['seed'] = $seed;//花田生长加速百分比 $value['next_seed'] = round($flower_field['speed']);//下一级花田生长加速百分比 $value['is_lock'] = $value['ff_vip']>1?2:($value['ff_id']==$tmp_ht_name?1:2);//是否可以解锁花田 1是2否 $value['pic'] = $flower_field['pic']; $value['ain'] = $flower_field['ain']; $sf_data = $GLOBALS["SYS_FLOWER_COMPOSTED"]['sf01'][1];//施肥数据 $value['fat_time'] = strtotime($value['fat_time'])-time()>0? strtotime($value['fat_time'])-time() : 0; //当前施肥时间 $value['fat_time_tol'] = strtotime($value['fat_time'])-time()>0? $sf_data['t'] : 0; //施肥总时间 //如果有种花,则获取花生长的数据 $value['seed_data'] = array(); if($value['seed_num']){ $value['seed_data'] = get_flower_data($uid,$value,$conn,$myredis); } //unset($value['fat_time']); unset($value['w_js_time']); unset($value['ger_time']); unset($value['grow_time']); unset($value['bud_time']); unset($value['seed_num']); unset($value['mature_time']); unset($value['grow_static']); $info[] =$value; } if($info){ return $info; }else{ return false; } } //花卉数据 /* 传入的数据 $arr = array( 'ff_id' => '花田id', 'ff_vip' => '花田等级', 'ff_exp' => '花田经验值', 'seed_num' => '花卉id', 'w_js_time' => '可浇水时间', 'ger_time' => '发芽时间', 'grow_time' => '生长时间', 'bud_time' => '花苞时间', 'mature_time' => '成熟时间', 'grow_static' => '生长状态', 'fat_time' => '施肥有效时间' ) //返回数据 array( 'grow_time_tol' => '生长总时间', //生长总时间 'mature_time' => '距离成熟时间', //距离成熟时间 'next_mature_time' => '当前阶段成长时间',//当前阶段成长时间 'grow_static' => '当前生长状态', //1发芽期、2生长期、3花苞期、4成熟期 'water_time' => '可以浇水时间', //可以浇水时间 'id' => '花卉ID', //'花卉ID', 'name' => '花卉名称', //'花卉名称', 'grade' => '花卉等级', //'花卉等级', 'pic' => '当前花卉图片', //'当前花卉图片', 'ain' => '当前花卉动画', //'当前花卉动画', ) */ function get_flower_data($uid,$arr,$conn=false,$myredis=false){ if(empty($uid)){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } $flower_plants = $GLOBALS["SYS_FLOWER_PLANTS"][$arr['seed_num']][1];//花卉数据 $tmp_time = time(); $water_time = strtotime($arr['w_js_time'])-$tmp_time>0?strtotime($arr['w_js_time'])-$tmp_time:0;//浇水时间 //花的状态 if( strtotime($arr['ger_time'])-$tmp_time>=0 ){ //发芽阶段 $mature_time = strtotime($arr['mature_time'])-$tmp_time;//距离成熟时间 $next_mature_time = strtotime($arr['ger_time'])-$tmp_time;//当前阶段成长时间 $grow_static = 1; }elseif( strtotime($arr['grow_time'])-$tmp_time>=0 && (strtotime($arr['ger_time'])-$tmp_time<0) ){ //生长阶段 grow_time $mature_time = strtotime($arr['mature_time'])-$tmp_time;//距离成熟时间 $next_mature_time = strtotime($arr['grow_time'])-$tmp_time;//当前阶段成长时间 if($arr['grow_static']!=2){ $arr_up = array( 'grow_static' => 2 ); update_game_user_field($uid,$arr['ff_id'],$arr_up,$conn,$myredis); } $grow_static = 2; }elseif( (strtotime($arr['bud_time'])-$tmp_time>0) && (strtotime($arr['grow_time'])-$tmp_time<0) && (strtotime($arr['ger_time'])-$tmp_time<0) ){ //花苞阶段 bud_time $mature_time = strtotime($arr['mature_time'])-$tmp_time;//距离成熟时间 $next_mature_time = strtotime($arr['bud_time'])-$tmp_time;//当前阶段成长时间 if($arr['grow_static']!=3){ $arr_up = array( 'grow_static' => 3 ); update_game_user_field($uid,$arr['ff_id'],$arr_up,$conn,$myredis); } $grow_static = 3; }else{//成熟阶段 mature_time $mature_time = 0;//距离成熟时间 $next_mature_time = 0;//当前阶段成长时间 $water_time = false; if($arr['grow_static']!=4){ $arr_up = array( 'grow_static' => 4 ); update_game_user_field($uid,$arr['ff_id'],$arr_up,$conn,$myredis); } $grow_static = 4; } $pic = 'pic'.($grow_static+1); $ain = 'ain'.($grow_static+1); if( strtotime($arr['fat_time'])-$tmp_time>0 ){//如果施肥还有效 $seed_sf = $GLOBALS["SYS_FLOWER_COMPOSTED"]['sf01'][1]['num2'];//施肥加速 $speed = $flower_plants['speed'] + $GLOBALS["SYS_FLOWER_FIELD"][$arr['ff_id']][$arr['ff_vip']-1]['speed']+$seed_sf;//生长速度 }else{ $speed = $flower_plants['speed'] + $GLOBALS["SYS_FLOWER_FIELD"][$arr['ff_id']][$arr['ff_vip']-1]['speed'];//生长速度 } $flower_seed_data = array(//花卉数据 'grow_time_tol' => strtotime($arr['mature_time'])-$tmp_time>0? round($flower_plants['t']/$speed) : 0, //生长总时间 'mature_time' => $mature_time, //距离成熟时间 'next_mature_time' => $next_mature_time,//当前阶段成长时间 'grow_static' => $grow_static, //1发芽期、2生长期、3花苞期、4成熟期 'water_time' => $water_time, //可以浇水时间 'id' => $arr['seed_num'], //'花卉ID', 'name' => $flower_plants['name'], //'花卉名称', 'grade' => $flower_plants['grade'], //'花卉等级', 'pic' => $flower_plants[$pic], //'当前花卉图片', 'ain' => $flower_plants[$ain], //'当前花卉动画', ); return $flower_seed_data; } //获取仓库的数据 /** $uid=>用户uid, $get_good=是否同时获取仓库对应的物品数据(true获取,false不获取,默认获取) */ function get_store_data($uid,$get_good=true,$conn=false,$myredis=false){ if(empty($uid)){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } $tmp_arr = array( 'sysid as store_id', 'grade', 'num', 'num2', 'num3', 'name' ); $info = get_info($conn,'game_member_store',$tmp_arr," and uid=".$uid); if($info && !empty($info['store_id']) ){ if($get_good){ //查找仓库对应的物品 $sql = "select good_id,pos,num from game_member_goods where uid=".$uid." and store_id=".$info['store_id']; $query = $conn->Query($sql); $info['data_info'] = array(); while($value = $conn->FetchArray($query)) { $info['data_info'][] = $value; } } return $info; }else{ return false; } } //获取用户单个工厂数据 /* $uid 用户ID $mf_id 工厂编号 $arr 需返回的字段 */ function get_game_user_factory_info($uid,$mf_id,$arr=array(),$conn=false,$myredis=false){ if(empty($uid)){ return false; } if(empty($mf_id)){ return false; } $info = get_info($conn,'game_member_factory',$arr," and uid=".$uid." and mf_id='".$mf_id."' "); if($info){ return $info; }else{ return false; } } //获取用户的物品数据 /** $uid=>用户uid */ function get_user_good_data($uid,$conn=false,$myredis=false){ if(empty($uid)){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } //查找仓库对应的物品 $sql = "select good_id,pos,num from game_member_goods where uid=".$uid; $query = $conn->Query($sql); $info = array(); while($value = $conn->FetchArray($query)) { $info[$value['good_id']] = $value; } return $info; } //把物品移出用户的仓库 /** * $arr = array( 'good_id'=>"物品ID", 'num'=>"物品数量", 'ip'=>"移出时的IP地址" ) */ function store_good_data_del($uid,$arr,$conn=false,$myredis=false){ if(empty($uid) || empty($arr['good_id']) || empty($arr['num']) ){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } //判断用户的仓库是否够这么多个物品先 $tmp_good = get_info($conn,'game_member_goods',array()," and uid=".$uid." and good_id='".$arr['good_id']."' and num>=".$arr['num']); if($tmp_good && isset($tmp_good['sysid'])){ //如果数据刚好相等,则删除 if($tmp_good['num']==$arr['num']){ $tmp_del = array('sysid'=>$tmp_good['sysid'],'uid'=>$uid); $rs_del = delete_record($conn,'game_member_goods',$tmp_del); if($rs_del){//如果删除成功,减少用户已使用的仓库个数 $up_arr = array( 'num2'=>"num2-1",//仓库已使用数量', 'up_time'=>date("Y-m-d H:i:s",time())//'修改时间', ); $rs_up = update_record($conn,'game_member_store',$up_arr,array('sysid'=>$tmp_good['store_id'],'uid'=>$uid)); if(!$rs_up){//如果操作出错 sys_log_write_content( 'game_member_store:'.json_encode($up_arr) ,"error_log","game_member_store_sql"); } }else{//如果删除失败 sys_log_write_content( 'game_member_goods:'.json_encode($tmp_del) ,"error_log","game_member_goods_sql"); return false; } }else{//否则减少数量就好了 $up_arr = array( 'num'=>"num-".$arr['num'],//物品数量', 'up_time'=>date("Y-m-d H:i:s",time()),//'完成时间', ); $rs_up = update_record($conn,'game_member_goods',$up_arr,array('sysid'=>$tmp_good['sysid'],'uid'=>$uid)); if(!$rs_up){//如果操作出错 sys_log_write_content( 'game_member_goods:'.json_encode($up_arr) ,"error_log","game_member_goods_sql"); return false; } } //记录删除物品的日志 $arr = array( 'uid'=>$uid,//'用户ID', 'good_id'=>$arr['good_id'],//'物品ID', 'store_id'=>$tmp_good['store_id'],//'仓库ID', 'pos'=>$tmp_good['pos'],//'仓库位置', 'num'=>$arr['num'],//'物品数量', 'add_time'=>date("Y-m-d H:i:s",time()),//'回收时间', 'add_ip'=>$arr['ip'],//'回收时IP', 'info'=>'物品移除' ); add_member_goods_log($arr,$conn,$myredis); return true; }else{ return false; } } //获取用户所有工厂数据 /* $uid 用户ID $arr 需返回的字段 $is_sub 是否指定 数组key */ function get_game_user_factory_all($uid,$arr='*',$is_sub='',$conn=false,$myredis=false){ if(empty($uid)){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } //已有的工厂 $tol = $conn->NumRows( $conn->Query("SELECT * FROM ".get_table("game_member_factory")." WHERE `uid`='".$uid."'") ); if($tol){ $sql = "SELECT ".$arr." FROM ".get_table("game_member_factory")." where `uid`=$uid"; $query = $conn->Query($sql); $info = array(); while($value = $conn -> FetchArray($query)) { $tmp_goods = get_factory_goods($uid,$value,$conn,$myredis); $value['being_goods'] = $tmp_goods['being_goods']?$tmp_goods['being_goods']:array(); $value['queue_goods'] = $tmp_goods['queue_goods']?$tmp_goods['queue_goods']:array(); $value['succ_goods'] = $tmp_goods['succ_goods']?$tmp_goods['succ_goods']:array(); unset($value['goods_num']); if($is_sub){ $info[$value[$is_sub]] = $value; }else{ $info[] = $value; } } return $info; }else{ return false; } } //工厂产品生产数据 /* $uid, $arr */ function get_factory_goods($uid,$arr,$conn=false,$myredis=false){ if(empty($uid)){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } $tmp_being = $arr['being_goods']?json_decode($arr['being_goods'],true):array();//正在生产的数据 $tmp_queue = $arr['queue_goods']?json_decode($arr['queue_goods'],true):array();//排队生产的数据 $tmp_succ = $arr['succ_goods']?json_decode($arr['succ_goods'],true):array();//已完成生产的数据 $info = array(); if($tmp_being || $tmp_queue){ if(strtotime($tmp_being['t2'])-time()>0){//时间大于0 //处理工厂3个生产状态的数据 $info = up_factory_goods($tmp_being,$tmp_queue,$tmp_succ); }else{//否则已完成正在生产的物品 $being_goods = array(); $queue_goods = array(); $queue_tol = $tmp_queue?count($tmp_queue):0;//排队生产数据的总数 if($queue_tol>0){ $being_goods = $tmp_queue[0];//取排队生产数据的第一组数据 $queue_goods = array_splice($tmp_queue,1); $queue_goods = $queue_goods?$queue_goods:array(); } $succ_tol = $tmp_succ?count($tmp_succ):0;//已完成生产数据的总数 if($succ_tol>0){ //array_merge $succ_goods = array_merge_recursive($tmp_succ,array($tmp_being));//合并数组 }else{ $succ_goods[] = $tmp_being; } //处理工厂3个生产状态的数据 if($queue_tol>0){ $info = up_factory_goods($being_goods,$queue_goods,$succ_goods); }else{ $info = array( 'being_goods' => $being_goods, 'queue_goods' => $queue_goods, 'succ_goods' => $succ_goods ); } $being_goods = $being_goods?json_encode($being_goods,JSON_UNESCAPED_UNICODE ):''; $queue_goods = $queue_goods?json_encode($queue_goods,JSON_UNESCAPED_UNICODE ):''; $succ_goods = $succ_goods?json_encode($succ_goods,JSON_UNESCAPED_UNICODE ):''; //更新用户的工厂数据 $up_arr = array( 'used_seat_num' => $queue_goods?count($queue_goods):0, //已用生产位数量 'goods_num' => $arr['goods_num']+1, //已经生产的物品总数量 'being_goods' => $being_goods, //正在生产的物品 'queue_goods' => $queue_goods, //准备生产的物品队列 'succ_goods' => $succ_goods //已完成生产的物品 ); update_game_user_factory($uid,$arr['mf_id'],$up_arr,$conn,$myredis); } }else{ $info = array( 'being_goods' => $tmp_being, 'queue_goods' => $tmp_queue, 'succ_goods' => $tmp_succ ); } return $info; } //处理工厂3个生产状态的数据 /* $tmp_being=array(),//正在生产的数据 $tmp_queue=array(),//排队生产的数据 $tmp_succ=array()//已完成生产的数据 */ function up_factory_goods($tmp_being=array(),$tmp_queue=array(),$tmp_succ=array()){ //正在生产的数据 $tmp_being_goods = array( 'id' => $tmp_being['id'],//生产物品的ID 't' => strtotime($tmp_being['t2'])-time() //还有多少秒生产完成 ); //排队生产的数据 $tmp_queue_goods = array();//返回 排队生产的数据 if($tmp_queue){ foreach($tmp_queue as $k=>$v){ $tmp_queue_goods[] = array( 'id' => $v['id'], 't' => strtotime($v['t'])-strtotime($tmp_being['t2']), 't2' => strtotime($v['t2'])-strtotime($tmp_being['t2']) ); } } //已完成生产的数据 $tmp_succ_goods = $tmp_succ; $info = array( 'being_goods' => $tmp_being_goods, 'queue_goods' => $tmp_queue_goods, 'succ_goods' => $tmp_succ_goods ); return $info; } //工厂生产加入队列处理 /* $id => '生产物品的ID', $time => '生产完成时间', $being_goods = array(//正在生产的数组 'id' => $id,//生产物品的ID 't' => date("Y-m-d H:i:s",$tmp_time),//开始生产时间 't2' => date("Y-m-d H:i:s",$t2),//生产完成时间 'n' => 1 //生产物品个数 ); $queue_goods = array(//正在排队生产的数组 array( 'id' => $id,//生产物品的ID 't' => date("Y-m-d H:i:s",$tmp_time),//开始生产时间 't2' => date("Y-m-d H:i:s",$t2),//生产完成时间 'n' => 1 //生产物品个数 ) ); */ function factory_goods_queue($id,$time,$being_goods,$queue_goods=array()){ if($queue_goods){ //统计当前在排队的生产数组 $tol = $queue_goods?count($queue_goods):0; $t = strtotime($queue_goods[($tol-1)]['t2']);//开始生产时间 $tmp_add_arr = array( 'id' => $id,//生产物品的ID 't' => date("Y-m-d H:i:s",$t),//开始生产时间 't2' => date("Y-m-d H:i:s",($time)+$t),//生产完成时间 'n' => 1 //生产物品个数 ); $tmp_queue_goods = array_merge_recursive($queue_goods,array($tmp_add_arr));//合并数组 }else{ $t = strtotime($being_goods['t2']);//开始生产时间 $tmp_add_arr = array( 'id' => $id,//生产物品的ID 't' => date("Y-m-d H:i:s",$t),//开始生产时间 't2' => date("Y-m-d H:i:s",($time)+$t),//生产完成时间 'n' => 1 //生产物品个数 ); $tmp_queue_goods[] = $tmp_add_arr;// } return $tmp_queue_goods; } //获取用户物品数据 /* $uid 用户ID $good_id 物品id $arr 需返回的字段 */ function get_game_user_goods_info($uid,$good_id,$arr=array(),$conn=false,$myredis=false){ if(empty($uid)){ return false; } if(empty($good_id)){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } $info = get_info($conn,'game_member_goods',$arr," and uid=".$uid." and good_id='".$good_id."' "); if($info){ return $info; }else{ return false; } } //获取用户多个物品数据 /* $uid 用户ID $good_id 多个物品id $arr 需返回的字段 $is_sub 是否指定 数组key */ function get_game_user_goods_all($uid,$good_id='',$arr='*',$is_sub='',$conn=false,$myredis=false){ if(empty($uid)){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } if($good_id){ $sql = "SELECT ".$arr." FROM ".get_table("game_member_goods")." where `uid`=$uid and good_id in (".$good_id.")"; }else{ $sql = "SELECT ".$arr." FROM ".get_table("game_member_goods")." where `uid`=$uid"; } $query = $conn->Query($sql); $info = array(); while($value = $conn -> FetchArray($query)) { if($is_sub){ $info[$value[$is_sub]] = $value; }else{ $info[] = $value; } } if(!empty($info)){ return $info; }else{ return false; } } //把检查仓库是否够用 /* * $arr = array( array( 'good_id'=>"物品ID", 'num'=>"物品数量" ) ) */ function is_check_store($uid,$arr=array(),$conn=false,$myredis=false){ if(empty($uid) || empty($arr) ){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } $tmp_store = get_store_data($uid,true,$conn,$myredis); $data_info_tol = $tmp_store['data_info']?count($tmp_store['data_info']):0;//用户的所有格子数量 foreach($arr as $k=>$v){ $tmp_good = get_info($conn,'game_member_goods',array()," and uid=".$uid." and good_id='".$v['good_id']."'"); if(!$tmp_good && $data_info_tol>=$tmp_store['num']){//如果没有而且还大于仓库格子数量的则提示仓库已满 return false; }else{ return true; } } } //把物品保存到仓库 /* * $arr = array( 'good_id'=>"物品ID", 'num'=>"物品数量" ) */ function store_good_data_save($uid,$arr,$ip,$conn=false,$myredis=false){ if(empty($uid) || empty($arr['good_id']) || empty($arr['num']) ){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } //判断用户的仓库是已经有这个物品先 $tmp_good = get_info($conn,'game_member_goods',array()," and uid=".$uid." and good_id='".$arr['good_id']."'"); if($tmp_good && isset($tmp_good['sysid'])) {//如果已经存有这个物品 $up_arr = array( 'num'=>"num+".$arr['num'],//物品数量', 'up_time'=>date("Y-m-d H:i:s",time()),//'完成时间', ); $rs_up = update_record($conn,'game_member_goods',$up_arr,array('sysid'=>$tmp_good['sysid'],'uid'=>$uid)); if(!$rs_up){//如果操作出错 sys_log_write_content( 'game_member_goods:'.json_encode($up_arr) ,"error_log","game_member_goods_sql"); }else{ return true; } }else{//如果未存有这个物品 /*-----------*/ //判断是否有这个物品 if(isset($GLOBALS["SYS_GOOD_INFO"][$arr['good_id']])){ $tmp_good = $GLOBALS["SYS_GOOD_INFO"][$arr['good_id']]; if($tmp_good['type']==1){//如果是宝石,则添加宝石 if($arr['num']>0){ $u_gold = $arr['num']; //改变的宝石数 $u_type = 1; //改变类型(1增加宝石,2减少宝石) $u_info = '任务获得'; // 说明 update_user_have_gold( $uid, $u_gold, $u_type, $u_info, $ip, $conn,$myredis ); } }elseif($tmp_good['type']==2){//如果是经验,则增加经验 //经验值增加 if($arr['num']>0){ $exp_exp = $arr['num'];//改变的经验数 $exp_info = '任务获得';//经验说明 update_user_exp($uid,$exp_exp,$exp_info,$ip,$conn,$myredis); } }else{//如果是其它物品,则添加到仓库 /*=================*/ //查到可用的仓库格子 $tmp_store = get_store_good_pos($uid,$conn,$myredis); if($tmp_store){//如果有找到可用的格子 $add_arr = array( 'uid'=>$uid,//用户ID', 'good_id'=>$arr['good_id'],//'物品ID', 'store_id'=>intval($tmp_store['store_id']),//'仓库ID', 'pos'=>$tmp_store['pos'],//'仓库位置', 'num'=>$arr['num'],//'物品数量', 'add_time'=>date("Y-m-d H:i:s",time()),//'获得时间', 'up_time'=>date("Y-m-d H:i:s",time())//'完成时间', ); $rs_add = add_record($conn,'game_member_goods',$add_arr); if($rs_add){//如果保存物品成功,则减少仓库可用格数 $up_arr = array( 'num2'=>"num2+1",//仓库已使用数量', 'up_time'=>date("Y-m-d H:i:s",time())//'修改时间', ); $rs_up = update_record($conn,'game_member_store',$up_arr,array('sysid'=>$tmp_store['store_id'],'uid'=>$uid)); if(!$rs_up){//如果操作出错 sys_log_write_content( 'game_member_store:'.json_encode($up_arr) ,"error_log","game_member_store_sql"); return false; }else{ return true; } } } /*=================*/ } }else{ return false; } /*-----------*/ } return false; } //获取用户仓库里最小的可用空格 /* 成功返回: $return = array( "pos"=>"可用的空格", "store_id"=>"仓库ID" ); 失败返回: false */ function get_store_good_pos($uid,$conn=false,$myredis=false){ if(empty($uid)){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } //获取用户的仓库及现存的物品 $tmp_store = get_store_data($uid,true,$conn,$myredis); if(!$tmp_store){ sys_log_write_content( 'get_store_data:读取用户的仓库出错,uid:'.$uid ,"error_log","error_log"); return false; } $pos = false; $is_get = false;//判断是否已经有找到过 for($i=1;$i<=$tmp_store['num'];$i++){ foreach($tmp_store['data_info'] as $val){ if($i==$val['pos']){//如果这格已经用了,则跳出不用检查了 $is_get = true; break; }else{ $is_get = false; } } if($is_get==false){//如果没有找到过,则表示还没有用这个格子 $pos = $i; break; } } if(!$pos){//如果没有可用的格子 return false; }else{ $return_arr = array( "pos"=>$pos,//"可用的空格", "store_id"=>$tmp_store['store_id'],//"仓库ID" ); return $return_arr; } } //判断需要的物品是否足够 /* * $uid=>是判断的用户uid, * $arr=>array(//要求的物品列表 array( 'id'=>"g001",//'生产材料的ID', 'num'=>"250",//'生产材料的数量', ) * ), */ function check_user_good($uid,$arr,$conn=false,$myredis=false){ if(empty($uid) || empty($arr) ){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } //获取玩家仓库物品的数据 $tmp_store_good = get_user_good_data($uid,$conn,$myredis); //如果要求的物品不够 foreach($arr as $val){ //如果有要求的物品,则判断 if(!empty($val['id']) && $val['num']>0 ){ //判断是否有这个物品 if(isset($GLOBALS["SYS_GOOD_INFO"][$val['id']])){ $tmp_good = $GLOBALS["SYS_GOOD_INFO"][$val['id']]; if($tmp_good['type']==1){//如果是宝石 //获取用户的属性信息 $tmp_user_prop = get_game_user_prop($uid,$GLOBALS['conn'],$GLOBALS['myredis']); //如果宝石不足,则 if(!$tmp_user_prop || $tmp_user_prop['have_gold']<$val['num']){ return false; } }else{//如果是其它物品 if(!isset($tmp_store_good[$val['id']]) || $tmp_store_good[$val['id']]['num']<$val['num']){ return false; } } }else{ return false; } } } //如果都能满足,表示需要的物品足够 return true; } //扣掉用户的物品 //(使用这个函数之前必须先调用check_user_good判断用户是否有足够的物品先) /* * $uid=>用户uid, * $ip=>用户的IP, * $arr=>array(//要求扣掉的物品列表 array( 'id'=>"g001",//'生产材料的ID', 'num'=>"250",//'生产材料的数量', ) * ), * */ function del_user_good($uid,$ip,$arr,$conn=false,$myredis=false){ if(empty($uid) || empty($arr) ){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } //检查物品是否足够,如果物品不足,则返回失败 if(!check_user_good($uid,$arr,$conn,$myredis)){ return false; } //移除玩家的物品 foreach($arr as $val){ //如果有要求的物品,则判断 if(!empty($val['id']) && $val['num']>0 ){ $tmp_good = $GLOBALS["SYS_GOOD_INFO"][$val['id']]; if($tmp_good['type']==1){//如果是宝石 $sobj['ip'] = $ip; $tmp_del = update_user_have_gold($uid,$val['num'],2,"扣除宝石",$ip,$conn,$myredis); if(!$tmp_del){ sys_log_write_content( "del_user_good改变玩家的宝石出错,UID:".$uid."=>".json_encode($arr) ,"error_log","error_log"); return false; } }else{//如果是其它物品 $tmp_arr = array( 'good_id'=>$val['id'],//"物品ID", 'num'=>$val['num'],//"物品数量", 'ip'=>$ip,//"移出时的IP地址" ); $tmp_del = store_good_data_del($uid,$tmp_arr,$conn,$myredis); if(!$tmp_del){ sys_log_write_content( "del_user_good改变玩家的宝石出错,UID:".$uid."=>".json_encode($arr) ,"error_log","error_log"); return false; } } } } //如果都能满足,表示需要的物品足够 return true; } //用户增加宝石 /* * 输入参数 * $uid=>改变经验的用户uid, * $gold=>改变的宝石数, * $type=>改变类型(1增加宝石,2减少宝石) * $info=>说明 * $ip=>操作时的IP * $is_send=>是否需要通知长连接属性改变 */ function update_user_have_gold($uid,$gold,$type,$info,$ip,$mysql_conn,$redis_conn){ if($gold<1){//如果宝石的改变数据为0,则直接返回 return true; } if($type==1){//如果是增加宝石 $arr = array( 'have_gold' => 'have_gold+'.$gold ); }else{//如果是减少 $arr = array( 'have_gold' => 'have_gold-'.$gold, 'used_gold' => 'used_gold+'.$gold ); } //改变用户的宝石 $tmp_up = update_game_user_prop($uid,$arr,$mysql_conn,$redis_conn); if($tmp_up){ //日志 $add_arr = array( 'data_id' => 0, 'uid' => $uid, 'card_num' => $gold, 'state' => 3, 'create_time'=> date("Y-m-d H:i:s", time()), 'create_ip' => $ip, 'mod_time' => '0000-00-00 00:00:00', 'mod_ip' => '', 'info' => $info, 'pay_type' => $type ); add_gold_log($add_arr,$mysql_conn,$redis_conn); return true; }else{ sys_log_write_content( "改变玩家的宝石出错,UID:".$uid ,"error_log","error_log"); } return false; } //用户增加经验 /* * 输入参数 * $sobj=>服务器连接对像(即 $this->arr), * $uid=>改变经验的用户uid, * $exp=>改变的经验数, * $info=>经验说明 * $ip=>操作时的IP */ function update_user_exp($uid,$exp,$info,$ip,$mysql_conn,$redis_conn){ //用户经验增加 if($exp>0){ //判断用户是否可以升级 //获取用户的属性 $tmp_prop = get_game_user_prop($uid,$mysql_conn,$redis_conn); if(!$tmp_prop){ return false; }else{ //获取用户的所有等级 $tmp_grade_data = $GLOBALS["SYS_FLOWER_MEMBER_2"]; //统计用户等级总数 $tmp_grade_tol = count($tmp_grade_data); //获取用户当前等级的数据 $tmp_grade = $tmp_grade_data[$tmp_prop['grade']]; //如果经验到了可以升级的,则进行升级 if( $tmp_prop['grade']<$tmp_grade_tol && ($tmp_prop['exp'] + $exp) >=$tmp_grade['next_exp']){//可以升级 //获取用户新等级的数据 $tmp_grade2 = $GLOBALS["SYS_FLOWER_MEMBER_2"][$tmp_prop['grade']+1]; $arr = array( 'exp' => $tmp_prop['exp'] + $exp - $tmp_grade['next_exp'], 'grade' => $tmp_prop['grade']+1, ); //添加宝石增加日志 if($tmp_grade2['num']>0){//如果升级有增加宝石,则记录日志 update_user_have_gold($uid,$tmp_grade2['num'],1,"用户升级增加宝石,原等级为:".$tmp_prop['grade'],$ip,$mysql_conn,$redis_conn); } //玩家增加可开花田数 if($tmp_grade2['field']>0){//这里版本没有要求 } //玩家增加仓库大小 if($tmp_grade2['store']>0){//这里版本没有要求 } //仓库增加每格可放物品的数量 if($tmp_grade2['store_num']>0){//这里版本没有要求 } //记录升级日志 $tmp_grade_log = array( 'uid'=>$uid,//'用户ID' 'before_grade'=>$tmp_prop['grade'],//'升级前的等级' 'after_grade'=>$tmp_prop['grade']+1,//'升级后的等级' 'exp'=>$tmp_grade['next_exp'],//'升级时所用的经验' 'gold'=>0,//'升级时所用的宝石' 'add_time'=>date("Y-m-d H:i:s", time()),//'升级时间' 'info'=>'经验达标升级'//'备注' ); add_member_grade_log($tmp_grade_log,$mysql_conn,$redis_conn); //发送用户升级通知给客户端 //=====begin 进行用户通知 $tmp_send_data = array( 'uid'=>$uid,//http请求的用户UID, 'do_a'=>"do_act",//http要执行的动作(在ajax_user_msg.class.php里制定的动作), 'a'=>"send_user_grade_up",//需要执行的websocket端动作 'm'=>"gzhq_game",//需要执行的websocket端模块, 'd'=>array( 'grade'=>$tmp_prop['grade'],//"原等级", 'grade2'=>$tmp_prop['grade']+1,//"新等级", 'num'=>$tmp_grade2['num'],//'玩家增加宝石数量', 'field'=>$tmp_grade2['field'],//'玩家增加可开花田数', 'store'=>$tmp_grade2['store'],//'玩家增加仓库大小', 'store_num'=>$tmp_grade2['store_num'],//'仓库增加每格可放物品的数量' 'up_data'=>$tmp_grade2['up_data'], 'msg' => '用户升级成功' ),//websocket端执行时自动提交的数据参数(数组) 't'=>time(),//生成消息的时间, ); $tmp_send_data = set_login_token($tmp_send_data); do_act_post_websocket($uid,$tmp_send_data,$redis_conn); //=====end 进行用户通知 }else{ $arr = array( 'exp' => "exp+".$exp ); } //改变用户的属性 update_game_user_prop($uid,$arr,$mysql_conn,$redis_conn); //添加用户经验日志 $add_arr = array( 'uid' => $uid, 'num' => $exp, 'type' => 1, 'add_time' => date("Y-m-d H:i:s", time()), 'info' => $info ); add_member_exp_log($add_arr,$mysql_conn,$redis_conn); } return true; }else{ return false; } } //更新用户仓库 /* $uid=>用户uid, $store_id=>仓库ID, $arr=array( 'uid'=>'用户ID', 'grade'=>'仓库等级', 'num'=>'仓库总大小', 'num2'=>'仓库已使用数量', 'num3'=>'每格的大小', 'name'=>'仓库名称', 'add_time'=>'获得时间', 'up_time'=>'修改时间', ) */ function update_game_member_store($uid,$store_id,$arr,$conn=false,$myredis=false){ if(empty($uid)){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } $prop = array(//属性 'uid'=>'用户ID', 'grade'=>'仓库等级', 'num'=>'仓库总大小', 'num2'=>'仓库已使用数量', 'num3'=>'每格的大小', 'name'=>'仓库名称', 'add_time'=>'获得时间', 'up_time' => date("Y-m-d H:i:s",time()) //更新时间 ); $arr_up = array(); foreach($arr as $key=>$val){ if(isset($prop[$key])){ $arr_up[$key] = $val; }else{ return false; } } if(empty($arr_up)){ return false; } $info = update_record($conn,'game_member_store',$arr_up,''," and uid='".$uid."' and sysid=".$store_id); if($info){ unset($arr_up,$info); return true; }else{ sys_log_write_content( 'game_member_store:'.json_encode($arr_up) ,"error_log","game_member_store_sql"); unset($arr_up,$info); return false; } } //获取用户数据统计 /** $uid=>用户uid */ function get_user_count_info($uid,$conn=false,$myredis=false){ if(empty($uid)){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } $where = " and uid='".$uid."'"; $arr = array('flower_num','order_num','goods_num','up_time'); $info = get_info($conn,"game_num",$arr,$where); return $info; } //获取用户所有任务数据 /** $uid=>用户uid, */ function get_lottery_data($uid,$daytime="",$conn=false,$myredis=false){ if(empty($uid) || empty($daytime)){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } $where = " uid=".$uid." and left(add_time,10) ='".$daytime."' "; $sql = "select `lottery_id`,`task_uid`, `is_ok`, `type`, `num` from game_global_lottery_log where ".$where; $query = $conn->Query($sql); while($value = $conn->FetchArray($query)) { $value['task_uid_pic'] = ""; if($value['task_uid']>0){ $user_info = get_game_user_info($uid,$conn,$myredis); $value['task_uid_pic'] = $user_info['pic']; } $info[] = $value; } return $info; } //检查用户任务是否完成 /* $uid=>用户uid, $num=>任务次数, */ function get_user_lottery($uid,$lottery_id,$daytime="",$conn=false,$myredis=false){ if(empty($uid) || empty($daytime)){ return false; } if(!$conn){ $conn = $GLOBALS["conn"]; } if(!$myredis){ $myredis = $GLOBALS["myredis"]; } $where = " and uid='".$uid."' and lottery_id='".$lottery_id."' and left(add_time,10) ='".$daytime."' "; $arr = array('task_uid','type','add_time','info','get_good','num','is_ok'); $info = get_info($conn,"game_global_lottery_log",$arr,$where); $info['task_uid_pic'] = ""; if($info['task_uid']>0){ $user_info = get_game_user_info($uid,$conn,$myredis); $info['task_uid_pic'] = $user_info['pic']; } return $info; } //更新用户的订单数据 /* $arr=>array(//用户的花田 'task_uid' => 0,//分配任务用户id 'type' => 0, //任务类型 'add_time' => '', //接任务时间 'add_ip' => '', //接任务时IP 'info' => '', //说明 'get_good' => '', //实际获取物品 'num' => 0, //接任务的次数 'is_ok' => 1, //是否已完成任务 'up_time' => '' //完成时间 'up_ip' => '' //完成时IP ) */ function update_game_user_lottery($uid,$lottery_id,$daytime="",$arr,$conn=false,$myredis=false){ if(empty($uid) || empty($daytime)){ return false; } $prop = array(//用户的属性 'task_uid' => 0,//分配任务用户id 'type' => 0, //任务类型 'add_time' => '', //接任务时间 'add_ip' => '', //接任务时IP 'info' => '', //说明 'get_good' => '', //实际获取物品 'num' => 0, //接任务的次数 'is_ok' => 1, //是否已完成任务 'up_time' => '', //完成时间 'up_ip' => '' //完成时IP ); $arr_up = array(); foreach($arr as $key=>$val){ if(isset($prop[$key])){ $arr_up[$key] = $val; }else{ return false; } } if(empty($arr_up)){ return false; } $info = update_record($conn,'game_global_lottery_log',$arr_up,''," and uid='".$uid."' and lottery_id='".$lottery_id."' and left(add_time,10) ='".$daytime."' "); if($info){ unset($arr_up,$info); return true; }else{ sys_log_write_content( 'game_global_lottery_log:'.json_encode($arr_up) ,"error_log","game_global_lottery_log"); unset($arr_up,$info); return false; } } //保存数据到redis /* $myredis=>redis连接, $key=>redis要存的key, $arr=>要存的数据, $time=>要存的时间(秒) */ function set_redis_info($myredis,$key,$arr,$time=0){ $myredis->set($key,json_encode($arr)); if($time>0){ $myredis->expire($key,$time); } return true; } //获取redis里的数据 /* $myredis=>redis连接, $key=>redis要存的key, $time=>要存的时间(秒) */ function get_redis_info($myredis,$key,$time=0){ $info = $myredis->get($key); if($info){ $info = json_decode($info,true); if($time>0){ $myredis->expire($key,$time); } return $info; }else{ return false; } } //删除redis里的数据 function del_redis_info($myredis,$key){ return $myredis->del($key); } //进行游戏配置数据的初始化操作 /* $myredis=>redis连接 $is_now=false(是否强制刷新,默认 false 不强制刷新) */ function hotUpdata($myredis,$is_now=false){ //判断 redis里有了配置没有。 foreach($GLOBALS['DATA_CONFIF_ARR'] as $val){ if(!empty($val)){ if($is_now==true){//如果是强制刷新 require_once(WEBPATH_DIR."data/".$val.".php"); $myredis->set($val,json_encode($GLOBALS[strtoupper($val)])); sys_log_write_content( '重新加载配置文件:'.WEBPATH_DIR."data/".$val.".php" ,"error_log","data_config_ok.log"); }else{//如果不是强制 刷新 $GLOBALS[strtoupper($val)] = $myredis->get($val); //如果redis没有值,则包含文件,并把值重新存入redis中去 if(empty($GLOBALS[strtoupper($val)])){ require_once(WEBPATH_DIR."data/".$val.".php"); $myredis->set($val,json_encode($GLOBALS[strtoupper($val)])); sys_log_write_content( '重新加载配置文件:'.WEBPATH_DIR."data/".$val.".php" ,"error_log","data_config_ok2.log"); }else{ $GLOBALS[strtoupper($val)] = json_decode($GLOBALS[strtoupper($val)],true); } } } } }