wugg 2 years ago
parent
commit
e6a24c772d
2 changed files with 49 additions and 2 deletions
  1. 48 2
      app/command/reportTips.php
  2. 1 0
      config/console.php

+ 48 - 2
app/command/reportTips.php

@@ -8,7 +8,7 @@ use think\console\Input;
 use think\console\input\Argument;
 use think\console\input\Option;
 use think\console\Output;
-use think\facade\Db;
+use think\facade\Cache;use think\facade\Db;
 
 class reportTips extends Command
 {
@@ -23,10 +23,56 @@ class reportTips extends Command
     {
         // 指令输出
         $supplier = ["QS2203150147015222","QS2206011447553544","QS2203150147013805"];
+        $this->GetData($supplier);
         $output->writeln('reporttips');
     }
 
 	private function GetData($code){
-		$total =Db::name("qrd_info")->where([["companyNo","=",$code],[""]])->sum('totalPrice+th_fee');
+		$month_total =Db::name("qrd_info")->where([["companyNo","in",$code]])->whereMonth("createdTime","this month")
+		->group("companyNo")->column('sum(totalPrice+th_fee) as monthTotal','companyNo');
+		$month_thtotal=Db::name("th_source")->where([["th_companyNo","in",$code]])->whereMonth("createtime","this month")
+		->group("th_companyNo")->column('sum(th_qrd_fee) as month_thTotal','th_companyNo');
+		$week_total =Db::name("qrd_info")->where([["companyNo","in",$code]])->whereWeek("createdTime","this week")
+		->group("companyNo")->column('sum(totalPrice+th_fee) as weekTotal','companyNo');
+		$week_thtotal=Db::name("th_source")->where([["th_companyNo","in",$code]])->whereWeek("createtime","this week")
+		->group("th_companyNo")->column('sum(th_qrd_fee) as week_thTotal','th_companyNo');
+		$day_total =Db::name("qrd_info")->where([["companyNo","in",$code]])->whereDay("createdTime","today")->group("companyNo")
+		->column('sum(totalPrice+th_fee) as dayTotal','companyNo');
+		$day_thtotal=Db::name("th_source")->where([["th_companyNo","in",$code]])->whereDay("createtime","today")
+		->group("th_companyNo")->column('sum(th_qrd_fee) as day_thTotal','th_companyNo');
+	 $tips = Db::name("depart_tips")->where('year=YEAR(NOW()) and month=month(NOW())')->column("department,total_tips","departcode");
+        $data=[];
+        $temp=["p"=>"总计","thtotal"=>0,"mtotal"=>0,"mthfee"=>0,"wtotal"=>0,"wthfee"=>0,"dtotal"=>0,"thfee"=>0,
+        "tips"=>0,"rate"=>0,"thrate"=>0];
+        foreach ($tips as $key=>$value){
+			$t=[];
+			$t['p']=$value['department'];
+			$t['thtotal']=$month_total[$key]??0 - $month_thtotal[$key]??0;
+			$t['mtotal']=$month_total[$key]??0 ;
+			$t['mthfee']=$month_thtotal[$key]??0;
+			$t['wtotal']=$week_total[$key]??0;
+			$t['wthfee']= $week_thtotal[$key]??0;
+			$t['dtotal']=$day_total[$key]??0;
+			$t['thfee']= $day_thtotal[$key]??0;
+			$t['tips']= $value['total_tips']??0;
+			$t["rate"]=number_format( $t['mtotal']/$value['total_tips']*100,2);
+			$t["thrate"]=number_format( $t['thtotal']/$value['total_tips']*100,2);
+			$data[]=$t;
+        }
+        $temp['thtotal'] = array_sum(array_column($data,'thtotal'));
+        $temp['mtotal'] = array_sum(array_column($data,'mtotal'));
+        $temp['mthfee'] = array_sum(array_column($data,'mthfee'));
+        $temp['wtotal'] = array_sum(array_column($data,'wtotal'));
+        $temp['wthfee'] = array_sum(array_column($data,'wthfee'));
+        $temp['dtotal'] = array_sum(array_column($data,'dtotal'));
+        $temp['thfee'] = array_sum(array_column($data,'thfee'));
+        $temp['tips'] = array_sum(array_column($data,'tips'));
+        $temp["rate"]=number_format( $temp['mtotal']/$temp['tips']*100,2);
+		$temp["thrate"]=number_format( $temp['thtotal']/$temp['tips']*100,2);
+
+		$sort = array_column($data,"thrate");
+        array_multisort($sort,SORT_DESC,$data);
+        array_unshift($data,$temp);
+        Cache::store("redis")->set("statContent",$data);
 	}
 }

+ 1 - 0
config/console.php

@@ -12,5 +12,6 @@ return [
         'handleCxData'=>app\command\handleCxData::class,//处理中间表的采销数据
 
         'Good'=>app\command\good::class,//处理中间表的采销数据
+        'reporttips'=>app\command\reportTips::class,//处理中间表的采销数据
     ],
 ];