wugg 10 months ago
parent
commit
04b468afa2

+ 2 - 3
app/admin/controller/Consult.php

@@ -1784,10 +1784,10 @@ class Consult extends Base
 
             }else{
                 if($bidinfos['nake_fee']!=0){
-                          $lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+  $bidinfos['cert_fee'] +  $bidinfos['nake_fee']) / (1 - $lower_rate);
+                	$lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+  $bidinfos['cert_fee'] +  $bidinfos['nake_fee']) / (1 - $lower_rate);
 
                 }else{
-                       $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+  $bidinfos['cert_fee'])/ (1 - $lower_rate);
+                   $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+  $bidinfos['cert_fee'])/ (1 - $lower_rate);
                 }
             }
         $info['cost_desc'] =$bidinfos['cost_desc'];
@@ -1837,7 +1837,6 @@ class Consult extends Base
         $info['is_custom'] =$consultinfos['is_custom'];
 
         $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
-//        $info['sale_price'] =round($bidinfos['sale_price'],2);//议价前价格
         $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
         $info['lower_price'] =round($lower_price,2);
         //获取议价原因

+ 30 - 0
app/admin/model/CompanyCatProfit.php

@@ -0,0 +1,30 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class CompanyCatProfit extends Model
+{
+    public function GetRate($companyNo,$cat_id,$field){
+        $rate=$this->where(["companyNo"=>$companyNo,"cat_id"=>$cat_id])->value($field,0);
+        if($rate==0){
+        	$parent = $this->name("cat")->where(["id"=>$cat_id])->value("parent_id",0);
+        	if($parent>0)$rate=$this->GetRate($companyNo,$parent,$field);
+        }
+        return $rate;
+    }
+    
+     public function GetAllRate($companyNo,$cat_id){
+        $rate=$this->where(['companyNo'=>$companyNo,'cat_id'=>$cat_id])->findOrEmpty();
+        if($rate->isEmpty()){
+        	$parent = $this->name('cat')->where(['id'=>$cat_id])->value('parent_id',0);
+        	if($parent>0)$rate=$this->GetAllRate($companyNo,$parent);
+        }
+        return $rate;
+    }
+}

+ 30 - 0
app/admin/model/CompanyPlatformCatProfit.php

@@ -0,0 +1,30 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class CompanyPlatformCatProfit extends Model
+{
+    public function GetRate($companyNo,$cat_id,$platform,$field){
+        $rate=$this->where(['companyNo'=>$companyNo,'cat_id'=>$cat_id,'platform_id'=>$platform])->value($field,0);
+        if($rate==0){
+        	$parent = $this->name('cat')->where(['id'=>$cat_id])->value('parent_id',0);
+        	if($parent>0)$rate=$this->GetRate($companyNo,$parent,$platform,$field);
+        }
+        return $rate;
+    }
+    
+     public function GetAllRate($companyNo,$cat_id,$platform){
+        $rate=$this->where(['companyNo'=>$companyNo,'cat_id'=>$cat_id,'platform_id'=>$platform])->findOrEmpty();
+        if($rate->isEmpty()){
+        	$parent = $this->name('cat')->where(['id'=>$cat_id])->value('parent_id',0);
+        	if($parent>0)$rate=$this->GetAllRate($companyNo,$parent,$platform);
+        }
+        return $rate;
+    }
+}

+ 14 - 8
app/common.php

@@ -1627,15 +1627,16 @@ function endTime($time){
 if (function_exists('get_budget') == false) {
     function get_budget(int $cat_id = 0, string $relaComNo = '', int $platform_id = 0,bool $is_show_more=false)
     {
-        $sale_rate_1 = Db::name('company_cat_profit')
-            ->where(['is_del' => 0, 'cat_id' => $cat_id, 'companyNo' => $relaComNo])
-            ->findOrEmpty();
-
-        $sale_rate_2 = Db::name('company_platform_cat_profit')
-            ->where(['is_del' => 0, 'companyNo' => $relaComNo, 'platform_id' => $platform_id, 'cat_id' => $cat_id, 'status' => 1])
-            ->findOrEmpty();
+//        $sale_rate_1 = (new \app\admin\model\CompanyCatProfit)->GetAllRate($relaComNo,$cat_id);
+//		if($sale_rate_1->isEmpty()) throw new \think\Exception("该分类未找到有关毛利信息");
+//        $sale_rate_2 = Db::name('company_platform_cat_profit')
+//            ->where(['is_del' => 0, 'companyNo' => $relaComNo, 'platform_id' => $platform_id, 'cat_id' => $cat_id, 'status' => 1])
+//            ->findOrEmpty();
 
         if ($is_show_more) {
+	        $sale_rate_1 = (new \app\admin\model\CompanyCatProfit)->GetAllRate($relaComNo,$cat_id);
+			if($sale_rate_1->isEmpty()) throw new \think\Exception('该分类未找到有关毛利信息');
+			 $sale_rate_2 = (new \app\admin\model\CompanyPlatformCatProfit)->GetAllRate($relaComNo,$cat_id,$platform_id);
             //返回多个字段的和
             return [
                 'rate' => (($sale_rate_1['rate'] ?? 0) + ($sale_rate_2['rate'] ?? 0)) / 100,
@@ -1645,7 +1646,12 @@ if (function_exists('get_budget') == false) {
                 'sale_rate' => (($sale_rate_1['sale_rate'] ?? 0) + ($sale_rate_2['sale_rate'] ?? 0)) / 100,
                 'lower_rate'=>0,//boss利率,默认0,数据库没有这个值
             ];
-        } else return (($sale_rate_1['sale_rate'] ?? 0) + ($sale_rate_2['sale_rate'] ?? 0)) / 100; //此时的毛利率要取两个毛利的和
+        } else {
+        	 $sale_rate_1 = (new \app\admin\model\CompanyCatProfit)->GetRate($relaComNo,$cat_id,"sale_rate");
+			if($sale_rate_1==0) throw new \think\Exception('该分类未找到有关毛利信息');
+			 $sale_rate_2 = (new \app\admin\model\CompanyPlatformCatProfit)->GetRate($relaComNo,$cat_id,$platform_id,'sale_rate');
+        	return ($sale_rate_1 + $sale_rate_2) / 100;
+        } //此时的毛利率要取两个毛利的和
 
     }
 }