cqp 1 месяц назад
Родитель
Сommit
2943952c3b
1 измененных файлов с 53 добавлено и 829 удалено
  1. 53 829
      app/Service/U8ServerService.php

+ 53 - 829
app/Service/U8ServerService.php

@@ -2,863 +2,87 @@
 
 namespace App\Service;
 
-use App\Model\BasicType;
-use App\Model\Customer;
-use App\Model\Depart;
-use App\Model\Employee;
-use App\Model\Product;
-use App\Model\PurchaseOrder;
-use App\Model\PurchaseOrderInfo;
-use App\Model\SalesOrder;
-use App\Model\SalesOrderProductInfo;
-use App\Model\SeeRange;
-use App\Model\Setting;
-use App\Model\Supplier;
-use App\Model\U8Job;
 use Illuminate\Support\Facades\Config;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Log;
-use Illuminate\Support\Facades\Redis;
 
 class U8ServerService extends Service
 {
     public $db = null;
     public $error = null; // 错误信息
-    public $u8 = []; //u8 配置连接参数
-    public $u8_api = ""; //u8接口请求地址
-    public $post_common = [];//u8接口公用参数
 
-    public function __construct($is_need_connect = false)
+    public function __construct()
     {
-        //u8 配置连接参数 u8_api设置
-        list($status,$msg) = $this->settingConnection();
-        if(! $status) {
-            $this->error = $msg;
-            return;
-        }
-
-        //是否需要连接u8数据库
-        if($is_need_connect){
-            //构建数据库连接对象
-            list($status,$msg) = $this->settingDb();
-            if(! $status) {
-                $this->error = $msg;
-            }
-        }
+        $this->createConnection();
     }
 
-    //设置u8连接参数
-    private function settingConnection(){
-        $u8 = Setting::where('setting_name','u8')->where('setting_value','<>','')->first();
-        if(empty($u8)) return [false, 'u8配置参数不存在!'];
-        $u8 = $u8->toArray();
-        // 使用 eval() 函数执行字符串并转换为数组
-        $u8 = eval("return {$u8['setting_value']};");
-
-        if(empty($u8['domain'])) return [false, '外部域名不能为空!'];
-        if(empty($u8['u8_api_port'])) return [false, 'u8程序API端口不能为空!'];
-        if(empty($u8['u8_database_port'])) return [false, 'u8程序数据库端口不能为空!'];
-        if(empty($u8['database'])) return [false, 'u8程序数据库不能为空!'];
-        if(empty($u8['database_account'])) return [false, 'u8程序数据库登录账号不能为空!'];
-        if(empty($u8['database_password'])) return [false, 'u8程序数据库登录密码不能为空!'];
-        if(empty($u8['sAccID'])) return [false, 'u8程序sAccID不能为空!'];
-        if(empty($u8['sServer'])) return [false, 'u8程序sServer不能为空!'];
-        if(empty($u8['sUserID'])) return [false, 'u8程序sUserID不能为空!'];
-        if(empty($u8['sPassword'])) return [false, 'u8程序sPassword不能为空!'];
-
-        $this->u8 = $u8;
-        $this->u8_api = "https://" . $u8['domain'] . ":" . $u8['u8_api_port'] . "/U8Sys/U8API";
-        $this->post_common = [
-            "password"=>"cloud@123456",
-            "entity"=>"", //调用方法
-            "login"=>[
-                "sAccID"=> $u8['sAccID'],
-                "sDate"=> date("Y-m-d"),
-                "sServer"=> $u8['sServer'],
-                "sUserID"=> $u8['sUserID'],
-                "sSerial"=> "",
-                "sPassword"=> $u8['sPassword']
-            ]
+    private function createConnection()
+    {
+        // 主数据库连接
+        $mainConnName = 'sqlsrv_main_' . uniqid();
+        $mainConfig = [
+            'driver' => 'sqlsrv',
+            'host' => env('SQLSRV_HOST'),
+            'port' => env('SQLSRV_PORT'),
+            'database' => env('SQLSRV_DATABASE'),
+            'username' => env('SQLSRV_USERNAME'),
+            'password' => env('SQLSRV_PASSWORD'),
+            'options' => [
+//                \PDO::ATTR_TIMEOUT => 30, // 查询超时30秒
+                \PDO::SQLSRV_ATTR_QUERY_TIMEOUT => 30, // SQL Server专用超时
+                \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
+//                \PDO::ATTR_PERSISTENT => false, // 重要:禁用持久连接
+            ],
         ];
 
-        return [true, ''];
-    }
-
-    //设置u8数据库连接
-    private function settingDb(){
-        if(empty($this->db)){
-            $u8 = $this->u8;
-
-            $config = [
-                'driver' => 'sqlsrv',
-                'host' =>  $u8['domain'],
-                'port' => $u8['u8_database_port'],
-                'database' => $u8['database'],
-                'username' => $u8['database_account'],
-                'password' => $u8['database_password'],
-            ];
-
-            // 数据库配置设置
-            Config::set('database.connections.sqlsrvs', $config);
-
-            // 连接
-            try {
-                $pdo = DB::connection('sqlsrvs')->getPdo();
-                if ($pdo instanceof \PDO) {
-                    // 连接成功的逻辑代码
-                    $this->db = DB::connection('sqlsrvs');
-                } else {
-                    return [false, '连接失败!'];
-                }
-            } catch (\Throwable $e) {
-                return [false, $e->getMessage()];
-            }
-
-        }
-
-        return [true, ''];
-    }
-
-    //采购订单保存
-    public function U8PO_PomainSave($data,$cmaker = ""){
-        if(! is_array($data)) $data = [$data];
-        $id = $data;
-
-        //映射ip是否通畅
-        $bool = $this->isDomainAvailable($this->u8['domain']);
-        if(! $bool) {
-            $msg = 'U8程序外部域名不可达';
-            $this->finalSettle($id, U8Job::one,$msg);
-            return;
-        }
-
-        //获取数据
-        $result = $this->getPurchaseData($id);
-        if(empty($result)) {
-            $msg = "同步数据获取失败";
-            $this->finalSettle($id, U8Job::one, $msg);
-            return;
-        }
-
-        //u8接口参数组织
-        $post = $this->post_common;
-        $post['entity'] = "U8PO_PomainSave";
-
-        $time = date("Y-m-d");
-
-        foreach ($result as $value){
-            $bodys = [];
-            foreach ($value['product'] as $son){
-                //子表数据
-                $bodys[] = [
-                    "iappids"=>"", //子表id
-                    "cinvcode"=>$son['code'], //存货编码
-                    "iquantity"=>$son['number'], //数量
-                    "inum"=>$son['number'], //件数
-                    "ipertaxrate"=>$son['ipertaxrate'], //税率
-                    "iunitprice"=>$son['iunitprice'], //原币单价
-                    "itaxprice"=>$son['itaxprice'], //原币含税单价
-                    "isum"=>$son['isum'], //原币价税合计
-                    "imoney"=>$son['imoney'], //原币无税金额
-                    "itax"=>$son['itax'],//原币税额
-                    "cbmemo"=>$son['mark'], //表体备注
-                    "cdefine22"=>"",
-                    "cdefine23"=>"",
-                    "cdefine24"=>"",
-                    "cdefine25"=>"",
-                    "cdefine26"=>"",
-                    "cdefine27"=>"",
-                    "cdefine28"=>"",
-                    "cdefine29"=>"",
-                    "cdefine30"=>"",
-                    "cdefine31"=>"",
-                    "cdefine32"=>"",
-                    "cdefine33"=>"",
-                    "cdefine34"=>"",
-                    "cdefine35"=>"",
-                    "cdefine36"=>"",
-                    "cdefine37"=>"",
-                    "cfree1"=>"",
-                    "cfree2"=>"",
-                    "cfree3"=>"",
-                    "cfree4"=>"",
-                    "cfree5"=>"",
-                    "cfree6"=>"",
-                    "cfree7"=>"",
-                    "cfree8"=>"",
-                    "cfree9"=>"",
-                    "cfree10"=>""
-                ];
-            }
-
-            //最终数据
-            $post['data'] = [
-                "cpoid"=>"",
-                "dpodate"=>date("Y-m-d",$value['crt_time']),
-                "cmemo"=>$value['mark'], //"T9采购单:" . $value['order_number']
-                "cmaker"=>$cmaker ?? 'admin',
-                "cmaketime"=>$time,
-                "IsExamine"=>false,
-                "cptname"=>$value['cptname']??"",//采购类型
-                "cvencode"=>"", //供应商编码
-                "cvenname"=>$value['cvenname'], //供应商名称
-                "cdepcode"=>"", //部门编号
-                "cdepname"=>"", //部门名称 $value['cdepname']
-                "cpersoncode"=>"", //业务员编码jobnumber
-                "jobnumber"=>$value['jobnumber'], //业务员编码
-                "cdefine1"=>"",
-                "cdefine2"=>"",
-                "cdefine3"=>"",
-                "cdefine4"=>"",
-                "cdefine5"=>"",
-                "cdefine6"=>"",
-                "cdefine7"=>"",
-                "cdefine8"=>"",
-                "cdefine9"=>"",
-                "cdefine10"=>"",
-                "cdefine11"=>"",
-                "cdefine12"=>"",
-                "cdefine13"=>"",
-                "cdefine14"=>"",
-                "cdefine15"=>"",
-                "cdefine16"=>"",
-                "bodys"=>$bodys
-            ];
-
-            file_put_contents('record_purchase.txt',"请求参数:" . json_encode($post) . PHP_EOL,8);
-            $return = $this->post_u8_helper($this->u8_api,json_encode($post), ['Content-Type:application/json']);
-            file_put_contents('record_purchase.txt',"返回结果:" . json_encode($return). PHP_EOL,8);
-
-            //剔除数据
-            $id = array_diff($id, [$value['id']]);
-
-            if(empty($return)) {
-                $msg = '异常错误,请确认请求接口地址或地址不可达';
-                $this->finalSettle($value['id'], U8Job::one, $msg);
-            }else{
-                if( ! empty($return['flag'])){
-                    $this->finalSettle($value['id'], U8Job::one);
-                }else{
-                    $this->finalSettle($value['id'],  U8Job::one, $return['msg']);
-                }
-            }
-        }
-
-        if(! empty($id)){
-            $msg = "未找到同步数据";
-            $this->finalSettle($id, U8Job::one, $msg);
-        }
-    }
-
-    //销售订单(合同)保存
-    public function U8SaleOrderSave($data,$cmaker = ""){
-        if(! is_array($data)) $data = [$data];
-        $id = $data;
-
-        //映射ip是否通畅
-        $bool = $this->isDomainAvailable($this->u8['domain']);
-        if(! $bool) {
-            $msg = 'U8程序外部域名不可达';
-            $this->finalSettle($id, U8Job::two, $msg);
-            return;
-        }
-
-        //获取数据
-        $result = $this->getSaleOrderData($id);
-        if(empty($result)) {
-            $msg = "同步数据获取失败";
-            $this->finalSettle($id, U8Job::two, $msg);
-            return;
-        }
-
-        //u8接口参数组织
-        $post = $this->post_common;
-        $post['entity'] = "U8SaleOrderSave";
-
-        $time = date("Y-m-d");
-        $time1 = date("Y-m-d H:i:s");
-        foreach ($result as $value){
-            $bodys = [];
-
-            $cdefine31 = "";
-            if($value['model_type'] == SalesOrder::Model_type_two) $cdefine31 = $value['ccusabbname'];
-            foreach ($value['product'] as $son){
-                //子表数据
-                $bodys[] = [
-                    "cinvcode"=>$son['code'], //存货编码
-                    "iquantity"=>$son['number'], //数量
-                    "inum"=>$son['number'], //件数
-                    "itaxrate"=>$son['itaxrate'], //税率
-                    "iunitprice"=>$son['iunitprice'],//原币单价
-                    "itaxunitprice"=>$son['itaxunitprice'], // 原币含税单价
-                    "isum"=>$son['isum'], //原币价税合计
-                    "imoney"=>$son['imoney'], //原币无税金额
-                    "itax"=>$son['itax'],//原币税额
-                    "cbmemo"=>$son['mark'], //表体备注
-//                    "iappids"=>"", //子表id
-//                    "cinvcode"=>$son['code'], //存货编码
-//                    "iquantity"=>$son['number'], //数量
-//                    "inum"=>$son['number'], //件数
-//                    "ipertaxrate"=>$son['ipertaxrate'], //税率
-//                    "iunitprice"=>$son['iunitprice'], //原币单价
-//                    "itaxprice"=>$son['itaxprice'], //原币含税单价
-//                    "isum"=>$son['isum'], //原币价税合计
-//                    "imoney"=>$son['imoney'], //原币无税金额
-//                    "itax"=>$son['itax'],//原币税额
-//                    "cbmemo"=>$son['mark'], //表体备注
-                    "cdefine22"=>$son['cdefine22'], //手机号码
-                    "cdefine25"=>$son['cdefine25'], //平台类型
-                    "cdefine28"=>$son['cdefine28'], //平台单号
-                    "cdefine29"=>$son['cdefine29'], //分社施工
-                    "cdefine30"=>$son['cdefine30'], //业务员
-                    "cdefine31"=>$cdefine31 ? $cdefine31 : $son['cdefine31'],//客户名称
-                    "cdefine32"=>$son['cdefine32'], //达人昵称
-                    "cdefine33"=>"",
-                    "cdefine34"=>"",
-                    "cdefine35"=>"",
-                    "cdefine36"=>"",
-                    "cdefine37"=>"",
-                    "cfree1"=>"",
-                    "cfree2"=>"",
-                    "cfree3"=>"",
-                    "cfree4"=>"",
-                    "cfree5"=>"",
-                    "cfree6"=>"",
-                    "cfree7"=>"",
-                    "cfree8"=>"",
-                    "cfree9"=>"",
-                    "cfree10"=>""
-                ];
-            }
-
-            //最终数据
-            $post['data'] = [
-                "csocode"=>'',
-                "ddate"=> $time,
-                "cmaker"=>$cmaker ?? 'admin',
-                "dcreatesystime"=> $time1,
-                "cstcode"=>"",
-                "cbustype" => $value['cbustype'], //业务类型
-                "cstname"=>$value['cstname'], //销售类型
-                "ccuscode"=>"",
-                "ccusabbname"=>$value['ccusabbname'], //客户简称
-                "cdepcode"=>"",
-                "cdepname"=>"", // 部门名称 $value['cdepname']
-                "cpersoncode"=>"", //业务员编码 暂时不要
-                "jobnumber"=>$value['jobnumber'],//业务员工号
-                "itaxrate"=>"0",
-                "cmemo"=>$value['mark'],//"T9销售订单:". $value['order_number']
-                "cdefine1"=>"",
-                "cdefine2"=>"",
-                "cdefine3"=>"",
-                "cdefine4"=>"",
-                "cdefine5"=>"",
-                "cdefine6"=>"",
-                "cdefine7"=>"",
-                "cdefine8"=>"",
-                "cdefine9"=>"",
-                "cdefine10"=>"",
-                "cdefine11"=>"",
-                "cdefine12"=>"",
-                "cdefine13"=>"",
-                "cdefine14"=>"",
-                "cdefine15"=>"",
-                "cdefine16"=>"",
-                "bodys"=>$bodys
-            ];
-
-            file_put_contents('record_purchase.txt',date("Y-m-d H:i:s") . "请求参数:" . json_encode($post) . PHP_EOL,8);
-            $return = $this->post_u8_helper($this->u8_api,json_encode($post), ['Content-Type:application/json']);
-            file_put_contents('record_purchase.txt',date("Y-m-d H:i:s") ."返回结果:" . json_encode($return). PHP_EOL,8);
-
-            //剔除数据
-            $id = array_diff($id, [$value['id']]);
+        Config::set("database.connections.{$mainConnName}", $mainConfig);
+        $this->db = DB::connection($mainConnName);
 
-            if(empty($return)) {
-                $msg = '异常错误,请确认请求接口地址或地址不可达';
-                $this->finalSettle($value['id'],U8Job::two, $msg);
-            }else{
-                if( ! empty($return['flag'])){
-                    $this->finalSettle($value['id'],U8Job::two);
-                }else{
-                    $this->finalSettle($value['id'], U8Job::two, $return['msg']);
-                }
-            }
-        }
-
-        if(! empty($id)){
-            $msg = "未找到同步数据";
-            $this->finalSettle($id,U8Job::two, $msg);
-        }
+        // 测试连接有效性
+        $this->validateConnection($this->db);
     }
 
-    //最终处理
-    public function finalSettle($data,$data_type, $msg = ''){
-        if(! is_array($data)) $data = [$data];
-        $time = time();
-        $insert = [];
+    private function validateConnection($connection)
+    {
+        try {
+            $pdo = $connection->getPdo();
+            $stmt = $pdo->prepare("SELECT 1 AS connection_test");
+            $stmt->execute();
+            $result = $stmt->fetch(\PDO::FETCH_ASSOC);
 
-        U8Job::where('del_time',0)
-            ->where('data_type',$data_type)
-            ->whereIn('data',$data)
-            ->update(['del_time' => $time]);
-        foreach ($data as $value){
-            if(empty($msg)){
-                $insert[] = [
-                    'data' => $value,
-                    'data_type' => $data_type,
-                    'crt_time' => $time,
-                    'state' => U8Job::success,
-                ];
-            }else{
-                $insert[] = [
-                    'data' => $value,
-                    'data_type' => $data_type,
-                    'crt_time' => $time,
-                    'state' => U8Job::failed,
-                    'msg' => $msg
-                ];
+            if (empty($result) || $result['connection_test'] != 1) {
+                $this->error = "数据库连接失败";
             }
+        } catch (\Throwable $e) {
+            $this->error = "数据库连接验证失败: " . $e->getMessage();
         }
-
-        U8Job::insert($insert);
-    }
-
-    public function getStock($code = [], $warehouse = ""){
-        if(empty($code) || empty($warehouse)) return [false, '存货以及仓库不能为空'];
-
-        //映射ip是否通畅
-        $bool = $this->isDomainAvailable($this->u8['domain']);
-        if(! $bool) return [false, 'U8程序外部域名不可达'];
-
-        $result = $this->db->table('CurrentStock')
-            ->where("cWhCode", $warehouse)
-            ->whereIn("cInvCode", $code)
-            ->select('iQuantity as number', 'cInvCode as product_no')
-            ->get()->toArray();
-        $return = [];
-        foreach ($result as $value){
-            $return[] = [
-                'number' => floatval($value->number),
-                'product_no' => $value->product_no
-            ];
-        }
-
-        return [true, $return];
-    }
-
-    public function getSnList($data, $user){
-        //映射ip是否通畅
-        $bool = $this->isDomainAvailable($this->u8['domain']);
-        if(! $bool) return [false, 'U8程序外部域名不可达'];
-
-        if($data['sn_type'] == 1){
-            list($status, $msg) = $this->getSnListFormU8One($this->db,$data);
-        }else{
-            //发货出库单 sn码
-            list($status, $msg) = $this->getSnListFormU8Two($this->db,$data);
-        }
-
-        return [$status, $msg];
-    }
-
-    public function getSnListFormU8One($db, $data){
-        if(empty($data['code'])) return [false, '存货不能为空'];
-        $sn = $data['sn'] ?? "";
-        $construction_id = $data['construction_id'] ?? 0;
-        $warehouse = [
-            '001',
-            '003',
-            '010',
-        ];
-//        $db->enableQueryLog();
-
-        //检索条件 在库的
-        $model = $db->table('ST_SNState')
-            ->select('cinvCode as code','cInvSN as sn','AutoID as auto_id')
-            ->whereIn("cWhCode", $warehouse)
-            ->where("cInvCode", $data['code'])
-            ->where("iSNState", 2)
-            ->when(! empty($sn), function ($query) use ($sn) {
-                return $query->where('cInvSN', 'LIKE', '%'.$sn.'%');
-            })
-//            ->when(! empty($construction_id), function ($query) use ($construction_id) {
-//                return $query->whereNull('cSNDefine1')->orWhere('cSNDefine1', '')->orWhere('cSNDefine1', $construction_id);
-//            })
-            ->when(empty($construction_id), function ($query) {
-                return $query->where(function ($q) {
-                    $q->whereNull('cSNDefine1')
-                        ->orWhere('cSNDefine1', '');
-                });
-            })
-            ->orderBy('cSNDefine1','desc')
-            ->orderBy('AutoID','asc');
-
-        $list = $this->limit($model, '', $data);
-//        dd($db->getQueryLog());
-
-        return [true, $list];
-    }
-
-    public function getSnListFormU8Two($db, $data){
-        if(empty($data['code']) || empty($data['depart_title'])) return [false, '存货以及门店信息不能为空'];
-        $sn = $data['sn'] ?? "";
-        $construction_id = $data['construction_id'] ?? 0;
-//        $db->enableQueryLog();
-
-        $model = $db->table('rdrecord32 as a')
-            ->leftJoin('rdrecords32 as b','b.ID','a.ID')
-            ->leftJoin('ST_SNDetail_SaleOut as c','c.iVouchsID','b.AutoID')
-            ->select("c.cInvCode as code",'c.cinvSN as sn','c.AutoID as auto_id') //,'c.cSNDefine1','a.ID'
-            ->whereNotNull('a.cHandler')
-            ->where("b.cInvCode", $data['code'])
-            ->where("b.iQuantity", '>', 0)
-            ->where("b.cDefine31", $data['depart_title'])
-            ->whereNotNull("c.cinvSN")
-            ->when(! empty($sn), function ($query) use ($sn) {
-                return $query->where('c.cInvSN', 'LIKE', '%'.$sn.'%');
-            })
-//            ->when(! empty($construction_id), function ($query) use ($construction_id) {
-//                return $query->whereNull('c.cSNDefine1')->orWhere('c.cSNDefine1', '')->orWhere('c.cSNDefine1', $construction_id);
-//            })
-            ->when(empty($construction_id), function ($query) {
-                return $query->where(function ($q) {
-                    $q->whereNull('c.cSNDefine1')
-                        ->orWhere('c.cSNDefine1', '');
-                });
-            })
-            ->orderBy('c.cSNDefine1','desc')
-            ->orderBy('a.ID','desc')
-            ->orderBy('c.AutoID','asc');
-
-        $list = $this->limit($model, '', $data);
-//        $logs = $db->getQueryLog();dd($logs);
-
-        return [true, $list];
     }
 
-    public function getSnListFormU8ForMap($data){
-        //映射ip是否通畅
-        $bool = $this->isDomainAvailable($this->u8['domain']);
-        if(! $bool) return [false, 'U8程序外部域名不可达'];
-
-        $warehouse = [
-            '001',
-            '003',
-            '010',
-        ];
-
-        $list = $this->db->table('ST_SNState')
-            ->select("cInvCode as code",'cinvSN as sn')
-            ->whereIn("cWhCode", $warehouse)
-            ->whereIn("cInvCode", $data['code'])
-            ->whereIn('cInvSN', $data['sn'])
-//            ->where("iSNState", 2)
-            ->get()->toArray();
-
-        $return = [];
-
-        foreach ($list as $value){
-            $return[] = [
-                'code' => $value->code,
-                'sn' => $value->sn
-            ];
-        }
-
-        return [true, $return];
+    public function __destruct()
+    {
+        // 主动关闭连接
+        $this->safeDisconnect($this->db);
     }
 
-    public function saveSnUseDataDetail($sn_type, $sn_for_u8, $data_id){
-        $bool = $this->isDomainAvailable($this->u8['domain']);
-        if(! $bool) return [false, 'U8程序外部域名不可达'];
-        $db = $this->db;
-
+    private function safeDisconnect(&$connection)
+    {
         try {
-            DB::beginTransaction();
-            if(empty($sn_for_u8)){//删除
-                if($sn_type == 1){
-                    $db->table('ST_SNState')
-                        ->where('cSNDefine1', $data_id)
-                        ->update(['cSNDefine1' => ""]);
-                }else{
-                    $db->table('ST_SNDetail_SaleOut')
-                        ->where('cSNDefine1', $data_id)
-                        ->update(['cSNDefine1' => ""]);
-                }
-            }else{//增加或更新
-                if($sn_type == 1){
-                    $db->table('ST_SNState')
-                        ->whereIn('AutoID', $sn_for_u8)
-                        ->update(['cSNDefine1' => $data_id]);
-                }else{
-                    $db->table('ST_SNDetail_SaleOut')
-                        ->whereIn('AutoID', $sn_for_u8)
-                        ->update(['cSNDefine1' => $data_id]);
-                }
-            }
-
-            DB::commit();
-        }catch (\Exception $exception){
-            DB::rollBack();
-            return [false, $exception->getMessage()];
-        }
-
-        return [true, ''];
-    }
-
-    public function getSnForWarrantyData($data){
-        //映射ip是否通畅
-        $bool = $this->isDomainAvailable($this->u8['domain']);
-        if(! $bool) return [false, 'U8程序外部域名不可达'];
-
-        $warehouse = [
-            '001',
-            '003',
-            '010',
-        ];
-
-        $list = $this->db->table('ST_SNState')
-            ->select("cInvCode as code",'cinvSN as sn','AutoID as auto_id')
-            ->whereIn("cWhCode", $warehouse)
-            ->where('cInvSN', $data['sn'])
-//            ->where("iSNState", 2)
-            ->first();
-
-        $listArray = [];
-        if (! empty($list)) $listArray = get_object_vars($list);
-
-        return [true, $listArray];
-    }
-
-    public function getPurchaseData($id){
-        $main = PurchaseOrder::whereIn('id',$id)
-            ->where('del_time',0)
-            ->get()->toArray();
-        if(empty($main)) return [];
-        $supplier = Supplier::whereIn('id',array_unique(array_column($main,'supplier')))
-            ->pluck('title','id')
-            ->toArray();
-//        $depart = Depart::whereIn('id',array_unique(array_column($main,'depart_id')))
-//            ->pluck('title','id')
-//            ->toArray();
-        $emp = Employee::whereIn('id',array_unique(array_column($main,'purchase_id')))
-            ->pluck('number','id')
-            ->toArray();
-        $code_map = BasicType::whereIn('id',array_unique(array_column($main,'purchase_type')))
-            ->pluck('title','id')
-            ->toArray();
+            if ($connection instanceof \Illuminate\Database\Connection) {
+                // 物理断开连接
+                $connection->disconnect();
 
-        $sub = PurchaseOrderInfo::whereIn('purchase_order_id',$id)
-            ->where('del_time',0)
-            ->get()->toArray();
-        $product = Product::whereIn('id',array_unique(array_column($sub,'product_id')))
-            ->get()->toArray();
-        $product_map = array_column($product,null,'id');
+                // 清除连接引用
+                $connection = null;
 
-        $sub_map = [];
-        foreach ($sub as $value){
-            $product_tmp = $product_map[$value['product_id']] ?? [];
-            $value['code'] = $product_tmp['code'];
-
-            //计算金额
-            if($value['rate'] > 0){
-//                    ipertaxrate 税率
-//                    iunitprice 原币单价
-//                    itaxprice 原币含税单价
-//                    isum 原币价税合计
-//                    imoney 原币无税金额
-//                    itax 原币税额
-                $value['ipertaxrate'] = $value['rate'];
-                $rate = round($value['rate'] / 100,2);
-                $value['iunitprice'] = round($value['price'] / (1 + $rate),2);
-                $value['itaxprice'] = $value['price'];
-                $value['isum'] = round($value['price'] * $value['number'],2);
-                $value['imoney'] = round($value['iunitprice'] * $value['number'],2);
-                $value['itax'] = round($value['isum'] - $value['imoney'],2);
-            }else{
-                $value['ipertaxrate'] = 0;
-                $value['iunitprice'] = $value['price'];
-                $value['itaxprice'] = $value['price'];
-                $value['isum'] = $value['price'] * $value['number'];
-                $value['imoney'] = $value['isum'];
-                $value['itax'] = 0;
+//                Log::info("动作", [
+//                    'param' => "执行了析构",
+//                ]);
             }
-
-            $sub_map[$value['purchase_order_id']][] = $value;
+        } catch (\Throwable $e) {
+            // 静默处理断开错误
+            Log::info("错误", [
+                'param' => $e->getMessage(),
+            ]);
         }
-        foreach ($main as $key => $value){
-            $main[$key]['cptname'] = $code_map[$value['purchase_type']] ?? "";
-            $main[$key]['cvenname'] = $supplier[$value['supplier']] ?? "";
-//            $main[$key]['cdepname'] = $depart[$value['depart_id']] ?? "";
-//            $main[$key]['cpersoncode'] = $emp[$value['purchase_id']] ?? "";
-            $main[$key]['jobnumber'] = $emp[$value['purchase_id']] ?? "";
-            $main[$key]['product'] = $sub_map[$value['id']] ?? [];
-        }
-
-        return $main;
-    }
-
-    public function getSaleOrderData($id){
-        $main = SalesOrder::whereIn('id',$id)
-            ->where('del_time',0)
-            ->get()->toArray();
-        if(empty($main)) return [];
-        $main_map = array_column($main,null,'id');
-        $sub = SalesOrderProductInfo::whereIn('sales_order_id',$id)
-            ->where('del_time',0)
-            ->get()->toArray();
-        $product = Product::whereIn('id',array_unique(array_column($sub,'product_id')))
-            ->get()->toArray();
-        $product_map = array_column($product,null,'id');
-        $code_id = array_filter(array_unique(array_merge_recursive(array_column($main,'sale_type'),array_column($main,'plat_type'),array_column($main,'install_position'),array_column($main,'customer_short_name'))));
-        $code_map = BasicType::whereIn('id',$code_id)
-            ->pluck('title','id')
-            ->toArray();
-        $customer_map = Customer::whereIn('id',array_unique(array_column($main,'customer_id')))
-            ->pluck('title','id')
-            ->toArray();
-        $empList = Employee::whereIn('id',array_unique(array_column($main,'crt_id')))
-            ->select('number','id','emp_name')
-            ->get()
-            ->toArray();
-        $emp = array_column($empList,'number','id');
-        $emp2 = array_column($empList,'emp_name','id');
-
-        $sub_map = [];
-        foreach ($sub as $value){
-            $product_tmp = $product_map[$value['product_id']] ?? [];
-            $main_tmp = $main_map[$value['sales_order_id']] ?? [];
-            $position = $code_map[$main_tmp['install_position']] ?? "";
-
-            $cdefine25 = $code_map[$main_tmp['plat_type']] ?? "";//平台类型
-            $cdefine31 = $customer_map[$main_tmp['customer_id']] ?? "";
-            $cdefine28 = $cdefine29 = $cdefine30 = $cdefine32 = "";
-            if($main_tmp['model_type'] == SalesOrder::Model_type_four){
-                //线上订单
-                $cdefine28 = $main_tmp['plat_order'] ?? "";//平台单号
-                $cdefine29 = $main_tmp['cdefine29'] ?? "";
-                $cdefine30 = $main_tmp['cdefine30'] ?? "";
-                $cdefine32 = $main_tmp['cdefine32'] ?? "";
-            }elseif($main_tmp['model_type'] == SalesOrder::Model_type_two){
-                //分社订货
-                $purchase_order = PurchaseOrder::where('del_time',0)
-                    ->where('order_number',$main_tmp['contact_order_no'])
-                    ->first();
-                if(! empty($purchase_order)) $cdefine28 = SalesOrder::where('id',$purchase_order->sales_order_id)->value('order_number') ?? "";
-                $cdefine25 = "渠道部—分社";
-                $depart_tmp = Depart::where('id', $main_tmp['top_depart_id'])->first();
-                if(! empty($depart_tmp)) {
-                    $depart_tmp = $depart_tmp->toArray();
-                    if($depart_tmp['channel_id'] > 0) $cdefine30 = Employee::where('id',$depart_tmp['channel_id'])->value('emp_name');
-                }
-            }else{
-                $cdefine28 = $main_tmp['order_number'] ?? "";
-                $cdefine29 = $position;
-                $cdefine30 = $emp2[$main_tmp['crt_id']] ?? "";
-            }
-//            "itaxrate"=>$son['itaxrate'], //税率
-//            "iunitprice"=>$son['iunitprice'],//原币单价
-//            "itaxunitprice"=>$son['itaxunitprice'], // 原币含税单价
-//            "isum"=>$son['isum'], //原币价税合计
-//            "imoney"=>$son['imoney'], //原币无税金额
-//            "itax"=>$son['itax'],//原币税额
-            //计算金额
-            //比如这4个产品合同金额是300.11,那么价税合计就是300.11,
-            //含税单价就是300.11/4,目前加了税率的没有计算规则。税率不进入计算
-
-            $value['itaxrate'] = 0;//税率
-            $value['iunitprice'] = $value['price'];
-            $value['itaxunitprice'] = $value['price'];
-            $value['isum'] = $value['final_amount']; //原币价税合计
-            $value['imoney'] = $value['isum']; //原币无税金额
-            $value['itax'] = 0;
-
-//            if($value['rate'] > 0){
-//                $value['itaxrate'] = $value['rate'];
-//                $rate = round($value['rate'] / 100,2);
-//                $value['iunitprice'] = round($value['final_amount'] / (1 + $rate),2);
-//                $value['itaxunitprice'] = $value['final_amount'];
-//                $value['isum'] = round($value['final_amount'] * $value['number'],2);
-//                $value['imoney'] = round($value['iunitprice'] * $value['number'],2);
-//                $value['itax'] = round($value['isum'] - $value['imoney'],2);
-//            }else{
-//                $value['itaxrate'] = 0;
-//                $value['iunitprice'] = $value['final_amount'];
-//                $value['itaxunitprice'] = $value['final_amount'];
-//                $value['isum'] = $value['final_amount'] * $value['number'];
-//                $value['imoney'] = $value['isum'];
-//                $value['itax'] = 0;
-//            }
-            $value['cdefine25'] = $cdefine25;//平台类型
-            $value['cdefine28'] = $cdefine28; //平台单号
-            $value['cdefine29'] = $cdefine29;//分社施工
-            $value['cdefine32'] = $cdefine32;//达人昵称
-            $value['cdefine31'] = $cdefine31;//客户名称
-            $value['cdefine22'] = $main_tmp['customer_contact'] ?? "";//手机号码
-            $value['cdefine30'] = $cdefine30;//业务员
-            $value['code'] = $product_tmp['code'];//存货编码
-
-            $sub_map[$value['sales_order_id']][] = $value;
-        }
-        foreach ($main as $key => $value){
-            $customer_short_name = $code_map[$value['customer_short_name']] ?? "";
-            if($value['model_type'] == SalesOrder::Model_type_two && $value['customer_short_name'] == 0) {
-                $purchase_tmp = PurchaseOrder::where('order_number',$value['contact_order_no'])->value("top_depart_id");
-                $customer_short_name = Depart::where('id',$purchase_tmp)->value('title');
-            }
-            $main[$key]['cbustype'] = "普通销售"; //业务类型(本身就是中文)
-            $main[$key]['cstname'] = SalesOrder::$model_type_title_u8[$value['model_type']] ?? ""; //销售类型
-            $main[$key]['ccusabbname'] = $customer_short_name;//客户简称
-//            $main[$key]['cdepname'] = $depart[$value['top_depart_id']] ?? "";//部门名称
-//            $main[$key]['cpersoncode'] = $emp[$value['crt_id']] ?? "";//业务员
-//            $main[$key]['jobnumber'] = $emp[$value['crt_id']] ?? "";
-            if($value['model_type'] == SalesOrder::Model_type_one){
-                $main[$key]['jobnumber'] = "T90043";
-            }elseif ($value['model_type'] == SalesOrder::Model_type_two){
-                $main[$key]['jobnumber'] = "T90022";
-            }elseif ($value['model_type'] == SalesOrder::Model_type_four){
-                $main[$key]['jobnumber'] = "T90043";
-            }else{
-                $main[$key]['jobnumber'] = "T90000";
-            }
-
-            $main[$key]['product'] = $sub_map[$value['id']] ?? [];
-        }
-
-        return $main;
-    }
-
-    public function getMessage($id,$type){
-        $result = U8Job::where('del_time',0)
-            ->whereIn('data',$id)
-            ->where('data_type',$type)
-            ->select('data','state','crt_time','msg')
-            ->get()->toArray();
-        $return = [];
-        foreach ($result as $value){
-            if($value['state'] == 1){
-                $return[$value['data']] = '同步成功';
-            }else{
-                $return[$value['data']] = '同步失败:' . $value['msg'];
-            }
-        }
-
-        return $return;
-    }
-
-    public function post_u8_helper($url, $data, $header = [], $timeout = 50){
-        $ch = curl_init();
-        curl_setopt($ch, CURLOPT_URL, $url);
-        curl_setopt($ch,  CURLOPT_RETURNTRANSFER, true);
-        curl_setopt($ch, CURLOPT_ENCODING, '');
-        curl_setopt($ch, CURLOPT_POST, 1);
-        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
-        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
-        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
-        if(!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
-        $r = curl_exec($ch);
-        curl_close($ch);
-        return json_decode($r, true);
     }
 }