cqpCow 1 рік тому
батько
коміт
46dd660778

+ 4 - 8
app/Service/Box/BoxHookService.php

@@ -45,9 +45,7 @@ class BoxHookService extends Service
     public function boxInsert($data){
         $box = new Box();
         if(!isset($data['order_no'])||empty($data['order_no'])) $data['order_no'] = $this->setOrderNo();
-        if(!isset($data['out_order_no'])) return [false,'out_order_no is not exist'];
-//        if(!isset($data['top_id'])) return [false,'top_id is not exist'];
-//        if(!isset($data['num'])) return [false,'num is not exist'];
+        if(!isset($data['out_order_no'])) return [false,'out_order_no不存在!'];
         list($status,$box) = $this->dealBox($box,$data);
         if(!$status) return [false,$box];
         $box->save();
@@ -103,11 +101,8 @@ class BoxHookService extends Service
         $insert = [];
         $time = time();
         foreach ($data as $v){
-            if(!isset($v['top_id'])) return [false,'top_id is not exist'];
-//            if(!isset($v['code'])) return [false,'code is not exist'];
-//            if(!isset($v['title'])) return [false,'title is not exist'];
-//            if(!isset($v['type'])) return [false,'type is not exist'];
-            if(!isset($v['num'])) return [false,'type is not exist'];
+            if(!isset($v['top_id'])) return [false,'top_id不存在!'];
+            if(!isset($v['num'])) return [false,'数量不存在!'];
 
             $insert[] = [
                 'order_no' => $order_no,
@@ -116,6 +111,7 @@ class BoxHookService extends Service
                 'code' => '',
                 'title' => '',
                 'num' => $v['num'],
+                'price' => $v['price'],
                 'type' => isset($v['type'])?$v['type'] : 1,
                 'crt_time' => $time,
                 'upd_time' => $time,

+ 11 - 47
app/Service/Box/BoxService.php

@@ -34,7 +34,6 @@ class BoxService extends Service
 
     }
 
-
     /**
      * 包装
      * @param $data
@@ -42,27 +41,6 @@ class BoxService extends Service
      */
     public function boxIn($data)
     {
-//        if(!isset($data['params'])) return [false,'not found params'];
-//        $param = $data['params'];
-//        $param = [
-//            [
-//                'id' => 716,
-//                'order_no' => 716,
-//                'params' => [
-//                    '1',
-//                    '1',
-//
-//                ],
-
-//            ], [
-//                'id' => 723,
-//                'order_no' => 716,
-//                'params' => [
-//                    '40'
-//                ],
-//            ],
-//        ];
-
         $ids = [];
         $sale_ids = [];
         $top_order_no = $data['order_no'];
@@ -120,12 +98,13 @@ class BoxService extends Service
                         'ext_4' => $ext_4,
                         'ext_5' => $ext_5,
                         'num' => $vv,
+                        'price' => $v['price'],
                         'box_type' => 1,
                         'team_id' => $team_id,
                         'shipment_order_no' => $transport_no,
                     ];
-
                 }
+
                 SaleOrdersProduct::where('id',$v['sale_orders_product_id'])->update([
                     'box_num' => DB::raw('box_num + '.$total),
                 ]);
@@ -164,6 +143,7 @@ class BoxService extends Service
                         'ext_4' => $ext_4,
                         'ext_5' => $ext_5,
                         'num' => $vv,
+                        'price' => $v['price'],
                         'box_type' => $box_type,
                         'team_id' => $team_id,
                         'shipment_order_no' => $transport_no,
@@ -175,6 +155,11 @@ class BoxService extends Service
                 ]);
             }
 
+            //客户名称
+            $ext_1 = "";
+            if(empty($ext_1) && isset($sale_product_list[0]['customer_name'])) $ext_1 = $sale_product_list[0]['customer_name'];
+            if(empty($ext_1) && isset($product_list[0]['customer_name'])) $ext_1 = $product_list[0]['customer_name'];
+
             $insert['detail'] = $box_insert;
             $insert['top_order_no'] = $top_order_no;
             $insert['order_no'] = $box_no;
@@ -188,7 +173,7 @@ class BoxService extends Service
             $this->delLock($key);
 
             DB::commit();
-            return [true,''];
+            return [true, ['package_data' => $msg->toArray()]];
         }catch (\Exception $e){
             DB::rollBack();
             return [false,$e->getLine().':'.$e->getMessage()];
@@ -326,7 +311,7 @@ class BoxService extends Service
         $model = SaleOrdersProduct::where('del_time',0)->wherein('id',$sale_order_ids)
             ->select('id','out_order_no','order_no','customer_no','customer_name','product_no','product_title','product_size','crt_time as production_time','id as sale_orders_product_id','finished_num as dispatch_complete_quantity','box_num','technology_name','wood_name','crt_time','order_quantity','technology_material','technology_name','wood_name','process_mark')
             ->orderBy('id','desc')->get()->toArray();
-        $product_list = ordersProduct::where('del_time',0)->wherein('sale_orders_product_id',$sale_order_ids)->select('id','out_order_no','customer_no','customer_name','product_no','sale_orders_product_id','product_title','product_size','dispatch_complete_quantity','box_num','technology_name','wood_name','crt_time',DB::raw('(production_quantity - scrapp_num) as production_quantity '),DB::raw('finished_num as dispatch_complete_quantity '),'technology_material','technology_name','wood_name','process_mark')->get()->toArray();
+        $product_list = ordersProduct::where('del_time',0)->wherein('sale_orders_product_id',$sale_order_ids)->select('id','out_order_no','customer_no','customer_name','product_no','sale_orders_product_id','product_title','product_size','dispatch_complete_quantity','box_num','technology_name','wood_name','crt_time',DB::raw('(production_quantity - scrapp_num) as production_quantity'),DB::raw('finished_num as dispatch_complete_quantity'),'technology_material','technology_name','wood_name','process_mark')->get()->toArray();
         $model_key_list = [];
         foreach ($model as $v){
             $model_key_list[$v['id']] = $v;
@@ -361,12 +346,7 @@ class BoxService extends Service
                         $box_num += $vv['box_num'];
                     }
                 }
-
-//                $product_num = isset($product_key_num_list[$v['id']]) ? $product_key_num_list[$v['id']]['product_num'] : 0;
-//                $box_num = isset($product_key_num_list[$v['id']]) ? $product_key_num_list[$v['id']]['box_num'] : 0;
                 if(($v['order_quantity'] - $product_num) === 0) continue;
-//                var_dump($v['order_quantity']);
-//                var_dump($v['order_quantity']);
                 $product_key_list[$v['sale_orders_product_id']] = [
                     'out_order_no' => $v['out_order_no'],
                     'order_no' => $v['order_no'],
@@ -413,23 +393,6 @@ class BoxService extends Service
             $return[] = $v;
         }
 
-//        $data = [
-//            [
-//                'id' => 1,
-//                'out_order_no' => '销售订单号',
-//                'production_time' => '下生产时间',
-//                'customer_no' => '客户编码',
-//                'customer_name' => '客户名称',
-//                'product_no' => '产品编码',
-//                'product_title' => '产品名称',
-//                'product_size' => '产品规格',
-//                'type' => '1生产包装2备用包装',
-//                'is_box_num' => '已包装数量',
-//                'un_box_num' => '未包装',
-//                'sale_num' => '销售数量',
-//            ]
-//        ];
-
         return [true,$return];
     }
 
@@ -563,6 +526,7 @@ class BoxService extends Service
                     //                $ext_3 = $v['technology_name'];//工艺名称
                     //                $ext_4 = $v['wood_name'];//木皮
                     //                $ext_5 = $v['process_mark'];//工艺备注
+                    // toDO 有问题
                     OrdersProduct::where('product_no',$vv['ext_1'])->where('technology_material',$vv['ext_2'])->where('technology_name',$vv['ext_3'])->where('wood_name',$vv['ext_4'])->where('process_mark',$vv['ext_5'])->where('sale_orders_product_id',$vv['top_id'])
                         ->update([
                             'box_num' => DB::raw('box_num - '.$vv['num'])

+ 31 - 0
app/Service/FinishedOrderService.php

@@ -3,6 +3,8 @@
 namespace App\Service;
 
 use App\Jobs\ProcessDataJob;
+use App\Model\Box;
+use App\Model\BoxDetail;
 use App\Model\DispatchSub;
 use App\Model\Employee;
 use App\Model\EmployeeTeamPermission;
@@ -154,6 +156,35 @@ class FinishedOrderService extends Service
         return [true, ''];
     }
 
+    //产成品入口
+    public function U8Rdrecord10Save($package_data, $user){
+        if(empty($package_data)) return [true, ''];
+
+        try{
+            //获取包装单信息
+            $box = $package_data;
+            $boxDetail = new BoxDetail(['channel'=>$box['top_order_no']]);
+            $boxDetail = $boxDetail->where('del_time',0)
+                ->where('order_no',$box['order_no'])
+                ->select('id','top_id','num','ext_1','ext_2','ext_3','ext_4','ext_5','out_order_no','box_type','price')
+                ->get()->toArray();
+
+
+            //用友数据插入------------
+            if(! empty($insert_sql_server)){
+                $sqlServerModel = new FyySqlServerService($user);
+                if($sqlServerModel->error) return [false, $sqlServerModel->error];
+                list($status,$msg) = $sqlServerModel->U8Rdrecord10Save($box,$boxDetail);
+                if(! $status) return [false, $msg];
+            }
+
+        }catch (\Exception $e){
+            return [false,$e->getMessage() . '|' . $e->getFile() . '|' . $e->getLine()];
+        }
+
+        return [true,''];
+    }
+
     public function addInJob($result,$data,$user){
         try{
             //获取数据库连接

+ 28 - 23
app/Service/FyySqlServerService.php

@@ -257,34 +257,37 @@ class FyySqlServerService extends Service
     }
 
     //产成品入库单保存接口以及审核
-    public function U8Rdrecord10Save($data, $bredvouch = 0)
+    public function U8Rdrecord10Save($data, $data_detail,  $bredvouch = 0)
     {
-        if (!empty($this->error)) return [false, $this->error];
+        if (! empty($this->error)) return [false, $this->error];
 
         if ($bredvouch) {
             $cmemo = '来源:恒诚塑业完工操作撤回';
         } else {
-            $cmemo = '来源:恒诚塑业完工操作 派工单号:' . $data['dispatch_no'];
+            $cmemo = '来源:恒诚塑业完工操作 包装单号:' . $data['order_no'];
         }
 
         //数据
-        $bodys[] = [
-            "cinvcode" => $data["product_no"],
-            "cposition" => "",
-            "cbatch" => "",
-            "iquantity" => $data["quantity"],
-            "inum" => $data["quantity"],
-            "iunitcost" => $data["price"] * 0.95,
-            "iprice" => $data["price"] * 0.95 * $data['quantity'],
-            "iinvexchrate" => "1.00",
-            "impoids" => "",
-            "cmocode" => "",
-            "imoseq" => "",
-            "cbmemo" => "",
-            "cfree1" => $data['technology_name'],
-            "cfree2" => $data['wood_name'],
-            "cdefine28" => $data['technology_material'],
-        ];
+        foreach ($data_detail as $value){
+            $bodys[] = [
+                "cinvcode" => $value["ext_1"],
+                "cposition" => "",
+                "cbatch" => "",
+                "iquantity" => $value["num"],
+                "inum" => $data["num"],
+                "iunitcost" => $data["price"] * 0.95,
+                "iprice" => $data["price"] * 0.95 * $data['num'],
+                "iinvexchrate" => "1.00",
+                "impoids" => "",
+                "cmocode" => "",
+                "imoseq" => "",
+                "cbmemo" => "",
+                "cfree1" => $value['technology_name'], //颜色
+                "cfree2" => "",
+                "cdefine28" => "",
+            ];
+        }
+
         $post = [
             "password" => "cloud@123456",
             "entity" => "U8Rdrecord10Save",
@@ -307,14 +310,16 @@ class FyySqlServerService extends Service
                 "cdepcode" => "06",
                 "crdcode" => "102", //生产入库
                 "cmemo" => $cmemo,
-                "cdefine10" => $data['customer_name'], //客户名称
+                "cdefine10" => $data['ext_1'] ?? "", //客户名称
                 "bodys" => $bodys
             ]
         ];
-        file_put_contents('record_ss.txt', json_encode($post) . PHP_EOL, 8);
+
+        Log::channel('apiLog')->info('产成品入库:源数据', ["param" => $post]);
 
         $return = $this->post_helper($this->url, json_encode($post), ['Content-Type:application/json']);
-        file_put_contents('record_ss.txt', json_encode($return) . PHP_EOL, 8);
+
+        Log::channel('apiLog')->info('产成品入库:返回结果', ["param" => $return]);
 
         if (empty($return)) return [false, '异常错误,请确认请求接口地址!'];
         return [$return['flag'], $return['msg']];

+ 8 - 0
config/logging.php

@@ -107,6 +107,14 @@ return [
             'level' => 'debug',
             'days' => 7,
         ],
+
+        //接口日志记录
+        'apiLog' => [
+            'driver' => 'daily',
+            'path' => storage_path('logs/api_log.log'),
+            'level' => 'debug',
+            'days' => 7,
+        ],
     ],
 
 ];

+ 1 - 1
routes/api.php

@@ -213,7 +213,7 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('boxDetail', 'Api\BoxController@boxDetail');
     $route->any('boxOrderDetail', 'Api\BoxController@boxOrderDetail');
     $route->any('boxProductList', 'Api\BoxController@boxProductList');
-    $route->any('box_in', 'Api\BoxController@boxIn');
+    $route->any('box_in', 'Api\BoxController@boxIn')->middleware('YongYou');
     $route->any('transportBoxIn', 'Api\BoxController@transportBoxIn');
     $route->any('boxOrderDetailByTop', 'Api\BoxController@boxOrderDetailByTop');
     $route->any('boxOrderDetailByOrderNo', 'Api\BoxController@boxOrderDetailByOrderNo');