cqpCow 2 年之前
父節點
當前提交
c1bc512acc

+ 91 - 0
app/Http/Controllers/Api/DispatchController.php

@@ -0,0 +1,91 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+
+use App\Service\DispatchService;
+use Illuminate\Http\Request;
+
+
+class DispatchController extends BaseController
+{
+    public function add(Request $request)
+    {
+        $service = new DispatchService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->add($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function edit(Request $request)
+    {
+        $service = new DispatchService();
+        $user = $request->get('auth');
+        list($status,$data) = $service->edit($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function del(Request $request)
+    {
+        $service = new DispatchService();
+        $user = $request->get('auth');
+        list($status,$data) = $service->del($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+
+    public function orderList(Request $request)
+    {
+        $service = new DispatchService();
+        $user = $request->get('auth');
+        list($status,$data) = $service->orderList($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+
+    public function orderDetail(Request $request)
+    {
+        $service = new DispatchService();
+        $user = $request->get('auth');
+        list($status,$data) = $service->orderDetail($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function dispatchOrderList(Request $request)
+    {
+        $service = new DispatchService();
+        $user = $request->get('auth');
+        list($status,$data) = $service->dispatchOrderList($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+}

+ 19 - 0
app/Model/Dispatch.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ *
+ * Class Unit
+ * @package App\Models
+ */
+class Dispatch extends Model
+{
+    protected $table = "dispatch"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+}

+ 19 - 0
app/Model/DispatchSub.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ *
+ * Class Unit
+ * @package App\Models
+ */
+class DispatchSub extends Model
+{
+    protected $table = "dispatch_sub"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+}

+ 19 - 0
app/Model/OrdersProductMain.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ *
+ * Class Unit
+ * @package App\Models
+ */
+class OrdersProductMain extends Model
+{
+    protected $table = "orders_product_main"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+}

+ 19 - 1
app/Model/OrdersProductProcess.php

@@ -21,7 +21,7 @@ class OrdersProductProcess extends Model
     //$guarded属性里面的字段是不可以赋值,其他的所有属性都能被赋值
     protected $guarded = [];
 
-    protected $month = [
+    public $month = [
         1 => '01_03',
         2 => '01_03',
         3 => '01_03',
@@ -44,6 +44,11 @@ class OrdersProductProcess extends Model
             $month = (int)substr($channel,4,2);
             $channel = substr($channel,0,4).$this->month[$month];
             $this->setTableById($channel);
+        }elseif (isset($attributes['process']) && $attributes['process'] > 0){
+            $process = $attributes['process'];
+            $month = (int)substr($process,4,2);
+            $process = substr($process,0,4).$this->month[$month];
+            $this->setTableByProcess($process);
         }
     }
 
@@ -64,4 +69,17 @@ class OrdersProductProcess extends Model
             DB::statement('create table '. $table .' like orders_product_bom_process');
         }
     }
+
+    public function setTableByProcess($process)
+    {
+        if ($process > 0) {
+            $tb = $this->table.'_' . (string)$process;
+            $this->setTable($tb);
+        }
+    }
+
+    public function is_table_isset(){
+        if(Schema::hasTable($this->table)) return true;
+        return false;
+    }
 }

+ 296 - 0
app/Service/DispatchService.php

@@ -0,0 +1,296 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\Dispatch;
+use App\Model\DispatchSub;
+use App\Model\Employee;
+use App\Model\EmployeeTeamPermission;
+use App\Model\OrdersProduct;
+use App\Model\OrdersProductProcess;
+use Illuminate\Support\Facades\DB;
+
+class DispatchService extends Service
+{
+    public function edit($data){}
+
+    public function setOrderNO(){
+        $str = date('Ymd',time());
+
+        $order_number = Dispatch::where('dispatch_no','Like','%'. $str . '%')
+            ->max('dispatch_no');
+
+        if(empty($order_number)){
+            $number = str_pad(1,3,'0',STR_PAD_LEFT);
+            $number = $str . $number;
+        }else{
+            $tmp = substr($order_number, -3);
+            $tmp = $tmp + 1;
+
+            //超过99999
+            if(strlen($tmp) > 3) return '';
+
+            $number = str_pad($tmp,3,'0',STR_PAD_LEFT);
+            $number = $str . $number;
+        }
+
+        return $number;
+    }
+
+    public function add($data,$user){
+        //数据校验以及填充
+        list($status,$msg) = $this->orderRule($data);
+        if(!$status) return [$status,$msg];
+
+        $dispatch_no = $this->setOrderNO();
+        try{
+            DB::beginTransaction();
+
+            //主表
+            Dispatch::insert(['dispatch_no' => $dispatch_no,'process_id' => $data['process_id'],'equipment_id' => $data['equipment_id'], 'team_id' => $data['team_id'],'dispatch_time_start' => $data['dispatch_time'][0],'dispatch_time_end' => $data['dispatch_time'][1], 'crt_time' => time()]);
+
+            date_default_timezone_set("PRC");
+            $process_model = new OrdersProductProcess(['channel' => date('Ymd',$data['out_order_no_time'][0])]);
+
+            //生产数据的源数据
+            $result = $msg;
+            $time = time();
+            foreach ($result as $key => $value){
+                $quantity_tmp = $data['quantity'][$key];
+                $result[$key]['dispatch_no'] = $dispatch_no;
+                $result[$key]['process_id'] = $data['process_id'];
+                $result[$key]['equipment_id'] = $data['equipment_id'];
+                $result[$key]['team_id'] = $data['team_id'];
+                $result[$key]['dispatch_time_start'] = $data['dispatch_time'][0];
+                $result[$key]['dispatch_time_end'] = $data['dispatch_time'][1];
+                $result[$key]['dispatch_quantity'] = $quantity_tmp;
+                $result[$key]['crt_time'] = $time;
+                $result[$key]['crt_id'] = $user['id'];
+
+                $process_model->where('order_product_id',$value['order_product_id'])
+                    ->where('process_id',$data['process_id'])
+                    ->where('dispatch_no','')
+                    ->take($quantity_tmp)
+                    ->update(['dispatch_no' => $dispatch_no]);
+            }
+
+            DispatchSub::insert($result);
+
+            DB::commit();
+        }catch (\Exception $e){
+            DB::rollBack();
+            return [false,$e->getLine().':'.$e->getMessage()];
+        }
+
+        return [true,'保存成功!'];
+    }
+
+    public function del($data){
+        if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
+
+        return [true,'删除成功'];
+    }
+
+    public function orderDetail($data){
+        return [200,''];
+    }
+
+    public function is_same_month($timestamp1,$timestamp2){
+        date_default_timezone_set("PRC");
+
+        // 格式化时间戳为年份和月份
+        $year1 = date('Y', $timestamp1);
+        $month1 = date('m', $timestamp1);
+
+        $year2 = date('Y', $timestamp2);
+        $month2 = date('m', $timestamp2);
+
+        if ($year1 === $year2 && $month1 === $month2) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public function orderList($data){
+        list($status,$msg) = $this->orderListRule($data);
+        if(! $status) return [false, $msg];
+
+        $model = OrdersProduct::where('del_time',0)
+            ->select('id','order_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','order_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','out_checker_man','out_checker_time','production_quantity','production_time','production_no','status','crt_id')
+            ->whereBetween('out_order_no_time',[$data['out_order_no_time'][0],$data['out_order_no_time'][1]])
+            ->whereIn('id',$msg)
+            ->orderBy('id','desc');
+
+        if(! empty($data['order_no'])) $model->where('order_no', 'LIKE', '%'.$data['order_no'].'%');
+        if(! empty($data['out_order_no'])) $model->where('out_order_no', 'LIKE', '%'.$data['out_order_no'].'%');
+        if(! empty($data['production_no'])) $model->where('production_no', 'LIKE', '%'.$data['production_no'].'%');
+        if(! empty($data['customer_name'])) $model->where('customer_name', 'LIKE', '%'.$data['customer_name'].'%');
+        if(! empty($data['product_title'])) $model->where('product_title', 'LIKE', '%'.$data['product_title'].'%');
+        if(! empty($data['product_size'])) $model->where('product_size', 'LIKE', '%'.$data['product_size'].'%');
+        if(! empty($data['technology_material'])) $model->where('technology_material', 'LIKE', '%'.$data['technology_material'].'%');
+        if(! empty($data['technology_name'])) $model->where('technology_name', 'LIKE', '%'.$data['technology_name'].'%');
+        if(! empty($data['wood_name'])) $model->where('wood_name', 'LIKE', '%'.$data['wood_name'].'%');
+        if(! empty($data['process_mark'])) $model->where('process_mark', 'LIKE', '%'.$data['process_mark'].'%');
+        if(! empty($data['table_header_mark'])) $model->where('table_header_mark', 'LIKE', '%'.$data['table_header_mark'].'%');
+        if(! empty($data['table_body_mark'])) $model->where('table_body_mark', 'LIKE', '%'.$data['table_body_mark'].'%');
+        if(! empty($data['out_checker_man'])) $model->where('out_checker_man', 'LIKE', '%'.$data['out_checker_man'].'%');
+        if(! empty($data['out_crt_man'])) $model->where('out_crt_man', 'LIKE', '%'.$data['out_crt_man'].'%');
+        if(! empty($data['out_checker_time'][0]) && ! empty($data['out_checker_time'][1])) $model->whereBetween('out_checker_time',[$data['out_checker_time'][0],$data['out_checker_time'][1]]);
+        if(! empty($data['production_time'][0]) && ! empty($data['production_time'][1])) $model->whereBetween('production_time',[$data['production_time'][0],$data['production_time'][1]]);
+        if(isset($data['status'])) $model->where('status',$data['status']);
+
+        $list = $this->limit($model,'',$data);
+        $list = $this->fillData($list);
+
+        return [true,$list];
+    }
+
+    public function orderListRule($data){
+        if(empty($data['process_id'])) return [false, '工序必须选择!'];
+        if(empty($data['out_order_no_time'][0]) || empty($data['out_order_no_time'][1])) return [false,'制单日期必须选择'];
+        $bool = $this->is_same_month($data['out_order_no_time'][0],$data['out_order_no_time'][1]);
+        if(! $bool) return [false,'制单日期必须同月!'];
+
+        date_default_timezone_set("PRC");
+        $process_model = new OrdersProductProcess(['process' => date('Ymd',$data['out_order_no_time'][0])]);
+        if(! $process_model->is_table_isset()) return [true, []];//不存在process子表 返回空数据
+        $process_array = $process_model->where('del_time',0)
+            ->where('process_id',$data['process_id'])
+            ->distinct()
+            ->select('order_product_id')
+            ->get()->toArray();
+        $order_product_id = array_column($process_array,'order_product_id');
+        if(empty($order_product_id)) return [true,[]];//process子表无数据 返回空数据
+
+        return [true, $order_product_id];
+    }
+
+    public function orderRule($data){
+        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
+        if($this->isEmpty($data,'quantity')) return [false,'请填写数量!'];
+        if(empty($data['dispatch_time'][0]) || empty($data['dispatch_time'][1])) return [false,'计划生产时间!'];
+        if($this->isEmpty($data,'process_id')) return [false,'工序不能为空!'];
+        if($this->isEmpty($data,'equipment_id')) return [false,'设备不能为空!'];
+        if($this->isEmpty($data,'team_id')) return [false,'班组不能为空!'];
+
+        $result = OrdersProduct::whereIn('id',$data['id'])
+            ->select('id as order_product_id','order_no','table_header_mark','product_no','product_title','product_size','product_unit','production_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark')
+            ->get()->toArray();
+
+        //已派工数据
+        $map = $this->getDispatchQuantity($data['id']);
+
+        foreach ($result as $key => $value){
+            if(isset($map[$value['order_product_id']])){
+                if($map[$value['order_product_id']] + $data['quantity'][$key] > $value['production_quantity']) return [false,'派单数量不能大于生产订单数量'];
+            }else{
+                if($data['quantity'][$key] > $value['production_quantity']) return [false,'派单数量不能大于生产订单数量'];
+            }
+        }
+
+        return [true, $result];
+    }
+
+    public function fillData($data){
+        if(empty($data['data'])) return $data;
+
+        $map = $this->getDispatchQuantity(array_column($data['data'],'id'));
+        $emp_map = Employee::whereIn('id',array_column($data['data'],'crt_id'))
+            ->pluck('emp_name','id')
+            ->toArray();
+        date_default_timezone_set("PRC");
+        foreach ($data['data'] as $key => $value){
+            $data['data'][$key]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
+            $data['data'][$key]['out_checker_time'] = $value['out_checker_time'] ? date('Y-m-d',$value['out_checker_time']) : '';
+            $data['data'][$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
+            $data['data'][$key]['dispatch_quantity'] = $map[$value['id']] ?? 0;
+            $data['data'][$key]['not_dispatch_quantity'] = $value['production_quantity'] - ($map[$value['id']] ?? 0);
+            $data['data'][$key]['order_product_man'] = $emp_map[$value['crt_id']] ?? '';
+        }
+        $data['production_quantity'] = array_sum(array_column($data['data'], 'production_quantity'));
+        $data['dispatch_quantity'] = array_sum(array_column($data['data'], 'dispatch_quantity'));
+        $data['not_dispatch_quantity'] = array_sum(array_column($data['data'], 'not_dispatch_quantity'));
+
+        return $data;
+    }
+
+    //返回已派工数量
+    public function getDispatchQuantity($order_product_id = []){
+        if(empty($order_product_id)) return [];
+
+        $result = DispatchSub::where('del_time',0)
+            ->whereIn("order_product_id",$order_product_id)
+            ->select(DB::raw("sum(dispatch_quantity) as dispatch_quantity"),'order_product_id')
+            ->groupby('order_product_id')
+            ->pluck('dispatch_quantity','order_product_id')
+            ->toArray();
+
+        return $result;
+    }
+
+    public function dispatchOrderList($data){
+        $model = DispatchSub::where('del_time',0)
+            ->select('id','order_no','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','production_quantity','production_time','dispatch_no','status','crt_id','process_id','equipment_id','team_id','dispatch_time_start','dispatch_time_end')
+            ->orderBy('id','desc');
+
+        if(! empty($data['order_no'])) $model->where('order_no', 'LIKE', '%'.$data['order_no'].'%');
+        if(! empty($data['dispatch_no'])) $model->where('dispatch_no', 'LIKE', '%'.$data['dispatch_no'].'%');
+        if(! empty($data['process_id'])) $model->where('process_id',$data['process_id']);
+        if(! empty($data['team_id'])) $model->where('team_id',$data['team_id']);
+        if(! empty($data['equipment_id'])) $model->where('equipment_id',$data['equipment_id'].'%');
+        if(! empty($data['technology_material'])) $model->where('technology_material', 'LIKE', '%'.$data['technology_material'].'%');
+        if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) $model->whereBetween('crt_time',[$data['crt_time'][0],$data['crt_time'][1]]);
+        if(! empty($data['dispatch_time'][0]) && ! empty($data['dispatch_time'][1])){
+            $model->where('dispatch_time_start','<=',$data['dispatch_time'][0]);
+            $model->where('dispatch_time_end','>=',$data['dispatch_time'][1]);
+        }
+        if(! empty($data['emp_name'])) {
+            $team_id = Employee::from('employee as a')
+                ->left('employee_team_permission as b','b.employee_id','a.id')
+                ->where('a.emp_name', 'LIKE', '%'.$data['emp_name'].'%')
+                ->select('b.team_id')
+                ->get()->toArray();
+            $team_id = array_column($team_id,'team_id');
+            $model->where('team_id',$team_id ?? []);
+        }
+
+        $list = $this->limit($model,'',$data);
+        $list = $this->fillDispatchOrderListData($list);
+
+        return [true,$list];
+    }
+
+    public function fillDispatchOrderListData($data){
+        if(empty($data['data'])) return $data;
+
+        $team = EmployeeTeamPermission::from('employee_team_permission as a')
+            ->leftJoin('employee as b','b.id','a.employee_id')
+            ->whereIn('a.team_id',array_column($data['data'],'team_id'))
+            ->select('b.emp_name','a.team_id')
+            ->get()
+            ->toArray();
+        $team_map = [];
+        if(! empty($team)){
+            foreach ($team as $value){
+                if(isset($team_map[$value['team_id']])){
+                    $team_map[$value['team_id']] .= ','. $value['emp_name'];
+                }else{
+                    $team_map[$value['team_id']] = $value['emp_name'];
+                }
+            }
+        }
+        date_default_timezone_set("PRC");
+        foreach ($data['data'] as $key => $value){
+            $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d',$value['crt_time']) : '';
+
+            $time1 = $value['dispatch_time_start'] ? date('Y-m-d',$value['dispatch_time_start']) : '';
+            $time2 = $value['dispatch_time_end'] ? date('Y-m-d',$value['dispatch_time_end']) : '';
+            $data['data'][$key]['dispatch_time'] = $time1 . ' ' . $time2;
+            $data['data'][$key]['team_man'] = $team_map[$value['team_id']] ?? '';
+        }
+        $data['dispatch_quantity'] = array_sum(array_column($data['data'], 'dispatch_quantity'));
+
+        return $data;
+    }
+}

+ 2 - 2
app/Service/FyyOrderService.php

@@ -137,7 +137,7 @@ class FyyOrderService extends Service
         }
 
         //已生产数量
-        $production_map = (new ProductionOrderService())->getProductionOrderQuantity($data['data']);
+        $production_map = (new ProductionOrderService())->getProductionOrderQuantity(array_column($data['data'],'id'));
 
         date_default_timezone_set("PRC");
         foreach ($data['data'] as $key => $value){
@@ -146,7 +146,7 @@ class FyyOrderService extends Service
             $data['data'][$key]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
             $data['data'][$key]['out_checker_time'] = $value['out_checker_time'] ? date('Y-m-d',$value['out_checker_time']) : '';
             $data['data'][$key]['product_quantity_on_hand'] = $detailMap[$keys] ?? 0;
-            $data['data'][$key]['production_quantity'] = $production_map[$value['order_no'] . $value['technology_name'] . $value['wood_name']] ?? 0;
+            $data['data'][$key]['production_quantity'] = $production_map[$value['id']] ?? 0;
         }
         $data['order_quantity'] = array_sum(array_column($data['data'], 'order_quantity'));
 

+ 29 - 28
app/Service/ProductionOrderService.php

@@ -4,8 +4,8 @@ namespace App\Service;
 
 use App\Model\OrdersProduct;
 use App\Model\OrdersProductBom;
+use App\Model\OrdersProductMain;
 use App\Model\OrdersProductProcess;
-use App\Model\Process;
 use App\Model\SaleOrdersProduct;
 use App\Model\Technology;
 use Illuminate\Support\Facades\DB;
@@ -21,7 +21,7 @@ class ProductionOrderService extends Service
     public function setOrderNO(){
         $str = date('Ymd',time());
 
-        $order_number = OrdersProduct::where('production_no','Like','%'. $str . '%')
+        $order_number = OrdersProductMain::where('production_no','Like','%'. $str . '%')
             ->max('production_no');
 
         if(empty($order_number)){
@@ -58,6 +58,9 @@ class ProductionOrderService extends Service
         try{
             DB::beginTransaction();
 
+            //主表数据写入
+            OrdersProductMain::insert(['production_no' => $production_no,'crt_time' => time(),'crt_id' => $user['id']]);
+
             //生产数据的源数据
             $result = $msg;
 
@@ -69,9 +72,18 @@ class ProductionOrderService extends Service
                 $result[$key]['production_no'] = $production_no;
                 $result[$key]['production_quantity'] = $quantity_tmp;
                 $result[$key]['production_time'] = $time;
+            }
+            OrdersProduct::insert($result);
+
+            $last_insert_id = OrdersProduct::where('production_no',$production_no)->select('id')->get()->toArray();
+            $last_insert_id = array_column($last_insert_id,'id');
+
+            foreach ($result as $key => $value){
+                $quantity_tmp = $data['quantity'][$key];
 
                 for ($i = 1; $i <= $quantity_tmp; $i++) {
                     $boom[$value['order_no']][] = [
+                        'order_product_id' => $last_insert_id[$key],
                         'production_no' => $production_no,
                         'order_no' => $value['order_no'],
                         'out_order_no' => $value['out_order_no'],
@@ -82,6 +94,7 @@ class ProductionOrderService extends Service
 
                     foreach ($process_arr as $v){
                         $process[$value['order_no']][] = [
+                            'order_product_id' => $last_insert_id[$key],
                             'production_no' => $production_no,
                             'process_id' => $v,
                             'order_no' => $value['order_no'],
@@ -94,8 +107,6 @@ class ProductionOrderService extends Service
                 }
             }
 
-            OrdersProduct::insert($result);
-
             foreach ($boom as $key => $value){
                 $boom_model = new OrdersProductBom(['channel'=> $key]);
                 $boom_model->insert($value);
@@ -127,7 +138,7 @@ class ProductionOrderService extends Service
 
     public function orderList($data){
         $model = OrdersProduct::where('del_time',0)
-            ->select('id','order_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','order_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','out_checker_man','out_checker_time','production_quantity','production_time','production_no','status')
+            ->select('id','order_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','order_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','out_checker_man','out_checker_time','production_quantity','production_time','production_no','status','sale_orders_product_id')
             ->orderBy('id','desc');
 
         if(! empty($data['order_no'])) $model->where('order_no', 'LIKE', '%'.$data['order_no'].'%');
@@ -161,13 +172,12 @@ class ProductionOrderService extends Service
         if(in_array(false, $data['quantity'], true) || in_array(0, $data['quantity'], true) || in_array('', $data['quantity'], true))return [false,'数量不能为空!'];
 
         $result = SaleOrdersProduct::whereIn('id',$data['id'])
-            ->select('order_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','order_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','out_checker_man','out_checker_time')->get()->toArray();
-        $map = $this->getProductionOrderQuantity($result);
+            ->select('id as sale_orders_product_id','order_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','order_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','out_checker_man','out_checker_time')->get()->toArray();
+        $map = $this->getProductionOrderQuantity(array_column($result,'sale_orders_product_id'));
 
         foreach ($result as $key => $value){
-            $keys = $value['order_no'] . $value['technology_name'] . $value['wood_name'];
-            if(isset($map[$keys])){
-                if($map[$keys] + $data['quantity'][$key] > $value['order_quantity']) return [false,'生产数量不能大于订单数量'];
+            if(isset($map[$value['sale_orders_product_id']])){
+                if($map[$value['sale_orders_product_id']] + $data['quantity'][$key] > $value['order_quantity']) return [false,'生产数量不能大于订单数量'];
             }else{
                 if($data['quantity'][$key] > $value['order_quantity']) return [false,'生产数量不能大于订单数量'];
             }
@@ -179,15 +189,15 @@ class ProductionOrderService extends Service
     public function fillData($data){
         if(empty($data['data'])) return $data;
 
-        $production_map = $this->getProductionOrderQuantity($data['data']);
+        $sale_orders_product_id = array_unique(array_column($data['data'],'sale_orders_product_id'));
+        $production_map = $this->getProductionOrderQuantity($sale_orders_product_id);
 
         date_default_timezone_set("PRC");
         foreach ($data['data'] as $key => $value){
             $data['data'][$key]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
             $data['data'][$key]['out_checker_time'] = $value['out_checker_time'] ? date('Y-m-d',$value['out_checker_time']) : '';
             $data['data'][$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
-            $keys = $value['order_no'] . $value['technology_name'] . $value['wood_name'];
-            $data['data'][$key]['not_production'] = $value['order_quantity'] - ($production_map[$keys] ?? 0);
+            $data['data'][$key]['not_production'] = $value['order_quantity'] - ($production_map[$value['sale_orders_product_id']] ?? 0);
         }
 
         return $data;
@@ -197,22 +207,13 @@ class ProductionOrderService extends Service
     public function getProductionOrderQuantity($data){
         if(empty($data)) return [];
 
-        $args = '';
-        foreach ($data as $value){
-            $args .= "(order_no = '{$value['order_no']}' and technology_name = '{$value['technology_name']}' and wood_name = '{$value['wood_name']}') OR ";
-        }
-        $args = rtrim($args,'OR ');
         $result = OrdersProduct::where('del_time',0)
-            ->whereRaw("($args)")
-            ->select(DB::raw("sum(production_quantity) as production_quantity"),'order_no','technology_name','wood_name')
-            ->groupby('order_no','technology_name','wood_name')
-            ->get()->toArray();
-
-        $map = [];
-        foreach ($result as $value){
-            $map[$value['order_no'] . $value['technology_name'] . $value['wood_name']] = $value['production_quantity'];
-        }
+            ->whereIn('sale_orders_product_id',$data)
+            ->select(DB::raw("sum(production_quantity) as production_quantity"),'sale_orders_product_id')
+            ->groupby('sale_orders_product_id')
+            ->pluck('production_quantity','sale_orders_product_id')
+            ->toArray();
 
-        return $map;
+        return $result;
     }
 }

+ 11 - 0
routes/api.php

@@ -43,6 +43,7 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
 
     $route->any('teamAdd', 'Api\EmployeeController@teamAdd');
     $route->any('teamEdit', 'Api\EmployeeController@teamEdit');
+    $route->any('teamDetail', 'Api\EmployeeController@teamDetail');
     $route->any('teamDel', 'Api\EmployeeController@teamDel');
     $route->any('teamList', 'Api\EmployeeController@teamList');
 
@@ -110,6 +111,16 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('productionDel', 'Api\ProductionOrderController@del');
     $route->any('productionList', 'Api\ProductionOrderController@orderList');
 
+    //派工界面
+    $route->any('dispatchAdd', 'Api\DispatchController@add');
+    $route->any('dispatchEdit', 'Api\DispatchController@edit');
+    $route->any('dispatchDel', 'Api\DispatchController@del');
+    $route->any('dispatchList', 'Api\DispatchController@orderList');
+
+    //工序派工单
+    $route->any('dispatchOrderList', 'Api\DispatchController@dispatchOrderList');
+    $route->any('dispatchOrderDel', 'Api\DispatchController@dispatchOrderDel');
+
     $route->any('productList', 'Api\MaterialController@productList');
     $route->any('productEdit', 'Api\MaterialController@edit');
     $route->any('productAdd', 'Api\MaterialController@edd');