12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- class queue_logic
- {
- public function login($req_url,$key)
- {
- $resp = $this->reqest($req_url,'/login',['key' => $key]);
- if(!empty($resp) && $resp['code'] == 0) {
- return $resp['data']['token'];
- } else {
- Log::record("Login Error,{$resp['msg']}",Log::ERR);
- return false;
- }
- }
- private function reqest($url,$api,$params,$token='')
- {
- if(empty($token)) {
- $url = "{$url}{$api}";
- }
- else {
- $url = "{$url}{$api}?token={$token}";
- }
- $resp = http_post_data($url,json_encode($params));
- $resp = json_decode($resp,true);
- return $resp;
- }
- public function OpenBox($params) {
- $postData['cabinet_code'] = $params['cabinet_code'];
- $postData['box_position_list'] = $params['box_position_list'];
- $postData['delay_time'] = 0;
- $token = $this->login($params['req_url'],$params['key']);
- $resp = $this->reqest($params['req_url'] ,'/open_box', $postData,$token);
- $this->sync_return($params['ret_queue'],$resp);
- }
- public function LockCabinet($params) {
- $box_list[] = $params['box_number'];
- $postData['cabinet_code'] = $params['cabinet_number'];
- $postData['box_position_list'] = $box_list;
- $postData['delay_time'] = 0;
- $token = $this->login($params['req_url'],$params['key']);
- $resp = $this->reqest($params['req_url'] ,'/open_box', $postData,$token);
- $this->sync_return($params['ret_queue'],$resp);
- }
- public function LockBox($params) {
- $box_list[] = $params['box_number'];
- $postData['cabinet_code'] = $params['cabinet_number'];
- $postData['box_position_list'] = $box_list;
- $postData['delay_time'] = 0;
- $return = http_post($params['req_url'] , $postData);
- $return['code'] = 'ok';
- if($return['code'] != 0){
- $return['value'] = 'error';
- }
- $this->sync_return($params['ret_queue'] ,$return);
- }
- public function UnLockBox($params) {
- $box_list[] = $params['box_number'];
- $postData['cabinet_code'] = $params['cabinet_number'];
- $postData['box_position_list'] = $box_list;
- $postData['delay_time'] = 0;
- $return = http_post($params['req_url'] , $postData);
- $return['code'] = 'ok';
- if($return['code'] != 0){
- $return['value'] = 'error';
- }
- $this->sync_return($params['ret_queue'] , $return);
- }
- private function sync_return($queue_name,$params){
- global $config;
- $host = ['net_queue']['host'];
- $port = $config['net_queue']['port'];
- $worker = new QueueDB($queue_name,$host,$port);
- $worker->push($params);
- }
- }
|