ソースを参照

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	app/Http/Controllers/Api/DwyController.php
gogs 10 ヶ月 前
コミット
40b3b39138

+ 173 - 0
app/Console/Commands/ReadCommand.php

@@ -0,0 +1,173 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Jobs\SendDataJob;
+use App\Model\BigKingCbj;
+use App\Service\DwyService;
+use App\Service\LabelDealService;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+
+class ReadCommand extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'command:tcp';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '读取文件';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    const inventory_port = 7880; //盘点设备端口
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->tcpServer();
+        $this->info('Your command executed!');
+    }
+
+    public function tcpServer(){
+        $host = "121.41.102.225";
+        $port = self::inventory_port;
+
+        // 创建一个TCP socket
+        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+        // 绑定到指定的主机和端口  第二个参数不写 默认局域网ipv4地址
+        socket_bind($socket, '', $port);
+        // 监听连接
+        socket_listen($socket);
+
+        // 初始内存使用量
+        $initialMemoryUsage = memory_get_usage();
+
+        echo date("Y-m-d H:i:s") . " 服务器" . $host . ":" . $port . "已启动监听\n";
+//        file_put_contents('C:\Users\Administrator\Desktop\record.txt',date("Y-m-d H:i:s") . "服务器已启动".PHP_EOL,8);
+
+        while (true) {
+            // 接受连接请求并创建新的套接字
+            $clientSocket = socket_accept($socket);
+
+            if ($clientSocket === false) {
+                // 错误处理
+                $error = socket_strerror(socket_last_error($socket));
+                echo "接受连接请求失败:{$error}\n";
+                continue; // 继续下一次循环
+            }
+
+            // 读取客户端发送的数据
+            $data = socket_read($clientSocket, 1024);
+//            file_put_contents('C:\Users\Administrator\Desktop\record2.txt',$data .PHP_EOL,8);
+
+            $this->byteParsingInventory($data);
+
+            // 发送响应给客户端
+//            $response = "服务器已接收到您的消息:" . $data;
+//            socket_write($clientSocket, $response, strlen($response));
+
+            $currentMemoryUsage = memory_get_usage();
+            $memoryDiff = $currentMemoryUsage - $initialMemoryUsage;
+
+            echo "内存使用量变化:" . $memoryDiff . " 字节\n";
+
+            $initialMemoryUsage = $currentMemoryUsage;
+
+            // 关闭当前连接的套接字
+            socket_close($clientSocket);
+
+            gc_collect_cycles();
+
+            sleep(5);
+        }
+
+        // 关闭服务器套接字
+        socket_close($socket);
+    }
+
+    //盘点设备 数据解析发送
+    // 5a55167fa90d010cbbdd8204000116010a000000000000476a69
+    // 5a55166dcd0d010cbbdd8204000116010a000000000000596a69
+    // 5a551679b50d010cbbdd8204000116010a0000000000004d6a69
+    //
+    public function byteParsingInventory($data){
+        Log::channel('request')->info('request', ['paramlog'=> $data]);
+
+        DB::table('test')->insert(['data' => $data]);
+        echo $data . PHP_EOL;
+        $hexData = bin2hex($data);
+        $hexData = str_replace(' ', '', $hexData);
+//        $toReplace = array("5a55167fa90d010cbbdd8204000116010a000000000000476a69", "5a55166dcd0d010cbbdd8204000116010a000000000000596a69","5a551679b50d010cbbdd8204000116010a0000000000004d6a69","5a551673c10d010cbbdd8204000116010a000000000000536a69","5a55167faa0d010cbbdd8204000116010a000000000000486a69","5a551679b60d010cbbdd8204000116010a0000000000004e6a69");
+        $toReplace = [];
+        $result = str_replace($toReplace, "", $hexData);
+
+    }
+
+    //获取本机ipv4地址
+    public function getMyIpV4(){
+        $ip = exec("ipconfig | findstr /i \"IPv4\"");
+        $parts = explode(": ", $ip);
+        $ipAddress = $parts[1];
+        return $ipAddress;
+    }
+
+    public function sendData($data){
+        $url = env('CLOUD_ADDRESS',null);
+
+        if(empty($url)) return;
+
+        $curl = curl_init();
+        curl_setopt_array($curl, array(
+            CURLOPT_URL => $url,
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_ENCODING => '',
+            CURLOPT_MAXREDIRS => 10,
+            CURLOPT_TIMEOUT => 0,
+            CURLOPT_FOLLOWLOCATION => true,
+            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
+            CURLOPT_CUSTOMREQUEST => 'POST',
+            CURLOPT_POSTFIELDS => $data,
+        ));
+        $response = curl_exec($curl);
+        curl_close($curl);
+    }
+
+    public function cbjSettle(){
+        $id = 0;
+        BigKingCbj::where('id',0);
+        $data = $this->data;
+        $dv = $data['key'];
+        $return = $box_list = [];
+        //处理数据
+        LabelDealService::getInstance()->clearData($data,$return,$box_list);
+
+        //调用外部方法
+        list($lead_bind,$lead_out) = DwyService::getInstance()->setBoxData($this->header,$dv,$return,$box_list,$data);
+
+        //调用保存接口
+        LabelDealService::getInstance()->boxOut($lead_bind,$lead_out,$this->header,$this->id);
+    }
+}

+ 1 - 1
app/Jobs/LabelDealJob.php

@@ -51,7 +51,7 @@ class LabelDealJob implements ShouldQueue
             //调用保存接口
             LabelDealService::getInstance()->boxOut($lead_bind,$lead_out,$this->header,$this->id);
         }catch (\Throwable $exception){
-            file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "队列捕获:" . $exception->getLine() . "|" . $exception->getMessage(). "|"  . $exception->getCode(). PHP_EOL,8);
+            file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "队列捕获:" . $exception->getFile() . "|" . $exception->getLine() . "|" . $exception->getMessage(). "|"  . $exception->getCode(). PHP_EOL,8);
             $this->delete();
         }
     }

ファイルの差分が大きいため隠しています
+ 0 - 0
app/Service/DwyService.php


+ 1 - 1
app/Service/LabelDealService.php

@@ -27,7 +27,7 @@ class LabelDealService extends Service
                         'detail' => [],
                     ];
                 }
-                $return[$value['send_box_code']]['fake_qty'] += $tmp['fake_qty'] ?? 0;
+                $return[$value['send_box_code']]['fake_qty'] += $tmp['fake_qty'];
                 $return[$value['send_box_code']]['detail'] = array_merge($return[$value['send_box_code']]['detail'], explode(',',$tmp['brand_qr_code_list']));
             }
         }

+ 0 - 2
routes/api.php

@@ -24,7 +24,6 @@ Route::any('openDoor', 'Api\DwyController@openDoor');
 Route::any('setLb', 'Api\DwyController@setLb');
 Route::any('boxList', 'Api\DwyController@boxList');
 Route::any('ttttt', 'Api\TestController@deviceCallback');
-Route::any('maintenance', 'Api\DwyController@maintenance');
 //Route::any('boxOut', 'Api\DwyController@boxOut');
 
 //贴标机
@@ -60,7 +59,6 @@ Route::any('tttt', 'Api\DwyController@tttt');
 Route::any('getBoxTrademark', 'Api\DwyController@getBoxTrademark');
 Route::any('aaaa', 'Api\DwyController@setBoxTrademark');
 Route::any('boxOut', 'Api\JobController@labelDeal');
-Route::any('getObsUrl', 'Api\DwyController@getObsUrl');
 
 Route::group(['middleware'=> []],function ($route){
     $route->any('menuAdd', 'Api\SysMenuController@add');

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません