cqpCow 1 年之前
父節點
當前提交
3bdbfdbc59

+ 1 - 1
app/Model/BasicType.php

@@ -33,6 +33,6 @@ class BasicType extends Model
         19 => '紧急程度',
         20 => '产品单位',
         21 => '跟进方式',
-        22 => '产品价格'
+        22 => '产品价格'
     ];
 }

+ 47 - 0
app/Service/ConstructionService.php

@@ -9,6 +9,8 @@ use App\Model\ConstructionProductInfo;
 use App\Model\Customer;
 use App\Model\Employee;
 use App\Model\SalesOrder;
+use App\Model\SalesOrderInfo;
+use App\Model\SalesOrderProductInfo;
 use App\Model\Storehouse;
 use Illuminate\Support\Facades\DB;
 
@@ -427,6 +429,20 @@ class ConstructionService extends Service
             $product_id[] = $value['product_id'];
         }
 
+        //剩余能施工
+        $id = $data['id'] ?? 0;
+        $s_product = $this->getSaveReturnCompareMessage($id, $data['sales_order_id']);
+
+        //比较
+        foreach ($product_submit as $pro => $number){
+            $tmp = explode(',',$pro);
+            $p = $tmp[0];
+            if(! isset($s_product[$p])) return [false,'施工产品错误,合同中不存在该产品'];
+            $s_number = $s_product[$p];
+
+            if($number > $s_number) return [false,'施工产品数量不能超过合同产品数据'];
+        }
+
         $id = $data['id'] ?? 0;
         $product_save = $this->getSaveDetail($id);
         list($status,$msg) = (new ProductInventoryService())->compareStock($product_id, $product_submit, $product_save);
@@ -525,4 +541,35 @@ class ConstructionService extends Service
 
         return $product_save;
     }
+
+    public function getSaveReturnCompareMessage($id = 0, $sales_order_id = 0){
+        $product_save = [];
+        $sub = ConstructionProductInfo::where('del_time',0)
+            ->when(! empty($id), function ($query) use ($id) {
+                return $query->where('construction_id', '<>',$id);
+            })
+            ->get()->toArray();
+        foreach ($sub as $value){
+            if(isset($product_save[$value['product_id']])){
+                $product_save[$value['product_id']] += $value['number'];
+            }else{
+                $product_save[$value['product_id']] = $value['number'];
+            }
+        }
+
+        $sales_order_product = [];
+        $sales_product = SalesOrderProductInfo::where('del_time',0)
+            ->where('sales_order_id',$sales_order_id)
+            ->get()->toArray();
+        foreach ($sales_product as $value){
+            $product_save_tmp = $product_save[$value['product_id']] ?? 0;
+            if(isset($sales_order_product[$value['product_id']])){
+                $sales_order_product[$value['product_id']] += $value['number'];
+            }else{
+                $sales_order_product[$value['product_id']] = $value['number'] - $product_save_tmp;
+            }
+        }
+
+        return $sales_order_product;
+    }
 }

+ 8 - 2
app/Service/ProductService.php

@@ -468,12 +468,19 @@ class ProductService extends Service
         foreach ($detail as $value){
             if(! $is_main){
                 $top_depart = $user['depart_top'][0] ?? [];
-                if($top_depart['basic_type_id'] != $value['basic_type_id']) continue;
+                if($top_depart['basic_type_id'] != $value['basic_type_id']){
+                    $is_show = 0;
+                }else{
+                    $is_show = 1;
+                }
+            }else{
+                $is_show = 1;
             }
             $customer['product_price'][] = [
                 'basic_type_id' => $value['basic_type_id'],
                 'basic_type_title' => $title_map[$value['basic_type_id']] ?? '',
                 'price' => $value['price'],
+                'is_show' => $is_show,
             ];
         }
 
@@ -541,7 +548,6 @@ class ProductService extends Service
             ->select('title','id','product_category_id','code','size','unit','bar_code','retail_price','cost','state','crt_id','crt_time','mark','depart_id','top_depart_id')
             ->orderby('id', 'desc');
 
-        //getALL传入后无视设置范围
         if($user['id'] != Employee::SPECIAL_ADMIN ) {
             $user_id = $user['id'];
             $depart_id = $user['depart_range'];

+ 1 - 1
app/Service/ReturnExchangeOrderService.php

@@ -392,7 +392,7 @@ class ReturnExchangeOrderService extends Service
         }
 
         //剩余能退
-        $id = $data['id'] ?? '';
+        $id = $data['id'] ?? 0;
         $s_product = $this->getSaveReturnCompareMessage($id, $data['sales_order_id']);
 
         //比较