cqpCow 2 years ago
parent
commit
e767ccf93b

+ 30 - 0
app/Service/FinishedOrderService.php

@@ -64,11 +64,13 @@ class FinishedOrderService extends Service
 
 
             date_default_timezone_set("PRC");
             date_default_timezone_set("PRC");
 
 
+            $insert_sql_server = [];
             foreach ($result as $key => $value){
             foreach ($result as $key => $value){
                 $quantity_tmp = $data['quantity'][$key];
                 $quantity_tmp = $data['quantity'][$key];
                 $finished_id_tmp = $data['finish_id'][$key];
                 $finished_id_tmp = $data['finish_id'][$key];
                 $team_tmp = $data['team_id'][$key];
                 $team_tmp = $data['team_id'][$key];
                 $equipment_id_tmp = $data['equipment_id'][$key];
                 $equipment_id_tmp = $data['equipment_id'][$key];
+                $result[$key]['quantity'] = $quantity_tmp;
 
 
                 $finished_num = $quantity_tmp + $value['finished_num'];
                 $finished_num = $quantity_tmp + $value['finished_num'];
                 DispatchSub::where('id',$value['id'])
                 DispatchSub::where('id',$value['id'])
@@ -99,7 +101,24 @@ class FinishedOrderService extends Service
                     }
                     }
                 }
                 }
 
 
+                //工序表
                 $process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
                 $process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
+
+                $process_id = $process_model->select('process_id')
+                    ->where('sort',$process_model->where('del_time',0)
+                        ->where('order_product_id',$value['order_product_id'])
+                        ->max('sort'))
+                    ->first();
+
+                if(empty($process_id)){
+                    DB::rollBack();
+                    return [false,"未找到最后一道工序"];
+                }
+                $process_id = $process_id->process_id;
+                if($process_id == $value['process_id']){
+                    $insert_sql_server[] = $result[$key];
+                }
+
                 $process_model->where('order_product_id',$value['order_product_id'])
                 $process_model->where('order_product_id',$value['order_product_id'])
                     ->where('process_id',$value['process_id'])
                     ->where('process_id',$value['process_id'])
                     ->where('dispatch_no',$value['dispatch_no'])
                     ->where('dispatch_no',$value['dispatch_no'])
@@ -115,8 +134,19 @@ class FinishedOrderService extends Service
                 if(! empty($insert_waste)) $process_model->insert($insert_waste);
                 if(! empty($insert_waste)) $process_model->insert($insert_waste);
             }
             }
 
 
+            //反写数量
             $this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'));
             $this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'));
 
 
+            if(! empty($insert_sql_server)){
+                //生成产成品入库
+                $sqlServerModel = new FyySqlServerService();
+                list($status,$msg) = $sqlServerModel->U8Rdrecord10Save($insert_sql_server);
+                if(! $status) {
+                    DB::rollBack();
+                    return [false,$msg];
+                }
+            }
+
             DB::commit();
             DB::commit();
         }catch (\Exception $e){
         }catch (\Exception $e){
             DB::rollBack();
             DB::rollBack();

+ 110 - 0
app/Service/FyySqlServerService.php

@@ -6,12 +6,17 @@ use App\Model\Orders;
 use App\Model\SaleOrdersProduct;
 use App\Model\SaleOrdersProduct;
 use Illuminate\Support\Facades\Config;
 use Illuminate\Support\Facades\Config;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Redis;
 use Illuminate\Support\Facades\Redis;
 
 
 class FyySqlServerService extends Service
 class FyySqlServerService extends Service
 {
 {
     public $db = null;
     public $db = null;
     public $error = null;
     public $error = null;
+    public $host = "";
+    public $port = 0;
+    public $database = "";
+    public $url = "";
 
 
     public function __construct()
     public function __construct()
     {
     {
@@ -22,6 +27,11 @@ class FyySqlServerService extends Service
         }
         }
         $fyy_array = json_decode($fyy_array,true);
         $fyy_array = json_decode($fyy_array,true);
 
 
+        $this->host = $fyy_array['sqlserver_host'] ?? '';
+        $this->port = $fyy_array['sqlserver_port'] ?? 0;
+        $this->database = $fyy_array['sqlserver_database'] ?? '';
+        $this->url = empty($this->host)?: "http://" . $this->host . ":12365/U8Sys/U8API";
+
         if(! $this->db){
         if(! $this->db){
             $config = [
             $config = [
                 'driver' => 'sqlsrv',
                 'driver' => 'sqlsrv',
@@ -271,4 +281,104 @@ class FyySqlServerService extends Service
 
 
         return [true,$message,$product];
         return [true,$message,$product];
     }
     }
+
+    //产成品入库单保存接口以及审核
+    public function U8Rdrecord10Save($data){
+        if(! empty($this->error)) return [false,$this->error];
+        date_default_timezone_set("PRC");
+
+        list($bool,$msg) = $this->createOrderNumberAboutSCRK();
+        if(! $bool) return [false,$msg];
+
+        //数据
+        $bodys = [];
+        foreach ($data as $value){
+            $bodys[] = [
+                "cinvcode" => $value["product_no"],
+                "cposition" => "",
+                "cbatch" => "",
+                "iquantity" => $value["quantity"],
+                "inum" => $value["quantity"],
+                "iunitcost" => "0",
+                "iprice" => "0",
+                "iinvexchrate" => "1.00",
+                "impoids" => "",
+                "cmocode" => "",
+                "imoseq" => "",
+                "cbmemo" => "",
+                "cfree1" => "",
+                "cfree2" => ""
+            ];
+        }
+        $post = [
+            "password"=>"cloud@123456",
+            "entity"=>"U8Rdrecord10Save",
+            "login"=>[
+                "sAccID"=> "(default)@001",
+                "sDate"=> date("Y-m-d"),
+                "sServer"=> '127.0.0.1',
+                "sUserID"=> "董晓磊",
+                "sSerial"=> "",
+                "sPassword"=> ""
+            ],
+            "data"=>[
+                "ccode"=>$msg,
+                "ddate"=>date("Y-m-d"),
+                "cmaker"=>"董晓磊",
+                "dnmaketime"=> date("Y-m-d"),
+                "IsExamine"=>true,
+                "bredvouch"=>"0",
+                "cwhcode"=>"02",
+                "cdepcode"=>"",
+                "crdcode"=>"",
+                "cmemo"=>"",
+                "bodys"=>$bodys
+            ]
+        ];
+
+        $return = $this->post_helper($this->url,json_encode($post), ['Content-Type:application/json']);
+        return [$return['flag'], $return['msg']];
+    }
+
+    //产成品入库单单据号
+    public function createOrderNumberAboutSCRK(){
+        date_default_timezone_set("PRC");
+
+        $current_month = date('m'); // 获取当前月份
+        $date1 = date('y') . $current_month  ; // 格式 "2307"
+        $date2 = date('Y') . $current_month; // 格式 "202307"
+
+        $record = $this->db->table('VoucherHistory')
+            ->where('CardNumber','0411')
+            ->whereRaw("(cSeed = '{$date1}' or cSeed = '{$date2}')")
+            ->select('cNumber')
+            ->first();
+        $record = (array)$record;
+        if(empty($record)) return [false,'未找到产成品入库当月流水号信息!'];
+
+        $tmp = $record['cNumber'] + 1;
+        if(strlen($tmp) > 4) return [false,'产成品入库当月流水号超过四位数!'];
+
+        $number = str_pad($tmp,4,'0',STR_PAD_LEFT);
+        $number = $tmp . $number;
+        $ccode = "SCRK" . $date2 . $number;
+
+        return [true,$ccode];
+    }
+
+    public function post_helper($url, $data,$header = [],$timeout = 60){
+        $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);
+    }
 }
 }

+ 3 - 2
app/Service/ProductionOrderService.php

@@ -101,7 +101,7 @@ class ProductionOrderService extends Service
                         'crt_time' => $time
                         'crt_time' => $time
                     ];
                     ];
 
 
-                    foreach ($process_arr as $v){
+                    foreach ($process_arr as $k => $v){
                         $process[$time_tmp][] = [
                         $process[$time_tmp][] = [
                             'order_product_id' => $last_insert_id[$key],
                             'order_product_id' => $last_insert_id[$key],
                             'production_no' => $production_no,
                             'production_no' => $production_no,
@@ -110,7 +110,8 @@ class ProductionOrderService extends Service
                             'out_order_no' => $value['out_order_no'],
                             'out_order_no' => $value['out_order_no'],
                             'product_no' => $value['product_no'],
                             'product_no' => $value['product_no'],
                             'product_title' => $value['product_title'],
                             'product_title' => $value['product_title'],
-                            'crt_time' => $time
+                            'crt_time' => $time,
+                            'sort' => $k,
                         ];
                         ];
                     }
                     }
                 }
                 }