cqpCow 1 anno fa
parent
commit
9502ffc747

+ 2 - 1
app/Http/Controllers/Api/BoxController.php

@@ -13,7 +13,8 @@ class BoxController extends BaseController
     public function boxIn(Request $request)
     {
         $service = new BoxService();
-        list($status,$data) = $service->boxIn($request->all());
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->boxIn($request->all(),$userData);
 
         if($status){
             return $this->json_return(200,'',$data);

+ 18 - 4
app/Service/Box/BoxService.php

@@ -9,6 +9,8 @@ use App\Model\Header_ext;
 use App\Model\OrdersProduct;
 use App\Model\SaleOrdersProduct;
 use App\Model\Team;
+use App\Service\FinishedOrderService;
+use App\Service\FyySqlServerService;
 use App\Service\Service;
 use Illuminate\Support\Facades\DB;
 
@@ -39,7 +41,7 @@ class BoxService extends Service
      * @param $data
      * @return array
      */
-    public function boxIn($data)
+    public function boxIn($data,$user)
     {
         $ids = [];
         $sale_ids = [];
@@ -67,6 +69,7 @@ class BoxService extends Service
 
         try{
             DB::beginTransaction();
+            $time = time();
             $key = $this->lock_key.'_'.$v['id'];
             $lock_status = $this->isLock($key);
             if(!$lock_status) return [false,'操作过于频繁'];
@@ -160,7 +163,6 @@ class BoxService extends Service
             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['ext_1'] = $ext_1;
-
             $insert['detail'] = $box_insert;
             $insert['top_order_no'] = $top_order_no;
             $insert['order_no'] = $box_no;
@@ -173,8 +175,20 @@ class BoxService extends Service
             }
             $this->delLock($key);
 
+            //调用产成品入库
+            $package_data = $msg->toArray();
+            if(! empty($package_data)) {
+                $service = new FinishedOrderService();
+                list($status,$msg) = $service->U8Rdrecord10Save($package_data,$user);
+                if(! $status) {
+                    (new FyySqlServerService())->recordErrorTable($msg,$user,$package_data,$time,1);
+                    DB::rollBack();
+                    return [false, $msg];
+                }
+            }
+
             DB::commit();
-            return [true, ['package_data' => $msg->toArray()]];
+            return [true, ['package_data' => $package_data]];
         }catch (\Exception $e){
             DB::rollBack();
             return [false,$e->getLine().':'.$e->getMessage()];
@@ -187,7 +201,7 @@ class BoxService extends Service
      * @return array
      */
     public function transportBoxIn($data)
-    {
+    {return [true,''];
 //        $param = [
 //            [
 //                'order_no' => 'XD202309000155',

+ 24 - 6
app/Service/FyySqlServerService.php

@@ -4,6 +4,7 @@ namespace App\Service;
 
 use App\Model\BoxDetail;
 use App\Model\Employee;
+use App\Model\ErrorTable;
 use App\Model\Orders;
 use App\Model\SaleOrdersProduct;
 use Illuminate\Support\Facades\Config;
@@ -40,6 +41,10 @@ class FyySqlServerService extends Service
                 return;
             }
 
+            $this->host = env('Yongyou_database_ip');
+            $this->host_api = env('Yongyou_api_ip');
+            $this->database = env('Yongyou_database');
+
             //映射ip是否通畅
             $bool = $this->isHostReachable($this->host);
             if(! $bool) {
@@ -268,21 +273,22 @@ class FyySqlServerService extends Service
         }
 
         //数据
+        $bodys = [];
         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'],
+                "inum" => $value["num"],
+                "iunitcost" => $value["price"] * 0.95,
+                "iprice" => $value["price"] * 0.95 * $value['num'],
                 "iinvexchrate" => "1.00",
                 "impoids" => "",
                 "cmocode" => "",
                 "imoseq" => "",
                 "cbmemo" => "",
-                "cfree1" => $value['technology_name'], //颜色
+                "cfree1" => $value['ext_3'], //颜色
                 "cfree2" => "",
                 "cdefine28" => "",
             ];
@@ -306,8 +312,8 @@ class FyySqlServerService extends Service
                 "dnmaketime" => date("Y-m-d"),
                 "IsExamine" => true,
                 "bredvouch" => $bredvouch,
-                "cwhcode" => "02",
-                "cdepcode" => "06",
+                "cwhcode" => "002",
+                "cdepcode" => "03",
                 "crdcode" => "102", //生产入库
                 "cmemo" => $cmemo,
                 "cdefine10" => $data['ext_1'] ?? "", //客户名称
@@ -510,4 +516,16 @@ class FyySqlServerService extends Service
 
         return $list;
     }
+
+    public function recordErrorTable($msg,$user,$data,$time,$type){
+        // 连接到指定数据库连接
+        ErrorTable::insert([
+            'msg' => $msg,
+            'data' => json_encode($data),
+            'user_id' => $user['id'],
+            'user_operation_time' => $time,
+            'type' => $type,
+            'order_no' => $data['order_no'] ?? ""
+        ]);
+    }
 }

+ 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')->middleware('YongYou');
+    $route->any('box_in', 'Api\BoxController@boxIn');
     $route->any('transportBoxIn', 'Api\BoxController@transportBoxIn');
     $route->any('boxOrderDetailByTop', 'Api\BoxController@boxOrderDetailByTop');
     $route->any('boxOrderDetailByOrderNo', 'Api\BoxController@boxOrderDetailByOrderNo');