chenqp 7 months ago
parent
commit
2e98e34ce1
1 changed files with 28 additions and 9 deletions
  1. 28 9
      app/Service/SalesOrderService.php

+ 28 - 9
app/Service/SalesOrderService.php

@@ -1331,7 +1331,8 @@ class SalesOrderService extends Service
             SalesOrder::where('del_time',0)->where('id',$msg['id'])->update([
                 'state' => SalesOrder::State_four,
                 'dispatch_time_second' => $time,
-                'dispatch_time_second_id' => $user['id']
+                'dispatch_time_second_id' => $user['id'],
+                'type' => $data['type'] ?? 0
             ]);
 
             SeeRange::where('del_time',0)
@@ -1411,7 +1412,7 @@ class SalesOrderService extends Service
      * @param $data
      * @return array
      */
-    public function salesOrderDispatchCompanyRule($data){
+    public function salesOrderDispatchCompanyRule(&$data){
         if(empty($data['id'])) return [false,'请选择合同派单'];
         $sale = SalesOrder::where('del_time',0)
             ->where('id',$data['id'])
@@ -1423,7 +1424,7 @@ class SalesOrderService extends Service
         if($sale['state'] > SalesOrder::State_four) return [false,'请确认合同状态,操作失败'];
         $product = SalesOrderProductInfo::where('del_time',0)
             ->where('sales_order_id',$data['id'])
-            ->select('product_id')
+            ->select('product_id','number')
             ->get()->toArray();
         if(empty($product)) return [false,'合同产品不能为空'];
 
@@ -1433,10 +1434,17 @@ class SalesOrderService extends Service
         if($bool) return [false,'合同已下施工,操作失败'];
 
         if(empty($data['dispatch_depart_two'])) return [false, '请指派总社或分社'];
-        $product = array_unique(array_column($product,'product_id'));
-        $return = RangeService::productNotSeeRange($product);
+        $product_id = array_unique(array_column($product,'product_id'));
+        $return = RangeService::productNotSeeRange($product_id);
+
+        //产品信息
+        $product_array = Product::whereIn('id',$product_id)->select('title','id','build_fee')->get()->toArray();
+        $map = $map2 = [];
+        foreach ($product_array as $value){
+            $map[$value['id']] = $value['title'];
+            $map2[$value['id']] = $value['build_fee'];
+        }
         if(! empty($return)){
-            $map = Product::whereIn('id',$product)->pluck('title','id')->toArray();
             foreach ($data['dispatch_depart_two'] as $value){
                 foreach ($return as $key => $values){
                     $tmp = $map[$key] ?? "";
@@ -1445,9 +1453,20 @@ class SalesOrderService extends Service
             }
         }
 
-        if(empty($data['other_fee_1'])) return [false,'价格不能为空'];
-        $res = $this->checkNumber($data['other_fee_1']);
-        if(! $res) return [false,'价格请输入不超过两位小数并且大于0的数值'];
+        //到店安装 原逻辑
+        if(empty($data['type'])){
+            if(empty($data['other_fee_1'])) return [false,'价格不能为空'];
+            $res = $this->checkNumber($data['other_fee_1']);
+            if(! $res) return [false,'到店安装价格请输入不超过两位小数并且大于0的数值'];
+        }else{
+            $other_fee_1 = 0;
+            foreach ($product as $value){
+                $build_fee = $map2[$value['product_id']] ?? 0;
+                $fee = bcmul($value['number'],$build_fee,2);
+                $other_fee_1 = bcadd($other_fee_1,$fee,2);
+            }
+            $data['other_fee_1'] = $other_fee_1;
+        }
 
         return [true, $sale];
     }