cqpCow 1 anno fa
parent
commit
5665c27c75
1 ha cambiato i file con 7 aggiunte e 1 eliminazioni
  1. 7 1
      app/Service/PurchaseOrderService.php

+ 7 - 1
app/Service/PurchaseOrderService.php

@@ -318,7 +318,7 @@ class PurchaseOrderService extends Service
             }
         }
         if(! empty($data['order_type'])) {
-            if($data['order_type'] != PurchaseOrder::Order_type_five){
+            if($data['order_type'] == PurchaseOrder::Order_type_five){
                 $model->whereIn('order_type',[PurchaseOrder::Order_type_two,PurchaseOrder::Order_type_three,PurchaseOrder::Order_type_four]);
             }else{
                 $model->where('order_type',$data['order_type']);
@@ -420,6 +420,12 @@ class PurchaseOrderService extends Service
      */
     public function orderRule(&$data, $user, $is_check = true){
         if(empty($data['order_type'])) return [false,'采购订单类型不能为空'];
+        if($data['order_type'] == PurchaseOrder::Order_type_two && ! empty($data['supplier'])) {
+            $supplier = Supplier::where('id',$data['supplier'])->first();
+            if(! empty($supplier->is_main)) return [false,PurchaseOrder::$order_type[PurchaseOrder::Order_type_two] . '供应商请选择非总社供应商'];
+        }
+        if(($data['order_type'] == PurchaseOrder::Order_type_three || $data['order_type'] == PurchaseOrder::Order_type_four) && empty($data['supplier'])) return [false,'请选择总部供应商'];
+        if($data['order_type'] == PurchaseOrder::Order_type_three && ! empty($data['sales_order_id'])) return [false,PurchaseOrder::$order_type[PurchaseOrder::Order_type_three] . '不需要选择合同'];
         if($data['order_type'] == PurchaseOrder::Order_type_four && empty($data['sales_order_id'])) return [false, PurchaseOrder::$order_type[PurchaseOrder::Order_type_four] . '必须选择合同'];
         if($this->isEmpty($data,'product')) return [false,'产品不能为空'];
         if(empty($data['storehouse_id'])) return [false,'请选择仓库'];