Browse Source

第三个统计

lizhen_gitee 1 year ago
parent
commit
b42f7bb334
1 changed files with 44 additions and 4 deletions
  1. 44 4
      application/api/controller/company/Index.php

+ 44 - 4
application/api/controller/company/Index.php

@@ -89,7 +89,7 @@ class Index extends Apic
 
     //数据中心
     public function datacenter_one(){
-        $date = input('date',0);
+        $date = input('date',date('Y-m-01'));
         $starttime = strtotime($date);    //月初第一天
         $endtime = strtotime("+1 month",$starttime) - 1; //月末最后一天
 
@@ -164,7 +164,6 @@ class Index extends Apic
             $endtime   = strtotime(date('Y-m-d')) + 86399;
 
             $ec_date = [];
-            $ec_totalfee = [];
 
             $map = [
                 'company_id'  => $this->auth->company_id,
@@ -194,11 +193,52 @@ class Index extends Apic
                 }
                 unset($val['id']);
             }
-            $ec_totalfee = $servicetype;
 
             $result = [
                 'ec_data'     => $ec_date,
-                'ec_totalfee' => $ec_totalfee,
+                'ec_totalfee' => $servicetype,
+            ];
+            $this->success(1,$result);
+        }else{
+            $thismonth = strtotime(date('Y-m-01'));
+
+            $ec_date = [];
+
+            $map = [
+                'company_id'  => $this->auth->company_id,
+            ];
+            if($this->auth->type == 2){
+                $map['staff_id'] = $this->auth->id;
+            }
+
+
+            for($i=5;$i>=0;$i-=1){
+                $starttime_i = strtotime("-".$i." month",$thismonth);
+                $endtime_i = strtotime("-".$i+1 ." month",$thismonth) - 1;
+                //日历
+                $ec_date[] = date('m',$starttime_i).'月';
+                //dump(date('Y-m-d H:i:s',$starttime_i));
+                //dump(date('Y-m-d H:i:s',$endtime_i));
+            }
+
+
+            foreach($servicetype as $key => &$val){
+                $map['servicetype_id'] = $val['id'];
+                $val['data'] = [];
+                $val['textColor'] = '#FFFFFF';
+                for($i=5;$i>=0;$i-=1){
+                    $starttime_i = strtotime("-".$i." month",$thismonth);
+                    $endtime_i = strtotime("-".$i+1 ." month",$thismonth) - 1;
+                    //销售金额
+                    $map['finish_time'] = ['between',[$starttime_i,$endtime_i]];
+                    $val['data'][] = Db::name('order')->where($map)->sum('total_fee');
+                }
+                unset($val['id']);
+            }
+
+            $result = [
+                'ec_data'     => $ec_date,
+                'ec_totalfee' => $servicetype,
             ];
             $this->success(1,$result);
         }