Browse Source

for something

stanley-king 4 years ago
parent
commit
dc6102ffe3

+ 3 - 3
application/common.php

@@ -112,7 +112,7 @@ function _curl(array $params,$is_json=false )
     return $result;
 }
 
-function http_request($method,$url,$data)
+function httpRequest($method,$url,$data)
 {
     $method = strtolower($method);
     $params['method'] = $method;
@@ -124,12 +124,12 @@ function http_request($method,$url,$data)
 
 function http_get($url,$data)
 {
-    return json_decode(http_request('GET',$url,$data),true);
+    return json_decode(httpRequest('GET',$url,$data),true);
 }
 
 function http_post($url,$data)
 {
-    return json_decode(http_request('POST',$url,$data),true);
+    return json_decode(httpRequest('POST',$url,$data),true);
 }
 
 /**

+ 11 - 0
application/index/controller/Index.php

@@ -28,6 +28,17 @@ class Index
         json_success($result['data']);
     }
 
+    public function _CheckOrder($order_sn){
+        $result = http_get(self::admin_url . '/CheckOrder' ,['order_sn' => $order_sn]);
+        if($result == false){
+            json_return(500,[],'网络错误');
+        }
+        if($result['code'] != 0){
+            json_return($result['code'],[],$result['msg']);
+        }
+        json_success($result['data']);
+    }
+
     public function CheckFcode(){
         $code = input('param.code');
         $result = http_get(self::admin_url . ':8080/CheckFcode' ,['code' => $code]);

+ 1 - 1
conf/php/php-debug.ini

@@ -1325,7 +1325,7 @@ bcmath.scale = 0
 ; http://php.net/session.save-handler
 ;session.save_handler = file
 session.save_handler = redis
-session.save_path = tcp://redisrv:6379
+session.save_path = tcp://accredis:6379
 
 ; Argument passed to save_handler.  In the case of files, this is the path
 ; where data files are stored. Note: Windows users have to change this

+ 1 - 1
conf/php/php.ini

@@ -1325,7 +1325,7 @@ bcmath.scale = 0
 ; http://php.net/session.save-handler
 ;session.save_handler = file
 session.save_handler = redis
-session.save_path = tcp://redisrv:6379
+session.save_path = tcp://accredis:6379
 
 ; Argument passed to save_handler.  In the case of files, this is the path
 ; where data files are stored. Note: Windows users have to change this

+ 0 - 3
crontab/config.ini.php

@@ -1,3 +0,0 @@
-<?php
-
-require_once(BASE_PATH . '/config.mac.php');

+ 0 - 1
crontab/config.test.php

@@ -1 +0,0 @@
-<?php

+ 3 - 32
crontab/index.php

@@ -5,7 +5,7 @@ define('BASE_PATH',BASE_ROOT_PATH . '/crontab');
 define('BASE_DATA_PATH',BASE_ROOT_PATH . '/data');
 define('APP_ID','crontab');
 
-require_once(BASE_PATH . '/config.ini.php');
+require_once(BASE_ROOT_PATH . '/other/config.ini.php');
 
 require_once(BASE_ROOT_PATH . '/extend/queue.php');
 require_once(BASE_ROOT_PATH . '/extend/queue.logic.php');
@@ -14,36 +14,7 @@ require_once(BASE_ROOT_PATH . '/extend/http.php');
 
 Log::record("Crontab startHandling something....",Log::DEBUG);
 
-class crontab
-{
-    public function onFifteenMinute()
-    {
-        $cabinets = $this->getAllCabinet();
-        foreach ($cabinets as $cabinet) {
-
-
-        }
-    }
-
-    private function getAllCabinet()
-    {
-
-    }
-
-    private function getBox($cabinet) {
-
-    }
-
-    private function reportState()
-    {
-
-    }
-}
-
-$worker = new crontab();
-$worker->onFifteenMinute();
-
-
-
+$logic_queue = new queue_logic();
+$logic_queue->UpdateAllBoxState();
 
 

+ 5 - 2
extend/http.php

@@ -16,8 +16,8 @@ function http_request($url, $params = array(), $method = 'GET', $multi = false,
     $method = strtoupper($method);
     $ci = curl_init();
     curl_setopt($ci, CURLOPT_USERAGENT, 'PHP-SDK OAuth2.0');
-    curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 3);
-    curl_setopt($ci, CURLOPT_TIMEOUT, 3);
+    curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);
+    curl_setopt($ci, CURLOPT_TIMEOUT, 30);
     curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, false);
@@ -59,6 +59,9 @@ function http_request($url, $params = array(), $method = 'GET', $multi = false,
     }
 
     $response = curl_exec($ci);
+    if($response === false) {
+        $err = curl_error($ci);
+    }
     curl_close($ci);
 
     return $response;

+ 81 - 2
extend/queue.logic.php

@@ -30,6 +30,7 @@ class queue_logic
         $postData['cabinet_code']       = $params['cabinet_code'];
         $postData['box_position_list']  = $params['box_position_list'];
         $postData['delay_time']         = $params['delay_time'];
+        $postData['id']                 = $params['id'];
 
         return $this->proc_request($params,'/open_box',$postData);
     }
@@ -37,33 +38,47 @@ class queue_logic
     public function LockCabinet($params) {
         $postData['cabinet_code']  = $params['cabinet_code'];
         $postData['delay_time'] = $params['delay_time'];
+        $postData['id']                 = $params['id'];
 
         return $this->proc_request($params,'/lock_cabinet',$postData);
     }
     public function UnLockCabinet($params) {
         $postData['cabinet_code']  = $params['cabinet_code'];
-        $postData['delay_time'] = $params['delay_time'];
+        $postData['delay_time']    = $params['delay_time'];
+        $postData['id']            = $params['id'];
 
         return $this->proc_request($params,'/unlock_cabinet',$postData);
     }
     public function ReleaseAlarm($params) {
         $postData['cabinet_code']  = $params['cabinet_code'];
         $postData['delay_time'] = $params['delay_time'];
+        $postData['id']         = $params['id'];
+
 
         return $this->proc_request($params,'/release_alarm',$postData);
     }
     public function Reboot($params) {
         $postData['cabinet_code']  = $params['cabinet_code'];
         $postData['delay_time'] = $params['delay_time'];
+        $postData['id']         = $params['id'];
 
         return $this->proc_request($params,'/reboot',$postData);
     }
     public function QueryState($params) {
         $postData['cabinet_code']  = $params['cabinet_code'];
         $postData['delay_time'] = $params['delay_time'];
+        $postData['id']         = $params['id'];
 
         return $this->proc_request($params,'/query_state',$postData);
     }
+    public function QueryBoxState($params) {
+        $postData['cabinet_code']       = $params['cabinet_code'];
+        $postData['box_position_list']  = $params['box_position_list'];
+        $postData['delay_time']         = $params['delay_time'];
+        $postData['id']                 = $params['id'];
+
+        return $this->proc_request($params,'/query_box_state',$postData);
+    }
 
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     private function proc_request($params,$api,$postData)
@@ -84,7 +99,7 @@ class queue_logic
         return $resp;
     }
 
-    private function sync_result($queue_name, $key, $params){
+    private function sync_result($queue_name, $key, $params) {
         global $config;
         $host = $config['net_queue']['host'];
         $port = $config['net_queue']['port'];
@@ -96,4 +111,68 @@ class queue_logic
             return ['code'=>1 , 'msg' => 'cabinet redis connect error'];
         }
     }
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    public function UpdateAllBoxState()
+    {
+        global $config;
+        $admin_url = $config['admin_url'];
+
+        $result = $this->getCabinets("{$admin_url}/GetCabinetsBoxs");
+        if(empty($result) || $result['code'] != 0) {
+            return false;
+        }
+        $cabinets = $result['data'];
+        foreach ($cabinets as $cabinet)
+        {
+            $params['req_url'] = $cabinet['req_url'];
+            $params['key'] = $cabinet['login_key'];
+            $token = $this->login($params['req_url'],$params['key']);
+            if(empty($token)) {
+                return false;
+            }
+
+            $boxes = $cabinet['box_data'];
+            $i = 1;
+            foreach ($boxes as $box)
+            {
+                $data['id'] = "{$i}";
+                $data['cabinet_code'] = $cabinet['cabinet_code'];
+                $data['box_position_list'] = [$box['box_number']];
+                $data['delay_time'] = 0;
+
+                $resp = $this->reqest($params['req_url'],'/query_box_state',$data,$token);
+                if($resp['code'] == 0)
+                {
+                    $update_url = $admin_url . "/BoxChangeStatus";
+                    foreach ($resp['data']['result_list'] as $value) {
+                        $data = [];
+                        $data['cabinet_code'] = $cabinet['cabinet_code'];
+                        $data['box_number'] = $value['box_position'];
+                        $data['box_status'] = $value['result'];
+
+                        $ret = http_request($update_url,$resp,'POST');
+                        if($ret == false || $ret['code'] != 0) {
+                            Log::record("update box state error: cabinet={$cabinet['cabinet_code']},box={$box['box_number']}",log::DEBUG);
+                        }
+                    }
+                }
+                else {
+                    Log::record("query state err: cabinet={$cabinet['cabinet_code']},box={$box['box_number']}",log::DEBUG);
+                }
+
+                $i++;
+            }
+        }
+    }
+
+    public function getCabinets($url) {
+        $resp = http_request($url,[]);
+        if($resp) {
+            $result = json_decode($resp,true);
+            return $result;
+        }
+        else {
+            return false;
+        }
+    }
 }

+ 3 - 0
other/config.ini.php

@@ -0,0 +1,3 @@
+<?php
+
+require_once(BASE_ROOT_PATH . '/other/config.mac.php');

+ 8 - 0
other/config.mac.php

@@ -0,0 +1,8 @@
+<?php
+
+$config['net_queue']['name'] = 'net_access_queue';
+$config['net_queue']['host'] = 'host.docker.internal';
+$config['net_queue']['port'] = 6380;
+
+$config['admin_url'] = 'http://39.97.239.116:8080';
+

crontab/config.prod.php → other/config.prod.php


+ 0 - 1
queue/config.test.php

@@ -2,5 +2,4 @@
 
 $config['net_queue']['name'] = 'net_access_queue';
 $config['net_queue']['host'] = 'docker.hostip';
-//$config['net_queue']['host'] = '192.168.1.195';
 $config['net_queue']['port'] = 6380;

+ 1 - 2
crontab/config.mac.php

@@ -2,5 +2,4 @@
 
 $config['net_queue']['name'] = 'net_access_queue';
 $config['net_queue']['host'] = 'host.docker.internal';
-$config['net_queue']['port'] = 6380;
-
+$config['net_queue']['port'] = 6380;

+ 0 - 7
queue/config.mac.php

@@ -1,7 +0,0 @@
-<?php
-
-$config['net_queue']['name'] = 'net_access_queue';
-//$config['net_queue']['host'] = 'host.docker.internal';
-$config['net_queue']['host'] = '192.168.1.195';
-$config['net_queue']['port'] = 6380;
-

+ 0 - 1
queue/config.prod.php

@@ -1 +0,0 @@
-<?php

+ 0 - 6
queue/config.windows.php

@@ -1,6 +0,0 @@
-<?php
-
-$config['net_queue']['name'] = 'net_access_queue';
-//$config['net_queue']['host'] = 'host.docker.internal';
-$config['net_queue']['host'] = '192.168.1.200';
-$config['net_queue']['port'] = 6380;

+ 1 - 1
queue/index.php

@@ -6,7 +6,7 @@ define('BASE_PATH',BASE_ROOT_PATH . '/queue');
 define('BASE_DATA_PATH',BASE_ROOT_PATH . '/data');
 define('APP_ID','queue');
 
-require_once(BASE_PATH . '/config.ini.php');
+require_once(BASE_ROOT_PATH . '/other/config.ini.php');
 require_once(BASE_ROOT_PATH . '/extend/queue.php');
 require_once(BASE_ROOT_PATH . '/extend/queue.logic.php');
 require_once(BASE_ROOT_PATH . '/extend/log.php');

+ 30 - 3
tests/TestIndex.php

@@ -8,10 +8,16 @@ namespace think;
 define('BASE_ROOT_PATH',str_replace('/tests','',dirname(__FILE__)));
 define('BASE_PATH',BASE_ROOT_PATH . '/tests');
 define('APP_ID','tests');
+define('BASE_DATA_PATH',BASE_ROOT_PATH . '/data');
 
-require BASE_ROOT_PATH . '/thinkphp/base.php';
+require_once(BASE_ROOT_PATH . '/other/config.ini.php');
+require_once(BASE_ROOT_PATH . '/thinkphp/base.php');
+require_once(BASE_ROOT_PATH . '/extend/http.php');
+require_once(BASE_ROOT_PATH . '/extend/queue.logic.php');
+require_once(BASE_ROOT_PATH . '/extend/log.php');
 
 use PHPUnit\Framework\TestCase;
+use queue_logic;
 
 class TestIndex extends TestCase
 {
@@ -20,11 +26,32 @@ class TestIndex extends TestCase
     {
         App::getInstance()->path(BASE_ROOT_PATH . '/application/')->initialize();
     }
-
+    public function testCheckOrder()
+    {
+        $resp = http_request('http://host.docker.internal:8080/CheckOrder',['order_sn' => '123456'],'GET');
+    }
     public function testInviteBonus()
     {
         $obj = new \app\index\controller\Index;
-        $obj->index();
+
+        $obj->_CheckOrder('123456789');
     }
 
+    public function testOpenBox()
+    {
+        $logic_queue = new queue_logic();
+        $logic_queue->OpenBox(['cabinet_code' => '0000000000000000','box_position_list' => [1],'delay_time' => 0,
+        'req_url' => 'http://221.217.229.194:8888','key' => '12345678','id' => '1234567' ,'ret_queue' => 'test_queue']);
+    }
+    public function testQueryBoxState()
+    {
+        $logic_queue = new queue_logic();
+        $logic_queue->QueryBoxState(['cabinet_code' => '0000000000000000','box_position_list' => [1],'delay_time' => 0,
+            'req_url' => 'http://221.217.229.194:8888','key' => '12345678','id' => '1234567','ret_queue' => 'test_queue']);
+    }
+    public function testUpdateAllBoxState()
+    {
+        $logic_queue = new queue_logic();
+        $logic_queue->UpdateAllBoxState();
+    }
 }