Browse Source

数据大屏优化转单率和完成率

wufeng 2 years ago
parent
commit
64047ded7f
1 changed files with 17 additions and 12 deletions
  1. 17 12
      app/admin/controller/Data.php

+ 17 - 12
app/admin/controller/Data.php

@@ -230,9 +230,9 @@ class Data extends BaseController
         //已反馈单数
         $zixun_bids = Db::name('consult_info')
             ->alias('ci')
-            ->join('consult_bids cb','cb.infoNo=ci.infoNo')
+            ->join('consult_bids cb', 'cb.infoNo=ci.infoNo')
             ->join('consult_order co', 'co.zxNo = cb.zxNo ')
-            ->where(['cb.is_del'=>0,'ci.is_del'=>0,'bargain_code'=>''])
+            ->where(['cb.is_del' => 0, 'ci.is_del' => 0, 'bargain_code' => ''])
             ->where('co.endtime', '>=', date('Y-m-d H:i:s'))
             ->group('cb.infoNo')
             ->count('cb.id');
@@ -319,22 +319,27 @@ class Data extends BaseController
             ->select()
             ->toArray();
 
+        $da = [];
         //计算完成率
-        foreach ($sale_indicators as &$value) {
-            $temp = isset($sales_volume[$value['department']]['sales_volume']) ? $sales_volume[$value['department']]['sales_volume'] : 0;
-            $value['finish'] = $temp;
-            $value['finish_rate'] = round(($temp / $value['total_tips']) * 100, 5);
+        foreach ($sale_indicators as $value) {
+
+            if (isset($sales_volume[$value['department']]['sales_volume'])) {
+                $value['finish'] = $sales_volume[$value['department']]['sales_volume'];
+                $value['finish_rate'] = round(($value['finish'] / $value['total_tips']) * 100, 5);
+                $da[] = $value;
+            } else continue;
+
         }
 
         //按照完成率排序
-        usort($sale_indicators, function ($left, $right) {
+        usort($da, function ($left, $right) {
             return ($left['finish_rate'] > $right['finish_rate']) ? -1 : 1;
         });
 
         //计算汇总完成率
-        $total_finish_rate = round((array_sum(array_column($sales_volume, 'sales_volume')) / array_sum(array_column($sale_indicators, 'total_tips'))) * 100, 2);
+        $total_finish_rate = round((array_sum(array_column($sales_volume, 'sales_volume')) / array_sum(array_column($da, 'total_tips'))) * 100, 2);
 
-        return app_show(0, '请求成功', ['list' => $sale_indicators, 'total_finish_rate' => $total_finish_rate]);
+        return app_show(0, '请求成功', ['list' => $da, 'total_finish_rate' => $total_finish_rate]);
 
     }
 
@@ -344,7 +349,7 @@ class Data extends BaseController
         $consulting = Db::name('sale')
             ->alias('s')
             ->leftJoin('depart_user u', 'u.uid=s.apply_id AND u.is_del=0')
-            ->where(['s.order_type' => 2, 's.is_del' => 0])
+            ->where(['s.order_type' => 3, 's.is_del' => 0])//order_type==3 咨询采反
             ->whereDay('s.addtime')
             ->group('u.itemid')
             ->column('count(s.id) consulting', 'u.itemid');
@@ -374,7 +379,7 @@ class Data extends BaseController
         $consulting = Db::name('sale')
             ->alias('s')
             ->leftJoin('depart_user u', 'u.uid=s.apply_id AND u.is_del=0')
-            ->where(['s.order_type' => 2, 's.is_del' => 0])
+            ->where(['s.order_type' => 3, 's.is_del' => 0])//order_type==3 咨询采反
             ->whereMonth('s.addtime')
             ->group('u.itemid')
             ->column('count(s.id) consulting', 'u.itemid');
@@ -405,7 +410,7 @@ class Data extends BaseController
         $consulting = Db::name('sale')
             ->alias('s')
             ->leftJoin('depart_user u', 'u.uid=s.apply_id AND u.is_del=0')
-            ->where(['s.order_type' => 2, 's.is_del' => 0])
+            ->where(['s.order_type' => 3, 's.is_del' => 0])//order_type==3 咨询采反
             ->whereYear('s.addtime', date('Y'))
             ->group('u.itemid')
             ->column('count(s.id) consulting', 'u.itemid');