queue.logic.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. class queue_logic
  3. {
  4. public function login($req_url,$key)
  5. {
  6. $resp = $this->reqest($req_url,'/login',['key' => $key]);
  7. if(!empty($resp) && $resp['code'] == 0) {
  8. return $resp['data']['token'];
  9. } else {
  10. Log::record("Login Error,{$resp['msg']}",Log::ERR);
  11. return false;
  12. }
  13. }
  14. private function reqest($url,$api,$params,$token='')
  15. {
  16. if(empty($token)) {
  17. $url = "{$url}{$api}";
  18. }
  19. else {
  20. $url = "{$url}{$api}?token={$token}";
  21. }
  22. $resp = http_post_data($url,json_encode($params));
  23. $resp = json_decode($resp,true);
  24. return $resp;
  25. }
  26. public function OpenBox($params) {
  27. $postData['cabinet_code'] = $params['cabinet_code'];
  28. $postData['box_position_list'] = $params['box_position_list'];
  29. $postData['delay_time'] = 0;
  30. $token = $this->login($params['req_url'],$params['key']);
  31. $resp = $this->reqest($params['req_url'] ,'/open_box', $postData,$token);
  32. $this->sync_return($params['ret_queue'],$resp);
  33. }
  34. public function LockCabinet($params) {
  35. $box_list[] = $params['box_number'];
  36. $postData['cabinet_code'] = $params['cabinet_number'];
  37. $postData['box_position_list'] = $box_list;
  38. $postData['delay_time'] = 0;
  39. $token = $this->login($params['req_url'],$params['key']);
  40. $resp = $this->reqest($params['req_url'] ,'/open_box', $postData,$token);
  41. $this->sync_return($params['ret_queue'],$resp);
  42. }
  43. public function LockBox($params) {
  44. $box_list[] = $params['box_number'];
  45. $postData['cabinet_code'] = $params['cabinet_number'];
  46. $postData['box_position_list'] = $box_list;
  47. $postData['delay_time'] = 0;
  48. $return = http_post($params['req_url'] , $postData);
  49. $return['code'] = 'ok';
  50. if($return['code'] != 0){
  51. $return['value'] = 'error';
  52. }
  53. $this->sync_return($params['ret_queue'] ,$return);
  54. }
  55. public function UnLockBox($params) {
  56. $box_list[] = $params['box_number'];
  57. $postData['cabinet_code'] = $params['cabinet_number'];
  58. $postData['box_position_list'] = $box_list;
  59. $postData['delay_time'] = 0;
  60. $return = http_post($params['req_url'] , $postData);
  61. $return['code'] = 'ok';
  62. if($return['code'] != 0){
  63. $return['value'] = 'error';
  64. }
  65. $this->sync_return($params['ret_queue'] , $return);
  66. }
  67. private function sync_return($queue_name,$params){
  68. global $config;
  69. $host = ['net_queue']['host'];
  70. $port = $config['net_queue']['port'];
  71. $worker = new QueueDB($queue_name,$host,$port);
  72. $worker->push($params);
  73. }
  74. }