挂号排队

appkey = array ( 'app_key' => urlencode('D79F0A7696C357A3821258C9CB3A728C'), 'sign' => urlencode('AA34A2974E4275A20B8E9C08172FC66D'), ); } /** * 注 册 信 息 * param string $name 姓名 * param int $moblie 手机号码 * param int $sfz 证件 * return JSON message */ public function add($name,$moblie,$sfz) { $posts = array('id_number' => $sfz); $posts = http_build_query($posts); $appkey = http_build_query($this->appkey); $set = "$posts&$appkey"; $setUrl="http://hn216.api.yesapi.cn/?s=App.Common_IDCard.Parse&return_data=0&$set"; if(!$http_getData = file_get_contents($setUrl)) { exit(json_encode(array('code'=>-1,'msg'=>'HTTPS ERROR...'))); } $str=preg_match('/[^\x00-\xff]/u',$name); if ($str==0 && !$name) { exit(json_encode(array('code'=>-1,'msg'=>'ERROR NAME!!!'))); } if (!preg_match('/1[0-9]{10}/',$moblie)) { exit(json_encode(array('code'=>-1,'msg'=>'ERROR MOBLIE!!!'))); } $con = count($this->arr); $array = array ( 'id' => $con+1, 'name' => $name, 'moblie' => $moblie, 'sfz' => $sfz, 'addtime' => time() ); if(!array_push($this->arr,$array)) { exit(json_encode(array('code'=>-1,'msg'=>'请重新填写'),JSON_UNESCAPED_UNICODE)); } //打印 $arr = array ( '排号凭证', '您的号码是'=>$con+1, '姓 名' => $name, '手机号码'=>$moblie, '证件号码'=>$sfz, '排号时间'=>date('Y-m-d h:i:s'), ); return json_encode(array('code'=>1,'info'=>'已成功排上号','data'=>$arr,JSON_UNESCAPED_UNICODE)); } //设置柜台数 public function qt($int,$addit=1) { if (!is_int($int)) { return '请输入正整数'; } if ($addit <= $int) { $array = array ( //状态1 正常0休息2忙碌 'pid' => $addit, 'status' => 0, ); $this->qt[]=$array; $addit++; $this->qt($int,$addit); } return json_encode(array('code'=>1,'msg'=>'新增成功'),JSON_UNESCAPED_UNICODE); } /** * 叫号减一 * param int $del 几号柜台delete * param int $qs 几号柜台休息 * param string 1开始0关闭 DEBUG * return string message */ public function del($del='',$qs,$debug='DEBUG') { if (!is_int($qs) && !$qs && $qs> count($this->qt)) { exit(json_encode(array('code'=>-1,'msg'=>'非法参数','errcode'=>402))); } if ($del=='' ||!is_int($del) &&$del > count($this->qt)) { echo(json_encode(array('code'=>-1,'msg'=>'非法参数','errcode'=>401))); } if ($qs===$del)return array('code'=>-1,'msg'=>'错误'); $min = min($this->arr); if(!$info = "请".$min['id']."号到".$this->qt[$del]['pid']."号窗口办理") { echo json_encode(array('code'=>-1,'msg'=>'{ERROR}'),JSON_UNESCAPED_UNICODE); } $min = $min['id']-1; sleep(3); if (!$this->arr[$min]['deltime']=time()) { if($debug==1)echo json_encode(array('code'=>-1,'msg'=>'time不能为零'),JSON_UNESCAPED_UNICODE); } //回收数据 if (array_push($this->hssd,$this->arr[$min])) { if($debug==1)echo json_encode(array('code'=>1,'msg'=>'已更新'),JSON_UNESCAPED_UNICODE); }else{ if($debug==1)echo json_encode(array('code'=>-1,'msg'=>'更新失败'),JSON_UNESCAPED_UNICODE); } for ($i = 0; $i < count($this->qt); $i++) { if ($del == $i) { $this->qt[$i]['info'] = $info; $this->qt[$i]['status'] = 2; if($debug==1)echo json_encode(array('code'=>1,'msg'=>'成功','edit_time'=>time()),JSON_UNESCAPED_UNICODE); }else{ $this->qt[$i]['status'] = 1; if($debug==1)echo json_encode(array('code'=>-1,'msg'=>'正常','edit_time'=>time()),JSON_UNESCAPED_UNICODE); } } if (!$del && $this->qt[$qs]['status']!=2) { $this->qt[$qs]['status'] = 0; $this->qt[$qs]['info'] = array('code' => 2,'info' => '暂停服务'); if($debug==1)echo json_encode(array('code'=>1,'msg'=>'已提报,状态待审核'),JSON_UNESCAPED_UNICODE); } if(rsort($this->arr)) { if(array_pop($this->arr)) { echo json_encode(array('code'=>-1,'msg'=>'没有排序删除失败'),JSON_UNESCAPED_UNICODE); } }else{ unset($this->arr[$min]); } return json_encode(array("code"=>1,"info"=>"delete ok","delete_time"=>date('Y/m/d h:i:s',time()))); } public function run() { //1开启0关闭调试模式debug echo(array('msg'=>'是否开启调试')); //$del=$this->del('','',1); //********************************* $add = $this->add('城里人',13811112222,431111111111111111); $bdd = $this->add('老郭',18666786543,432222222222222222); $qt = $this->qt(4); $del = $this->del(1,3,'');//1柜台号发起事件2柜台号 从0开始 echo ($add)?$add:$bdd."\n"; echo "$qt\n"; echo str_repeat('_',12)."自动生成柜台数".str_repeat('_',12)."\n"; echo str_repeat('_',6)."3种工作状态(休息,忙碌,正常)".str_repeat('_',6)."\n"; print_r($this->qt); echo str_repeat('_',12)."在队列中的数据".str_repeat('_',12)."\n"; print_r($this->arr)."\n"; echo str_repeat('_',12)."被回收的数据".str_repeat('_',12)."\n"; print_r($this->hssd); echo "$del\n"; echo str_repeat('_',40); } } $data = new Data(); $data->run();
posted @ 2021-04-17 05:13  Yu环上的黑影  阅读(23)  评论(0编辑  收藏  举报